org.tigris.gef.graph.presentation
Class JGraph

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.tigris.gef.graph.presentation.JGraph
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Cloneable, javax.accessibility.Accessible

public class JGraph
extends javax.swing.JPanel
implements java.lang.Cloneable

JGraph is a Swing component that displays a connected graph and allows interactive editing. In many ways this class serves as a simple front-end to class Editor, and other classes which do the real work.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JGraph()
          Make a new JGraph with a new DefaultGraphModel.
JGraph(ConnectionConstrainer cc)
          Make a new JGraph with a new DefaultGraphModel.
JGraph(Diagram d)
          Make a new JGraph with a the GraphModel and Layer from the given Diagram.
JGraph(Editor ed)
          Make a new JGraph with the given Editor.
JGraph(GraphModel gm)
          Make a new JGraph with the given GraphModel
 
Method Summary
 void addGraphSelectionListener(GraphSelectionListener listener)
          Add listener to the objects to notify whenever the Editor changes its current selection.
 void addKeyListener(java.awt.event.KeyListener listener)
           
 void addModeChangeListener(ModeChangeListener listener)
           
 void addMouseListener(java.awt.event.MouseListener listener)
           
 void addMouseMotionListener(java.awt.event.MouseMotionListener listener)
           
 void bindKey(java.awt.event.ActionListener action, int keyCode, int modifiers)
          Utility function to bind a keystroke to a Swing Action.
 java.lang.Object clone()
          Make a copy of this JGraph so that it can be shown in another window.
 void deselect(Fig f)
          Remove the given item from this editors selections.
 void deselectAll()
          Deslect everything that is currently selected.
 boolean equals(java.lang.Object o)
           
 void establishAlternateMouseWheelListener(java.awt.event.MouseWheelListener listener, int mask)
          Establishes alternate MouseWheelListener object that's only active when the alt/shift/ctrl keys are held down.
protected  java.lang.String getCurrentDiagramId()
           
 java.awt.Dimension getDefaultSize()
           
 Editor getEditor()
          Get the Editor that is being displayed
 GraphEdgeRenderer getGraphEdgeRenderer()
           
 GraphModel getGraphModel()
          Get the GraphModel the Editor is using.
 GraphNodeRenderer getGraphNodeRenderer()
           
 java.awt.Point getViewPosition()
          Get the position of the editor's scrollpane.
 int hashCode()
           
 void initKeys()
           
 boolean isFocusTraversable()
          Tell Swing/AWT that JGraph can be tabbed into.
 boolean isManagingFocus()
          Tell Swing/AWT that JGraph handles tab-order itself.
 void removeGraphSelectionListener(GraphSelectionListener listener)
           
 void removeModeChangeListener(ModeChangeListener listener)
           
 void select(Fig f)
          Add the given item to this Editor's selections.
 void select(java.util.Vector items)
          Select a collection of Figs.
 void selectByOwner(java.lang.Object owner)
          Find the Fig that owns the given item and select it.
 void selectByOwnerOrFig(java.lang.Object owner)
          Find Fig that owns the given item, or the item if it is a Fig, and select it.
 void selectByOwnerOrNoChange(java.lang.Object owner)
          Add the Fig that owns the given item to this Editor's selections.
 java.util.Vector selectedFigs()
          reply a Vector of all selected Figs.
 void setDefaultSize(java.awt.Dimension dim)
           
 void setDefaultSize(int width, int height)
           
 void setDiagram(Diagram d)
          Set the Diagram that should be displayed by setting the GraphModel and Layer that the Editor is using.
 void setDrawingSize(java.awt.Dimension dim)
           
 void setDrawingSize(int width, int height)
           
 void setGraphEdgeRenderer(GraphEdgeRenderer r)
          Get and set the Renderer used to make FigEdges for edges in the GraphModel.
 void setGraphModel(GraphModel gm)
          Set the GraphModel the Editor is using.
 void setGraphNodeRenderer(GraphNodeRenderer r)
          Get and set the Renderer used to make FigNodes for nodes in the GraphModel.
 void setViewPosition(java.awt.Point p)
          Set the position of the editor's scrollpane.
 void setVisible(boolean b)
          When the JGraph is hidden, hide its internal pane
 void toggleItem(Fig f)
          Select the given item if it was not already selected, and vis-a-versa.
 void toggleItems(java.util.Vector items)
          Toggle the selection of a collection of Figs.
protected  void updateDrawingSizeToIncludeAllFigs(java.util.Enumeration iter)
          Enlarges the JGraphInternalPane dimensions as necessary to insure that all the contained Figs are visible.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JGraph

public JGraph()
Make a new JGraph with a new DefaultGraphModel.

See Also:
DefaultGraphModel

JGraph

public JGraph(ConnectionConstrainer cc)
Make a new JGraph with a new DefaultGraphModel.

See Also:
DefaultGraphModel

JGraph

public JGraph(Diagram d)
Make a new JGraph with a the GraphModel and Layer from the given Diagram.


JGraph

public JGraph(GraphModel gm)
Make a new JGraph with the given GraphModel


JGraph

public JGraph(Editor ed)
Make a new JGraph with the given Editor. All JGraph contructors eventually call this contructor.

Method Detail

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
TODO: Investigate further:

