Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| JGraph v5.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jgraph
Class JGraph

    java.lang.Object
      |
      +--java.awt.Component
            |
            +--java.awt.Container
                  |
                  +--javax.swing.JComponent
                        |
                        +--org.jgraph.JGraph

All Implemented Interfaces:
  Accessible, CellViewFactory, ImageObserver, MenuContainer, Scrollable, Serializable

public class JGraph
extends JComponent
implements CellViewFactory, Scrollable, Accessible, Serializable

A control that displays a network of related objects using the well-known paradigm of a graph.

A JGraph object doesn't actually contain your data; it simply provides a view of the data. Like any non-trivial Swing component, the graph gets data by querying its data model.

JGraph displays its data by drawing individual elements. Each element displayed by the graph contains exactly one item of data, which is called a cell. A cell may either be a vertex or an edge. Vertices may have neighbours or not, and edges may have source and target vertices or not, depending on whether they are connected.

Creating a Graph

The following code creates a JGraph object:

JGraph graph = new JGraph();
...
JScrollPane graphLayoutCache = new JScrollPane(graph)

The code creates an instance of JGraph and puts it in a scroll pane. JGraphs constructor is called with no arguments in this example, which causes the constructor to create a sample model.

Editing

JGraph supports in-place editing of text and shapes. These features can be disabled using the setEnabled() method, which blocks all features, or individually, using the following methods:

setEditable() controls in-place editing of cells. Moving, cloning, sizing, and bending, connection and disconnection of edges may also be disabled using the respective methods, namemly setMoveable(), setCloneable(), setSizeable(), setBendable(), setConnectable() and setDisconnectable().

The model offers fainer control of connection establishment based on the passed-in edge and port. The individual cells offer yet another level of control in that they may allow/disallow being edited, moved, cloned, resized, and shaped, or connected/disconnected to or from other cells.

Keyboard Bindings

JGraph defines the following set of keyboard bindings:

- Alt-Click forces marquee selection if over a cell.
- Shift- or Ctrl-Select extends or toggles the selection.
- Shift-Drag constrains the offset to one direction.
- Ctrl-Drag clones the selection.
- Doubleclick/F2 starts editing a cell.

You can change the number of clicks that triggers editing using setEditClickCount().

Customization

There are a number of additional methods that customize JGraph. For example, setMinimumMove() defines the minimum amount of pixels before a move operation is initiated. setSnapSize() defines the maximum distance for a cell to be selected. setFloatEnabled() enables/disables port floating.

With setDisconnectOnMove() you can indicate if the selected subgraph should be disconnected from the unselected rest when a move operation is initiated. setDragEnabled() enables/disables the use of Drag And Drop, and setDropEnabled() sets if the graph accepts Drops from external sources.

Customizing a graphs display

JGraph performs some look-and-feel specific painting. You can customize this painting in a limited way. For example, you can modify the grid using setGridColor() and setGridSize(), and you can change the handle colors using setHandleColor() and setLockedHandleColor().

If you want finer control over the rendering, you can subclass one of the default renderers, and extend its paint()-method. A renderer is a Component-extension that paints a cell based on its attributes. Thus, neither the JGraph nor its look-and-feel-specific implementation actually contain the code that paints the cell. Instead, the graph uses the cell renderers painting code.

Selection

Apart from the single-cell and marquee-selection, JGraphs selection model also allows to "step-into" groups, and select children. This feature can be disabled using the setAllowsChildSelection() method of the selection model instance.

If you are interested in knowing when the selection changes implement the `GraphSelectionListener` interface and add the instance using the method `addGraphSelectionListener`. `valueChanged` will be invoked when the selection changes, that is if the user clicks twice on the same vertex `valueChanged` will only be invoked once.

Change Notification

If you are interested in handling modifications, implement the `GraphEventHandler` interface and add the instance using the method `addGraphEventHandler`.

For detection of double-clicks or when a user clicks on a cell, regardless of whether or not it was selected, I recommend you implement a MouseListener and use `getFirstCellForLocation`.

Undo Support

To enable Undo-Support, a `GraphUndoManager` must be added using `addGraphSelectionListener`. The GraphUndoManager is an extension of Swing's `GraphUndoManager` that maintains a command history in the context of multiple views. In this setup, a cell may have a set of attributes in each view attached to the model.

For example, consider a position that is stored separately in each view. If a node is inserted, the change will be visible in all attached views, resulting in a new node that pops-up at the initial position. If the node is subsequently moved, say, in view1, this does not constitute a change in view2. If view2 does an "undo", the move and the insertion must be undone, whereas an "undo" in view1 will only undo the previous move operation.

Like all `JComponent` classes, you can use `InputMap`and `ActionMap`to associate an `Action`object with a `KeyStroke`and execute the action under specified conditions.

See Also:
  Serialized Form

Nested Class Summary
`static class` | `JGraph.EmptySelectionModel` `EmptySelectionModel` is a `GraphSelectionModel` that does not allow anything to be selected.
`protected class` | `JGraph.GraphSelectionRedirector` Handles creating a new `GraphSelectionEvent` with the `JGraph` as the source and passing it off to all the listeners.

