edu.neu.ccs.gui
Class CheckerBoard

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byedu.neu.ccs.gui.DisplayPanel
                      extended byedu.neu.ccs.gui.TablePanel
                          extended byedu.neu.ccs.gui.CheckerBoard
All Implemented Interfaces:
Accessible, AlertListener, Displayable, EventListener, ImageObserver, JPTConstants, MalformedDataListener, MenuContainer, Serializable, SwingConstants

public class CheckerBoard
extends TablePanel

CheckerBoard implements a checkerboard in which one can interactively contrast two colors. This is useful for a developer in planning color combinations because it is often difficult to tell how two colors will look when placed side by side. The board is rendered in a BufferedPanel. Normally, a CheckerBoard object also comes with two ColorView dropdown panels that may be used to interactively select the contrasting colors and a button that will reset the colors to their original state. However, it is also possible to omit these interactive controls and then the panel may be used for board games such as checkers and chess. To do this, one may add Paintable game pieces to the internal BufferedPanel and then may manipulate these pieces either programmatically or by using the mouse.

Colors may be entered in the ColorView dropdown panels in the following ways:

The default constructor creates a checkerboard with default settings and but, as of 2.6.0, does not install the checkerboard in a frame automatically.

Using the general constructor, one can control settings, choose whether to show the interactive controls, and whether to frame the panel automatically.

Since:
2.4
Version:
2.6
See Also:
ColorView, VisualColorSampler, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
private  int block
          The size of a checkerboard block.
static int BLOCK
          The default checkerboard block size = 48.
private  Rectangle2D[][] blocks
          The array of checkerboard blocks.
static Color COLOR0
          The default color for checkerboard blocks whose (row + column) sum is even: black.
static Color COLOR1
          The default color for checkerboard blocks whose (row + column) sum is odd: white.
private  SimpleAction colorCheckerBoard
          The action to make a checkerboard patten.
static int gap
          The pixel gap between items in this panel.
static int MAXIMUM_BLOCK
          The maximum checkerboard block size = 80.
static int MINIMUM_BLOCK
          The minimum checkerboard block size = 16.
private  SimpleAction resetColorViews
          The action to reset the colors to their original settings.
private  ColorView view0
          Color view 0.
private  ColorView view1
          Color view 1.
private  BufferedPanel window
          The checkerboard graphics window.
 
Fields inherited from class edu.neu.ccs.gui.TablePanel
DEFAULT_ALIGNMENT, DEFAULT_ORIENTATION, tg
 
Fields inherited from class edu.neu.ccs.gui.DisplayPanel
background, codec, CODEC
 
Fields inherited from class javax.swing.JPanel
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface edu.neu.ccs.gui.Displayable
DEFAULT_VIEW_STATE, VIEW_STATE
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CheckerBoard()
          The constructor that creates a checkerboard panel using the default block size and default colors and includes the interactive color controls.
CheckerBoard(int block, Color color0, Color color1, boolean showColorViews, boolean autoFrame)
          The constructor that permits the caller to control the size of the checkerboard block (within limits), the initial block colors, whether to show the interactive color controls, and whether to automatically put the checkerboard into a JPTFrame.
 
Method Summary
private  int adjustBlock(int block)
          Adjust the block size to lie between the minimum and maximum.
private  void autoFramePanel(boolean autoFrame)
          Auto frame if desired.
protected  void colorCheckerBoard()
          The method to color the checkerboard patten.
private  void createCheckerBoard(int block)
          Create the checker board and the blocks data structure.
private  void createColorViews(Color color0, Color color1)
          Create the color views with the given original colors.
 int getBlockSize()
          Returns the checkerboard block size.
 BufferedPanel getCheckerboard()
          Returns a reference to the checkerboard BufferedPanel on which the checkerboard is painted.
 int getCheckerBoardSize()
          Returns the checkerboard BufferedPanel size.
 Color getColor0()
          Returns the color for blocks with (row + column) sum even.
 Color getColor1()
          Returns the color for blocks with (row + column) sum odd.
private  void installContents(boolean showColorViews)
          Install the contents in this panel.
 void resetColorViews()
          Resets the colors to their original settings.
 void setColor0(Color color0)
          Sets the color for blocks with (row + column) sum even to the given color.
 void setColor1(Color color1)
          Sets the color for blocks with (row + column) sum odd to the given color.
 
Methods inherited from class edu.neu.ccs.gui.TablePanel
addObject, addObject, autoEmptyBorder, createCells, getCellAlignment, getCellAlignment, getColumnAlignment, getColumnCount, getComponentTable, getEffectiveCellAlignment, getEffectiveCellAlignment, getHorizontalGap, getMaximumSize, getMinimumColumnWidth, getMinimumRowHeight, getMinimumSize, getOrientation, getPreferredSize, getRowAlignment, getRowCount, getTableAlignment, getTableEntry, getTableEntry, getTableGenerator, getTableLayout, getVerticalGap, isEmptyColumn, isEmptyRow, isValidColumn, isValidRow, removeCells, resetPreferredSize, setAllMinimumColumnWidths, setAllMinimumRowHeights, setCellAlignment, setCellAlignment, setColumnAlignment, setColumns, setHorizontalGap, setLayout, setMinimumColumnWidth, setMinimumRowHeight, setOrientation, setRowAlignment, setRows, setTableAlignment, setVerticalGap, uniformizeCellHeight, uniformizeCellSize, uniformizeCellWidth
 
