Class: Shoes::Swt::RadioGroup

Inherits:
Object
  • Object
show all
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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = DEFAULT_RADIO_GROUP) ⇒ 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_lookupObject (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

#nameObject (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(radio_button)
  return if @radio_buttons.include?(radio_button)
  @radio_buttons << radio_button

  selection_listener = SelectionListener.new radio_button do |selected_radio, _event|
    select_only_one_radio_in_group(selected_radio)
  end
  @selection_listeners << selection_listener
  radio_button.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(radio_button)
  index = @radio_buttons.index(radio_button)
  return if index.nil?
  @radio_buttons.delete_at(index)

  radio_button.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