Field Summary
`protected boolean` | `antiAliased` True if the graph is anti-aliased.
`static String` | `ANTIALIASED_PROPERTY` Bound property name for `antiAliased`.
`protected boolean` | `bendable` True if the graph allows points to be midified/added/removed.
`protected boolean` | `cloneable` True if the graph allows "ctrl-drag" operations.
`protected boolean` | `connectable` True if the graph allows new connections to be established.
`static int` | `CROSS_GRID_MODE`
`protected boolean` | `disconnectable` True if the graph allows existing connections to be removed.
`protected boolean` | `disconnectOnMove` True if selected edges are disconnected from unselected vertices on move.
`static int` | `DOT_GRID_MODE`
`protected boolean` | `dragEnabled` True if Drag-and-Drop should be used for move operations.
`protected boolean` | `dropEnabled` True if the graph accepts transfers from other components (graphs).
`protected boolean` | `editable` True if the graph allows editing the value of a cell.
`static String` | `EDITABLE_PROPERTY` Bound property name for `editable`.
`protected int` | `editClickCount` Number of clicks for editing to start.
`protected boolean` | `enabled` True if the graph allows interactions.
`static String` | `GRAPH_LAYOUT_CACHE_PROPERTY` Bound property name for `graphModel`.
`static String` | `GRAPH_MODEL_PROPERTY` Bound property name for `graphModel`.
`protected GraphLayoutCache` | `graphLayoutCache` The view that defines the display properties of the model.
`protected GraphModel` | `graphModel` The model that defines the graph displayed by this object.
`static String` | `GRID_SIZE_PROPERTY` Bound property name for `gridSize`.
`static String` | `GRID_VISIBLE_PROPERTY` Bound property name for `gridVisible`.
`protected Color` | `gridColor` The color of the grid.
`protected boolean` | `gridEnabled` True if the snap method should be active (snap to grid).
`protected int` | `gridMode` The style of the grid.
`protected double` | `gridSize` The size of the grid in points.
`protected boolean` | `gridVisible` True if the grid is visible.
`protected Color` | `handleColor` Color of the handles and locked handles.
`protected int` | `handleSize` Size of a handle.
`protected Color` | `highlightColor` Highlight Color.
`static String` | `INVOKES_STOP_CELL_EDITING_PROPERTY` Bound property name for `messagesStopCellEditing`.
`protected boolean` | `invokesStopCellEditing` If true, when editing is to be stopped by way of selection changing, data in graph changing or other means `stopCellEditing` is invoked, and changes are saved.
`static int` | `LINE_GRID_MODE`
`protected Color` | `lockedHandleColor` Color of the handles and locked handles.
`protected BasicMarqueeHandler` | `marquee` Handler for marquee selection.
`static String` | `MARQUEE_HANDLER_PROPERTY` Bound property name for `graphModel`.
`protected Color` | `marqueeColor` Color of the marquee.
`protected int` | `minimumMove` Minimum amount of pixels to start a move transaction.
`protected boolean` | `moveable` True if the graph allows move operations.
`protected boolean` | `moveBelowZero` True if the graph allows to move cells below cero.
`static String` | `PORTS_VISIBLE_PROPERTY` Bound property name for `gridVisible`.
`protected boolean` | `portsVisible` True if the ports are visible.
`protected double` | `scale` Scale of the graph.
`static String` | `SCALE_PROPERTY` Bound property name for `scale`.
`static String` | `SELECTION_MODEL_PROPERTY` Bound property name for `selectionModel`.
`protected GraphSelectionModel` | `selectionModel` Models the set of selected objects in this graph.
`protected JGraph.GraphSelectionRedirector` | `selectionRedirector` Creates a new event and passes it off the `selectionListeners`.
`protected boolean` | `selectNewCells` True if inserted cells should be selected.
`protected boolean` | `sizeable` True if the graph allows cells to be resized.
`protected int` | `tolerance` Maximum distance between a cell and the mousepointer.
`static String` | `VERSION`

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()` Returns a `JGraph` with a sample model.
`JGraph(GraphModel model)` Returns an instance of `JGraph` which displays the the specified data model.
`JGraph(GraphModel model, BasicMarqueeHandler mh)` Returns an instance of `JGraph` which displays the specified data model using the specified view.
`JGraph(GraphModel model, GraphLayoutCache view)` Returns an instance of `JGraph` which displays the specified data model using the specified view.
`JGraph(GraphModel model, GraphLayoutCache view, BasicMarqueeHandler mh)` Returns an instance of `JGraph` which displays the specified data model using the specified view.

Method Summary
`void` | `addGraphSelectionListener(GraphSelectionListener tsl)` Adds a listener for `GraphSelection` events.
`static void` | `addSampleData(GraphModel model)` Creates and returns a sample `GraphModel`.
`void` | `addSelectionCell(Object cell)` Adds the cell identified by the specified `Object` to the current selection.
`void` | `addSelectionCells(Object[] cells)` Adds each cell in the array of cells to the current selection.
`void` | `cancelEditing()` Cancels the current editing session.
`void` | `clearSelection()` Clears the selection.
`Map` | `cloneCells(Object[] cells)` Returns a map of (cell, clone)-pairs for all `cells` and their children.
`String` | `convertValueToString(Object value)` Converts the specified value to string.
`static Map` | `createBounds(AttributeMap map, int x, int y, Color c)` Returns an attributeMap for the specified position and color.
`protected static GraphLayoutCache` | `createDefaultGraphView(JGraph graph)` Creates and returns a default `GraphLayoutCache`.
`protected EdgeView` | `createEdgeView(JGraph graph, CellMapper mapper, Edge cell)` Deprecated. replaced by `#createEdgeView(Object,CellMapper)`since JGraph no longer exposes dependecies on GraphCell subclasses (Port, Edge)
`protected EdgeView` | `createEdgeView(JGraph graph, CellMapper mapper, Object cell)` Constructs an EdgeView view for the specified object.
`protected PortView` | `createPortView(JGraph graph, CellMapper mapper, Object cell)` Constructs a PortView view for the specified object.
`protected PortView` | `createPortView(JGraph graph, CellMapper mapper, Port cell)` Deprecated. replaced by `#createPortView(Object,CellMapper)`since JGraph no longer exposes dependecies on GraphCell subclasses (Port, Edge)
`protected VertexView` | `createVertexView(JGraph graph, CellMapper mapper, Object cell)` Constructs a VertexView view for the specified object.
`CellView` | `createView(JGraph graph, CellMapper mapper, Object cell)` Constructs a view for the specified cell and associates it with the specified object using the specified CellMapper.
`protected void` | `fireValueChanged(GraphSelectionEvent e)` Notifies all listeners that have registered interest for notification on this event type.
`Point2D` | `fromScreen(Point2D p)` Downscale the given point in place, ie.
`Rectangle2D` | `fromScreen(Rectangle2D rect)` Downscale the given rectangle in place, ie.
`Rectangle2D` | `getCellBounds(Object cell)` Returns the bounding rectangle of the specified cell.
`Rectangle2D` | `getCellBounds(Object[] cells)` Returns the bounding rectangle of the specified cells.
`Object[]` | `getDescendantList(Object[] cells)` Returns all `cells` including all descendants.
`Object[]` | `getDescendants(Object[] cells)` Returns all `cells` including all descendants.
`int` | `getEditClickCount()` Returns the number of clicks for editing to start.
`Object` | `getEditingCell()` Returns the cell that is currently being edited.
`Object` | `getFirstCellForLocation(double x, double y)` Returns the topmost cell at the specified location.
`GraphLayoutCache` | `getGraphLayoutCache()` Returns the `GraphLayoutCache` that is providing the view-data.
`Color` | `getGridColor()` Returns the current grid color.
`int` | `getGridMode()` Returns the current grid view mode.
`double` | `getGridSize()` Returns the size of the grid in pixels.
`Color` | `getHandleColor()` Returns the current handle color.
`int` | `getHandleSize()` Returns the size of the handles.
`Color` | `getHighlightColor()` Returns the current highlight color.
`boolean` | `getInvokesStopCellEditing()` Returns the indicator that tells what happens when editing is interrupted.
`Color` | `getLockedHandleColor()` Returns the current second handle color.
`Color` | `getMarqueeColor()` Returns the current marquee color.
`BasicMarqueeHandler` | `getMarqueeHandler()` Returns the `MarqueeHandler` that will handle marquee selection.
`int` | `getMinimumMove()` Returns the miminum amount of pixels for a move operation.
`GraphModel` | `getModel()` Returns the `GraphModel` that is providing the data.
`Object` | `getNextCellForLocation(Object current, double x, double y)` Returns the cell at the specified location that is "behind" the `current` cell.
`CellView` | `getNextViewAt(CellView[] cells, CellView c, double x, double y)` Returns the next view at the specified location wrt.
`CellView` | `getNextViewAt(CellView current, double x, double y)` Returns the next view at the specified location wrt.
`Object` | `getPortForLocation(double x, double y)` Convenience method to return the port at the specified location.
`PortView` | `getPortViewAt(double x, double y)` Returns the portview at the specified location.
`Dimension` | `getPreferredScrollableViewportSize()` Returns the preferred display size of a `JGraph`.
`Object[]` | `getRoots()` Returns all cells that the model contains.
`Object[]` | `getRoots(Rectangle clip)` Returns all cells that intersect the given rectangle.
`double` | `getScale()` Returns the current scale.
`int` | `getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)` Returns the amount for a block increment, which is the height or width of `visibleRect`, based on `orientation`.
`boolean` | `getScrollableTracksViewportHeight()` Returns false to indicate that the height of the viewport does not determine the height of the graph, unless the preferred height of the graph is smaller than the viewports height.
`boolean` | `getScrollableTracksViewportWidth()` Returns false to indicate that the width of the viewport does not determine the width of the graph, unless the preferred width of the graph is smaller than the viewports width.
`int` | `getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)` Returns the amount to increment when scrolling.
`Object` | `getSelectionCell()` Returns the first selected cell.
`Object[]` | `getSelectionCells()` Returns all selected cells.
`int` | `getSelectionCount()` Returns the number of cells selected.
`GraphSelectionModel` | `getSelectionModel()` Returns the model for selections.
`int` | `getTolerance()` Returns the maximum distance between the mousepointer and a cell to be selected.
`String` | `getToolTipText(MouseEvent event)` Overrides `JComponent`'s`getToolTipText` method in order to allow the graph to create a tooltip for the topmost cell under the mousepointer.
`GraphUI` | `getUI()` Returns the L&F object that renders this component.
`String` | `getUIClassID()` Returns the name of the L&F class that renders this component.
`void` | `graphDidChange()` Messaged when the graph has changed enough that we need to resize the bounds, but not enough that we need to remove the cells (e.g cells were inserted into the graph).
`boolean` | `isAntiAliased()` Returns true if the graph will be anti aliased.
`boolean` | `isBendable()` Returns true if the graph allows adding/removing/modifying points.
`boolean` | `isCellEditable(Object cell)` Returns `isEditable`.
`boolean` | `isCellSelected(Object cell)` Returns true if the cell is currently selected.
`boolean` | `isCloneable()` Returns true if cells are cloned on CTRL-Drag operations.
`boolean` | `isConnectable()` Returns true if the graph allows new connections to be established.
`boolean` | `isDisconnectable()` Returns true if the graph allows existing connections to be removed.
`boolean` | `isDisconnectOnMove()` Returns true if selected edges should be disconnected from unselected vertices when they are moved.
`boolean` | `isDragEnabled()` Returns true if the graph uses Drag-and-Drop to move cells.
`boolean` | `isDropEnabled()` Returns true if the graph accepts drops/pastes from external sources.
`boolean` | `isEditable()` Returns true if the graph is editable, ie.
`boolean` | `isEditing()` Returns true if the graph is being edited.
`boolean` | `isGridEnabled()` Returns true if the grid is active.
`boolean` | `isGridVisible()` Returns true if the grid will be visible.
`boolean` | `isMoveable()`
`boolean` | `isMoveBelowZero()` Returns true if the graph allows to move cells below zero.
`boolean` | `isPortsVisible()` Returns true if the ports will be visible.
`boolean` | `isSelectionEmpty()` Returns true if the selection is currently empty.
`boolean` | `isSelectNewCells()` Returns true if selected edges should be disconnected from unselected vertices when they are moved.
`boolean` | `isSizeable()` Returns true if the graph allows cells to be resized.
`static void` | `main(String[] args)`
`protected String` | `paramString()` Returns a string representation of this `JGraph`.
`void` | `removeGraphSelectionListener(GraphSelectionListener tsl)` Removes a `GraphSelection` listener.
`void` | `removeSelectionCell(Object cell)` Removes the cell identified by the specified Object from the current selection.
`void` | `scrollCellToVisible(Object cell)` Scrolls to the specified cell.
`void` | `scrollPointToVisible(Point2D p)` Makes sure the specified point is visible.
`void` | `setAntiAliased(boolean newValue)` Sets antialiasing on or off based on the boolean value.
`void` | `setBendable(boolean flag)` Sets if the graph allows adding/removing/modifying points.
`void` | `setCloneable(boolean flag)` Sets if cells are cloned on CTRL-Drag operations.
`void` | `setConnectable(boolean flag)` Setse if the graph allows new connections to be established.
`void` | `setDisconnectable(boolean flag)` Sets if the graph allows existing connections to be removed.
`void` | `setDisconnectOnMove(boolean flag)` Sets if selected edges should be disconnected from unselected vertices when they are moved.
`void` | `setDragEnabled(boolean flag)` Sets if the graph uses Drag-and-Drop to move cells.
`void` | `setDropEnabled(boolean flag)` Sets if the graph accepts drops/pastes from external sources.
`void` | `setEditable(boolean flag)` Determines whether the graph is editable.
`void` | `setEditClickCount(int count)` Sets the number of clicks for editing to start.
`void` | `setGraphLayoutCache(GraphLayoutCache newLayoutCache)` Sets the `GraphLayoutCache` that will provide the view-data.
`void` | `setGridColor(Color newColor)` Sets the current grid color.
`void` | `setGridEnabled(boolean flag)` If set to true, the grid will be active.
`void` | `setGridMode(int mode)` Sets the current grid view mode.
`void` | `setGridSize(double newSize)` Sets the size of the grid.
`void` | `setGridVisible(boolean flag)` If set to true, the grid will be visible.
`void` | `setHandleColor(Color newColor)` Sets the current handle color.
`void` | `setHandleSize(int size)` Sets the size of the handles.
`void` | `setHighlightColor(Color newColor)` Sets the current selection highlight color.
`void` | `setInvokesStopCellEditing(boolean newValue)` Determines what happens when editing is interrupted by selecting another cell in the graph, a change in the graph's data, or by some other means.
`void` | `setLockedHandleColor(Color newColor)` Sets the current second handle color.
`void` | `setMarqueeColor(Color newColor)` Sets the current marquee color.
`void` | `setMarqueeHandler(BasicMarqueeHandler newMarquee)` Sets the `MarqueeHandler` that will handle marquee selection.
`void` | `setMinimumMove(int pixels)` Sets the miminum amount of pixels for a move operation.
`void` | `setModel(GraphModel newModel)` Sets the `GraphModel` that will provide the data.
`void` | `setMoveable(boolean flag)` Sets if the graph allows movement of cells.
`void` | `setMoveBelowZero(boolean moveBelowZero)` Sets if the graph allows to move cells below zero.
`void` | `setPortsVisible(boolean flag)` If set to true, the ports will be visible.
`void` | `setScale(double newValue)` Sets the current scale.
`void` | `setSelectionCell(Object cell)` Selects the specified cell.
`void` | `setSelectionCells(Object[] cells)` Selects the specified cells.
`void` | `setSelectionModel(GraphSelectionModel selectionModel)` Sets the graph's selection model.
`void` | `setSelectNewCells(boolean flag)` Sets if selected edges should be disconnected from unselected vertices when they are moved.
`void` | `setSizeable(boolean flag)` Sets if the graph allows cells to be resized.
`void` | `setTolerance(int size)` Sets the maximum distance between the mousepointer and a cell to be selected.
`void` | `setUI(GraphUI ui)` Sets the L&F object that renders this component.
`Dimension2D` | `snap(Dimension2D d)` Returns the given point applied to the grid.
`Point2D` | `snap(Point2D p)` Returns the given point applied to the grid.
`void` | `startEditingAtCell(Object cell)` Selects the specified cell and initiates editing.
`boolean` | `stopEditing()` Ends the current editing session.
`Point2D` | `toScreen(Point2D p)` Upscale the given point in place, ie.
`Rectangle2D` | `toScreen(Rectangle2D rect)` Upscale the given rectangle in place, ie.
`void` | `updateAutoSize(JGraph graph, CellView view)` Computes and updates the size for `view`.
`void` | `updateUI()` Notification from the `UIManager` that the L&F has changed.