Methods inherited from class edu.neu.ccs.gui.DisplayPanel
add, add, add, add, add, addBorder, addObject, addObject, addObject, addObject, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, compoundBorder, compoundBorder, dataMalformed, emptyBorder, emptyBorder, emptyBorder, endAlert, etchBorderLowered, etchBorderLowered, etchBorderLowered, etchBorderRaised, etchBorderRaised, etchBorderRaised, frame, frame, frame, frame, frame, frame, generalDialog, generalDialog, generalDialog, generalDialog, getCodec, getDefaultViewState, getDefaultViewStates, getDisplayables, getViewState, getViewStates, lineBorder, lineBorder, lineBorder, lineBorder, makeComponent, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, OKCancelDialog, OKCancelDialog, OKDialog, OKDialog, refreshComponent, remove, remove, removeAll, removeBorder, reset, sandwichBorder, setCodec, setDeepBackground, setDeepBackground, setDefaultViewState, setDefaultViewStates, setEnabled, setViewState, setViewStates, startAlert, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, uniformizeHeight, uniformizeSize, uniformizeWidth, YesNoCancelDialog, YesNoCancelDialog
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

gap

public static final int gap
The pixel gap between items in this panel.

See Also:
Constant Field Values

MAXIMUM_BLOCK

public static final int MAXIMUM_BLOCK
The maximum checkerboard block size = 80.

See Also:
Constant Field Values

BLOCK

public static final int BLOCK
The default checkerboard block size = 48.

See Also:
Constant Field Values

MINIMUM_BLOCK

public static final int MINIMUM_BLOCK
The minimum checkerboard block size = 16.

See Also:
Constant Field Values

COLOR0

public static final Color COLOR0
The default color for checkerboard blocks whose (row + column) sum is even: black.


COLOR1

public static final Color COLOR1
The default color for checkerboard blocks whose (row + column) sum is odd: white.


window

private BufferedPanel window
The checkerboard graphics window.


block

private int block
The size of a checkerboard block.


blocks

private Rectangle2D[][] blocks
The array of checkerboard blocks.


view0

private ColorView view0
Color view 0.


view1

private ColorView view1
Color view 1.


colorCheckerBoard

private SimpleAction colorCheckerBoard
The action to make a checkerboard patten.


resetColorViews

private SimpleAction resetColorViews
The action to reset the colors to their original settings.

Constructor Detail

CheckerBoard

public CheckerBoard()

The constructor that creates a checkerboard panel using the default block size and default colors and includes the interactive color controls.

As of 2.6.0, this constructor does not automatically open the checkerboard in a frame. This turnes out to be a more convenient default behavior.


CheckerBoard

public CheckerBoard(int block,
                    Color color0,
                    Color color1,
                    boolean showColorViews,
                    boolean autoFrame)

The constructor that permits the caller to control the size of the checkerboard block (within limits), the initial block colors, whether to show the interactive color controls, and whether to automatically put the checkerboard into a JPTFrame.

Parameters:
block - the size of a checkerboard block
color0 - color for blocks with (row + column) sum even
color1 - color for blocks with (row + column) sum odd
showColorViews - whether to show the interactive color controls
autoFrame - whether to automatically frame the checkerboard
Method Detail

getCheckerboard

public final BufferedPanel getCheckerboard()

Returns a reference to the checkerboard BufferedPanel on which the checkerboard is painted.

This permits the user to add Paintable objects such as "game pieces" to the paintable sequence layer of the checkerboard.


getBlockSize

public final int getBlockSize()

Returns the checkerboard block size.

The checkerboard panel has size equal to 8 times the block size.


getCheckerBoardSize

public final int getCheckerBoardSize()

Returns the checkerboard BufferedPanel size.

The checkerboard panel has size equal to 8 times the block size.

The caller should not modify the BufferedPanel size using calls from the BufferedPanel class.


getColor0

public final Color getColor0()
Returns the color for blocks with (row + column) sum even.


getColor1

public final Color getColor1()
Returns the color for blocks with (row + column) sum odd.


setColor0

public final void setColor0(Color color0)

Sets the color for blocks with (row + column) sum even to the given color.

Does nothing if the given color is null

Parameters:
color0 - color for blocks with (row + column) sum even

setColor1

public final void setColor1(Color color1)

Sets the color for blocks with (row + column) sum odd to the given color.

Does nothing if the given color is null

Parameters:
color1 - color for blocks with (row + column) sum odd

resetColorViews

public final void resetColorViews()
Resets the colors to their original settings.


adjustBlock

private final int adjustBlock(int block)
Adjust the block size to lie between the minimum and maximum.


createCheckerBoard

private final void createCheckerBoard(int block)
Create the checker board and the blocks data structure.


createColorViews

private final void createColorViews(Color color0,
                                    Color color1)
Create the color views with the given original colors.

Parameters:
color0 - color for blocks with (row + column) sum even
color1 - color for blocks with (row + column) sum odd

installContents

private final void installContents(boolean showColorViews)
Install the contents in this panel.


autoFramePanel

private final void autoFramePanel(boolean autoFrame)
Auto frame if desired.


colorCheckerBoard

protected final void colorCheckerBoard()
The method to color the checkerboard patten.