JHotDraw 7.0.9

org.jhotdraw.draw
Class DefaultDrawingView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.jhotdraw.draw.DefaultDrawingView
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, EditableComponent, DrawingListener, DrawingView, HandleListener

public class DefaultDrawingView
extends javax.swing.JComponent
implements DrawingView, DrawingListener, HandleListener, EditableComponent

The DefaultDrawingView is suited for viewing drawings with a small number of Figures. FIXME - DefaultDrawingView should not implement DrawingListener and HandleListener. It should use internal classes for this.

Version:
3.5 2007-04-13 Implement clipboard functions using TransferHandler.
3.4 2007-04-09 Visualizes the canvas size of a Drawing by a filled white rectangle on the background.
3.3 2007-01-23 Only repaint handles on focus gained/lost.
3.2 2006-12-26 Rewrote storage and clipboard support.
3.1 2006-12-17 Added printing support.
3.0.2 2006-07-03 Constrainer must be a bound property.
3.0.1 2006-06-11 Draw handles when this DrawingView is the focused drawing view of the DrawingEditor.
3.0 2006-02-17 Reworked to support multiple drawing views in a DrawingEditor.
2.0 2006-01-14 Changed to support double precision coordinates.
1.0 2003-12-01 Derived from JHotDraw 5.4b1.
Author:
Werner Randelshofer
See Also:
Serialized Form

Nested Class Summary
 
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 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
DefaultDrawingView()
          Creates new instance.
 
Method Summary
 void addFigureSelectionListener(FigureSelectionListener fsl)
          Add a listener for selection changes in this DrawingView.
 void addNotify(DrawingEditor editor)
          Informs the view that it has been added to the specified editor.
 void addToSelection(java.util.Collection<Figure> figures)
          Adds a collection of figures to the current selection.
 void addToSelection(Figure figure)
          Adds a figure to the current selection.
 void areaInvalidated(DrawingEvent evt)
          Sent when an area of the drawing needs to be repainted.
 void areaInvalidated(HandleEvent evt)
          Sent when an area of the drawing view needs to be repainted.
 void clearSelection()
          Clears the current selection.
 void delete()
          Deletes the component at (or after) the caret position.
protected  void drawBackground(java.awt.Graphics2D g)
           
protected  void drawDrawing(java.awt.Graphics2D gr)
           
protected  void drawGrid(java.awt.Graphics2D g)
           
protected  void drawHandles(java.awt.Graphics2D g)
           
 java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
          Converts drawing coordinates to view coordinates.
 java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double r)
          Converts drawing coordinates to view coordinates.
protected  void drawTool(java.awt.Graphics2D g)
           
 void duplicate()
          Duplicates the selected region.
 void figureAdded(DrawingEvent evt)
          Sent when a figure was added.
 void figureRemoved(DrawingEvent evt)
          Sent when a figure was removed.
 Figure findFigure(java.awt.Point p)
          Finds a figure at a given coordinates.
 java.util.Collection<Figure> findFigures(java.awt.Rectangle r)
          Returns all figures that lie within or intersect the specified bounds.
 java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
          Returns all figures that lie within the specified bounds.
 Handle findHandle(java.awt.Point p)
          Finds a handle at a given coordinates.
protected  void fireSelectionChanged(java.util.Set<Figure> oldValue, java.util.Set<Figure> newValue)
          Notify all listenerList that have registered interest for notification on this event type.
protected  void fireViewTransformChanged()
           
 java.util.Collection<Handle> getCompatibleHandles(Handle master)
          Gets compatible handles.
 javax.swing.JComponent getComponent()
          Returns the JComponent of the drawing view.
 Constrainer getConstrainer()
          Gets the editor's constrainer.
 Drawing getDrawing()
          Gets the drawing.
protected  java.awt.geom.Rectangle2D.Double getDrawingArea()
          Side effect: Changes view Translation!!!
 java.awt.geom.AffineTransform getDrawingToViewTransform()
          Gets an transform which can be used to convert drawing coordinates to view coordinates.
 java.lang.String getEmptyDrawingMessage()
           
 int getHandleDetailLevel()
          Returns the detail level of the handles.
 java.awt.Dimension getPreferredSize()
          Side effect: Changes view Translation!!!
 double getScaleFactor()
          Gets the scale factor of the drawing view.
 java.util.Set<Figure> getSelectedFigures()
          Gets the current selection as a FigureSelection.
 int getSelectionCount()
          Gets the number of selected figures.
 java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
           
 void handleRequestRemove(HandleEvent e)
          Sent when requesting to remove a handle.
 void handleRequestSecondaryHandles(HandleEvent e)
          Sent when requesting to add secondary handles.
 void invalidate()
           
protected  void invalidateDimension()
           
 boolean isFigureSelected(Figure checkFigure)
          Test whether a given figure is selected.
 void paintComponent(java.awt.Graphics gr)
          Paints the drawing view.
 void printComponent(java.awt.Graphics gr)
          Prints the drawing view.
 void removeFigureSelectionListener(FigureSelectionListener fsl)
          Remove a listener for selection changes in this DrawingView.
 void removeFromSelection(Figure figure)
          Removes a figure from the selection.
 void removeNotify(DrawingEditor editor)
          Informs the view that it has been removed from the specified editor.
protected  void repaint(java.awt.geom.Rectangle2D.Double r)
           
protected  void repaintHandles()
          Repaints the handles.
 void selectAll()
          Selects all figures.
 void setConstrainer(Constrainer newValue)
          Sets the editor's constrainer.
 void setDrawing(Drawing d)
          Sets and installs another drawing in the view.
 void setEmptyDrawingMessage(java.lang.String newValue)
           
 void setEnabled(boolean b)
          Sets the enabled state of the drawing view.
 void setHandleDetailLevel(int newValue)
          The detail level of the handles.
 void setScaleFactor(double newValue)
          Sets the scale factor of the drawing view.
 void toggleSelection(Figure figure)
          If a figure isn't selected it is added to the selection.
 java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
          Converts view coordinates to drawing coordinates.
 java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle r)
          Converts view coordinates to drawing coordinates.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
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, 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
 
Methods inherited from interface org.jhotdraw.draw.DrawingView
addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, isEnabled, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, requestFocus, setCursor
 

Constructor Detail

DefaultDrawingView

public DefaultDrawingView()
Creates new instance.

Method Detail

getDrawing

public Drawing getDrawing()
Description copied from interface: DrawingView
Gets the drawing.

Specified by:
getDrawing in interface DrawingView

getToolTipText

public java.lang.String getToolTipText(java.awt.event.MouseEvent evt)
Overrides:
getToolTipText in class javax.swing.JComponent

setEmptyDrawingMessage

public void setEmptyDrawingMessage(java.lang.String newValue)

getEmptyDrawingMessage

public java.lang.String getEmptyDrawingMessage()

paintComponent

public void paintComponent(java.awt.Graphics gr)
Paints the drawing view. Uses rendering hints for fast painting. Paints the background, the grid, the drawing, the handles and the current tool.

Overrides:
paintComponent in class javax.swing.JComponent

printComponent

public void printComponent(java.awt.Graphics gr)
Prints the drawing view. Uses high quality rendering hints for printing. Only prints the drawing. Doesn't print the background, the grid, the handles and the tool.

Overrides:
printComponent in class javax.swing.JComponent

drawBackground

protected void drawBackground(java.awt.Graphics2D g)

drawGrid

protected void drawGrid(java.awt.Graphics2D g)

drawDrawing

protected void drawDrawing(java.awt.Graphics2D gr)

drawHandles

protected void drawHandles(java.awt.Graphics2D g)

drawTool

protected void drawTool(java.awt.Graphics2D g)

setDrawing

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

Specified by:
setDrawing in interface DrawingView

repaint

protected void repaint(java.awt.geom.Rectangle2D.Double r)

areaInvalidated

public void areaInvalidated(DrawingEvent evt)
Description copied from interface: DrawingListener
Sent when an area of the drawing needs to be repainted.

Specified by:
areaInvalidated in interface DrawingListener

