org.tigris.gef.base
Class Layer

java.lang.Object
  extended by org.tigris.gef.base.Layer
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
LayerDiagram, LayerGrid, LayerPageBreaks, LayerPolar

public abstract class Layer
extends java.lang.Object
implements java.io.Serializable

A Layer is like a drawing layer in high-end drawing applications (e.g., MacDraw Pro). A Layer is like a sheet of clear plastic that can contain part of the picture being drawn and multiple layers are put on top of each other to make the overall picture. Different layers can be hidden, locked, or grayed out independently. In GEF the Layer class is more abstract than described above. LayerDiagram is a subclass of Layer that does what is described above. Other subclasses of Layer can provide functionality. For example the background drawing grid is a subclass of Layer that computes its display rather than displaying what is stored in a data structure. Generalizing the concept of a layer to handle grids and other computed display features gives more power and allows the framework to be extended in building various applications. For example an application that needs polar coordinates might use LayerPolar, and an application that used a world map might implement LayerMap. But since layers can be composed, the user could put a grid in front of or behind the map.

This approach to implementing drawing editors is similar to that described in a published paper: "Using the Multi-Layer Model for Building Interactive Graphical Applications" Fekete, et al. UIST'96. pp. 109-117. GEF might be improved by making it more like the system described in that paper: basically by moving some of the XXXManage functionality into Layers, or merging Layers and Modes.

See Also:
LayerDiagram, LayerPerspective, LayerGrid, LayerPolar, Serialized Form

Field Summary
 java.util.List _editors
          A list of the Editors that are displaying this Layer.
protected  boolean _onMenu
          Should the user be able to hide, lock, or gray this layer? Needs-More-Work.
 
Constructor Summary
Layer()
          Construct a new Layer.
Layer(java.lang.String name)
          Construct a new layer with the given name.
Layer(java.lang.String name, java.lang.String type)
          Construct a new layer with the given name and type.
 
Method Summary
 void add(Fig f)
          Most Layers contain Fig, so I have empty implementations of add, remove, removeAll, elements, and hit.
 void addEditor(Editor ed)
          Add an Editor to the list of Editors showing this Layer.
 void adjust()
          Allow the user to edit the properties of this layer (not the properties of the contents of this layer).
 void bringForward(Fig f)
           
 void bringInFrontOf(Fig f1, Fig f2)
           
 void bringToFront(Fig f)
           
 java.awt.Rectangle calcDrawingArea()
           
 java.lang.Object clone()
           
 void damageAll()
          A Fig in this Layer has changed state and needs to be redrawn.
 void deleted(Fig f)
          A Fig in this Layer has been deleted.
 java.util.Enumeration elements()
           
 java.util.Enumeration elementsIn(java.awt.Rectangle r)
          Reply an enumeration of all the Figs in this Layer that intersect given Rectangle.
 java.util.List getContents()
          Get the figs that make up this layer.
abstract  java.util.Collection getContents(java.util.Collection edges)
          Get the figs that make up this layer.
 java.util.List getContentsEdgesOnly()
          USED BY SVG.tee
 java.util.List getContentsNoEdges()
          USED BY SVG.tee
 java.util.List getEditors()
          Return the list of Editors that are showing this Layer.
 boolean getGrayed()
           
 boolean getHidden()
           
 boolean getLocked()
           
 java.lang.String getName()
          Get and set methods
 boolean getOnMenu()
           
 java.lang.String getPerspectiveType()
          Return a string that can be used to make some Layers show nodes in one way and other Layers show the same nodes in a different way.
 double getScale()
           
 Fig hit(java.awt.Rectangle r)
           
 boolean isAlwaysOnTop()
           
 java.util.Enumeration nodesIn(java.awt.Rectangle r)
          Reply an enumeration of all the FigNodes in this Layer that intersect given Rectangle.
 void paint(java.awt.Graphics g)
          Paint this Layer on the given Graphics.
 void paint(java.awt.Graphics g, FigPainter painter)
          Paint this Layer on the given Graphics using the given FigPainter.
abstract  void paintContents(java.awt.Graphics g)
          Abstract method to paint the contents of this layer, subclasses must define this.
 void paintContents(java.awt.Graphics g, FigPainter painter)
          Method to paint the contents of this layer using a given painter.
 void paintGrayContents(java.awt.Graphics g)
          Paint the contents in a dimmed, demphasized way.
 void postLoad()
           
 void postSave()
           
 void preSave()
           
abstract  Fig presentationFor(java.lang.Object obj)
          Given an object from the net-level model (e.g., NetNode or NetPort), reply the graphical depiction of that object in this layer, if there is one.
 void print(java.awt.Graphics g)
          Draw the Layer on a PrintGraphics.
 void refreshEditors()
          Ask all Editors to completely redraw their display.
 void remove(Fig f)
           
 void removeAll()
           
 void removeEditor(Editor ed)
           
 void reorder(Fig f, int function)
           
 void sendBackward(Fig f)
           
 void sendToBack(Fig f)
          Most Layers will contain things in back to front order, so I define empty reordering functions here.
 void setAlwaysOnTop(boolean onTop)
           
 void setGrayed(boolean b)
           
 void setHidden(boolean b)
           
 void setLocked(boolean b)
           
 void setName(java.lang.String n)
           
 void setOnMenu(boolean b)
           
 void setPerspectiveType(java.lang.String t)
           
 void setScale(double scale)
           
 java.lang.String toString()
          Reply a string useful for debugging
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_onMenu

protected boolean _onMenu
Should the user be able to hide, lock, or gray this layer? Needs-More-Work.


_editors

public transient java.util.List _editors
A list of the Editors that are displaying this Layer.

Constructor Detail

Layer

public Layer()
Construct a new Layer. This abstract class really does nothing in its constructor, but subclasses may have meaningful constructors.


Layer

public Layer(java.lang.String name)
Construct a new layer with the given name.


Layer

public Layer(java.lang.String name,
             java.lang.String type)
Construct a new layer with the given name and type.

Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Reply a string useful for debugging

Overrides:
toString in class java.lang.Object

getName

public java.lang.String getName()
Get and set methods


setName

public void setName(java.lang.String n)

setHidden

public void setHidden(boolean b)

getHidden

public boolean getHidden()

setGrayed

public void setGrayed(boolean b)

getGrayed

public boolean getGrayed()

setLocked

public void setLocked(boolean b)

getLocked

public boolean getLocked()

setAlwaysOnTop

public void setAlwaysOnTop(boolean onTop)

isAlwaysOnTop

public boolean isAlwaysOnTop()

setScale

public void setScale(double scale)

getScale

public double getScale()

setOnMenu

public void setOnMenu(boolean b)

getOnMenu

public boolean getOnMenu()

getContents

public abstract java.util.Collection getContents(java.util.Collection edges)
Get the figs that make up this layer.

Parameters:
edges - the collection in which to place the edges or null if a new collection should be created
Returns:
the figs

getContents

public java.util.List getContents()
Get the figs that make up this layer.

Returns:
the figs

getContentsNoEdges

public java.util.List getContentsNoEdges()
USED BY SVG.tee


getContentsEdgesOnly

public java.util.List getContentsEdgesOnly()
USED BY SVG.tee


getEditors

public java.util.List getEditors()
Return the list of Editors that are showing this Layer.


add

public void add(Fig f)
Most Layers contain Fig, so I have empty implementations of add, remove, removeAll, elements, and hit.

See Also:
LayerDiagram

remove

public void remove(Fig f)

removeAll

public void removeAll()

elements

public java.util.Enumeration elements()

hit

public Fig hit(java.awt.Rectangle r)

elementsIn

public java.util.Enumeration elementsIn(java.awt.Rectangle r)
Reply an enumeration of all the Figs in this Layer that intersect given Rectangle.


nodesIn

public java.util.Enumeration nodesIn(java.awt.Rectangle r)
Reply an enumeration of all the FigNodes in this Layer that intersect given Rectangle.


presentationFor

public abstract Fig presentationFor(java.lang.Object obj)
Given an object from the net-level model (e.g., NetNode or NetPort), reply the graphical depiction of that object in this layer, if there is one. Otherwise reply null.


getPerspectiveType

public java.lang.String getPerspectiveType()
Return a string that can be used to make some Layers show nodes in one way and other Layers show the same nodes in a different way. By default just use the name of the layer, but in general names are for users to specify as reminders to themselves and the perspectiveType controls what kinds of node FigNodes will be added to that view.


setPerspectiveType

public void setPerspectiveType(java.lang.String t)

sendToBack

public void sendToBack(Fig f)
Most Layers will contain things in back to front order, so I define empty reordering functions here. Subclasses can implement these if appropriate.


bringForward

public void bringForward(Fig f)

sendBackward

public void sendBackward(Fig f)

bringToFront

public void bringToFront(Fig f)

bringInFrontOf

public void bringInFrontOf(Fig f1,
                           Fig f2)

reorder

public void reorder(Fig f,
                    int function)

print

public void print(java.awt.Graphics g)
Draw the Layer on a PrintGraphics. By default, just calls paint(g).


paint

public void paint(java.awt.Graphics g)
Paint this Layer on the given Graphics. Sublasses should define methods for paintContents, which is called from here if the Layer is not hidden.


paint

public void paint(java.awt.Graphics g,
                  FigPainter painter)
Paint this Layer on the given Graphics using the given FigPainter. Sublasses should define methods for paintContents, which is called from here if the Layer is not hidden.


paintContents

public void paintContents(java.awt.Graphics g,
                          FigPainter painter)
Method to paint the contents of this layer using a given painter. The default implementation ignores the painter.


paintContents

public abstract void paintContents(java.awt.Graphics g)
Abstract method to paint the contents of this layer, subclasses must define this. For example, LayerDiagram paints itself by painting a list of Figs and LayerGrid paints itself by painting a lot lines.


paintGrayContents

public void paintGrayContents(java.awt.Graphics g)
Paint the contents in a dimmed, demphasized way. Calls paintContents. Needs-More-Work: really needs a new kind of Graphics to work right.


calcDrawingArea

public java.awt.Rectangle calcDrawingArea()

damageAll

public void damageAll()
A Fig in this Layer has changed state and needs to be redrawn. Notify all Editors showing this Layer that they should record the damage.


deleted

public void deleted(Fig f)
A Fig in this Layer has been deleted. Notify all Editors so that they can deselect the Fig.


refreshEditors

public void refreshEditors()
Ask all Editors to completely redraw their display.


addEditor

public void addEditor(Editor ed)
Add an Editor to the list of Editors showing this Layer.


removeEditor

public void removeEditor(Editor ed)

preSave

public void preSave()

postSave

public void postSave()

postLoad

public void postLoad()

adjust

public void adjust()
Allow the user to edit the properties of this layer (not the properties of the contents of this layer). For example, in LayerGrid this could set the grid size. By default, does nothing.

See Also:
LayerGrid