org.tigris.gef.base
Class Editor

java.lang.Object
  extended by org.tigris.gef.base.Editor
All Implemented Interfaces:
java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable, java.util.EventListener

public class Editor
extends java.lang.Object
implements java.io.Serializable, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.KeyListener

This class provides an editor for manipulating graphical documents. The editor is the central class of the graph editing framework, but it does not contain very much code. It can be this small because all the net-level models, graphical objects, layers, editor modes, editor commands, and supporting dialogs and frames are implemented in their own classes.

An Editor's LayerManager has a stack of Layer's. Normally Layers contain Figs. Some Figs are linked to NetPrimitives. When Figs are selected the SelectionManager holds a Selection object. The behavior of the Editor is determined by its current Mode. The Editor's ModeManager keeps track of all the active Modes. Modes interpert user input events and decide how to change the state of the diagram. The Editor acts as a shell for executing Commands that modify the document or the Editor itself.

When Figs change visible state (e.g., color, size, or postition) they tell their Layer that they are damageAll and need to be repainted. The Layer tells all Editors that are editing that A major goal of GEF is to make it easy to extend the framework for application to a specific domain. It is very important that new functionality can be added without modifying what is already there. The fairly small size of the Editor is a good indicator that it is not a bottleneck for enhancing the framework.

See Also:
Layer, Fig, NetPrimitive, Selection, Mode, Cmd, Serialized Form

Field Summary
protected  boolean _canSelectElements
          Should elements in this editor be selectable?
protected  java.lang.Object _document
          This points to the document object that the user is working on.
protected  Guide _guide
          The grid to snap points to.
protected static java.awt.Rectangle _hitRect
          Temp var used to implement hit() without doing memory allocation.
protected  LayerManager _layerManager
          The LayerManager for this Editor.
protected  ModeManager _modeManager
          The user interface mode that the Editor is currently in.
protected  SelectionManager _selectionManager
          All the selection objects for what the user currently has selected.
static int GRIP_SIZE
          Clicking exactly on a small shape is hard for users to do.
 
Constructor Summary
Editor()
           
Editor(Diagram d)
           
Editor(GraphModel gm)
           
Editor(GraphModel gm, javax.swing.JComponent jComponent)
          Construct a new Editor to edit the given NetList
Editor(GraphModel gm, javax.swing.JComponent jComponent, Layer lay)
           
 
Method Summary
 void add(Fig f)
          Add a Fig to the diagram being edited.
 void addGraphSelectionListener(GraphSelectionListener listener)
          Remember to notify listener whenever the selection changes.
 void addModeChangeListener(ModeChangeListener listener)
          Remember to notify listener whenever the mode changes.
 boolean canSelectElements()
          Returns this Editor's current value for the selection flag.
 java.lang.Object clone()
          Clone the receiving editor.
 java.awt.Image createImage(int w, int h)
          Create an Image (an off-screen bit-map) to be used to reduce flicker in redrawing.
 void damageAll()
          Mark the entire visible area of this Editor as damageAll.
 void damaged(Fig f)
           
 void damaged(int x, int y, int width, int height)
          Calling any one of the following damageAll() methods adds a damageAll region (rectangle) that will be redrawn asap.
 void damaged(java.awt.Rectangle r)
          Calling any one of the following damageAll() methods adds a damageAll region (rectangle) that will be redrawn asap.
 void damaged(Selection sel)
          This method will take the current scale into account
