ballwar.view
Class BallGUI

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by ballwar.view.BallGUI
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class BallGUI
extends JFrame

A subclass of JFrame containing the various GUI components specified in the program behavior specification. Allows the balls to be specified, constructed, drawn and controlled. Allows players to be specified and the game to be controlled. Provides a Container area where the drawing object is to be drawn.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  JButton _addBtn
          Button to add the strategy entered in inputTF to both drop lists.
private  JButton _addPaintBtn
          Button to add the paint strategy entered in _paintTF to the drop list.
private  IBallCreateAdapter _bCreateA
          IBallCreateAdapater used to create new balls.
private  IBallCtrlAdapter _bCtrlA
          The IBallCtrlAdapter used to control the balls.
private  JPanel _canvasPnl
          The panel upon which the balls are painted.
private  JPanel _cbPnl
          The sub-panel that holds the drop-lists of strategies and their control buttons.
private  JButton _clearAllBtn
          The button to clear all the balls.
private  JButton _combineBtn
          Button used to combine a selection from _list1CBox and a selection from _list2BCBox into a combined strategy.
private  JPanel _controlPnl
          The panel upon which all the game controls are located.
private  IGameCtrlAdapter _gCtrlA
          The IGameCtrlAdapter used to control the game.
private  JPanel _inputPnl
          The sub-panel that the input textfield is located.
private  JTextField _inputTF
          The textfield where the user can type in the classname of a new strategy.
private  JComboBox _list1CBox
          A drop-list with all the strategies and combinations of strategies.
private  JComboBox _list2CBox
          Same content as _list1CBox because two lists are needed to create combinations of strategies.
private  JButton _makePlayerBtn
          Button to make a new player with the name typed in by the user.
private  JButton _makeSelectedBtn
          Button to make a ball with the selected strategy in _list1CBox.
private  JButton _makeSwitcherBtn
          The button that makes a new ball with a SwitcherStrategy.
private  JComboBox _paintCBox
          Drop list with available paint strategies.
private  JPanel _paintSelPnl
          The sub-panel that the paint selection controls are located.
private  JTextField _paintTF
          The textfield where the user can type in the classname of a new painting strategy.
private  JComboBox _playersCBox
          Drop list that shows the names of all the players made so far.
private  JLabel _statusLbl
          Label at the bottom of the screen used to display the status of the game and the player's scores.
private  JButton _switchBtn
          The button that switches the decoree in the SwitcherStrategy to the currently selected strategey.
private  JPanel _switcherPnl
          The sub-panel that holds the SwitcherStrategy controls.
private static long serialVersionUID
           
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
BallGUI(WindowListener wl, IBallCreateAdapter bCreateA, IBallCtrlAdapter bCtrlA, IGameCtrlAdapter gCtrlA)
          Constructor for the class.
 
Method Summary
 void addComponent(Component c)
          Adds the given Component to the control panel.
 void addKeyCmd(String keyName, ILambda cmd)
          Adds the given key such that whenever that key is pressed the given command (AbstractAction) is performed.
 void autoWidth()
          Automatically adjusts the width of the GUI to its minimum size such that all the controls can be seen.
 Container getCanvas()
          Accessor method for the panel upon which the balls are to be drawn
 Object getSelectedPlayer()
          Returns the selected player (held in a drop list) .
private  void init()
          Initializes and lays out the GUI components.
 void update()
          Updates the view.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

_controlPnl

private JPanel _controlPnl
The panel upon which all the game controls are located.


_canvasPnl

private JPanel _canvasPnl
The panel upon which the balls are painted.


_clearAllBtn

private JButton _clearAllBtn
The button to clear all the balls.


_inputTF

private JTextField _inputTF
The textfield where the user can type in the classname of a new strategy.


_addBtn

private JButton _addBtn
Button to add the strategy entered in inputTF to both drop lists.


_inputPnl

private JPanel _inputPnl
The sub-panel that the input textfield is located.


_makeSwitcherBtn

private JButton _makeSwitcherBtn
The button that makes a new ball with a SwitcherStrategy.


_switchBtn

private JButton _switchBtn
The button that switches the decoree in the SwitcherStrategy to the currently selected strategey.


