Class DefaultView

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.graphstream.ui.swing_viewer.ViewPanel
org.graphstream.ui.swing_viewer.DefaultView
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, org.graphstream.ui.view.View

public class DefaultView
extends ViewPanel
implements java.awt.event.WindowListener, java.awt.event.ComponentListener
Base for constructing views.

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

  • the painting and repainting mechanism.
  • the optional frame handling.
  • the frame closing protocol.

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

    javax.swing.JComponent.AccessibleJComponent

    Nested classes/interfaces inherited from class java.awt.Component

    java.awt.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

    Constructors 
    Constructor Description
    DefaultView​(org.graphstream.ui.view.Viewer viewer, java.lang.String identifier, org.graphstream.ui.view.GraphRenderer renderer)  
  • Method Summary

    Modifier and Type Method Description
    <T,​ U> void addListener​(T descriptor, U listener)  
    java.util.Collection<org.graphstream.ui.graphicGraph.GraphicElement> allGraphicElementsIn​(java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x1, double y1, double x2, double y2)  
    void beginSelectionAt​(double x1, double y1)  
    void close​(org.graphstream.ui.graphicGraph.GraphicGraph graph)  
    void componentHidden​(java.awt.event.ComponentEvent e)  
    void componentMoved​(java.awt.event.ComponentEvent e)  
    void componentResized​(java.awt.event.ComponentEvent e)  
    void componentShown​(java.awt.event.ComponentEvent e)  
    void display​(org.graphstream.ui.graphicGraph.GraphicGraph graph, boolean graphChanged)  
    void enableMouseOptions()
    This is a shortcut to a call setMouseManager with a MouseOverMouseManager instance and with (InteractiveElement.EDGE, InteractiveElement.NODE, InteractiveElement.SPRITE).
    void endSelectionAt​(double x2, double y2)  
    org.graphstream.ui.graphicGraph.GraphicElement findGraphicElementAt​(java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y)  
    void freezeElement​(org.graphstream.ui.graphicGraph.GraphicElement element, boolean frozen)  
    org.graphstream.ui.view.camera.Camera getCamera()  
    void moveElementAtPx​(org.graphstream.ui.graphicGraph.GraphicElement element, double x, double y)  
    void openInAFrame​(boolean on)  
    void paintComponent​(java.awt.Graphics g)  
    <T,​ U> void removeListener​(T descriptor, U listener)  
    void render​(java.awt.Graphics2D g)  
    java.lang.Object requireFocus()  
    void resizeFrame​(int width, int height)
    Set the size of the view frame, if any.
    void selectionGrowsAt​(double x, double y)  
    void setBackLayerRenderer​(org.graphstream.ui.view.LayerRenderer<java.awt.Graphics2D> renderer)  
    void setForeLayoutRenderer​(org.graphstream.ui.view.LayerRenderer<java.awt.Graphics2D> renderer)  
    void setMouseManager​(org.graphstream.ui.view.util.MouseManager manager)  
    void setShortcutManager​(org.graphstream.ui.view.util.ShortcutManager manager)  
    void windowActivated​(java.awt.event.WindowEvent e)  
    void windowClosed​(java.awt.event.WindowEvent e)  
    void windowClosing​(java.awt.event.WindowEvent e)  
    void windowDeactivated​(java.awt.event.WindowEvent e)  
    void windowDeiconified​(java.awt.event.WindowEvent e)  
    void windowIconified​(java.awt.event.WindowEvent e)  
    void windowOpened​(java.awt.event.WindowEvent e)  

    Methods inherited from class org.graphstream.ui.swing_viewer.ViewPanel

    getIdView

    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, hide, 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, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, 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

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DefaultView

      public DefaultView​(org.graphstream.ui.view.Viewer viewer, java.lang.String identifier, org.graphstream.ui.view.GraphRenderer renderer)
  • Method Details

    • getCamera

      public org.graphstream.ui.view.camera.Camera getCamera()
      Specified by:
      getCamera in interface org.graphstream.ui.view.View
    • display

      public void display​(org.graphstream.ui.graphicGraph.GraphicGraph graph, boolean graphChanged)
      Specified by:
      display in interface org.graphstream.ui.view.View
    • paintComponent

      public void paintComponent​(java.awt.Graphics g)
    • close

      public void close​(org.graphstream.ui.graphicGraph.GraphicGraph graph)
      Specified by:
      close in interface org.graphstream.ui.view.View
    • resizeFrame

      public void resizeFrame​(int width, int height)
      Description copied from class: ViewPanel
      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 ViewPanel
      Parameters:
      width - The new width.
      height - The new height.
    • openInAFrame

      public void openInAFrame​(boolean on)
      Specified by:
      openInAFrame in interface org.graphstream.ui.view.View
    • render

      public void render​(java.awt.Graphics2D g)
    • beginSelectionAt

      public void beginSelectionAt​(double x1, double y1)
      Specified by:
      beginSelectionAt in interface org.graphstream.ui.view.View
    • selectionGrowsAt

      public void selectionGrowsAt​(double x, double y)
      Specified by:
      selectionGrowsAt in interface org.graphstream.ui.view.View
    • endSelectionAt

      public void endSelectionAt​(double x2, double y2)
      Specified by:
      endSelectionAt in interface org.graphstream.ui.view.View
    • windowActivated

      public void windowActivated​(java.awt.event.WindowEvent e)
      Specified by:
      windowActivated in interface java.awt.event.WindowListener
    • windowClosed

      public void windowClosed​(java.awt.event.WindowEvent e)
      Specified by:
      windowClosed in interface java.awt.event.WindowListener
    • windowClosing

      public void windowClosing​(java.awt.event.WindowEvent e)
      Specified by:
      windowClosing in interface java.awt.event.WindowListener
    • windowDeactivated

      public void windowDeactivated​(java.awt.event.WindowEvent e)
      Specified by:
      windowDeactivated in interface java.awt.event.WindowListener
    • windowDeiconified

      public void windowDeiconified​(java.awt.event.WindowEvent e)
      Specified by:
      windowDeiconified in interface java.awt.event.WindowListener
    • windowIconified

      public void windowIconified​(java.awt.event.WindowEvent e)
      Specified by:
      windowIconified in interface java.awt.event.WindowListener
    • windowOpened

      public void windowOpened​(java.awt.event.WindowEvent e)
      Specified by:
      windowOpened in interface java.awt.event.WindowListener
    • componentHidden

      public void componentHidden​(java.awt.event.ComponentEvent e)
      Specified by:
      componentHidden in interface java.awt.event.ComponentListener
    • componentMoved

      public void componentMoved​(java.awt.event.ComponentEvent e)
      Specified by:
      componentMoved in interface java.awt.event.ComponentListener
    • componentResized

      public void componentResized​(java.awt.event.ComponentEvent e)
      Specified by:
      componentResized in interface java.awt.event.ComponentListener
    • componentShown

      public void componentShown​(java.awt.event.ComponentEvent e)
      Specified by:
      componentShown in interface java.awt.event.ComponentListener
    • allGraphicElementsIn

      public java.util.Collection<org.graphstream.ui.graphicGraph.GraphicElement> allGraphicElementsIn​(java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x1, double y1, double x2, double y2)
      Specified by:
      allGraphicElementsIn in interface org.graphstream.ui.view.View
    • findGraphicElementAt

      public org.graphstream.ui.graphicGraph.GraphicElement findGraphicElementAt​(java.util.EnumSet<org.graphstream.ui.view.util.InteractiveElement> types, double x, double y)
      Specified by:
      findGraphicElementAt in interface org.graphstream.ui.view.View
    • moveElementAtPx

      public void moveElementAtPx​(org.graphstream.ui.graphicGraph.GraphicElement element, double x, double y)
      Specified by:
      moveElementAtPx in interface org.graphstream.ui.view.View
    • freezeElement

      public void freezeElement​(org.graphstream.ui.graphicGraph.GraphicElement element, boolean frozen)
      Specified by:
      freezeElement in interface org.graphstream.ui.view.View
    • setBackLayerRenderer

      public void setBackLayerRenderer​(org.graphstream.ui.view.LayerRenderer<java.awt.Graphics2D> renderer)
    • setForeLayoutRenderer

      public void setForeLayoutRenderer​(org.graphstream.ui.view.LayerRenderer<java.awt.Graphics2D> renderer)
    • setMouseManager

      public void setMouseManager​(org.graphstream.ui.view.util.MouseManager manager)
      Specified by:
      setMouseManager in interface org.graphstream.ui.view.View
    • enableMouseOptions

      public void enableMouseOptions()
      This is a shortcut to a call setMouseManager with a MouseOverMouseManager instance and with (InteractiveElement.EDGE, InteractiveElement.NODE, InteractiveElement.SPRITE).
      Specified by:
      enableMouseOptions in interface org.graphstream.ui.view.View
      Specified by:
      enableMouseOptions in class ViewPanel
    • setShortcutManager

      public void setShortcutManager​(org.graphstream.ui.view.util.ShortcutManager manager)
      Specified by:
      setShortcutManager in interface org.graphstream.ui.view.View
    • requireFocus

      public java.lang.Object requireFocus()
      Specified by:
      requireFocus in interface org.graphstream.ui.view.View
    • addListener

      public <T,​ U> void addListener​(T descriptor, U listener)
      Specified by:
      addListener in interface org.graphstream.ui.view.View
    • removeListener

      public <T,​ U> void removeListener​(T descriptor, U listener)
      Specified by:
      removeListener in interface org.graphstream.ui.view.View