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 can be optionally used with WidgetProxy to manipulate an SWT widget font (reusing its FontData but building a new Font)

Otherwise, if no WidgetProxy is passed to constructor, it builds new FontData

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 = nil, 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



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/glimmer/swt/font_proxy.rb', line 55

def initialize(widget_proxy = nil, font_properties)
  @widget_proxy = widget_proxy
  if font_properties.is_a?(FontData)
    font_datum = font_properties
    @font_properties = {name: font_properties.name, height: font_properties.height, style: font_properties.style}
  elsif font_properties.is_a?(Hash)
    @font_properties = font_properties
    detect_invalid_font_property(font_properties)
    font_properties[:style] = SWTProxy[*font_properties[:style]]
    # TODO consider supporting other properties like locale in the future
    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)
  end
  @swt_font = Font.new(DisplayProxy.instance.swt_display, font_datum)
end

Instance Attribute Details

#font_propertiesObject (readonly)

Returns the value of attribute font_properties.



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

def font_properties
  @font_properties
end

#swt_fontObject (readonly)

Returns the value of attribute swt_font.



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

def swt_font
  @swt_font
end

#widget_proxyObject (readonly)

Returns the value of attribute widget_proxy.



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

def widget_proxy
  @widget_proxy
end

Instance Method Details

#heightObject



77
78
79
# File 'lib/glimmer/swt/font_proxy.rb', line 77

def height
  font_datum.getHeight
end

#nameObject



73
74
75
# File 'lib/glimmer/swt/font_proxy.rb', line 73

def name
  font_datum.getName
end

#styleObject



81
82
83
# File 'lib/glimmer/swt/font_proxy.rb', line 81

def style
  font_datum.getStyle
end