areaInvalidated

public void areaInvalidated(HandleEvent evt)
Description copied from interface: HandleListener
Sent when an area of the drawing view needs to be repainted.

Specified by:
areaInvalidated in interface HandleListener

figureAdded

public void figureAdded(DrawingEvent evt)
Description copied from interface: DrawingListener
Sent when a figure was added.

Specified by:
figureAdded in interface DrawingListener

figureRemoved

public void figureRemoved(DrawingEvent evt)
Description copied from interface: DrawingListener
Sent when a figure was removed.

Specified by:
figureRemoved in interface DrawingListener

invalidate

public void invalidate()
Overrides:
invalidate in class java.awt.Container

addToSelection

public void addToSelection(Figure figure)
Adds a figure to the current selection.

Specified by:
addToSelection in interface DrawingView

addToSelection

public void addToSelection(java.util.Collection<Figure> figures)
Adds a collection of figures to the current selection.

Specified by:
addToSelection in interface DrawingView

removeFromSelection

public void removeFromSelection(Figure figure)
Removes a figure from the selection.

Specified by:
removeFromSelection in interface DrawingView

toggleSelection

public void toggleSelection(Figure figure)
If a figure isn't selected it is added to the selection. Otherwise it is removed from the selection.

Specified by:
toggleSelection in interface DrawingView

setEnabled

public void setEnabled(boolean b)
Description copied from interface: DrawingView
Sets the enabled state of the drawing view. This is a bound property.

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

selectAll

public void selectAll()
Selects all figures.

Specified by:
selectAll in interface EditableComponent
Specified by:
selectAll in interface DrawingView

clearSelection

public void clearSelection()
Clears the current selection.

Specified by:
clearSelection in interface DrawingView

isFigureSelected

public boolean isFigureSelected(Figure checkFigure)
Test whether a given figure is selected.

Specified by:
isFigureSelected in interface DrawingView

getSelectedFigures

public java.util.Set<Figure> getSelectedFigures()
Gets the current selection as a FigureSelection. A FigureSelection can be cut, copied, pasted.

Specified by:
getSelectedFigures in interface DrawingView

getSelectionCount

public int getSelectionCount()
Gets the number of selected figures.

Specified by:
getSelectionCount in interface DrawingView

findHandle

public Handle findHandle(java.awt.Point p)
Finds a handle at a given coordinates.

Specified by:
findHandle in interface DrawingView
Returns:
A handle, null if no handle is found.

getCompatibleHandles

public java.util.Collection<Handle> getCompatibleHandles(Handle master)
Gets compatible handles.

Specified by:
getCompatibleHandles in interface DrawingView
Returns:
A collection containing the handle and all compatible handles.

findFigure

public Figure findFigure(java.awt.Point p)
Finds a figure at a given coordinates.

Specified by:
findFigure in interface DrawingView
Returns:
A figure, null if no figure is found.

findFigures

public java.util.Collection<Figure> findFigures(java.awt.Rectangle r)
Description copied from interface: DrawingView
Returns all figures that lie within or intersect the specified bounds. The figures are returned in Z-order from back to front.

Specified by:
findFigures in interface DrawingView

findFiguresWithin

public java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
Description copied from interface: DrawingView
Returns all figures that lie within the specified bounds. The figures are returned in Z-order from back to front.

Specified by:
findFiguresWithin in interface DrawingView

repaintHandles

protected void repaintHandles()
Repaints the handles.


addFigureSelectionListener

public void addFigureSelectionListener(FigureSelectionListener fsl)
Description copied from interface: DrawingView
Add a listener for selection changes in this DrawingView.

Specified by:
addFigureSelectionListener in interface DrawingView
Parameters:
fsl - jhotdraw.framework.FigureSelectionListener

removeFigureSelectionListener

public void removeFigureSelectionListener(FigureSelectionListener fsl)
Description copied from interface: DrawingView
Remove a listener for selection changes in this DrawingView.

Specified by:
removeFigureSelectionListener in interface DrawingView
Parameters:
fsl - jhotdraw.framework.FigureSelectionListener

