shoes-swt 4.0.0.pre3 → 4.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/bin/shoes-swt +2 -2
  3. data/lib/shoes/swt.rb +90 -72
  4. data/lib/shoes/swt/app.rb +5 -0
  5. data/lib/shoes/swt/click_listener.rb +0 -1
  6. data/lib/shoes/swt/color.rb +7 -7
  7. data/lib/shoes/swt/common/fill.rb +9 -3
  8. data/lib/shoes/swt/common/painter.rb +14 -11
  9. data/lib/shoes/swt/common/stroke.rb +9 -3
  10. data/lib/shoes/swt/dialog.rb +2 -2
  11. data/lib/shoes/swt/gradient.rb +13 -11
  12. data/lib/shoes/swt/image.rb +1 -3
  13. data/lib/shoes/swt/image_pattern.rb +2 -2
  14. data/lib/shoes/swt/line.rb +0 -2
  15. data/lib/shoes/swt/list_box.rb +6 -1
  16. data/lib/shoes/swt/progress.rb +9 -8
  17. data/lib/shoes/swt/redrawing_aspect.rb +1 -1
  18. data/lib/shoes/swt/shape.rb +3 -1
  19. data/lib/shoes/swt/shoes_layout.rb +38 -24
  20. data/lib/shoes/swt/text_block.rb +41 -12
  21. data/lib/shoes/swt/text_block/cursor_painter.rb +1 -1
  22. data/lib/shoes/swt/text_block/fitter.rb +8 -3
  23. data/lib/shoes/swt/text_block/painter.rb +9 -28
  24. data/lib/shoes/swt/text_block/text_segment.rb +16 -6
  25. data/lib/shoes/swt/text_block/text_segment_collection.rb +17 -5
  26. data/lib/shoes/swt/tooling/leak_hunter.rb +1 -1
  27. data/lib/shoes/swt/version.rb +1 -1
  28. data/shoes-swt.gemspec +2 -2
  29. data/spec/shoes/cli_spec.rb +1 -1
  30. data/spec/shoes/swt/app_spec.rb +15 -6
  31. data/spec/shoes/swt/color_spec.rb +8 -7
  32. data/spec/shoes/swt/common/painter_spec.rb +30 -5
  33. data/spec/shoes/swt/disposed_protection_spec.rb +0 -1
  34. data/spec/shoes/swt/font_spec.rb +2 -2
  35. data/spec/shoes/swt/gradient_spec.rb +5 -2
  36. data/spec/shoes/swt/image_pattern_spec.rb +11 -1
  37. data/spec/shoes/swt/list_box_spec.rb +24 -4
  38. data/spec/shoes/swt/mouse_move_listener_spec.rb +1 -1
  39. data/spec/shoes/swt/oval_spec.rb +0 -1
  40. data/spec/shoes/swt/progress_spec.rb +3 -4
  41. data/spec/shoes/swt/radio_group_spec.rb +4 -4
  42. data/spec/shoes/swt/radio_spec.rb +1 -1
  43. data/spec/shoes/swt/shape_spec.rb +8 -1
  44. data/spec/shoes/swt/shared_examples/paintable.rb +0 -1
  45. data/spec/shoes/swt/shared_examples/pattern.rb +2 -6
  46. data/spec/shoes/swt/shared_examples/swt_app_context.rb +0 -1
  47. data/spec/shoes/swt/shell_control_listener_spec.rb +4 -4
  48. data/spec/shoes/swt/shoes_layout_spec.rb +84 -0
  49. data/spec/shoes/swt/slot_spec.rb +1 -1
  50. data/spec/shoes/swt/spec_helper.rb +2 -0
  51. data/spec/shoes/swt/text_block/cursor_painter_spec.rb +2 -2
  52. data/spec/shoes/swt/text_block/fitter_spec.rb +19 -4
  53. data/spec/shoes/swt/text_block/painter_spec.rb +15 -189
  54. data/spec/shoes/swt/text_block/text_segment_collection_spec.rb +10 -5
  55. data/spec/shoes/swt/text_block/text_segment_spec.rb +4 -4
  56. data/spec/shoes/swt/text_block_spec.rb +28 -15
  57. metadata +8 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6157cdc9610526ffb063c6c08ee1a78d77d26e86
