Generic Environment GUI Class Library

Class ScrollableEnvDisplay

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--ScrollableEnvDisplay
All Implemented Interfaces:
javax.accessibility.Accessible, EnvDisplay, java.awt.image.ImageObserver, java.awt.MenuContainer, PseudoInfiniteViewport.Pannable, javax.swing.Scrollable, java.io.Serializable, SettableEnvDisplay

public class ScrollableEnvDisplay
extends javax.swing.JPanel
implements SettableEnvDisplay, javax.swing.Scrollable, PseudoInfiniteViewport.Pannable

Environment-Based Applications:
A ScrollableEnvDisplay is a panel containing a scrollable graphical display of an environment.

Version:
1 September 2002
See Also:
Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  java.awt.Color bgColor
           
protected  int cellSize
           
protected static int DEFAULT_MIN_CELL_SIZE
           
protected static int DEFAULT_VIEWABLE_SIZE
           
protected  int displayHeight
           
protected  int displayWidth
           
protected static int LOCATION_TOOL_TIPS
           
protected  int minCellSize
           
protected  int numCols
           
protected  int numRows
           
protected static int OBJECT_STRING_TOOL_TIPS
           
protected static java.awt.Color OCEAN_BLUE
           
protected  int originCol
           
protected  int originRow
           
protected  Environment theEnv
           
protected  boolean toolTipsEnabledFlag
           
protected  int toolTipsType
           
protected  boolean visibleGridLines
           
 
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.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ScrollableEnvDisplay()
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
ScrollableEnvDisplay(java.awt.Color backgroundColor)
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
ScrollableEnvDisplay(int minimumCellSize)
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
ScrollableEnvDisplay(int minimumCellSize, java.awt.Color backgroundColor)
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
ScrollableEnvDisplay(int width, int height)
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
ScrollableEnvDisplay(int width, int height, java.awt.Color backgroundColor)
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
ScrollableEnvDisplay(int width, int height, int minimumCellSize)
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
ScrollableEnvDisplay(int viewingWidth, int viewingHeight, int minimumCellSize, java.awt.Color backgroundColor)
          Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
 
Method Summary
 java.awt.Color backgroundColor()
          Gets the background color for displaying the environment.
protected  int colToXCoord(int col)
           
protected  void drawGridlines(java.awt.Graphics2D g2)
          Draws the gridlines for the environment.
protected  void drawLocatable(java.awt.Graphics2D g2, Locatable obj)
          Draws one environment object.
 Environment environment()
          Gets the environment.
protected  int extraHeight()
           
protected  int extraWidth()
           
protected  javax.swing.JViewport getEnclosingViewport()
           
 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.
 boolean gridLinesAreVisible()
          Returns true if the grid lines are visible, false otherwise.
 boolean isPannableUnbounded()
           
 Location locationForPoint(java.awt.Point p)
          Given a Point, determines which environment 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 environment.
 void makeToolTipsReportObject()
          Sets tool tips to provide information about the contents of cells in the environment.
 int minimumCellSize()
          Gets the minimum cell size.
 void paint(java.awt.Graphics g)
          Shows the environment.
 void paintComponent(java.awt.Graphics g)
          Paints this component.
 void panBy(int hDelta, int vDelta)
           
protected  void recalculateCellSize(javax.swing.JViewport vp, int minSize)
          Calculates the cell size to use given the current viewable region and the the number of rows and columns in the environment.
 void recenterOnOrigin()
          Pans the display back to the origin, so that 0, 0 is at the the upper left of the visible viewport.
protected  int rowToYCoord(int row)
           
 void setBackgroundColor(java.awt.Color newBackgroundColor)
          Sets the background color for displaying the environment.
 void setEnv(Environment env)
          Sets the Environment being displayed.
 void setToolTipsEnabled(boolean flag)
          Enables/disables showing of tooltip giving information about the environment object beneath the mouse.
 void showEnv()
          Shows the environment.
 boolean toolTipsEnabled()
          Indicates whether tool tips have been enabled.
protected  int xCoordToCol(int xCoord)
           
protected  int yCoordToRow(int yCoord)
           
 void zoomIn()
          Zooms in the display by doubling the current cell size.
 void zoomOut()
          Zooms out the display by halving the current cell size.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, 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, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_MIN_CELL_SIZE

