glimmer-dsl-swt 0.5.6 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/RUBY_VERSION +1 -1
- data/VERSION +1 -1
- data/bin/girb +1 -1
- data/bin/glimmer +1 -1
- data/icons/scaffold_app.ico +0 -0
- data/icons/scaffold_app.png +0 -0
- data/lib/ext/glimmer/config.rb +5 -1
- data/lib/glimmer/Rakefile +5 -0
- data/lib/glimmer/dsl/swt/cursor_expression.rb +23 -0
- data/lib/glimmer/dsl/swt/dsl.rb +3 -0
- data/lib/glimmer/dsl/swt/font_expression.rb +26 -0
- data/lib/glimmer/dsl/swt/image_expression.rb +21 -0
- data/lib/glimmer/dsl/swt/message_box_expression.rb +9 -1
- data/lib/glimmer/dsl/swt/widget_expression.rb +7 -7
- data/lib/glimmer/launcher.rb +36 -8
- data/lib/glimmer/package.rb +31 -7
- data/lib/glimmer/rake_task.rb +111 -6
- data/lib/glimmer/scaffold.rb +98 -62
- data/lib/glimmer/swt/cursor_proxy.rb +45 -0
- data/lib/glimmer/swt/display_proxy.rb +13 -2
- data/lib/glimmer/swt/font_proxy.rb +7 -7
- data/lib/glimmer/swt/image_proxy.rb +16 -23
- data/lib/glimmer/swt/layout_proxy.rb +2 -0
- data/lib/glimmer/swt/message_box_proxy.rb +23 -5
- data/lib/glimmer/swt/scrolled_composite_proxy.rb +6 -11
- data/lib/glimmer/swt/style_constantizable.rb +11 -1
- data/lib/glimmer/swt/table_proxy.rb +50 -2
- data/lib/glimmer/swt/widget_proxy.rb +79 -18
- data/samples/elaborate/contact_manager.rb +121 -0
- data/samples/elaborate/contact_manager/contact.rb +11 -0
- data/samples/elaborate/contact_manager/contact_manager_presenter.rb +26 -0
- data/samples/elaborate/contact_manager/contact_repository.rb +244 -0
- data/samples/elaborate/login.rb +108 -0
- data/samples/elaborate/tic_tac_toe.rb +55 -0
- data/samples/elaborate/tic_tac_toe/board.rb +124 -0
- data/samples/elaborate/tic_tac_toe/cell.rb +27 -0
- data/samples/hello/hello_browser.rb +8 -0
- data/samples/hello/hello_combo.rb +38 -0
- data/samples/hello/hello_computed.rb +69 -0
- data/samples/hello/hello_computed/contact.rb +21 -0
- data/samples/hello/hello_drag_and_drop.rb +29 -0
- data/samples/hello/hello_list_multi_selection.rb +48 -0
- data/samples/hello/hello_list_single_selection.rb +37 -0
- data/samples/hello/hello_menu_bar.rb +64 -0
- data/samples/hello/hello_message_box.rb +15 -0
- data/samples/hello/hello_pop_up_context_menu.rb +36 -0
- data/samples/hello/hello_tab.rb +24 -0
- data/samples/hello/hello_world.rb +8 -0
- data/vendor/swt/linux/swt.jar +0 -0
- data/vendor/swt/mac/swt.jar +0 -0
- data/vendor/swt/windows/swt.jar +0 -0
- metadata +48 -7
data/lib/glimmer/scaffold.rb
CHANGED
@@ -73,24 +73,11 @@ class Scaffold
|
|
73
73
|
|
74
74
|
# Glimmer
|
75
75
|
dist
|
76
|
-
packages
|
76
|
+
packages
|
77
|
+
vendor/jars
|
77
78
|
MULTI_LINE_STRING
|
78
79
|
|
79
|
-
|
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
|
80
|
+
GEMFILE = <<~MULTI_LINE_STRING
|
94
81
|
# frozen_string_literal: true
|
95
82
|
|
96
83
|
source 'https://rubygems.org'
|
@@ -101,24 +88,12 @@ class Scaffold
|
|
101
88
|
|
102
89
|
group :development do
|
103
90
|
gem 'rspec', '~> 3.5.0'
|
91
|
+
gem 'git-glimmer', '1.7.0'
|
104
92
|
gem 'jeweler', '2.3.9'
|
105
93
|
gem 'simplecov', '>= 0'
|
106
94
|
end
|
107
95
|
MULTI_LINE_STRING
|
108
96
|
|
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
97
|
RVM_FUNCTION = <<~MULTI_LINE_STRING
|
123
98
|
# Load RVM into a shell session *as a function*
|
124
99
|
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
|
@@ -135,31 +110,54 @@ class Scaffold
|
|
135
110
|
MULTI_LINE_STRING
|
136
111
|
|
137
112
|
def app(app_name)
|
138
|
-
|
139
|
-
|
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',
|
146
|
-
write '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
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
130
|
+
|
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
|
+
|
136
|
+
mkdir_p 'package/macosx'
|
137
|
+
icon_file = "package/macosx/#{human_name(app_name)}.icns"
|
138
|
+
cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
|
139
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
140
|
+
|
141
|
+
mkdir_p 'package/linux'
|
142
|
+
icon_file = "package/linux/#{human_name(app_name)}.png"
|
143
|
+
cp File.expand_path('../../../icons/scaffold_app.png', __FILE__), icon_file
|
144
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
145
|
+
|
158
146
|
mkdir 'bin'
|
159
147
|
write "bin/#{file_name(app_name)}", app_bin_file(app_name)
|
160
|
-
|
161
|
-
|
162
|
-
|
148
|
+
write 'spec/spec_helper.rb', spec_helper_file
|
149
|
+
if OS.windows?
|
150
|
+
system "bundle"
|
151
|
+
system "glimmer package[image]"
|
152
|
+
system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
|
153
|
+
else
|
154
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
|
155
|
+
if OS.mac?
|
156
|
+
system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
|
157
|
+
else
|
158
|
+
system "glimmer bin/#{file_name(app_name)}"
|
159
|
+
end
|
160
|
+
end
|
163
161
|
end
|
164
162
|
|
165
163
|
def custom_shell(custom_shell_name, namespace, shell_type = nil)
|
@@ -179,22 +177,22 @@ class Scaffold
|
|
179
177
|
end
|
180
178
|
|
181
179
|
def custom_shell_gem(custom_shell_name, namespace)
|
182
|
-
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'
|
183
180
|
gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
|
184
181
|
gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
|
185
182
|
if namespace
|
186
183
|
gem_name += "-#{compact_name(namespace)}"
|
187
184
|
gem_summary += " (#{human_name(namespace)})"
|
188
185
|
else
|
186
|
+
return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
|
189
187
|
namespace = 'glimmer'
|
190
188
|
end
|
191
|
-
system "jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
|
189
|
+
system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
|
192
190
|
cd gem_name
|
193
191
|
write '.gitignore', GITIGNORE
|
194
192
|
write '.ruby-version', RUBY_VERSION
|
195
193
|
write '.ruby-gemset', gem_name
|
196
194
|
write 'VERSION', '1.0.0'
|
197
|
-
write 'Gemfile',
|
195
|
+
write 'Gemfile', GEMFILE
|
198
196
|
write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
|
199
197
|
append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
|
200
198
|
mkdir 'lib/views'
|
@@ -203,14 +201,35 @@ class Scaffold
|
|
203
201
|
write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
|
204
202
|
write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
|
205
203
|
FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
204
|
+
write 'spec/spec_helper.rb', spec_helper_file
|
205
|
+
|
206
|
+
mkdir_p 'package/windows'
|
207
|
+
icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
|
208
|
+
cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
|
209
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
210
|
+
|
211
|
+
mkdir_p 'package/macosx'
|
212
|
+
icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
|
213
|
+
cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
|
214
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
215
|
+
|
216
|
+
mkdir_p 'package/linux'
|
217
|
+
icon_file = "package/linux/#{human_name(custom_shell_name)}.png"
|
218
|
+
cp File.expand_path('../../../icons/scaffold_app.png', __FILE__), icon_file
|
219
|
+
puts "Created #{current_dir_name}/#{icon_file}"
|
220
|
+
|
221
|
+
if OS.windows?
|
222
|
+
system "bundle"
|
223
|
+
system "glimmer package[image]"
|
224
|
+
system "\"packages/bundles/#{human_name(custom_shell_name)}/#{human_name(custom_shell_name)}.exe\""
|
225
|
+
else
|
226
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
|
227
|
+
if OS.mac?
|
228
|
+
system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" if OS.mac?
|
229
|
+
else
|
230
|
+
system "bin/#{file_name(custom_shell_name)}"
|
231
|
+
end
|
211
232
|
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"
|
214
233
|
puts "Finished creating #{gem_name} Ruby gem."
|
215
234
|
puts 'Edit Rakefile to configure gem details.'
|
216
235
|
puts 'Run `rake` to execute specs.'
|
@@ -228,19 +247,23 @@ class Scaffold
|
|
228
247
|
else
|
229
248
|
namespace = 'glimmer'
|
230
249
|
end
|
231
|
-
system "jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
|
250
|
+
system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
|
232
251
|
cd gem_name
|
233
252
|
write '.gitignore', GITIGNORE
|
234
253
|
write '.ruby-version', RUBY_VERSION
|
235
254
|
write '.ruby-gemset', gem_name
|
236
255
|
write 'VERSION', '1.0.0'
|
237
|
-
write 'Gemfile',
|
256
|
+
write 'Gemfile', GEMFILE
|
238
257
|
write 'Rakefile', gem_rakefile
|
239
258
|
write 'spec/spec_helper.rb', spec_helper_file
|
240
259
|
append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
|
241
260
|
mkdir 'lib/views'
|
242
261
|
custom_widget(custom_widget_name, namespace)
|
243
|
-
|
262
|
+
if OS.windows?
|
263
|
+
system "bundle"
|
264
|
+
else
|
265
|
+
system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
|
266
|
+
end
|
244
267
|
puts "Finished creating #{gem_name} Ruby gem."
|
245
268
|
puts 'Edit Rakefile to configure gem details.'
|
246
269
|
puts 'Run `rake` to execute specs.'
|
@@ -338,7 +361,7 @@ class Scaffold
|
|
338
361
|
|
339
362
|
def gem_bin_command_file(gem_name)
|
340
363
|
<<~MULTI_LINE_STRING
|
341
|
-
#!/usr/bin/env
|
364
|
+
#!/usr/bin/env jruby
|
342
365
|
|
343
366
|
require 'glimmer/launcher'
|
344
367
|
|
@@ -355,10 +378,11 @@ class Scaffold
|
|
355
378
|
lines.insert(require_rake_line_index, "require 'glimmer/launcher'")
|
356
379
|
gem_files_line_index = lines.index(lines.detect {|l| l.include?('# dependencies defined in Gemfile') })
|
357
380
|
if custom_shell_name
|
358
|
-
lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib
|
381
|
+
lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*', 'app/**/*', 'bin/**/*', 'vendor/**/*', 'package/**/*']")
|
359
382
|
lines.insert(gem_files_line_index+1, " gem.executables = ['#{gem_name}', '#{file_name(custom_shell_name)}']")
|
383
|
+
lines.insert(gem_files_line_index+2, " gem.require_paths = ['vendor', 'lib', 'app']")
|
360
384
|
else
|
361
|
-
lines.insert(gem_files_line_index, " gem.files = Dir['lib
|
385
|
+
lines.insert(gem_files_line_index, " gem.files = Dir['VERSION', 'LICENSE.txt', 'lib/**/*']")
|
362
386
|
end
|
363
387
|
spec_pattern_line_index = lines.index(lines.detect {|l| l.include?('spec.pattern =') })
|
364
388
|
lines.insert(spec_pattern_line_index+1, " spec.ruby_opts = [Glimmer::Launcher.jruby_swt_options]")
|
@@ -383,7 +407,7 @@ class Scaffold
|
|
383
407
|
content = File.read('spec/spec_helper.rb')
|
384
408
|
lines = content.split("\n")
|
385
409
|
require_line_index = lines.index(lines.detect {|l| l.include?(current_dir_name) })
|
386
|
-
lines[require_line_index
|
410
|
+
lines[require_line_index..require_line_index] = [
|
387
411
|
"require 'bundler/setup'",
|
388
412
|
'Bundler.require(:default, :development)',
|
389
413
|
]
|
@@ -412,9 +436,9 @@ class Scaffold
|
|
412
436
|
|
413
437
|
if shell_type == :gem
|
414
438
|
custom_shell_file_content += <<-MULTI_LINE_STRING
|
415
|
-
|
416
|
-
VERSION = File.read(File.join(
|
417
|
-
LICENSE = File.read(File.join(
|
439
|
+
APP_ROOT = File.expand_path('../../../..', __FILE__)
|
440
|
+
VERSION = File.read(File.join(APP_ROOT, 'VERSION'))
|
441
|
+
LICENSE = File.read(File.join(APP_ROOT, 'LICENSE.txt'))
|
418
442
|
|
419
443
|
MULTI_LINE_STRING
|
420
444
|
end
|
@@ -470,6 +494,7 @@ class Scaffold
|
|
470
494
|
shell {
|
471
495
|
# Replace example content below with custom shell content
|
472
496
|
minimum_size 320, 240
|
497
|
+
image File.join(APP_ROOT, 'package', 'windows', "#{human_name(shell_type == :gem ? custom_shell_name : current_dir_name)}.ico") if OS.windows?
|
473
498
|
text "#{human_name(namespace)} - #{human_name(custom_shell_name)}"
|
474
499
|
grid_layout
|
475
500
|
label(:center) {
|
@@ -477,6 +502,17 @@ class Scaffold
|
|
477
502
|
font height: 40
|
478
503
|
layout_data :fill, :center, true, true
|
479
504
|
}
|
505
|
+
menu_bar {
|
506
|
+
menu {
|
507
|
+
text '&File'
|
508
|
+
menu_item {
|
509
|
+
text '&Preferences...'
|
510
|
+
on_widget_selected {
|
511
|
+
display_preferences_dialog
|
512
|
+
}
|
513
|
+
}
|
514
|
+
}
|
515
|
+
}
|
480
516
|
}
|
481
517
|
}
|
482
518
|
MULTI_LINE_STRING
|
@@ -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
|
@@ -35,16 +35,26 @@ module Glimmer
|
|
35
35
|
@swt_display = Display.new(*args)
|
36
36
|
@swt_display.set_data('proxy', self)
|
37
37
|
end
|
38
|
+
|
39
|
+
def content(&block)
|
40
|
+
Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::DisplayExpression.new, &block)
|
41
|
+
end
|
38
42
|
|
39
43
|
def method_missing(method, *args, &block)
|
40
|
-
|
44
|
+
if can_handle_observation_request?(method)
|
45
|
+
handle_observation_request(method, &block)
|
46
|
+
else
|
47
|
+
swt_display.send(method, *args, &block)
|
48
|
+
end
|
41
49
|
rescue => e
|
42
50
|
Glimmer::Config.logger.debug {"Neither DisplayProxy nor #{swt_display.class.name} can handle the method ##{method}"}
|
43
51
|
super
|
44
52
|
end
|
45
53
|
|
46
54
|
def respond_to?(method, *args, &block)
|
47
|
-
super ||
|
55
|
+
super ||
|
56
|
+
can_handle_observation_request?(method) ||
|
57
|
+
swt_display.respond_to?(method, *args, &block)
|
48
58
|
end
|
49
59
|
|
50
60
|
def can_handle_observation_request?(observation_request)
|
@@ -61,6 +71,7 @@ module Glimmer
|
|
61
71
|
end
|
62
72
|
|
63
73
|
def handle_observation_request(observation_request, &block)
|
74
|
+
observation_request = observation_request.to_s
|
64
75
|
if observation_request.start_with?('on_swt_')
|
65
76
|
constant_name = observation_request.sub(/^on_swt_/, '')
|
66
77
|
add_swt_event_listener(constant_name, &block)
|
@@ -6,11 +6,10 @@ module Glimmer
|
|
6
6
|
module SWT
|
7
7
|
# Proxy for org.eclipse.swt.graphics.Font
|
8
8
|
#
|
9
|
-
# This class
|
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
|
-
#
|
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)
|
@@ -8,7 +8,7 @@ module Glimmer
|
|
8
8
|
class ImageProxy
|
9
9
|
include_package 'org.eclipse.swt.graphics'
|
10
10
|
|
11
|
-
attr_reader :jar_file_path, :image_data
|
11
|
+
attr_reader :file_path, :jar_file_path, :image_data, :swt_image
|
12
12
|
|
13
13
|
# Initializes a proxy for an SWT Image object
|
14
14
|
#
|
@@ -17,31 +17,24 @@ module Glimmer
|
|
17
17
|
# and returns an image object.
|
18
18
|
def initialize(*args)
|
19
19
|
@args = args
|
20
|
-
@
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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)
|
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)
|
38
28
|
end
|
39
|
-
|
40
|
-
|
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
|
41
35
|
end
|
42
|
-
|
36
|
+
|
43
37
|
def scale_to(width, height)
|
44
|
-
return @swt_image if image_data.nil?
|
45
38
|
scaled_image_data = image_data.scaledTo(width, height)
|
46
39
|
device = swt_image.device
|
47
40
|
swt_image.dispose
|