fireSelectionChanged

protected void fireSelectionChanged(java.util.Set<Figure> oldValue,
                                    java.util.Set<Figure> newValue)
Notify all listenerList that have registered interest for notification on this event type.


handleRequestRemove

public void handleRequestRemove(HandleEvent e)
Description copied from interface: HandleListener
Sent when requesting to remove a handle.

Specified by:
handleRequestRemove in interface HandleListener

invalidateDimension

protected void invalidateDimension()

getConstrainer

public Constrainer getConstrainer()
Description copied from interface: DrawingView
Gets the editor's constrainer.

Specified by:
getConstrainer in interface DrawingView

setConstrainer

public void setConstrainer(Constrainer newValue)
Description copied from interface: DrawingView
Sets the editor's constrainer.

Specified by:
setConstrainer in interface DrawingView

getPreferredSize

public java.awt.Dimension getPreferredSize()
Side effect: Changes view Translation!!!

Overrides:
getPreferredSize in class javax.swing.JComponent

getDrawingArea

protected java.awt.geom.Rectangle2D.Double getDrawingArea()
Side effect: Changes view Translation!!!


drawingToView

public java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
Converts drawing coordinates to view coordinates.

Specified by:
drawingToView in interface DrawingView

viewToDrawing

public java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
Converts view coordinates to drawing coordinates.

Specified by:
viewToDrawing in interface DrawingView

drawingToView

public java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double r)
Description copied from interface: DrawingView
Converts drawing coordinates to view coordinates.

Specified by:
drawingToView in interface DrawingView

viewToDrawing

public java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle r)
Description copied from interface: DrawingView
Converts view coordinates to drawing coordinates.

Specified by:
viewToDrawing in interface DrawingView

getComponent

public javax.swing.JComponent getComponent()
Description copied from interface: DrawingView
Returns the JComponent of the drawing view.

Specified by:
getComponent in interface DrawingView

getScaleFactor

public double getScaleFactor()
Description copied from interface: DrawingView
Gets the scale factor of the drawing view.

Specified by:
getScaleFactor in interface DrawingView

setScaleFactor

public void setScaleFactor(double newValue)
Description copied from interface: DrawingView
Sets the scale factor of the drawing view. This is a bound property.

Specified by:
setScaleFactor in interface DrawingView

fireViewTransformChanged

protected void fireViewTransformChanged()

setHandleDetailLevel

public void setHandleDetailLevel(int newValue)
Description copied from interface: DrawingView
The detail level of the handles.

Specified by:
setHandleDetailLevel in interface DrawingView

getHandleDetailLevel

public int getHandleDetailLevel()
Description copied from interface: DrawingView
Returns the detail level of the handles.

Specified by:
getHandleDetailLevel in interface DrawingView

handleRequestSecondaryHandles

public void handleRequestSecondaryHandles(HandleEvent e)
Description copied from interface: HandleListener
Sent when requesting to add secondary handles.

Specified by:
handleRequestSecondaryHandles in interface HandleListener

getDrawingToViewTransform

public java.awt.geom.AffineTransform getDrawingToViewTransform()
Description copied from interface: DrawingView
Gets an transform which can be used to convert drawing coordinates to view coordinates.

Specified by:
getDrawingToViewTransform in interface DrawingView

delete

public void delete()
Description copied from interface: EditableComponent
Deletes the component at (or after) the caret position.

Specified by:
delete in interface EditableComponent

duplicate

public void duplicate()
Description copied from interface: EditableComponent
Duplicates the selected region.

Specified by:
duplicate in interface EditableComponent

removeNotify

public void removeNotify(DrawingEditor editor)
Description copied from interface: DrawingView
Informs the view that it has been removed from the specified editor. The view must not draw the tool from the editor anymore.

Specified by:
removeNotify in interface DrawingView

addNotify

public void addNotify(DrawingEditor editor)
Description copied from interface: DrawingView
Informs the view that it has been added to the specified editor. The view must draw the tool of the editor, if getActiveView() of the editor returns the view.

Specified by:
addNotify in interface DrawingView

Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.