|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface SVGEventListener
The SVGEventListener
is used to forward platform-specific events
to an application. The application can implement this interface and, in
response, dispatch SVG events on an SVGImage
object.
Note: SVGEventListener
implementations are called back in the platform's event thread.
In MIDP, the SVGEventListener
is called back in the same thread as the one used to invoke
event methods on the javax.microedition.lcdui.Canvas
class extensions. In AWT, the
SVGEventListener
is called back in the AWT event thread.
// Create an SVGAnimator SVGImage map = ...; // See the SVGImage documentation. SVGAnimator svgAnimator = SVGAnimator.createAnimator(map); // Create an SVGEventListener and set it on the animator. MIDPSVGEventListener listener = new MIDPSVGEventListener(map, animator); svgAnimator.setSVGEventListener(listener); // // SVGEventListener sample implementation. Adds a new // circle every time a key is pressed. // class MIDPSVGEventListener implements SVGEventListener, Runnable { protected SVGDocument svgDocument; protected SVGAnimator svgAnimator; protected Vector addToTree = new Vector(); public MIDPSVGEventListener(SVGImage svgImage, SVGAnimator animator) { this.svgDocument = svgImage.getDocument(); this.svgAnimator = svgAnimator; } public void keyPressed(int keyCode) { SVGElement circle = svgDocument.createElementNS(svgNS, "circle"); circle.setFloatTrait("cx", ...); circle.setFloatTrait("cy", ...); // .... // We synchronized access to the addToTree vector because // it is accessed from different threads. Because we do // no know how fast this runnable is going to be scheduled // by the animator, it is possible that multiple circles // be created before the run() method is invoked. This explain // why we put all the newly created circles in a Vector and why // the run method inserts the current content of the vector // into the SVG document. synchronized (addToTree) { addToTree.addElement(circle); } svgAnimator.invokeLater(this); } public run() { synchronized (addToTree) { for (int i = 0; i < addToTree.size(); i++) { svgDocument.getDocumentElement().appendChild( (SVGElement) addToTree.elementAt(i)); } addToTree.clear(); } } }
Method Summary | |
---|---|
void |
hideNotify()
Invoked by the SVG implementation when the associated component is hidden. |
void |
keyPressed(int keyCode)
Invoked by the SVG implementation when a key was pressed while the component associated with the SVGAnimator had focus. |
void |
keyReleased(int keyCode)
Invoked by the SVG implementation when a key was released while the component associated with the SVGAnimator had focus. |
void |
pointerPressed(int x,
int y)
Invoked by the SVG implementation when the pointer device (if any), is pressed over the component associated with the SVGAnimator . |
void |
pointerReleased(int x,
int y)
Invoked by the SVG implementation when the pointer device (if any), is released over the component associated with the SVGAnimator . |
void |
showNotify()
Invoked by the SVG implementation when the associated component is shown. |
void |
sizeChanged(int width,
int height)
Invoked by the SVG implementation when the associated component is resized. |
Method Detail |
---|
void keyPressed(int keyCode)
SVGAnimator
had focus.
On MIDP, this method is invoked when the
javax.microedition.lcdui.Canvas.keyPressed()
method is
invoked.
On AWT, this method is invoked when the
java.awt.event.KeyListener.keyPressed()
method is invoked on
a java.awt.Component
's key listener.
keyCode
- the code of the key that was pressed. For MIDP, the code
is the same as for the javax.microedition.lcdui.Canvas
keyPressed
keyCode
argument. For AWT, the code
is the same as in the java.awt.event.KeyEvent.getKeyCode()
method.void keyReleased(int keyCode)
SVGAnimator
had focus.
On MIDP, this method is invoked when the
javax.microedition.lcdui.Canvas.keyReleased()
method is
invoked.
On AWT, this method is invoked when the
java.awt.event.KeyListener.keyReleased()
method is invoked on
a java.awt.Component
's key listener.
keyCode
- the code of the key that was pressed. For MIDP, the code
is the same as for the javax.microedition.lcdui.Canvas
keyReleased
keyCode
argument. For AWT, the code
is the same as in the java.awt.event.KeyEvent.getKeyCode()
method.void pointerPressed(int x, int y)
SVGAnimator
.
On MIDP, this method is invoked when the
javax.microedition.lcdui.Canvas.pointerPressed()
method is
invoked. Note that pointer events are only supported on MIDP if the
platform supports them, as defined by the
Canvas.hasPointerEvents
method.
On AWT, this method is invoked when the
java.awt.event.MouseListener.mousePressed()
method is invoked on
a java.awt.Component
's mouse listener.
x
- the x-axis coordinate, in the target component's space (i.e.,
relative to the upper left corner of the component associated with the
SVGAnimator
. On MIDP, this is the same value as passed to the
javax.microedition.midp.Canvas.pointerPressed()
method. On
AWT, this is the same value as returned from the
java.awt.event.MouseEvent.getX()
method.y
- the y-axis coordinate, in the target component's space (i.e.,
relative to the upper left corner of the component associated with the
SVGAnimator
. On MIDP, this is the same value as passed to the
javax.microedition.midp.Canvas.pointerPressed()
method. On
AWT, this is the same value as returned from the
java.awt.event.MouseEvent.getY()
method.void pointerReleased(int x, int y)
SVGAnimator
.
On MIDP, this method is invoked when the
javax.microedition.lcdui.Canvas.pointerReleased()
method is
invoked. Note that pointer events are only supported on MIDP if the
platform supports them, as defined by the
Canvas.hasPointerEvents
method.
On AWT, this method is invoked when the
java.awt.event.MouseListener.mouseReleased()
method is invoked on
a java.awt.Component
's mouse listener.
x
- the x-axis coordinate, in the target component's space (i.e.,
relative to the upper left corner of the component associated with the
SVGAnimator
. On MIDP, this is the same value as passed to the
javax.microedition.midp.Canvas.pointerReleased()
method. On
AWT, this is the same value as returned from the
java.awt.event.MouseEvent.getX()
method.y
- the y-axis coordinate, in the target component's space (i.e.,
relative to the upper left corner of the component associated with the
SVGAnimator
. On MIDP, this is the same value as passed to the
javax.microedition.midp.Canvas.pointerReleased()
method. On
AWT, this is the same value as returned from the
java.awt.event.MouseEvent.getY()
method.void hideNotify()
javax.microedition.lcdui.Canvas.hideNotify
method is invoked.
On AWT, this method is invoked when the java.awt.event.ComponentEvent
with type java.awt.event.ComponentEvent.COMPONENT_HIDDEN
is
invoked on a java.awt.Component
's component listener.
void showNotify()
javax.microedition.lcdui.Canvas.showNotify
method is invoked.
On AWT, this method is invoked when the java.awt.event.ComponentEvent
with type java.awt.event.ComponentEvent.COMPONENT_SHOWN
is
invoked on a java.awt.Component
's component listener.
void sizeChanged(int width, int height)
javax.microedition.lcdui.Canvas.sizeChanged
method is invoked.
On AWT, this method is invoked when the java.awt.event.ComponentEvent
with type java.awt.event.ComponentEvent.COMPONENT_RESIZED
is
invoked on a java.awt.Component
's component listener.
width
- the new component width.height
- the new component height.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |