Class: Shoes::Swt::RadioGroup
- Inherits:
-
Object
- Object
- Shoes::Swt::RadioGroup
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- shoes-swt/lib/shoes/swt/radio_group.rb
Overview
In Swt radio groups are managed by composites which occupy space and can interfere with users interacting with other controls. Here we simulate radio groups so that they can all be in one composite.
Constant Summary collapse
- DEFAULT_RADIO_GROUP =
"Default Radio Group"
Class Attribute Summary collapse
-
.group_lookup ⇒ Object
readonly
Returns the value of attribute group_lookup.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #add(radio_button) ⇒ Object
-
#initialize(name = DEFAULT_RADIO_GROUP) ⇒ RadioGroup
constructor
A new instance of RadioGroup.
- #remove(radio_button) ⇒ Object
- #select_only_one_radio_in_group(selected_radio) ⇒ Object
Constructor Details
#initialize(name = DEFAULT_RADIO_GROUP) ⇒ RadioGroup
Returns a new instance of RadioGroup.
19 20 21 22 23 |
# File 'shoes-swt/lib/shoes/swt/radio_group.rb', line 19 def initialize(name = DEFAULT_RADIO_GROUP) @name = name @radio_buttons = [] @selection_listeners = [] end |
Class Attribute Details
.group_lookup ⇒ Object (readonly)
Returns the value of attribute group_lookup.
46 47 48 |
# File 'shoes-swt/lib/shoes/swt/radio_group.rb', line 46 def group_lookup @group_lookup end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'shoes-swt/lib/shoes/swt/radio_group.rb', line 16 def name @name end |
Instance Method Details
#add(radio_button) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'shoes-swt/lib/shoes/swt/radio_group.rb', line 25 def add() return if @radio_buttons.include?() @radio_buttons << selection_listener = SelectionListener.new do |selected_radio, _event| select_only_one_radio_in_group(selected_radio) end @selection_listeners << selection_listener .real.add_selection_listener selection_listener end |
#remove(radio_button) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'shoes-swt/lib/shoes/swt/radio_group.rb', line 36 def remove() index = @radio_buttons.index() return if index.nil? @radio_buttons.delete_at(index) .real.remove_selection_listener @selection_listeners[index] @selection_listeners.delete_at(index) end |
#select_only_one_radio_in_group(selected_radio) ⇒ Object
49 50 51 52 53 |
# File 'shoes-swt/lib/shoes/swt/radio_group.rb', line 49 def select_only_one_radio_in_group(selected_radio) @radio_buttons.each do |radio| radio.real.set_selection(radio == selected_radio) end end |