Class: Shoes::Swt::ColorFactory

Inherits:
Object
  • Object
show all
Defined in:
shoes-swt/lib/shoes/swt/color_factory.rb

Overview

ColorFactory is used for tracking SWT-backed resources related to colors that potentially need to get disposed. It can additionally take gradients and maybe other values, though, so it can't assume values will be disposable.

Additionally this factory does caching against the DSL element so we don't needlessly generate things like OS colors over and over again.

Instance Method Summary collapse

Constructor Details

#initializeColorFactory


13
14
15
# File 'shoes-swt/lib/shoes/swt/color_factory.rb', line 13

def initialize
  @swt_elements = {}
end

Instance Method Details

#create(element) ⇒ Object


24
25
26
27
28
29
30
# File 'shoes-swt/lib/shoes/swt/color_factory.rb', line 24

def create(element)
  return nil if element.nil?
  return @swt_elements[element] if @swt_elements.include?(element)
  swt_element = ::Shoes.backend_for(element)
  @swt_elements[element] = swt_element
  swt_element
end

#disposeObject


17
18
19
20
21
22
# File 'shoes-swt/lib/shoes/swt/color_factory.rb', line 17

def dispose
  @swt_elements.each_value do |swt_element|
    swt_element.dispose if swt_element.respond_to?(:dispose)
  end
  @swt_elements.clear
end