4
- data.tar.gz: 29e9d0f9376d61eabcdafe9429e9c914bcd3aa99
3
+ metadata.gz: ffaed9c950057b7cfab0d611a0570dec0b604151
4
+ data.tar.gz: 2308581f63ff15b868167ce26cbb6d7898face7a
5
5
  SHA512:
6
- metadata.gz: d357ec7854ea59d2746ad44a482e13be4d3f4f0a06bfb7fbf01e3d31da2046c3df97babfad75d4faa4bf0925dcf6716420c3c8d5c5e7bb7ecdce1d036fac278d
7
- data.tar.gz: 517a9db8cd6880ffeeea32425604800879c1a9c02670e0d11e0a762643e193b49edd0f5542edcad802dd8e40c199aa562c4dcc952f4058067e2f71bc8a7289b9
6
+ metadata.gz: 93191af23b19fa9f015ac6803c2cb00facd3265ad85d84bef0278626f1f408fa441d2bafc5c26b721afe909935801324f10f04994588997db9a2d28d16bf55b6
7
+ data.tar.gz: c99eafcac01873724c545367dc5ff5ca21a4ab257bfc68ede4f919991dcb3d6b3561e3b454fde2bc78c5f39d086aa4949c25639bb1ccdba32b6b92071313bde0
data/bin/shoes-swt CHANGED
@@ -2,10 +2,10 @@
2
2
  lib_directory = File.expand_path('../../lib', __FILE__)
3
3
  $LOAD_PATH << lib_directory
4
4
 
5
- if File.exists?("Gemfile")
5
+ if File.exist?("Gemfile")
6
6
  require "bundler/setup"
7
7
  Bundler.require
8
8
  end
9
9
 
10
10
  require 'shoes/ui/cli'
11
- Shoes::CLI.new.run ARGV
11
+ Shoes::CLI.new("swt").run ARGV
data/lib/shoes/swt.rb CHANGED
@@ -41,81 +41,99 @@ class Shoes
41
41
  def self.display
42
42
  ::Swt::Widgets::Display.getCurrent
43
43
  end
44
+ end
45
+
46
+ def self.initialize_backend
47
+ return if @initialized
48
+ @initialized = true
44
49
 
45
50
  ::Swt::Widgets::Display.new.getFontList(nil, true).each { |f| ::Shoes::FONTS << f.getName }
46
51
  ::Shoes::FONTS.uniq!
