Class: LifeGameViewerFrame

Inherits:
JFrame
  • Object
show all
Defined in:
lib/life_game_viewer/view/life_game_viewer_frame.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(life_model) ⇒ LifeGameViewerFrame

Returns a new instance of LifeGameViewerFrame.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/life_game_viewer/view/life_game_viewer_frame.rb', line 58

def initialize(life_model)
  model_validation_message = ModelValidation.new.methods_missing_message(life_model)
  if model_validation_message
    raise model_validation_message
  end

  super('The Game of Life')
  @table_model = LifeTableModel.new(life_model)
  self.default_close_operation = JFrame::EXIT_ON_CLOSE
  add(JScrollPane.new(Table.new(table_model)), BorderLayout::CENTER)
  add(HeaderPanel.new, BorderLayout::NORTH)
  add(BottomPanel.new(@table_model, self), BorderLayout::SOUTH)
  content_pane.border = BorderFactory.create_empty_border(12, 12, 12, 12)
  pack
end

Instance Attribute Details

#table_modelObject

Returns the value of attribute table_model.



44
45
46
# File 'lib/life_game_viewer/view/life_game_viewer_frame.rb', line 44

def table_model
  @table_model
end

Class Method Details

.view_sampleObject

Special class method for demonstration purposes; makes it trivially simple to view the program in action without having to add any custom behavior.



49
50
51
52
53
54
55
56
# File 'lib/life_game_viewer/view/life_game_viewer_frame.rb', line 49

def self.view_sample
  str = ''
  12.times { str << ('*-' * 6) << "\n" }
  model = SampleLifeModel.create_from_string(str)
  frame = LifeGameViewerFrame.new(model)
  frame.visible = true
  frame  # return frame so it can be manipulated (.visible =, etc.)
end

Instance Method Details

#getPreferredSizeObject

This is the method that Swing will call to ask what size to attempt to set for this window.



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/life_game_viewer/view/life_game_viewer_frame.rb', line 76

def getPreferredSize
  # use the default size calculation; this would of course also be accomplished
  # by not implementing the method at all.
  super

  # Or, you can override it with specific pixel sizes (width, height)
  # Dimension.new(700, 560)

  # Or, use the line below to make it the full screen size:
  # Toolkit.get_default_toolkit.screen_size
end