hades.gui
Class CanvasScroller

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byhades.gui.CanvasScroller
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.AdjustmentListener, java.awt.event.ComponentListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseMotionListener, java.io.Serializable, ZoomListener

public class CanvasScroller
extends java.awt.Panel
implements java.awt.event.AdjustmentListener, java.awt.event.ComponentListener, java.awt.event.MouseMotionListener, ZoomListener

CanvasScroller - an AWT component to manage a JavaFIG/HADES editor canvas with rulers at the top and left sides, and additional standard right and bottom scrollbars. Also, a simple Label field is provided to display the current mouse coordinates and zoom factor.

This class needs to be provided with the (real or approximate) bounding box of all visible objects, in order to calculate and set the size and position of the scrollbar thumbs. The thumbs are sized to match the ratio of the visible region to the union of the visible region plus the bounding box of all displayed objects.
Remember to call 'setObjectBoundingBox( xl, yt, xr, yb )' after any editing operation in your application which changes this bounding box - otherwise the visible objects will not match the user expectations built from the scrollbar sizes.
Usually, you may want to initialize the bounding box with a suitable default value. For example, call setObjectBoundingBox( 0, 0, 28000, 18600 ) to initialize the CanvasScroller to (approximate) "A4 paper size" in landscape orientation. This is also the default object bounding box used. See class jfig.canvas.FigTrafo2D for documentation about the coordinate system used in JavaFIG/HADES (2400 dpi world coords, origin at top left).

Usually, the default behaviour of scrollbars is to clip all scrolling to the limit of the underlying data model: Once you arrive at the end of your document, you cannot scroll further. This is the default behaviour of CanvasScroller, where the limit of the 'allowed' region is set by calling setObjectBoundingBox.

However, in order to get the xfig/JavaFIG/HADES behaviour of enlarging the current object region as needed, CanvasScroller also implements a variant of the above strategy, where the scrollbars are not clipped to the visible region or any other predefined values. Instead, the scrollbar thumbs are clipped after each event, to allow one more click in the respective direction. For simplicity, scrollbar values are used in the range 0 ... 99. Therefore, we clip the scrollbar thumb position to the range 1 .. 98. Call setClipToBoudingBox( boolean ) to switch the scrollbar clipping on or off.

See Also:
Serialized Form

Nested Class Summary
(package private)  class CanvasScroller.DummyObjectEnumerator
           
(package private)  class CanvasScroller.Filler
          inner class Filler: used to fill the bottom right corner in a BorderLayout with two Scrollbars
(package private)  class CanvasScroller.InfoLabel
           
 
Nested classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.Panel bottomPanel
           
protected  boolean clipToObjectBoundingBox
           
protected  java.awt.Label coordLabel
           
protected  FigCanvas editorCanvas
           
protected  CanvasScroller.Filler filler
           
protected  CanvasScroller.InfoLabel infoLabel
           
protected  java.awt.Panel labelPanel
           
protected  FigBbox objectBBox
           
protected  java.awt.Scrollbar scrollbarX
           
protected  java.awt.Scrollbar scrollbarY
           
protected  FigBbox totalBBox
           
protected  FigBbox visibleRegionBBox
           
protected  java.awt.Label zoomLabel
           
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CanvasScroller(FigCanvas _canvas)
           
 
Method Summary
 void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)
           
(package private)  void buildGUI()
           
 int clip(int value, int min_value, int max_value)
           
 void componentHidden(java.awt.event.ComponentEvent evt)
           
 void componentMoved(java.awt.event.ComponentEvent evt)
           
 void componentResized(java.awt.event.ComponentEvent evt)
           
 void componentShown(java.awt.event.ComponentEvent evt)
           
 void doLayout()
           
 int getScrollbarWidth()
           
static void main(java.lang.String[] argv)
           
 void mouseDragged(java.awt.event.MouseEvent evt)
           
 void mouseMoved(java.awt.event.MouseEvent evt)
           
static void msg(java.lang.String s)
           
 void rebuildBoundingBoxes()
           
 void rebuildScrollbars()
          rebuild the scrollbar thumbs, assuming that the visible region and object bounding boxes are set correctly (by a previous call to rebuildBoundingBoxes).
 void setCanvas(FigCanvas _canvas)
           
 void setClipToObjectBoundingBox(boolean b)
           
 void setObjectBoundingBox(int xl, int yt, int xr, int yb)
           
 void trackScrollbarX()
           
 void trackScrollbarY()
           
 void zoomChanged(java.lang.Object arg)
           
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, 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, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, 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

editorCanvas

protected FigCanvas editorCanvas

bottomPanel

protected java.awt.Panel bottomPanel

labelPanel

protected java.awt.Panel labelPanel

scrollbarX

protected java.awt.Scrollbar scrollbarX

scrollbarY

protected java.awt.Scrollbar scrollbarY

coordLabel

protected java.awt.Label coordLabel

zoomLabel

protected java.awt.Label zoomLabel

filler

protected CanvasScroller.Filler filler

infoLabel

protected CanvasScroller.InfoLabel infoLabel

objectBBox

protected FigBbox objectBBox

visibleRegionBBox

protected FigBbox visibleRegionBBox

totalBBox

protected FigBbox totalBBox

clipToObjectBoundingBox

protected boolean clipToObjectBoundingBox
Constructor Detail

CanvasScroller

public CanvasScroller(FigCanvas _canvas)
Method Detail

setCanvas

public void setCanvas(FigCanvas _canvas)

buildGUI

void buildGUI()

getScrollbarWidth

public int getScrollbarWidth()

doLayout

public void doLayout()

rebuildBoundingBoxes

public void rebuildBoundingBoxes()

setObjectBoundingBox

public void setObjectBoundingBox(int xl,
                                 int yt,
                                 int xr,
                                 int yb)

setClipToObjectBoundingBox

public void setClipToObjectBoundingBox(boolean b)

rebuildScrollbars

public void rebuildScrollbars()
rebuild the scrollbar thumbs, assuming that the visible region and object bounding boxes are set correctly (by a previous call to rebuildBoundingBoxes).


clip

public int clip(int value,
                int min_value,
                int max_value)

componentHidden

public void componentHidden(java.awt.event.ComponentEvent evt)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent evt)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent evt)
Specified by:
componentShown in interface java.awt.event.ComponentListener

componentResized

public void componentResized(java.awt.event.ComponentEvent evt)
Specified by:
componentResized in interface java.awt.event.ComponentListener

adjustmentValueChanged

public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)
Specified by:
adjustmentValueChanged in interface java.awt.event.AdjustmentListener

trackScrollbarX

public void trackScrollbarX()

trackScrollbarY

public void trackScrollbarY()

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent evt)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent evt)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

zoomChanged

public void zoomChanged(java.lang.Object arg)
Specified by:
zoomChanged in interface ZoomListener

msg

public static void msg(java.lang.String s)

main

public static void main(java.lang.String[] argv)