glimmer-dsl-swt 0.5.3 → 0.6.1

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: 7ce0b74d98304d4ef0a093bf6dcd2a05612f4e437a4468307bf04bb98751bd67
4
- data.tar.gz: 16624ff216b60f6448d624a778e021115a9bd83c548a9dd9e637f40693d33641
3
+ metadata.gz: 470667c11a2cadd8113d2067cffbf7db92647712dab8367a5b71ce0cbb990c02
4
+ data.tar.gz: 634143f2c4adbe46aeb5b09cbf373b20d1e513584fbfc405ceb5d74212d7ffd1
5
5
  SHA512:
6
- metadata.gz: eec38142ade569bc1bcca40d075ef64f8be649df9b0322fedbcd1c0e9df4b1ee481b878489531ebbee74d6b8f23c160e64cbac732f15fb850365ce352ecdc45b
7
- data.tar.gz: e24d03c58b50294cfef56300f7bcfb2371856be1ff22f4c81ffb6089455d8f99b2a3df7e4b0e0cc9628ffd0a241297167b3a4898a54014bb5fc894cce63a33a1
6
+ metadata.gz: cbe32cbaf2d2f2bc7670a982abbaac8c490f41b307a2500b08158aa30bc775425d29be576411ef9618e0a3c9cc1118913f2017b4374c90e70fb196dd76beff95
7
+ data.tar.gz: 6656c29c0221adc159007c3e8f728e355d8d5cb8dbe193d049e5e24d4da0b53c30525e2ee79fc5b303be3d0e2787bc890321d0b83ca0d1783052f680e3f3fefd
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.3 (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.1 (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.3
1
+ 0.6.1
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,26 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/dsl/top_level_expression'
3
+ require 'glimmer/swt/cursor_proxy'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module SWT
8
+ # cursor expression
9
+ # Note: Cannot be a static expression because it clashes with cursor property expression
10
+ class CursorExpression < Expression
11
+ include TopLevelExpression
12
+
13
+ def can_interpret?(parent, keyword, *args, &block)
14
+ keyword.to_s == 'cursor' and
15
+ (parent.nil? or !parent.respond_to?('cursor')) and
16
+ args.size == 1 and
17
+ (args.first.is_a?(Integer) or textual?(args.first))
18
+ end
19
+
20
+ def interpret(parent, keyword, *args, &block)
21
+ Glimmer::SWT::CursorProxy.new(*args)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -24,6 +24,8 @@ module Glimmer
24
24
  tree_items_data_binding
25
25
  table_items_data_binding
26
26
  data_binding
27
+ cursor
28
+ font
27
29
  property
28
30
  block_property
29
31
  widget
@@ -0,0 +1,24 @@
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')) && args.size == 1 && args.first.is_a?(Hash)
16
+ end
17
+
18
+ def interpret(parent, keyword, *args, &block)
19
+ Glimmer::SWT::FontProxy.new(*args)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ 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,63 @@
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 :jar_file_path, :image_data
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
+ @jar_file_path = @args.first if @args.first.is_a?(String) && @args.size == 1
21
+
22
+ end
23
+
24
+ def swt_image
25
+ unless @swt_image
26
+ if @jar_file_path
27
+ file_path = @jar_file_path
28
+ if file_path.start_with?('uri:classloader')
29
+ file_path = file_path.sub(/^uri\:classloader\:/, '').sub('//', '/') # the latter sub is needed for Mac
30
+ object = java.lang.Object.new
31
+ file_input_stream = object.java_class.resource_as_stream(file_path)
32
+ buffered_file_input_stream = java.io.BufferedInputStream.new(file_input_stream)
33
+ end
34
+ @image_data = ImageData.new(buffered_file_input_stream || file_path)
35
+ @swt_image = Image.new(DisplayProxy.instance.swt_display, @image_data)
36
+ else
37
+ @swt_image = Image.new(*@args)
38
+ end
39
+ end
40
+ @swt_image
41
+ end
42
+
43
+ def scale_to(width, height)
44
+ return @swt_image if image_data.nil?
45
+ scaled_image_data = image_data.scaledTo(width, height)
46
+ device = swt_image.device
47
+ swt_image.dispose
48
+ @swt_image = Image.new(device, scaled_image_data)
49
+ end
50
+
51
+ def method_missing(method, *args, &block)
52
+ swt_image.send(method, *args, &block)
53
+ rescue => e
54
+ Glimmer::Config.logger.debug {"Neither ImageProxy nor #{swt_image.class.name} can handle the method ##{method}"}
55
+ super
56
+ end
57
+
58
+ def respond_to?(method, *args, &block)
59
+ super || swt_image.respond_to?(method, *args, &block)
60
+ end
61
+ end
62
+ end
63
+ 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
 
@@ -590,25 +591,31 @@ module Glimmer
590
591
  @property_type_converters ||= {
591
592
  :background => color_converter,
592
593
  :background_image => lambda do |value|
594
+ image_proxy = nil
593
595
  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
596
+ image_proxy = ImageProxy.new(value)
597
+ elsif value.is_a?(Array)
598
+ image_proxy = ImageProxy.new(*value)
599
+ end
600
+ if image_proxy
602
601
  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))
602
+ image_proxy.scale_to(@swt_widget.getSize.x, @swt_widget.getSize.y)
603
+ @swt_widget.setBackgroundImage(image_proxy.swt_image)
606
604
  end
607
- Image.new(@swt_widget.getDisplay, image_data)
605
+ image_proxy.swt_image
608
606
  else
609
607
  value
610
608
  end
611
609
  end,
610
+ :cursor => lambda do |value|
611
+ cursor_proxy = nil
612
+ if value.is_a?(CursorProxy)
613
+ cursor_proxy = value
614
+ elsif value.is_a?(Symbol) || value.is_a?(String) || value.is_a?(Integer)
615
+ cursor_proxy = CursorProxy.new(value)
616
+ end
617
+ cursor_proxy ? cursor_proxy.swt_cursor : value
618
+ end,
612
619
  :foreground => color_converter,
613
620
  :font => lambda do |value|
614
621
  if value.is_a?(Hash)
@@ -620,14 +627,9 @@ module Glimmer
620
627
  end,
621
628
  :image => lambda do |value|
622
629
  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)
630
+ ImageProxy.new(value).swt_image
631
+ elsif value.is_a?(Array)
632
+ ImageProxy.new(*value).swt_image
631
633
  else
632
634
  value
633
635
  end
@@ -635,14 +637,9 @@ module Glimmer
635
637
  :images => lambda do |array|
636
638
  array.to_a.map do |value|
637
639
  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)
640
+ ImageProxy.new(value).swt_image
641
+ elsif value.is_a?(Array)
642
+ ImageProxy.new(*value).swt_image
646
643
  else
647
644
  value
648
645
  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.3
4
+ version: 0.6.1
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-28 00:00:00.000000000 Z
11
+ date: 2020-08-06 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,7 @@ 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
319
336
  - lib/glimmer/dsl/swt/layout_data_expression.rb
320
337
  - lib/glimmer/dsl/swt/layout_expression.rb
321
338
  - lib/glimmer/dsl/swt/list_selection_data_binding_expression.rb
@@ -341,9 +358,11 @@ files:
341
358
  - lib/glimmer/rake_task/list.rb
342
359
  - lib/glimmer/scaffold.rb
343
360
  - lib/glimmer/swt/color_proxy.rb
361
+ - lib/glimmer/swt/cursor_proxy.rb
344
362
  - lib/glimmer/swt/display_proxy.rb
345
363
  - lib/glimmer/swt/dnd_proxy.rb
346
364
  - lib/glimmer/swt/font_proxy.rb
365
+ - lib/glimmer/swt/image_proxy.rb
347
366
  - lib/glimmer/swt/layout_data_proxy.rb
348
367
  - lib/glimmer/swt/layout_proxy.rb
349
368
  - lib/glimmer/swt/menu_proxy.rb