Methods inherited from class javax.swing.JComponent
`addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update`

Methods inherited from class java.awt.Container
`add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree`

Methods inherited from class java.awt.Component
`action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface javax.accessibility.Accessible
`getAccessibleContext`

Field Detail

### VERSION

    public static final String VERSION

See Also:
  Constant Field Values

### DOT_GRID_MODE

    public static final int DOT_GRID_MODE

See Also:
  Constant Field Values

### CROSS_GRID_MODE

    public static final int CROSS_GRID_MODE

See Also:
  Constant Field Values

### LINE_GRID_MODE

    public static final int LINE_GRID_MODE

See Also:
  Constant Field Values

### selectionRedirector

    protected transient JGraph.GraphSelectionRedirector selectionRedirector

  Creates a new event and passes it off the `selectionListeners`.

### graphModel

    protected transient GraphModel graphModel

  The model that defines the graph displayed by this object. Bound property.

### graphLayoutCache

    protected transient GraphLayoutCache graphLayoutCache

  The view that defines the display properties of the model. Bound property.

### marquee

    protected transient BasicMarqueeHandler marquee

  Handler for marquee selection.

### selectionModel

    protected transient GraphSelectionModel selectionModel

  Models the set of selected objects in this graph. Bound property.

### scale

    protected double scale

  Scale of the graph. Default is 1. Bound property.

### antiAliased

    protected boolean antiAliased

  True if the graph is anti-aliased. Default is false. Bound property.

### editable

    protected boolean editable

  True if the graph allows editing the value of a cell. Bound property.

### gridVisible

    protected boolean gridVisible

  True if the grid is visible. Bound property.

### gridSize

    protected double gridSize

  The size of the grid in points. Default is 10. Bound property.

### gridMode

    protected int gridMode

  The style of the grid. Use one of the _GRID_MODE constants.

### portsVisible

    protected boolean portsVisible

  True if the ports are visible. Bound property.

### moveBelowZero

    protected boolean moveBelowZero

  True if the graph allows to move cells below cero.

### highlightColor

    protected Color highlightColor

  Highlight Color. Changes when the Look-and-Feel changes.

### handleColor

    protected Color handleColor

  Color of the handles and locked handles. Changes when the Look-and-Feel changes.

### lockedHandleColor

    protected Color lockedHandleColor

  Color of the handles and locked handles. Changes when the Look-and-Feel changes.

### marqueeColor

    protected Color marqueeColor

  Color of the marquee. Changes when the Look-and-Feel changes.

### gridColor

    protected Color gridColor

  The color of the grid. Changes when the Look-and-Feel changes.

### dragEnabled

    protected boolean dragEnabled

  True if Drag-and-Drop should be used for move operations. Default is false due to a JDK bug.

### dropEnabled

    protected boolean dropEnabled

  True if the graph accepts transfers from other components (graphs). This also affects the clipboard. Default is true.

### editClickCount

    protected int editClickCount

  Number of clicks for editing to start. Default is 2 clicks.

### enabled

    protected boolean enabled

  True if the graph allows interactions. Default is true.

### gridEnabled

    protected boolean gridEnabled

  True if the snap method should be active (snap to grid).

### handleSize

    protected int handleSize

  Size of a handle. Default is 3 pixels.

### tolerance

    protected int tolerance

  Maximum distance between a cell and the mousepointer. Default is 4.

### minimumMove

    protected int minimumMove

  Minimum amount of pixels to start a move transaction. Default is 5.

### selectNewCells

    protected boolean selectNewCells

  True if inserted cells should be selected. Default is false.

### disconnectOnMove

    protected boolean disconnectOnMove

  True if selected edges are disconnected from unselected vertices on move. Default is true.

### moveable

    protected boolean moveable

  True if the graph allows move operations. Default is true.

### cloneable

    protected boolean cloneable

  True if the graph allows "ctrl-drag" operations. Default is false.

### sizeable

    protected boolean sizeable

  True if the graph allows cells to be resized. Default is true.

### bendable

    protected boolean bendable

  True if the graph allows points to be midified/added/removed. Default is true.

### connectable

    protected boolean connectable

  True if the graph allows new connections to be established. Default is true.

### disconnectable

    protected boolean disconnectable

  True if the graph allows existing connections to be removed. Default is true.

### invokesStopCellEditing

    protected boolean invokesStopCellEditing

  If true, when editing is to be stopped by way of selection changing, data in graph changing or other means `stopCellEditing` is invoked, and changes are saved. If false, `cancelCellEditing` is invoked, and changes are discarded. Default is false.

### GRAPH_MODEL_PROPERTY

    public static final String GRAPH_MODEL_PROPERTY

  Bound property name for `graphModel`.

  See Also:
    Constant Field Values

### GRAPH_LAYOUT_CACHE_PROPERTY

    public static final String GRAPH_LAYOUT_CACHE_PROPERTY

  Bound property name for `graphModel`.

  See Also:
    Constant Field Values

### MARQUEE_HANDLER_PROPERTY

    public static final String MARQUEE_HANDLER_PROPERTY

  Bound property name for `graphModel`.

  See Also:
    Constant Field Values

### EDITABLE_PROPERTY

    public static final String EDITABLE_PROPERTY

  Bound property name for `editable`.

  See Also:
    Constant Field Values

### SCALE_PROPERTY

    public static final String SCALE_PROPERTY

  Bound property name for `scale`.

  See Also:
    Constant Field Values

### ANTIALIASED_PROPERTY

    public static final String ANTIALIASED_PROPERTY

  Bound property name for `antiAliased`.

  See Also:
    Constant Field Values

### GRID_SIZE_PROPERTY

    public static final String GRID_SIZE_PROPERTY

  Bound property name for `gridSize`.

  See Also:
    Constant Field Values

### GRID_VISIBLE_PROPERTY

    public static final String GRID_VISIBLE_PROPERTY

  Bound property name for `gridVisible`.

  See Also:
    Constant Field Values

### PORTS_VISIBLE_PROPERTY

    public static final String PORTS_VISIBLE_PROPERTY

  Bound property name for `gridVisible`.

  See Also:
    Constant Field Values

### SELECTION_MODEL_PROPERTY

    public static final String SELECTION_MODEL_PROPERTY

  Bound property name for `selectionModel`.

  See Also:
    Constant Field Values

### INVOKES_STOP_CELL_EDITING_PROPERTY

    public static final String INVOKES_STOP_CELL_EDITING_PROPERTY

  Bound property name for `messagesStopCellEditing`.

  See Also:
    Constant Field Values

Constructor Detail

### JGraph

    public JGraph()

  Returns a `JGraph` with a sample model.

### JGraph

    public JGraph(GraphModel model)

  Returns an instance of `JGraph` which displays the the specified data model.

Parameters:
  `model` - the `GraphModel` to use as the data model

### JGraph

    public JGraph(GraphModel model,
                  GraphLayoutCache view)

  Returns an instance of `JGraph` which displays the specified data model using the specified view.

Parameters:
  `model` - the `GraphModel` to use as the data model
  `view` - the `GraphLayoutCache` to use as the view

### JGraph

    public JGraph(GraphModel model,
                  BasicMarqueeHandler mh)

  Returns an instance of `JGraph` which displays the specified data model using the specified view.

Parameters:
  `model` - the `GraphModel` to use as the data model

### JGraph

    public JGraph(GraphModel model,
                  GraphLayoutCache view,
                  BasicMarqueeHandler mh)

  Returns an instance of `JGraph` which displays the specified data model using the specified view.

Parameters:
  `model` - the `GraphModel` to use as the data model
  `view` - the `GraphLayoutCache` to use as the view

Method Detail

### createDefaultGraphView

    protected static GraphLayoutCache createDefaultGraphView(JGraph graph)

  Creates and returns a default `GraphLayoutCache`.

  Returns:
    the default `GraphLayoutCache`

### addSampleData

    public static void addSampleData(GraphModel model)

  Creates and returns a sample `GraphModel`. Used primarily for beanbuilders to show something interesting.

  Returns:
    the default `GraphModel`

### createBounds

    public static Map createBounds(AttributeMap map,
                                   int x,
                                   int y,
                                   Color c)

  Returns an attributeMap for the specified position and color.

### getUI

    public GraphUI getUI()

  Returns the L&F object that renders this component.

  Returns:
    the GraphUI object that renders this component

### setUI

    public void setUI(GraphUI ui)

  Sets the L&F object that renders this component.

  Parameters:
    `ui` - the GraphUI L&F object
  See Also:
    `UIDefaults.getUI(JComponent)`

### updateUI

    public void updateUI()

  Notification from the `UIManager` that the L&F has changed. Replaces the current UI object with the latest version from the `UIManager`. Subclassers can override this to support different GraphUIs.

  Overrides:
    `updateUI` in class `JComponent`
  See Also:
    `JComponent.updateUI()`

### getUIClassID

    public String getUIClassID()

  Returns the name of the L&F class that renders this component.

  Overrides:
    `getUIClassID` in class `JComponent`
  Returns:
    the string "GraphUI"
  See Also:
    `JComponent.getUIClassID()`

### getRoots

    public Object[] getRoots()

  Returns all cells that the model contains.

### getRoots

    public Object[] getRoots(Rectangle clip)

  Returns all cells that intersect the given rectangle.

### getDescendants

    public Object[] getDescendants(Object[] cells)

  Returns all `cells` including all descendants. DEPRECATED: Use getDescendantList instead.

### getDescendantList

    public Object[] getDescendantList(Object[] cells)

  Returns all `cells` including all descendants.

### cloneCells

    public Map cloneCells(Object[] cells)

  Returns a map of (cell, clone)-pairs for all `cells` and their children. Special care is taken to replace the anchor references between ports. (Iterative implementation.)

### getFirstCellForLocation

    public Object getFirstCellForLocation(double x,
                                          double y)

  Returns the topmost cell at the specified location.

  Parameters:
    `x` - an integer giving the number of pixels horizontally from the left edge of the display area, minus any left margin
    `y` - an integer giving the number of pixels vertically from the top of the display area, minus any top margin
  Returns:
    the topmost cell at the specified location

### getNextCellForLocation

    public Object getNextCellForLocation(Object current,
                                         double x,
                                         double y)

  Returns the cell at the specified location that is "behind" the `current` cell. Returns the topmost cell if there are no more cells behind `current`.

### getCellBounds

    public Rectangle2D getCellBounds(Object cell)

  Returns the bounding rectangle of the specified cell.

### getCellBounds

    public Rectangle2D getCellBounds(Object[] cells)

  Returns the bounding rectangle of the specified cells.

### getNextViewAt

    public CellView getNextViewAt(CellView current,
                                  double x,
                                  double y)

  Returns the next view at the specified location wrt. `current`. This is used to iterate overlapping cells, and cells that are grouped. The current selection affects this method.

### getNextViewAt

    public CellView getNextViewAt(CellView[] cells,
                                  CellView c,
                                  double x,
                                  double y)

  Returns the next view at the specified location wrt. `c` in the specified array of views. The views must be in order, as returned, for example, by GraphLayoutCache.order(Object[]).

### getPortForLocation

    public Object getPortForLocation(double x,
                                     double y)

  Convenience method to return the port at the specified location.

### getPortViewAt

    public PortView getPortViewAt(double x,
                                  double y)

  Returns the portview at the specified location.

### convertValueToString

    public String convertValueToString(Object value)

  Converts the specified value to string. If the value is an instance of CellView or the current GraphLayoutCache returns a mapping for value, then then value attribute of that CellView is used. (The value is retrieved using getAllAttributes.) If the value is an instance of DefaultMutableTreeNode (e.g. DefaultGraphCell), then the userobject is returned as a String.

### snap

    public Point2D snap(Point2D p)

  Returns the given point applied to the grid.

  Parameters:
    `p` - a point in screen coordinates.
  Returns:
    the same point applied to the grid.

### snap

    public Dimension2D snap(Dimension2D d)

  Returns the given point applied to the grid.

  Returns:
    the same point applied to the grid.

### toScreen

    public Point2D toScreen(Point2D p)

  Upscale the given point in place, ie. using the given instance.

  Parameters:
    `p` - the point to be upscaled
  Returns:
    the upscaled point instance

### fromScreen

    public Point2D fromScreen(Point2D p)

  Downscale the given point in place, ie. using the given instance.

  Parameters:
    `p` - the point to be downscaled
  Returns:
    the downscaled point instance

### toScreen

    public Rectangle2D toScreen(Rectangle2D rect)

  Upscale the given rectangle in place, ie. using the given instance.

  Parameters:
    `rect` - the rectangle to be upscaled
  Returns:
    the upscaled rectangle instance

### fromScreen

    public Rectangle2D fromScreen(Rectangle2D rect)

  Downscale the given rectangle in place, ie. using the given instance.

  Parameters:
    `rect` - the rectangle to be downscaled
  Returns:
    the down-scaled rectangle instance

### createView

    public CellView createView(JGraph graph,
                               CellMapper mapper,
                               Object cell)

  Constructs a view for the specified cell and associates it with the specified object using the specified CellMapper. This calls refresh on the created CellView to create all dependent views.

  Note: The mapping needs to be available before the views of child cells and ports are created.

  Specified by:
    `createView` in interface `CellViewFactory`
  Parameters:
    `cell` - reference to the object in the model

### updateAutoSize

    public void updateAutoSize(JGraph graph,
                               CellView view)

  Computes and updates the size for `view`.

  Specified by:
    `updateAutoSize` in interface `CellViewFactory`

### createEdgeView

    protected EdgeView createEdgeView(JGraph graph,
                                      CellMapper mapper,
                                      Object cell)

  Constructs an EdgeView view for the specified object.

### createPortView

    protected PortView createPortView(JGraph graph,
                                      CellMapper mapper,
                                      Object cell)

  Constructs a PortView view for the specified object.

### createEdgeView

    protected EdgeView createEdgeView(JGraph graph,
                                      CellMapper mapper,
                                      Edge cell)

  Deprecated. replaced by `#createEdgeView(Object,CellMapper)`since JGraph no longer exposes dependecies on GraphCell subclasses (Port, Edge)

  Constructs an EdgeView view for the specified object.