protected static final int DEFAULT_MIN_CELL_SIZE

DEFAULT_VIEWABLE_SIZE

protected static final int DEFAULT_VIEWABLE_SIZE

OCEAN_BLUE

protected static final java.awt.Color OCEAN_BLUE

LOCATION_TOOL_TIPS

protected static final int LOCATION_TOOL_TIPS

OBJECT_STRING_TOOL_TIPS

protected static final int OBJECT_STRING_TOOL_TIPS

theEnv

protected Environment theEnv

displayWidth

protected int displayWidth

displayHeight

protected int displayHeight

minCellSize

protected int minCellSize

numRows

protected int numRows

numCols

protected int numCols

originRow

protected int originRow

originCol

protected int originCol

cellSize

protected int cellSize

bgColor

protected java.awt.Color bgColor

visibleGridLines

protected boolean visibleGridLines

toolTipsEnabledFlag

protected boolean toolTipsEnabledFlag

toolTipsType

protected int toolTipsType
Constructor Detail

ScrollableEnvDisplay

public ScrollableEnvDisplay()
Constructs a new ScrollableEnvDisplay object with no environment and an empty view.

ScrollableEnvDisplay

public ScrollableEnvDisplay(int width,
                            int height)
Constructs a new ScrollableEnvDisplay object with no environment and an empty view. (Precondition: width > 0 and height > 0.)
Parameters:
width - the width of the viewing area
height - the height of the viewing area

ScrollableEnvDisplay

public ScrollableEnvDisplay(int minimumCellSize)
Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
Parameters:
minimumCellSize - minimum cell side length

ScrollableEnvDisplay

public ScrollableEnvDisplay(int width,
                            int height,
                            int minimumCellSize)
Constructs a new ScrollableEnvDisplay object with no environment and an empty view. (Precondition: width > 0 and height > 0.)
Parameters:
width - the width of the viewing area
height - the height of the viewing area
minimumCellSize - minimum cell side length

ScrollableEnvDisplay

public ScrollableEnvDisplay(java.awt.Color backgroundColor)
Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
Parameters:
backgroundColor - color to paint background of environment

ScrollableEnvDisplay

public ScrollableEnvDisplay(int width,
                            int height,
                            java.awt.Color backgroundColor)
Constructs a new ScrollableEnvDisplay object with no environment and an empty view. (Precondition: width > 0 and height > 0.)
Parameters:
width - the width of the viewing area
height - the height of the viewing area
backgroundColor - color to paint background of environment

ScrollableEnvDisplay

public ScrollableEnvDisplay(int minimumCellSize,
                            java.awt.Color backgroundColor)
Constructs a new ScrollableEnvDisplay object with no environment and an empty view.
Parameters:
minimumCellSize - minimum cell side length
backgroundColor - color to paint background of environment

ScrollableEnvDisplay

public ScrollableEnvDisplay(int viewingWidth,
                            int viewingHeight,
                            int minimumCellSize,
                            java.awt.Color backgroundColor)
Constructs a new ScrollableEnvDisplay object with no environment and an empty view. (Precondition: width > 0 and height > 0.)
Parameters:
viewingWidth - the width of the viewing area
viewingHeight - the height of the viewing area
minimumCellSize - minimum cell side length
backgroundColor - color to paint background of environment
Method Detail

setEnv

public void setEnv(Environment env)
Sets the Environment being displayed. Sets the cell size to be the largest that fits the entire environment in the current viewing area (uses a default minimum if environment is too large). (Precondition: env is not null.)
Specified by:
setEnv in interface SettableEnvDisplay
Parameters:
env - the Environment to display

getEnclosingViewport

protected javax.swing.JViewport getEnclosingViewport()

recalculateCellSize

protected void recalculateCellSize(javax.swing.JViewport vp,
                                   int minSize)
Calculates the cell size to use given the current viewable region and the the number of rows and columns in the environment. We use the largest cellSize that will fit in the viewable region, bounded to be at least the parameter minSize.
Parameters:
vp - the view port that represents the viewable region
minSize - the minimum size for the side of a cell

environment

public Environment environment()
Gets the environment.

minimumCellSize

public int minimumCellSize()
Gets the minimum cell size.

backgroundColor

public java.awt.Color backgroundColor()
Gets the background color for displaying the environment.

setBackgroundColor

