shoes-swt 4.0.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +84 -0
- data/Gemfile +24 -0
- data/Guardfile +11 -0
- data/LICENSE +31 -0
- data/README.md +201 -0
- data/lib/shoes/swt.rb +118 -0
- data/lib/shoes/swt/animation.rb +46 -0
- data/lib/shoes/swt/app.rb +314 -0
- data/lib/shoes/swt/arc.rb +71 -0
- data/lib/shoes/swt/background.rb +41 -0
- data/lib/shoes/swt/border.rb +41 -0
- data/lib/shoes/swt/button.rb +18 -0
- data/lib/shoes/swt/check.rb +14 -0
- data/lib/shoes/swt/check_button.rb +19 -0
- data/lib/shoes/swt/color.rb +49 -0
- data/lib/shoes/swt/color_factory.rb +32 -0
- data/lib/shoes/swt/common/child.rb +16 -0
- data/lib/shoes/swt/common/clickable.rb +68 -0
- data/lib/shoes/swt/common/container.rb +28 -0
- data/lib/shoes/swt/common/fill.rb +38 -0
- data/lib/shoes/swt/common/painter.rb +92 -0
- data/lib/shoes/swt/common/painter_updates_position.rb +12 -0
- data/lib/shoes/swt/common/remove.rb +30 -0
- data/lib/shoes/swt/common/resource.rb +29 -0
- data/lib/shoes/swt/common/selection_listener.rb +14 -0
- data/lib/shoes/swt/common/stroke.rb +42 -0
- data/lib/shoes/swt/common/update_position.rb +15 -0
- data/lib/shoes/swt/common/visibility.rb +13 -0
- data/lib/shoes/swt/dialog.rb +90 -0
- data/lib/shoes/swt/disposed_protection.rb +23 -0
- data/lib/shoes/swt/download.rb +24 -0
- data/lib/shoes/swt/font.rb +32 -0
- data/lib/shoes/swt/gradient.rb +92 -0
- data/lib/shoes/swt/image.rb +128 -0
- data/lib/shoes/swt/image_pattern.rb +31 -0
- data/lib/shoes/swt/input_box.rb +73 -0
- data/lib/shoes/swt/key_listener.rb +145 -0
- data/lib/shoes/swt/line.rb +60 -0
- data/lib/shoes/swt/link.rb +31 -0
- data/lib/shoes/swt/link_segment.rb +111 -0
- data/lib/shoes/swt/list_box.rb +48 -0
- data/lib/shoes/swt/mouse_move_listener.rb +67 -0
- data/lib/shoes/swt/oval.rb +52 -0
- data/lib/shoes/swt/progress.rb +35 -0
- data/lib/shoes/swt/radio.rb +29 -0
- data/lib/shoes/swt/radio_group.rb +54 -0
- data/lib/shoes/swt/rect.rb +30 -0
- data/lib/shoes/swt/rect_painter.rb +23 -0
- data/lib/shoes/swt/redrawing_aspect.rb +123 -0
- data/lib/shoes/swt/shape.rb +133 -0
- data/lib/shoes/swt/shoes_layout.rb +43 -0
- data/lib/shoes/swt/slot.rb +39 -0
- data/lib/shoes/swt/sound.rb +119 -0
- data/lib/shoes/swt/star.rb +50 -0
- data/lib/shoes/swt/support/jl1.0.1.jar +0 -0
- data/lib/shoes/swt/support/jogg-0.0.7.jar +0 -0
- data/lib/shoes/swt/support/jorbis-0.0.15.jar +0 -0
- data/lib/shoes/swt/support/log4j-1.2.16.jar +0 -0
- data/lib/shoes/swt/support/mp3spi1.9.5.jar +0 -0
- data/lib/shoes/swt/support/tritonus_share.jar +0 -0
- data/lib/shoes/swt/support/vorbisspi1.0.3.jar +0 -0
- data/lib/shoes/swt/swt_button.rb +56 -0
- data/lib/shoes/swt/text_block.rb +124 -0
- data/lib/shoes/swt/text_block/centered_text_segment.rb +22 -0
- data/lib/shoes/swt/text_block/cursor_painter.rb +53 -0
- data/lib/shoes/swt/text_block/fitter.rb +212 -0
- data/lib/shoes/swt/text_block/painter.rb +47 -0
- data/lib/shoes/swt/text_block/text_font_factory.rb +50 -0
- data/lib/shoes/swt/text_block/text_segment.rb +108 -0
- data/lib/shoes/swt/text_block/text_segment_collection.rb +160 -0
- data/lib/shoes/swt/text_block/text_style_factory.rb +88 -0
- data/lib/shoes/swt/timer.rb +19 -0
- data/lib/shoes/swt/tooling/leak_hunter.rb +35 -0
- data/lib/shoes/swt/version.rb +5 -0
- data/manifests/common.rb +34 -0
- data/manifests/shoes-swt.rb +29 -0
- data/shoes-swt.gemspec +24 -0
- data/spec/code_coverage.rb +14 -0
- data/spec/shoes/animation_spec.rb +65 -0
- data/spec/shoes/app_spec.rb +484 -0
- data/spec/shoes/arc_spec.rb +51 -0
- data/spec/shoes/background_spec.rb +53 -0
- data/spec/shoes/border_spec.rb +47 -0
- data/spec/shoes/builtin_methods_spec.rb +110 -0
- data/spec/shoes/button_spec.rb +44 -0
- data/spec/shoes/check_spec.rb +35 -0
- data/spec/shoes/cli_spec.rb +15 -0
- data/spec/shoes/color_spec.rb +408 -0
- data/spec/shoes/common/inspect_spec.rb +26 -0
- data/spec/shoes/common/remove_spec.rb +38 -0
- data/spec/shoes/common/style_normalizer_spec.rb +28 -0
- data/spec/shoes/common/style_spec.rb +147 -0
- data/spec/shoes/configuration_spec.rb +36 -0
- data/spec/shoes/constants_spec.rb +38 -0
- data/spec/shoes/dialog_spec.rb +163 -0
- data/spec/shoes/dimension_spec.rb +407 -0
- data/spec/shoes/dimensions_spec.rb +837 -0
- data/spec/shoes/download_spec.rb +142 -0
- data/spec/shoes/flow_spec.rb +133 -0
- data/spec/shoes/font_spec.rb +37 -0
- data/spec/shoes/framework_learning_spec.rb +30 -0
- data/spec/shoes/gradient_spec.rb +32 -0
- data/spec/shoes/helpers/fake_element.rb +17 -0
- data/spec/shoes/helpers/inspect_helpers.rb +5 -0
- data/spec/shoes/helpers/sample17_helper.rb +66 -0
- data/spec/shoes/image_spec.rb +49 -0
- data/spec/shoes/images/shoe.jpg +0 -0
- data/spec/shoes/input_box_spec.rb +80 -0
- data/spec/shoes/integration_spec.rb +20 -0
- data/spec/shoes/internal_app_spec.rb +141 -0
- data/spec/shoes/keypress_spec.rb +11 -0
- data/spec/shoes/keyrelease_spec.rb +12 -0
- data/spec/shoes/line_spec.rb +49 -0
- data/spec/shoes/link_spec.rb +105 -0
- data/spec/shoes/list_box_spec.rb +74 -0
- data/spec/shoes/logger/ruby_spec.rb +8 -0
- data/spec/shoes/logger_spec.rb +45 -0
- data/spec/shoes/oval_spec.rb +24 -0
- data/spec/shoes/point_spec.rb +71 -0
- data/spec/shoes/progress_spec.rb +54 -0
- data/spec/shoes/radio_spec.rb +32 -0
- data/spec/shoes/rect_spec.rb +39 -0
- data/spec/shoes/renamed_delegate_spec.rb +70 -0
- data/spec/shoes/shape_spec.rb +95 -0
- data/spec/shoes/shared_examples/button.rb +6 -0
- data/spec/shoes/shared_examples/changeable.rb +26 -0
- data/spec/shoes/shared_examples/clickable.rb +5 -0
- data/spec/shoes/shared_examples/common_methods.rb +35 -0
- data/spec/shoes/shared_examples/dimensions.rb +32 -0
- data/spec/shoes/shared_examples/dsl.rb +44 -0
- data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
- data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
- data/spec/shoes/shared_examples/dsl/background.rb +26 -0
- data/spec/shoes/shared_examples/dsl/border.rb +10 -0
- data/spec/shoes/shared_examples/dsl/button.rb +5 -0
- data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
- data/spec/shoes/shared_examples/dsl/check.rb +11 -0
- data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
- data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
- data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
- data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
- data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
- data/spec/shoes/shared_examples/dsl/gradient.rb +62 -0
- data/spec/shoes/shared_examples/dsl/image.rb +21 -0
- data/spec/shoes/shared_examples/dsl/line.rb +9 -0
- data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
- data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
- data/spec/shoes/shared_examples/dsl/oval.rb +88 -0
- data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
- data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
- data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
- data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
- data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
- data/spec/shoes/shared_examples/dsl/star.rb +48 -0
- data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
- data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
- data/spec/shoes/shared_examples/dsl/style.rb +32 -0
- data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
- data/spec/shoes/shared_examples/dsl/video.rb +5 -0
- data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
- data/spec/shoes/shared_examples/hover_leave.rb +11 -0
- data/spec/shoes/shared_examples/parent.rb +6 -0
- data/spec/shoes/shared_examples/scroll.rb +41 -0
- data/spec/shoes/shared_examples/shared_element_method.rb +60 -0
- data/spec/shoes/shared_examples/slot.rb +331 -0
- data/spec/shoes/shared_examples/state.rb +19 -0
- data/spec/shoes/shared_examples/style.rb +82 -0
- data/spec/shoes/slot_spec.rb +130 -0
- data/spec/shoes/sound_spec.rb +15 -0
- data/spec/shoes/span_spec.rb +112 -0
- data/spec/shoes/spec_helper.rb +24 -0
- data/spec/shoes/stack_spec.rb +79 -0
- data/spec/shoes/star_spec.rb +31 -0
- data/spec/shoes/text_block_dimensions_spec.rb +75 -0
- data/spec/shoes/text_block_spec.rb +270 -0
- data/spec/shoes/url_spec.rb +68 -0
- data/spec/shoes/widget_spec.rb +70 -0
- data/spec/shoes_spec.rb +44 -0
- data/spec/spec_helper.rb +18 -0
- data/spec/swt_shoes/animation_spec.rb +86 -0
- data/spec/swt_shoes/app_spec.rb +84 -0
- data/spec/swt_shoes/arc_spec.rb +103 -0
- data/spec/swt_shoes/background_spec.rb +67 -0
- data/spec/swt_shoes/border_spec.rb +52 -0
- data/spec/swt_shoes/button_spec.rb +101 -0
- data/spec/swt_shoes/check_spec.rb +28 -0
- data/spec/swt_shoes/color_factory_spec.rb +49 -0
- data/spec/swt_shoes/color_spec.rb +67 -0
- data/spec/swt_shoes/common/painter_spec.rb +49 -0
- data/spec/swt_shoes/common/remove_spec.rb +53 -0
- data/spec/swt_shoes/configuration_spec.rb +12 -0
- data/spec/swt_shoes/dialog_spec.rb +106 -0
- data/spec/swt_shoes/disposed_protection_spec.rb +49 -0
- data/spec/swt_shoes/flow_spec.rb +36 -0
- data/spec/swt_shoes/font_spec.rb +33 -0
- data/spec/swt_shoes/gradient_spec.rb +31 -0
- data/spec/swt_shoes/image_pattern_spec.rb +35 -0
- data/spec/swt_shoes/image_spec.rb +100 -0
- data/spec/swt_shoes/input_box_spec.rb +116 -0
- data/spec/swt_shoes/integration_spec.rb +27 -0
- data/spec/swt_shoes/key_listener_spec.rb +325 -0
- data/spec/swt_shoes/line_spec.rb +49 -0
- data/spec/swt_shoes/link_segment_spec.rb +120 -0
- data/spec/swt_shoes/link_spec.rb +54 -0
- data/spec/swt_shoes/list_box_spec.rb +56 -0
- data/spec/swt_shoes/minimal.png +0 -0
- data/spec/swt_shoes/mouse_move_listener_spec.rb +123 -0
- data/spec/swt_shoes/oval_spec.rb +51 -0
- data/spec/swt_shoes/progress_spec.rb +44 -0
- data/spec/swt_shoes/radio_group_spec.rb +73 -0
- data/spec/swt_shoes/radio_spec.rb +56 -0
- data/spec/swt_shoes/rect_painter_spec.rb +45 -0
- data/spec/swt_shoes/rect_spec.rb +19 -0
- data/spec/swt_shoes/shape_spec.rb +84 -0
- data/spec/swt_shoes/shared_examples/button.rb +21 -0
- data/spec/swt_shoes/shared_examples/clickable.rb +85 -0
- data/spec/swt_shoes/shared_examples/movable.rb +36 -0
- data/spec/swt_shoes/shared_examples/paintable.rb +7 -0
- data/spec/swt_shoes/shared_examples/painter.rb +83 -0
- data/spec/swt_shoes/shared_examples/pattern.rb +32 -0
- data/spec/swt_shoes/shared_examples/removable.rb +41 -0
- data/spec/swt_shoes/shared_examples/swt_app_context.rb +23 -0
- data/spec/swt_shoes/shared_examples/visibility.rb +15 -0
- data/spec/swt_shoes/shell_control_listener_spec.rb +23 -0
- data/spec/swt_shoes/slot_spec.rb +24 -0
- data/spec/swt_shoes/sound.rb +10 -0
- data/spec/swt_shoes/spec_helper.rb +31 -0
- data/spec/swt_shoes/star_spec.rb +47 -0
- data/spec/swt_shoes/text_block/centered_text_segment_spec.rb +16 -0
- data/spec/swt_shoes/text_block/cursor_painter_spec.rb +120 -0
- data/spec/swt_shoes/text_block/fitter_spec.rb +213 -0
- data/spec/swt_shoes/text_block/painter_spec.rb +212 -0
- data/spec/swt_shoes/text_block/text_font_factory_spec.rb +40 -0
- data/spec/swt_shoes/text_block/text_segment_collection_spec.rb +256 -0
- data/spec/swt_shoes/text_block/text_segment_spec.rb +135 -0
- data/spec/swt_shoes/text_block_spec.rb +199 -0
- metadata +496 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
module Remove
|
|
5
|
+
def remove
|
|
6
|
+
app.remove_paint_listener @painter
|
|
7
|
+
remove_click_listeners
|
|
8
|
+
@real.dispose unless @real.nil? || @real.disposed?
|
|
9
|
+
dispose_held_resources
|
|
10
|
+
dispose
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def dispose_held_resources
|
|
14
|
+
@color_factory.dispose unless @color_factory.nil?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Classes should override to dispose of any Swt resources they create
|
|
18
|
+
def dispose
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
def remove_click_listeners
|
|
23
|
+
app.remove_listener ::Swt::SWT::MouseDown, @click_listener
|
|
24
|
+
app.remove_listener ::Swt::SWT::MouseUp, @click_listener
|
|
25
|
+
app.clickable_elements.delete self.dsl
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
module Resource
|
|
5
|
+
def reset_graphics_context(graphics_context)
|
|
6
|
+
dispose_previous_contexts
|
|
7
|
+
set_defaults_on_context(graphics_context)
|
|
8
|
+
track_graphics_context(graphics_context)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def dispose_previous_contexts
|
|
12
|
+
@graphic_contexts ||= []
|
|
13
|
+
@graphic_contexts.each{|g| g.dispose if g}
|
|
14
|
+
@graphic_contexts.clear
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def set_defaults_on_context(graphics_context)
|
|
18
|
+
graphics_context.set_antialias(::Swt::SWT::ON)
|
|
19
|
+
graphics_context.set_line_cap(::Swt::SWT::CAP_FLAT)
|
|
20
|
+
graphics_context.set_transform(nil)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def track_graphics_context(graphics_context)
|
|
24
|
+
@graphic_contexts << graphics_context
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
# Methods for retrieving stroke values from a Shoes DSL class
|
|
5
|
+
#
|
|
6
|
+
# @note Including classes must provide `#dsl`
|
|
7
|
+
module Stroke
|
|
8
|
+
# This object's stroke color
|
|
9
|
+
#
|
|
10
|
+
# @return [Swt::Graphics::Color] The Swt representation of this object's stroke color
|
|
11
|
+
def stroke
|
|
12
|
+
@color_factory ||= ::Shoes::Swt::ColorFactory.new
|
|
13
|
+
@color_factory.create(dsl.stroke)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# This object's stroke alpha value
|
|
17
|
+
#
|
|
18
|
+
# @return [Integer] The alpha value of this object's stroke color (0-255)
|
|
19
|
+
def stroke_alpha
|
|
20
|
+
dsl.stroke.alpha if dsl.stroke
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# This object's strokewidth
|
|
24
|
+
#
|
|
25
|
+
# @return [Integer] This object's strokewidth
|
|
26
|
+
def strokewidth
|
|
27
|
+
dsl.strokewidth
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def apply_stroke(context)
|
|
32
|
+
if stroke
|
|
33
|
+
l, t = self.is_a?(Star) ? [element_left - element_width/2.0, element_top - element_height/2.0] : [element_left, element_top]
|
|
34
|
+
stroke.apply_as_stroke(context, l, t, element_width, element_height, angle)
|
|
35
|
+
context.set_line_width strokewidth
|
|
36
|
+
true
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module Common
|
|
4
|
+
module UpdatePosition
|
|
5
|
+
# Updates the position of this object. This object does not have its
|
|
6
|
+
# own painter, so we need to update the position manually.
|
|
7
|
+
def update_position
|
|
8
|
+
unless @real.disposed?
|
|
9
|
+
@real.set_location dsl.element_left, dsl.element_top
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Dialog
|
|
4
|
+
SWT = ::Swt::SWT
|
|
5
|
+
ALERT_STYLE = SWT::OK | SWT::ICON_INFORMATION
|
|
6
|
+
CONFIRM_STYLE = SWT::YES | SWT::NO | SWT::ICON_QUESTION
|
|
7
|
+
|
|
8
|
+
def alert(msg = '')
|
|
9
|
+
open_message_box ALERT_STYLE, msg
|
|
10
|
+
nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def confirm(msg = '')
|
|
14
|
+
answer_id = open_message_box CONFIRM_STYLE, msg
|
|
15
|
+
confirmed? answer_id
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def dialog_chooser title, folder=false
|
|
19
|
+
style = ::Swt::SWT::OPEN
|
|
20
|
+
shell = ::Swt::Widgets::Shell.new Shoes.display
|
|
21
|
+
fd = folder ? ::Swt::Widgets::DirectoryDialog.new(shell, style) : ::Swt::Widgets::FileDialog.new(shell, style)
|
|
22
|
+
fd.setText title
|
|
23
|
+
fd.open
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def ask msg, args
|
|
27
|
+
Swt::AskDialog.new(::Swt::Widgets::Shell.new, msg, args).open
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def ask_color title
|
|
31
|
+
shell = ::Swt::Widgets::Shell.new Shoes.display
|
|
32
|
+
cd = ::Swt::Widgets::ColorDialog.new shell
|
|
33
|
+
cd.setText title
|
|
34
|
+
color = cd.open
|
|
35
|
+
color ? ::Shoes::Color.new(color.red, color.green, color.blue, ::Shoes::Color::OPAQUE) : ::Shoes::Color.new(0, 0, 0, ::Shoes::Color::OPAQUE)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
def open_message_box(style, msg)
|
|
40
|
+
shell = ::Swt::Widgets::Shell.new ::Swt.display
|
|
41
|
+
@message_box = ::Swt::Widgets::MessageBox.new shell, style
|
|
42
|
+
@message_box.message = msg.to_s
|
|
43
|
+
@message_box.open
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def confirmed?(answer_id)
|
|
47
|
+
answer_id == SWT::YES
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class AskDialog < ::Swt::Widgets::Dialog
|
|
52
|
+
def initialize shell, msg, args
|
|
53
|
+
@shell, @msg, @args= shell, msg, args
|
|
54
|
+
super shell
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def open
|
|
58
|
+
display = getParent.getDisplay
|
|
59
|
+
icon = ::Swt::Graphics::Image.new display, ::Shoes::Swt::ICON
|
|
60
|
+
@shell.setImage icon
|
|
61
|
+
@shell.setSize 300, 125
|
|
62
|
+
@shell.setText 'Shoes 4 asks:'
|
|
63
|
+
label = ::Swt::Widgets::Label.new @shell, ::Swt::SWT::NONE
|
|
64
|
+
label.setText @msg
|
|
65
|
+
label.setLocation 10, 10
|
|
66
|
+
label.pack
|
|
67
|
+
styles = @args[:secret] ? ::Swt::SWT::BORDER | ::Swt::SWT::SINGLE | ::Swt::SWT::PASSWORD : ::Swt::SWT::BORDER | ::Swt::SWT::SINGLE
|
|
68
|
+
text = ::Swt::Widgets::Text.new @shell, styles
|
|
69
|
+
text.setLocation 10, 30
|
|
70
|
+
text.setSize 270, 20
|
|
71
|
+
b = ::Swt::Widgets::Button.new @shell, ::Swt::SWT::NULL
|
|
72
|
+
b.setText 'OK'
|
|
73
|
+
b.setLocation 180, 55
|
|
74
|
+
b.pack
|
|
75
|
+
b.addSelectionListener{|e| @ret = text.getText; @shell.close}
|
|
76
|
+
b = ::Swt::Widgets::Button.new @shell, ::Swt::SWT::NULL
|
|
77
|
+
b.setText 'CANCEL'
|
|
78
|
+
b.setLocation 222, 55
|
|
79
|
+
b.pack
|
|
80
|
+
b.addSelectionListener{|e| @ret = nil; @shell.close}
|
|
81
|
+
@shell.open
|
|
82
|
+
while !@shell.isDisposed do
|
|
83
|
+
display.sleep unless display.readAndDispatch
|
|
84
|
+
end
|
|
85
|
+
icon.dispose
|
|
86
|
+
@ret
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
module DisposedProtection
|
|
4
|
+
def real
|
|
5
|
+
return NullObject.new(@real) if @real.disposed?
|
|
6
|
+
@real
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class NullObject < BasicObject
|
|
10
|
+
def initialize(real)
|
|
11
|
+
@real = real
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def respond_to?(method)
|
|
15
|
+
@real.respond_to? method
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def method_missing(method, *args)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Download
|
|
4
|
+
|
|
5
|
+
attr_accessor :busy
|
|
6
|
+
def initialize(_dsl)
|
|
7
|
+
@busy = false
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# This exists to guarantee the callback block for download completion
|
|
11
|
+
# executes on the main UI thread. Without it we get thread access errors.
|
|
12
|
+
def eval_block(blk, result)
|
|
13
|
+
::Swt.display.asyncExec do
|
|
14
|
+
blk.call result
|
|
15
|
+
@busy = false
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def busy?
|
|
20
|
+
@busy
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
|
|
3
|
+
module Swt
|
|
4
|
+
module Font
|
|
5
|
+
class << self
|
|
6
|
+
def add_font(path)
|
|
7
|
+
if File.exist? path
|
|
8
|
+
::Shoes::Font.add_font_to_fonts(path) if load_font(path)
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def initial_fonts
|
|
13
|
+
load_shoes_fonts #system fonts are loaded automatically by SWT
|
|
14
|
+
::Swt.display.get_font_list(nil, true).map(&:name)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
def load_font(path)
|
|
19
|
+
::Swt.display.load_font path
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def load_shoes_fonts
|
|
23
|
+
::Shoes::Font.font_paths_from_dir(::Shoes::FONT_DIR).each do |font_path|
|
|
24
|
+
add_font font_path
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
::Shoes::Font.initial_fonts.each {|font| Shoes::FONTS << font}
|
|
32
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Gradient
|
|
4
|
+
include Common::Remove
|
|
5
|
+
|
|
6
|
+
def initialize(dsl)
|
|
7
|
+
@dsl = dsl
|
|
8
|
+
@patterns = []
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def dispose
|
|
12
|
+
@color1.dispose if @color1
|
|
13
|
+
@color2.dispose if @color2
|
|
14
|
+
|
|
15
|
+
@patterns.each do |pattern|
|
|
16
|
+
pattern.dispose unless pattern.disposed?
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def color1
|
|
21
|
+
@color1 ||= Color.create @dsl.color1
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def color2
|
|
25
|
+
@color2 ||= Color.create @dsl.color2
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def alpha
|
|
29
|
+
@dsl.alpha
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def apply_as_fill(gc, left, top, width, height, angle = 0)
|
|
33
|
+
pattern = create_pattern(left, top, width, height, -angle)
|
|
34
|
+
gc.set_background_pattern pattern
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def apply_as_stroke(gc, left, top, width, height, angle = 0)
|
|
38
|
+
pattern = create_pattern(left, top, width, height, -angle)
|
|
39
|
+
gc.set_foreground_pattern pattern
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
def create_pattern left, top, width, height, angle
|
|
44
|
+
width = width * 0.5
|
|
45
|
+
height = height * 0.5
|
|
46
|
+
angle = normalize_angle(angle)
|
|
47
|
+
left, top, width, height = determine_args_based_on_angle(angle, left, top, width, height)
|
|
48
|
+
|
|
49
|
+
pattern = ::Swt::Pattern.new Shoes.display, left, top, width, height, color1.real, color2.real
|
|
50
|
+
@patterns << pattern
|
|
51
|
+
pattern
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def normalize_angle(angle)
|
|
55
|
+
angle = Math::PI * (angle/180.0)
|
|
56
|
+
angle % (Math::PI*2.0)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def determine_args_based_on_angle(angle, left, top, width, height)
|
|
60
|
+
x, y = calculate_x_and_y(angle, height, width)
|
|
61
|
+
if 0 <= angle and angle < Math::PI*0.5
|
|
62
|
+
args = [left+width+x, top+height-y, left+width-x, top+height+y]
|
|
63
|
+
elsif Math::PI*0.5 <= angle and angle < Math::PI
|
|
64
|
+
args = [left+width+y, top+height+x, left+width-y, top+height-x]
|
|
65
|
+
elsif Math::PI <= angle and angle < Math::PI*1.5
|
|
66
|
+
args = [left+width-x, top+height+y, left+width+x, top+height-y]
|
|
67
|
+
elsif Math::PI*1.5 <= angle and angle < Math::PI*2.0
|
|
68
|
+
args = [left+width-y, top+height-x, left+width+y, top+height+x]
|
|
69
|
+
end
|
|
70
|
+
args
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def calculate_x_and_y(angle, height, width)
|
|
74
|
+
if angle % Math::PI >= (Math::PI * 0.5)
|
|
75
|
+
my_width = height
|
|
76
|
+
my_height = width
|
|
77
|
+
else
|
|
78
|
+
my_width = width
|
|
79
|
+
my_height = height
|
|
80
|
+
end
|
|
81
|
+
my_angle = angle % (Math::PI * 0.5)
|
|
82
|
+
length = Math.sqrt(my_width**2 + my_height**2)
|
|
83
|
+
b = (my_height==0 and my_width==0) ? 0 : Math.atan(my_height/my_width)
|
|
84
|
+
c = Math::PI*0.5 - my_angle - b
|
|
85
|
+
r = length * Math.cos(c.abs)
|
|
86
|
+
x = r * Math.cos(b+c)
|
|
87
|
+
y = r * Math.sin(b+c)
|
|
88
|
+
return x, y
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
class Shoes
|
|
2
|
+
module Swt
|
|
3
|
+
class Image
|
|
4
|
+
import java.io.ByteArrayInputStream
|
|
5
|
+
|
|
6
|
+
include Common::Child
|
|
7
|
+
include Common::Resource
|
|
8
|
+
include Common::Clickable
|
|
9
|
+
include Common::PainterUpdatesPosition
|
|
10
|
+
include Common::Visibility
|
|
11
|
+
include Common::Remove
|
|
12
|
+
include ::Shoes::BackendDimensionsDelegations
|
|
13
|
+
|
|
14
|
+
BINARY_ENCODING = Encoding.find('binary')
|
|
15
|
+
|
|
16
|
+
attr_reader :parent, :real, :dsl, :painter
|
|
17
|
+
|
|
18
|
+
def initialize(dsl, parent)
|
|
19
|
+
@dsl = dsl
|
|
20
|
+
@parent = parent
|
|
21
|
+
|
|
22
|
+
load_image(@dsl.file_path)
|
|
23
|
+
|
|
24
|
+
add_paint_listener
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def update_image
|
|
28
|
+
load_image(@dsl.file_path)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
def load_image(name_or_data)
|
|
33
|
+
if url?(name_or_data)
|
|
34
|
+
save_width_and_height
|
|
35
|
+
display_temporary_download_image
|
|
36
|
+
download_and_display_real_image(name_or_data)
|
|
37
|
+
else
|
|
38
|
+
display_image(name_or_data)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def url?(name_or_data)
|
|
43
|
+
name_or_data =~ /^(http|https):\/\//
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def save_width_and_height
|
|
47
|
+
@saved_width = dsl.element_width
|
|
48
|
+
@saved_height = dsl.element_height
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def display_temporary_download_image
|
|
52
|
+
temporary_download_image = File.join(DIR, 'static/downloading.png')
|
|
53
|
+
create_image(temporary_download_image)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def create_image(data)
|
|
57
|
+
@real = ::Swt::Graphics::Image.new(::Swt.display, data)
|
|
58
|
+
@full_width = @real.getImageData.width
|
|
59
|
+
@full_height = @real.getImageData.height
|
|
60
|
+
dsl.element_width ||= default_width
|
|
61
|
+
dsl.element_height ||= default_height
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def default_width
|
|
65
|
+
if dsl.element_height
|
|
66
|
+
ratio = dsl.element_height.to_r / @full_height
|
|
67
|
+
(@full_width * ratio).to_i
|
|
68
|
+
else
|
|
69
|
+
@full_width
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def default_height
|
|
74
|
+
if dsl.element_width
|
|
75
|
+
ratio = dsl.element_width.to_r / @full_width
|
|
76
|
+
(@full_height * ratio).to_i
|
|
77
|
+
else
|
|
78
|
+
@full_height
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def download_and_display_real_image(url)
|
|
83
|
+
@tmpname = File.join(Dir.tmpdir, "__shoes4_#{Time.now.to_f}.png") unless @tmpname_or_data
|
|
84
|
+
@dsl.app.download url, save: @tmpname do
|
|
85
|
+
restore_width_and_height
|
|
86
|
+
create_image @tmpname
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def restore_width_and_height
|
|
91
|
+
dsl.element_width = @saved_width
|
|
92
|
+
dsl.element_height = @saved_height
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def display_image(name_or_data)
|
|
96
|
+
if raw_image_data?(name_or_data)
|
|
97
|
+
data = load_raw_image_data(name_or_data)
|
|
98
|
+
else
|
|
99
|
+
data = name_or_data
|
|
100
|
+
end
|
|
101
|
+
create_image(data)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def raw_image_data?(name_or_data)
|
|
105
|
+
name_or_data.encoding == BINARY_ENCODING
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def load_raw_image_data(name_or_data)
|
|
109
|
+
stream = ByteArrayInputStream.new(name_or_data.to_java_bytes)
|
|
110
|
+
begin
|
|
111
|
+
data = ::Swt::Graphics::ImageLoader.new.load(stream).first
|
|
112
|
+
rescue ::Swt::SWTException
|
|
113
|
+
data = name_or_data
|
|
114
|
+
end
|
|
115
|
+
data
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
def add_paint_listener
|
|
119
|
+
@painter = lambda do |event|
|
|
120
|
+
graphics_context = event.gc
|
|
121
|
+
graphics_context.drawImage @real, 0, 0, @full_width, @full_height, dsl.element_left, dsl.element_top, dsl.element_width, dsl.element_height unless @dsl.hidden
|
|
122
|
+
end
|
|
123
|
+
app.add_paint_listener(@painter)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|