y.view
Class NavigationComponent

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by y.view.NavigationComponent
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class NavigationComponent
extends JPanel

This component provides several controls to navigate inside a graph. The component consists of two main control groups named navigation controls and zoom controls. The navigation controls consist of 4 button, that provide a scroll functionality and one button to fi the graph content to the view. The zoom controls consist of a zoom slider and two buttons to zoom in and zoom out. One can define the alignment of both control groups to each other using method setOrientation(byte). The fit content button inside the navigation controls can be disabled using method setShowFitContentButton(boolean). Furthermor the zoom in and zoom out buttons can be hidden setShowZoomButtons(boolean). The step size used for the navigation buttons can be determined using method setScrollStepSize(double). By default this stepsize is 10 pixels for zoom level 1 and the stepsize will scale with the zoom level. This can be disabled using method setConsiderZoomLevel(boolean). When using the scroll buttons of the navigation controls, one can determine the repeat timer delay of those buttons by setting client property "NavigationComponent.ScrollTimerDelay" JComponent.putClientProperty(Object, Object) (e.g. to new Integer(30) which is default). Accordingly the initial timer delay can be set "NavigationComponent.ScrollTimerInitialDelay". (e.g. to new Integer(300), which is default). When using the fit content button setShowFitContentButton(boolean) one can determine whether the view transformation shall be animated or not by settng client property "NavigationComponent.AnimateFitContent". By default the animation is not enabled. JComponent.putClientProperty(Object, Object) to Boolean.TRUE;

See Also:
Serialized Form
 

Nested Class Summary
protected  class NavigationComponent.FitContentAction
          This action is used for the fit content button of the navigation controls.
protected  class NavigationComponent.ZoomAction
          This action is used for the zoom buttons of the zoom controls.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static byte ORIENTATION_BOTTOM_TO_TOP
          Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.
static byte ORIENTATION_LEFT_TO_RIGHT
          Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.
static byte ORIENTATION_RIGHT_TO_LEFT
          Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.
static byte ORIENTATION_TOP_TO_BOTTOM
          Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.
protected static byte SCROLL_DIRECTION_DOWN
           
protected static byte SCROLL_DIRECTION_LEFT
           
protected static byte SCROLL_DIRECTION_RIGHT
           
protected static byte SCROLL_DIRECTION_UP
           
protected  Graph2DView view
           
 
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
NavigationComponent(Graph2DView view)
           
 
Method Summary
protected  JButton createFitContentButton()
          Creates the button in the middle of the navigation controls.
protected  Icon createFitContentIcon()
          This method can be overwritten to return a custom icon for the created fit content button createFitContentButton()
protected  JButton createScrollButton(byte direction)
           
protected  Icon createScrollIcon(byte direction)
          This method can be overwritten to return a custom icon for the created scroll buttons createScrollButton(byte).
protected  JButton createZoomButton(boolean zoomIn)
          Creates the buttons above and below the zoom slider.
protected  Icon createZoomIcon(boolean zoomIn)
          This method can be overwritten to return a custom icon for the created zoom icons createZoomIcon(boolean).
protected  JSlider createZoomSlider(byte orientation)
          Creates the zoom slider that is used to zoom in and out of the graph.
 byte getOrientation()
          Returns an orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.
 double getScrollStepSize()
          Returns the step size used for the navigation buttons.
 boolean isConsiderZoomLevel()
          Returns whether the navigation scroll buttons shall take the zoom level into account when scrolling.
 boolean isShowFitContentButton()
          Whether the fit content button is shown.
 boolean isShowNavigationControls()
          Whether or not the navigation controls are shown.
 boolean isShowZoomButtons()
          Whether the zoom in and zoom out buttons are shown.
 boolean isShowZoomSlider()
          Whether the zoom slider is shown or not.
protected  void paintComponent(Graphics g)
           
 void setConsiderZoomLevel(boolean considerZoomLevel)
          Determines whether the navigation scroll buttons shall take the zoom level into account when scrolling.
 void setOrientation(byte orientation)
          Sets the orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.
 void setScrollStepSize(double stepSize)
          Determines the stepsize used for the navigation buttons.
 void setShowFitContentButton(boolean showFitContentButton)
          Whether the fit content button shall be shown.
 void setShowNavigationControls(boolean showNavigationControls)
          Determines whether or not the navigation controls are shown.
 void setShowZoomButtons(boolean showZoomButtons)
          Determines whether the zoom in and zoom out buttons shall be shown.
 void setShowZoomSlider(boolean showZoomSlider)
          Determines whether the zoom slider shall be shown.
protected  void updateComponents()
          Will fill the main panel with the components specified by the diverse settings.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, 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, update
 
Methods inherited from class java.awt.Container
add, 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, 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, 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, hide, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ORIENTATION_TOP_TO_BOTTOM

public static final byte ORIENTATION_TOP_TO_BOTTOM
Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned. This option will place the navigation controls above the zoom controls. The zoom slider will be drawn vertical.

See Also:
Constant Field Values

ORIENTATION_LEFT_TO_RIGHT

public static final byte ORIENTATION_LEFT_TO_RIGHT
Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned. This option will place the navigation controls left to the zoom controls. The zoom slider will be drawn horizontal.

See Also:
Constant Field Values

ORIENTATION_BOTTOM_TO_TOP

public static final byte ORIENTATION_BOTTOM_TO_TOP
Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned. This option will place the navigation controls below the zoom controls. The zoom slider will be drawn vertical.

See Also:
Constant Field Values

ORIENTATION_RIGHT_TO_LEFT

public static final byte ORIENTATION_RIGHT_TO_LEFT
Orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned. This option will place the navigation controls right to the zoom controls. The zoom slider will be drawn horizontal.

See Also:
Constant Field Values

SCROLL_DIRECTION_UP

protected static final byte SCROLL_DIRECTION_UP
See Also:
Constant Field Values

SCROLL_DIRECTION_DOWN

protected static final byte SCROLL_DIRECTION_DOWN
See Also:
Constant Field Values

SCROLL_DIRECTION_RIGHT

protected static final byte SCROLL_DIRECTION_RIGHT
See Also:
Constant Field Values

SCROLL_DIRECTION_LEFT

protected static final byte SCROLL_DIRECTION_LEFT
See Also:
Constant Field Values

view

protected final Graph2DView view
Constructor Detail

NavigationComponent

public NavigationComponent(Graph2DView view)
Method Detail

paintComponent

protected void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

updateComponents

protected void updateComponents()
Will fill the main panel with the components specified by the diverse settings.


createScrollButton

protected JButton createScrollButton(byte direction)
Parameters:
direction - the direction to which the created button shall scroll. One of SCROLL_DIRECTION_UP, SCROLL_DIRECTION_DOWN, SCROLL_DIRECTION_LEFT, SCROLL_DIRECTION_RIGHT
Returns:
a button that will perform a scroll action to the given direction with the given stepsize.
See Also:
createScrollIcon(byte)

createScrollIcon

protected Icon createScrollIcon(byte direction)
This method can be overwritten to return a custom icon for the created scroll buttons createScrollButton(byte).

Parameters:
direction - the direction to which the created button shall scroll. One of SCROLL_DIRECTION_UP, SCROLL_DIRECTION_DOWN, SCROLL_DIRECTION_LEFT, SCROLL_DIRECTION_RIGHT.
Returns:
an icon that is used for the created scroll buttons.
See Also:
createScrollButton(byte)

createFitContentButton

protected JButton createFitContentButton()
Creates the button in the middle of the navigation controls. This button will fit the graph to the current view dimensions and by clicking a second time will zoom back to the previous level and coordinate. This allows some kind of quick birds-eye view on the graph

Returns:
a JButton that will perform the above described behavior
See Also:
createFitContentIcon(), setShowFitContentButton(boolean)

createFitContentIcon

protected Icon createFitContentIcon()
This method can be overwritten to return a custom icon for the created fit content button createFitContentButton()

Returns:
an icon that is used for the created fit content button.
See Also:
createFitContentButton()

createZoomButton

protected JButton createZoomButton(boolean zoomIn)
Creates the buttons above and below the zoom slider. These are by default used to zoom in and zoom out.

Parameters:
zoomIn - whether a zoom in button (true) or a zoom out button (false) shall be created.
Returns:
a JButton that will zoom in or out of the graph.
See Also:
createZoomIcon(boolean), setShowZoomButtons(boolean)

createZoomIcon

protected Icon createZoomIcon(boolean zoomIn)
This method can be overwritten to return a custom icon for the created zoom icons createZoomIcon(boolean).

Parameters:
zoomIn - whether an icon for a zoom in button (true) or a zoom out button (false) shall be created.
Returns:
an icon that is used for the created zoom in and zoom out buttons.
See Also:
createZoomButton(boolean)

createZoomSlider

protected JSlider createZoomSlider(byte orientation)
Creates the zoom slider that is used to zoom in and out of the graph.

Parameters:
orientation - the orientation of the main component, that also is used to determine the slider orientation. ORIENTATION_LEFT_TO_RIGHT and ORIENTATION_RIGHT_TO_LEFT will usually lead to a horizontal slider, while ORIENTATION_TOP_TO_BOTTOM and ORIENTATION_BOTTOM_TO_TOP will lead to a vertical slider.
Returns:
a slider that is used to zoom in and out of the graph.

isShowNavigationControls

