org.graphstream.ui.swingViewer
Class DefaultView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.graphstream.ui.swingViewer.View
                      extended by org.graphstream.ui.swingViewer.DefaultView
All Implemented Interfaces:
WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class DefaultView
extends View
implements WindowListener

Base for constructing views.

This base view is an abstract class that provides mechanism that are necessary in any view :

This view also handle a current selection of nodes and sprites.

The painting mechanism

The main method to implement is render(Graphics2D). This method is called each time the graph needs to be rendered anew in the canvas.

The render(Graphics2D) is called only when a repainting is really needed.

All the painting, by default, is deferred to a GraphRenderer instance. This mechanism allows developers that do not want to mess with the viewer/view mechanisms to render a graph in any Swing surface.

The optional frame handling

This abstract view is able to create a frame that is added around this panel (each view is a JPanel instance). The frame can be removed at any time.

The frame closing protocol

This abstract view handles the closing protocol. This means that it will close the view if needed, or only hide it to allow reopening it later. Furthermore it adds the "ui.viewClosed" attribute to the graph when the view is closed or hidden, and removes it when the view is shown. The value of this graph attribute is the identifier of the view.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DefaultView(Viewer viewer, String identifier, GraphRenderer renderer)
           
 
Method Summary
 ArrayList<GraphicElement> allNodesOrSpritesIn(double x1, double y1, double x2, double y2)
          Search for all the nodes and sprites contained inside the rectangle (x1,y1)-(x2,y2).
 void beginSelectionAt(double x1, double y1)
          Called by the mouse manager to specify where a node and sprite selection started.
 void close(GraphicGraph graph)
          Close definitively this view.
 void display(GraphicGraph graph, boolean graphChanged)
          Redisplay or update the view contents.
 void endSelectionAt(double x2, double y2)
          Called by the mouse manager to specify where a node and spite selection stopped.
 GraphicElement findNodeOrSpriteAt(double x, double y)
          Search for the first node or sprite (in that order) that contains the point at coordinates (x, y).
 void freezeElement(GraphicElement element, boolean frozen)
          Freeze an element so that the optional layout cannot move it.
 Camera getCamera()
          Get a camera object to provide control commands on the view.
 void moveElementAtPx(GraphicElement element, double x, double y)
          Force an element to move at the given location in pixels.
 void openInAFrame(boolean on)
          Open this view JPanel in a frame.
 void paintComponent(Graphics g)
           
 void render(Graphics2D g)
           
 void resizeFrame(int width, int height)
          Set the size of the view frame, if any.
 void selectionGrowsAt(double x, double y)
          The selection already started grows toward position (x, y).
 void setBackLayerRenderer(LayerRenderer renderer)
          Set a layer renderer that will be called each time the graph needs to be redrawn before the graph is rendered.
 void setForeLayoutRenderer(LayerRenderer renderer)
          Set a layer renderer that will be called each time the graph needs to be redrawn after the graph is rendered.
 void setMouseManager(MouseManager manager)
          Change the manager for mouse events on this view.
 void setShortcutManager(ShortcutManager manager)
          Change the manager for key and shortcuts events on this view.
 void windowActivated(WindowEvent e)
           
 void windowClosed(WindowEvent e)
           
 void windowClosing(WindowEvent e)
           
 void windowDeactivated(WindowEvent e)
           
 void windowDeiconified(WindowEvent e)
           
 void windowIconified(WindowEvent e)
           
 void windowOpened(WindowEvent e)
           
 
Methods inherited from class org.graphstream.ui.swingViewer.View
getId
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultView

public DefaultView(Viewer viewer,
                   String identifier,
                   GraphRenderer renderer)
Method Detail

getCamera

public Camera getCamera()
Description copied from class: View
Get a camera object to provide control commands on the view.

Specified by:
getCamera in class View
Returns:
a Camera instance

display

public void display(GraphicGraph graph,
                    boolean graphChanged)
Description copied from class: View
Redisplay or update the view contents. Called by the Viewer.

Specified by:
display in class View
Parameters:
graph - The graphic graph to represent.
graphChanged - True if the graph changed since the last call to this method.

paintComponent

public void paintComponent(Graphics g)
Overrides:
paintComponent in class JComponent

close

public void close(GraphicGraph graph)
Description copied from class: View
Close definitively this view. Called by the Viewer.

Specified by:
close in class View
Parameters:
graph - The graphic graph.

resizeFrame

public void resizeFrame(int width,
                        int height)
Description copied from class: View
Set the size of the view frame, if any. If this view has been open in a frame, this changes the size of the frame containing it.

Specified by:
resizeFrame in class View
Parameters:
width - The new width.
height - The new height.

openInAFrame

public void openInAFrame(boolean on)
Description copied from class: View
Open this view JPanel in a frame. The argument allows to put the panel in a new frame or to remove it from the frame (if it already exists). Called by the Viewer.

