public class Figure extends CompoundDoodle
Details:
A Figure
is a model of a layered, two-Doodle
).
This class publishes model change events and provides drawing and hit testing support to views.
mDoodles, mDoodlesSorted
mToolTip, mZOrder
mParent
Constructor and Description |
---|
Figure() |
Modifier and Type | Method and Description |
---|---|
void |
add(Doodle iDoodle)
Adds doodle to figure.
|
boolean |
paint(FigGraphics iG)
Renders figure.
|
void |
remove(Doodle iDoodle)
Removes shape from figure.
|
void |
sendDoodleChanged(Doodle iShape)
Repaints views.
|
void |
subscribe(FigureObserver iObserver)
Registers observer.
|
void |
unsubscribe(FigureObserver iObserver)
Unregisters observer.
|
contains, draw, getBounds, getDoodles, getDoodlesAt, getZOrder, hasDescendant, identifyDoodle, setZOrder
getToolTip, setToolTip
getDefaultOrigin, getParent, redraw, setParent
public void subscribe(FigureObserver iObserver)
Details: subscribe
registers the given observer to receive notifications when the figure changes.
The observer must not be null
.
iObserver
- observer to registerunsubscribe(FigureObserver)
public void unsubscribe(FigureObserver iObserver)
Details:
unsubscribe
unregisters the given observer so that it will stop receiving notifications when the figure changes.
The observer should have already been registered via subscribe
, but there is no harm if this is not the case.
No action is taken if the observer is not registered or if the observer is null
.
iObserver
- observer unregistersubscribe(FigureObserver)
public void add(Doodle iDoodle)
Details:
This method adds the given shape to this figure.
All figure observers are notified via FigureObserver.doodleAdded(Figure, Doodle)
.
An appropriate FigureObserver.doodleChanged(Figure, Doodle)
message is also sent.
In most cases, this message will result in repainting the view.
add
in class CompoundDoodle
iDoodle
- doodle to addremove(Doodle)
public void remove(Doodle iDoodle)
Details:
This method removes the given doodle from this figure.
All figure observers are notified via FigureObserver.doodleRemoved(Figure, Doodle)
.
An appropriate FigureObserver.doodleChanged(Figure, Doodle)
message is also sent.
In most cases, this message will result in repainting the view.
remove
in class CompoundDoodle
iDoodle
- doodle to removeadd(Doodle)
public void sendDoodleChanged(Doodle iShape)
Details:
This method generates a FigureObserver.doodleChanged(Figure, Doodle)
message, with the area set to the bounds of the given shape.
This generally causes all views to mark the area covered by the shape for repainting.
sendDoodleChanged
in interface ParentDoodle
sendDoodleChanged
in class CompoundDoodle
iShape
- shape covering area to invalidatepublic boolean paint(FigGraphics iG)
Details:
paint
renders this figure using the supplied graphics environment.
Before this figure can be rendered correctly, its member shapes must be sorted by Z-draw
takes a "lazy" approach by re-sorting its members only when it has reason to believe that they may be unsorted.
There are two possible situations where re-sorting can be triggered:
1. Shapes have been added to this figure since the last time the collection was sorted.
When this situation occurs, paint
re-sorts the collection immediately before paint the figure.
2. While drawing the figure, paint
discovers unsorted shapes.
In this case, some painting may have already occurred, and paint
cannot continue, because continuing would result in an incorrect result.
Nor can paint
simply re-paint
's only recourse is to abort the operation and signal to the client that it was unsuccessful.
It is then up to the client to call paint
again.
The next time the client calls paint
, paint
will re-
The view, supplied as a InteractiveFigureView
, allows shapes to customize their appearance for various views.
For example, a shape could be configured to be invisible in one view, and visible in another.
Use of this parameter is optional, and null
is an acceptable value.
The caller of paint
should set this parameter to the widget on which the figure is being drawn.
(This model presupposes that each widget will only display one figure, an assumption that may be abandoned in the future.)
paint
returns true
if drawing was successful, false
otherwise.
iG
- the graphics contextCopyright © 2013. All Rights Reserved.