javax.microedition.m2g
Interface SVGEventListener


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.



Code example:

 // 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

keyPressed

void keyPressed(int keyCode)
Invoked by the SVG implementation when a key was pressed while the component associated with the 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.

Parameters:
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.

keyReleased

void keyReleased(int keyCode)
Invoked by the SVG implementation when a key was released while the component associated with the 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.

Parameters:
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.

pointerPressed

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

Parameters:
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.

pointerReleased

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

Parameters:
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.

hideNotify

void hideNotify()
Invoked by the SVG implementation when the associated component is hidden. On MIDP, this method is invoked when the 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.


showNotify

void showNotify()
Invoked by the SVG implementation when the associated component is shown. On MIDP, this method is invoked when the 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.


sizeChanged

void sizeChanged(int width,
                 int height)
Invoked by the SVG implementation when the associated component is resized. On MIDP, this method is invoked when the 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.

Parameters:
width - the new component width.
height - the new component height.


Copyright © 2003-2006 Nokia Corporation. See the Copyright Notice for details.