52
+
53
+ ::Shoes.configuration.backend = :swt
54
+
55
+ require 'shoes/swt/disposed_protection'
56
+ require 'shoes/swt/click_listener'
57
+ require 'shoes/swt/color'
58
+ require 'shoes/swt/color_factory'
59
+ require 'shoes/swt/common/child'
60
+ require 'shoes/swt/common/remove'
61
+ require 'shoes/swt/common/clickable'
62
+ require 'shoes/swt/common/container'
63
+ require 'shoes/swt/common/fill'
64
+ require 'shoes/swt/common/resource'
65
+ require 'shoes/swt/common/painter'
66
+ require 'shoes/swt/common/painter_updates_position'
67
+ require 'shoes/swt/common/visibility'
68
+ require 'shoes/swt/common/selection_listener'
69
+ require 'shoes/swt/common/stroke'
70
+ require 'shoes/swt/common/update_position'
71
+
72
+ require 'shoes/swt/input_box'
73
+ require 'shoes/swt/rect_painter.rb'
74
+ require 'shoes/swt/swt_button'
75
+ require 'shoes/swt/check_button'
76
+ require 'shoes/swt/radio_group'
77
+ require 'shoes/swt/text_block/painter'
78
+
79
+ require 'shoes/swt/app'
80
+ require 'shoes/swt/animation'
81
+ require 'shoes/swt/arc'
82
+ require 'shoes/swt/background'
83
+ require 'shoes/swt/border'
84
+ require 'shoes/swt/button'
85
+ require 'shoes/swt/check'
86
+ require 'shoes/swt/dialog'
87
+ require 'shoes/swt/download'
88
+ require 'shoes/swt/font'
89
+ require 'shoes/swt/gradient'
90
+ require 'shoes/swt/image'
91
+ require 'shoes/swt/image_pattern'
92
+ require 'shoes/swt/key_listener'
93
+ require 'shoes/swt/line'
94
+ require 'shoes/swt/link'
95
+ require 'shoes/swt/link_segment'
96
+ require 'shoes/swt/list_box'
97
+ require 'shoes/swt/mouse_move_listener'
98
+ require 'shoes/swt/oval'
99
+ require 'shoes/swt/progress'
100
+ require 'shoes/swt/radio'
101
+ require 'shoes/swt/rect'
102
+ require 'shoes/swt/shape'
103
+ require 'shoes/swt/shoes_layout'
104
+ require 'shoes/swt/slot'
105
+ require 'shoes/swt/star'
106
+ require 'shoes/swt/sound'
107
+ require 'shoes/swt/text_block'
108
+ require 'shoes/swt/timer'
109
+
110
+ require 'shoes/swt/text_block/text_segment'
111
+ require 'shoes/swt/text_block/centered_text_segment'
112
+ require 'shoes/swt/text_block/text_segment_collection'
113
+ require 'shoes/swt/text_block/cursor_painter'
114
+ require 'shoes/swt/text_block/fitter'
115
+ require 'shoes/swt/text_block/text_font_factory'
116
+ require 'shoes/swt/text_block/text_style_factory'
117
+
118
+ require 'shoes/swt/packager'
119
+
120
+ require 'shoes/swt/tooling/leak_hunter' if ENV["LEAK_HUNTER"]
121
+
122
+ # redrawing aspect needs to know all the classes
123
+ require 'shoes/swt/redrawing_aspect'
124
+
125
+ @initialized = true
126
+ rescue Java::OrgEclipseSwt::SWTException => e
127
+ if e.message == "Invalid thread access"
128
+ puts "Ooops, we couldn't start properly. We'll try again."
129
+ puts ""
130
+ puts "To avoid this restarting behavior, try one of the following:"
131
+ puts " * Use the shoes executable to start your app"
132
+ puts " * Add JRUBY_OPTS='-J-XstartOnFirstThread' to your environment before starting."
133
+
134
+ `JRUBY_OPTS=-J-XstartOnFirstThread #{$0} #{ARGV.join(" ")}`
135
+ exit $?.exitstatus
136
+ end
47
137
  end
48
138
  end
49
139
  end
