com.tensegrity.gui.swing.document
Class SwingTemplateDocument

java.lang.Object
  extended bycom.tensegrity.gui.document.AbstractDocument
      extended bycom.tensegrity.gui.swing.document.SwingDocument
          extended bycom.tensegrity.gui.swing.document.SwingGraphDocument
              extended bycom.tensegrity.gui.swing.document.SwingTemplateDocument
All Implemented Interfaces:
AttributableOnSetListener, Container, Document, EventListenerTag, GraphDocument, Observer, TemplateDocument

public class SwingTemplateDocument
extends SwingGraphDocument
implements TemplateDocument

The SwingTemplateDocument implements the document to be used when creating Templates. A template is a single element from a templatelist. Basically this implementation is based on the SwingGraphDocument, but provides additional functionality to handle Template elements, such as adding primitives, toggling a grid- and snap-to-grid-mode and updating an associated AttributableOnSet.

Version:
$Id: SwingTemplateDocument.java,v 1.52 2006/03/02 11:41:40 BurkhardWick Exp $
Author:
Gilles Iachelini

Field Summary
 
Fields inherited from interface com.tensegrity.gui.document.Document
GLUE_LEFTBOTTOM, GLUE_LEFTCENTEREXTEND, GLUE_LEFTTOP, GLUE_RIGHTBOTTOM, GLUE_RIGHTCENTEREXTEND, GLUE_RIGHTTOP, TYPE_FIXED_SIZE, TYPE_PACK_IS_OK, TYPE_TOOLDOCUMENT
 
Fields inherited from interface com.tensegrity.gui.graphdocument.GraphDocument
SETTING_ADJUSTVIEWAFTEROPEN, SETTING_ANTIALIAS, SETTING_COMPRESSIMAGES, SETTING_COMPRESSION, SETTING_DRAWINGORDER, SETTING_SAVEGEOMETRYDEFS, SETTING_SAVEGEOMETRYDEFSFILTER, SETTING_SAVEIMAGES, SETTING_SAVELAYOUT, SETTING_SAVELAYOUTDEFSFILTER, SETTING_SAVEPREVIEW, SETTING_SAVERULEDEFS, SETTING_SAVERULEDEFSFILTER, SETTING_SAVESTYLEDEFS, SETTING_SAVESTYLEDEFSFILTER, SETTING_SETDIRTYONVIEWCHANGES, SETTING_USEXMLENTITIES, SETTING_WARNWHENLOSINGINFOS_IMAGES, SETTING_WARNWHENLOSINGINFOS_LAYOUT, SETTING_WARNWHENLOSINGINFOS_RULES, SETTINGVALUE_COMPRESSION_GZIP, SETTINGVALUE_COMPRESSION_NONE, SETTINGVALUE_FILTER_ALL, SETTINGVALUE_FILTER_USED, SETTINGVALUE_WARNWHENLOSINGINFOS_CHANGED, SETTINGVALUE_WARNWHENLOSINGINFOS_NEVER, SETTINGVALUE_WARNWHENLOSINGINFOS_USED, SETTINGVALUE_WARNWHENLOSINGINFOS_USEDORCHANGED, SETTINGVALUE_WARNWHENLOSINGINFOS_USINGCHANGED
 
Constructor Summary
SwingTemplateDocument(java.lang.String name, GraphApplication graphapplication, GraphController graphcontroller, VisualGraphView visualgraphview, DragContext vgoDragSource)
          Creates the SwingTemplateDocument based on the given name.
 
Method Summary
 void addElements(BaseComposite baseComposite, java.util.Map elementsMap)
          This method recursively creates a map which either maps primtives to composites, or container to maps, which again contain primitve/composites or container/list elements.
 void addNodeForPrimitive(BaseComposite bcomposite, Primitive primitive)
          Adds a VisualNode, which wraps the given primitive, to this document.
 void addNodeForPrimitive(Primitive primitive)
          Adds a VisualNode, which wraps the given primitive, to this document.
 void addVisualGraphObject(VisualGraphObject vgo, int x, int y)
          Adds a VisualGraphObject to this document.
 void attributesChanged(AttributableOnSetEvent attributableOnSetEvent)
          Invoked when an attribute in an AttributableOnSet object has changed.
 void closeHandler()
          This method is a callback that is invoked before the document is closed.
 void deselect()
          Method deselect delesects all currently selected elements of this document.
 java.util.Map getElementsMap()
          This method should create map, where either primitives of the document are mapped towards their enclosing composites, or container elements are mapped to a list composite-primitive tuple.
 int getFlags()
          Returns flags describing the nature of the document.
 GraphPanel getGraphPanel()
          Returns the graphpanel inside this graphdocument.
 java.util.List getSelection()
          Method getSelection returns a list with all currently selected elements.
 AttributableOnSet getTemplateAttributable()
          Method getTemplateAttributable returns an AttributableOnSet describing all the properties of this document.
 void init(TemplateAttributableOnSet attributable)
          Method init adds a MouseListener to the internal JComponent instance to keep track about the current position (Required for the polygon editing).
 boolean isInPointMode()
          Should return true, when the user activates the point mode, otherwise false.
 boolean isShowGrid()
          Method isShowGrid returns true, if a grid is shown, otherwise false.
 boolean isSnapToGrid()
          Method isSnapToGrid returns true, if the all elements within the document should snap to the nearest grid point or not.
 void removeAllPrimitives()
          Method removeAllPrimitives removes all Primitives from this document.
 void removePrimitive(Primitive primitive)
          Method removePrimitive removes a specific primitive from this document.
 void repaint()
          Method repaint triggers a repaint of the document.
 void selectAll()
          Method selectAll selects all Elements of this document.
 void setName(java.lang.String name)
          Sets the name of this container.
 void setPopupMenuSource(JPopupMenuSourceWithUpdateUI popup)
          Allows users of this class to set an SwingPopupMenu for this document instance.
 void setShowGrid(boolean b)
          Method setShowGrid toggles whether a grid is shown or not.
 void setSnapToGrid(boolean b)
          Method setSnapToGrid toggles the snap-to-grid mode.
 void togglePointMode()
          Method togglePolygonMode toggles the edit-polygon mode.
 
