org.formaria.svg
Class SvgImageMap

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.formaria.svg.SvgImageMap
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class SvgImageMap
extends javax.swing.JPanel
implements java.awt.event.MouseMotionListener, java.awt.event.MouseListener

Copyright (c) Formaria Ltd., 2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from Formaria.

$Revision: 1.2 $

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
 
Field Summary
protected  java.lang.String blockPrefix
           
protected  java.lang.String rolloverPrefix
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, 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
SvgImageMap()
          Class constructor.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener al)
          Used to add an ActionListener to the list of action listeners.
 void addMapMouseListener(java.awt.event.MouseListener l)
          Adds a mouse listener to this component to listen for mouse events.
 SVGDiagram display()
          Displays the SVG image by adding the file to an SVGUniverse instance, extracting an SVGDiagram instance from SVGUniverse and displaying the diagram in an SVGDisplayPanel
 void drawAuxilaryImages(java.awt.Graphics2D g2d)
          Draws the auxilary images within the image map component.
 void endCoalesce()
          Stop coalescing, meaning the image will be repainted after the next pan or zoom action.
protected  void fireActionPerformed(java.awt.event.ActionEvent event)
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireActionPerformed(java.awt.event.MouseEvent event)
          Notifies all mouse listeners that have registered interest for notification on mouse event types.
 java.awt.image.BufferedImage getBufferedImage()
          Returns the rendered buffered image of the svg displayed by this class
 double getCenterX()
          Return the center position of the image on the x-axis.
 double getCenterY()
          Return the center position of the image on the y-axis.
 javax.swing.JPanel getGlassPane()
          Returns the glass pane component of the layered pane
 java.lang.String getImageName()
          Returns the content of the image map.
 boolean getPreserveAspect()
          Does the component preserve the aspect ratio of the image?
 double getScaleX()
          Return the scaleFactor currently being applied to the x-axis.
 double getScaleY()
          Return the scaleFactor currently being applied to the y-axis.
 java.lang.String getSelectedRollover(java.awt.event.MouseEvent e)
          Returns the id of the rollover block currently selected.
 RenderingSemaphore getSemaphore()
          Returns the semaphore used by this class to block on rendering events.
 SVGDiagram getSvgDiagram()
          Returns the instance of the SVG diagram used to access the image data.
 SvgRolloverFinder getSvgRolloverFinder()
          Get the compare interface
 java.lang.String getUrl()
          Returns the url of the image displayed in the image map.
 java.net.URL getURL()
          Used to return the URL pointing to the SVG image that is being displayed.
 java.awt.geom.Point2D glassPaneToSvg(double x, double y)
          Converts a coordinate from the glasspane coordinate system to the svg map coordinate system.
 void loadArrays()
          Extracts Group objects from SVG file and loads them into the corresponding arrays
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
          Monitors mouse dragged events.
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
          Detect if mouse has exited the component and reset visible rollove to hidden.
 void mouseMoved(java.awt.event.MouseEvent e)
          Monitors mouse movement and calls checkBlock method.
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void notifyListeners()
          Notify all listening components that the svg has been re-rendered.
 void paintComponent(java.awt.Graphics g)
          Used to paint a buffered image of the rendered svg to the component.
 void pan(double x, double y)
          Used to pan the image based on percentage of the current x and y locations.
 void removeActionListener(java.awt.event.ActionListener l)
          Removes an ActionListener from the button.
 void removeMapMouseListener(java.awt.event.MouseListener l)
          Removes a mouse listener to this component.
 void resetBuffer()
          Reset the image buffer meaning that the image will be re-rendered the next time the paintComponent method is called.
 void resetPanning()
          Resets the image to its original displayed coordinates.
 void resetZoom()
          Resets the image to its original zoomed view.
 void resize()
          Resizes the SVG image to fit the panel
 void setAuxilaryImages(java.awt.image.BufferedImage[] images)
          Set the auxilary images to be displayed when dragging the image map.
 void setBlockPrefix(java.lang.String prefix)
          Set the prefix for each block within the svg image.
 void setContent(java.lang.String value)
          Set teh content
 void setDrawAuxImages(boolean b)
          Sets whether the auxilary images are to be drawn or not.
 void setImage(java.awt.image.BufferedImage b)
          Sets the buffered image to be painted.
 void setImageLocation(int x, int y)
          Set the location of the buffered image in the panel.
 void setImageName(java.lang.String attribValue)
          Set the content of the image map.
 void setPanCoords(double x, double y)
          Set position of where the pan method is to begin panning from in the next pan action.
 void setPreserveAspect(boolean preserve)
          Set the aspect ratio preservation flag
 void setRolloverPrefix(java.lang.String prefix)
          Set the prefix for each rollover within the svg image.
 void setRollOverStatus(boolean setRollOvers)
          Allow rollovers or not based on boolean value.
 void setSvgRolloverFinder(SvgRolloverFinder sim)
          Set the compare interfaces for comparing groups/elements for identification of the rollovers
 void setURL(java.net.URL newUrl)
          Used to set the URL pointing to the SVG image that is to be displayed.
 void setViewBox(double x, double y, double width, double height)
          Sets the viewbox at the specified coordinates and preserves the aspect ratio of the image.
 void setVisibility(java.lang.String group, boolean v)
          Sets the visibility of a group
 void startCoalesce()
          Start coalesce, of panning and zooming actions.
 java.awt.geom.Point2D svgToGlassPane(double x, double y)
          Converts a coordinate from the svg map coordinate system to the glasspane coordinate system.
 void zoom(double zoom)
          Zooms the image by the scaling factor specified.
 
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, transferFocusBackward, 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, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

blockPrefix

protected java.lang.String blockPrefix

rolloverPrefix

protected java.lang.String rolloverPrefix
Constructor Detail

SvgImageMap

public SvgImageMap()
Class constructor.

Method Detail

getGlassPane

public javax.swing.JPanel getGlassPane()
Returns the glass pane component of the layered pane

Returns:
the JPanel component returned

glassPaneToSvg

public java.awt.geom.Point2D glassPaneToSvg(double x,
                                            double y)
Converts a coordinate from the glasspane coordinate system to the svg map coordinate system.

Parameters:
x - a double specifying the x coordinate to be converted.
y - a double specifying the y coordinate to be converted.
Returns:
Point2D object containing the converted coordinates.

svgToGlassPane

public java.awt.geom.Point2D svgToGlassPane(double x,
                                            double y)
Converts a coordinate from the svg map coordinate system to the glasspane coordinate system.

Parameters:
x - a double specifying the x coordinate to be converted.
y - a double specifying the y coordinate to be converted.
Returns:
Point2D object containing the converted coordinates.

setSvgRolloverFinder

public void setSvgRolloverFinder(SvgRolloverFinder sim)
Set the compare interfaces for comparing groups/elements for identification of the rollovers

Parameters:
sim - the comparison class

getSvgRolloverFinder

public SvgRolloverFinder getSvgRolloverFinder()
Get the compare interface

Returns:
the interface object or null if none has been set.

setBlockPrefix

public void setBlockPrefix(java.lang.String prefix)
Set the prefix for each block within the svg image.

Parameters:
prefix - String specifying the block prefix.

setRolloverPrefix

public void setRolloverPrefix(java.lang.String prefix)
Set the prefix for each rollover within the svg image.

Parameters:
prefix - String specifying the rollover prefix.

setContent

public void setContent(java.lang.String value)
Set teh content

Parameters:
value - the path specifying the location of the SVG image.

setURL

public void setURL(java.net.URL newUrl)
Used to set the URL pointing to the SVG image that is to be displayed.

Parameters:
newUrl - URL object specifying the location of the SVG image.

getURL

public java.net.URL getURL()
Used to return the URL pointing to the SVG image that is being displayed.

Returns:
URL object returned specifying the location of the SVG image.

display

public SVGDiagram display()
Displays the SVG image by adding the file to an SVGUniverse instance, extracting an SVGDiagram instance from SVGUniverse and displaying the diagram in an SVGDisplayPanel


resetBuffer

public void resetBuffer()
Reset the image buffer meaning that the image will be re-rendered the next time the paintComponent method is called.


notifyListeners

public void notifyListeners()
Notify all listening components that the svg has been re-rendered.


paintComponent

public void paintComponent(java.awt.Graphics g)
Used to paint a buffered image of the rendered svg to the component.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the delegate Graphics object.

resize

public void resize()
Resizes the SVG image to fit the panel


pan

public void pan(double x,
                double y)
Used to pan the image based on percentage of the current x and y locations.

Parameters:
x - double specifying the percentage to increase/decrease the x-coordinate by.
y - double specifying the percentage to increase/decrease the y-coordinate by.

resetPanning

public void resetPanning()
Resets the image to its original displayed coordinates.


zoom

public void zoom(double zoom)
Zooms the image by the scaling factor specified.

Parameters:
zoom - double specifying the scaling factor.

startCoalesce

public void startCoalesce()
Start coalesce, of panning and zooming actions. The svg won't be repainted until the endCoalesce method is called.


endCoalesce

public void endCoalesce()
Stop coalescing, meaning the image will be repainted after the next pan or zoom action.


setPanCoords

public void setPanCoords(double x,
                         double y)
Set position of where the pan method is to begin panning from in the next pan action.

Parameters:
x - double specifying the x coordinate of where the image is to be panned from.
y - double specifying the y coordinate of where the image is to be panned from.

resetZoom

public void resetZoom()
Resets the image to its original zoomed view.


setAuxilaryImages

public void setAuxilaryImages(java.awt.image.BufferedImage[] images)
Set the auxilary images to be displayed when dragging the image map.

Parameters:
images - BufferedImage array containing the auxilary images to be displayed.

drawAuxilaryImages

public void drawAuxilaryImages(java.awt.Graphics2D g2d)
Draws the auxilary images within the image map component.

Parameters:
g2d - the Graphics2D object used to draw the images.

setDrawAuxImages

public void setDrawAuxImages(boolean b)
Sets whether the auxilary images are to be drawn or not.

Parameters:
b - boolean specifying whether the auxilary images are to be drawn or not.

getSemaphore

public RenderingSemaphore getSemaphore()
Returns the semaphore used by this class to block on rendering events.

Returns:
RenderingSemaphore the semaphore instance used by this class.

setImageLocation

public void setImageLocation(int x,
                             int y)
Set the location of the buffered image in the panel.

Parameters:
x - the x coordinate of the buffered image.
y - the y coordinate of the buffered image.

setImage

public void setImage(java.awt.image.BufferedImage b)
Sets the buffered image to be painted.

Parameters:
b - BufferedImage set to true if movable image is to be repainted.

getBufferedImage

public java.awt.image.BufferedImage getBufferedImage()
Returns the rendered buffered image of the svg displayed by this class

Returns:
the returned BufferedImage instance

getSvgDiagram

public SVGDiagram getSvgDiagram()
Returns the instance of the SVG diagram used to access the image data.


setViewBox

public void setViewBox(double x,
                       double y,
                       double width,
                       double height)
Sets the viewbox at the specified coordinates and preserves the aspect ratio of the image.

Parameters:
x - double specifying the x coordinate
y - double specifying the y coordinate
width - double specifying the width
height - double specifying the height

loadArrays

public void loadArrays()
Extracts Group objects from SVG file and loads them into the corresponding arrays


setVisibility

public void setVisibility(java.lang.String group,
                          boolean v)
Sets the visibility of a group

Parameters:
group - String specifying the SVG grouping to be displayed
v - boolean specifying whether the group is to be set visible or hidden

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Monitors mouse movement and calls checkBlock method. to check if the mouse pointer position is within an SVG group

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
e - the MouseEvent that occured

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Monitors mouse dragged events.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
e - the MouseEvent that occured

setImageName

public void setImageName(java.lang.String attribValue)
Set the content of the image map.

Parameters:
attribValue - Object specifying the content.

getImageName

public java.lang.String getImageName()
Returns the content of the image map.

Returns:
String specifying the content value.

getUrl

public java.lang.String getUrl()
Returns the url of the image displayed in the image map.

Returns:
String specifying the content value.

setRollOverStatus

public void setRollOverStatus(boolean setRollOvers)
Allow rollovers or not based on boolean value.

Parameters:
setRollOvers - boolean used to set if rollovers are to be allowed or not.

getScaleX

public double getScaleX()
Return the scaleFactor currently being applied to the x-axis.


getScaleY

public double getScaleY()
Return the scaleFactor currently being applied to the y-axis.


getCenterX

public double getCenterX()
Return the center position of the image on the x-axis.


getCenterY

public double getCenterY()
Return the center position of the image on the y-axis.


addMapMouseListener

public void addMapMouseListener(java.awt.event.MouseListener l)
Adds a mouse listener to this component to listen for mouse events.

Parameters:
l - the MouseListener that is to be added.

removeMapMouseListener

public void removeMapMouseListener(java.awt.event.MouseListener l)
Removes a mouse listener to this component.

Parameters:
l - the MouseListener that is to be removed.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Detect if mouse has exited the component and reset visible rollove to hidden.

Specified by:
mouseExited in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

addActionListener

public void addActionListener(java.awt.event.ActionListener al)
Used to add an ActionListener to the list of action listeners.

Parameters:
al - the listener to be added

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Removes an ActionListener from the button. If the listener is the currently set Action for the button, then the Action is set to null.

Parameters:
l - the listener to be removed

fireActionPerformed

protected void fireActionPerformed(java.awt.event.MouseEvent event)
Notifies all mouse listeners that have registered interest for notification on mouse event types. The event instance is lazily created using the event parameter.

Parameters:
event - the MouseEvent object

fireActionPerformed

protected void fireActionPerformed(java.awt.event.ActionEvent event)
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the event parameter.

Parameters:
event - the ActionEvent object
See Also:
EventListenerList

getSelectedRollover

public java.lang.String getSelectedRollover(java.awt.event.MouseEvent e)
Returns the id of the rollover block currently selected.

Parameters:
e - the triggered MouseEvent.
Returns:
the id String.

getPreserveAspect

public boolean getPreserveAspect()
Does the component preserve the aspect ratio of the image?

Returns:
true if the aspect ratio is preserved.

setPreserveAspect

public void setPreserveAspect(boolean preserve)
Set the aspect ratio preservation flag

Parameters:
preserve - true to preserve the aspect