Specified by:
openInAFrame in class View
Parameters:
on - Add the panel in its own frame or remove it if it already was in its own frame.

render

public void render(Graphics2D g)

beginSelectionAt

public void beginSelectionAt(double x1,
                             double y1)
Description copied from class: View
Called by the mouse manager to specify where a node and sprite selection started.

Specified by:
beginSelectionAt in class View
Parameters:
x1 - The selection start abscissa.
y1 - The selection start ordinate.

selectionGrowsAt

public void selectionGrowsAt(double x,
                             double y)
Description copied from class: View
The selection already started grows toward position (x, y).

Specified by:
selectionGrowsAt in class View
Parameters:
x - The new end selection abscissa.
y - The new end selection ordinate.

endSelectionAt

public void endSelectionAt(double x2,
                           double y2)
Description copied from class: View
Called by the mouse manager to specify where a node and spite selection stopped.

Specified by:
endSelectionAt in class View
Parameters:
x2 - The selection stop abscissa.
y2 - The selection stop ordinate.

windowActivated

public void windowActivated(WindowEvent e)
Specified by:
windowActivated in interface WindowListener

windowClosed

public void windowClosed(WindowEvent e)
Specified by:
windowClosed in interface WindowListener

windowClosing

public void windowClosing(WindowEvent e)
Specified by:
windowClosing in interface WindowListener

windowDeactivated

public void windowDeactivated(WindowEvent e)
Specified by:
windowDeactivated in interface WindowListener

windowDeiconified

public void windowDeiconified(WindowEvent e)
Specified by:
windowDeiconified in interface WindowListener

windowIconified

public void windowIconified(WindowEvent e)
Specified by:
windowIconified in interface WindowListener

windowOpened

public void windowOpened(WindowEvent e)
Specified by:
windowOpened in interface WindowListener

allNodesOrSpritesIn

public ArrayList<GraphicElement> allNodesOrSpritesIn(double x1,
                                                     double y1,
                                                     double x2,
                                                     double y2)
Description copied from class: View
Search for all the nodes and sprites contained inside the rectangle (x1,y1)-(x2,y2).

Specified by:
allNodesOrSpritesIn in class View
Parameters:
x1 - The rectangle lowest point abscissa.
y1 - The rectangle lowest point ordinate.
x2 - The rectangle highest point abscissa.
y2 - The rectangle highest point ordinate.
Returns:
The set of sprites and nodes in the given rectangle.

findNodeOrSpriteAt

public GraphicElement findNodeOrSpriteAt(double x,
                                         double y)
Description copied from class: View
Search for the first node or sprite (in that order) that contains the point at coordinates (x, y).

Specified by:
findNodeOrSpriteAt in class View
Parameters:
x - The point abscissa.
y - The point ordinate.
Returns:
The first node or sprite at the given coordinates or null if nothing found.

moveElementAtPx

public void moveElementAtPx(GraphicElement element,
                            double x,
                            double y)
Description copied from class: View
Force an element to move at the given location in pixels.

Specified by:
moveElementAtPx in class View
Parameters:
element - The element.
x - The requested position abscissa in pixels.
y - The requested position ordinate in pixels.

freezeElement

public void freezeElement(GraphicElement element,
                          boolean frozen)
Description copied from class: View
Freeze an element so that the optional layout cannot move it.

Specified by:
freezeElement in class View
Parameters:
element - The element.
frozen - If true the element cannot be moved automatically.

setBackLayerRenderer

public void setBackLayerRenderer(LayerRenderer renderer)
Description copied from class: View
Set a layer renderer that will be called each time the graph needs to be redrawn before the graph is rendered. Pass "null" to remove the layer renderer.

Specified by:
setBackLayerRenderer in class View
Parameters:
renderer - The renderer (or null to remove it).

setForeLayoutRenderer

public void setForeLayoutRenderer(LayerRenderer renderer)
Description copied from class: View
Set a layer renderer that will be called each time the graph needs to be redrawn after the graph is rendered. Pass "null" to remove the layer renderer.

Specified by:
setForeLayoutRenderer in class View
Parameters:
renderer - The renderer (or null to remove it).

setMouseManager

public void setMouseManager(MouseManager manager)
Description copied from class: View
Change the manager for mouse events on this view. If the value for the new manager is null, a default manager is installed. The MouseManager.init(GraphicGraph, View) method must not yet have been called.

Specified by:
setMouseManager in class View
Parameters:
manager - The new manager, or null to set the default manager.
See Also:
MouseManager

setShortcutManager

public void setShortcutManager(ShortcutManager manager)
Description copied from class: View
Change the manager for key and shortcuts events on this view. If the value for the new manager is null, a default manager is installed. The ShortcutManager.init(GraphicGraph, View) method must not yet have been called.

Specified by:
setShortcutManager in class View
Parameters:
manager - The new manager, or null to set the default manager
See Also:
ShortcutManager


Copyright © 2013. All Rights Reserved.