Class Drawing
- java.lang.Object
-
- jpicedt.graphic.model.Drawing
-
- All Implemented Interfaces:
javax.swing.undo.StateEditable
public class Drawing extends java.lang.Object implements javax.swing.undo.StateEditableAn extensible array used to store ElementsThis is the MODEL part of the View-Model-Controller paradigm (aka javax.swing.text.Document), aimed at being plugged into an existing PECanvas. It has the structure of a tree-model, with the root element of the tree being Drawing.RootElement : Element's added to this Drawing are actually added to its RootElement ; each Element in turn may or may not have children (see e.g. classes DefaultLeafElement and BranchElement).
Element's should be added to this Drawing using the Drawing's API (i.e. shouldn't be directly added to RootElement), by using theaddElement()method. so that DrawingEvent's dispatching works properly.Objects are stored in ascending order according to their z-value, i.e. from back to front. Note that this class does NOT include any selection-handling mechanism : for a variety of reasons, this mechanism has been moved to the associated EditorKit (aka "Controller" in the VMC paradigm), which may itself delegate this behaviour to an appropriate SelectionHandler. This makes the Drawing class a versatile document model for handling a variety of graphics elements without bothering about the UI interaction.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classDrawing.Customizera customizer for editing the bounding boxclassDrawing.DefaultDrawingEventan implementation of DrawingEventclassDrawing.RootElementthe Element that is the root of the tree of Element's in this Drawing.
-
Field Summary
Fields Modifier and Type Field Description protected java.awt.geom.Rectangle2DboundingBoxbounding box used when formatting to text ; null means that it'll be computed automaticallyprotected javax.swing.event.EventListenerListlistenerListlist of listener's (e.g.protected java.lang.StringnotParsedCommandsa string containing commands read from file but not parsedprotected Drawing.RootElementrootthe root-element of the drawing
-
Constructor Summary
Constructors Constructor Description Drawing()Construct a new empty DrawingDrawing(java.util.Collection c)Construct a new Drawing from the given Collection, which is supposed to contain Element's.Drawing(BranchElement e)construct a new Drawing whose content is initialized from the content of the given BranchElement.Drawing(Drawing dr)cloning constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDrawingListener(DrawingListener l)adds a DrawingListener to the DrawingvoidaddElement(Element element)Add the given element to this Drawingjava.lang.Objectclone()java.util.Iteratorelements()protected voidfireChangedUpdate(Element changed, DrawingEvent.EventType type)Notify all listeners that have registered interest for notification on this event type.java.awt.geom.Rectangle2DgetBoundingBox()Drawing.CustomizergetCustomizer()Return a bounding box customizer for this DrawingElementgetElement(int i)java.lang.StringgetNotparsedCommands()Drawing.RootElementgetRootElement()ViewgetRootView()booleanisAutoComputeBoundingBox()Return true if the bb is computed automatically on-the-flyvoidremoveDrawingListener(DrawingListener l)removes a DrawingListener from the DrawingvoidremoveElement(Element element)Remove the given graphic object from this Drawing, overriden so as to update selection if this element was selected.voidreplaceElement(int index, Element element)Replace the element at the given index with the given graphic element No effet if "element" already belongs to the drawing.voidreplaceElement(Element src, Element dest)Replace the given "src" element with the given "dest" element, if "src" belongs to this drawing.voidrestoreState(java.util.Hashtable map)Restore RootElement from the given Hashtable, using key="state"voidsetBoundingBox(java.awt.geom.Rectangle2D bb)set bounding box manually ; set to null to switch back to automatic behaviourvoidsetNotparsedCommands(java.lang.String str)voidsetViewTree(ViewFactory f)set the view tree that renders this drawing to screen, starting from the root-element.intsize()voidstoreState(java.util.Hashtable map)Store a clone of RootElement in the given Hashtable, with key = "state"java.lang.StringtoString()Returns a String representing the drawing for debugging use only.
-
-
-
Field Detail
-
root
protected Drawing.RootElement root
the root-element of the drawing
-
listenerList
protected javax.swing.event.EventListenerList listenerList
list of listener's (e.g. DrawingListener's) that get notified events from this model
-
notParsedCommands
protected java.lang.String notParsedCommands
a string containing commands read from file but not parsed
-
boundingBox
protected java.awt.geom.Rectangle2D boundingBox
bounding box used when formatting to text ; null means that it'll be computed automatically
-
-
Constructor Detail
-
Drawing
public Drawing()
Construct a new empty Drawing
-
Drawing
public Drawing(java.util.Collection c)
Construct a new Drawing from the given Collection, which is supposed to contain Element's. Children are cloned beforehands.
-
Drawing
public Drawing(BranchElement e)
construct a new Drawing whose content is initialized from the content of the given BranchElement. Children are cloned beforehands, so it's perfectly safe to use this constructor if one doesn't want to modify the initial content of the given BranchElement.
-
Drawing
public Drawing(Drawing dr)
cloning constructor
-
-
Method Detail
-
clone
public java.lang.Object clone()
- Overrides:
clonein classjava.lang.Object- Returns:
- a deep copy of this Drawing
-
getRootElement
public Drawing.RootElement getRootElement()
- Returns:
- the root-element for the tree hierarchy that stores element in this drawing
-
size
public int size()
- Returns:
- the number of graphic objects in this drawing.
-
removeElement
public void removeElement(Element element)
Remove the given graphic object from this Drawing, overriden so as to update selection if this element was selected.
-
addElement
public void addElement(Element element)
Add the given element to this Drawing
-
replaceElement
public void replaceElement(int index, Element element)Replace the element at the given index with the given graphic element No effet if "element" already belongs to the drawing.
-
replaceElement
public void replaceElement(Element src, Element dest)
Replace the given "src" element with the given "dest" element, if "src" belongs to this drawing. No effet if "dest" already belongs to the drawing.
-
elements
public java.util.Iterator elements()
- Returns:
- an iterator over elements
-
getElement
public Element getElement(int i)
- Returns:
- the element at position i
-
getBoundingBox
public java.awt.geom.Rectangle2D getBoundingBox()
- Returns:
- the bounding-box of the drawing ; this is a convenience call to
rootElement.getBoundingBoxexcept if setBoundingBox was called with a non-null argument before.
-
setBoundingBox
public void setBoundingBox(java.awt.geom.Rectangle2D bb)
set bounding box manually ; set to null to switch back to automatic behaviour
-
isAutoComputeBoundingBox
public boolean isAutoComputeBoundingBox()
Return true if the bb is computed automatically on-the-fly
-
getRootView
public View getRootView()
- Returns:
- the root-view that renders this Drawing to a graphic context ; this is actually the View associated with the root-element.
-
setViewTree
public void setViewTree(ViewFactory f)
set the view tree that renders this drawing to screen, starting from the root-element. The root-view produced by the factory (to be associated with the root-element) must know how to find its container (usually a PECanvas), otherwise calls torepaint, etc... will fail.- Parameters:
f- the ViewFactory that produces View's for the Element's of the tree
-
addDrawingListener
public void addDrawingListener(DrawingListener l)
adds a DrawingListener to the Drawing
-
removeDrawingListener
public void removeDrawingListener(DrawingListener l)
removes a DrawingListener from the Drawing
-
fireChangedUpdate
protected void fireChangedUpdate(Element changed, DrawingEvent.EventType type)
Notify all listeners that have registered interest for notification on this event type.- Parameters:
changed- an array containing the elements that changed
-
storeState
public void storeState(java.util.Hashtable map)
Store a clone of RootElement in the given Hashtable, with key = "state"- Specified by:
storeStatein interfacejavax.swing.undo.StateEditable
-
restoreState
public void restoreState(java.util.Hashtable map)
Restore RootElement from the given Hashtable, using key="state"- Specified by:
restoreStatein interfacejavax.swing.undo.StateEditable
-
toString
public java.lang.String toString()
Returns a String representing the drawing for debugging use only.- Overrides:
toStringin classjava.lang.Object
-
setNotparsedCommands
public void setNotparsedCommands(java.lang.String str)
- Parameters:
a- string containing commands read from file or inserted by user, but not parsable.
-
getNotparsedCommands
public java.lang.String getNotparsedCommands()
- Returns:
- a string containing (e.g. LaTeX) commands read from file or inserted by user, but not parsable.
-
getCustomizer
public Drawing.Customizer getCustomizer()
Return a bounding box customizer for this Drawing
-
-