public class ScrollableGridDisplay extends javax.swing.JPanel implements GridDisplay, GridBackgroundDisplay, GridChangeListener, javax.swing.Scrollable, PseudoInfiniteViewport.Pannable
ScrollableGridDisplay is a panel containing a
scrollable graphical display of a grid.
There are a number of default settings that can be used or overridden:
Setting Default Value minimum cell size 8 pixels dimensions for viewing area 420 x 420 (pixels) background display solid background color background color ocean blue (Color(75, 75, 255)) grid lines visible tool tips enabled tool tip information content's toString info
javax.swing.JPanel.AccessibleJPaneljavax.swing.JComponent.AccessibleJComponent| Modifier and Type | Field and Description |
|---|---|
protected GridBackgroundDisplay |
backgroundDisplay |
protected java.awt.Color |
bgColor |
static int |
DEFAULT_MIN_CELL_SIZE |
static int |
DEFAULT_VIEWABLE_SIZE |
protected int |
gridLineWidth |
protected static int |
LOCATION_TOOL_TIPS |
protected int |
minCellSize |
protected int |
numCols |
protected int |
numRows |
protected static int |
OBJECT_STRING_TOOL_TIPS |
static java.awt.Color |
OCEAN_BLUE |
protected int |
originCol |
protected int |
originRow |
protected int |
outerCellSize |
protected java.awt.Dimension |
preferredVPSize |
protected Grid |
theGrid |
protected boolean |
toolTipsEnabledFlag |
protected boolean |
toolTipsSetEnabledFlag |
protected int |
toolTipsType |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW| Constructor and Description |
|---|
ScrollableGridDisplay()
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
ScrollableGridDisplay(java.awt.Color backgroundColor)
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
ScrollableGridDisplay(int minimumCellSize)
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
ScrollableGridDisplay(int minimumCellSize,
java.awt.Color backgroundColor)
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
ScrollableGridDisplay(int width,
int height)
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
ScrollableGridDisplay(int width,
int height,
java.awt.Color backgroundColor)
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
ScrollableGridDisplay(int width,
int height,
int minimumCellSize)
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
ScrollableGridDisplay(int viewingWidth,
int viewingHeight,
int minimumCellSize,
java.awt.Color backgroundColor)
Constructs a new ScrollableGridDisplay object with no grid
and an empty view.
|
| Modifier and Type | Method and Description |
|---|---|
java.awt.Color |
backgroundColor()
Gets the background color for displaying the grid.
|
protected int |
calculateGridLineWidth()
Returns the width of each grid line.
|
int |
colToXCoord(int col)
Returns X-coordinate of left side of given column.
|
void |
drawBackground(java.awt.Graphics2D g2)
Draws the grid background.
|
protected void |
drawGridlines(java.awt.Graphics2D g2)
Draws the gridlines for the grid.
|
protected void |
drawGridObject(java.awt.Graphics2D g2,
GridObject obj)
Draws one GridObject instance.
|
protected int |
extraHeight() |
protected int |
extraWidth() |
void |
fillBackground(java.awt.Graphics2D g2,
java.awt.Color fillColor)
Fills the grid background with the specified color.
|
javax.swing.JViewport |
getEnclosingViewport()
Gets our parent viewport, if we are in one.
|
java.awt.Dimension |
getMinimumSize()
Returns the minimum size of the display, for use by layout manager.
|
java.lang.String |
getPannableTipText() |
java.awt.Dimension |
getPreferredScrollableViewportSize() |
java.awt.Dimension |
getPreferredSize()
Returns the desired size of the display, for use by layout manager.
|
int |
getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
int orientation,
int direction) |
boolean |
getScrollableTracksViewportHeight() |
boolean |
getScrollableTracksViewportWidth() |
int |
getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
int orientation,
int direction) |
java.lang.String |
getToolTipText(java.awt.event.MouseEvent evt)
Given a MouseEvent, determines what text to place in the floating
tool tip when the the mouse hovers over this location.
|
Grid |
grid()
Gets the grid.
|
boolean |
gridLinesAreVisible()
Returns
true if the grid lines are visible,
false otherwise. |
int |
innerCellSize()
Returns the size of each cell, not including the width of a grid line.
|
boolean |
isPannableUnbounded() |
Location |
locationForPoint(java.awt.Point p)
Given a Point, determines which grid location (if any)
is under the mouse.
|
void |
makeGridLinesVisible(boolean visible)
Makes the gridlines visible or invisible, depending on the value
of the
visible parameter. |
void |
makeToolTipsReportLocation()
Sets tool tips to provide information about the locations
of cells in the grid.
|
void |
makeToolTipsReportObject()
Sets tool tips to provide information about the contents
of cells in the grid.
|
int |
minimumCellSize()
Gets the minimum cell size.
|
void |
paintComponent(java.awt.Graphics g)
Paints this component.
|
void |
panBy(int hDelta,
int vDelta) |
void |
reactToNewGrid(Grid newGrid)
Reacts to a change in grids being used.
|
protected void |
recalculateCellSize()
Calculates the cell size to use given the current viewable region and
the number of rows and columns in the grid.
|
void |
recenterOnOrigin()
Pans the display back to the origin, so that 0, 0 is at the
the upper left of the visible viewport.
|
void |
resetToolTips()
Resets tool tips to be enabled or disabled, as specified by the
most recent call to the
setToolTipsEnabled method. |
int |
rowToYCoord(int row)
Returns Y-coordinate of top of given row.
|
void |
setBackgroundColor(java.awt.Color newBackgroundColor)
Sets the background color for displaying the grid.
|
void |
setBackgroundDisplay(GridBackgroundDisplay bgDisplay)
Sets the object used to draw the background.
|
void |
setGrid(Grid grid)
Sets the Grid being displayed.
|
void |
setToolTipsEnabled(boolean flag)
Enables/disables showing of tooltip giving information about
the grid object beneath the mouse.
|
void |
showGrid()
Shows the grid.
|
void |
temporarilyDisableToolTips()
Temporarily disables tool tips (for a stepped application
that is in running mode, for example).
|
boolean |
toolTipsEnabled()
Indicates whether tool tips are currently enabled.
|
boolean |
toolTipsSetToBeEnabled()
Indicates whether tool tips were set to be enabled.
|
void |
updateLocation(Location loc)
Updates the display of just a single location on the grid.
|
protected int |
xCoordToCol(int xCoord)
Returns column corresponding to given X-coordinate.
|
protected int |
yCoordToRow(int yCoord)
Returns row corresponding to given Y-coordinate.
|
void |
zoomIn()
Zooms in the display by doubling the current cell size.
|
void |
zoomOut()
Zooms out the display by halving the current cell size.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIaddAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCyclepublic static final int DEFAULT_MIN_CELL_SIZE
public static final int DEFAULT_VIEWABLE_SIZE
public static final java.awt.Color OCEAN_BLUE
protected static final int LOCATION_TOOL_TIPS
protected static final int OBJECT_STRING_TOOL_TIPS
protected Grid theGrid
protected java.awt.Dimension preferredVPSize
protected int gridLineWidth
protected int minCellSize
protected int outerCellSize
protected int numRows
protected int numCols
protected int originRow
protected int originCol
protected GridBackgroundDisplay backgroundDisplay
protected java.awt.Color bgColor
protected boolean toolTipsSetEnabledFlag
protected boolean toolTipsEnabledFlag
protected int toolTipsType
public ScrollableGridDisplay()
public ScrollableGridDisplay(int width,
int height)
width and height must be
at least as large as the default minimum cell size.)width - the width of the viewing areaheight - the height of the viewing areapublic ScrollableGridDisplay(int minimumCellSize)
minimumCellSize - minimum cell side lengthpublic ScrollableGridDisplay(int width,
int height,
int minimumCellSize)
width and height must be
at least as large as minimumCellSize.)width - the width of the viewing areaheight - the height of the viewing areaminimumCellSize - minimum cell side lengthpublic ScrollableGridDisplay(java.awt.Color backgroundColor)
backgroundColor - color to paint background of gridpublic ScrollableGridDisplay(int width,
int height,
java.awt.Color backgroundColor)
width and height must be
at least as large as the default minimum cell size.)width - the width of the viewing areaheight - the height of the viewing areabackgroundColor - color to paint background of gridpublic ScrollableGridDisplay(int minimumCellSize,
java.awt.Color backgroundColor)
minimumCellSize - minimum cell side lengthbackgroundColor - color to paint background of gridpublic ScrollableGridDisplay(int viewingWidth,
int viewingHeight,
int minimumCellSize,
java.awt.Color backgroundColor)
width and height must be
at least as large as minimumCellSize.)viewingWidth - the width of the viewing areaviewingHeight - the height of the viewing areaminimumCellSize - minimum cell side lengthbackgroundColor - color to paint background of gridpublic void setGrid(Grid grid)
setGrid in interface GridDisplaygrid - the Grid to displaypublic void reactToNewGrid(Grid newGrid)
GridChangeListenerreactToNewGrid in interface GridChangeListenernewGrid - the new grid being usedpublic javax.swing.JViewport getEnclosingViewport()
protected void recalculateCellSize()
protected int calculateGridLineWidth()
public int innerCellSize()
public Grid grid()
public int minimumCellSize()
public void setBackgroundDisplay(GridBackgroundDisplay bgDisplay)
public java.awt.Color backgroundColor()
public void setBackgroundColor(java.awt.Color newBackgroundColor)
public void makeGridLinesVisible(boolean visible)
visible parameter. The gridlines are visible
by default.visible - whether to make the gridlines visible (true)
or invisible (false)public boolean gridLinesAreVisible()
true if the grid lines are visible,
false otherwise.public void showGrid()
repaint method is the standard way to ask a
Swing component to redraw itself. This eventually turns into a call
back to our version of the standard paintComponent
method where we do the actual drawing.showGrid in interface GridDisplaypublic void updateLocation(Location loc)
public void paintComponent(java.awt.Graphics g)
paintComponent in class javax.swing.JComponentg - the Graphics object to use to render this componentpublic void drawBackground(java.awt.Graphics2D g2)
drawBackground in interface GridBackgroundDisplayg2 - the Graphics2 object to use to renderpublic void fillBackground(java.awt.Graphics2D g2,
java.awt.Color fillColor)
g2 - the Graphics2 object to use to renderfillColor - the color with which to fill the backgroundprotected void drawGridlines(java.awt.Graphics2D g2)
g2 - the Graphics2 object to use to renderprotected void drawGridObject(java.awt.Graphics2D g2,
GridObject obj)
g2 - the Graphics2D object to use to renderobj - the GridObject object to drawpublic int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
int orientation,
int direction)
getScrollableUnitIncrement in interface javax.swing.Scrollablepublic int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
int orientation,
int direction)
getScrollableBlockIncrement in interface javax.swing.Scrollablepublic boolean getScrollableTracksViewportWidth()
getScrollableTracksViewportWidth in interface javax.swing.Scrollablepublic boolean getScrollableTracksViewportHeight()
getScrollableTracksViewportHeight in interface javax.swing.Scrollablepublic java.awt.Dimension getPreferredScrollableViewportSize()
getPreferredScrollableViewportSize in interface javax.swing.Scrollablepublic void zoomIn()
public void zoomOut()
public void recenterOnOrigin()
public void panBy(int hDelta,
int vDelta)
panBy in interface PseudoInfiniteViewport.Pannablepublic boolean isPannableUnbounded()
isPannableUnbounded in interface PseudoInfiniteViewport.Pannablepublic java.lang.String getPannableTipText()
getPannableTipText in interface PseudoInfiniteViewport.Pannablepublic void setToolTipsEnabled(boolean flag)
flag - whether to enable/disable tool tipspublic boolean toolTipsSetToBeEnabled()
true but
for tooTipsEnabled to return false\
if tool tips were set to be enabled but have been temporarily
disabled (if a stepped application is in running mode, for example).true if tool tips are enabled;
false otherwisepublic void temporarilyDisableToolTips()
public void resetToolTips()
setToolTipsEnabled method.public boolean toolTipsEnabled()
true if tool tips are enabled;
false otherwisepublic void makeToolTipsReportLocation()
public void makeToolTipsReportObject()
public java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
getToolTipText in class javax.swing.JComponentevt - the MouseEvent in questionpublic Location locationForPoint(java.awt.Point p)
p - the Point in question (in display's coordinate system)protected int xCoordToCol(int xCoord)
protected int yCoordToRow(int yCoord)
public int colToXCoord(int col)
public int rowToYCoord(int row)
public java.awt.Dimension getPreferredSize()
getPreferredSize in class javax.swing.JComponentpublic java.awt.Dimension getMinimumSize()
getMinimumSize in class javax.swing.JComponentprotected int extraWidth()
protected int extraHeight()