Class: Glimmer::SWT::FontProxy

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

Overview

Proxy for org.eclipse.swt.graphics.Font

This class is meant to be used with WidgetProxy to manipulate an SWT widget font.

It is not meant to create new SWT fonts form scratch without a widget proxy.

Invoking ‘#swt_font` returns the SWT Font object wrapped by this proxy

Follows the Proxy Design Pattern

Constant Summary collapse

ERROR_INVALID_FONT_STYLE =
" is an invalid font style! Valid values are :normal, :bold, and :italic"
FONT_STYLES =
[:normal, :bold, :italic]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(widget_proxy, font_properties) ⇒ FontProxy

Builds a new font proxy from passed in widget_proxy and font_properties hash,

It begins with existing SWT widget font and amends it with font properties.

Font properties consist of: :name, :height, and :style (one needed minimum)

Style (:style value) can only be one of FontProxy::FONT_STYLES values: that is :normal, :bold, or :italic



34
35
36
37
38
39
40
41
42
43
# File 'lib/glimmer/swt/font_proxy.rb', line 34

def initialize(widget_proxy, font_properties)
  @widget_proxy = widget_proxy
  detect_invalid_font_property(font_properties)
  font_properties[:style] = SWTProxy[*font_properties[:style]]
  font_data_args = [:name, :height, :style].map do |font_property_name|
    font_properties[font_property_name] || send(font_property_name)
  end
  font_datum = FontData.new(*font_data_args)
  @swt_font = Font.new(DisplayProxy.instance.swt_display, font_datum)
end

Instance Attribute Details

#swt_fontObject (readonly)

Returns the value of attribute swt_font.



24
25
26
# File 'lib/glimmer/swt/font_proxy.rb', line 24

def swt_font
  @swt_font
end

#widget_proxyObject (readonly)

Returns the value of attribute widget_proxy.



24
25
26
# File 'lib/glimmer/swt/font_proxy.rb', line 24

def widget_proxy
  @widget_proxy
end

Instance Method Details

#heightObject



49
50
51
# File 'lib/glimmer/swt/font_proxy.rb', line 49

def height
  font_datum.getHeight
end

#nameObject



45
46
47
# File 'lib/glimmer/swt/font_proxy.rb', line 45

def name
  font_datum.getName
end

#styleObject



53
54
55
# File 'lib/glimmer/swt/font_proxy.rb', line 53

def style
  font_datum.getStyle
end