public interface DrawingView
Drawing
on a JComponent
.
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 current Tool
of the drawing editor
receives mouse and key events from all drawing views of the drawing editor.
DrawingView
can paint the drawing with a scale factor. It supports
conversion between view coordinates and drawing coordinates.
DrawingView maintains a selection of the Figure
s contained in the
drawing. The selected figures can be the target of the current tool
of the drawing editor.
The painting process of DrawingView
view usually involves the
following steps:
Drawing.drawCanvas(java.awt.Graphics2D)
.Constrainer.draw(java.awt.Graphics2D, org.jhotdraw.draw.DrawingView)
if a constrainer is set.Figure.draw(java.awt.Graphics2D)
.Handle.draw(java.awt.Graphics2D)
on the handles
of selected figures.Tool.draw(java.awt.Graphics2D)
if the drawing view
is the active view of the DrawingEditor
.Framework
The following interfaces define the contracts of a framework for structured
drawing editors:
Contract: Drawing
, Figure
, DrawingView
,
DrawingEditor
, Handle
and
Tool
.
Chain of responsibility
Mouse and keyboard events of the user occur on the drawing view, and are
preprocessed by the DragTracker
of a SelectionTool
. In
turn org.jhotdraw.draw.selectiontool.DragTracker
invokes "track" methods on a Handle
which in
turn changes an aspect of a figure.
Client: SelectionTool
;
Handler: DragTracker
,
Handle
.
Mediator
DrawingEditor
acts 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 of DrawingView
are 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. Specifically
CompositeFigure
observes area invalidations and remove requests
of its child figures. DrawingView
also 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. Specifically
DrawingView
observes 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
.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACTIVE_HANDLE_PROPERTY
This constant is used to identify the activeHandle property of the DrawingView.
|
static java.lang.String |
CONSTRAINER_PROPERTY
This constant is used to identify the constrainer property of the DrawingView.
|
static java.lang.String |
CONSTRAINER_VISIBLE_PROPERTY
This constant is used to identify the constrainer visible property of the DrawingView.
|
static java.lang.String |
CURSOR_PROPERTY
This constant is used to identify the cursor property of the DrawingView.
|
static java.lang.String |
DRAWING_PROPERTY
This constant is used to identify the drawing property of the DrawingView.
|
static java.lang.String |
ENABLED_PROPERTY
This constant is used to identify the enabled property of the DrawingView.
|
static java.lang.String |
HANDLE_DETAIL_LEVEL_PROPERTY
This constant is used to identify the handle detail level property of the DrawingView.
|
static java.lang.String |
INVISIBLE_CONSTRAINER_PROPERTY
This constant is used to identify the invisible constrainer property of the DrawingView.
|
static java.lang.String |
SCALE_FACTOR_PROPERTY
This constant is used to identify the scale factor property of the DrawingView.
|
static java.lang.String |
VISIBLE_CONSTRAINER_PROPERTY
This constant is used to identify the visible constrainer property of the DrawingView.
|
Modifier and Type | Method and Description |
---|---|
void |
addFigureSelectionListener(FigureSelectionListener fsl)
Add a listener for selection changes in this DrawingView.
|
void |
addKeyListener(java.awt.event.KeyListener l)
Adds a key listener to the drawing view.
|
void |
addMouseListener(java.awt.event.MouseListener l)
Adds a mouse listener to the drawing view.
|
void |
addMouseMotionListener(java.awt.event.MouseMotionListener l)
Adds a mouse motion listener to the drawing view.
|
void |
addNotify(DrawingEditor editor)
Informs the view that it has been added to the specified editor.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a property change listener to the drawing view.
|
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 |
clearSelection()
Clears the current selection.
|
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 p)
Converts drawing coordinates to view coordinates.
|
Figure |
findFigure(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.
|
Handle |
findHandle(java.awt.Point p)
Finds a handle at the given coordinates.
|
Handle |
getActiveHandle()
Gets the active handle.
|
java.util.Collection<Handle> |
getCompatibleHandles(Handle handle)
Gets compatible handles.
|
javax.swing.JComponent |
getComponent()
Returns the JComponent of the drawing view.
|
Constrainer |
getConstrainer()
Gets the current constrainer of this view.
|
Drawing |
getDrawing()
Gets the drawing.
|
java.awt.geom.AffineTransform |
getDrawingToViewTransform()
Gets an transform which can be used to convert
drawing coordinates to view coordinates.
|
DrawingEditor |
getEditor()
Gets the drawing editor associated to the DrawingView.
|
int |
getHandleDetailLevel()
Returns the detail level of the handles.
|
Constrainer |
getInvisibleConstrainer()
Gets the editor's constrainer for this view, for use, when the
visible constrainer is turned off.
|
double |
getScaleFactor()
Gets the scale factor of the drawing view.
|
java.util.Set<Figure> |
getSelectedFigures()
Gets the selected figures.
|
int |
getSelectionCount()
Gets the number of selected figures.
|
Constrainer |
getVisibleConstrainer()
Gets the editor's constrainer for this view, for use, when the
visible constrainer is turned on.
|
boolean |
isConstrainerVisible()
Returns true, if the visible Constrainer is in use, returns false,
if the invisible Constrainer is in use.
|
boolean |
isEnabled()
Gets the enabled state of the drawing view.
|
boolean |
isFigureSelected(Figure checkFigure)
Test whether a given figure is selected.
|
void |
removeFigureSelectionListener(FigureSelectionListener fsl)
Remove a listener for selection changes in this DrawingView.
|
void |
removeFromSelection(Figure figure)
Removes a figure from the selection.
|
void |
removeKeyListener(java.awt.event.KeyListener l)
Removes a key listener to the drawing view.
|
void |
removeMouseListener(java.awt.event.MouseListener l)
Removes a mouse listener to the drawing view.
|
void |
removeMouseMotionListener(java.awt.event.MouseMotionListener l)
Removes a mouse motion listener to the drawing view.
|
void |
removeNotify(DrawingEditor editor)
Informs the view that it has been removed from the specified editor.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a property change listener to the drawing view.
|
void |
repaintHandles()
Repaints the handles of the view.
|
void |
requestFocus()
This is a convenience method for invoking
getComponent().requestFocus() . |
void |
selectAll()
Selects all figures.
|
void |
setActiveHandle(Handle newValue)
Sets the active handle.
|
void |
setConstrainerVisible(boolean newValue)
Changes between a visible Constrainer and an invisible Constrainer.
|
void |
setCursor(java.awt.Cursor c)
Sets the cursor of the DrawingView.
|
void |
setDrawing(Drawing d)
Sets and installs another drawing in the view.
|
void |
setEnabled(boolean newValue)
Sets the enabled state of the drawing view.
|
void |
setHandleDetailLevel(int newValue)
The detail level of the handles.
|
void |
setInvisibleConstrainer(Constrainer constrainer)
Sets the editor's constrainer for this view, for use, when the
visible constrainer is turned off.
|
void |
setScaleFactor(double newValue)
Sets the scale factor of the drawing view.
|
void |
setVisibleConstrainer(Constrainer constrainer)
Sets the editor's constrainer for this view, for use, when the
visible constrainer is turned on.
|
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 p)
Converts view coordinates to drawing coordinates.
|
static final java.lang.String DRAWING_PROPERTY
static final java.lang.String CURSOR_PROPERTY
static final java.lang.String CONSTRAINER_PROPERTY
static final java.lang.String VISIBLE_CONSTRAINER_PROPERTY
static final java.lang.String INVISIBLE_CONSTRAINER_PROPERTY
static final java.lang.String CONSTRAINER_VISIBLE_PROPERTY
static final java.lang.String SCALE_FACTOR_PROPERTY
static final java.lang.String HANDLE_DETAIL_LEVEL_PROPERTY
static final java.lang.String ENABLED_PROPERTY
static final java.lang.String ACTIVE_HANDLE_PROPERTY
Drawing getDrawing()
void setDrawing(Drawing d)
void setCursor(java.awt.Cursor c)
boolean isFigureSelected(Figure checkFigure)
void addToSelection(Figure figure)
void addToSelection(java.util.Collection<Figure> figures)
void removeFromSelection(Figure figure)
void toggleSelection(Figure figure)
void clearSelection()
void selectAll()
java.util.Set<Figure> getSelectedFigures()
int getSelectionCount()
Handle findHandle(java.awt.Point p)
java.util.Collection<Handle> getCompatibleHandles(Handle handle)
void setActiveHandle(Handle newValue)
Handle getActiveHandle()
Figure findFigure(java.awt.Point p)
java.util.Collection<Figure> findFigures(java.awt.Rectangle r)
java.util.Collection<Figure> findFiguresWithin(java.awt.Rectangle r)
void addNotify(DrawingEditor editor)
void removeNotify(DrawingEditor editor)
DrawingEditor getEditor()
void addFigureSelectionListener(FigureSelectionListener fsl)
fsl
- jhotdraw.framework.FigureSelectionListenervoid removeFigureSelectionListener(FigureSelectionListener fsl)
fsl
- jhotdraw.framework.FigureSelectionListenervoid requestFocus()
getComponent().requestFocus()
.java.awt.Point drawingToView(java.awt.geom.Point2D.Double p)
java.awt.geom.Point2D.Double viewToDrawing(java.awt.Point p)
java.awt.Rectangle drawingToView(java.awt.geom.Rectangle2D.Double p)
java.awt.geom.Rectangle2D.Double viewToDrawing(java.awt.Rectangle p)
Constrainer getConstrainer()
void setVisibleConstrainer(Constrainer constrainer)
Constrainer getVisibleConstrainer()
void setInvisibleConstrainer(Constrainer constrainer)
Constrainer getInvisibleConstrainer()
void setConstrainerVisible(boolean newValue)
boolean isConstrainerVisible()
javax.swing.JComponent getComponent()
java.awt.geom.AffineTransform getDrawingToViewTransform()
double getScaleFactor()
void setScaleFactor(double newValue)
void setHandleDetailLevel(int newValue)
int getHandleDetailLevel()
void setEnabled(boolean newValue)
boolean isEnabled()
void repaintHandles()
void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- void addMouseListener(java.awt.event.MouseListener l)
l
- the listener.void removeMouseListener(java.awt.event.MouseListener l)
l
- the listener.void addKeyListener(java.awt.event.KeyListener l)
l
- the listener.void removeKeyListener(java.awt.event.KeyListener l)
l
- the listener.void addMouseMotionListener(java.awt.event.MouseMotionListener l)
l
- the listener.void removeMouseMotionListener(java.awt.event.MouseMotionListener l)
l
- the listener.