protected  void defineLayers(GraphModel gm, Layer lay)
           
 java.lang.Object document()
          Get and set document being edited.
 void document(java.lang.Object d)
           
 void drawingSizeChanged(java.awt.Dimension dim)
          This method is called when the Editor is notified that the drawing panel's natural size has changed, typically because a new diagram has been set.
 void executeCmd(Cmd c, java.awt.event.InputEvent ie)
          The editor acts as a shell for Cmds.
 java.util.Enumeration figs()
          Returns a collection of all Figs in the layer currently being edited.
 java.awt.Frame findFrame()
          Find the AWT Frame that this Editor is being displayed in.
 void finishMode()
          Set this Editor's current Mode to the next global Mode.
 FigTextEditor getActiveTextEditor()
           
 java.awt.Color getBackground()
          Get the backgrund color of the Editor.
 Fig getCurrentFig()
           
 Selection getCurrentSelection()
          Gets the selection object the mouse is in
 GraphEdgeRenderer getGraphEdgeRenderer()
          Get the renderer object that decides how to display edges
 GraphModel getGraphModel()
          Return the net under the diagram being edited.
 GraphNodeRenderer getGraphNodeRenderer()
          Get the renderer object that decides how to display nodes
 boolean getGridHidden()
          Return true if the Grid layer is currently hidden.
 Guide getGuide()
           
 javax.swing.JComponent getJComponent()
           
 LayerManager getLayerManager()
          Return the LayerComposite that holds the diagram being edited.
 ModeManager getModeManager()
           
 javax.swing.JPopupMenu getPopupMenu()
           
 double getScale()
           
 SelectionManager getSelectionManager()
          Reply the current SelectionManager of this Editor.
 Fig hit(int x, int y)
           
 Fig hit(int x, int y, int w, int h)
           
 Fig hit(java.awt.Point p)
          Reply the top Fig in the current layer that contains the given point.
 Fig hit(java.awt.Rectangle r)
          Reply the top Fig in the current layer that contains the given rectangle.
 void keyPressed(java.awt.event.KeyEvent ke)
          Invoked when a key has been pressed.
 void keyReleased(java.awt.event.KeyEvent ke)
          Invoked when a key has been released.
 void keyTyped(java.awt.event.KeyEvent ke)
          Invoked when a key has been pressed and released.
 void mouseClicked(java.awt.event.MouseEvent me)
          Invoked after the mouse has been pressed and released.
 void mouseDragged(java.awt.event.MouseEvent me)
          Invoked when a mouse button is pressed in the Editor and then dragged.
 void mouseEntered(java.awt.event.MouseEvent me)
          Invoked when the mouse enters the Editor.
 void mouseExited(java.awt.event.MouseEvent me)
          Invoked when the mouse exits the Editor.
 void mouseMoved(java.awt.event.MouseEvent me)
          Invoked when the mouse button has been moved (with no buttons no down).
 void mousePressed(java.awt.event.MouseEvent me)
          Invoked when a mouse button has been pressed.
 void mouseReleased(java.awt.event.MouseEvent me)
          Invoked when a mouse button has been released.
 void paint(java.awt.Graphics g)
          Paints the graphs nodes by calling paint() on layers, selections, and mode.
 void postLoad()
          Called after the Editor is loaded from a file.
 void postSave()
          Called after the Editor is saved to a file.
 void preSave()
          Called before the Editor is saved to a file.
 void print(java.awt.Graphics g)
           
 void pushMode(FigModifyingMode mode)
          Pushes a new mode to the mode manager
 void remove(Fig f)
          Remove a Fig from the diagram being edited.
 void removed(Fig f)
          The given Fig was removed from the diagram this Editor is showing.
 void removeGraphSelectionListener(GraphSelectionListener listener)
          Stop notifing listener of selection changes.
 void removeModeChangeListener(ModeChangeListener listener)
          Stop notifing listener of mode changes.
 java.awt.event.MouseEvent retranslateMouseEvent(java.awt.event.MouseEvent me)
          Scales the mouse coordinates (which match the model scale) back to the drawing scale.
 void scaleRect(java.awt.Rectangle bounds)
           
 void scrollToShow(Fig fig)
          Scroll the JGraph so that the given Fig is entirely visible.
 void scrollToShow(int x, int y)
          Scroll the JGraph so that the given point is visible.
 void setCursor(java.awt.Cursor c)
           
 void setElementsSelectable(boolean selectable)
          Set's the selection flag for the Editor.
 void setGraphEdgeRenderer(GraphEdgeRenderer rend)
           
 void setGraphModel(GraphModel gm)
           
 void setGraphNodeRenderer(GraphNodeRenderer rend)
           
 void setGridHidden(boolean b)
          Set the hidden state of the Grid layer.
 void setGuide(Guide g)
           
 void setJComponent(javax.swing.JComponent c)
           
 void setPopupMenu(javax.swing.JPopupMenu p)
           
 void setScale(double scale)
          Set this Editor's drawing scale.
 void setShouldPaint(boolean shouldPaint)
           
protected  void setUnderMouse(java.awt.event.MouseEvent me)
          Find the Fig under the mouse, and the node it represents, if any
 boolean shouldPaint()
           
 void snap(java.awt.Point p)
          Modify the given point to be on the guideline (In this case, a gridline).
protected  java.awt.event.MouseEvent translateMouseEvent(java.awt.event.MouseEvent me)
          Scales the mouse coordinates (which match the drawing scale) back to the model scale.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GRIP_SIZE

public static final int GRIP_SIZE
Clicking exactly on a small shape is hard for users to do. GRIP_MARGIN gives them a chance to have the mouse outside a Fig by a few pixels and still hit it.

See Also:
Constant Field Values

_modeManager

protected ModeManager _modeManager
The user interface mode that the Editor is currently in. Generally Modes that the user has to think about are a bad idea. But even in a very easy to use editor there are plenty of "spring-loaded" modes that change the way the system interprets input. For example, when placing a new node, the editor is in ModePlace, and when dragging a handle of an object the editor is in ModeModify. In each case moving or dragging the mouse has a different effect.

See Also:
ModeModify, ModeSelect, ModePlace

_document

protected java.lang.Object _document
This points to the document object that the user is working on. At this point the framework does not have a very strong concept of document and there is no class Document. For now the meaning of this pointer is in the hands of the person applying this framework to an application.


_selectionManager

protected SelectionManager _selectionManager
All the selection objects for what the user currently has selected.


_layerManager

protected LayerManager _layerManager
The LayerManager for this Editor.


_guide

protected Guide _guide
The grid to snap points to.


_canSelectElements

protected boolean _canSelectElements
Should elements in this editor be selectable?


_hitRect

protected static java.awt.Rectangle _hitRect
Temp var used to implement hit() without doing memory allocation.

Constructor Detail

Editor

public Editor(GraphModel gm,
              javax.swing.JComponent jComponent)
Construct a new Editor to edit the given NetList


Editor

public Editor(GraphModel gm)

Editor

public Editor()

Editor

public Editor(Diagram d)

Editor

public Editor(GraphModel gm,
              javax.swing.JComponent jComponent,
              Layer lay)
Method Detail

defineLayers

protected void defineLayers(GraphModel gm,
                            Layer lay)

preSave

public void preSave()
Called before the Editor is saved to a file.


postSave

public void postSave()
Called after the Editor is saved to a file.


setPopupMenu

public void setPopupMenu(javax.swing.JPopupMenu p)

getPopupMenu

public javax.swing.JPopupMenu getPopupMenu()

postLoad

public void postLoad()
Called after the Editor is loaded from a file.


getGridHidden

public boolean getGridHidden()
Return true if the Grid layer is currently hidden.


setGridHidden

public void setGridHidden(boolean b)
Set the hidden state of the Grid layer.


clone

public java.lang.Object clone()
Clone the receiving editor. Called from ActionSpawn. Subclasses of Editor should override this method. TODO shouldn't this just call super.clone() instead of using reflection? Bob 29 Jan 2004

Overrides:
clone in class java.lang.Object

getModeManager

public ModeManager getModeManager()

pushMode

public void pushMode(FigModifyingMode mode)
Pushes a new mode to the mode manager


finishMode

public void finishMode()
Set this Editor's current Mode to the next global Mode.


getLayerManager

public LayerManager getLayerManager()
Return the LayerComposite that holds the diagram being edited.


getScale

public double getScale()

setScale

public void setScale(double scale)
Set this Editor's drawing scale. A value of 1.0 draws at 1 to 1. A value greater than 1 draws larger, less than 1 draws smaller. Conceptually the scale is an attribute of JGraph, but the editor needs to know it to paint accordingly.


canSelectElements

public boolean canSelectElements()
Returns this Editor's current value for the selection flag.

Returns:
The current value of the selection flag.

setElementsSelectable

public void setElementsSelectable(boolean selectable)
Set's the selection flag for the Editor. If the flag is set to true (default), elements in this Editor are selectable. Otherwise, elements are not selectable, neither by keyboard nor by mouse activity.

Parameters:
selectable - New value for the flag.

getGraphModel

public GraphModel getGraphModel()
Return the net under the diagram being edited.


setGraphModel

public void setGraphModel(GraphModel gm)

getGraphNodeRenderer

public GraphNodeRenderer getGraphNodeRenderer()
Get the renderer object that decides how to display nodes


setGraphNodeRenderer

public void setGraphNodeRenderer(GraphNodeRenderer rend)

getGraphEdgeRenderer

public GraphEdgeRenderer getGraphEdgeRenderer()
Get the renderer object that decides how to display edges


setGraphEdgeRenderer

public void setGraphEdgeRenderer(GraphEdgeRenderer rend)

figs

public java.util.Enumeration figs()
Returns a collection of all Figs in the layer currently being edited.


add

public void add(Fig f)
Add a Fig to the diagram being edited.


remove

public void remove(Fig f)
Remove a Fig from the diagram being edited.


hit

public final Fig hit(java.awt.Point p)
Reply the top Fig in the current layer that contains the given point. This is used in determining what the user clicked on, among other uses.


hit

public final Fig hit(int x,
                     int y)

hit

public final Fig hit(int x,
                     int y,
                     int w,
                     int h)

hit

public Fig hit(java.awt.Rectangle r)
Reply the top Fig in the current layer that contains the given rectangle. This is called by all other hit methods.


setUnderMouse

protected void setUnderMouse(java.awt.event.MouseEvent me)
Find the Fig under the mouse, and the node it represents, if any


document

public java.lang.Object document()
Get and set document being edited. There are no deep semantics here yet, a "document" is up to you to define.


document

public void document(java.lang.Object d)

snap

public void snap(java.awt.Point p)
Modify the given point to be on the guideline (In this case, a gridline).


getGuide

public Guide getGuide()

setGuide

public void setGuide(Guide g)

damaged

public void damaged(java.awt.Rectangle r)
Calling any one of the following damageAll() methods adds a damageAll region (rectangle) that will be redrawn asap.


damaged

public void damaged(int x,
                    int y,
                    int width,
                    int height)
Calling any one of the following damageAll() methods adds a damageAll region (rectangle) that will be redrawn asap. The given bounds must already be scaled accordingly.


damaged

public void damaged(Selection sel)
This method will take the current scale into account

Parameters:
sel -

damaged

public void damaged(Fig f)

scaleRect

public void scaleRect(java.awt.Rectangle bounds)

damageAll

public void damageAll()
Mark the entire visible area of this Editor as damageAll. Currently called when a LayerGrid is adjusted. This will be useful for ActionRefresh if I get around to it. Also some Actions may perfer to do this instead of keeping track of all modified objects, but only in cases where most of the visible area is expected to change anyway.


paint

public void paint(java.awt.Graphics g)
Paints the graphs nodes by calling paint() on layers, selections, and mode.


print

public void print(java.awt.Graphics g)

scrollToShow

public void scrollToShow(int x,
                         int y)
Scroll the JGraph so that the given point is visible. This is used when the user wants to drag an object a long distance. This is commented out right now because it causes too many out of memory errors and the size of the JGraphInternalPanel is not set properly.


scrollToShow

public void scrollToShow(Fig fig)
Scroll the JGraph so that the given Fig is entirely visible.


getSelectionManager

public SelectionManager getSelectionManager()
Reply the current SelectionManager of this Editor.


getCurrentFig

public Fig getCurrentFig()

getJComponent

public javax.swing.JComponent getJComponent()

setJComponent

public void setJComponent(javax.swing.JComponent c)

setCursor

public void setCursor(java.awt.Cursor c)

findFrame

public java.awt.Frame findFrame()
Find the AWT Frame that this Editor is being displayed in. This is needed to open a dialog box.


createImage

public java.awt.Image createImage(int w,
                                  int h)
Create an Image (an off-screen bit-map) to be used to reduce flicker in redrawing.


getBackground

public java.awt.Color getBackground()
Get the backgrund color of the Editor. Often, none of the background will be visible because LayerGrid covers the entire drawing area.


getActiveTextEditor

public FigTextEditor getActiveTextEditor()

drawingSizeChanged

public void drawingSizeChanged(java.awt.Dimension dim)
This method is called when the Editor is notified that the drawing panel's natural size has changed, typically because a new diagram has been set.


addGraphSelectionListener

public void addGraphSelectionListener(GraphSelectionListener listener)
Remember to notify listener whenever the selection changes.


removeGraphSelectionListener

public void removeGraphSelectionListener(GraphSelectionListener listener)
Stop notifing listener of selection changes.


addModeChangeListener

public void addModeChangeListener(ModeChangeListener listener)
Remember to notify listener whenever the mode changes.


removeModeChangeListener

public void removeModeChangeListener(ModeChangeListener listener)
Stop notifing listener of mode changes.


translateMouseEvent

protected java.awt.event.MouseEvent translateMouseEvent(java.awt.event.MouseEvent me)
Scales the mouse coordinates (which match the drawing scale) back to the model scale.


retranslateMouseEvent

public java.awt.event.MouseEvent retranslateMouseEvent(java.awt.event.MouseEvent me)
Scales the mouse coordinates (which match the model scale) back to the drawing scale.


mouseClicked

public void mouseClicked(java.awt.event.MouseEvent me)
Invoked after the mouse has been pressed and released. All events are passed on the SelectionManager and then ModeManager.

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent me)
Invoked when a mouse button has been pressed.

Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent me)
Invoked when a mouse button has been released.

Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent me)
Invoked when the mouse enters the Editor.

Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent me)
Invoked when the mouse exits the Editor.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent me)
Invoked when a mouse button is pressed in the Editor and then dragged. Mouse drag events will continue to be delivered to the Editor where the first originated until the mouse button is released (regardless of whether the mouse position is within the bounds of the Editor). BTW, this makes drag and drop editing almost impossible.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent me)
Invoked when the mouse button has been moved (with no buttons no down).

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

keyTyped

public void keyTyped(java.awt.event.KeyEvent ke)
Invoked when a key has been pressed and released. The KeyEvent has its keyChar ivar set to something, keyCode ivar is junk.

Specified by:
keyTyped in interface java.awt.event.KeyListener

keyPressed

public void keyPressed(java.awt.event.KeyEvent ke)
Invoked when a key has been pressed. The KeyEvent has its keyCode ivar set to something, keyChar ivar is junk.

Specified by:
keyPressed in interface java.awt.event.KeyListener

keyReleased

public void keyReleased(java.awt.event.KeyEvent ke)
Invoked when a key has been released.

Specified by:
keyReleased in interface java.awt.event.KeyListener

executeCmd

public void executeCmd(Cmd c,
                       java.awt.event.InputEvent ie)
The editor acts as a shell for Cmds. This method executes the given Cmd in response to the given event (some Cmds look at the Event that invoke them, even though this is discouraged). The Editor executes the Cmd in a safe environment so that buggy actions cannot crash the whole Editor.


removed

public void removed(Fig f)
The given Fig was removed from the diagram this Editor is showing. Now update the display.


setShouldPaint

public void setShouldPaint(boolean shouldPaint)

shouldPaint

public boolean shouldPaint()

getCurrentSelection

public Selection getCurrentSelection()
Gets the selection object the mouse is in

Returns:
the selection object or null