Class: Glimmer::SWT::ShellProxy
- Inherits:
-
WidgetProxy
- Object
- WidgetProxy
- Glimmer::SWT::ShellProxy
- Defined in:
- lib/glimmer/swt/shell_proxy.rb
Overview
Proxy for org.eclipse.swt.widgets.Shell
Follows the Proxy Design Pattern
Constant Summary collapse
- WIDTH_MIN =
130- HEIGHT_MIN =
0- CUSTOM_ATTRIBUTES =
%w[app_name app_version]
Constants inherited from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::DEFAULT_STYLES
Instance Attribute Summary collapse
-
#opened_before ⇒ Object
(also: #opened_before?)
readonly
Returns the value of attribute opened_before.
Attributes inherited from WidgetProxy
Instance Method Summary collapse
- #add_observer(observer, property_name) ⇒ Object
-
#center ⇒ Object
Centers shell within monitor it is in.
- #close ⇒ Object
- #content(&block) ⇒ Object
- #hide ⇒ Object
-
#initialize(*args) ⇒ ShellProxy
constructor
Instantiates ShellProxy with same arguments expected by SWT Shell.
-
#open ⇒ Object
(also: #show)
Opens shell and starts SWT’s UI thread event loop.
-
#start_event_loop ⇒ Object
(happens as part of ‘#open`) Starts SWT Event Loop.
-
#visible=(visibility) ⇒ Object
Setting to true opens/shows shell.
- #visible? ⇒ Boolean
Methods inherited from WidgetProxy
#async_exec, #can_add_observer?, #can_handle_observation_request?, #dispose, #extract_args, #get_attribute, #handle_observation_request, #has_attribute?, #has_style?, #remove_observer, #set_attribute, swt_widget_class_for, #sync_exec, widget_exists?, #widget_property_listener_installers
Methods included from DataBinding::ObservableWidget
Constructor Details
#initialize(*args) ⇒ ShellProxy
Instantiates ShellProxy with same arguments expected by SWT Shell
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 23 def initialize(*args) if args.last.is_a?(Hash) app_attributes = args.delete(args.last) Display.setAppName(app_attributes[:app_name]) Display.setAppVersion(app_attributes[:app_version]) end if args.first.is_a?(ShellProxy) args[0] = args[0]. end if args.first.nil? || (!args.first.is_a?(Display) && !args.first.is_a?(Shell)) @display = DisplayProxy.instance.swt_display args = [@display] + args end args = SWTProxy.constantify_args(args).compact @swt_widget = Shell.new(*args) @display ||= @swt_widget.getDisplay @swt_widget.setLayout(FillLayout.new) @swt_widget.setMinimumSize(WIDTH_MIN, HEIGHT_MIN) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Glimmer::DataBinding::ObservableWidget
Instance Attribute Details
#opened_before ⇒ Object (readonly) Also known as: opened_before?
Returns the value of attribute opened_before.
19 20 21 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 19 def opened_before @opened_before end |
Instance Method Details
#add_observer(observer, property_name) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 101 def add_observer(observer, property_name) case property_name.to_s when 'visible?' visibility_notifier = proc do observer.call(visible?) end on_event_show(&visibility_notifier) on_event_hide(&visibility_notifier) on_event_close(&visibility_notifier) else super end end |
#center ⇒ Object
Centers shell within monitor it is in
44 45 46 47 48 49 50 51 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 44 def center primary_monitor = @display.getPrimaryMonitor() monitor_bounds = primary_monitor.getBounds() shell_bounds = @swt_widget.getBounds() location_x = monitor_bounds.x + (monitor_bounds.width - shell_bounds.width) / 2 location_y = monitor_bounds.y + (monitor_bounds.height - shell_bounds.height) / 2 @swt_widget.setLocation(location_x, location_y) end |
#close ⇒ Object
72 73 74 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 72 def close @swt_widget.close end |
#content(&block) ⇒ Object
85 86 87 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 85 def content(&block) Glimmer::DSL::Engine.add_content(self, DSL::ShellExpression.new, &block) end |
#hide ⇒ Object
68 69 70 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 68 def hide @swt_widget.setVisible(false) end |
#open ⇒ Object Also known as: show
Opens shell and starts SWT’s UI thread event loop
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 54 def open if @opened_before @swt_widget.setVisible(true) # notify_observers('visible') else @opened_before = true @swt_widget.pack center @swt_widget.open start_event_loop end end |
#start_event_loop ⇒ Object
(happens as part of ‘#open`) Starts SWT Event Loop.
You may learn more about the SWT Event Loop here: help.eclipse.org/2019-12/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Display.html This method is not needed except in rare circumstances where there is a need to start the SWT Event Loop before opening the shell.
95 96 97 98 99 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 95 def start_event_loop until @swt_widget.isDisposed @display.sleep unless @display.readAndDispatch end end |
#visible=(visibility) ⇒ Object
Setting to true opens/shows shell. Setting to false hides the shell.
81 82 83 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 81 def visible=(visibility) visibility ? show : hide end |
#visible? ⇒ Boolean
76 77 78 |
# File 'lib/glimmer/swt/shell_proxy.rb', line 76 def visible? @swt_widget.isDisposed ? false : @swt_widget.isVisible end |