|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Window | +--java.awt.Frame | +--javax.swing.JFrame | +--edu.kzoo.grid.gui.GridAppFrame
Grid GUI Support Package:
The GridAppFrame
class provides a window in which
to display a grid and its contents. Options include menus, a
speed slider bar, and a control panel containing buttons such as
a Start/Restart/Reset button. Menus and buttons are usually
enabled (clickable) except when one of them is executing, when
they are generally disabled (grayed-out and not clickable). It
is possible, though, to create components that are always enabled
(such as the speed slider bar), enabled only when the application
is actively executing (such as a stop button), or always disabled
(useful when the program is under construction and the behavior for
a particular component has not yet been implemented).
Nested Class Summary | |
class |
GridAppFrame.DisplayMouseListener
Nested class that handles simple mouse presses over the grid display. |
static class |
GridAppFrame.GUIExceptionHandler
Nested class that is registered as the handler for exceptions on the Swing event thread. |
Field Summary | |
static int |
DEFAULT_MAX_DELAY_MSECS
Default maximum value for speed slider bar (1000 milliseconds). |
static int |
DEFAULT_MIN_DELAY_MSECS
Default minimum value for speed slider bar (10 milliseconds). |
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 | |
GridAppFrame()
Constructs an empty GridAppFrame window object that will display a grid. |
Method Summary | |
void |
addGridChangeListener(GridChangeListener listener)
Registers the specified object as interested in being notified of changes in the identify of the grid being modeled. |
protected boolean |
componentRequiresGrid(javax.swing.JComponent component)
Returns true if the given component requires the grid
to have been set in order to be enabled; false otherwise. |
protected java.util.Collection |
componentsEnabledOnlyIfGridSet()
Returns the set of components that should be enabled only when the current grid is not null. |
protected java.util.Collection |
componentsEnabledOnlyWhenRunning()
Returns the set of components that should be enabled only when the application is actively running, and should be disabled when the application is ready and waiting for user input. |
protected java.util.Collection |
componentsEnabledOnlyWhenWaiting()
Returns the set of components that should be enabled only when the application is ready and waiting for user input. |
protected ScrollableGridDisplay |
constructDisplay(int viewingWidth,
int viewingHeight,
int minCellSize,
java.awt.Color bgColor)
Constructs the grid display at the heart of the graphical user interface. |
void |
constructWindowContents(java.lang.String title,
java.awt.Color bgColor,
int viewingWidth,
int viewingHeight,
int minCellSize)
Constructs the body of a window containing a scrollable display for a grid and its contents. |
void |
constructWindowContents(java.lang.String title,
int viewingWidth,
int viewingHeight,
int minCellSize)
Constructs the body of a window containing a scrollable display for a grid and its contents. |
protected javax.swing.JPanel |
defineContent()
Defines contents of main window panel. |
protected void |
enableAndDisable()
Enables and disables components appropriately. |
void |
enableOnlyIfGridSet(javax.swing.JComponent component)
Enables the given component only when the application is ready and waiting for user input. |
void |
enableOnlyWhenRunning(javax.swing.JComponent component)
Enables the given component only when the application is actively executing (not just waiting for user input). |
void |
enableOnlyWhenWaiting(javax.swing.JComponent component)
Enables the given component only when the application is ready and waiting for user input. |
void |
enterNotRunningMode()
Enables and disables GUI components as necessary when an application is not running. |
void |
enterRunningMode()
Enables and disables GUI components as necessary while the application is running. |
protected javax.swing.JPanel |
getControlPanel()
Returns the control panel ( null if this
graphical user interface has no control panel). |
int |
getDelay()
Returns the current delay value from the speed slider or a previous call to setDelay ; defaults to 0 if there is no speed
slider included with this graphical user interface and if
setDelay has never been called. |
ScrollableGridDisplay |
getDisplay()
Gets the grid display. |
Grid |
getGrid()
Returns the grid at the center of this graphical user interface. |
protected java.awt.event.MouseAdapter |
getMouseListenerForDisplay()
Returns a mouse adapter that responds to mouse presses over the grid display. |
protected javax.swing.JSlider |
getSpeedSlider()
Returns the speed slider bar ( null if no speed slider
is included with this graphical user interface). |
void |
includeControlComponent(javax.swing.JComponent component,
int enableDisableIndicator)
Includes the specified control component in a list of control buttons. |
void |
includeControlComponent(javax.swing.JComponent component,
int enableDisableIndicator,
boolean initiallyEnabled)
Includes the specified control component in a list of control buttons. |
void |
includeControlComponents(java.util.ArrayList componentList,
int enableDisableIndicator)
Includes the control components in the given list in the control panel. |
void |
includeMenu(javax.swing.JMenu menu)
Includes the specified menu. |
void |
includeMenu(javax.swing.JMenu menu,
int enableDisableIndicator)
Includes the specified menu. |
void |
includeSpeedSlider()
Includes a speed adjustment slider bar with default values. |
void |
includeSpeedSlider(int maxDelayMsecs,
int minDelayMsecs)
Includes a speed adjustment slider bar with the specified extreme values and an initial delay halfway between them. |
void |
includeSpeedSlider(int maxDelayMsecs,
int minDelayMsecs,
int initialDelayMsecs)
Includes a speed adjustment slider bar with the specified properties. |
boolean |
isInRunningMode()
Returns true if the application is in "running mode"
(executing the behavior associated with a control button, for example);
returns false otherwise. |
protected javax.swing.JPanel |
makeControlPanel(java.lang.String title)
Creates a control panel that lays out control buttons starting from the top. |
protected javax.swing.JComponent |
makeDisplayPanel()
Creates the panel for displaying a grid application. |
protected javax.swing.JPanel |
makeSliderPanel()
Creates a speed slider for controling the speed of the animation. |
void |
notifyGridChangeListeners()
Notifies all registered model change listeners that the model has been replaced. |
protected void |
onMousePressOverDisplay(Location loc)
Handles a mouse press over the grid display. |
void |
resetDelay()
Resets the current delay value to the initial delay value and adjusts the speed slider, if there is one. |
void |
setDelay(int delayMsecs)
Sets the current delay value and adjusts the speed slider, if there is one. |
protected void |
setEnabledStatus(javax.swing.JComponent component,
int enableDisableIndicator)
Specifies when a given component should be enabled or disabled. |
void |
setGrid(Grid grid)
Sets the grid being displayed. |
void |
showGrid()
Shows the grid. |
Methods inherited from class javax.swing.JFrame |
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update |
Methods inherited from class java.awt.Frame |
addNotify, finalize, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setIconImage, 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, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo, 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, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, isOpaque, 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, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.awt.MenuContainer |
getFont, postEvent |
Field Detail |
public static final int DEFAULT_MIN_DELAY_MSECS
public static final int DEFAULT_MAX_DELAY_MSECS
Constructor Detail |
public GridAppFrame()
includeStartRestart
and
includeSpeedSlider
to include components on the
window other than the basic grid display.
Use the constructWindowContents method to set the properties of the
window and make it visible.
Method Detail |
public void includeMenu(javax.swing.JMenu menu)
JMenu
subclass, should implement the
GridChangeListener
interface, and should register
itself as a grid change listener.
This method will have no effect unless it is
called before the constructWindowContents method.
menu
- the menu to includeBasicGridFileMenu
,
BasicHelpMenu
,
MinimalFileMenu
,
addGridChangeListener(edu.kzoo.grid.gui.GridChangeListener)
public void includeMenu(javax.swing.JMenu menu, int enableDisableIndicator)
JMenu
subclass, should implement the
GridChangeListener
interface, and should register
itself as a grid change listener.
This method will have no effect unless it is
called before the constructWindowContents method.
menu
- the menu to includeenableDisableIndicator
- indicates when the menu should
enabled or disabledBasicGridFileMenu
,
BasicHelpMenu
,
MinimalFileMenu
,
addGridChangeListener(edu.kzoo.grid.gui.GridChangeListener)
protected void setEnabledStatus(javax.swing.JComponent component, int enableDisableIndicator)
component
- the component to includeenableDisableIndicator
- indicates when the component should
enabled or disabledpublic void enableOnlyIfGridSet(javax.swing.JComponent component)
public void enableOnlyWhenWaiting(javax.swing.JComponent component)
public void enableOnlyWhenRunning(javax.swing.JComponent component)
public void includeControlComponent(javax.swing.JComponent component, int enableDisableIndicator)
component
- the component to includeenableDisableIndicator
- indicates when the component should
be enabled or disabledpublic void includeControlComponent(javax.swing.JComponent component, int enableDisableIndicator, boolean initiallyEnabled)
initiallyEnabled
parameter;
it later switches to enabled or disabled under the conditions
indicated by the enableDisableIndicator
parameter.
Note, though, that it will only switch if there is a state change
that would normally cause it to switch. It will never switch,
for example, if the enableDisableIndicator
parameter
is ALWAYS_ENABLED or ALWAYS_DISABLED, because there is no defined
state change that would cause such components to switch. Thus,
a component that is specified as ALWAYS_ENABLED but initially
disabled will remain disabled throughout the application.
This method will have no effect unless it is called before the constructWindowContents method.
component
- the component to includeenableDisableIndicator
- indicates when the component should
be enabled or disabledinitiallyEnabled
- true if button should initially be enabled;
false if button should initially be disabledpublic void includeControlComponents(java.util.ArrayList componentList, int enableDisableIndicator)
componentList
- the list of components to include in the
control panelenableDisableIndicator
- indicates when the components should
be enabled or disabledpublic void includeSpeedSlider()
DEFAULT_MAX_DELAY_MSECS
to
DEFAULT_MIN_DELAY_MSECS
(maximum delay is
slowest; minimum dalay is fastest), with an initial
delay halfway between them.
public void includeSpeedSlider(int maxDelayMsecs, int minDelayMsecs)
maxDelayMsecs
to minDelayMsecsY_MSECS
(maximum delay is slowest; minimum dalay is fastest).
(Precondition: minDelayMsecs <= <= maxDelayMsecs)
maxDelayMsecs
- maximum delay value for slider, in millisecondsminDelayMsecs
- minimum delay value for slider, in millisecondspublic void includeSpeedSlider(int maxDelayMsecs, int minDelayMsecs, int initialDelayMsecs)
maxDelayMsecs
to minDelayMsecsY_MSECS
(maximum delay is slowest; minimum dalay is fastest).
(Precondition: minDelayMsecs <= initialDelayMsecs <= maxDelayMsecs)
maxDelayMsecs
- maximum delay value for slider, in millisecondsminDelayMsecs
- minimum delay value for slider, in millisecondsinitialDelayMsecs
- initial value for slider, in millisecondspublic void constructWindowContents(java.lang.String title, int viewingWidth, int viewingHeight, int minCellSize)
title
- frame titleviewingWidth
- the width of the viewing areaviewingHeight
- the height of the viewing areaminCellSize
- minimum grid cell side lengthpublic void constructWindowContents(java.lang.String title, java.awt.Color bgColor, int viewingWidth, int viewingHeight, int minCellSize)
title
- frame titlebgColor
- color to paint background of gridviewingWidth
- the width of the viewing areaviewingHeight
- the height of the viewing areaminCellSize
- minimum grid cell side lengthprotected ScrollableGridDisplay constructDisplay(int viewingWidth, int viewingHeight, int minCellSize, java.awt.Color bgColor)
ScrollableGridDisplay
(for
example, to modify the way tool tips are displayed, or some
other aspect of the scrollable display).
viewingWidth
- the width of the viewing areaviewingHeight
- the height of the viewing areaminCellSize
- minimum grid cell side lengthbgColor
- color to paint background of grid
public void setGrid(Grid grid)
setGrid
in interface GridDisplay
grid
- the Grid to displaypublic Grid getGrid()
public void showGrid()
setGrid
.)
showGrid
in interface GridDisplay
public ScrollableGridDisplay getDisplay()
protected java.awt.event.MouseAdapter getMouseListenerForDisplay()
protected javax.swing.JPanel getControlPanel()
null
if this
graphical user interface has no control panel).
protected boolean componentRequiresGrid(javax.swing.JComponent component)
true
if the given component requires the grid
to have been set in order to be enabled; false
otherwise.
protected java.util.Collection componentsEnabledOnlyIfGridSet()
protected java.util.Collection componentsEnabledOnlyWhenWaiting()
protected java.util.Collection componentsEnabledOnlyWhenRunning()
public boolean isInRunningMode()
true
if the application is in "running mode"
(executing the behavior associated with a control button, for example);
returns false
otherwise.
protected javax.swing.JSlider getSpeedSlider()
null
if no speed slider
is included with this graphical user interface).
public void setDelay(int delayMsecs)
delayMsecs
- the length of time the application should pause
after displaying the grid to allow users time
to see it (in milliseconds)public void resetDelay()
public int getDelay()
setDelay
; defaults to 0 if there is no speed
slider included with this graphical user interface and if
setDelay
has never been called.
protected javax.swing.JPanel defineContent()
protected javax.swing.JComponent makeDisplayPanel()
protected javax.swing.JPanel makeControlPanel(java.lang.String title)
title
- a title to put in the border of this control
panel, or null
if no title is desired
protected javax.swing.JPanel makeSliderPanel()
public void addGridChangeListener(GridChangeListener listener)
listener
- the object that should be notified of
changes to the identity of the gridpublic void notifyGridChangeListeners()
protected void onMousePressOverDisplay(Location loc)
public void enterRunningMode()
public void enterNotRunningMode()
protected void enableAndDisable()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |