Class JGraph
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- org.jgraph.JGraph
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.Scrollable
public class JGraph extends javax.swing.JComponent implements javax.swing.Scrollable, javax.accessibility.Accessible, java.io.SerializableA 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
Outmoved, 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.
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
GraphSelectionListenerinterface and add the instance using the methodaddGraphSelectionListener.valueChangedwill be invoked when the selection changes, that is if the user clicks twice on the same vertexvalueChangedwill only be invoked once.Change Notification
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
GraphUndoManagermust be added usingaddGraphSelectionListener. The GraphUndoManager is an extension of Swing'sGraphUndoManagerthat 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
JComponentclasses, you can useInputMapandActionMapto associate anActionobject with aKeyStrokeand execute the action under specified conditions.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJGraph.EmptySelectionModelEmptySelectionModelis aGraphSelectionModelthat does not allow anything to be selected.protected classJGraph.GraphSelectionRedirectorHandles creating a newGraphSelectionEventwith theJGraphas the source and passing it off to all the listeners.-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanantiAliasedTrue if the graph is anti-aliased.static java.lang.StringANTIALIASED_PROPERTYBound property name forantiAliased.protected booleanautoResizeGraphTrue if the graph should be auto resized when cells are moved below the bottom right corner.protected java.awt.ComponentbackgroundComponentA Component responsible for drawing the background image, if anyprotected javax.swing.ImageIconbackgroundImageHolds the background image.protected booleanbackgroundScaledWhether or not the background image is scaled on zoomingprotected booleanbendableTrue if the graph allows points to be modified/added/removed.protected booleancloneableTrue if the graph allows "ctrl-drag" operations.protected booleanconnectableTrue if the graph allows new connections to be established.static intCROSS_GRID_MODEprotected booleandisconnectableTrue if the graph allows existing connections to be removed.protected booleandisconnectOnMoveTrue if selected edges are disconnected from unselected vertices on move.static intDOT_GRID_MODEprotected booleandragEnabledTrue if Drag-and-Drop should be used for move operations.protected booleandropEnabledTrue if the graph accepts transfers from other components (graphs).protected booleanedgeLabelsMovableTrue if the labels on edges may be moved.protected booleaneditableTrue if the graph allows editing the value of a cell.static java.lang.StringEDITABLE_PROPERTYBound property name foreditable.protected inteditClickCountNumber of clicks for editing to start.protected booleanenabledTrue if the graph allows interactions.static java.lang.StringGRAPH_LAYOUT_CACHE_PROPERTYBound property name forgraphModel.static java.lang.StringGRAPH_MODEL_PROPERTYBound property name forgraphModel.protected GraphLayoutCachegraphLayoutCacheThe view that defines the display properties of the model.protected GraphModelgraphModelThe model that defines the graph displayed by this object.static java.lang.StringGRID_COLOR_PROPERTYBound property name forgridColor.static java.lang.StringGRID_SIZE_PROPERTYBound property name forgridSize.static java.lang.StringGRID_VISIBLE_PROPERTYBound property name forgridVisible.protected java.awt.ColorgridColorThe color of the grid.protected booleangridEnabledTrue if the snap method should be active (snap to grid).protected intgridModeThe style of the grid.protected doublegridSizeThe size of the grid in points.protected booleangridVisibleTrue if the grid is visible.protected booleangroupsEditableTrue if the graph allows editing of non-leaf cells.static java.lang.StringHANDLE_COLOR_PROPERTYBound property name forgridColor.static java.lang.StringHANDLE_SIZE_PROPERTYBound property name forgridColor.protected java.awt.ColorhandleColorColor of the handles and locked handles.protected inthandleSizeSize of a handle.protected java.awt.ColorhighlightColorHighlight Color.static java.lang.StringINVOKES_STOP_CELL_EDITING_PROPERTYBound property name formessagesStopCellEditing.protected booleaninvokesStopCellEditingIf true, when editing is to be stopped by way of selection changing, data in graph changing or other meansstopCellEditingis invoked, and changes are saved.static booleanIS_MACprotected booleanisJumpToDefaultPortTrue if getPortViewAt should return the default port if no other port is found.protected booleanisMoveIntoGroupsSpecifies if cells should be added to a group when moved over the group's area.protected booleanisMoveOutOfGroupsSpecifies if cells should be removed from groups when removed from the group area.protected booleanlastBufferAllocatedStores whether the last double buffer allocation worked or notstatic intLINE_GRID_MODEstatic java.lang.StringLOCKED_HANDLE_COLOR_PROPERTYBound property name forgridColor.protected java.awt.ColorlockedHandleColorColor of the handles and locked handles.protected BasicMarqueeHandlermarqueeHandler for marquee selection.static java.lang.StringMARQUEE_HANDLER_PROPERTYBound property name forgraphModel.protected java.awt.ColormarqueeColorColor of the marquee.protected intminimumMoveMinimum amount of pixels to start a move transaction.protected booleanmoveableTrue if the graph allows move operations.protected booleanmoveBelowZeroTrue if the graph allows to move cells below zero.protected booleanmoveBeyondGraphBoundsTrue if the graph allows to move cells beyond the graph boundsprotected java.awt.GraphicsoffgraphicsGraphics object of off screen imageprotected java.awt.ImageoffscreenOff screen image for double bufferingprotected java.awt.geom.Rectangle2DoffscreenBoundsThe bounds of the offscreen bufferprotected intoffscreenBufferThe buffer around the offscreen graphics object that provides the specified distance of scrolling before the buffer has to be recreated.protected java.awt.geom.Rectangle2DoffscreenDirtyWhether or not the current background image is correctprotected java.awt.geom.Point2DoffscreenOffsetThe offset of the offscreen bufferstatic java.lang.StringPORTS_SCALED_PROPERTYBound property name forportsScaled.static java.lang.StringPORTS_VISIBLE_PROPERTYBound property name forgridVisible.protected booleanportsOnTopTrue if port are painted above all other cells.protected booleanportsScaledTrue if the ports are scaled.protected booleanportsVisibleTrue if the ports are visible.protected booleanpreviewInvalidNullPortsTrue if the graph allows invalid null ports during previews (aka flip back edges).static java.lang.StringPROPERTY_BACKGROUNDIMAGEBound property name forbackgroundImage.protected doublescaleScale of the graph.static java.lang.StringSCALE_PROPERTYBound property name forscale.static java.lang.StringSELECTION_MODEL_PROPERTYBound property name forselectionModel.protected booleanselectionEnabledTrue if the graph allows selection of cells.static java.lang.StringSELECTIONENABLED_PROPERTYBound property name forselectionEnabled.protected GraphSelectionModelselectionModelModels the set of selected objects in this graph.protected JGraph.GraphSelectionRedirectorselectionRedirectorCreates a new event and passes it off theselectionListeners.protected booleansizeableTrue if the graph allows cells to be resized.protected inttoleranceMaximum distance between a cell and the mousepointer.static java.lang.StringVERSIONprotected booleanvolatileOffscreenWhether or not to try to use a volatile offscreen buffer for double buffering.protected booleanwholeOffscreenDirtyprotected doublewholeOffscreenDirtyProportionprotected booleanxorEnabledTrue if the graph accepts transfers from other components (graphs).-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description JGraph()Returns aJGraphwith a sample model.JGraph(GraphLayoutCache cache)Returns an instance ofJGraphwhich displays the data model using the specified view.JGraph(GraphModel model)Returns an instance ofJGraphwhich displays the the specified data model.JGraph(GraphModel model, BasicMarqueeHandler mh)Returns an instance ofJGraphwhich displays the specified data model and assigns the specified marquee handlerJGraph(GraphModel model, GraphLayoutCache cache)Returns an instance ofJGraphwhich displays the specified data model using the specified view.JGraph(GraphModel model, GraphLayoutCache layoutCache, BasicMarqueeHandler mh)Returns an instance ofJGraphwhich displays the specified data model using the specified view and assigns the specified marquee handler
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddGraphSelectionListener(GraphSelectionListener tsl)Adds a listener forGraphSelectionevents.voidaddOffscreenDirty(java.awt.geom.Rectangle2D offscreenDirty)Adds the specified area to the region deemed dirty for the next double buffered redrawstatic voidaddSampleData(GraphModel model)Creates and returns a sampleGraphModel.voidaddSelectionCell(java.lang.Object cell)Adds the cell identified by the specifiedObjectto the current selection.voidaddSelectionCells(java.lang.Object[] cells)Adds each cell in the array of cells to the current selection.voidcancelEditing()Cancels the current editing session.voidclearOffscreen()Invalidate the offscreen region, do not just delete it, since if the new region is smaller than the old you may not wish to re-create the buffervoidclearOffscreenDirty()Clears the region deemed dirty for the next double buffered redrawvoidclearSelection()Clears the selection.java.util.MapcloneCells(java.lang.Object[] cells)Returns a map of (cell, clone)-pairs for allcellsand their children.java.lang.StringconvertValueToString(java.lang.Object value)Converts the specified value to string.static java.util.MapcreateBounds(AttributeMap map, int x, int y, java.awt.Color c)Returns an attributeMap for the specified position and color.protected voidcreateBufferedImage(int width, int height)Utility method to create a standard buffered imagebooleandrawImage(int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2)Utility method to draw the off screen bufferbooleandrawImage(java.awt.Graphics g)protected voidfireValueChanged(GraphSelectionEvent e)Notifies all listeners that have registered interest for notification on this event type.java.awt.geom.Point2DfromScreen(java.awt.geom.Point2D p)Downscale the given point in place, using the given instance.java.awt.geom.Rectangle2DfromScreen(java.awt.geom.Rectangle2D rect)Downscale the given rectangle in place, using the given instance.AttributeMapgetAttributes(java.lang.Object cell)Returns the attributes for the specified cell.java.awt.ComponentgetBackgroundComponent()javax.swing.ImageIcongetBackgroundImage()Returns the background image.java.awt.geom.Rectangle2DgetCellBounds(java.lang.Object cell)Returns the bounding rectangle of the specified cell.java.awt.geom.Rectangle2DgetCellBounds(java.lang.Object[] cells)Returns the bounding rectangle of the specified cells.java.awt.geom.Point2DgetCenterPoint()Returns the center of the component relative to the parent viewport's position.java.awt.geom.Rectangle2DgetClipRectangle(GraphLayoutCacheEvent.GraphLayoutCacheChange change)Calculates the clipPortViewgetDefaultPortForCell(java.lang.Object cell)Returns the default portview for the specified cell.java.lang.Object[]getDescendants(java.lang.Object[] cells)Returns allcellsincluding all descendants in the passed in order of cells.booleangetEdgeLabelsMovable()Returns true if edge labels may be dragged and dropped.intgetEditClickCount()Returns the number of clicks for editing to start.java.lang.ObjectgetEditingCell()Returns the cell that is currently being edited.java.lang.ObjectgetFirstCellForLocation(double x, double y)Returns the topmost cell at the specified location.GraphLayoutCachegetGraphLayoutCache()Returns theGraphLayoutCachethat is providing the view-data.java.awt.ColorgetGridColor()Returns the current grid color.intgetGridMode()Returns the current grid view mode.doublegetGridSize()Returns the size of the grid in pixels.java.awt.ColorgetHandleColor()Returns the current handle color.intgetHandleSize()Returns the size of the handles.java.awt.ColorgetHighlightColor()Returns the current highlight color.java.awt.image.BufferedImagegetImage(java.awt.Color bg, int inset)Returns aBufferedImagefor the graph using inset as an empty border around the cells of the graph.booleangetInvokesStopCellEditing()Returns the indicator that tells what happens when editing is interrupted.CellViewgetLeafViewAt(double x, double y)Returns the next view at the specified location wrt.java.awt.ColorgetLockedHandleColor()Returns the current second handle color.java.awt.ColorgetMarqueeColor()Returns the current marquee color.BasicMarqueeHandlergetMarqueeHandler()Returns theMarqueeHandlerthat will handle marquee selection.intgetMinimumMove()Returns the miminum amount of pixels for a move operation.GraphModelgetModel()Returns theGraphModelthat is providing the data.java.lang.ObjectgetNextCellForLocation(java.lang.Object current, double x, double y)Returns the cell at the specified location that is "behind" thecurrentcell.CellViewgetNextSelectableViewAt(CellView current, double x, double y)Note: Arguments are not expected to be scaled (they are scaled in here).CellViewgetNextViewAt(CellView[] cells, CellView c, double x, double y)Returns the next view at the specified location wrt.CellViewgetNextViewAt(CellView[] cells, CellView c, double x, double y, boolean leafsOnly)Returns the next view at the specified location wrt.CellViewgetNextViewAt(CellView current, double x, double y)Returns the next view at the specified location wrt.CellViewgetNextViewAt(CellView current, double x, double y, boolean leafsOnly)Returns the next view at the specified location wrt.java.awt.GraphicsgetOffgraphics()Returns the current double buffering graphics object.java.awt.ImagegetOffscreen()java.awt.geom.Rectangle2DgetOffscreenDirty()Returns the area that is deemed dirty for the next double buffered redrawjava.awt.geom.Point2DgetOffscreenOffset()java.lang.ObjectgetPortForLocation(double x, double y)Convenience method to return the port at the specified location.PortViewgetPortViewAt(double x, double y)Returns the portview at the specified location.PortViewgetPortViewAt(double x, double y, int tolerance)Returns the portview at the specified location.java.awt.DimensiongetPreferredScrollableViewportSize()Returns the preferred display size of aJGraph.java.lang.Object[]getRoots()Returns all root cells (cells that have no parent) that the model contains.java.lang.Object[]getRoots(java.awt.Rectangle clip)Returns all cells that intersect the given rectangle.doublegetScale()Returns the current scale.intgetScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)Returns the amount for a block increment, which is the height or width ofvisibleRect, based onorientation.booleangetScrollableTracksViewportHeight()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.booleangetScrollableTracksViewportWidth()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.intgetScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)Returns the amount to increment when scrolling.java.lang.ObjectgetSelectionCell()Returns the first selected cell.java.lang.ObjectgetSelectionCellAt(java.awt.geom.Point2D pt)Returns the selection cell at the specified location.java.lang.Object[]getSelectionCells()Returns all selected cells.java.lang.Object[]getSelectionCells(java.lang.Object[] cells)Returns all selected cells incells.intgetSelectionCount()Returns the number of cells selected.GraphSelectionModelgetSelectionModel()Returns the model for selections.intgetTolerance()Returns the maximum distance between the mousepointer and a cell to be selected.java.lang.StringgetToolTipText(java.awt.event.MouseEvent e)OverridesJComponent'sgetToolTipTextmethod in order to allow the graph to create a tooltip for the topmost cell under the mousepointer.CellViewgetTopmostViewAt(double x, double y, boolean reverse, boolean leafsOnly)Returns the topmost cell view at the specified location using the view's bounds on non-leafs to check for containment.GraphUIgetUI()Returns the L&F object that renders this component.java.lang.StringgetUIClassID()Returns the name of the L&F class that renders this component.java.awt.geom.Rectangle2DgetViewPortBounds()Return the bounds of the parent viewport, if one exists.voidgraphDidChange()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).booleanisAntiAliased()Returns true if the graph will be anti aliased.booleanisAutoResizeGraph()Returns true if the graph should be automatically resized when cells are being moved below the bottom right corner.booleanisBackgroundScaled()booleanisBendable()Returns true if the graph allows adding/removing/modifying points.booleanisCellEditable(java.lang.Object cell)Returnstrueif the graph and the cell are editable.booleanisCellSelected(java.lang.Object cell)Returns true if the cell is currently selected.booleanisCloneable()Returns true if cells are cloned on CTRL-Drag operations.booleanisConnectable()Returns true if the graph allows new connections to be established.booleanisDisconnectable()Returns true if the graph allows existing connections to be removed.booleanisDisconnectOnMove()Returns true if selected edges should be disconnected from unselected vertices when they are moved.booleanisDragEnabled()Returns true if the graph uses Drag-and-Drop to move cells.booleanisDropEnabled()Returns true if the graph accepts drops/pastes from external sources.booleanisEditable()Returns true if the graph is editable (if it allows cells to be edited).booleanisEditing()Returns true if the graph is being edited.booleanisGridEnabled()Returns true if the grid is active.booleanisGridVisible()Returns true if the grid will be visible.booleanisGroupsEditable()booleanisJumpToDefaultPort()Returns true if getPortViewAt should return the default port if no other port is found.booleanisMoveable()booleanisMoveBelowZero()Returns true if the graph allows to move cells below zero.booleanisMoveBeyondGraphBounds()booleanisMoveIntoGroups()Returns true if cells should be added to groups when moved over the group's area.booleanisMoveOutOfGroups()Returns true if cells should be removed from groups when removed from the group's area.booleanisPortsOnTop()booleanisPortsScaled()Returns true if the ports will be scaled.booleanisPortsVisible()Returns true if the ports will be visible.booleanisPreviewInvalidNullPorts()Returns true if graph allows invalid null ports during previewsbooleanisSelectionEmpty()Returns true if the selection is currently empty.booleanisSelectionEnabled()Returns true if the cell selection is enabledbooleanisSizeable()Returns true if the graph allows cells to be resized.booleanisVolatileOffscreen()booleanisXorEnabled()Returns true if the graph accepts drops/pastes from external sources.static voidmain(java.lang.String[] args)java.lang.Object[]order(java.lang.Object[] cells)Returns allcellsincluding all descendants ordered using the current layering data stored by the model.protected java.lang.StringparamString()Returns a string representation of thisJGraph.voidrefresh()Repaints the entire graph, regardless of what is marked dirtyvoidreleaseOffscreenResources()Schedules the offscreen resources taken by the offscreen buffer to be reclaimed.voidremoveGraphSelectionListener(GraphSelectionListener tsl)Removes aGraphSelectionlistener.voidremoveSelectionCell(java.lang.Object cell)Removes the cell identified by the specified Object from the current selection.voidscrollCellToVisible(java.lang.Object cell)Scrolls to the specified cell.voidscrollPointToVisible(java.awt.geom.Point2D p)Makes sure the specified point is visible.voidsetAntiAliased(boolean newValue)Sets antialiasing on or off based on the boolean value.voidsetAutoResizeGraph(boolean autoResizeGraph)Sets whether or not the graph should be automatically resize when cells are being moved below the bottom right cornervoidsetBackground(java.awt.Color bg)Override parent to clear offscreen double buffervoidsetBackgroundComponent(java.awt.Component backgroundComponent)voidsetBackgroundImage(javax.swing.ImageIcon backgroundImage)Sets the background image.voidsetBackgroundScaled(boolean backgroundScaled)voidsetBendable(boolean flag)Sets if the graph allows adding/removing/modifying points.voidsetCloneable(boolean flag)Sets if cells are cloned on CTRL-Drag operations.voidsetConnectable(boolean flag)Setse if the graph allows new connections to be established.voidsetDisconnectable(boolean flag)Sets if the graph allows existing connections to be removed.voidsetDisconnectOnMove(boolean flag)Sets if selected edges should be disconnected from unselected vertices when they are moved.voidsetDragEnabled(boolean flag)Sets if the graph uses Drag-and-Drop to move cells.voidsetDropEnabled(boolean flag)Sets if the graph accepts drops/pastes from external sources.voidsetEdgeLabelsMovable(boolean edgeLabelsMovable)Set if edge labels may be moved with the mouse or not.voidsetEditable(boolean flag)Determines whether the graph is editable.voidsetEditClickCount(int count)Sets the number of clicks for editing to start.voidsetGraphLayoutCache(GraphLayoutCache newLayoutCache)Sets theGraphLayoutCachethat will provide the view-data.voidsetGridColor(java.awt.Color newColor)Sets the current grid color.voidsetGridEnabled(boolean flag)If set to true, the grid will be active.voidsetGridMode(int mode)Sets the current grid view mode.voidsetGridSize(double newSize)Sets the size of the grid.voidsetGridVisible(boolean flag)If set to true, the grid will be visible.voidsetGroupsEditable(boolean groupsEditable)voidsetHandleColor(java.awt.Color newColor)Sets the current handle color.voidsetHandleSize(int size)Sets the size of the handles.voidsetHighlightColor(java.awt.Color newColor)Sets the current selection highlight color.voidsetInvokesStopCellEditing(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.voidsetJumpToDefaultPort(boolean flag)Sets if getPortViewAt should return the default port if no other port is found.voidsetLockedHandleColor(java.awt.Color newColor)Sets the current second handle color.voidsetMarqueeColor(java.awt.Color newColor)Sets the current marquee color.voidsetMarqueeHandler(BasicMarqueeHandler newMarquee)Sets theMarqueeHandlerthat will handle marquee selection.voidsetMinimumMove(int pixels)Sets the miminum amount of pixels for a move operation.voidsetModel(GraphModel newModel)Sets theGraphModelthat will provide the data.voidsetMoveable(boolean flag)Sets if the graph allows movement of cells.voidsetMoveBelowZero(boolean moveBelowZero)Sets if the graph should auto resize when cells are being moved below the bottom right corner.voidsetMoveBeyondGraphBounds(boolean moveBeyondGraphBounds)voidsetMoveIntoGroups(boolean flag)Specifies if cells should be added to groups when moved over the group's area.voidsetMoveOutOfGroups(boolean flag)Specifies if cells should be removed from groups when removed from the group's area.voidsetOffscreenOffset(java.awt.geom.Point2D offscreenOffset)voidsetOpaque(boolean opaque)voidsetPortsOnTop(boolean portsOnTop)voidsetPortsScaled(boolean flag)If set to true, the ports will be scaled.voidsetPortsVisible(boolean flag)If set to true, the ports will be visible.voidsetPreviewInvalidNullPorts(boolean flag)Determines whether the graph allows invalid null ports during previewsvoidsetScale(double newValue)Sets the current scale.voidsetScale(double newValue, java.awt.geom.Point2D center)Sets the current scale and centers the graph to the specified pointvoidsetSelectionCell(java.lang.Object cell)Selects the specified cell.voidsetSelectionCells(java.lang.Object[] cells)Selects the specified cells.voidsetSelectionEnabled(boolean flag)Determines whether cell selection is enabled.voidsetSelectionModel(GraphSelectionModel selectionModel)Sets the graph's selection model.voidsetSizeable(boolean flag)Sets if the graph allows cells to be resized.voidsetTolerance(int size)Sets the maximum distance between the mousepointer and a cell to be selected.voidsetUI(GraphUI ui)Sets the L&F object that renders this component.protected voidsetupOffScreen(int x, int y, int width, int height, java.awt.geom.Rectangle2D newOffscreenBuffer)Utility method that initialises the offscreen graphics areavoidsetVolatileOffscreen(boolean volatileOffscreen)voidsetXorEnabled(boolean flag)Sets if the graph accepts drops/pastes from external sources.java.awt.geom.Dimension2Dsnap(java.awt.geom.Dimension2D d)Returns the given dimension applied to the grid.java.awt.geom.Point2Dsnap(java.awt.geom.Point2D p)Returns the given point applied to the grid.java.awt.geom.Rectangle2Dsnap(java.awt.geom.Rectangle2D r)Returns the given rectangle applied to the grid.voidstartEditingAtCell(java.lang.Object cell)Selects the specified cell and initiates editing.booleanstopEditing()Ends the current editing session.java.awt.geom.Point2DtoScreen(java.awt.geom.Point2D p)Upscale the given point in place, using the given instance.java.awt.geom.Rectangle2DtoScreen(java.awt.geom.Rectangle2D rect)Upscale the given rectangle in place, using the given instance.voidupdateAutoSize(CellView view)Computes and updates the size forview.voidupdateUI()Notification from theUIManagerthat the L&F has changed.-
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, getBaseline, getBaselineResizeBehavior, 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, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, 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, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
VERSION
public static final java.lang.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
-
IS_MAC
public static boolean IS_MAC
-
selectionRedirector
protected transient JGraph.GraphSelectionRedirector selectionRedirector
Creates a new event and passes it off theselectionListeners.
-
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.
-
selectionModel
protected transient GraphSelectionModel selectionModel
Models the set of selected objects in this graph. Bound property.
-
marquee
protected transient BasicMarqueeHandler marquee
Handler for marquee selection.
-
offscreen
protected transient java.awt.Image offscreen
Off screen image for double buffering
-
offscreenBounds
protected transient java.awt.geom.Rectangle2D offscreenBounds
The bounds of the offscreen buffer
-
offscreenOffset
protected transient java.awt.geom.Point2D offscreenOffset
The offset of the offscreen buffer
-
offgraphics
protected transient java.awt.Graphics offgraphics
Graphics object of off screen image
-
offscreenDirty
protected transient java.awt.geom.Rectangle2D offscreenDirty
Whether or not the current background image is correct
-
wholeOffscreenDirty
protected transient boolean wholeOffscreenDirty
-
wholeOffscreenDirtyProportion
protected transient double wholeOffscreenDirtyProportion
-
offscreenBuffer
protected transient int offscreenBuffer
The buffer around the offscreen graphics object that provides the specified distance of scrolling before the buffer has to be recreated. Increasing the value means fewer buffer allocations but more memory usage for the current buffer
-
volatileOffscreen
protected boolean volatileOffscreen
Whether or not to try to use a volatile offscreen buffer for double buffering. Volatile
-
lastBufferAllocated
protected boolean lastBufferAllocated
Stores whether the last double buffer allocation worked or not
-
backgroundImage
protected javax.swing.ImageIcon backgroundImage
Holds the background image.
-
backgroundComponent
protected java.awt.Component backgroundComponent
A Component responsible for drawing the background image, if any
-
backgroundScaled
protected boolean backgroundScaled
Whether or not the background image is scaled on zooming
-
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.
-
groupsEditable
protected boolean groupsEditable
True if the graph allows editing of non-leaf cells. Bound property.
-
selectionEnabled
protected boolean selectionEnabled
True if the graph allows selection of cells. Note: You must also disable selectNewCells if you disable this. Bound property.
-
previewInvalidNullPorts
protected boolean previewInvalidNullPorts
True if the graph allows invalid null ports during previews (aka flip back edges). Default is true.
-
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.
-
portsScaled
protected boolean portsScaled
True if the ports are scaled. Bound property.
-
portsOnTop
protected boolean portsOnTop
True if port are painted above all other cells.
-
moveBelowZero
protected boolean moveBelowZero
True if the graph allows to move cells below zero.
-
moveBeyondGraphBounds
protected boolean moveBeyondGraphBounds
True if the graph allows to move cells beyond the graph bounds
-
edgeLabelsMovable
protected boolean edgeLabelsMovable
True if the labels on edges may be moved.
-
autoResizeGraph
protected boolean autoResizeGraph
True if the graph should be auto resized when cells are moved below the bottom right corner. Default is true.
-
highlightColor
protected java.awt.Color highlightColor
Highlight Color. This color is used to draw the selection border of unfocused cells. Changes when the Look-and-Feel changes.
-
handleColor
protected java.awt.Color handleColor
Color of the handles and locked handles. Changes when the Look-and-Feel changes. This color is also used to draw the selection border of focused cells.
-
lockedHandleColor
protected java.awt.Color lockedHandleColor
Color of the handles and locked handles. Changes when the Look-and-Feel changes. This color is also used to draw the selection border of focused cells.
-
marqueeColor
protected java.awt.Color marqueeColor
Color of the marquee. Changes when the Look-and-Feel changes.
-
gridColor
protected java.awt.Color gridColor
The color of the grid. This color is used to draw the selection border for cells with selected children. 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.
-
xorEnabled
protected boolean xorEnabled
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.
-
isJumpToDefaultPort
protected boolean isJumpToDefaultPort
True if getPortViewAt should return the default port if no other port is found. Default is false.
-
isMoveIntoGroups
protected boolean isMoveIntoGroups
Specifies if cells should be added to a group when moved over the group's area. Default is false.
-
isMoveOutOfGroups
protected boolean isMoveOutOfGroups
Specifies if cells should be removed from groups when removed from the group area. Default is false.
-
disconnectOnMove
protected boolean disconnectOnMove
True if selected edges are disconnected from unselected vertices on move. Default is false.
-
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 modified/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 meansstopCellEditingis invoked, and changes are saved. If false,cancelCellEditingis invoked, and changes are discarded.
-
GRAPH_MODEL_PROPERTY
public static final java.lang.String GRAPH_MODEL_PROPERTY
Bound property name forgraphModel.- See Also:
- Constant Field Values
-
GRAPH_LAYOUT_CACHE_PROPERTY
public static final java.lang.String GRAPH_LAYOUT_CACHE_PROPERTY
Bound property name forgraphModel.- See Also:
- Constant Field Values
-
MARQUEE_HANDLER_PROPERTY
public static final java.lang.String MARQUEE_HANDLER_PROPERTY
Bound property name forgraphModel.- See Also:
- Constant Field Values
-
EDITABLE_PROPERTY
public static final java.lang.String EDITABLE_PROPERTY
Bound property name foreditable.- See Also:
- Constant Field Values
-
SELECTIONENABLED_PROPERTY
public static final java.lang.String SELECTIONENABLED_PROPERTY
Bound property name forselectionEnabled.- See Also:
- Constant Field Values
-
SCALE_PROPERTY
public static final java.lang.String SCALE_PROPERTY
Bound property name forscale.- See Also:
- Constant Field Values
-
ANTIALIASED_PROPERTY
public static final java.lang.String ANTIALIASED_PROPERTY
Bound property name forantiAliased.- See Also:
- Constant Field Values
-
GRID_SIZE_PROPERTY
public static final java.lang.String GRID_SIZE_PROPERTY
Bound property name forgridSize.- See Also:
- Constant Field Values
-
GRID_VISIBLE_PROPERTY
public static final java.lang.String GRID_VISIBLE_PROPERTY
Bound property name forgridVisible.- See Also:
- Constant Field Values
-
GRID_COLOR_PROPERTY
public static final java.lang.String GRID_COLOR_PROPERTY
Bound property name forgridColor.- See Also:
- Constant Field Values
-
HANDLE_COLOR_PROPERTY
public static final java.lang.String HANDLE_COLOR_PROPERTY
Bound property name forgridColor.- See Also:
- Constant Field Values
-
HANDLE_SIZE_PROPERTY
public static final java.lang.String HANDLE_SIZE_PROPERTY
Bound property name forgridColor.- See Also:
- Constant Field Values
-
LOCKED_HANDLE_COLOR_PROPERTY
public static final java.lang.String LOCKED_HANDLE_COLOR_PROPERTY
Bound property name forgridColor.- See Also:
- Constant Field Values
-
PORTS_VISIBLE_PROPERTY
public static final java.lang.String PORTS_VISIBLE_PROPERTY
Bound property name forgridVisible.- See Also:
- Constant Field Values
-
PORTS_SCALED_PROPERTY
public static final java.lang.String PORTS_SCALED_PROPERTY
Bound property name forportsScaled.- See Also:
- Constant Field Values
-
SELECTION_MODEL_PROPERTY
public static final java.lang.String SELECTION_MODEL_PROPERTY
Bound property name forselectionModel.- See Also:
- Constant Field Values
-
INVOKES_STOP_CELL_EDITING_PROPERTY
public static final java.lang.String INVOKES_STOP_CELL_EDITING_PROPERTY
Bound property name formessagesStopCellEditing.- See Also:
- Constant Field Values
-
PROPERTY_BACKGROUNDIMAGE
public static final java.lang.String PROPERTY_BACKGROUNDIMAGE
Bound property name forbackgroundImage.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
JGraph
public JGraph()
Returns aJGraphwith a sample model.
-
JGraph
public JGraph(GraphModel model)
Returns an instance ofJGraphwhich displays the the specified data model.- Parameters:
model- theGraphModelto use as the data model
-
JGraph
public JGraph(GraphLayoutCache cache)
Returns an instance ofJGraphwhich displays the data model using the specified view.- Parameters:
cache- theGraphLayoutCacheto use as the view
-
JGraph
public JGraph(GraphModel model, GraphLayoutCache cache)
Returns an instance ofJGraphwhich displays the specified data model using the specified view.- Parameters:
model- theGraphModelto use as the data modelcache- theGraphLayoutCacheto use as the cache
-
JGraph
public JGraph(GraphModel model, BasicMarqueeHandler mh)
Returns an instance ofJGraphwhich displays the specified data model and assigns the specified marquee handler- Parameters:
model- theGraphModelto use as the data modelmh- theBasicMarqueeHandlerto use as the marquee handler
-
JGraph
public JGraph(GraphModel model, GraphLayoutCache layoutCache, BasicMarqueeHandler mh)
Returns an instance ofJGraphwhich displays the specified data model using the specified view and assigns the specified marquee handler- Parameters:
model- theGraphModelto use as the data modellayoutCache- theGraphLayoutCacheto use as the cachemh- theBasicMarqueeHandlerto use as the marquee handler
-
-
Method Detail
-
addSampleData
public static void addSampleData(GraphModel model)
Creates and returns a sampleGraphModel. Used primarily for beanbuilders to show something interesting.
-
createBounds
public static java.util.Map createBounds(AttributeMap map, int x, int y, java.awt.Color c)
Returns an attributeMap for the specified position and color.
-
getUI
public GraphUI getUI()
Returns the L&F object that renders this component.- Overrides:
getUIin classjavax.swing.JComponent- 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 theUIManagerthat the L&F has changed. Replaces the current UI object with the latest version from theUIManager. Subclassers can override this to support different GraphUIs.- Overrides:
updateUIin classjavax.swing.JComponent- See Also:
JComponent.updateUI()
-
getUIClassID
public java.lang.String getUIClassID()
Returns the name of the L&F class that renders this component.- Overrides:
getUIClassIDin classjavax.swing.JComponent- Returns:
- the string "GraphUI"
- See Also:
JComponent.getUIClassID()
-
getRoots
public java.lang.Object[] getRoots()
Returns all root cells (cells that have no parent) that the model contains.
-
getRoots
public java.lang.Object[] getRoots(java.awt.Rectangle clip)
Returns all cells that intersect the given rectangle.
-
getDescendants
public java.lang.Object[] getDescendants(java.lang.Object[] cells)
Returns allcellsincluding all descendants in the passed in order of cells.
-
order
public java.lang.Object[] order(java.lang.Object[] cells)
Returns allcellsincluding all descendants ordered using the current layering data stored by the model.
-
cloneCells
public java.util.Map cloneCells(java.lang.Object[] cells)
Returns a map of (cell, clone)-pairs for allcellsand their children. Special care is taken to replace the anchor references between ports. (Iterative implementation.)
-
getTopmostViewAt
public CellView getTopmostViewAt(double x, double y, boolean reverse, boolean leafsOnly)
Returns the topmost cell view at the specified location using the view's bounds on non-leafs to check for containment. If reverse is true this will return the innermost view.
-
getFirstCellForLocation
public java.lang.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 marginy- 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 java.lang.Object getNextCellForLocation(java.lang.Object current, double x, double y)Returns the cell at the specified location that is "behind" thecurrentcell. Returns the topmost cell if there are no more cells behindcurrent. Note: This does only return visible cells.
-
getCellBounds
public java.awt.geom.Rectangle2D getCellBounds(java.lang.Object cell)
Returns the bounding rectangle of the specified cell.
-
getCellBounds
public java.awt.geom.Rectangle2D getCellBounds(java.lang.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.
Note: This returns the next selectable view.
Note: Arguments are not expected to be scaled (they are scaled in here).
-
getNextViewAt
public CellView getNextViewAt(CellView current, double x, double y, boolean leafsOnly)
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.
Note: This returns the next selectable view.
Note: Arguments are not expected to be scaled (they are scaled in here).
-
getNextSelectableViewAt
public CellView getNextSelectableViewAt(CellView current, double x, double y)
Note: Arguments are not expected to be scaled (they are scaled in here).
-
getNextViewAt
public CellView getNextViewAt(CellView[] cells, CellView c, double x, double y)
Returns the next view at the specified location wrt.cin the specified array of views. The views must be in order, as returned, for example, by GraphLayoutCache.order(Object[]).
-
getNextViewAt
public CellView getNextViewAt(CellView[] cells, CellView c, double x, double y, boolean leafsOnly)
Returns the next view at the specified location wrt.cin the specified array of views. The views must be in order, as returned, for example, by GraphLayoutCache.order(Object[]).
-
getLeafViewAt
public CellView getLeafViewAt(double x, double y)
Returns the next view at the specified location wrt.cin the specified array of views. The views must be in order, as returned, for example, by GraphLayoutCache.order(Object[]).
-
getPortForLocation
public java.lang.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.
Note: Arguments are not expected to be scaled (they are scaled in here).
-
getPortViewAt
public PortView getPortViewAt(double x, double y, int tolerance)
Returns the portview at the specified location.
Note: Arguments are not expected to be scaled (they are scaled in here).
-
getDefaultPortForCell
public PortView getDefaultPortForCell(java.lang.Object cell)
Returns the default portview for the specified cell. The default implementation returns the first floating port (ie. the first port that does not define an offset) or the port, if there is only one port.- Parameters:
cell- the cell whose port is to be obtained- Returns:
- the port view of the specified cell
-
convertValueToString
public java.lang.String convertValueToString(java.lang.Object value)
Converts the specified value to string. If the value is an instance of CellView then the corresponding value or cell is used.
-
snap
public java.awt.geom.Point2D snap(java.awt.geom.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 java.awt.geom.Rectangle2D snap(java.awt.geom.Rectangle2D r)
Returns the given rectangle applied to the grid.- Parameters:
r- a rectangle in screen coordinates.- Returns:
- the same rectangle applied to the grid.
-
snap
public java.awt.geom.Dimension2D snap(java.awt.geom.Dimension2D d)
Returns the given dimension applied to the grid.- Parameters:
d- a dimension in screen coordinates to snap to.- Returns:
- the same dimension applied to the grid.
-
toScreen
public java.awt.geom.Point2D toScreen(java.awt.geom.Point2D p)
Upscale the given point in place, using the given instance.- Parameters:
p- the point to be upscaled- Returns:
- the upscaled point instance
-
fromScreen
public java.awt.geom.Point2D fromScreen(java.awt.geom.Point2D p)
Downscale the given point in place, using the given instance.- Parameters:
p- the point to be downscaled- Returns:
- the downscaled point instance
-
toScreen
public java.awt.geom.Rectangle2D toScreen(java.awt.geom.Rectangle2D rect)
Upscale the given rectangle in place, using the given instance.- Parameters:
rect- the rectangle to be upscaled- Returns:
- the upscaled rectangle instance
-
fromScreen
public java.awt.geom.Rectangle2D fromScreen(java.awt.geom.Rectangle2D rect)
Downscale the given rectangle in place, using the given instance.- Parameters:
rect- the rectangle to be downscaled- Returns:
- the down-scaled rectangle instance
-
updateAutoSize
public void updateAutoSize(CellView view)
Computes and updates the size forview.
-
getAttributes
public AttributeMap getAttributes(java.lang.Object cell)
Returns the attributes for the specified cell. If the layout cache returns a view for the cell then this method returns allAttributes, otherwise the method returns model.getAttributes(cell).
-
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.
-
isXorEnabled
public boolean isXorEnabled()
Returns true if the graph accepts drops/pastes from external sources.
-
setXorEnabled
public void setXorEnabled(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.
-
setDisconnectOnMove
public void setDisconnectOnMove(boolean flag)
Sets if selected edges should be disconnected from unselected vertices when they are moved.
-
isDisconnectOnMove
public boolean isDisconnectOnMove()
Returns true if selected edges should be disconnected from unselected vertices when they are moved.
-
setJumpToDefaultPort
public void setJumpToDefaultPort(boolean flag)
Sets if getPortViewAt should return the default port if no other port is found.
-
isJumpToDefaultPort
public boolean isJumpToDefaultPort()
Returns true if getPortViewAt should return the default port if no other port is found.
-
setMoveIntoGroups
public void setMoveIntoGroups(boolean flag)
Specifies if cells should be added to groups when moved over the group's area.
-
isMoveIntoGroups
public boolean isMoveIntoGroups()
Returns true if cells should be added to groups when moved over the group's area.
-
setMoveOutOfGroups
public void setMoveOutOfGroups(boolean flag)
Specifies if cells should be removed from groups when removed from the group's area.
-
isMoveOutOfGroups
public boolean isMoveOutOfGroups()
Returns true if cells should be removed from groups when removed from the group's area.
-
isGridEnabled
public boolean isGridEnabled()
Returns true if the grid is active.- See Also:
snap(Point2D)
-
setGridEnabled
public void setGridEnabled(boolean flag)
If set to true, the grid will be active.- See Also:
snap(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 should auto resize when cells are being moved below the bottom right corner.
-
isMoveBeyondGraphBounds
public boolean isMoveBeyondGraphBounds()
- Returns:
- the moveBeyondGraphBounds
-
setMoveBeyondGraphBounds
public void setMoveBeyondGraphBounds(boolean moveBeyondGraphBounds)
- Parameters:
moveBeyondGraphBounds- the moveBeyondGraphBounds to set
-
getEdgeLabelsMovable
public boolean getEdgeLabelsMovable()
Returns true if edge labels may be dragged and dropped.- Returns:
- whether edge labels may be dragged and dropped
-
setEdgeLabelsMovable
public void setEdgeLabelsMovable(boolean edgeLabelsMovable)
Set if edge labels may be moved with the mouse or not.- Parameters:
edgeLabelsMovable- true if edge labels may be dragged
-
isAutoResizeGraph
public boolean isAutoResizeGraph()
Returns true if the graph should be automatically resized when cells are being moved below the bottom right corner. Note if the value ofmoveBeyondGraphBoundsiffalseauto resizing is automatically disabled
-
setAutoResizeGraph
public void setAutoResizeGraph(boolean autoResizeGraph)
Sets whether or not the graph should be automatically resize when cells are being moved below the bottom right corner
-
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 java.awt.Color getGridColor()
Returns the current grid color.
-
setGridColor
public void setGridColor(java.awt.Color newColor)
Sets the current grid color.
-
getHandleColor
public java.awt.Color getHandleColor()
Returns the current handle color.
-
setHandleColor
public void setHandleColor(java.awt.Color newColor)
Sets the current handle color.
-
getLockedHandleColor
public java.awt.Color getLockedHandleColor()
Returns the current second handle color.
-
setLockedHandleColor
public void setLockedHandleColor(java.awt.Color newColor)
Sets the current second handle color.
-
getMarqueeColor
public java.awt.Color getMarqueeColor()
Returns the current marquee color.
-
setMarqueeColor
public void setMarqueeColor(java.awt.Color newColor)
Sets the current marquee color.
-
getHighlightColor
public java.awt.Color getHighlightColor()
Returns the current highlight color.
-
setHighlightColor
public void setHighlightColor(java.awt.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
-
setScale
public void setScale(double newValue, java.awt.geom.Point2D center)Sets the current scale and centers the graph to the specified point- Parameters:
newValue- the new scalecenter- the center of the graph
-
clearOffscreen
public void clearOffscreen()
Invalidate the offscreen region, do not just delete it, since if the new region is smaller than the old you may not wish to re-create the buffer
-
getCenterPoint
public java.awt.geom.Point2D getCenterPoint()
Returns the center of the component relative to the parent viewport's position.
-
getViewPortBounds
public java.awt.geom.Rectangle2D getViewPortBounds()
Return the bounds of the parent viewport, if one exists. If one does not exist, null is returned- Returns:
- the bounds of the parent viewport
-
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 areDOT_GRID_MODE,CROSS_GRID_MODE, andLINE_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.
-
isPortsScaled
public boolean isPortsScaled()
Returns true if the ports will be scaled.- Returns:
- true if the ports are visible
-
setPortsScaled
public void setPortsScaled(boolean flag)
If set to true, the ports will be scaled.Fires a property change for the PORTS_SCALED_PROPERTY.
-
isPortsOnTop
public boolean isPortsOnTop()
-
setPortsOnTop
public void setPortsOnTop(boolean portsOnTop)
-
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 (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
-
isGroupsEditable
public boolean isGroupsEditable()
- Returns:
- the groupsEditable
-
setGroupsEditable
public void setGroupsEditable(boolean groupsEditable)
- Parameters:
groupsEditable- the groupsEditable to set
-
isSelectionEnabled
public boolean isSelectionEnabled()
Returns true if the cell selection is enabled- Returns:
- true if the cell selection is enabled
-
setSelectionEnabled
public void setSelectionEnabled(boolean flag)
Determines whether cell selection is enabled. Fires a property change event if the new setting is different from the existing setting.- Parameters:
flag- a boolean value, true if cell selection is enabled
-
isPreviewInvalidNullPorts
public boolean isPreviewInvalidNullPorts()
Returns true if graph allows invalid null ports during previews- Returns:
- true if the graph allows invalid null ports during previews
-
setPreviewInvalidNullPorts
public void setPreviewInvalidNullPorts(boolean flag)
Determines whether the graph allows invalid null ports during previews- Parameters:
flag- a boolean value, true if the graph allows invalid null ports during previews
-
getOffgraphics
public java.awt.Graphics getOffgraphics()
Returns the current double buffering graphics object. Checks to see if the graph bounds has changed since the last time the off screen image was created and if so, creates a new image.- Returns:
- the off screen graphics
-
createBufferedImage
protected void createBufferedImage(int width, int height)Utility method to create a standard buffered image- Parameters:
width-height-
-
setupOffScreen
protected void setupOffScreen(int x, int y, int width, int height, java.awt.geom.Rectangle2D newOffscreenBuffer)Utility method that initialises the offscreen graphics area- Parameters:
x-y-width-height-newOffscreenBuffer-
-
getOffscreen
public java.awt.Image getOffscreen()
- Returns:
- the offscreen
-
getOffscreenDirty
public java.awt.geom.Rectangle2D getOffscreenDirty()
Returns the area that is deemed dirty for the next double buffered redraw- Returns:
- the area that is deemed dirty for the next double buffered redraw
-
addOffscreenDirty
public void addOffscreenDirty(java.awt.geom.Rectangle2D offscreenDirty)
Adds the specified area to the region deemed dirty for the next double buffered redraw- Parameters:
offscreenDirty- the region to add
-
clearOffscreenDirty
public void clearOffscreenDirty()
Clears the region deemed dirty for the next double buffered redraw
-
releaseOffscreenResources
public void releaseOffscreenResources()
Schedules the offscreen resources taken by the offscreen buffer to be reclaimed. Note that this does not force garbage collection
-
drawImage
public boolean drawImage(int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2)Utility method to draw the off screen buffer- Parameters:
dx1- the x coordinate of the first corner of the destination rectangle.dy1- the y coordinate of the first corner of the destination rectangle.dx2- the x coordinate of the second corner of the destination rectangle.dy2- the y coordinate of the second corner of the destination rectangle.sx1- the x coordinate of the first corner of the source rectangle.sy1- the y coordinate of the first corner of the source rectangle.sx2- the x coordinate of the second corner of the source rectangle.sy2- the y coordinate of the second corner of the source rectangle.- Returns:
trueif the current output representation is complete;falseotherwise.
-
drawImage
public boolean drawImage(java.awt.Graphics g)
-
getBackgroundImage
public javax.swing.ImageIcon getBackgroundImage()
Returns the background image.- Returns:
- Returns the backgroundImage.
-
setBackgroundImage
public void setBackgroundImage(javax.swing.ImageIcon backgroundImage)
Sets the background image. Fires a property change event forPROPERTY_BACKGROUNDIMAGE.- Parameters:
backgroundImage- The backgroundImage to set.
-
setBackground
public void setBackground(java.awt.Color bg)
Override parent to clear offscreen double buffer- Overrides:
setBackgroundin classjavax.swing.JComponent
-
isBackgroundScaled
public boolean isBackgroundScaled()
- Returns:
- the backgroundScaled
-
getOffscreenOffset
public java.awt.geom.Point2D getOffscreenOffset()
- Returns:
- the offscreenOffset
-
setOffscreenOffset
public void setOffscreenOffset(java.awt.geom.Point2D offscreenOffset)
- Parameters:
offscreenOffset- the offscreenOffset to set
-
isVolatileOffscreen
public boolean isVolatileOffscreen()
- Returns:
- the volatileOffscreen
-
setVolatileOffscreen
public void setVolatileOffscreen(boolean volatileOffscreen)
- Parameters:
volatileOffscreen- the volatileOffscreen to set
-
setBackgroundScaled
public void setBackgroundScaled(boolean backgroundScaled)
- Parameters:
backgroundScaled- the backgroundScaled to set
-
getBackgroundComponent
public java.awt.Component getBackgroundComponent()
- Returns:
- the backgroundComponent
-
setBackgroundComponent
public void setBackgroundComponent(java.awt.Component backgroundComponent)
- Parameters:
backgroundComponent- the backgroundComponent to set
-
setOpaque
public void setOpaque(boolean opaque)
- Overrides:
setOpaquein classjavax.swing.JComponent
-
getModel
public GraphModel getModel()
Returns theGraphModelthat is providing the data.- Returns:
- the model that is providing the data
-
setModel
public void setModel(GraphModel newModel)
Sets theGraphModelthat 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- theGraphModelthat is to provide the data
-
getGraphLayoutCache
public GraphLayoutCache getGraphLayoutCache()
Returns theGraphLayoutCachethat is providing the view-data.- Returns:
- the view that is providing the view-data
-
setGraphLayoutCache
public void setGraphLayoutCache(GraphLayoutCache newLayoutCache)
Sets theGraphLayoutCachethat will provide the view-data.Note: Updates the graphs's model using using the model from the layout cache.
Fires a property change for the GRAPH_LAYOUT_CACHE_PROPERTY.
- Parameters:
newLayoutCache- theGraphLayoutCachethat is to provide the view-data
-
getMarqueeHandler
public BasicMarqueeHandler getMarqueeHandler()
Returns theMarqueeHandlerthat will handle marquee selection.
-
setMarqueeHandler
public void setMarqueeHandler(BasicMarqueeHandler newMarquee)
Sets theMarqueeHandlerthat will handle marquee selection.- Parameters:
newMarquee- theBasicMarqueeHandlerthat is to provide marquee handling
-
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 totruecauses 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 thatstopCellEditingis invoked when editing is interruped, and data is saved; false means thatcancelCellEditingis 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(java.lang.Object cell)
Returnstrueif the graph and the cell are editable. This is invoked from the UI before editing begins to ensure that the given cell can be edited.- Returns:
- true if the specified cell is editable
- See Also:
isEditable()
-
getToolTipText
public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
OverridesJComponent'sgetToolTipTextmethod 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
JGraphto properly display tooltips of its renderers,JGraphmust be a registered component with theToolTipManager. This can be done by invokingToolTipManager.sharedInstance().registerComponent(graph). This is not done automatically!- Overrides:
getToolTipTextin classjavax.swing.JComponent- Parameters:
e- theMouseEventthat initiated theToolTipdisplay- Returns:
- a string containing the tooltip or
nullifeventis null
-
setSelectionModel
public void setSelectionModel(GraphSelectionModel selectionModel)
Sets the graph's selection model. When anullvalue is specified an emtpyselectionModelis used, which does not allow selections.- Parameters:
selectionModel- theGraphSelectionModelto use, ornullto disable selections- See Also:
GraphSelectionModel
-
getSelectionModel
public GraphSelectionModel getSelectionModel()
Returns the model for selections. This should always return a non-nullvalue. If you don't want to allow anything to be selected set the selection model tonull, 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 forGraphSelectionevents.- Parameters:
tsl- theGraphSelectionListenerthat will be notified when a cell is selected or deselected (a "negative selection")
-
removeGraphSelectionListener
public void removeGraphSelectionListener(GraphSelectionListener tsl)
Removes aGraphSelectionlistener.- Parameters:
tsl- theGraphSelectionListenerto 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- theGraphSelectionEventgenerated by theGraphSelectionModelwhen a cell is selected or deselected- See Also:
EventListenerList
-
setSelectionCell
public void setSelectionCell(java.lang.Object cell)
Selects the specified cell.- Parameters:
cell- theObjectspecifying the cell to select
-
setSelectionCells
public void setSelectionCells(java.lang.Object[] cells)
Selects the specified cells.- Parameters:
cells- an array of objects that specifies the cells to select
-
addSelectionCell
public void addSelectionCell(java.lang.Object cell)
Adds the cell identified by the specifiedObjectto the current selection.- Parameters:
cell- the cell to be added to the selection
-
addSelectionCells
public void addSelectionCells(java.lang.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(java.lang.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 java.lang.Object getSelectionCell()
Returns the first selected cell.- Returns:
- the
Objectfor the first selected cell, ornullif nothing is currently selected
-
getSelectionCells
public java.lang.Object[] getSelectionCells()
Returns all selected cells.- Returns:
- an array of objects representing the selected cells, or
nullif nothing is currently selected
-
getSelectionCells
public java.lang.Object[] getSelectionCells(java.lang.Object[] cells)
Returns all selected cells incells.
-
getSelectionCellAt
public java.lang.Object getSelectionCellAt(java.awt.geom.Point2D pt)
Returns the selection cell at the specified location.- Returns:
- Returns the selection cell for
pt.
-
getSelectionCount
public int getSelectionCount()
Returns the number of cells selected.- Returns:
- the number of cells selected
-
isCellSelected
public boolean isCellSelected(java.lang.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(java.lang.Object cell)
Scrolls to the specified cell. Only works when thisJGraphis contained in aJScrollPane.- Parameters:
cell- the object identifying the cell to bring into view
-
scrollPointToVisible
public void scrollPointToVisible(java.awt.geom.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 usinggetEditingCell.- Returns:
- true if the user is currently editing a cell
- See Also:
getSelectionCell()
-
stopEditing
public boolean stopEditing()
Ends the current editing session. (TheDefaultGraphCellEditorobject 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, usesetInvokesStopCellEditing(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(java.lang.Object cell)
Selects the specified cell and initiates editing. The edit-attempt fails if theCellEditordoes not allow editing for the specified item.
-
getEditingCell
public java.lang.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.)
-
refresh
public void refresh()
Repaints the entire graph, regardless of what is marked dirty
-
getImage
public java.awt.image.BufferedImage getImage(java.awt.Color bg, int inset)Returns aBufferedImagefor the graph using inset as an empty border around the cells of the graph. If bg is null then a transparent background is applied to the image, else the background is filled with the bg color. Therefore, one should only use a null background if the fileformat support transparency, eg. GIF and PNG. For JPG, you can useColor.WHITEfor example.- Returns:
- Returns an image of the graph.
-
getClipRectangle
public java.awt.geom.Rectangle2D getClipRectangle(GraphLayoutCacheEvent.GraphLayoutCacheChange change)
Calculates the clip- Parameters:
change-- Returns:
- the total region dirty as a result of this change
-
getPreferredScrollableViewportSize
public java.awt.Dimension getPreferredScrollableViewportSize()
Returns the preferred display size of aJGraph. The height is determined fromgetPreferredWidth.- Specified by:
getPreferredScrollableViewportSizein interfacejavax.swing.Scrollable- Returns:
- the graph's preferred size
-
getScrollableUnitIncrement
public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)Returns the amount to increment when scrolling. The amount is 4.- Specified by:
getScrollableUnitIncrementin interfacejavax.swing.Scrollable- Parameters:
visibleRect- the view area visible within the viewportorientation- eitherSwingConstants.VERTICALorSwingConstants.HORIZONTALdirection- 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(java.awt.Rectangle visibleRect, int orientation, int direction)Returns the amount for a block increment, which is the height or width ofvisibleRect, based onorientation.- Specified by:
getScrollableBlockIncrementin interfacejavax.swing.Scrollable- Parameters:
visibleRect- the view area visible within the viewportorientation- eitherSwingConstants.VERTICALorSwingConstants.HORIZONTALdirection- 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:
getScrollableTracksViewportWidthin interfacejavax.swing.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:
getScrollableTracksViewportHeightin interfacejavax.swing.Scrollable- Returns:
- false
- See Also:
Scrollable.getScrollableTracksViewportHeight()
-
paramString
protected java.lang.String paramString()
Returns a string representation of thisJGraph. 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 benull.- Overrides:
paramStringin classjavax.swing.JComponent- Returns:
- a string representation of this
JGraph.
-
main
public static void main(java.lang.String[] args)
-
-