According to a mail from GZ (6th November 2004) on the ArgoUML dev list, {@link javax.swing.RepaintManager} puts these objects in some kind of data structure that uses this function. Assuming that there is a reason for this we dare not sabotage this by short-circuiting this to 0. Instead we rely on that {@link org.tigris.gef.graph.presentation.JGraph#setDiagram( org.tigris.gef.base.Diagram)} actually removes this object from the {@link javax.swing.RepaintManager} and registers it again when resetting the diagram id.

This is based on the assumption that the function {@link #equals(Object)} must work as it does. I (Linus) have not understood why it must. Could someone please explain that in the javadoc.


addMouseListener

public void addMouseListener(java.awt.event.MouseListener listener)
Overrides:
addMouseListener in class java.awt.Component

addMouseMotionListener

public void addMouseMotionListener(java.awt.event.MouseMotionListener listener)
Overrides:
addMouseMotionListener in class java.awt.Component

addKeyListener

public void addKeyListener(java.awt.event.KeyListener listener)
Overrides:
addKeyListener in class java.awt.Component

clone

public java.lang.Object clone()
Make a copy of this JGraph so that it can be shown in another window.

Overrides:
clone in class java.lang.Object

initKeys

public void initKeys()

bindKey

public void bindKey(java.awt.event.ActionListener action,
                    int keyCode,
                    int modifiers)
Utility function to bind a keystroke to a Swing Action. Note that GEF Cmds are subclasses of Swing's Actions.


getEditor

public Editor getEditor()
Get the Editor that is being displayed


setDiagram

public void setDiagram(Diagram d)
Set the Diagram that should be displayed by setting the GraphModel and Layer that the Editor is using.


updateDrawingSizeToIncludeAllFigs

protected void updateDrawingSizeToIncludeAllFigs(java.util.Enumeration iter)
Enlarges the JGraphInternalPane dimensions as necessary to insure that all the contained Figs are visible.


setDrawingSize

public void setDrawingSize(int width,
                           int height)

setDrawingSize

public void setDrawingSize(java.awt.Dimension dim)

setGraphModel

public void setGraphModel(GraphModel gm)
Set the GraphModel the Editor is using.


getGraphModel

public GraphModel getGraphModel()
Get the GraphModel the Editor is using.


setGraphNodeRenderer

public void setGraphNodeRenderer(GraphNodeRenderer r)
Get and set the Renderer used to make FigNodes for nodes in the GraphModel.


getGraphNodeRenderer

public GraphNodeRenderer getGraphNodeRenderer()

setGraphEdgeRenderer

public void setGraphEdgeRenderer(GraphEdgeRenderer r)
Get and set the Renderer used to make FigEdges for edges in the GraphModel.


getGraphEdgeRenderer

public GraphEdgeRenderer getGraphEdgeRenderer()

setVisible

public void setVisible(boolean b)
When the JGraph is hidden, hide its internal pane

Overrides:
setVisible in class javax.swing.JComponent

isManagingFocus

public boolean isManagingFocus()
Tell Swing/AWT that JGraph handles tab-order itself.

Overrides:
isManagingFocus in class javax.swing.JComponent

isFocusTraversable

public boolean isFocusTraversable()
Tell Swing/AWT that JGraph can be tabbed into.

Overrides:
isFocusTraversable in class java.awt.Component

addGraphSelectionListener

public void addGraphSelectionListener(GraphSelectionListener listener)
Add listener to the objects to notify whenever the Editor changes its current selection.


removeGraphSelectionListener

public void removeGraphSelectionListener(GraphSelectionListener listener)

addModeChangeListener

public void addModeChangeListener(ModeChangeListener listener)

removeModeChangeListener

public void removeModeChangeListener(ModeChangeListener listener)

select

public void select(Fig f)
Add the given item to this Editor's selections.


selectByOwner

public void selectByOwner(java.lang.Object owner)
Find the Fig that owns the given item and select it.


selectByOwnerOrFig

public void selectByOwnerOrFig(java.lang.Object owner)
Find Fig that owns the given item, or the item if it is a Fig, and select it.


selectByOwnerOrNoChange

public void selectByOwnerOrNoChange(java.lang.Object owner)
Add the Fig that owns the given item to this Editor's selections.


deselect

public void deselect(Fig f)
Remove the given item from this editors selections.


toggleItem

public void toggleItem(Fig f)
Select the given item if it was not already selected, and vis-a-versa.


deselectAll

public void deselectAll()
Deslect everything that is currently selected.


select

public void select(java.util.Vector items)
Select a collection of Figs.


toggleItems

public void toggleItems(java.util.Vector items)
Toggle the selection of a collection of Figs.


selectedFigs

public java.util.Vector selectedFigs()
reply a Vector of all selected Figs. Used in many Cmds.


setDefaultSize

public void setDefaultSize(int width,
                           int height)

setDefaultSize

public void setDefaultSize(java.awt.Dimension dim)

getDefaultSize

public java.awt.Dimension getDefaultSize()

getViewPosition

public java.awt.Point getViewPosition()
Get the position of the editor's scrollpane.


setViewPosition

public void setViewPosition(java.awt.Point p)
Set the position of the editor's scrollpane.


establishAlternateMouseWheelListener

public void establishAlternateMouseWheelListener(java.awt.event.MouseWheelListener listener,
                                                 int mask)
Establishes alternate MouseWheelListener object that's only active when the alt/shift/ctrl keys are held down.

Parameters:
listener - MouseWheelListener that will receive MouseWheelEvents generated by this JGraph.
mask - logical OR of key modifier values as defined by java.awt.event.KeyEvent constants. This has been tested with ALT_MASK, SHIFT_MASK, and CTRL_MASK.

getCurrentDiagramId

protected java.lang.String getCurrentDiagramId()
Returns:
Returns the _currentDiagramId.