Methods inherited from class com.tensegrity.gui.swing.document.SwingGraphDocument
getJComponent, getPageFormat, getViewBuilderFilter, getViewSerializerFilter, registerViewBuilderFilter, registerViewSerializerFilter, setDocumentSetting, setModified, setPageFormat, setUnmodified, setVisualGraphView, update
 
Methods inherited from class com.tensegrity.gui.swing.document.SwingDocument
getApplicationFrame
 
Methods inherited from class com.tensegrity.gui.document.AbstractDocument
getCopyCounter, getDocumentDataProvider, getDocumentSetting, getDocumentSettings, getFile, getName, isModified, setDocumentSettings, setFile, setSelected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.tensegrity.gui.document.Document
getCopyCounter, getDocumentDataProvider, getDocumentSetting, getDocumentSettings, getFile, isModified, setDocumentSetting, setDocumentSettings, setFile, setModified, setUnmodified
 
Methods inherited from interface com.tensegrity.generic.util.Observer
update
 
Methods inherited from interface com.tensegrity.gui.container.Container
getApplicationFrame, getName, setSelected
 

Constructor Detail

SwingTemplateDocument

public SwingTemplateDocument(java.lang.String name,
                             GraphApplication graphapplication,
                             GraphController graphcontroller,
                             VisualGraphView visualgraphview,
                             DragContext vgoDragSource)
Creates the SwingTemplateDocument based on the given name. All other parameters are directly passed to the super class.

Parameters:
name - the name of the document.
graphapplication - the enclosing GraphApplication.
graphcontroller - the GraphController.
visualgraphview - the wrapped VisualGraphView
vgoDragSource - a DragContext instance.
Method Detail

init

public void init(TemplateAttributableOnSet attributable)
Method init adds a MouseListener to the internal JComponent instance to keep track about the current position (Required for the polygon editing). Furthermore this method creates all internally used Commands, adds a PopupMenuSource to the internal GraphPanel and creates a custom AttributableOnSetDelegate for the GraphPanel to show Document properties on empty selections.

Specified by:
init in interface TemplateDocument
Parameters:
attributable - the TemplateAttributableOnSet containing the document related information.

closeHandler

public void closeHandler()
Description copied from interface: Document
This method is a callback that is invoked before the document is closed. It allows the document to clean up and properly dispose of any resources it had acquired and/or allocated.

Specified by:
closeHandler in interface Document
Overrides:
closeHandler in class SwingGraphDocument

addVisualGraphObject

public void addVisualGraphObject(VisualGraphObject vgo,
                                 int x,
                                 int y)
Description copied from interface: TemplateDocument
Adds a VisualGraphObject to this document.

Specified by:
addVisualGraphObject in interface TemplateDocument
Parameters:
vgo - object to add.
x - x position
y - y position

addNodeForPrimitive

public void addNodeForPrimitive(Primitive primitive)
Description copied from interface: TemplateDocument
Adds a VisualNode, which wraps the given primitive, to this document.

Specified by:
addNodeForPrimitive in interface TemplateDocument
Parameters:
primitive - the new primitive to add.

addNodeForPrimitive

public void addNodeForPrimitive(BaseComposite bcomposite,
                                Primitive primitive)
Description copied from interface: TemplateDocument
Adds a VisualNode, which wraps the given primitive, to this document. The composite is required to obtain the correct sizes, position and coordinates.

Specified by:
addNodeForPrimitive in interface TemplateDocument
Parameters:
bcomposite - the composite to use to obtain sizes and positions.
primitive - the primitive to add.

deselect

public void deselect()
Description copied from interface: TemplateDocument
Method deselect delesects all currently selected elements of this document.

Specified by:
deselect in interface TemplateDocument

addElements

public void addElements(BaseComposite baseComposite,
                        java.util.Map elementsMap)
This method recursively creates a map which either maps primtives to composites, or container to maps, which again contain primitve/composites or container/list elements.

Parameters:
baseComposite - The composite to analyze.
elementsMap - the Map to add the elements to.