### createPortView

    protected PortView createPortView(JGraph graph,
                                      CellMapper mapper,
                                      Port cell)

  Deprecated. replaced by `#createPortView(Object,CellMapper)`since JGraph no longer exposes dependecies on GraphCell subclasses (Port, Edge)

  Constructs a PortView view for the specified object.

### createVertexView

    protected VertexView createVertexView(JGraph graph,
                                          CellMapper mapper,
                                          Object cell)

  Constructs a VertexView view for the specified object.

### getEditClickCount

    public int getEditClickCount()

  Returns the number of clicks for editing to start.

### setEditClickCount

    public void setEditClickCount(int count)

  Sets the number of clicks for editing to start.

### isDropEnabled

    public boolean isDropEnabled()

  Returns true if the graph accepts drops/pastes from external sources.

### setDropEnabled

    public void setDropEnabled(boolean flag)

  Sets if the graph accepts drops/pastes from external sources.

### isDragEnabled

    public boolean isDragEnabled()

  Returns true if the graph uses Drag-and-Drop to move cells.

### setDragEnabled

    public void setDragEnabled(boolean flag)

  Sets if the graph uses Drag-and-Drop to move cells.

### isMoveable

    public boolean isMoveable()

### setMoveable

    public void setMoveable(boolean flag)

  Sets if the graph allows movement of cells.

### isBendable

    public boolean isBendable()

  Returns true if the graph allows adding/removing/modifying points.

### setBendable

    public void setBendable(boolean flag)

  Sets if the graph allows adding/removing/modifying points.

### isConnectable

    public boolean isConnectable()

  Returns true if the graph allows new connections to be established.

### setConnectable

    public void setConnectable(boolean flag)

  Setse if the graph allows new connections to be established.

### isDisconnectable

    public boolean isDisconnectable()

  Returns true if the graph allows existing connections to be removed.

### setDisconnectable

    public void setDisconnectable(boolean flag)

  Sets if the graph allows existing connections to be removed.

### isCloneable

    public boolean isCloneable()

  Returns true if cells are cloned on CTRL-Drag operations.

### setCloneable

    public void setCloneable(boolean flag)

  Sets if cells are cloned on CTRL-Drag operations.

### isSizeable

    public boolean isSizeable()

  Returns true if the graph allows cells to be resized.

### setSizeable

    public void setSizeable(boolean flag)

  Sets if the graph allows cells to be resized.

### isDisconnectOnMove

    public boolean isDisconnectOnMove()

  Returns true if selected edges should be disconnected from unselected vertices when they are moved.

### setSelectNewCells

    public void setSelectNewCells(boolean flag)

  Sets if selected edges should be disconnected from unselected vertices when they are moved.

### isSelectNewCells

    public boolean isSelectNewCells()

  Returns true if selected edges should be disconnected from unselected vertices when they are moved.

### setDisconnectOnMove

    public void setDisconnectOnMove(boolean flag)

  Sets if selected edges should be disconnected from unselected vertices when they are moved.

### isGridEnabled

    public boolean isGridEnabled()

  Returns true if the grid is active.

  See Also:
    `snap(java.awt.geom.Point2D)`

### setGridEnabled

    public void setGridEnabled(boolean flag)

  If set to true, the grid will be active.

  See Also:
    `snap(java.awt.geom.Point2D)`

### isMoveBelowZero

    public boolean isMoveBelowZero()

  Returns true if the graph allows to move cells below zero.

### setMoveBelowZero

    public void setMoveBelowZero(boolean moveBelowZero)

  Sets if the graph allows to move cells below zero.

### getTolerance

    public int getTolerance()

  Returns the maximum distance between the mousepointer and a cell to be selected.

### setTolerance

    public void setTolerance(int size)

  Sets the maximum distance between the mousepointer and a cell to be selected.

### getHandleSize

    public int getHandleSize()

  Returns the size of the handles.

### setHandleSize

    public void setHandleSize(int size)

  Sets the size of the handles.

### getMinimumMove

    public int getMinimumMove()

  Returns the miminum amount of pixels for a move operation.

### setMinimumMove

    public void setMinimumMove(int pixels)

  Sets the miminum amount of pixels for a move operation.

### getGridColor

    public Color getGridColor()

  Returns the current grid color.

### setGridColor

    public void setGridColor(Color newColor)

  Sets the current grid color.

### getHandleColor

    public Color getHandleColor()

  Returns the current handle color.

### setHandleColor

    public void setHandleColor(Color newColor)

  Sets the current handle color.

### getLockedHandleColor

    public Color getLockedHandleColor()

  Returns the current second handle color.

### setLockedHandleColor

    public void setLockedHandleColor(Color newColor)

  Sets the current second handle color.

### getMarqueeColor

    public Color getMarqueeColor()

  Returns the current marquee color.

### setMarqueeColor

    public void setMarqueeColor(Color newColor)

  Sets the current marquee color.

### getHighlightColor

    public Color getHighlightColor()

  Returns the current highlight color.

### setHighlightColor

    public void setHighlightColor(Color newColor)

  Sets the current selection highlight color.

### getScale

    public double getScale()

  Returns the current scale.

  Returns:
    the current scale as a double

### setScale

    public void setScale(double newValue)

  Sets the current scale.

  Fires a property change for the SCALE_PROPERTY.

  Parameters:
    `newValue` - the new scale

### getGridSize

    public double getGridSize()

  Returns the size of the grid in pixels.

  Returns:
    the size of the grid as an int

### getGridMode

    public int getGridMode()

  Returns the current grid view mode.

### setGridSize

    public void setGridSize(double newSize)

  Sets the size of the grid.

  Fires a property change for the GRID_SIZE_PROPERTY.

  Parameters:
    `newSize` - the new size of the grid in pixels

### setGridMode

    public void setGridMode(int mode)

  Sets the current grid view mode.

  Parameters:
    `mode` - The current grid view mode. Valid values are `DOT_GRID_MODE`,`CROSS_GRID_MODE`, and `LINE_GRID_MODE`.

### isGridVisible

    public boolean isGridVisible()

  Returns true if the grid will be visible.

  Returns:
    true if the grid is visible

### setGridVisible

    public void setGridVisible(boolean flag)

  If set to true, the grid will be visible.

  Fires a property change for the GRID_VISIBLE_PROPERTY.

### isPortsVisible

    public boolean isPortsVisible()

  Returns true if the ports will be visible.

  Returns:
    true if the ports are visible

### setPortsVisible

    public void setPortsVisible(boolean flag)

  If set to true, the ports will be visible.

  Fires a property change for the PORTS_VISIBLE_PROPERTY.

### isAntiAliased

    public boolean isAntiAliased()

  Returns true if the graph will be anti aliased.

  Returns:
    true if the graph is anti aliased

### setAntiAliased

    public void setAntiAliased(boolean newValue)

  Sets antialiasing on or off based on the boolean value.

  Fires a property change for the ANTIALIASED_PROPERTY.

  Parameters:
    `newValue` - whether to turn antialiasing on or off

### isEditable

    public boolean isEditable()

  Returns true if the graph is editable, ie. if it allows cells to be edited.

  Returns:
    true if the graph is editable

### setEditable

    public void setEditable(boolean flag)

  Determines whether the graph is editable. Fires a property change event if the new setting is different from the existing setting.

  Note: Editable determines whether the graph allows editing. This is not to be confused with enabled, which allows the graph to handle mouse events (including editing).

  Parameters:
    `flag` - a boolean value, true if the graph is editable

### getModel

    public GraphModel getModel()

  Returns the `GraphModel` that is providing the data.

  Returns:
    the model that is providing the data

### setModel

    public void setModel(GraphModel newModel)

  Sets the `GraphModel` that will provide the data. Note: Updates the current GraphLayoutCache's model using setModel if the GraphLayoutCache points to a different model.

  Fires a property change for the GRAPH_MODEL_PROPERTY.

  Parameters:
    `newModel` - the `GraphModel` that is to provide the data

### getGraphLayoutCache

    public GraphLayoutCache getGraphLayoutCache()

  Returns the `GraphLayoutCache` that is providing the view-data.

  Returns:
    the view that is providing the view-data

### setGraphLayoutCache

    public void setGraphLayoutCache(GraphLayoutCache newLayoutCache)

  Sets the `GraphLayoutCache` that will provide the view-data.

  Note: Updates the GraphLayoutCache's model using setModel if the GraphLayoutCache points to an other model than this graph.

  Fires a property change for the GRAPH_LAYOUT_CACHE_PROPERTY.

### getMarqueeHandler

    public BasicMarqueeHandler getMarqueeHandler()

  Returns the `MarqueeHandler` that will handle marquee selection.

### setMarqueeHandler

    public void setMarqueeHandler(BasicMarqueeHandler newMarquee)

  Sets the `MarqueeHandler` that will handle marquee selection.

### setInvokesStopCellEditing

    public void setInvokesStopCellEditing(boolean newValue)

  Determines what happens when editing is interrupted by selecting another cell in the graph, a change in the graph's data, or by some other means. Setting this property to `true` causes the changes to be automatically saved when editing is interrupted.

  Fires a property change for the INVOKES_STOP_CELL_EDITING_PROPERTY.

  Parameters:
    `newValue` - true means that `stopCellEditing` is invoked when editing is interruped, and data is saved; false means that `cancelCellEditing` is invoked, and changes are lost

### getInvokesStopCellEditing

    public boolean getInvokesStopCellEditing()

  Returns the indicator that tells what happens when editing is interrupted.

  Returns:
    the indicator that tells what happens when editing is interrupted
  See Also:
    `setInvokesStopCellEditing(boolean)`

### isCellEditable

    public boolean isCellEditable(Object cell)

  Returns `isEditable`. This is invoked from the UI before editing begins to ensure that the given cell can be edited. This is provided as an entry point for subclassers to add filtered editing without having to resort to creating a new editor.

  Returns:
    true if the specified cell is editable
  See Also:
    `isEditable()`

### getToolTipText

    public String getToolTipText(MouseEvent event)

  Overrides `JComponent`'s`getToolTipText` method in order to allow the graph to create a tooltip for the topmost cell under the mousepointer. This differs from JTree where the renderers tooltip is used.

  NOTE: For `JGraph` to properly display tooltips of its renderers, `JGraph` must be a registered component with the `ToolTipManager`. This can be done by invoking `ToolTipManager.sharedInstance().registerComponent(graph)`. This is not done automatically!

  Overrides:
    `getToolTipText` in class `JComponent`
  Parameters:
    `event` - the `MouseEvent` that initiated the `ToolTip` display
  Returns:
    a string containing the tooltip or `null` if `event` is null

### setSelectionModel

    public void setSelectionModel(GraphSelectionModel selectionModel)

  Sets the graph's selection model. When a `null` value is specified an emtpy `selectionModel` is used, which does not allow selections.

  Parameters:
    `selectionModel` - the `GraphSelectionModel` to use, or `null` to disable selections
  See Also:
    `GraphSelectionModel`

### getSelectionModel

    public GraphSelectionModel getSelectionModel()

  Returns the model for selections. This should always return a non- `null` value. If you don't want to allow anything to be selected set the selection model to `null`, which forces an empty selection model to be used.

  Returns:
    the current selection model
  See Also:
    `setSelectionModel(org.jgraph.graph.GraphSelectionModel)`

### clearSelection

    public void clearSelection()

  Clears the selection.

### isSelectionEmpty

    public boolean isSelectionEmpty()

  Returns true if the selection is currently empty.

  Returns:
    true if the selection is currently empty

### addGraphSelectionListener

    public void addGraphSelectionListener(GraphSelectionListener tsl)

  Adds a listener for `GraphSelection` events.

  Parameters:
    `tsl` - the `GraphSelectionListener` that will be notified when a cell is selected or deselected (a "negative selection")

