Interface DrawingView
-
- All Known Implementing Classes:
- DefaultDrawingView
public interface DrawingViewA drawing view paints aDrawingon aJComponent. A drawing view can hold only one drawing at a time, but a drawing can be in multiple drawing views at the same time.To support editing, a drawing view needs to be added to a
DrawingEditor. The currentToolof the drawing editor receives mouse and key events from all drawing views of the drawing editor.DrawingViewcan paint the drawing with a scale factor. It supports conversion between view coordinates and drawing coordinates.DrawingView maintains a selection of the
Figures contained in the drawing. The selected figures can be the target of the current tool of the drawing editor.The painting process of
DrawingViewview usually involves the following steps:- Paint the background of the drawing view.
- Invoke
Drawing.drawCanvas(java.awt.Graphics2D). - Invoke
Constrainer.draw(java.awt.Graphics2D, org.jhotdraw.draw.DrawingView)if a constrainer is set. - Invoke
Figure.draw(java.awt.Graphics2D). - Invoke
Handle.draw(java.awt.Graphics2D)on the handles of selected figures. - Invoke
Tool.draw(java.awt.Graphics2D)if the drawing view is the active view of theDrawingEditor.
Design PatternsFramework
The following interfaces define the contracts of a framework for structured drawing editors:
Contract:Drawing,Figure,DrawingView,DrawingEditor,HandleandTool.Chain of responsibility
Mouse and keyboard events of the user occur on the drawing view, and are preprocessed by theDragTrackerof aSelectionTool. In turnorg.jhotdraw.draw.selectiontool.DragTrackerinvokes "track" methods on aHandlewhich in turn changes an aspect of a figure.
Client:SelectionTool; Handler:DragTracker,Handle.Mediator
DrawingEditoracts as a mediator for coordinating drawing tools and drawing views:
Mediator:DrawingEditor; Colleagues:DrawingView,Tool.Model-View-Controller
The following classes implement together the Model-View-Controller design pattern:
Model:Drawing; View:DrawingView; Controller:DrawingEditor.Observer
Selection changes ofDrawingVieware observed by user interface components which act on selected figures.
Subject:DrawingView; Observer:FigureSelectionListener; Event:FigureSelectionEvent.Observer
State changes of figures can be observed by other objects. SpecificallyCompositeFigureobserves area invalidations and remove requests of its child figures.DrawingViewalso observes area invalidations of its drawing object. Subject:Figure; Observer:FigureListener; Event:FigureEvent; Concrete Observer:CompositeFigure,DrawingView.Observer
State changes of handles can be observed by other objects. SpecificallyDrawingViewobserves area invalidations and remove requests of handles.
Subject:Handle; Observer:HandleListener; Event:HandleEvent; Concrete Observer:DrawingView.Strategy
Editing can be constrained by a constrainer which is associated to a drawing view.
Context:DrawingView; Strategy:Constrainer.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringACTIVE_HANDLE_PROPERTYThis constant is used to identify the activeHandle property of the DrawingView.static java.lang.StringCONSTRAINER_PROPERTYThis constant is used to identify the constrainer property of the DrawingView.static java.lang.StringCONSTRAINER_VISIBLE_PROPERTYThis constant is used to identify the constrainer visible property of the DrawingView.static java.lang.StringCURSOR_PROPERTYThis constant is used to identify the cursor property of the DrawingView.static java.lang.StringDRAWING_PROPERTYThis constant is used to identify the drawing property of the DrawingView.static java.lang.StringENABLED_PROPERTYThis constant is used to identify the enabled property of the DrawingView.static java.lang.StringHANDLE_DETAIL_LEVEL_PROPERTYThis constant is used to identify the handle detail level property of the DrawingView.static java.lang.StringINVISIBLE_CONSTRAINER_PROPERTYThis constant is used to identify the invisible constrainer property of the DrawingView.static java.lang.StringSCALE_FACTOR_PROPERTYThis constant is used to identify the scale factor property of the DrawingView.static java.lang.StringVISIBLE_CONSTRAINER_PROPERTYThis constant is used to identify the visible constrainer property of the DrawingView.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method and Description voidaddFigureSelectionListener(FigureSelectionListener fsl)Add a listener for selection changes in this DrawingView.voidaddKeyListener(java.awt.event.KeyListener l)Adds a key listener to the drawing view.voidaddMouseListener(java.awt.event.MouseListener l)Adds a mouse listener to the drawing view.voidaddMouseMotionListener(java.awt.event.MouseMotionListener l)Adds a mouse motion listener to the drawing view.voidaddNotify(DrawingEditor editor)Informs the view that it has been added to the specified editor.voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds a property change listener to the drawing view.voidaddToSelection(java.util.Collection<Figure> figures)Adds a collection of figures to the current selection.voidaddToSelection(Figure figure)Adds a figure to the current selection.voidclearSelection()Clears the current selection.java.awt.PointdrawingToView(java.awt.geom.Point2D.Double p)Converts drawing coordinates to view coordinates.java.awt.RectangledrawingToView(java.awt.geom.Rectangle2D.Double p)Converts drawing coordinates to view coordinates.FigurefindFigure(java.awt.Point p)Finds a figure at the given point.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.HandlefindHandle(java.awt.Point p)Finds a handle at the given coordinates.HandlegetActiveHandle()Gets the active handle.java.util.Collection<Handle>getCompatibleHandles(Handle handle)Gets compatible handles.javax.swing.JComponentgetComponent()Returns the JComponent of the drawing view.ConstrainergetConstrainer()Gets the current constrainer of this view.DrawinggetDrawing()Gets the drawing.java.awt.geom.AffineTransformgetDrawingToViewTransform()Gets an transform which can be used to convert drawing coordinates to view coordinates.DrawingEditorgetEditor()Gets the drawing editor associated to the DrawingView.intgetHandleDetailLevel()Returns the detail level of the handles.ConstrainergetInvisibleConstrainer()Gets the editor's constrainer for this view, for use, when the visible constrainer is turned off.doublegetScaleFactor()Gets the scale factor of the drawing view.java.util.Set<Figure>getSelectedFigures()Gets the selected figures.intgetSelectionCount()Gets the number of selected figures.ConstrainergetVisibleConstrainer()Gets the editor's constrainer for this view, for use, when the visible constrainer is turned on.booleanisConstrainerVisible()Returns true, if the visible Constrainer is in use, returns false, if the invisible Constrainer is in use.booleanisEnabled()Gets the enabled state of the drawing view.booleanisFigureSelected(Figure checkFigure)Test whether a given figure is selected.voidremoveFigureSelectionListener(FigureSelectionListener fsl)Remove a listener for selection changes in this DrawingView.voidremoveFromSelection(Figure figure)Removes a figure from the selection.voidremoveKeyListener(java.awt.event.KeyListener l)Removes a key listener to the drawing view.voidremoveMouseListener(java.awt.event.MouseListener l)Removes a mouse listener to the drawing view.voidremoveMouseMotionListener(java.awt.event.MouseMotionListener l)Removes a mouse motion listener to the drawing view.voidremoveNotify(DrawingEditor editor)Informs the view that it has been removed from the specified editor.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Removes a property change listener to the drawing view.voidrepaintHandles()Repaints the handles of the view.voidrequestFocus()This is a convenience method for invokinggetComponent().requestFocus().voidselectAll()Selects all figures.voidsetActiveHandle(Handle newValue)Sets the active handle.voidsetConstrainerVisible(boolean newValue)Changes between a visible Constrainer and an invisible Constrainer.voidsetCursor(java.awt.Cursor c)Sets the cursor of the DrawingView.voidsetDrawing(Drawing d)Sets and installs another drawing in the view.voidsetEnabled(boolean newValue)Sets the enabled state of the drawing view.voidsetHandleDetailLevel(int newValue)The detail level of the handles.voidsetInvisibleConstrainer(Constrainer constrainer)Sets the editor's constrainer for this view, for use, when the visible constrainer is turned off.voidsetScaleFactor(double newValue)Sets the scale factor of the drawing view.voidsetVisibleConstrainer(Constrainer constrainer)Sets the editor's constrainer for this view, for use, when the visible constrainer is turned on.voidtoggleSelection(Figure figure)If a figure isn't selected it is added to the selection.java.awt.geom.Point2D.DoubleviewToDrawing(java.awt.Point p)Converts view coordinates to drawing coordinates.java.awt.geom.Rectangle2D.DoubleviewToDrawing(java.awt.Rectangle p)Converts view coordinates to drawing coordinates.
-
-
-
Field Detail
-
DRAWING_PROPERTY
static final java.lang.String DRAWING_PROPERTY
This constant is used to identify the drawing property of the DrawingView.- See Also:
- Constant Field Values
-
CURSOR_PROPERTY
static final java.lang.String CURSOR_PROPERTY
This constant is used to identify the cursor property of the DrawingView.- See Also:
- Constant Field Values
-
CONSTRAINER_PROPERTY
static final java.lang.String CONSTRAINER_PROPERTY
This constant is used to identify the constrainer property of the DrawingView.- See Also:
- Constant Field Values
-
VISIBLE_CONSTRAINER_PROPERTY
static final java.lang.String VISIBLE_CONSTRAINER_PROPERTY
This constant is used to identify the visible constrainer property of the DrawingView.- See Also:
- Constant Field Values
-
INVISIBLE_CONSTRAINER_PROPERTY
static final java.lang.String INVISIBLE_CONSTRAINER_PROPERTY
This constant is used to identify the invisible constrainer property of the DrawingView.- See Also:
- Constant Field Values
-
CONSTRAINER_VISIBLE_PROPERTY
static final java.lang.String CONSTRAINER_VISIBLE_PROPERTY
This constant is used to identify the constrainer visible property of the DrawingView.- See Also:
- Constant Field Values
-
SCALE_FACTOR_PROPERTY
static final java.lang.String SCALE_FACTOR_PROPERTY
This constant is used to identify the scale factor property of the DrawingView.- See Also:
- Constant Field Values
-
HANDLE_DETAIL_LEVEL_PROPERTY
static final java.lang.String HANDLE_DETAIL_LEVEL_PROPERTY
This constant is used to identify the handle detail level property of the DrawingView.- See Also:
- Constant Field Values
-
ENABLED_PROPERTY
static final java.lang.String ENABLED_PROPERTY
This constant is used to identify the enabled property of the DrawingView.- See Also:
- Constant Field Values
-
ACTIVE_HANDLE_PROPERTY
static final java.lang.String ACTIVE_HANDLE_PROPERTY
This constant is used to identify the activeHandle property of the DrawingView.- See Also:
- Constant Field Values
-
-
Method Detail
-
setDrawing
void setDrawing(@Nullable Drawing d)
Sets and installs another drawing in the view. This is a bound property.
-
setCursor
void setCursor(@Nullable java.awt.Cursor c)
Sets the cursor of the DrawingView. This is a bound property.
-
isFigureSelected
boolean isFigureSelected(Figure checkFigure)
Test whether a given figure is selected.
-
addToSelection
void addToSelection(Figure figure)
Adds a figure to the current selection.
-
addToSelection
void addToSelection(java.util.Collection<Figure> figures)
Adds a collection of figures to the current selection.
-
removeFromSelection
void removeFromSelection(Figure figure)
Removes a figure from the selection.
-
toggleSelection
void toggleSelection(Figure figure)
If a figure isn't selected it is added to the selection. Otherwise it is removed from the selection.
-
clearSelection
void clearSelection()
Clears the current selection.
-
selectAll
void selectAll()
Selects all figures.
-
getSelectedFigures
java.util.Set<Figure> getSelectedFigures()
Gets the selected figures. Returns an empty set, if no figures are selected.
-
getSelectionCount
int getSelectionCount()
Gets the number of selected figures.
-
findHandle
@Nullable Handle findHandle(java.awt.Point p)
Finds a handle at the given coordinates.- Returns:
- A handle, null if no handle is found.
-
getCompatibleHandles
java.util.Collection<Handle> getCompatibleHandles(Handle handle)
Gets compatible handles.- Returns:
- A collection containing the handle and all compatible handles.
-
findFigure
@Nullable Figure findFigure(java.awt.Point p)
Finds a figure at the given point.- Returns:
- A figure, null if no figure is found.
-
findFigures
java.util.Collection<Figure> findFigures(java.awt.Rectangle r)
Returns all figures that lie within or intersect the specified bounds. The figures are returned in Z-order from back to front.
-
findFiguresWithin
java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
Returns all figures that lie within the specified bounds. The figures are returned in Z-order from back to front.
-
addNotify
void addNotify(DrawingEditor editor)
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.
-
removeNotify
void removeNotify(DrawingEditor editor)
Informs the view that it has been removed from the specified editor. The view must not draw the tool from the editor anymore.
-
getEditor
@Nullable DrawingEditor getEditor()
Gets the drawing editor associated to the DrawingView. This is a bound property.
-
addFigureSelectionListener
void addFigureSelectionListener(FigureSelectionListener fsl)
Add a listener for selection changes in this DrawingView.- Parameters:
fsl- jhotdraw.framework.FigureSelectionListener
-
removeFigureSelectionListener
void removeFigureSelectionListener(FigureSelectionListener fsl)
Remove a listener for selection changes in this DrawingView.- Parameters:
fsl- jhotdraw.framework.FigureSelectionListener
-
requestFocus
void requestFocus()
This is a convenience method for invokinggetComponent().requestFocus().
-
drawingToView
java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
Converts drawing coordinates to view coordinates.
-
viewToDrawing
java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
Converts view coordinates to drawing coordinates.
-
drawingToView
java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double p)
Converts drawing coordinates to view coordinates.
-
viewToDrawing
java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle p)
Converts view coordinates to drawing coordinates.
-
getConstrainer
@Nullable Constrainer getConstrainer()
Gets the current constrainer of this view. If isConstrainerVisible is true, this method returns getVisibleConstrainer, otherwise it returns getInvisibleConstrainer. This is a bound property.
-
setVisibleConstrainer
void setVisibleConstrainer(@Nullable Constrainer constrainer)
Sets the editor's constrainer for this view, for use, when the visible constrainer is turned on. This is a bound property.
-
getVisibleConstrainer
@Nullable Constrainer getVisibleConstrainer()
Gets the editor's constrainer for this view, for use, when the visible constrainer is turned on. This is a bound property.
-
setInvisibleConstrainer
void setInvisibleConstrainer(Constrainer constrainer)
Sets the editor's constrainer for this view, for use, when the visible constrainer is turned off. This is a bound property.
-
getInvisibleConstrainer
Constrainer getInvisibleConstrainer()
Gets the editor's constrainer for this view, for use, when the visible constrainer is turned off. This is a bound property.
-
setConstrainerVisible
void setConstrainerVisible(boolean newValue)
Changes between a visible Constrainer and an invisible Constrainer. This is a bound property.
-
isConstrainerVisible
boolean isConstrainerVisible()
Returns true, if the visible Constrainer is in use, returns false, if the invisible Constrainer is in use. This is a bound property.
-
getComponent
javax.swing.JComponent getComponent()
Returns the JComponent of the drawing view.
-
getDrawingToViewTransform
java.awt.geom.AffineTransform getDrawingToViewTransform()
Gets an transform which can be used to convert drawing coordinates to view coordinates.
-
getScaleFactor
double getScaleFactor()
Gets the scale factor of the drawing view. This is a bound property.
-
setScaleFactor
void setScaleFactor(double newValue)
Sets the scale factor of the drawing view. This is a bound property.
-
setHandleDetailLevel
void setHandleDetailLevel(int newValue)
The detail level of the handles. This is a bound property.
-
getHandleDetailLevel
int getHandleDetailLevel()
Returns the detail level of the handles. This is a bound property.
-
setEnabled
void setEnabled(boolean newValue)
Sets the enabled state of the drawing view. This is a bound property.
-
isEnabled
boolean isEnabled()
Gets the enabled state of the drawing view. This is a bound property.
-
repaintHandles
void repaintHandles()
Repaints the handles of the view.
-
addPropertyChangeListener
void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a property change listener to the drawing view.- Parameters:
listener-
-
removePropertyChangeListener
void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a property change listener to the drawing view.- Parameters:
listener-
-
addMouseListener
void addMouseListener(java.awt.event.MouseListener l)
Adds a mouse listener to the drawing view.- Parameters:
l- the listener.
-
removeMouseListener
void removeMouseListener(java.awt.event.MouseListener l)
Removes a mouse listener to the drawing view.- Parameters:
l- the listener.
-
addKeyListener
void addKeyListener(java.awt.event.KeyListener l)
Adds a key listener to the drawing view.- Parameters:
l- the listener.
-
removeKeyListener
void removeKeyListener(java.awt.event.KeyListener l)
Removes a key listener to the drawing view.- Parameters:
l- the listener.
-
addMouseMotionListener
void addMouseMotionListener(java.awt.event.MouseMotionListener l)
Adds a mouse motion listener to the drawing view.- Parameters:
l- the listener.
-
removeMouseMotionListener
void removeMouseMotionListener(java.awt.event.MouseMotionListener l)
Removes a mouse motion listener to the drawing view.- Parameters:
l- the listener.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG