Package org.jgraph.plaf.basic
Class BasicGraphUI
java.lang.Object
javax.swing.plaf.ComponentUI
org.jgraph.plaf.GraphUI
org.jgraph.plaf.basic.BasicGraphUI
- All Implemented Interfaces:
Serializable
The basic L&F for a graph data structure.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassListener responsible for getting cell editing events and updating the graph accordingly.classUpdates the preferred size when scrolling (if necessary).classGraph Drop Target ListenerclassGraphIncrementAction is used to handle up/down actions.classListens for changes in the graph view and updates the size accordingly.classListens for changes in the graph model and updates the view accordingly.classListens for changes in the selection model and updates the display accordingly.classThis is used to get mutliple key down events to appropriately generate events.classTreeMouseListener is responsible for updating the selection based on mouse events.classMouseInputHandler handles passing all mouse events, including mouse motion events, until the mouse is released to the destination it is constructed with.classPropertyChangeListener for the graph.class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected GraphCellEditorCurrent editor for the graph.protected CellEditorListenerListens for CellEditor events.protected ComponentListenerListens for Component events.protected BasicGraphUI.GraphDropTargetListenerThe default DropTargetListener.protected TransferHandlerThe default TransferHandler.static final booleanControls live-preview in dragEnabled mode.protected intNeeded to exchange information between DropTargetHandler and TransferHandler.protected DropTargetThe drop target where the default listener was last installed.protected ObjectPath that is being edited.protected ComponentWhen editing, this will be the Component that is doing the actual editing.protected booleanSet to true if the editor has a different size than the renderer.protected CellViewThe focused cell under the mousepointer and the last focused cell.protected JGraphComponent that we're going to be drawing into.protected GraphLayoutCacheReference to the graph's view (geometric pattern).protected GraphLayoutCacheListenerUpdates the display when the view has changed.protected GraphModelUsed to determine what to display.protected GraphModelListenerIs responsible for updating the view based on model events.protected GraphSelectionListenerUpdates the display when the selection changes.protected GraphSelectionModelModel maintaining the selection.protected CellHandleHandle that we are going to use.protected PointNeeded to exchange information between Transfer- and MouseListener.protected KeyListenerListens for KeyListener events.protected CellViewThe focused cell under the mousepointer and the last focused cell.protected BasicMarqueeHandlerMarquee that we are going to use.static intThe maximum number of cells to paint when dragging.static intMaximum number of cells to compute clipping bounds for.static intThe maximum number of handles to paint individually.protected MouseListenerListens for Mouse events.protected DimensionMinimum preferred size.protected DimensionSize needed to completely display all the cells.protected PropertyChangeListenerListens for JGraph property changes and updates display.protected CellRendererPaneUsed to paint the CellRenderer.static intBorder in pixels to scroll if marquee or dragging are active.static floatMultiplicator for width and height when autoscrolling (=stepsize).protected booleanIf ture, a the view under mousepointer will be snapped to the grid lines during a drag operation.protected booleanSet to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing.protected booleanIs the preferredSize valid? -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidautoscroll(JGraph graph, Point p) Scroll the graph for an event atp.voidcancelEditing(JGraph graph) Cancels all current editing sessions.protected voidMessages to stop the editing session.protected voidcompleteEditing(boolean messageStop, boolean messageCancel, boolean messageGraph) Stops the editing session.protected voidInvoked from installUI after all the defaults/listeners have been installed.protected voidprotected CellEditorListenerCreates a listener to handle events from the current editor.protected CellRendererPaneReturns the renderer pane that renderer components are placed in.protected ComponentListenerCreates and returns a new ComponentHandler.protected GraphContextcreateContext(JGraph graph, Object[] cells) protected GraphLayoutCacheListenerReturns a listener that can update the graph when the view changes.protected GraphModelListenerReturns a listener that can update the graph when the model changes.protected GraphSelectionListenerCreates the listener that updates the display based on selection change methods.createHandle(GraphContext context) Constructs the "root handle" forcontext.protected KeyListenerCreates the listener reponsible for getting key events from the graph.protected MouseListenerCreates the listener responsible for calling the correct handlers based on mouse events, and to select invidual cells.protected PropertyChangeListenerCreates a listener that is responsible to update the UI based on how the graph's bounds properties change.protected TransferHandlerCreates an instance of TransferHandler.static ComponentUIvoiddrawGraph(Graphics g, Rectangle2D clipBounds) Draws the graph to the specified graphics object within the specified clip bounds, if anyintReturns the current drop action.getEditingCell(JGraph graph) Returns the element that is being edited.protected Point2DgetEditorLocation(Object cell, Dimension2D editorSize, Point2D pt) Subclassers may override this to provide a better location for the in-place editing of edges (if you do not inherit from the EdgeRenderer class).protected ObjectReturns the cell that has the focus.Returns the handle that is currently active, or null, if no handle is currently active.Returns the current location of the Drag-and-Drop activity.Returns the maximum size for this component, which will be the preferred size if the instance is currently in a JGraph, or 0, 0.Returns the minimum size for this component.Returns the minimum preferred size.Returns the preferred size to properly display the graph.getPreferredSize(JGraph graph, CellView view) Get the preferred Size for a cell view.protected voidIntalls the subcomponents of the graph, which is the renderer pane.protected voidInvoked as part from the boilerplate install block.protected voidInvoked as part from the boilerplate install block.protected voidInvoked as part from the boilerplate install block.voidbooleanReturning true signifies that cells are added to the selection.booleanisConstrainedMoveEvent(MouseEvent event) Returning true signifies a move should only be applied to one direction.booleanReturns true if the graph is being edited.booleanisForceMarqueeEvent(MouseEvent event) Returning true signifies the marquee handler has precedence over other handlers, and is receiving subsequent mouse events.booleanbooleanReturning true signifies a mouse event on the cell should toggle the selection of only the cell under mouse.voidpaint(Graphics g, JComponent c) Main painting routine.protected voidPaint the background of this graph.protected voidpaintBackgroundComponent(Graphics g, Component component) Requests that the component responsible for painting the background paint itselfprotected voidpaintBackgroundComponent(Graphics g, Component component, Rectangle clip) Requests that the component responsible for painting the background paint itselfprotected voidpaintBackgroundImage(Graphics g, Rectangle clip) Hook for subclassers to paint the background image.voidpaintCell(Graphics g, CellView view, Rectangle2D bounds, boolean preview) Paints the renderer ofviewtogatbounds.protected voidpaintCells(Graphics g, Rectangle2D realClipBounds) Hook method to allow subclassers to alter just the cell painting functionalityprotected voidPaint the foreground of this graph.protected voidpaintGrid(double gs, Graphics g, Rectangle2D clipBounds) Paint the grid.protected voidHook method to paints the overlayvoidpaintPorts(Graphics g, CellView[] ports) Paintports.protected voidInvoked after thegraphinstance variable has been set, but before any defaults/listeners have been installed.voidselectCellForEvent(Object cell, MouseEvent event) Messaged to update the selection based on a MouseEvent over a particular cell.voidselectCellsForEvent(Object[] cells, MouseEvent event) Messaged to update the selection based on a MouseEvent for a group of cells.voidselectCellsForEvent(JGraph graph, Object[] cells, MouseEvent event) From GraphUI interface.protected voidSets the GraphLayoutCache (geometric pattern).voidSets the current location for Drag-and-Drop activity.protected voidsetMarquee(BasicMarqueeHandler marqueeHandler) Sets the marquee handler.protected voidsetModel(GraphModel model) Sets the GraphModel.voidsetPreferredMinSize(Dimension newSize) Sets the preferred minimum size.protected voidsetSelectionModel(GraphSelectionModel newLSM) Resets the selection model.voidsetSnapSelectedView(boolean snapSelectedView) Sets the mode of the snapSelectedView drag operation.protected booleanstartEditing(Object cell, MouseEvent event) Will start editing for cell if there is a cellEditor and shouldSelectCell returns true.voidstartEditingAtCell(JGraph graph, Object cell) Selects the cell and tries to edit it.booleanstopEditing(JGraph graph) Stops the current editing session.protected voidtoggleSelectionCellForEvent(Object cell, MouseEvent event) Messaged to update the selection based on a toggle selection event, which means the cell's selection state is inverted.protected voidUninstalls the renderer pane.protected voidprotected voidvoidprotected voidUpdates thepreferredSizeinstance variable, which is returned fromgetPreferredSize().voidUpdate the handle using createHandle.voidMessages the Graph withgraphDidChange.Methods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, update
-
Field Details
-
DNDPREVIEW
public static final boolean DNDPREVIEWControls live-preview in dragEnabled mode. This is used to disable live-preview in dragEnabled mode on Java 1.4.0 to workaround a bug that cause the VM to hang during concurrent DnD and repaints. Is this still required? -
SCROLLBORDER
public static int SCROLLBORDERBorder in pixels to scroll if marquee or dragging are active. -
SCROLLSTEP
public static float SCROLLSTEPMultiplicator for width and height when autoscrolling (=stepsize). -
MAXCELLS
public static int MAXCELLSThe maximum number of cells to paint when dragging. -
MAXHANDLES
public static int MAXHANDLESThe maximum number of handles to paint individually. -
MAXCLIPCELLS
public static int MAXCLIPCELLSMaximum number of cells to compute clipping bounds for. -
preferredMinSize
Minimum preferred size. -
graph
Component that we're going to be drawing into. -
graphLayoutCache
Reference to the graph's view (geometric pattern). -
cellEditor
Current editor for the graph. -
stopEditingInCompleteEditing
protected boolean stopEditingInCompleteEditingSet to false when editing and shouldSelectCell() returns true meaning the node should be selected before editing, used in completeEditing. -
rendererPane
Used to paint the CellRenderer. -
preferredSize
Size needed to completely display all the cells. -
validCachedPreferredSize
protected boolean validCachedPreferredSizeIs the preferredSize valid? -
graphModel
Used to determine what to display. -
graphSelectionModel
Model maintaining the selection. -
handle
Handle that we are going to use. -
marquee
Marquee that we are going to use. -
editingComponent
When editing, this will be the Component that is doing the actual editing. -
focus
The focused cell under the mousepointer and the last focused cell. -
lastFocus
The focused cell under the mousepointer and the last focused cell. -
editingCell
Path that is being edited. -
editorHasDifferentSize
protected boolean editorHasDifferentSizeSet to true if the editor has a different size than the renderer. -
insertionLocation
Needed to exchange information between Transfer- and MouseListener. -
dropAction
protected int dropActionNeeded to exchange information between DropTargetHandler and TransferHandler. -
snapSelectedView
protected boolean snapSelectedViewIf ture, a the view under mousepointer will be snapped to the grid lines during a drag operation. If snap-to-grid mode is disabled, views are moved by a snap increment. -
propertyChangeListener
Listens for JGraph property changes and updates display. -
mouseListener
Listens for Mouse events. -
keyListener
Listens for KeyListener events. -
componentListener
Listens for Component events. -
cellEditorListener
Listens for CellEditor events. -
graphSelectionListener
Updates the display when the selection changes. -
graphModelListener
Is responsible for updating the view based on model events. -
graphLayoutCacheListener
Updates the display when the view has changed. -
defaultTransferHandler
The default TransferHandler. -
defaultDropTargetListener
The default DropTargetListener. -
dropTarget
The drop target where the default listener was last installed.
-
-
Constructor Details
-
BasicGraphUI
public BasicGraphUI()
-
-
Method Details
-
createUI
-
setModel
Sets the GraphModel. This invokesupdateSize. -
setGraphLayoutCache
Sets the GraphLayoutCache (geometric pattern). This invokesupdateSize. -
setMarquee
Sets the marquee handler. -
setSelectionModel
Resets the selection model. The appropriate listeners are installed on the model. -
getHandle
Returns the handle that is currently active, or null, if no handle is currently active. Typically, the returned objects are instances of the RootHandle inner class. -
getDropAction
public int getDropAction()Returns the current drop action.- Specified by:
getDropActionin classGraphUI
-
getFocusedCell
Returns the cell that has the focus. -
getPreferredSize
Get the preferred Size for a cell view.- Specified by:
getPreferredSizein classGraphUI
-
getInsertionLocation
Returns the current location of the Drag-and-Drop activity.- Specified by:
getInsertionLocationin classGraphUI
-
setInsertionLocation
Sets the current location for Drag-and-Drop activity. Should be set to null after a drop. Used from within DropTargetListener.- Specified by:
setInsertionLocationin classGraphUI
-
selectCellsForEvent
From GraphUI interface.- Specified by:
selectCellsForEventin classGraphUI
-
selectCellsForEvent
Messaged to update the selection based on a MouseEvent for a group of cells. If the event is a toggle selection event, the cells are either selected, or deselected. Otherwise the cells are selected. -
selectCellForEvent
Messaged to update the selection based on a MouseEvent over a particular cell. If the event is a toggle selection event, the cell is either selected, or deselected. Otherwise the cell is selected. -
toggleSelectionCellForEvent
Messaged to update the selection based on a toggle selection event, which means the cell's selection state is inverted. -
isAddToSelectionEvent
Returning true signifies that cells are added to the selection. -
isToggleSelectionEvent
Returning true signifies a mouse event on the cell should toggle the selection of only the cell under mouse. -
isForceMarqueeEvent
Returning true signifies the marquee handler has precedence over other handlers, and is receiving subsequent mouse events. -
isConstrainedMoveEvent
Returning true signifies a move should only be applied to one direction. -
isEditing
Returns true if the graph is being edited. The item that is being edited can be returned by getEditingPath(). -
stopEditing
Stops the current editing session. This has no effect if the graph isn't being edited. Returns true if the editor allows the editing session to stop.- Specified by:
stopEditingin classGraphUI
-
cancelEditing
Cancels all current editing sessions.- Specified by:
cancelEditingin classGraphUI
-
startEditingAtCell
Selects the cell and tries to edit it. Editing will fail if the CellEditor won't allow it for the selected item.- Specified by:
startEditingAtCellin classGraphUI
-
getEditingCell
Returns the element that is being edited.- Specified by:
getEditingCellin classGraphUI
-
installUI
- Overrides:
installUIin classComponentUI
-
prepareForUIInstall
protected void prepareForUIInstall()Invoked after thegraphinstance variable has been set, but before any defaults/listeners have been installed. -
completeUIInstall
protected void completeUIInstall()Invoked from installUI after all the defaults/listeners have been installed. -
installDefaults
protected void installDefaults()Invoked as part from the boilerplate install block. This sets the look and feel specific variables in JGraph. -
installListeners
protected void installListeners()Invoked as part from the boilerplate install block. This installs the listeners from BasicGraphUI in the graph. -
installKeyboardActions
protected void installKeyboardActions()Invoked as part from the boilerplate install block. -
installComponents
protected void installComponents()Intalls the subcomponents of the graph, which is the renderer pane. -
createTransferHandler
Creates an instance of TransferHandler. Used for subclassers to provide different TransferHandler. -
createPropertyChangeListener
Creates a listener that is responsible to update the UI based on how the graph's bounds properties change. -
createMouseListener
Creates the listener responsible for calling the correct handlers based on mouse events, and to select invidual cells. -
createKeyListener
Creates the listener reponsible for getting key events from the graph. -
createGraphSelectionListener
Creates the listener that updates the display based on selection change methods. -
createCellEditorListener
Creates a listener to handle events from the current editor. -
createComponentListener
Creates and returns a new ComponentHandler. -
createCellRendererPane
Returns the renderer pane that renderer components are placed in. -
createGraphLayoutCacheListener
Returns a listener that can update the graph when the view changes. -
createGraphModelListener
Returns a listener that can update the graph when the model changes. -
uninstallUI
- Overrides:
uninstallUIin classComponentUI
-
completeUIUninstall
protected void completeUIUninstall() -
uninstallListeners
protected void uninstallListeners() -
uninstallKeyboardActions
protected void uninstallKeyboardActions() -
uninstallComponents
protected void uninstallComponents()Uninstalls the renderer pane. -
paint
Main painting routine.- Overrides:
paintin classComponentUI
-
paintOverlay
Hook method to paints the overlay- Parameters:
g- the graphics object to paint the overlay to
-
drawGraph
Draws the graph to the specified graphics object within the specified clip bounds, if any- Parameters:
g- the graphics object to draw the graph toclipBounds- the bounds within graph cells must intersect to be redrawn
-
paintCells
Hook method to allow subclassers to alter just the cell painting functionality- Parameters:
g- the graphics object to paint torealClipBounds- the bounds of the region being repainted
-
paintCell
Paints the renderer ofviewtogatbounds. Recursive implementation that paints the children first.The reciever should NOT modify
clipBounds, orinsets. Thepreviewflag is passed to the renderer, and is not used here. -
paintBackground
Paint the background of this graph. Calls paintGrid. -
paintBackgroundImage
Hook for subclassers to paint the background image.- Parameters:
g- The graphics object to paint the image on.clip- The clipping region to draw into
-
paintBackgroundComponent
Requests that the component responsible for painting the background paint itself- Parameters:
g- The graphics object to paint the image on.component- the component to be painted onto the background image
-
paintBackgroundComponent
Requests that the component responsible for painting the background paint itself- Parameters:
g- The graphics object to paint the image on.component- the component to be painted onto the background imageclip- The clipping region to draw into
-
paintGrid
Paint the grid. -
paintForeground
Paint the foreground of this graph. Calls paintPorts. -
paintPorts
Paintports.- Specified by:
paintPortsin classGraphUI
-
updateHandle
public void updateHandle()Update the handle using createHandle.- Specified by:
updateHandlein classGraphUI
-
createContext
-
createHandle
Constructs the "root handle" forcontext.- Parameters:
context- reference to the context of the current selection.
-
updateSize
public void updateSize()Messages the Graph withgraphDidChange. -
updateCachedPreferredSize
protected void updateCachedPreferredSize()Updates thepreferredSizeinstance variable, which is returned fromgetPreferredSize(). -
setPreferredMinSize
Sets the preferred minimum size. -
getPreferredMinSize
Returns the minimum preferred size. -
getPreferredSize
Returns the preferred size to properly display the graph.- Overrides:
getPreferredSizein classComponentUI
-
getMinimumSize
Returns the minimum size for this component. Which will be the min preferred size or 0, 0.- Overrides:
getMinimumSizein classComponentUI
-
getMaximumSize
Returns the maximum size for this component, which will be the preferred size if the instance is currently in a JGraph, or 0, 0.- Overrides:
getMaximumSizein classComponentUI
-
completeEditing
protected void completeEditing()Messages to stop the editing session. If the UI the receiver is providing the look and feel for returns true fromgetInvokesStopCellEditing, stopCellEditing will invoked on the current editor. Then completeEditing will be messaged with false, true, false to cancel any lingering editing. -
completeEditing
protected void completeEditing(boolean messageStop, boolean messageCancel, boolean messageGraph) Stops the editing session. If messageStop is true the editor is messaged with stopEditing, if messageCancel is true the editor is messaged with cancelEditing. If messageGraph is true the graphModel is messaged with valueForCellChanged. -
startEditing
Will start editing for cell if there is a cellEditor and shouldSelectCell returns true.This assumes that cell is valid and visible.
-
getEditorLocation
Subclassers may override this to provide a better location for the in-place editing of edges (if you do not inherit from the EdgeRenderer class). -
autoscroll
Scroll the graph for an event atp. -
isSnapSelectedView
public boolean isSnapSelectedView()- Returns:
- true if snapSelectedView mode is enabled during the drag
operation. If it is enabled, the view, that is returned by the
findViewForPoint(Point pt), will be snapped to the grid lines.
By default, findViewForPoint() returns the first view from the GraphContext whose bounds intersect with snap proximity of a mouse pointer. If snap-to-grid mode is disabled, views are moved by a snap increment.
-
setSnapSelectedView
public void setSnapSelectedView(boolean snapSelectedView) Sets the mode of the snapSelectedView drag operation.- Parameters:
snapSelectedView- specifies if the snap-to-grid mode should be applied during a drag operation. If it is enabled, the view, that is returned by the findViewForPoint(Point pt), will be snapped to the grid lines.
By default, findViewForPoint() returns the first view from the GraphContext whose bounds intersect with snap proximity of a mouse pointer. If snap-to-grid mode is disabled, views are moved by a snap increment.
-