getElementsMap

public java.util.Map getElementsMap()
Description copied from interface: TemplateDocument
This method should create map, where either primitives of the document are mapped towards their enclosing composites, or container elements are mapped to a list composite-primitive tuple. This means: This map contains as key either a primitive or a container. A primitive is always map to a composite (its enclosing one), and a container is always mapped to a List, which is again a primitive-composites map, or container-list map.

Specified by:
getElementsMap in interface TemplateDocument
Returns:
a Map where Primitive's are mapped to their enclosing Composite's.

getSelection

public java.util.List getSelection()
Description copied from interface: TemplateDocument
Method getSelection returns a list with all currently selected elements.

Specified by:
getSelection in interface TemplateDocument
Returns:
List an instance of java.util.List with all selected elements.

getTemplateAttributable

public AttributableOnSet getTemplateAttributable()
Description copied from interface: TemplateDocument
Method getTemplateAttributable returns an AttributableOnSet describing all the properties of this document. This AttributableOnSet should structured in Categories which contain the category specific attributes.

Specified by:
getTemplateAttributable in interface TemplateDocument
Returns:
AttributableOnSet
See Also:
AttributeTable

isShowGrid

public boolean isShowGrid()
Description copied from interface: TemplateDocument
Method isShowGrid returns true, if a grid is shown, otherwise false.

Specified by:
isShowGrid in interface TemplateDocument
Returns:
boolean that indicates whether a grid is shown or not.

isSnapToGrid

public boolean isSnapToGrid()
Description copied from interface: TemplateDocument
Method isSnapToGrid returns true, if the all elements within the document should snap to the nearest grid point or not.

Specified by:
isSnapToGrid in interface TemplateDocument
Returns:
boolean true, if snapToGrid is activated, otherwise false.

removeAllPrimitives

public void removeAllPrimitives()
Description copied from interface: TemplateDocument
Method removeAllPrimitives removes all Primitives from this document.

Specified by:
removeAllPrimitives in interface TemplateDocument

removePrimitive

public void removePrimitive(Primitive primitive)
Description copied from interface: TemplateDocument
Method removePrimitive removes a specific primitive from this document.

Specified by:
removePrimitive in interface TemplateDocument
Parameters:
primitive - the instance of Primitive to remove.

repaint

public void repaint()
Description copied from interface: TemplateDocument
Method repaint triggers a repaint of the document.

Specified by:
repaint in interface TemplateDocument

setPopupMenuSource

public void setPopupMenuSource(JPopupMenuSourceWithUpdateUI popup)
Description copied from interface: TemplateDocument
Allows users of this class to set an SwingPopupMenu for this document instance.

Specified by:
setPopupMenuSource in interface TemplateDocument
Parameters:
popup - the new SwingPopupMenu for this document.

selectAll

public void selectAll()
Description copied from interface: TemplateDocument
Method selectAll selects all Elements of this document.

Specified by:
selectAll in interface TemplateDocument

setName

public void setName(java.lang.String name)
Description copied from interface: Container
Sets the name of this container.

Specified by:
setName in interface Container
Overrides:
setName in class AbstractDocument
Parameters:
name - the document's name.

setShowGrid

public void setShowGrid(boolean b)
Description copied from interface: TemplateDocument
Method setShowGrid toggles whether a grid is shown or not.

Specified by:
setShowGrid in interface TemplateDocument
Parameters:
b - if true, a grid is shown, otherwise false.

setSnapToGrid

public void setSnapToGrid(boolean b)
Description copied from interface: TemplateDocument
Method setSnapToGrid toggles the snap-to-grid mode.

Specified by:
setSnapToGrid in interface TemplateDocument
Parameters:
b - if true, all objects are snapping to a grid when added or moved.

togglePointMode

public void togglePointMode()
Description copied from interface: TemplateDocument
Method togglePolygonMode toggles the edit-polygon mode. Such a mode allows users to add points to a given polygon.

Specified by:
togglePointMode in interface TemplateDocument

isInPointMode

public boolean isInPointMode()
Description copied from interface: TemplateDocument
Should return true, when the user activates the point mode, otherwise false.

Specified by:
isInPointMode in interface TemplateDocument
Returns:
true if the point mode is active on this document.

getGraphPanel

public GraphPanel getGraphPanel()
Description copied from interface: TemplateDocument
Returns the graphpanel inside this graphdocument.

Specified by:
getGraphPanel in interface TemplateDocument
Overrides:
getGraphPanel in class SwingGraphDocument

attributesChanged

public void attributesChanged(AttributableOnSetEvent attributableOnSetEvent)
Description copied from interface: AttributableOnSetListener
Invoked when an attribute in an AttributableOnSet object has changed.

Specified by:
attributesChanged in interface AttributableOnSetListener
Parameters:
attributableOnSetEvent - the event carrying information.

getFlags

public int getFlags()
Description copied from interface: Document
Returns flags describing the nature of the document.

Specified by:
getFlags in interface Document
Overrides:
getFlags in class AbstractDocument
Returns:
flags describing the nature of the document.


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.