50
-
51
- Shoes.configuration.backend = :swt
52
-
53
- require 'shoes/swt/disposed_protection'
54
- require 'shoes/swt/click_listener'
55
- require 'shoes/swt/color'
56
- require 'shoes/swt/color_factory'
57
- require 'shoes/swt/common/child'
58
- require 'shoes/swt/common/remove'
59
- require 'shoes/swt/common/clickable'
60
- require 'shoes/swt/common/container'
61
- require 'shoes/swt/common/fill'
62
- require 'shoes/swt/common/resource'
63
- require 'shoes/swt/common/painter'
64
- require 'shoes/swt/common/painter_updates_position'
65
- require 'shoes/swt/common/visibility'
66
- require 'shoes/swt/common/selection_listener'
67
- require 'shoes/swt/common/stroke'
68
- require 'shoes/swt/common/update_position'
69
-
70
- require 'shoes/swt/input_box'
71
- require 'shoes/swt/rect_painter.rb'
72
- require 'shoes/swt/swt_button'
73
- require 'shoes/swt/check_button'
74
- require 'shoes/swt/radio_group'
75
- require 'shoes/swt/text_block/painter'
76
-
77
- require 'shoes/swt/app'
78
- require 'shoes/swt/animation'
79
- require 'shoes/swt/arc'
80
- require 'shoes/swt/background'
81
- require 'shoes/swt/border'
82
- require 'shoes/swt/button'
83
- require 'shoes/swt/check'
84
- require 'shoes/swt/dialog'
85
- require 'shoes/swt/download'
86
- require 'shoes/swt/font'
87
- require 'shoes/swt/gradient'
88
- require 'shoes/swt/image'
89
- require 'shoes/swt/image_pattern'
90
- require 'shoes/swt/key_listener'
91
- require 'shoes/swt/line'
92
- require 'shoes/swt/link'
93
- require 'shoes/swt/link_segment'
94
- require 'shoes/swt/list_box'
95
- require 'shoes/swt/mouse_move_listener'
96
- require 'shoes/swt/oval'
97
- require 'shoes/swt/progress'
98
- require 'shoes/swt/radio'
99
- require 'shoes/swt/rect'
100
- require 'shoes/swt/shape'
101
- require 'shoes/swt/shoes_layout'
102
- require 'shoes/swt/slot'
103
- require 'shoes/swt/star'
104
- require 'shoes/swt/sound'
105
- require 'shoes/swt/text_block'
106
- require 'shoes/swt/timer'
107
-
108
- require 'shoes/swt/text_block/text_segment'
109
- require 'shoes/swt/text_block/centered_text_segment'
110
- require 'shoes/swt/text_block/text_segment_collection'
111
- require 'shoes/swt/text_block/cursor_painter'
112
- require 'shoes/swt/text_block/fitter'
113
- require 'shoes/swt/text_block/text_font_factory'
114
- require 'shoes/swt/text_block/text_style_factory'
115
-
116
- require 'shoes/swt/packager'
117
-
118
- require 'shoes/swt/tooling/leak_hunter' if ENV["LEAK_HUNTER"]
119
-
120
- # redrawing aspect needs to know all the classes
121
- require 'shoes/swt/redrawing_aspect'
data/lib/shoes/swt/app.rb CHANGED
@@ -35,6 +35,10 @@ class Shoes
35
35
  end
36
36
 
37
37
  def open
38
+ # If something called quit during the app block's initial evaluation
39
+ # we might already be disposed of, in which case get out of here!
40
+ return if ::Shoes::Swt.main_app.disposed? || @shell.disposed?
41
+
38
42
  @shell.pack
39
43
  force_shell_size
40
44
  @shell.open
@@ -231,6 +235,7 @@ class Shoes
231
235
  def unregister_app
232
236
  proc do |_event|
233
237
  ::Shoes::Swt.unregister(self)
238
+ ::Shoes.unregister(self.dsl.app)
234
239
  end
235
240
  end
236
241
 
@@ -40,7 +40,6 @@ class Shoes
40
40
  handlers = case event.type
41
41
  when ::Swt::SWT::MouseDown then @clicks
42
42
  when ::Swt::SWT::MouseUp then @releases
43
- else nil
44
43
  end
45
44
  return if handlers.nil? || handlers.empty?
46
45
 
@@ -14,7 +14,7 @@ class Shoes
14
14
  end
15
15
 
16
16
  def dispose
17
- @real.dispose unless @real.disposed?
17
+ real.dispose
18
18
  end
19
19
 
20
20
  attr_reader :dsl
@@ -25,15 +25,15 @@ class Shoes
25
25
  end
26
26
 
27
27
  # @param [Swt::Graphics::GC] gc the graphics context on which to apply fill
28
- # @note left, top, width, height, and angle are not used in this method, and only
29
- # exist to satisfy the Pattern interface
30
- def apply_as_fill(gc, _left = nil, _top = nil, _width = nil, _height = nil, _angle = nil)
28
+ # @dsl unused by this method, passed to satisfy the Pattern interface
29
+ def apply_as_fill(gc, _dsl = nil)
31
30
  gc.set_background real
32
31
  gc.set_alpha alpha
33
32
  end
34
33
 
35
34
  # @param [Swt::Graphics::GC] gc the graphics context on which to apply stroke
36
- def apply_as_stroke(gc, _left = nil, _top = nil, _width = nil, _height = nil, _angle = nil)
35
+ # @dsl unused by this method, passed to satisfy the Pattern interface
36
+ def apply_as_stroke(gc, _dsl = nil)
37
37
  gc.set_foreground real
38
38
  gc.set_alpha alpha
