Module: RSwing::Components::Container
- Includes:
- Component, Events::ContainerEvents
- Defined in:
- lib/rswing/components/container.rb
Constant Summary
Constants included from Events::ContainerEvents
Events::ContainerEvents::ContainerListener
Constants included from Events::FocusEvents
Events::FocusEvents::FocusListener
Constants included from Events::PropertyChanged
Events::PropertyChanged::PropertyChangeListener
Constants included from Events::InputMethodEvents
Events::InputMethodEvents::InputMethodListener
Constants included from Events::HierarchyBoundsEvents
Events::HierarchyBoundsEvents::HierarchyBoundsListener
Constants included from Events::KeyEvents
Events::KeyEvents::KeyListener
Constants included from Events::MouseWheelEvents
Events::MouseWheelEvents::MouseWheelListener
Constants included from Events::MouseMotionEvents
Events::MouseMotionEvents::MouseMotionListener
Constants included from Events::MouseEvents
Events::MouseEvents::MouseListener
Constants included from Events::ComponentEvents
Events::ComponentEvents::ComponentListener
Class Method Summary collapse
-
.add_if_requested(component, options) ⇒ Object
Adds a component to a container, if specified via :belongs_to in options.
Instance Method Summary collapse
-
#[](name_symbol) ⇒ Object
Returns the component with a given name inside of this container (if available).
-
#add(component, options = {}) ⇒ Object
Adds a component with a set of options to this container.
-
#add_with_name(component, name_symbol) ⇒ Object
Adds a component to the component_hash with a given name symbol.
-
#components ⇒ Object
Returns the components of a container.
-
#remove(component) ⇒ Object
Removes a component from this container.
Methods included from Events::ContainerEvents
Methods included from Events::FocusEvents
Methods included from Events::InputMethodEvents
Methods included from Events::HierarchyBoundsEvents
Methods included from Events::KeyEvents
Methods included from Events::MouseMotionEvents
Methods included from Events::MouseEvents
Methods included from Events::ComponentEvents
Class Method Details
.add_if_requested(component, options) ⇒ Object
Adds a component to a container, if specified via :belongs_to in options.
89 90 91 92 93 94 95 96 97 |
# File 'lib/rswing/components/container.rb', line 89 def self.add_if_requested(component, ) if(container = Options.value_for( => :belongs_to)) if(Options.value_for( => :layout) || Options.value_for( => :name)) container.add(component, ) else container.add(component) end end end |
Instance Method Details
#[](name_symbol) ⇒ Object
Returns the component with a given name inside of this container (if available).
-
name_symbolName (as symbol) of the component to get.
70 71 72 73 74 75 76 |
# File 'lib/rswing/components/container.rb', line 70 def [](name_symbol) if self.component_hash.has_key?(name_symbol) self.component_hash[name_symbol] # erstes hash mit diesem namen als key zurückgeben else nil end end |
#add(component, options = {}) ⇒ Object
Adds a component with a set of options to this container.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rswing/components/container.rb', line 29 def add(component, = {}) if(self.respond_to?(:getContentPane)) self.add_to_content_pane(component, ) else if(layout = Options.value_for( => :layout)) super(component, layout) else super(component) end end # if :name given, add with name if(name = Options.value_for( => :name)) self.add_with_name(component, name) # also set components name attribute, if specified component.name = name.to_s end component # return component end |
#add_with_name(component, name_symbol) ⇒ Object
Adds a component to the component_hash with a given name symbol. Raises an exception if name already taken.
52 53 54 55 56 57 58 |
# File 'lib/rswing/components/container.rb', line 52 def add_with_name(component, name_symbol) if self.component_hash.has_key?(name_symbol) raise "Name in component already taken!" else self.component_hash[name_symbol] = component end end |
#components ⇒ Object
Returns the components of a container. If the container uses a content_pane, its components are returned.
80 81 82 83 84 85 86 |
# File 'lib/rswing/components/container.rb', line 80 def components if self.respond_to?(:getContentPane) self.content_pane.components else super end end |
#remove(component) ⇒ Object
Removes a component from this container. Also removes it from the component_hash
62 63 64 65 66 |
# File 'lib/rswing/components/container.rb', line 62 def remove(component) super(component) # delete all entries with component as value in component_hash self.component_hash.delete_if { |key,value| value == component } end |