JHotDraw 6.0b1

org.jhotdraw.contrib.zoom
Class ZoomDrawingView

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 org.jhotdraw.standard.StandardDrawingView
                      extended by org.jhotdraw.contrib.zoom.ZoomDrawingView
All Implemented Interfaces:
java.awt.dnd.Autoscroll, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, DNDInterface, DrawingChangeListener, DrawingView

public class ZoomDrawingView
extends StandardDrawingView

A view that can display drawings at an arbitrary scale.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.jhotdraw.standard.StandardDrawingView
StandardDrawingView.DrawingViewKeyListener, StandardDrawingView.DrawingViewMouseListener, StandardDrawingView.DrawingViewMouseMotionListener
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class org.jhotdraw.standard.StandardDrawingView
MINIMUM_HEIGHT, MINIMUM_WIDTH, SCROLL_INCR, SCROLL_OFFSET
 
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
ZoomDrawingView(DrawingEditor editor)
           
ZoomDrawingView(DrawingEditor editor, int width, int height)
           
 
Method Summary
protected  java.awt.Point constrainPoint(java.awt.Point p)
          Constrain to user coordinates, not screen coordinates.
protected  java.awt.event.KeyListener createKeyListener()
           
protected  java.awt.event.MouseListener createMouseListener()
           
protected  java.awt.event.MouseMotionListener createMouseMotionListener()
           
 void deZoom(int x, int y)
          Sets the zoom scale to 1.0 and adjusts the scroll pane so that point (x, y) is in the center.
 void drawBackground(java.awt.Graphics g)
          Draws the background.
 void drawingInvalidated(DrawingChangeEvent e)
          Overridden to accumulate damage in an instance variable of this class.
 java.awt.Graphics getGraphics()
          Gets a graphic to draw into
 java.awt.Dimension getMinimumSize()
          Gets the minimum dimension of the drawing.
Fixed version (JHotDraw version has a bug).
 java.awt.Dimension getPreferredSize()
          Gets the preferred dimension of the drawing..
 double getScale()
           
 java.awt.Dimension getSize()
          Gets the size of the drawing.
 java.awt.Dimension getUserSize()
           
 java.awt.Dimension getViewportSize()
           
 double getZoomSpeed()
          Returns the current zoom speed
protected  boolean hasZoomSupport()
           
 void paint(java.awt.Graphics g)
          Paints the drawing view.
 void repairDamage()
          Overridden to scale damage to screen coordinates.
 void setDrawing(Drawing d)
          Sets and installs another drawing in the view.
 void setOriginPosition(java.awt.Point newOrigin)
          Sets the coordinates of the left top corner displayed by the view.
 void setUserSize(java.awt.Dimension d)
          Sets the size of this view in user coordinates.
 void setUserSize(int width, int height)
          Sets the size of this view in user coordinates.
protected  void setViewPosition(java.awt.Point newPosition)
           
 void setZoomSpeed(double newZoomSpeed)
          Set the zoom speed.
 void zoom(float newScale)
          Set this view's scale factor
 void zoom(int x, int y, int width, int height)
          Readjusts this view and its containing ScrollPane to display the given rectangle, which is given in user coordinates.
 void zoomIn(int x, int y)
          InContext Zooms in by a factor of the current scale, keeping point (x,y), which is given in user coordinates, in the center.
 void zoomOut(int x, int y)
          Zooms out by a factor of two, keeping point (x,y), which is given in user coordinates, in the center.
 
Methods inherited from class org.jhotdraw.standard.StandardDrawingView
add, addAll, addBackground, addFigureSelectionListener, addForeground, addToSelection, addToSelectionAll, addToSelectionAll, addToSelectionImpl, autoscroll, checkDamage, checkMinimumSize, clearSelection, clearToolTip, createDisplayUpdate, createDNDHelper, DNDDeinitialize, DNDInitialize, draw, drawAll, drawDrawing, drawHandles, drawing, drawingRequestUpdate, drawingTitleChanged, drawPainters, editor, figureExists, findHandle, fireSelectionChanged, freezeView, getAutoscrollInsets, getBackgrounds, getConnectionFigures, getConstrainer, getDamage, getDefaultDNDActions, getDisplayUpdate, getDNDHelper, getDragSourceListener, getDrawingSize, getFigureSelection, getForegrounds, getToolTipLocation, handleMouseEventException, insertFigures, isFigureSelected, isFocusTraversable, isInteractive, isReadOnly, keyReleased, keyTyped, lastClick, paintComponent, remove, removeBackground, removeFigureSelectionListener, removeForeground, removeFromSelection, selection, selectionCount, selectionHandles, selectionZOrdered, setConstrainer, setCursor, setDamage, setDisplayUpdate, setEditor, setLastClick, setReadOnly, setToolTipFigure, setToolTipLocation, toggleSelection, tool, toString, unfreezeView
 
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, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, 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, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jhotdraw.framework.DrawingView
createImage, getBackground, setBackground
 
Methods inherited from interface java.awt.image.ImageObserver
imageUpdate
 

Constructor Detail

ZoomDrawingView

public ZoomDrawingView(DrawingEditor editor)