_switcherPnl

private JPanel _switcherPnl
The sub-panel that holds the SwitcherStrategy controls.


_cbPnl

private JPanel _cbPnl
The sub-panel that holds the drop-lists of strategies and their control buttons.


_list1CBox

private JComboBox _list1CBox
A drop-list with all the strategies and combinations of strategies. Holds the factories that are used by the model to instantiate balls with that strategy. The factory's toString() method is called to generate the text shown on the drop list. This drop list is the list used when the user selects a strategy, except when creating a combination.


_list2CBox

private JComboBox _list2CBox
Same content as _list1CBox because two lists are needed to create combinations of strategies.


_combineBtn

private JButton _combineBtn
Button used to combine a selection from _list1CBox and a selection from _list2BCBox into a combined strategy.


_makeSelectedBtn

private JButton _makeSelectedBtn
Button to make a ball with the selected strategy in _list1CBox.


_statusLbl

private JLabel _statusLbl
Label at the bottom of the screen used to display the status of the game and the player's scores.


_makePlayerBtn

private JButton _makePlayerBtn
Button to make a new player with the name typed in by the user.


_playersCBox

private JComboBox _playersCBox
Drop list that shows the names of all the players made so far. Holds players and uses their toString() method to display their names.


_paintTF

private JTextField _paintTF
The textfield where the user can type in the classname of a new painting strategy.


_paintSelPnl

private JPanel _paintSelPnl
The sub-panel that the paint selection controls are located.


_addPaintBtn

private JButton _addPaintBtn
Button to add the paint strategy entered in _paintTF to the drop list.


_paintCBox

private JComboBox _paintCBox
Drop list with available paint strategies.


_bCtrlA

private IBallCtrlAdapter _bCtrlA
The IBallCtrlAdapter used to control the balls.


_gCtrlA

private IGameCtrlAdapter _gCtrlA
The IGameCtrlAdapter used to control the game.


_bCreateA

private IBallCreateAdapter _bCreateA
IBallCreateAdapater used to create new balls.

Constructor Detail

BallGUI

public BallGUI(WindowListener wl,
               IBallCreateAdapter bCreateA,
               IBallCtrlAdapter bCtrlA,
               IGameCtrlAdapter gCtrlA)
Constructor for the class. Attaches the given adapters to their respective behaviors. Notice how the adapter functionalities are grouped such that related behaviors are on the same adapter. The view (this class) has no knowledge of the actual organization of the model, for instance, that it is even represented by a single class.

Parameters:
wl - The WindowListener called when this window closes.
bCreateA - The IBallCreateAdapter used to create the balls.
bCtrlA - The IBallCtrlAdapter used to control the balls.
gCtrlA - The IGameCtrlAdapter used to control the game.
Method Detail

init

private void init()
           throws Exception
Initializes and lays out the GUI components.

Throws:
Exception

autoWidth

public void autoWidth()
Automatically adjusts the width of the GUI to its minimum size such that all the controls can be seen. The height is unaffected. Useful when new items are added to the drop lists, changing the required width of the GUI.


getCanvas

public Container getCanvas()
Accessor method for the panel upon which the balls are to be drawn


update

public void update()
Updates the view. This will update the display string shown on the status label. This will also, in turn, ask the model to update. This is required because the model has the timer which tells the system when to update, but the model cannot update until the view is ready to repaint.


addKeyCmd

public void addKeyCmd(String keyName,
                      ILambda cmd)
Adds the given key such that whenever that key is pressed the given command (AbstractAction) is performed. If the given key was already added, its behavior is replaced by the new behavior.

Parameters:
keyName - The name of the virtual key to add, minus the leading "VK_". See the Java documentation under "KeyEvent".
cmd - The behavior to associate with this key. The command's actionPerformed() method will be called whenever the given key is pressed.

getSelectedPlayer

public Object getSelectedPlayer()
Returns the selected player (held in a drop list) . The GUI has no knowledge of the type or usage of the player object.

Returns:
The selected player.

addComponent

public void addComponent(Component c)
Adds the given Component to the control panel. Used to add such things as new OptionPanels to the control panel without requiring that the GUI know what their functionality.

Parameters:
c - The component to add.