net.xoetrope.optional.svg
Class XSvgCanvas

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by net.xoetrope.optional.svg.XSvgCanvas
All Implemented Interfaces:
com.tinyline.svg.ImageLoader, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.lang.Runnable, EventTarget, XAttributedComponent
Direct Known Subclasses:
XSvgImageMap

public class XSvgCanvas
extends javax.swing.JComponent
implements java.lang.Runnable, com.tinyline.svg.ImageLoader, EventTarget, XAttributedComponent

The PPSVGCanvas is the J2ME Personal Profile implementation of the SVG Canvas.

anit

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.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
 java.lang.String currentURL
          The current URL to go
 SVGEventQueue eventQueue
          The events queue
 com.tinyline.svg.SVGRaster raster
          The SVG renderer
 
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
XSvgCanvas()
          Constructs a new PPSVGCanvas instance.
 
Method Summary
 void addEventListener(java.lang.String type, EventListener listener, boolean useCapture)
          uDOM: This method allows the registration of event listeners on the event target.
 void addNotify()
          Requests a repaint of the control once it has been created
 void alertError(java.lang.String s)
          StatusBar: shows an alert
 void alertInit(java.lang.String s)
          StatusBar: inits the bar
 void alertWait(java.lang.String s)
          StatusBar: shows a wait
 com.tinyline.tiny2d.TinyBitmap createTinyBitmap(byte[] imageData, int imageOffset, int imageLength)
          Creates a TinyBitmap which decodes the image stored in the specified byte array, and at the specified offset and length.
 com.tinyline.tiny2d.TinyBitmap createTinyBitmap(com.tinyline.tiny2d.TinyString uri)
          Returns a TinyBitmap for the given image URL or path.
 boolean dispatchEvent(Event evt)
          uDOM: This method allows the dispatch of events into the implementations event model.
 void flush()
          Flushes the allocated resources.
 java.awt.Dimension getMinimumSize()
          The minimum size of the canvas.
 java.awt.Dimension getPreferredSize()
          The preferred size of the canvas.
 void goURL(java.lang.String url)
          Loads and dispalys an SVG document from the given URL.
 boolean hasFileLoadCompleted()
          Has the component finished with the input file?
 boolean imageUpdate(java.awt.Image img, int flags, int x, int y, int width, int height)
          This method is called when information about an image which was previously requested using an asynchronous interface becomes available.
 void init()
           
 com.tinyline.svg.SVGDocument loadSVG(java.io.InputStream is)
          Loads an SVGT document from the given InputStream.
 com.tinyline.svg.SVGDocument loadSVG(java.lang.String urlStr)
          Loads an SVGT document from the given URL.
 void origView()
          Returns the current SVGT document to its original view.
 void paintComponent(java.awt.Graphics g)
          Paints this canvas
 void pan(int x, int y)
          Pan/scroll the image to toa new location
 void pauseResumeAnimations()
          Suspends or unsuspends all animations that are defined within the current SVGT document fragment.
 void postEvent(SVGEvent theEvent)
          Posts an event to the event queue.
 void removeEventListener(EventListener listener)
          uDOM: This method allows the removal of event listeners from the event target.
 void reset()
          Reset the image to its original size and position
 void run()
          The events dispatching thread run()
 int setAttribute(java.lang.String attribName, java.lang.Object attribValue)
          Set one or more attributes of the component.
 void setBounds(int x, int y, int w, int h)
           
 void setVisible(boolean state)
           
 void start()
          Starts the events dispatching thread
 void stop()
          Stops the events dispatching thread
 void switchQuality()
          Switches the rendering quality of this SVGPlayer .
protected  void updateImage()
          Update the raster image
 void zoom(double scaleFactor)
          Zoom in on the image param scaleFactor the factor by which to adjust the scaling.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, unregisterKeyboardAction, update, updateUI
 
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, 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, 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

raster

public com.tinyline.svg.SVGRaster raster
The SVG renderer


eventQueue

public SVGEventQueue eventQueue
The events queue


currentURL

public java.lang.String currentURL
The current URL to go

Constructor Detail

XSvgCanvas

public XSvgCanvas()
Constructs a new PPSVGCanvas instance.

Method Detail

hasFileLoadCompleted

public boolean hasFileLoadCompleted()
Has the component finished with the input file?

Parameters:
true - if the input file is closed

addNotify

public void addNotify()
Requests a repaint of the control once it has been created

Overrides:
addNotify in class javax.swing.JComponent

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
Overrides:
setBounds in class java.awt.Component

init

public void init()

createTinyBitmap

public com.tinyline.tiny2d.TinyBitmap createTinyBitmap(com.tinyline.tiny2d.TinyString uri)
Returns a TinyBitmap for the given image URL or path.

Specified by:
createTinyBitmap in interface com.tinyline.svg.ImageLoader
Parameters:
uri - The image URL or path.
Returns:
a TinyBitmap object which gets its pixel data from the specified URL or path.

createTinyBitmap

public com.tinyline.tiny2d.TinyBitmap createTinyBitmap(byte[] imageData,
                                                       int imageOffset,
                                                       int imageLength)
Creates a TinyBitmap which decodes the image stored in the specified byte array, and at the specified offset and length.

Specified by:
createTinyBitmap in interface com.tinyline.svg.ImageLoader
Parameters:
imageData - an array of bytes, representing image data in a supported image format.
imageOffset - the offset of the beginning of the data in the array.
imageLength - the length of the data in the array.
Returns:
a TinyBitmap object.

start

public void start()
Starts the events dispatching thread


stop

public void stop()
Stops the events dispatching thread


run

public void run()
The events dispatching thread run()

Specified by:
run in interface java.lang.Runnable

goURL

public void goURL(java.lang.String url)
Loads and dispalys an SVG document from the given URL. External hyperlinks handling


origView

public void origView()
Returns the current SVGT document to its original view.


switchQuality

public void switchQuality()
Switches the rendering quality of this SVGPlayer .


pauseResumeAnimations

public void pauseResumeAnimations()
Suspends or unsuspends all animations that are defined within the current SVGT document fragment.


imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int flags,
                           int x,
                           int y,
                           int width,
                           int height)
This method is called when information about an image which was previously requested using an asynchronous interface becomes available. Asynchronous interfaces are method calls such as getWidth(ImageObserver) and drawImage(img, x, y, ImageObserver) which take an ImageObserver object as an argument.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Overrides:
imageUpdate in class java.awt.Component
Parameters:
img - the image being observed.
flags - the image status flags.
x - the x coordinate.
y - the y coordinate.
width - the width.
height - the height.
Returns:
false if the infoflags indicate that the image is completely loaded; true otherwise.

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints this canvas

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - the specified Graphics context.

getMinimumSize

public java.awt.Dimension getMinimumSize()
The minimum size of the canvas.

Overrides:
getMinimumSize in class javax.swing.JComponent
Returns:
The minimum size of the canvas.

getPreferredSize

public java.awt.Dimension getPreferredSize()
The preferred size of the canvas.

Overrides:
getPreferredSize in class javax.swing.JComponent
Returns:
The preferred size of the canvas.

flush

public void flush()
Flushes the allocated resources.


loadSVG

public com.tinyline.svg.SVGDocument loadSVG(java.lang.String urlStr)
Loads an SVGT document from the given URL.

Parameters:
urlStr - The SVGT document URL or path.
Returns:
An SVGT document.

loadSVG

public com.tinyline.svg.SVGDocument loadSVG(java.io.InputStream is)
Loads an SVGT document from the given InputStream.

Parameters:
is - The InputStream.
Returns:
An SVGT document.

alertError

public void alertError(java.lang.String s)
StatusBar: shows an alert


alertWait

public void alertWait(java.lang.String s)
StatusBar: shows a wait


alertInit

public void alertInit(java.lang.String s)
StatusBar: inits the bar


postEvent

public void postEvent(SVGEvent theEvent)
Posts an event to the event queue.

Parameters:
theEvent - an instance of Event, or a subclass of it.

addEventListener

public void addEventListener(java.lang.String type,
                             EventListener listener,
                             boolean useCapture)
uDOM: This method allows the registration of event listeners on the event target.

Specified by:
addEventListener in interface EventTarget
Parameters:
type - The event type for which the user is registering
listener - The listener parameter takes an interface implemented by the user which contains the methods to be called when the event occurs.
useCapture - If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered EventListener before being dispatched to any EventTargets beneath them in the tree. Events which are bubbling upward through the tree will not trigger an EventListener designated to use capture.

removeEventListener

public void removeEventListener(EventListener listener)
uDOM: This method allows the removal of event listeners from the event target.

Specified by:
removeEventListener in interface EventTarget
Parameters:
listener - The listener parameter indicates the EventListener to be removed.

dispatchEvent

public boolean dispatchEvent(Event evt)
uDOM: This method allows the dispatch of events into the implementations event model. Events dispatched in this manner will have the same behavior as events dispatched directly by the implementation.

Specified by:
dispatchEvent in interface EventTarget
Parameters:
evt - Specifies the event type, behavior, and contextual information to be used in processing the event.
Returns:
The return value of dispatchEvent indicates whether any of the listeners which handled the event called preventDefault. If preventDefault was called the value is false, else the value is true.

setAttribute

public int setAttribute(java.lang.String attribName,
                        java.lang.Object attribValue)
Set one or more attributes of the component.

Specified by:
setAttribute in interface XAttributedComponent
Parameters:
attribName - the name of the attribute
attribValue - the value of the attribute
Returns:
0 for success, non zero for failure or to require some further action

setVisible

public void setVisible(boolean state)
Overrides:
setVisible in class javax.swing.JComponent

pan

public void pan(int x,
                int y)
Pan/scroll the image to toa new location

Parameters:
x - the number of pixels to move horizontally, moved the display viewport
y - the number of pixels to move vertically, moved the display viewport

zoom

public void zoom(double scaleFactor)
Zoom in on the image param scaleFactor the factor by which to adjust the scaling. Greater than 1.0 for zooming in and less than 1.0 for zooming out.


reset

public void reset()
Reset the image to its original size and position


updateImage

protected void updateImage()
Update the raster image