glimmer-dsl-swt 0.5.4 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87bcff5d2b652ab8238bfa4860c5c7710e56155712aafc80dd3f8a4acd6a080c
4
- data.tar.gz: 7b4dd240b1af86fa39233dec7b9e1e514245ec35513a1589510d0ab21ffbdf9b
3
+ metadata.gz: 1d54a8793938853e74eb207e159ce6ab3f856ac57f737a3bd28990f5e52a745d
4
+ data.tar.gz: a28121a29d1a123b056d121642bf70acd12891c428bdda8602caa2cf7157df35
5
5
  SHA512:
6
- metadata.gz: 302644cbe7cbfc6c416585ab4c8d6cc38447ea0a3cb98eaf34473d8b0760f03d67eb9f59616ccf6d4e77b7cfc6112432dcdf6d16a5ccb310d90002ab2e39496d
7
- data.tar.gz: efac7d222037f8e3434750c514b6afedcef6faefc60911291261387a4f0639ba73fb7d5f152abebfbc0ba6097701c124b83ca0975a0244add554cb58ab720a80
6
+ metadata.gz: 21a850f6805c1cc2f129bdc91c09c7a8b336ce81640311af63040c8168d535ab68fb91cb53bf0a8421ec38d1daab94b9a835eec209e2685e1702ca3e91b51af8
7
+ data.tar.gz: 3044e95046bbda195c0ecd736ff30097ab6dadf660093d317d86d92c46f1bdf16dc669f944a9a62b398fa2f27697572290f4df9caffb8825c6b61a8f0ff2fea1
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 0.5.4 (Desktop GUI)
1
+ # [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for SWT 0.6.2 (Desktop GUI)
2
2
  [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-swt.svg)](http://badge.fury.io/rb/glimmer-dsl-swt)
3
3
  [![Travis CI](https://travis-ci.com/AndyObtiva/glimmer-dsl-swt.svg?branch=master)](https://travis-ci.com/github/AndyObtiva/glimmer-dsl-swt)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/glimmer-dsl-swt/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/glimmer-dsl-swt?branch=master)
@@ -1 +1 @@
1
- jruby-9.2.12.0
1
+ jruby-9.2.13.0
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.4
1
+ 0.6.2
Binary file
@@ -105,7 +105,6 @@ end
105
105
  Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
106
106
  method = method_symbol.to_s
107
107
  result = false
108
- result ||= method.start_with?('on_swt_') && is_a?(Glimmer::UI::CustomWidget) && respond_to?(method)
109
108
  result ||= method == 'dispose' && is_a?(Glimmer::UI::CustomWidget) && respond_to?(method)
110
109
  result ||= ['drag_source_proxy', 'drop_target_proxy'].include?(method) && is_a?(Glimmer::UI::CustomWidget)
111
110
  result ||= method == 'post_initialize_child'
@@ -0,0 +1,23 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/swt/cursor_proxy'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module SWT
7
+ # cursor expression
8
+ # Note: Cannot be a static expression because it clashes with cursor property expression
9
+ class CursorExpression < Expression
10
+ def can_interpret?(parent, keyword, *args, &block)
11
+ keyword.to_s == 'cursor' and
12
+ (parent.nil? or !parent.respond_to?('cursor')) and
13
+ args.size == 1 and
14
+ (args.first.is_a?(Integer) or textual?(args.first))
15
+ end
16
+
17
+ def interpret(parent, keyword, *args, &block)
18
+ Glimmer::SWT::CursorProxy.new(*args)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -24,6 +24,9 @@ module Glimmer
24
24
  tree_items_data_binding
25
25
  table_items_data_binding
26
26
  data_binding
27
+ cursor
28
+ font
29
+ image
27
30
  property
28
31
  block_property
29
32
  widget
@@ -0,0 +1,26 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/dsl/top_level_expression'
3
+ require 'glimmer/swt/font_proxy'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ # font expression
9
+ # Note: Cannot be a static expression because it clashes with font property expression
10
+ class FontExpression < Expression
11
+ include TopLevelExpression
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ keyword.to_s == 'font' and
15
+ (parent.nil? || !parent.respond_to?('font')) and
16
+ args.size == 1 and
17
+ args.first.is_a?(Hash)
18
+ end
19
+
20
+ def interpret(parent, keyword, *args, &block)
21
+ Glimmer::SWT::FontProxy.new(*args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/swt/image_proxy'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module SWT
7
+ # image expression
8
+ # Note: Cannot be a static expression because it clashes with image property expression
9
+ class ImageExpression < Expression
10
+ def can_interpret?(parent, keyword, *args, &block)
11
+ keyword.to_s == 'image' and
12
+ (parent.nil? or !parent.respond_to?('image'))
13
+ end
14
+
15
+ def interpret(parent, keyword, *args, &block)
16
+ Glimmer::SWT::ImageProxy.new(*args)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -25,6 +25,12 @@ module Glimmer
25
25
  end
26
26
  widget_class.new(keyword, parent, args)
27
27
  end
28
+
29
+ def add_content(parent, &block)
30
+ super
31
+ parent.post_add_content
32
+ end
33
+
28
34
  end
29
35
  end
30
36
  end
@@ -110,7 +110,7 @@ module Glimmer
110
110
  end
111
111
  command = "#{env_vars_string} jruby #{jruby_options_string}#{jruby_os_specific_options} #{devmode_require}-r #{the_glimmer_lib} -S #{application}"
112
112
  puts command if jruby_options_string.to_s.include?('--debug')
113
- system command
113
+ exec command
114
114
  end
115
115
  end
116
116
  end
@@ -21,7 +21,7 @@ module Glimmer
21
21
  system('warble config')
22
22
  new_config = File.read('config/warble.rb').split("\n").inject('') do |output, line|
23
23
  if line.include?('config.dirs =')
24
- line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app config db lib script bin docs fonts icons images sounds videos vendor)')
24
+ line = line.sub('# ', '').sub(/=[^=\n]+$/, '= %w(app bin config db docs fonts icons images lib package script sounds vendor videos)')
25
25
  end
26
26
  if line.include?('config.includes =')
27
27
  line = line.sub('# ', '').sub(/=[^=\n]+$/, "= FileList['LICENSE.txt', 'VERSION']")
@@ -41,7 +41,15 @@ module Glimmer
41
41
  system('warble')
42
42
  end
43
43
 
44
- def native
44
+ def lock_jars
45
+ puts 'Locking JARs with jar-dependencies...'
46
+ command = "lock_jars --vendor-dir vendor"
47
+ puts command
48
+ system command
49
+ end
50
+
51
+ def native(native_type=nil)
52
+ puts "Generating native executable with javapackager..."
45
53
  require 'facets/string/titlecase'
46
54
  require 'facets/string/underscore'
47
55
  project_name = File.basename(File.expand_path('.'))
@@ -51,14 +59,13 @@ module Glimmer
51
59
  license = (File.read(license_file).strip if File.exists?(license_file) && File.file?(license_file)) rescue nil
52
60
  copyright = license.split("\n").first
53
61
  human_name = project_name.underscore.titlecase
54
- command = "javapackager -deploy -native -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" -BsystemWide=#{OS.mac?} "
62
+ command = "javapackager -deploy -native #{native_type} -outdir packages -outfile \"#{project_name}\" -srcfiles \"dist/#{project_name}.jar\" -appclass JarMain -name \"#{human_name}\" -title \"#{human_name}\" -Bmac.CFBundleName=\"#{human_name}\" -Bmac.CFBundleIdentifier=\"org.#{project_name}.application.#{project_name}\" -Bmac.category=\"public.app-category.business\" -BinstalldirChooser=true -Bvendor=\"#{human_name}\" -Bwin.menuGroup=\"#{human_name}\" -BsystemWide=#{OS.mac?} "
55
63
  command += " -BjvmOptions=-XstartOnFirstThread " if OS.mac?
56
64
  command += " -BappVersion=#{version} -Bmac.CFBundleVersion=#{version} " if version
57
65
  command += " -srcfiles LICENSE.txt -BlicenseFile=LICENSE.txt " if license
58
66
  command += " -Bcopyright=\"#{copyright}\" " if copyright
59
67
  command += " #{javapackager_extra_args} " if javapackager_extra_args
60
68
  command += " #{ENV['JAVAPACKAGER_EXTRA_ARGS']} " if ENV['JAVAPACKAGER_EXTRA_ARGS']
61
- puts "Generating DMG/PKG/APP/JNLP with javapackager..."
62
69
  puts command
63
70
  system command
64
71
  end
@@ -19,17 +19,24 @@ namespace :glimmer do
19
19
  Glimmer::Package.jar
20
20
  end
21
21
 
22
- desc 'Generate Native files (DMG/PKG/APP on the Mac, EXE on Windows, RPM/DEB on Linux)'
23
- task :native do
24
- Glimmer::Package.native
22
+ desc 'Lock JARs'
23
+ task :lock_jars do
24
+ Glimmer::Package.lock_jars
25
+ end
26
+
27
+ desc 'Generate Native files (DMG/PKG/APP on the Mac, MSI/EXE/IMAGE on Windows, RPM/DEB on Linux) (type is optional)'
28
+ task :native, [:type] do |t, args|
29
+ Glimmer::Package.native(args[:type])
25
30
  end
26
31
  end
27
32
 
28
- desc 'Package app for distribution (generating config, jar, and native files)'
29
- task :package do
33
+ desc 'Package app for distribution (generating config, jar, and native files) (type is optional)'
34
+ task :package, [:type] do |t, args|
30
35
  Rake::Task['glimmer:package:config'].execute
31
36
  Rake::Task['glimmer:package:jar'].execute
32
- Rake::Task['glimmer:package:native'].execute
37
+ Rake::Task['glimmer:package:lock_jars'].execute
38
+ Rake::Task['gemspec:generate'].execute
39
+ Rake::Task['glimmer:package:native'].execute(args)
33
40
  end
34
41
 
35
42
 
@@ -76,21 +76,7 @@ class Scaffold
76
76
  packages
77
77
  MULTI_LINE_STRING
78
78
 
79
- GEMFILE_APP = <<~MULTI_LINE_STRING
80
- # frozen_string_literal: true
81
-
82
- source 'https://rubygems.org'
83
-
84
- git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
85
-
86
- gem 'glimmer-dsl-swt', '~> #{VERSION}'
87
-
88
- group :test do
89
- gem 'rspec'
90
- end
91
- MULTI_LINE_STRING
92
-
93
- GEMFILE_GEM = <<~MULTI_LINE_STRING
79
+ GEMFILE = <<~MULTI_LINE_STRING
94
80
  # frozen_string_literal: true
95
81
 
96
82
  source 'https://rubygems.org'
@@ -101,24 +87,12 @@ class Scaffold
101
87
 
102
88
  group :development do
103
89
  gem 'rspec', '~> 3.5.0'
90
+ gem 'git-glimmer', '1.7.0'
104
91
  gem 'jeweler', '2.3.9'
105
92
  gem 'simplecov', '>= 0'
106
93
  end
107
94
  MULTI_LINE_STRING
108
95
 
109
- RAKEFILE = <<~MULTI_LINE_STRING
110
- require 'glimmer/rake_task'
111
-
112
- ## Use the following configuration if you would like to customize javapackager
113
- ## arguments for `glimmer package` command.
114
- #
115
- # Glimmer::Package.javapackager_extra_args =
116
- # " -BlicenseType=" +
117
- # " -Bmac.CFBundleIdentifier=" +
118
- # " -Bmac.category=" +
119
- # " -Bmac.signing-key-developer-id-app="
120
- MULTI_LINE_STRING
121
-
122
96
  RVM_FUNCTION = <<~MULTI_LINE_STRING
123
97
  # Load RVM into a shell session *as a function*
124
98
  if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
@@ -135,21 +109,30 @@ class Scaffold
135
109
  MULTI_LINE_STRING
136
110
 
137
111
  def app(app_name)
138
- mkdir app_name
139
- cd app_name
112
+ return puts('Namespace is required! Usage: glimmer scaffold:custom_shell_gem[custom_shell_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
113
+ gem_name = file_name(app_name)
114
+ gem_summary = human_name(app_name)
115
+ system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
116
+ cd gem_name
117
+ rm_rf 'lib'
140
118
  write '.gitignore', GITIGNORE
141
119
  write '.ruby-version', RUBY_VERSION
142
120
  write '.ruby-gemset', app_name
143
121
  write 'VERSION', '1.0.0'
144
122
  write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
145
- write 'Gemfile', GEMFILE_APP
146
- write 'Rakefile', RAKEFILE
123
+ write 'Gemfile', GEMFILE
124
+ write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
147
125
  mkdir 'app'
148
126
  write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
149
127
  mkdir 'app/models'
150
128
  mkdir 'app/views'
151
129
  custom_shell('AppView', current_dir_name, :app)
152
- if OS.mac?
130
+ if OS::Underlying.windows?
131
+ mkdir_p 'package/windows'
132
+ icon_file = "package/windows/#{human_name(app_name)}.ico"
133
+ cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
134
+ puts "Created #{current_dir_name}/#{icon_file}"
135
+ elsif OS.mac?
153
136
  mkdir_p 'package/macosx'
154
137
  icon_file = "package/macosx/#{human_name(app_name)}.icns"
155
138
  cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
@@ -157,8 +140,15 @@ class Scaffold
157
140
  end
158
141
  mkdir 'bin'
159
142
  write "bin/#{file_name(app_name)}", app_bin_file(app_name)
160
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
161
- system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
143
+ write 'spec/spec_helper.rb', spec_helper_file
144
+ if OS.windows?
145
+ system "bundle"
146
+ system "glimmer package[image]"
147
+ system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
148
+ else
149
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
150
+ system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app" if OS.mac?
151
+ end
162
152
  # TODO generate rspec test suite
163
153
  end
164
154
 
@@ -188,13 +178,13 @@ class Scaffold
188
178
  else
189
179
  namespace = 'glimmer'
190
180
  end
191
- system "jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
181
+ system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
192
182
  cd gem_name
193
183
  write '.gitignore', GITIGNORE
194
184
  write '.ruby-version', RUBY_VERSION
195
185
  write '.ruby-gemset', gem_name
196
186
  write 'VERSION', '1.0.0'
197
- write 'Gemfile', GEMFILE_GEM
187
+ write 'Gemfile', GEMFILE
198
188
  write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
199
189
  append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
200
190
  mkdir 'lib/views'
@@ -203,14 +193,26 @@ class Scaffold
203
193
  write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
204
194
  write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
205
195
  FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
206
- if OS.mac?
196
+ write 'spec/spec_helper.rb', spec_helper_file
197
+ if OS::Underlying.windows?
198
+ mkdir_p 'package/windows'
199
+ icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
200
+ cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
201
+ puts "Created #{current_dir_name}/#{icon_file}"
202
+ elsif OS.mac?
207
203
  mkdir_p 'package/macosx'
208
204
  icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
209
205
  cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
210
206
  puts "Created #{current_dir_name}/#{icon_file}"
211
207
  end
212
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
213
- system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app"
208
+ if OS.windows?
209
+ system "bundle"
210
+ system "glimmer package[image]"
211
+ system "\"packages/bundles/#{human_name(custom_shell_name)}/#{human_name(custom_shell_name)}.exe\""
212
+ else
213
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
214
+ system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" if OS.mac?
215
+ end
214
216
  puts "Finished creating #{gem_name} Ruby gem."
215
217
  puts 'Edit Rakefile to configure gem details.'
216
218
  puts 'Run `rake` to execute specs.'
@@ -228,19 +230,23 @@ class Scaffold
228
230
  else
229
231
  namespace = 'glimmer'
230
232
  end
231
- system "jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
233
+ system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
232
234
  cd gem_name
233
235
  write '.gitignore', GITIGNORE
234
236
  write '.ruby-version', RUBY_VERSION
235
237
  write '.ruby-gemset', gem_name
236
238
  write 'VERSION', '1.0.0'
237
- write 'Gemfile', GEMFILE_GEM
239
+ write 'Gemfile', GEMFILE
238
240
  write 'Rakefile', gem_rakefile
239
241
  write 'spec/spec_helper.rb', spec_helper_file
240
242
  append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
241
243
  mkdir 'lib/views'
242
244
  custom_widget(custom_widget_name, namespace)
243
- system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
245
+ if OS.windows?
246
+ system "bundle"
247
+ else
248
+ system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
249
+ end
244
250
  puts "Finished creating #{gem_name} Ruby gem."
245
251
  puts 'Edit Rakefile to configure gem details.'
246
252
  puts 'Run `rake` to execute specs.'
@@ -355,10 +361,11 @@ class Scaffold
355
361
  lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
356
362
  gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
357
363
  if custom_shell_name
358
- lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*.rb', 'bin/**/*']")
364
+ lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*', 'app/**/*', 'bin/**/*', 'vendor/**/*', 'package/**/*']")
359
365
  lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
366
+ lines.insert(gem_files_line_index+2, " gem.require_paths = ['vendor', 'lib', 'app']")
360
367
  else
361
- lines.insert(gem_files_line_index, " gem.files = Dir['lib/**/*.rb']")
368
+ lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*']")
362
369
  end
363
370
  spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
364
371
  lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_swt_options]")
@@ -383,7 +390,7 @@ class Scaffold
383
390
  content = File.read('spec/spec_helper.rb')
384
391
  lines = content.split("\n")
385
392
  require_line_index = lines.index(lines.detect {|l| l.include?(current_dir_name) })
386
- lines[require_line_index...require_line_index] = [
393
+ lines[require_line_index..require_line_index] = [
387
394
  "require 'bundler/setup'",
388
395
  'Bundler.require(:default, :development)',
389
396
  ]
@@ -412,9 +419,9 @@ class Scaffold
412
419
 
413
420
  if shell_type == :gem
414
421
  custom_shell_file_content += <<-MULTI_LINE_STRING
415
- GEM_ROOT = File.expand_path('../../../..', __FILE__)
416
- VERSION = File.read(File.join(GEM_ROOT, 'VERSION'))
417
- LICENSE = File.read(File.join(GEM_ROOT, 'LICENSE.txt'))
422
+ APP_ROOT = File.expand_path('../../../..', __FILE__)
423
+ VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
424
+ LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
418
425
 
419
426
  MULTI_LINE_STRING
420
427
  end
@@ -470,6 +477,7 @@ class Scaffold
470
477
  shell {
471
478
  # Replace example content below with custom shell content
472
479
  minimum_size 320, 240
480
+ image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
473
481
  text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
474
482
  grid_layout
475
483
  label(:center) {
@@ -477,6 +485,17 @@ class Scaffold
477
485
  font height: 40
478
486
  layout_data :fill, :center, true, true
479
487
  }
488
+ menu_bar {
489
+ menu {
490
+ text '&File'
491
+ menu_item {
492
+ text 'Preferences...'
493
+ on_widget_selected {
494
+ display_preferences_dialog
495
+ }
496
+ }
497
+ }
498
+ }
480
499
  }
481
500
  }
482
501
  MULTI_LINE_STRING
@@ -5,7 +5,7 @@ module Glimmer
5
5
  module SWT
6
6
  # Proxy for org.eclipse.swt.graphics.Color
7
7
  #
8
- # Invoking `#swt_color` returns the SWT color object wrapped by this proxy
8
+ # Invoking `#swt_color` returns the SWT Color object wrapped by this proxy
9
9
  #
10
10
  # Follows the Proxy Design Pattern
11
11
  class ColorProxy
@@ -0,0 +1,45 @@
1
+ require 'glimmer/error'
2
+ require 'glimmer/swt/swt_proxy'
3
+ require 'glimmer/swt/display_proxy'
4
+
5
+ module Glimmer
6
+ module SWT
7
+ # Proxy for org.eclipse.swt.graphics.Cursor
8
+ #
9
+ # Invoking `#swt_cursor` returns the SWT Cursor object wrapped by this proxy
10
+ #
11
+ # Follows the Proxy Design Pattern
12
+ class CursorProxy
13
+ CURSOR_STYLES = org.eclipse.swt.SWT.constants.select {|c| c.to_s.downcase.start_with?('cursor_')}.map {|c| c.to_s.downcase.sub('cursor_', '').to_sym}
14
+ ERROR_INVALID_CURSOR_STYLE = " is an invalid cursor style! Valid values are #{CURSOR_STYLES.map(&:to_s).join(", ")}"
15
+
16
+ include_package 'org.eclipse.swt.graphics'
17
+
18
+ attr_reader :swt_cursor, :cursor_style
19
+
20
+ # Builds a new CursorProxy from passed in cursor SWT style (e.g. :appstarting, :hand, or :help)
21
+ #
22
+ # Cursor SWT styles are those that begin with "CURSOR_" prefix
23
+ #
24
+ # They are expected to be passed in in short form without the prefix (but would work with the prefix too)
25
+ def initialize(cursor_style)
26
+ @cursor_style = cursor_style
27
+ @cursor_style = SWTProxy.reverse_lookup(@cursor_style).detect { |symbol| symbol.to_s.downcase.start_with?('cursor_') } if cursor_style.is_a?(Integer)
28
+ @cursor_style = @cursor_style.to_s.downcase
29
+ @cursor_style = @cursor_style.sub(/^cursor\_/, '') if @cursor_style.start_with?('cursor_')
30
+ detect_invalid_cursor_style
31
+ @swt_cursor = DisplayProxy.instance.swt_display.get_system_cursor(SWTProxy[swt_style])
32
+ end
33
+
34
+ def swt_style
35
+ @swt_style ||= @cursor_style.upcase.start_with?('CURSOR_') ? @cursor_style : "CURSOR_#{@cursor_style}"
36
+ end
37
+
38
+ private
39
+
40
+ def detect_invalid_cursor_style
41
+ raise Error, cursor_style.to_s + ERROR_INVALID_CURSOR_STYLE unless CURSOR_STYLES.include?(cursor_style.to_s.downcase.to_sym)
42
+ end
43
+ end
44
+ end
45
+ end
@@ -6,11 +6,10 @@ module Glimmer
6
6
  module SWT
7
7
  # Proxy for org.eclipse.swt.graphics.Font
8
8
  #
9
- # This class is meant to be used with WidgetProxy to manipulate
10
- # an SWT widget font.
9
+ # This class can be optionally used with WidgetProxy to manipulate
10
+ # an SWT widget font (reusing its FontData but building a new Font)
11
11
  #
12
- # It is not meant to create new SWT fonts form scratch without
13
- # a widget proxy.
12
+ # Otherwise, if no WidgetProxy is passed to constructor, it builds new FontData
14
13
  #
15
14
  # Invoking `#swt_font` returns the SWT Font object wrapped by this proxy
16
15
  #
@@ -21,7 +20,7 @@ module Glimmer
21
20
 
22
21
  include_package 'org.eclipse.swt.graphics'
23
22
 
24
- attr_reader :widget_proxy, :swt_font
23
+ attr_reader :widget_proxy, :swt_font, :font_properties
25
24
 
26
25
  # Builds a new font proxy from passed in widget_proxy and font_properties hash,
27
26
  #
@@ -31,8 +30,9 @@ module Glimmer
31
30
  #
32
31
  # Style (:style value) can only be one of FontProxy::FONT_STYLES values:
33
32
  # that is :normal, :bold, or :italic
34
- def initialize(widget_proxy, font_properties)
33
+ def initialize(widget_proxy = nil, font_properties)
35
34
  @widget_proxy = widget_proxy
35
+ @font_properties = font_properties
36
36
  detect_invalid_font_property(font_properties)
37
37
  font_properties[:style] = SWTProxy[*font_properties[:style]]
38
38
  font_data_args = [:name, :height, :style].map do |font_property_name|
@@ -57,7 +57,7 @@ module Glimmer
57
57
  private
58
58
 
59
59
  def font_datum
60
- @font_datum ||= @widget_proxy.swt_widget.getFont.getFontData[0]
60
+ @font_datum ||= @widget_proxy ? @widget_proxy.swt_widget.getFont.getFontData[0] : FontData.new
61
61
  end
62
62
 
63
63
  def detect_invalid_font_property(font_properties)
@@ -0,0 +1,56 @@
1
+ module Glimmer
2
+ module SWT
3
+ # Proxy for org.eclipse.swt.graphics.Image
4
+ #
5
+ # Invoking `#swt_image` returns the SWT Image object wrapped by this proxy
6
+ #
7
+ # Follows the Proxy Design Pattern
8
+ class ImageProxy
9
+ include_package 'org.eclipse.swt.graphics'
10
+
11
+ attr_reader :file_path, :jar_file_path, :image_data, :swt_image
12
+
13
+ # Initializes a proxy for an SWT Image object
14
+ #
15
+ # Takes the same args as the SWT Image class
16
+ # Alternatively, takes a file path string or a uri:classloader file path string (generated by JRuby when invoking `File.expand_path` inside a JAR file)
17
+ # and returns an image object.
18
+ def initialize(*args)
19
+ @args = args
20
+ @file_path = @args.first if @args.first.is_a?(String) && @args.size == 1
21
+ if @file_path
22
+ if @file_path.start_with?('uri:classloader')
23
+ @jar_file_path = @file_path
24
+ @file_path = @jar_file_path.sub(/^uri\:classloader\:/, '').sub('//', '/') # the latter sub is needed for Mac
25
+ object = java.lang.Object.new
26
+ file_input_stream = object.java_class.resource_as_stream(file_path)
27
+ buffered_file_input_stream = java.io.BufferedInputStream.new(file_input_stream)
28
+ end
29
+ @image_data = ImageData.new(buffered_file_input_stream || @file_path)
30
+ @swt_image = Image.new(DisplayProxy.instance.swt_display, @image_data)
31
+ else
32
+ @swt_image = Image.new(*@args)
33
+ @image_data = @swt_image.image_data
34
+ end
35
+ end
36
+
37
+ def scale_to(width, height)
38
+ scaled_image_data = image_data.scaledTo(width, height)
39
+ device = swt_image.device
40
+ swt_image.dispose
41
+ @swt_image = Image.new(device, scaled_image_data)
42
+ end
43
+
44
+ def method_missing(method, *args, &block)
45
+ swt_image.send(method, *args, &block)
46
+ rescue => e
47
+ Glimmer::Config.logger.debug {"Neither ImageProxy nor #{swt_image.class.name} can handle the method ##{method}"}
48
+ super
49
+ end
50
+
51
+ def respond_to?(method, *args, &block)
52
+ super || swt_image.respond_to?(method, *args, &block)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -45,6 +45,8 @@ module Glimmer
45
45
  @widget_proxy = widget_proxy
46
46
  args = SWTProxy.constantify_args(args)
47
47
  @swt_layout = self.class.swt_layout_class_for(underscored_layout_name).new(*args)
48
+ @swt_layout.marginWidth = 15 if @swt_layout.respond_to?(:marginWidth)
49
+ @swt_layout.marginHeight = 15 if @swt_layout.respond_to?(:marginHeight)
48
50
  @widget_proxy.swt_widget.setLayout(@swt_layout)
49
51
  end
50
52
 
@@ -1,21 +1,16 @@
1
1
  require 'glimmer/swt/widget_proxy'
2
+ require 'glimmer/swt/swt_proxy'
2
3
 
3
4
  module Glimmer
4
5
  module SWT
5
- class ScrolledCompositeProxy < Glimmer::SWT::WidgetProxy
6
- def initialize(underscored_widget_name, parent, args)
7
- unless args.first.is_a?(Numeric)
8
- args.unshift(:h_scroll)
9
- args.unshift(:v_scroll)
10
- end
11
- super
12
- swt_widget.expand_horizontal = true
13
- swt_widget.expand_vertical = true
14
- end
15
-
6
+ class ScrolledCompositeProxy < Glimmer::SWT::WidgetProxy
16
7
  def post_initialize_child(child)
17
8
  swt_widget.content = child.swt_widget
18
9
  end
10
+
11
+ def post_add_content
12
+ swt_widget.set_min_size(swt_widget.computeSize(SWTProxy[:default], SWTProxy[:default]))
13
+ end
19
14
  end
20
15
  end
21
16
  end
@@ -130,7 +130,7 @@ module Glimmer
130
130
  begin
131
131
  @display.sleep unless @display.readAndDispatch
132
132
  rescue => e
133
- Glimmer::Config.logger.debug {e.full_message}
133
+ Glimmer::Config.logger.info {e.full_message}
134
134
  end
135
135
  end
136
136
  end
@@ -106,7 +106,17 @@ module Glimmer
106
106
  def deconstruct(integer)
107
107
  constant_source_class.constants.reduce([]) do |found, c|
108
108
  constant_value = constant_source_class.const_get(c) rescue -1
109
- is_found = constant_value.is_a?(Integer) && (constant_value & integer) == constant_value
109
+ is_found = constant_value.is_a?(Integer) && (integer & constant_value) == integer
110
+ is_found ? found += [c] : found
111
+ end
112
+ end
113
+
114
+ # Reverse engineer a style integer into a symbol
115
+ # Useful for debugging
116
+ def reverse_lookup(integer)
117
+ constant_source_class.constants.reduce([]) do |found, c|
118
+ constant_value = constant_source_class.const_get(c) rescue -1
119
+ is_found = constant_value.is_a?(Integer) && integer == constant_value
110
120
  is_found ? found += [c] : found
111
121
  end
112
122
  end
@@ -3,6 +3,7 @@ require 'glimmer/swt/color_proxy'
3
3
  require 'glimmer/swt/font_proxy'
4
4
  require 'glimmer/swt/swt_proxy'
5
5
  require 'glimmer/swt/dnd_proxy'
6
+ require 'glimmer/swt/image_proxy'
6
7
 
7
8
  # TODO refactor to make file smaller and extract sub-widget-proxies out of this
8
9
 
@@ -21,21 +22,39 @@ module Glimmer
21
22
  include Packages
22
23
 
23
24
  DEFAULT_STYLES = {
24
- "text" => [:border],
25
- "table" => [:virtual, :border, :full_selection],
26
- "tree" => [:virtual, :border, :h_scroll, :v_scroll],
27
- "spinner" => [:border],
28
- "styled_text" => [:border],
29
- "list" => [:border, :v_scroll],
30
- "button" => [:push],
31
- "menu_item" => [:push],
32
- "drag_source" => [:drop_copy],
33
- "drop_target" => [:drop_copy],
25
+ "arrow" => [:arrow],
26
+ "button" => [:push],
27
+ "checkbox" => [:check],
28
+ "drag_source" => [:drop_copy],
29
+ "drop_target" => [:drop_copy],
30
+ "list" => [:border, :v_scroll],
31
+ "menu_item" => [:push],
32
+ "radio" => [:radio],
33
+ "scrolled_composite" => [:border, :h_scroll, :v_scroll],
34
+ "spinner" => [:border],
35
+ "styled_text" => [:border],
36
+ "table" => [:virtual, :border, :full_selection],
37
+ "text" => [:border],
38
+ "toggle" => [:toggle],
39
+ "tree" => [:virtual, :border, :h_scroll, :v_scroll],
34
40
  }
35
41
 
36
42
  DEFAULT_INITIALIZERS = {
37
43
  "composite" => lambda do |composite|
38
- composite.setLayout(GridLayout.new)
44
+ layout = GridLayout.new
45
+ layout.marginWidth = 15
46
+ layout.marginHeight = 15
47
+ composite.layout = layout
48
+ end,
49
+ "scrolled_composite" => lambda do |scrolled_composite|
50
+ scrolled_composite.expand_horizontal = true
51
+ scrolled_composite.expand_vertical = true
52
+ end,
53
+ "shell" => lambda do |shell|
54
+ layout = FillLayout.new
55
+ layout.marginWidth = 15
56
+ layout.marginHeight = 15
57
+ shell.layout = layout
39
58
  end,
40
59
  "table" => lambda do |table|
41
60
  table.setHeaderVisible(true)
@@ -49,18 +68,19 @@ module Glimmer
49
68
  end,
50
69
  }
51
70
 
52
- attr_reader :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
71
+ attr_reader :parent_proxy, :swt_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
53
72
 
54
73
  # Initializes a new SWT Widget
55
74
  #
56
75
  # Styles is a comma separate list of symbols representing SWT styles in lower case
57
76
  def initialize(underscored_widget_name, parent, args)
77
+ @parent_proxy = parent
58
78
  styles, extra_options = extract_args(underscored_widget_name, args)
59
79
  swt_widget_class = self.class.swt_widget_class_for(underscored_widget_name)
60
- @swt_widget = swt_widget_class.new(parent.swt_widget, style(underscored_widget_name, styles), *extra_options)
80
+ @swt_widget = swt_widget_class.new(@parent_proxy.swt_widget, style(underscored_widget_name, styles), *extra_options)
61
81
  @swt_widget.set_data('proxy', self)
62
82
  DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@swt_widget)
63
- parent.post_initialize_child(self)
83
+ @parent_proxy.post_initialize_child(self)
64
84
  end
65
85
 
66
86
  # Subclasses may override to perform post initialization work on an added child
@@ -68,6 +88,11 @@ module Glimmer
68
88
  # No Op by default
69
89
  end
70
90
 
91
+ # Subclasses may override to perform post add_content work
92
+ def post_add_content
93
+ # No Op by default
94
+ end
95
+
71
96
  def extract_args(underscored_widget_name, args)
72
97
  @arg_extractor_mapping ||= {
73
98
  'menu_item' => lambda do |args|
@@ -263,6 +288,7 @@ module Glimmer
263
288
 
264
289
  # This supports widgets in and out of basic SWT
265
290
  def self.swt_widget_class_for(underscored_widget_name)
291
+ underscored_widget_name = 'button' if %w[radio checkbox toggle arrow].include?(underscored_widget_name)
266
292
  swt_widget_name = underscored_widget_name.camelcase(:upper)
267
293
  swt_widget_class = eval(swt_widget_name)
268
294
  unless swt_widget_class.ancestors.include?(org.eclipse.swt.widgets.Widget)
@@ -590,25 +616,31 @@ module Glimmer
590
616
  @property_type_converters ||= {
591
617
  :background => color_converter,
592
618
  :background_image => lambda do |value|
619
+ image_proxy = nil
593
620
  if value.is_a?(String)
594
- if value.start_with?('uri:classloader')
595
- value = value.sub(/^uri\:classloader\:/, '')
596
- object = java.lang.Object.new
597
- value = object.java_class.resource_as_stream(value)
598
- value = java.io.BufferedInputStream.new(value)
599
- end
600
- image_data = ImageData.new(value)
601
- # TODO in the future, look into unregistering this listener when no longer needed
621
+ image_proxy = ImageProxy.new(value)
622
+ elsif value.is_a?(Array)
623
+ image_proxy = ImageProxy.new(*value)
624
+ end
625
+ if image_proxy
602
626
  on_swt_Resize do |resize_event|
603
- new_image_data = image_data.scaledTo(@swt_widget.getSize.x, @swt_widget.getSize.y)
604
- @swt_widget.getBackgroundImage&.dispose
605
- @swt_widget.setBackgroundImage(Image.new(@swt_widget.getDisplay, new_image_data))
627
+ image_proxy.scale_to(@swt_widget.getSize.x, @swt_widget.getSize.y)
628
+ @swt_widget.setBackgroundImage(image_proxy.swt_image)
606
629
  end
607
- Image.new(@swt_widget.getDisplay, image_data)
630
+ image_proxy.swt_image
608
631
  else
609
632
  value
610
633
  end
611
634
  end,
635
+ :cursor => lambda do |value|
636
+ cursor_proxy = nil
637
+ if value.is_a?(CursorProxy)
638
+ cursor_proxy = value
639
+ elsif value.is_a?(Symbol) || value.is_a?(String) || value.is_a?(Integer)
640
+ cursor_proxy = CursorProxy.new(value)
641
+ end
642
+ cursor_proxy ? cursor_proxy.swt_cursor : value
643
+ end,
612
644
  :foreground => color_converter,
613
645
  :font => lambda do |value|
614
646
  if value.is_a?(Hash)
@@ -620,14 +652,9 @@ module Glimmer
620
652
  end,
621
653
  :image => lambda do |value|
622
654
  if value.is_a?(String)
623
- if value.start_with?('uri:classloader')
624
- value = value.sub(/^uri\:classloader\:/, '')
625
- object = java.lang.Object.new
626
- value = object.java_class.resource_as_stream(value)
627
- value = java.io.BufferedInputStream.new(value)
628
- end
629
- image_data = ImageData.new(value)
630
- Image.new(@swt_widget.getDisplay, image_data)
655
+ ImageProxy.new(value).swt_image
656
+ elsif value.is_a?(Array)
657
+ ImageProxy.new(*value).swt_image
631
658
  else
632
659
  value
633
660
  end
@@ -635,14 +662,9 @@ module Glimmer
635
662
  :images => lambda do |array|
636
663
  array.to_a.map do |value|
637
664
  if value.is_a?(String)
638
- if value.start_with?('uri:classloader')
639
- value = value.sub(/^uri\:classloader\:/, '')
640
- object = java.lang.Object.new
641
- value = object.java_class.resource_as_stream(value)
642
- value = java.io.BufferedInputStream.new(value)
643
- end
644
- image_data = ImageData.new(value)
645
- Image.new(@swt_widget.getDisplay, image_data)
665
+ ImageProxy.new(value).swt_image
666
+ elsif value.is_a?(Array)
667
+ ImageProxy.new(*value).swt_image
646
668
  else
647
669
  value
648
670
  end
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glimmer-dsl-swt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - AndyMaleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '='
73
+ - !ruby/object:Gem::Version
74
+ version: 1.7.0
75
+ name: git-glimmer
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.7.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  requirement: !ruby/object:Gem::Requirement
71
85
  requirements:
@@ -294,6 +308,7 @@ files:
294
308
  - bin/girb_runner.rb
295
309
  - bin/glimmer
296
310
  - icons/scaffold_app.icns
311
+ - icons/scaffold_app.ico
297
312
  - lib/ext/glimmer.rb
298
313
  - lib/ext/glimmer/config.rb
299
314
  - lib/glimmer-dsl-swt.rb
@@ -309,6 +324,7 @@ files:
309
324
  - lib/glimmer/dsl/swt/color_expression.rb
310
325
  - lib/glimmer/dsl/swt/column_properties_expression.rb
311
326
  - lib/glimmer/dsl/swt/combo_selection_data_binding_expression.rb
327
+ - lib/glimmer/dsl/swt/cursor_expression.rb
312
328
  - lib/glimmer/dsl/swt/custom_widget_expression.rb
313
329
  - lib/glimmer/dsl/swt/data_binding_expression.rb
314
330
  - lib/glimmer/dsl/swt/dialog_expression.rb
@@ -316,6 +332,8 @@ files:
316
332
  - lib/glimmer/dsl/swt/dnd_expression.rb
317
333
  - lib/glimmer/dsl/swt/dsl.rb
318
334
  - lib/glimmer/dsl/swt/exec_expression.rb
335
+ - lib/glimmer/dsl/swt/font_expression.rb
336
+ - lib/glimmer/dsl/swt/image_expression.rb
319
337
  - lib/glimmer/dsl/swt/layout_data_expression.rb
320
338
  - lib/glimmer/dsl/swt/layout_expression.rb
321
339
  - lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb
@@ -341,9 +359,11 @@ files:
341
359
  - lib/glimmer/rake_task/list.rb
342
360
  - lib/glimmer/scaffold.rb
343
361
  - lib/glimmer/swt/color_proxy.rb
362
+ - lib/glimmer/swt/cursor_proxy.rb
344
363
  - lib/glimmer/swt/display_proxy.rb
345
364
  - lib/glimmer/swt/dnd_proxy.rb
346
365
  - lib/glimmer/swt/font_proxy.rb
366
+ - lib/glimmer/swt/image_proxy.rb
347
367
  - lib/glimmer/swt/layout_data_proxy.rb
348
368
  - lib/glimmer/swt/layout_proxy.rb
349
369
  - lib/glimmer/swt/menu_proxy.rb