Class: LifeTableModel
- Inherits:
-
AbstractTableModel
- Object
- AbstractTableModel
- LifeTableModel
- Defined in:
- lib/life_game_viewer/view/life_table_model.rb
Overview
This class is the model used to drive Swing’s JTable. It contains a LifeModel to which it delegates most calls.
Instance Attribute Summary collapse
-
#generations ⇒ Object
readonly
Returns the value of attribute generations.
-
#life_model ⇒ Object
Returns the value of attribute life_model.
Instance Method Summary collapse
- #add_current_num_change_handler(callable) ⇒ Object
- #at_first_generation? ⇒ Boolean
- #at_last_generation? ⇒ Boolean
- #fire_current_number_changed ⇒ Object
- #getColumnCount ⇒ Object
- #getColumnName(colnum) ⇒ Object
- #getRowCount ⇒ Object
- #getValueAt(row, col) ⇒ Object
- #go_to_first_generation ⇒ Object
- #go_to_last_generation ⇒ Object
- #go_to_next_generation ⇒ Object
- #go_to_previous_generation ⇒ Object
-
#initialize(life_model) ⇒ LifeTableModel
constructor
A new instance of LifeTableModel.
- #inner_model=(life_model) ⇒ Object
- #number_living ⇒ Object
- #reset_model(new_model) ⇒ Object
Constructor Details
#initialize(life_model) ⇒ LifeTableModel
Returns a new instance of LifeTableModel.
16 17 18 19 20 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 16 def initialize(life_model) super() @current_num_change_handlers = [] self.inner_model = life_model end |
Instance Attribute Details
#generations ⇒ Object (readonly)
Returns the value of attribute generations.
13 14 15 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 13 def generations @generations end |
#life_model ⇒ Object
Returns the value of attribute life_model.
12 13 14 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 12 def life_model @life_model end |
Instance Method Details
#add_current_num_change_handler(callable) ⇒ Object
80 81 82 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 80 def add_current_num_change_handler(callable) @current_num_change_handlers << callable end |
#at_first_generation? ⇒ Boolean
43 44 45 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 43 def at_first_generation? generations.at_first_generation? end |
#at_last_generation? ⇒ Boolean
47 48 49 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 47 def at_last_generation? generations.at_last_generation? end |
#fire_current_number_changed ⇒ Object
90 91 92 93 94 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 90 def fire_current_number_changed @current_num_change_handlers.each do |handler| handler.call(generations.current_num) end end |
#getColumnCount ⇒ Object
31 32 33 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 31 def getColumnCount life_model.column_count end |
#getColumnName(colnum) ⇒ Object
39 40 41 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 39 def getColumnName(colnum) nil end |
#getRowCount ⇒ Object
27 28 29 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 27 def getRowCount life_model.row_count end |
#getValueAt(row, col) ⇒ Object
35 36 37 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 35 def getValueAt(row, col) life_model.alive?(row, col) end |
#go_to_first_generation ⇒ Object
70 71 72 73 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 70 def go_to_first_generation self.life_model = generations.first fire_current_number_changed end |
#go_to_last_generation ⇒ Object
75 76 77 78 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 75 def go_to_last_generation self.life_model = generations.last fire_current_number_changed end |
#go_to_next_generation ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 55 def go_to_next_generation if at_last_generation? JOptionPane.(nil, "Generation ##{generations.current_num} is the last non-repeating generation.") else self.life_model = generations.next fire_current_number_changed end end |
#go_to_previous_generation ⇒ Object
64 65 66 67 68 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 64 def go_to_previous_generation raise "Should not have gotten here; already at first generation" if at_first_generation? self.life_model = generations.previous fire_current_number_changed end |
#inner_model=(life_model) ⇒ Object
22 23 24 25 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 22 def inner_model=(life_model) @life_model = life_model @generations = Generations.new(life_model) end |
#number_living ⇒ Object
51 52 53 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 51 def number_living life_model.number_living end |
#reset_model(new_model) ⇒ Object
84 85 86 87 88 |
# File 'lib/life_game_viewer/view/life_table_model.rb', line 84 def reset_model(new_model) self.inner_model = new_model fire_table_structure_changed fire_current_number_changed end |