### removeGraphSelectionListener

    public void removeGraphSelectionListener(GraphSelectionListener tsl)

  Removes a `GraphSelection` listener.

  Parameters:
    `tsl` - the `GraphSelectionListener` to remove

### fireValueChanged

    protected void fireValueChanged(GraphSelectionEvent e)

  Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.

  Parameters:
    `e` - the `GraphSelectionEvent` generated by the `GraphSelectionModel` when a cell is selected or deselected
  See Also:
    `EventListenerList`

### setSelectionCell

    public void setSelectionCell(Object cell)

  Selects the specified cell.

  Parameters:
    `cell` - the `Object` specifying the cell to select

### setSelectionCells

    public void setSelectionCells(Object[] cells)

  Selects the specified cells.

  Parameters:
    `cells` - an array of objects that specifies the cells to select

### addSelectionCell

    public void addSelectionCell(Object cell)

  Adds the cell identified by the specified `Object` to the current selection.

  Parameters:
    `cell` - the cell to be added to the selection

### addSelectionCells

    public void addSelectionCells(Object[] cells)

  Adds each cell in the array of cells to the current selection.

  Parameters:
    `cells` - an array of objects that specifies the cells to add

### removeSelectionCell

    public void removeSelectionCell(Object cell)

  Removes the cell identified by the specified Object from the current selection.

  Parameters:
    `cell` - the cell to be removed from the selection

### getSelectionCell

    public Object getSelectionCell()

  Returns the first selected cell.

  Returns:
    the `Object` for the first selected cell, or `null` if nothing is currently selected

### getSelectionCells

    public Object[] getSelectionCells()

  Returns all selected cells.

  Returns:
    an array of objects representing the selected cells, or `null` if nothing is currently selected

### getSelectionCount

    public int getSelectionCount()

  Returns the number of cells selected.

  Returns:
    the number of cells selected

### isCellSelected

    public boolean isCellSelected(Object cell)

  Returns true if the cell is currently selected.

  Parameters:
    `cell` - an object identifying a cell
  Returns:
    true if the cell is selected

### scrollCellToVisible

    public void scrollCellToVisible(Object cell)

  Scrolls to the specified cell. Only works when this `JGraph` is contained in a `JScrollPane`.

  Parameters:
    `cell` - the object identifying the cell to bring into view

### scrollPointToVisible

    public void scrollPointToVisible(Point2D p)

  Makes sure the specified point is visible.

  Parameters:
    `p` - the point that should be visible

### isEditing

    public boolean isEditing()

  Returns true if the graph is being edited. The item that is being edited can be obtained using `getEditingCell`.

  Returns:
    true if the user is currently editing a cell
  See Also:
    `getSelectionCell()`

### stopEditing

    public boolean stopEditing()

  Ends the current editing session. (The `DefaultGraphCellEditor` object saves any edits that are currently in progress on a cell. Other implementations may operate differently.) Has no effect if the tree isn't being edited.

  > Note:
  > To make edit-saves automatic whenever the user changes their position in the graph, use `setInvokesStopCellEditing(boolean)`.

  Returns:
    true if editing was in progress and is now stopped, false if editing was not in progress

### cancelEditing

    public void cancelEditing()

  Cancels the current editing session. Has no effect if the graph isn't being edited.

### startEditingAtCell

    public void startEditingAtCell(Object cell)

  Selects the specified cell and initiates editing. The edit-attempt fails if the `CellEditor` does not allow editing for the specified item.

### getEditingCell

    public Object getEditingCell()

  Returns the cell that is currently being edited.

  Returns:
    the cell being edited

### graphDidChange

    public void graphDidChange()

  Messaged when the graph has changed enough that we need to resize the bounds, but not enough that we need to remove the cells (e.g cells were inserted into the graph). You should never have to invoke this, the UI will invoke this as it needs to. (Note: This is invoked by GraphUI, eg. after moving.)

### getPreferredScrollableViewportSize

    public Dimension getPreferredScrollableViewportSize()

  Returns the preferred display size of a `JGraph`. The height is determined from `getPreferredWidth`.

  Specified by:
    `getPreferredScrollableViewportSize` in interface `Scrollable`
  Returns:
    the graph's preferred size

### getScrollableUnitIncrement

    public int getScrollableUnitIncrement(Rectangle visibleRect,
                                          int orientation,
                                          int direction)

  Returns the amount to increment when scrolling. The amount is 4.

  Specified by:
    `getScrollableUnitIncrement` in interface `Scrollable`
  Parameters:
    `visibleRect` - the view area visible within the viewport
    `orientation` - either `SwingConstants.VERTICAL` or `SwingConstants.HORIZONTAL`
    `direction` - less than zero to scroll up/left, greater than zero for down/right
  Returns:
    the "unit" increment for scrolling in the specified direction
  See Also:
    `JScrollBar.setUnitIncrement(int)`

### getScrollableBlockIncrement

    public int getScrollableBlockIncrement(Rectangle visibleRect,
                                           int orientation,
                                           int direction)

  Returns the amount for a block increment, which is the height or width of `visibleRect`, based on `orientation`.

  Specified by:
    `getScrollableBlockIncrement` in interface `Scrollable`
  Parameters:
    `visibleRect` - the view area visible within the viewport
    `orientation` - either `SwingConstants.VERTICAL` or `SwingConstants.HORIZONTAL`
    `direction` - less than zero to scroll up/left, greater than zero for down/right.
  Returns:
    the "block" increment for scrolling in the specified direction
  See Also:
    `JScrollBar.setBlockIncrement(int)`

### getScrollableTracksViewportWidth

    public boolean getScrollableTracksViewportWidth()

  Returns false to indicate that the width of the viewport does not determine the width of the graph, unless the preferred width of the graph is smaller than the viewports width. In other words: ensure that the graph is never smaller than its viewport.

  Specified by:
    `getScrollableTracksViewportWidth` in interface `Scrollable`
  Returns:
    false
  See Also:
    `Scrollable.getScrollableTracksViewportWidth()`

### getScrollableTracksViewportHeight

    public boolean getScrollableTracksViewportHeight()

  Returns false to indicate that the height of the viewport does not determine the height of the graph, unless the preferred height of the graph is smaller than the viewports height. In other words: ensure that the graph is never smaller than its viewport.

  Specified by:
    `getScrollableTracksViewportHeight` in interface `Scrollable`
  Returns:
    false
  See Also:
    `Scrollable.getScrollableTracksViewportHeight()`

### paramString

    protected String paramString()

  Returns a string representation of this `JGraph`. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be `null`.

  Overrides:
    `paramString` in class `JComponent`
  Returns:
    a string representation of this `JGraph`.

### main

    public static void main(String[] args)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| JGraph v5.0
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) 2003-2004 Gaudenz Alder. All rights reserved.