ZoomDrawingView

public ZoomDrawingView(DrawingEditor editor,
                       int width,
                       int height)
Method Detail

getScale

public final double getScale()
Returns:
The current zoom scale of this view. The dimensions of figures are multiplied by this number before display.

setUserSize

public void setUserSize(int width,
                        int height)
Sets the size of this view in user coordinates. The size of the view on the screen will be this size, multiplied by the current scale.


setUserSize

public void setUserSize(java.awt.Dimension d)
Sets the size of this view in user coordinates. The size of the view on the screen will be this size, multiplied by the current scale.


getSize

public java.awt.Dimension getSize()
Description copied from interface: DrawingView
Gets the size of the drawing.

Specified by:
getSize in interface DrawingView
Overrides:
getSize in class java.awt.Component
Returns:
the size of this view, in screen coordinates

getViewportSize

public java.awt.Dimension getViewportSize()

hasZoomSupport

protected boolean hasZoomSupport()

setOriginPosition

public void setOriginPosition(java.awt.Point newOrigin)
Sets the coordinates of the left top corner displayed by the view.


setViewPosition

protected void setViewPosition(java.awt.Point newPosition)

getUserSize

public java.awt.Dimension getUserSize()
Returns:
The size of this view, in user coordinates. The size on the screen is this size, multiplied by the current scale.

zoom

public void zoom(int x,
                 int y,
                 int width,
                 int height)
Readjusts this view and its containing ScrollPane to display the given rectangle, which is given in user coordinates. This method only works if this view is contained in a JViewport. It throws a RuntimeException otherwise.


zoom

public void zoom(float newScale)
Set this view's scale factor


zoomOut

public void zoomOut(int x,
                    int y)
Zooms out by a factor of two, keeping point (x,y), which is given in user coordinates, in the center.


zoomIn

public void zoomIn(int x,
                   int y)
InContext Zooms in by a factor of the current scale, keeping point (x,y), which is given in user coordinates, in the center.


deZoom

public void deZoom(int x,
                   int y)
Sets the zoom scale to 1.0 and adjusts the scroll pane so that point (x, y) is in the center.


paint

public void paint(java.awt.Graphics g)
Description copied from interface: DrawingView
Paints the drawing view. The actual drawing is delegated to the current update strategy.

Specified by:
paint in interface DrawingView
Overrides:
paint in class javax.swing.JComponent
See Also:
Painter

getGraphics

public java.awt.Graphics getGraphics()
Description copied from interface: DrawingView
Gets a graphic to draw into

Specified by:
getGraphics in interface DrawingView
Overrides:
getGraphics in class javax.swing.JComponent

constrainPoint

protected java.awt.Point constrainPoint(java.awt.Point p)
Constrain to user coordinates, not screen coordinates.

Overrides:
constrainPoint in class StandardDrawingView

drawBackground

public void drawBackground(java.awt.Graphics g)
Description copied from class: StandardDrawingView
Draws the background. If a background pattern is set it is used to fill the background. Otherwise the background is filled in the background color.

Specified by:
drawBackground in interface DrawingView
Overrides:
drawBackground in class StandardDrawingView

setDrawing

public void setDrawing(Drawing d)
Description copied from class: StandardDrawingView
Sets and installs another drawing in the view.

Specified by:
setDrawing in interface DrawingView
Overrides:
setDrawing in class StandardDrawingView

getMinimumSize

public java.awt.Dimension getMinimumSize()
Description copied from class: StandardDrawingView
Gets the minimum dimension of the drawing.
Fixed version (JHotDraw version has a bug).

Specified by:
getMinimumSize in interface DrawingView
Overrides:
getMinimumSize in class StandardDrawingView
See Also:
StandardDrawingView.getMinimumSize(), Component.getMinimumSize()

getPreferredSize

public java.awt.Dimension getPreferredSize()
Description copied from interface: DrawingView
Gets the preferred dimension of the drawing..

Specified by:
getPreferredSize in interface DrawingView
Overrides:
getPreferredSize in class javax.swing.JComponent

repairDamage

public void repairDamage()
Overridden to scale damage to screen coordinates.

Specified by:
repairDamage in interface DrawingView
Overrides:
repairDamage in class StandardDrawingView

drawingInvalidated

public void drawingInvalidated(DrawingChangeEvent e)
Overridden to accumulate damage in an instance variable of this class.

Specified by:
drawingInvalidated in interface DrawingChangeListener
Overrides:
drawingInvalidated in class StandardDrawingView

createMouseListener

protected java.awt.event.MouseListener createMouseListener()
Overrides:
createMouseListener in class StandardDrawingView

createMouseMotionListener

protected java.awt.event.MouseMotionListener createMouseMotionListener()
Overrides:
createMouseMotionListener in class StandardDrawingView

createKeyListener

protected java.awt.event.KeyListener createKeyListener()
Overrides:
createKeyListener in class StandardDrawingView

getZoomSpeed

public double getZoomSpeed()
Returns the current zoom speed


setZoomSpeed

public void setZoomSpeed(double newZoomSpeed)
Set the zoom speed. Will be greater than 1.


JHotDraw 6.0b1