public void setBackgroundColor(java.awt.Color newBackgroundColor)
Sets the background color for displaying the environment.

makeGridLinesVisible

public void makeGridLinesVisible(boolean visible)
Makes the gridlines visible or invisible, depending on the value of the visible parameter. The gridlines are visible by default.
Parameters:
visible - whether to make the gridlines visible (true) or invisible (false)

gridLinesAreVisible

public boolean gridLinesAreVisible()
Returns true if the grid lines are visible, false otherwise.

showEnv

public void showEnv()
Shows the environment. This is the one required method in the EnvDisplay interface. Invoking the 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 the standard paintComponent method where we do the actual drawing.
Specified by:
showEnv in interface SettableEnvDisplay

paint

public void paint(java.awt.Graphics g)
Shows the environment. This is the one required method in the EnvDisplay interface. Invoking the 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 the standard paintComponent method where we do the actual drawing.
Overrides:
paint in class javax.swing.JComponent

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints this component.
Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the Graphics object to use to render this component

drawGridlines

protected void drawGridlines(java.awt.Graphics2D g2)
Draws the gridlines for the environment. We only draw the portion of the lines that intersect the current clipping bounds.
Parameters:
g2 - the Graphics2 object to use to render

drawLocatable

protected void drawLocatable(java.awt.Graphics2D g2,
                             Locatable obj)
Draws one environment object. First verifies that the object is actually visible before any drawing, sets up the clip appropriately and uses the DisplayMap to determine which object to call upon to render this particular Locatable. Note that we save and restore the graphics transform to restore back to normalcy no matter what the renderer did to to the coordinate system.
Parameters:
g2 - the Graphics2D object to use to render
obj - the Locatable object to draw

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable

zoomIn

public void zoomIn()
Zooms in the display by doubling the current cell size.

zoomOut

public void zoomOut()
Zooms out the display by halving the current cell size.

recenterOnOrigin

public void recenterOnOrigin()
Pans the display back to the origin, so that 0, 0 is at the the upper left of the visible viewport.

panBy

public void panBy(int hDelta,
                  int vDelta)
Specified by:
panBy in interface PseudoInfiniteViewport.Pannable

isPannableUnbounded

public boolean isPannableUnbounded()
Specified by:
isPannableUnbounded in interface PseudoInfiniteViewport.Pannable

getPannableTipText

public java.lang.String getPannableTipText()
Specified by:
getPannableTipText in interface PseudoInfiniteViewport.Pannable

setToolTipsEnabled

public void setToolTipsEnabled(boolean flag)
Enables/disables showing of tooltip giving information about the environment object beneath the mouse.
Parameters:
flag - whether to enable/disable tool tips

toolTipsEnabled

public boolean toolTipsEnabled()
Indicates whether tool tips have been enabled.
Returns:
true if tool tips are enabled; false otherwise

makeToolTipsReportLocation

public void makeToolTipsReportLocation()
Sets tool tips to provide information about the locations of cells in the environment.

makeToolTipsReportObject

public void makeToolTipsReportObject()
Sets tool tips to provide information about the contents of cells in the environment.

getToolTipText

public 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. If the mouse is over a valid environment cell, we provide some information about the cell and its contents. This method is automatically called on mouse-moved events if we register for tool tips.
Overrides:
getToolTipText in class javax.swing.JComponent
Parameters:
evt - the MouseEvent in question
Returns:
the tool tip string for this location

locationForPoint

public Location locationForPoint(java.awt.Point p)
Given a Point, determines which environment location (if any) is under the mouse. This method is used by the GUI when generating text tips.
Parameters:
p - the Point in question (in display's coordinate system)
Returns:
the environment Location beneath the event, or null if no cell is beneath the mouse

xCoordToCol

protected int xCoordToCol(int xCoord)

yCoordToRow

protected int yCoordToRow(int yCoord)

colToXCoord

protected int colToXCoord(int col)

rowToYCoord

protected int rowToYCoord(int row)

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the desired size of the display, for use by layout manager.
Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
preferred size

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the minimum size of the display, for use by layout manager.
Overrides:
getMinimumSize in class javax.swing.JComponent
Returns:
minimum size

extraWidth

protected int extraWidth()

extraHeight

protected int extraHeight()

Generic Environment GUI Class Library

Copyright© 2003 Alyce Brady