Class NavigableSVGPanel

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, javax.accessibility.Accessible
    Direct Known Subclasses:
    DotPanel

    public class NavigableSVGPanel
    extends javax.swing.JPanel
    implements java.awt.print.Printable
    A JPanel that displays an SVG image. Animation support is present, but not complete, i.e. you'll need a subclass to perform animation. Controls are included to ease implementation of subclasses.
    Author:
    sleemans
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Constructor Summary

      Constructors 
      Constructor Description
      NavigableSVGPanel​(com.kitfox.svg.SVGDiagram newImage)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void centerImageAround​(java.awt.Point pointInNavigationCoordinates)
      The user clicked within the navigation image and this part of the image is displayed in the panel.
      protected void drawAnimation​(java.awt.Graphics2D g)
      Draw the animation.
      static void drawSVG​(java.awt.Graphics2D g, com.kitfox.svg.SVGDiagram image, int x, int y, int width, int height)
      Draw an svg image at the given coordinates and of the given size.
      void exportView()
      Prompts the user for a file name and saves the view under that file name.
      double getAnimationMaximumTime()
      Needs to be overridden by a subclass.
      double getAnimationMinimumTime()
      Needs to be overridden by a subclass.
      double getAnimationTime()
      Needs to be overridden by a subclass.
      java.awt.Rectangle getControlsProgressLine()  
      java.util.List<Exporter> getExporters()  
      java.util.List<java.lang.String> getHelperControlsExplanations()  
      java.util.List<java.lang.String> getHelperControlsShortcuts()  
      com.kitfox.svg.SVGDiagram getImage()  
      java.awt.Rectangle getImageBoundingBoxInUserCoordinates()  
      double getTimeScale()
      Needs to be overridden by a subclass.
      java.awt.Rectangle getVisibleImageBoundingBoxInUserCoordinates()  
      boolean isAnimationControlsShowing()  
      boolean isAnimationEnabled()
      Needs to be overridden by a subclass.
      boolean isAnimationPlaying()
      Needs to be overridden by a subclass.
      boolean isImageCompletelyInPanel()
      Returns whether the image is completely visible in the panel
      protected boolean isInAnimationControls​(java.awt.Point p)  
      boolean isInHelperControls​(java.awt.Point pointInUserCoordinates)  
      boolean isInImage​(java.awt.Point pointInUserCoordinates)
      Returns whether a point (in user coordinates) is in the image and not in the navigation image.
      boolean isInNavigation​(java.awt.Point pointInUserCoordinates)
      Returns whether a point (in user coordinates) is in the navigation image.
      protected void paintComponent​(java.awt.Graphics g)
      Paints the panel and its image at the current zoom level, location, and interpolation method dependent on the image scale.
      protected void paintImage​(java.awt.Graphics2D g)  
      void pause()
      Request the animation to pause.
      void pauseResume()
      Request the animation to pause or resume.
      int print​(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int page)  
      protected boolean processMouseClick​(java.awt.event.MouseEvent e)
      Process a mouse click
      protected boolean processMouseDrag​(java.awt.event.MouseEvent e)
      Process a mouse drag;
      protected boolean processMouseExit​(java.awt.event.MouseEvent e)
      Process a mouse exit
      protected boolean processMouseMove​(java.awt.event.MouseEvent e)
      Process a mouse move.
      protected boolean processMousePress​(java.awt.event.MouseEvent e)
      Process a mouse press.
      protected boolean processMouseRelease​(java.awt.event.MouseEvent e)
      Process a mouse release
      void renderOneFrame()
      Request one frame of the animation to be rendered.
      void resetView()
      Scale and center the image just in the viewport.
      void resume()
      Resume the animation from pausing.
      void seek​(double time)
      Request the next animation frame to be rendered at the given time.
      void setHelperControlsExplanations​(java.util.List<java.lang.String> helperControlsExplanations)
      Sets the shortcut explanations, displayed when hovering over the question mark in the lower right corner.
      void setHelperControlsShortcuts​(java.util.List<java.lang.String> helperControlsShortcuts)
      Sets the shortcuts, displayed when hovering over the question mark in the lower right corner.
      void setImage​(com.kitfox.svg.SVGDiagram image, boolean resetView)
      Sets an image for display in the panel.
      void setImageTransformationChangedListener​(ImageTransformationChangedListener listener)  
      void setTimeScale​(double time)
      Request the time scale to be set.
      void setTransformation​(java.awt.geom.AffineTransform image2user, java.awt.geom.AffineTransform user2image)  
      void setupListeners()  
      java.awt.geom.Point2D transformElement2Image​(java.awt.geom.Point2D p, com.kitfox.svg.SVGElement svgElement)  
      java.awt.geom.Point2D transformImage2User​(java.awt.geom.Point2D p)  
      java.awt.geom.Point2D transformImageToNavigation​(java.awt.geom.Point2D p)
      Transforms the given point in image coordinates to navigation coordinates
      java.awt.geom.Point2D transformNavigationToImage​(java.awt.geom.Point2D p)
      Transforms the given point in navigation coordinates to image coordinates
      java.awt.geom.Point2D transformUser2Image​(java.awt.geom.Point2D p)  
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • 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, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, 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, 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • image

        protected com.kitfox.svg.SVGDiagram image
      • image2user

        protected java.awt.geom.AffineTransform image2user
      • isDraggingImage

        protected boolean isDraggingImage
      • isDraggingAnimation

        protected boolean isDraggingAnimation
      • isDraggingTimeScale

        protected boolean isDraggingTimeScale
      • animationControls

        protected java.awt.Rectangle animationControls
      • controlsPlayPause

        protected java.awt.Rectangle controlsPlayPause
      • controlsTimeScale

        protected java.awt.Rectangle controlsTimeScale
      • navigationImageWidthInPartOfPanel

        public static final double navigationImageWidthInPartOfPanel
        See Also:
        Constant Field Values
      • navigationImageBorderColor

        public static final java.awt.Color navigationImageBorderColor
      • dash1

        public static final float[] dash1
      • navigationImageOutlineStroke

        public static final java.awt.BasicStroke navigationImageOutlineStroke
      • helperControlsFont

        public static final java.awt.Font helperControlsFont
      • helperControlsButtonFont

        protected static final java.awt.Font helperControlsButtonFont
      • helperControlsButtonString

        protected static final java.lang.String helperControlsButtonString
        See Also:
        Constant Field Values
      • helperControlsShortcuts

        protected java.util.List<java.lang.String> helperControlsShortcuts
      • helperControlsExplanations

        protected java.util.List<java.lang.String> helperControlsExplanations
    • Constructor Detail

      • NavigableSVGPanel

        public NavigableSVGPanel​(com.kitfox.svg.SVGDiagram newImage)
    • Method Detail

      • setupListeners

        public void setupListeners()
      • paintComponent

        protected void paintComponent​(java.awt.Graphics g)
        Paints the panel and its image at the current zoom level, location, and interpolation method dependent on the image scale.

        Overrides:
        paintComponent in class javax.swing.JComponent
        Parameters:
        g - the Graphics context for painting
      • paintImage

        protected void paintImage​(java.awt.Graphics2D g)
      • drawSVG

        public static void drawSVG​(java.awt.Graphics2D g,
                                   com.kitfox.svg.SVGDiagram image,
                                   int x,
                                   int y,
                                   int width,
                                   int height)
        Draw an svg image at the given coordinates and of the given size.
        Parameters:
        g -
        image -
        x -
        y -
        width -
        height -
      • drawAnimation

        protected void drawAnimation​(java.awt.Graphics2D g)
        Draw the animation.
        Parameters:
        g -
      • transformNavigationToImage

        public java.awt.geom.Point2D transformNavigationToImage​(java.awt.geom.Point2D p)
        Transforms the given point in navigation coordinates to image coordinates
        Parameters:
        p -
        Returns:
      • transformImageToNavigation

        public java.awt.geom.Point2D transformImageToNavigation​(java.awt.geom.Point2D p)
        Transforms the given point in image coordinates to navigation coordinates
        Parameters:
        p -
        Returns:
      • isInImage

        public boolean isInImage​(java.awt.Point pointInUserCoordinates)
        Returns whether a point (in user coordinates) is in the image and not in the navigation image.
        Parameters:
        pointInUserCoordinates -
        Returns:
      • isInNavigation

        public boolean isInNavigation​(java.awt.Point pointInUserCoordinates)
        Returns whether a point (in user coordinates) is in the navigation image.
        Parameters:
        pointInUserCoordinates -
        Returns:
      • isInHelperControls

        public boolean isInHelperControls​(java.awt.Point pointInUserCoordinates)
      • getHelperControlsShortcuts

        public java.util.List<java.lang.String> getHelperControlsShortcuts()
        Returns:
        The currently registered shortcuts, which are displayed when hovering over the question mark in the lower right corner.
      • setHelperControlsShortcuts

        public void setHelperControlsShortcuts​(java.util.List<java.lang.String> helperControlsShortcuts)
        Sets the shortcuts, displayed when hovering over the question mark in the lower right corner.
        Parameters:
        helperControlsShortcuts -
      • getHelperControlsExplanations

        public java.util.List<java.lang.String> getHelperControlsExplanations()
        Returns:
        The currently registered shortcut explanations, which are displayed when hovering over the question mark in the lower right corner.
      • setHelperControlsExplanations

        public void setHelperControlsExplanations​(java.util.List<java.lang.String> helperControlsExplanations)
        Sets the shortcut explanations, displayed when hovering over the question mark in the lower right corner.
        Parameters:
        helperControlsExplanations -
      • getImage

        public com.kitfox.svg.SVGDiagram getImage()
        Returns:
        The currently displaying svg image.
      • getVisibleImageBoundingBoxInUserCoordinates

        public java.awt.Rectangle getVisibleImageBoundingBoxInUserCoordinates()
        Returns:
        The bounding box of the image in user coordinates, truncated (approximately) to the visible area.
      • getImageBoundingBoxInUserCoordinates

        public java.awt.Rectangle getImageBoundingBoxInUserCoordinates()
        Returns:
        the bounding box of the complete image in user coordinates
      • isImageCompletelyInPanel

        public boolean isImageCompletelyInPanel()
        Returns whether the image is completely visible in the panel
        Parameters:
        panState -
        diagram -
        panel -
        Returns:
      • setImage

        public void setImage​(com.kitfox.svg.SVGDiagram image,
                             boolean resetView)

        Sets an image for display in the panel.

        Parameters:
        image - an image to be set in the panel
      • resetView

        public void resetView()
                       throws java.awt.geom.NoninvertibleTransformException
        Scale and center the image just in the viewport.
        Throws:
        java.awt.geom.NoninvertibleTransformException
      • centerImageAround

        public void centerImageAround​(java.awt.Point pointInNavigationCoordinates)
                               throws java.awt.geom.NoninvertibleTransformException
        The user clicked within the navigation image and this part of the image is displayed in the panel. The clicked point of the image is centered in the panel.
        Parameters:
        pointInNavigationCoordinates -
        Throws:
        java.awt.geom.NoninvertibleTransformException
      • processMousePress

        protected boolean processMousePress​(java.awt.event.MouseEvent e)
        Process a mouse press.
        Parameters:
        e -
        Returns:
        whether the press was handled and did something.
      • processMouseRelease

        protected boolean processMouseRelease​(java.awt.event.MouseEvent e)
        Process a mouse release
        Parameters:
        e -
        Returns:
        whether the hover was handled and did something.
      • processMouseDrag

        protected boolean processMouseDrag​(java.awt.event.MouseEvent e)
        Process a mouse drag;
        Parameters:
        e -
        Returns:
        whether the drag was handled and did something.
      • processMouseMove

        protected boolean processMouseMove​(java.awt.event.MouseEvent e)
        Process a mouse move. Captured = true implies that the hover was already processed (and we should hide everything related to hovering).
        Parameters:
        e -
        Returns:
        whether the move is hovering something.
      • processMouseClick

        protected boolean processMouseClick​(java.awt.event.MouseEvent e)
        Process a mouse click
        Parameters:
        e -
        Returns:
        whether the click was handled and did something.
      • processMouseExit

        protected boolean processMouseExit​(java.awt.event.MouseEvent e)
        Process a mouse exit
        Parameters:
        e -
        Returns:
        whether the exit was handled and did something.
      • setTransformation

        public void setTransformation​(java.awt.geom.AffineTransform image2user,
                                      java.awt.geom.AffineTransform user2image)
      • transformUser2Image

        public java.awt.geom.Point2D transformUser2Image​(java.awt.geom.Point2D p)
      • transformImage2User

        public java.awt.geom.Point2D transformImage2User​(java.awt.geom.Point2D p)
      • transformElement2Image

        public java.awt.geom.Point2D transformElement2Image​(java.awt.geom.Point2D p,
                                                            com.kitfox.svg.SVGElement svgElement)
      • isAnimationEnabled

        public boolean isAnimationEnabled()
        Needs to be overridden by a subclass.
        Returns:
        whether the animation is rendered and controls are displayed.
      • isAnimationPlaying

        public boolean isAnimationPlaying()
        Needs to be overridden by a subclass.
        Returns:
        whether the animation is currently playing (not paused)
      • getTimeScale

        public double getTimeScale()
        Needs to be overridden by a subclass.
        Returns:
        the time scale set, which is a 0 <= number <= 1.
      • setTimeScale

        public void setTimeScale​(double time)
        Request the time scale to be set. Needs to be overridden by a subclass.
        Parameters:
        time -
      • getAnimationTime

        public double getAnimationTime()
        Needs to be overridden by a subclass.
        Returns:
        the current animation time.
      • getAnimationMinimumTime

        public double getAnimationMinimumTime()
        Needs to be overridden by a subclass.
        Returns:
        the minimum animation time.
      • getAnimationMaximumTime

        public double getAnimationMaximumTime()
        Needs to be overridden by a subclass.
        Returns:
        the maximum animation time.
      • isInAnimationControls

        protected boolean isInAnimationControls​(java.awt.Point p)
        Parameters:
        p -
        Returns:
        whether a point lies in the animation controls.
      • seek

        public void seek​(double time)
        Request the next animation frame to be rendered at the given time. Needs to be overridden by a subclass.
        Parameters:
        time -
      • pause

        public void pause()
        Request the animation to pause. Needs to be overridden by a subclass.
      • resume

        public void resume()
        Resume the animation from pausing. Needs to be overridden by a subclass.
      • pauseResume

        public void pauseResume()
        Request the animation to pause or resume. Needs to be overridden by a subclass.
      • renderOneFrame

        public void renderOneFrame()
        Request one frame of the animation to be rendered. Needs to be overridden by a subclass.
      • getControlsProgressLine

        public java.awt.Rectangle getControlsProgressLine()
      • isAnimationControlsShowing

        public boolean isAnimationControlsShowing()
      • getExporters

        public java.util.List<Exporter> getExporters()
        Returns:
        The list of exporters. Subclasses can override this to a relevant list. Called everytime the user attempts to export the image.
      • exportView

        public void exportView()
        Prompts the user for a file name and saves the view under that file name.
      • print

        public int print​(java.awt.Graphics g,
                         java.awt.print.PageFormat pageFormat,
                         int page)
                  throws java.awt.print.PrinterException
        Specified by:
        print in interface java.awt.print.Printable
        Throws:
        java.awt.print.PrinterException