Class: Glimmer::SWT::CursorProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/glimmer/swt/cursor_proxy.rb

Overview

Proxy for org.eclipse.swt.graphics.Cursor

Invoking ‘#swt_cursor` returns the SWT Cursor object wrapped by this proxy

Follows the Proxy Design Pattern

Constant Summary collapse

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}
ERROR_INVALID_CURSOR_STYLE =
" is an invalid cursor style! Valid values are #{CURSOR_STYLES.map(&:to_s).join(", ")}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cursor_style) ⇒ CursorProxy

Builds a new CursorProxy from passed in cursor SWT style (e.g. :appstarting, :hand, or :help)

Cursor SWT styles are those that begin with “CURSOR_” prefix

They are expected to be passed in in short form without the prefix (but would work with the prefix too)



25
26
27
28
29
30
31
32
# File 'lib/glimmer/swt/cursor_proxy.rb', line 25

def initialize(cursor_style)
  @cursor_style = cursor_style
  @cursor_style = SWTProxy.reverse_lookup(@cursor_style).detect { |symbol| symbol.to_s.downcase.start_with?('cursor_') } if cursor_style.is_a?(Integer)
  @cursor_style = @cursor_style.to_s.downcase
  @cursor_style = @cursor_style.sub(/^cursor\_/, '') if @cursor_style.start_with?('cursor_')
  detect_invalid_cursor_style
  @swt_cursor = DisplayProxy.instance.swt_display.get_system_cursor(SWTProxy[swt_style])
end

Instance Attribute Details

#cursor_styleObject (readonly)

Returns the value of attribute cursor_style.



18
19
20
# File 'lib/glimmer/swt/cursor_proxy.rb', line 18

def cursor_style
  @cursor_style
end

#swt_cursorObject (readonly)

Returns the value of attribute swt_cursor.



18
19
20
# File 'lib/glimmer/swt/cursor_proxy.rb', line 18

def swt_cursor
  @swt_cursor
end

Instance Method Details

#swt_styleObject



34
35
36
# File 'lib/glimmer/swt/cursor_proxy.rb', line 34

def swt_style
  @swt_style ||= @cursor_style.upcase.start_with?('CURSOR_') ? @cursor_style : "CURSOR_#{@cursor_style}"
end