39
39
  end
@@ -41,9 +41,9 @@ class Shoes
41
41
 
42
42
  class NullColor
43
43
  attr_reader :alpha, :dsl, :real
44
- def apply_as_fill(_gc); end
44
+ def apply_as_fill(_gc, _dsl); end
45
45
 
46
- def apply_as_stroke(_gc); end
46
+ def apply_as_stroke(_gc, _dsl); end
47
47
  end
48
48
  end
49
49
  end
@@ -9,8 +9,10 @@ class Shoes
9
9
  #
10
10
  # @return [Swt::Graphics::Color] The Swt representation of this object's fill color
11
11
  def fill
12
+ return @cached_swt_fill if @cached_swt_fill
13
+
12
14
  @color_factory ||= ::Shoes::Swt::ColorFactory.new
13
- @color_factory.create(dsl.fill)
15
+ @cached_swt_fill = @color_factory.create(dsl.fill)
14
16
  end
15
17
 
16
18
  # This object's fill alpha value
@@ -25,10 +27,14 @@ class Shoes
25
27
  @angle || 0
26
28
  end
27
29
 
30
+ # Just clear it out and let next paint recreate and save our SWT color
31
+ def update_fill
32
+ @cached_swt_fill = nil
33
+ end
34
+
28
35
  def apply_fill(context)
29
36
  if fill
30
- left, top = self.is_a?(Star) ? [element_left - element_width / 2.0, element_top - element_height / 2.0] : [element_left, element_top]
31
- fill.apply_as_fill(context, left, top, element_width, element_height, angle)
37
+ fill.apply_as_fill(context, self)
32
38
  true
33
39
  end
34
40
  end
@@ -33,21 +33,24 @@ class Shoes
33
33
  cap = LINECAP[@obj.dsl.style[:cap]]
34
34
  graphics_context.set_line_cap(cap) if cap
35
35
  graphics_context.set_transform(@obj.transform)
36
+
36
37
  obj = @obj.dsl
37
- case obj
38
- when ::Shoes::Oval, ::Shoes::Rect
39
- set_rotate graphics_context, obj.rotate,
40
- obj.element_left + obj.element_width / 2.0,
41
- obj.element_top + obj.element_height / 2.0 do
42
- fill graphics_context if fill_setup(graphics_context)
43
- draw graphics_context if draw_setup(graphics_context)
44
- end
45
- else
46
- fill graphics_context if fill_setup(graphics_context)
47
- draw graphics_context if draw_setup(graphics_context)
38
+ if obj.needs_rotate?
39
+ set_rotate graphics_context, obj.rotate,
40
+ obj.element_left + obj.element_width / 2.0,
41
+ obj.element_top + obj.element_height / 2.0 do
42
+ fill_and_draw(graphics_context)
43
+ end
44
+ else
45
+ fill_and_draw(graphics_context)
48
46
  end
49
47
  end
50
48
 
49
+ def fill_and_draw(graphics_context)
50
+ fill graphics_context if fill_setup(graphics_context)
51
+ draw graphics_context if draw_setup(graphics_context)
52
+ end
53
+
51
54
  # Override in subclass and return something falsy if not using fill
52
55
  def fill_setup(graphics_context)
53
56
  @obj.apply_fill(graphics_context)
@@ -9,8 +9,10 @@ class Shoes
9
9
  #
10
10
  # @return [Swt::Graphics::Color] The Swt representation of this object's stroke color
11
11
  def stroke
12
+ return @cached_swt_stroke if @cached_swt_stroke
13
+
12
14
  @color_factory ||= ::Shoes::Swt::ColorFactory.new
13
- @color_factory.create(dsl.stroke)
15
+ @cached_swt_stroke = @color_factory.create(dsl.stroke)
14
16
  end
15
17
 
16
18
  # This object's stroke alpha value
@@ -27,10 +29,14 @@ class Shoes
27
29
  dsl.strokewidth
28
30
  end
29
31
 
32
+ # Just clear it out and let next paint recreate and save our SWT color
33
+ def update_stroke
34
+ @cached_swt_stroke = nil
35
+ end
36
+
30
37
  def apply_stroke(context)