public boolean isShowNavigationControls()
Whether or not the navigation controls are shown. The navigation controls consist of the scroll buttons created using method createScrollButton(byte) and a button to fit the content created using createFitContentButton(). By default all navigation controls are shown. One can specify to not show the fit content button using method showFitContentButton.

Returns:
  • true - if the navigation controls are shown (default)
  • false - if the navigation controls are not shown

setShowNavigationControls

public void setShowNavigationControls(boolean showNavigationControls)
Determines whether or not the navigation controls are shown. The navigation controls consist of the scroll buttons created using method createScrollButton(byte) and a button to fit the content created using createFitContentButton(). By default all navigation controls are shown. One can specify to not show the fit content button using method setShowFitContentButton(boolean).

Parameters:
showNavigationControls -
  • true - if the navigation controls shall be shown (default)
  • false - if the navigation controls shall not be shown

isShowFitContentButton

public boolean isShowFitContentButton()
Whether the fit content button is shown. Note: Besides this setting, the navigation controls themselves need to be shown, too.

Returns:
  • true - if the fit content button shall be shown (default)
  • false - if the fit content button shall not be shown
See Also:
setShowNavigationControls(boolean)

setShowFitContentButton

public void setShowFitContentButton(boolean showFitContentButton)
Whether the fit content button shall be shown. Note: Besides this setting, the navigation controls themselves need to be shown, too.

Parameters:
showFitContentButton -
  • true - if the fit content button shall be shown (default)
  • false - if the fit content button shall not be shown
See Also:
setShowNavigationControls(boolean)

isShowZoomButtons

public boolean isShowZoomButtons()
Whether the zoom in and zoom out buttons are shown.

Returns:
  • true - if the zoom buttons are shown (default)
  • false - if the zoom buttons are not shown

setShowZoomButtons

public void setShowZoomButtons(boolean showZoomButtons)
Determines whether the zoom in and zoom out buttons shall be shown.

Parameters:
showZoomButtons -
  • true - if the zoom buttons shall be shown (default)
  • false - if the zoom buttons shall not be shown

isShowZoomSlider

public boolean isShowZoomSlider()
Whether the zoom slider is shown or not.

Returns:
  • true - if the zoom slider is shown (default)
  • false - if the zoom slider is not shown

setShowZoomSlider

public void setShowZoomSlider(boolean showZoomSlider)
Determines whether the zoom slider shall be shown.

Parameters:
showZoomSlider -
  • true - if the zoom slider shall be shown (default)
  • false - if the zoom slider shall not be shown

getScrollStepSize

public double getScrollStepSize()
Returns the step size used for the navigation buttons. By default this stepsize is 10 pixels. By default the stepsize will scale with the zoom level.

Returns:
the step size in pixels used for the navigation buttons. If the zoom level is beeing considered, this method will return the step size for zoom level 1.
See Also:
setConsiderZoomLevel(boolean)

setScrollStepSize

public void setScrollStepSize(double stepSize)
Determines the stepsize used for the navigation buttons. By default this stepsize is 10 pixels. By default the stepsize will scale with the zoom level.

Parameters:
stepSize - the stepsize that is used for the navigation buttons. If the zoom level is beeing considered, the stepsize is taken as the stepsize for zoom level 1.
See Also:
setConsiderZoomLevel(boolean)

getOrientation

public byte getOrientation()
Returns an orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.

Returns:
One of ORIENTATION_TOP_TO_BOTTOM (default), ORIENTATION_RIGHT_TO_LEFT, ORIENTATION_BOTTOM_TO_TOP, ORIENTATION_LEFT_TO_RIGHT.

setOrientation

public void setOrientation(byte orientation)
Sets the orientation specifier that is used to determine how the navigation controls and the zoom controls are aligned.

Parameters:
orientation - One of ORIENTATION_TOP_TO_BOTTOM (default), ORIENTATION_RIGHT_TO_LEFT, ORIENTATION_BOTTOM_TO_TOP, ORIENTATION_LEFT_TO_RIGHT.

isConsiderZoomLevel

public boolean isConsiderZoomLevel()
Returns whether the navigation scroll buttons shall take the zoom level into account when scrolling. By default this is enabled. The set scroll step size setScrollStepSize(double) will then be increased for zoom levels smaller than "1" and decreased for zoom levels greater than "1".

Returns:
  • true - if the scroll buttons do take the zoom level into account (default)
  • false - if the scroll buttons do not take the zoom level into account

setConsiderZoomLevel

public void setConsiderZoomLevel(boolean considerZoomLevel)
Determines whether the navigation scroll buttons shall take the zoom level into account when scrolling. By default this is enabled. The set scroll step size setScrollStepSize(double) will then be increased for zoom levels smaller than "1" and decreased for zoom levels greater than "1".

Parameters:
considerZoomLevel -
  • true - if the scroll buttons shall take the zoom level into account (default)
  • false - if the scroll buttons shall not take the zoom level into account