31
38
  if stroke
32
- l, t = self.is_a?(Star) ? [element_left - element_width / 2.0, element_top - element_height / 2.0] : [element_left, element_top]
33
- stroke.apply_as_stroke(context, l, t, element_width, element_height, angle)
39
+ stroke.apply_as_stroke(context, self)
34
40
  context.set_line_width strokewidth
35
41
  true
36
42
  end
@@ -15,8 +15,8 @@ class Shoes
15
15
  confirmed? answer_id
16
16
  end
17
17
 
18
- def dialog_chooser(title, folder = false)
19
- style = ::Swt::SWT::OPEN
18
+ def dialog_chooser(title, folder = false, style = :open)
19
+ style = (style == :save ? ::Swt::SWT::SAVE : ::Swt::SWT::OPEN)
20
20
  shell = ::Swt::Widgets::Shell.new Shoes.display
21
21
  fd = folder ? ::Swt::Widgets::DirectoryDialog.new(shell, style) : ::Swt::Widgets::FileDialog.new(shell, style)
22
22
  fd.setText title
@@ -29,25 +29,27 @@ class Shoes
29
29
  @dsl.alpha
30
30
  end
31
31
 
32
- def apply_as_fill(gc, left, top, width, height, angle = 0)
33
- pattern = create_pattern(left, top, width, height, -angle)
32
+ def apply_as_fill(gc, dsl)
33
+ pattern = create_pattern(dsl)
34
34
  gc.set_background_pattern pattern
35
35
  end
36
36
 
37
- def apply_as_stroke(gc, left, top, width, height, angle = 0)
38
- pattern = create_pattern(left, top, width, height, -angle)
37
+ def apply_as_stroke(gc, dsl)
38
+ pattern = create_pattern(dsl)
39
39
  gc.set_foreground_pattern pattern
40
40
  end
41
41
 
42
42
  private
43
+ def create_pattern(dsl)
44
+ width = dsl.element_width * 0.5
45
+ height = dsl.element_height * 0.5
46
+ angle = normalize_angle(-dsl.angle)
47
+ left, top, width, height = determine_args_based_on_angle(angle,
48
+ dsl.element_left, dsl.element_top,
49
+ width, height)
43
50
 
44
- def create_pattern(left, top, width, height, angle)
45
- width = width * 0.5
46
- height = height * 0.5
47
- angle = normalize_angle(angle)
48
- left, top, width, height = determine_args_based_on_angle(angle, left, top, width, height)
49
-
50
- pattern = ::Swt::Pattern.new Shoes.display, left, top, width, height, color1.real, color2.real
51
+ pattern = ::Swt::Pattern.new Shoes.display, left, top, width, height,
52
+ color1.real, color2.real
51
53
  @patterns << pattern
52
54
  pattern
53
55
  end
@@ -16,9 +16,7 @@ class Shoes
16
16
  def initialize(dsl, parent)
17
17
  @dsl = dsl
18
18
  @parent = parent
19
-
20
- load_image(@dsl.file_path)
21
-
19
+ update_image
22
20
  add_paint_listener
23
21
  end
24
22
 
@@ -19,11 +19,11 @@ class Shoes
19
19
  @pattern ||= ::Swt::Pattern.new(Shoes.display, @image)
20
20
  end
21
21
 
22
- def apply_as_fill(gc, _left, _top, _width, _height, _angle = 0)
22
+ def apply_as_fill(gc, _dsl)
23
23
  gc.set_background_pattern pattern
24
24
  end
25
25
 
26
- def apply_as_stroke(gc, _left, _top, _width, _height, _angle = 0)
26
+ def apply_as_stroke(gc, _dsl)
27
27
  gc.set_foreground_pattern pattern
28
28
  end
29
29
  end
@@ -23,8 +23,6 @@ class Shoes
23
23
  @dsl.angle
24
24
  end
25
25
 
26
- private
27
-
28
26
  class Painter < Common::Painter
29
27
  def draw(gc)
30
28
  gc.draw_line(@obj.element_left, @obj.element_top,