diff -r 023eef975703 -r abc41079b313 javauis/m2g_qt/javasrc/javax/microedition/m2g/SVGEventListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/javauis/m2g_qt/javasrc/javax/microedition/m2g/SVGEventListener.java Fri Jul 23 12:27:20 2010 +0300
@@ -0,0 +1,233 @@
+/*
+* Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+
+package javax.microedition.m2g;
+
+/**
+ * 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.
+ *
+ *
+ *
+ * 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(); + * } + * } + * } + *+ * + */ +public interface SVGEventListener +{ + /** + * 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.
+ *
+ */
+ void hideNotify();
+
+ /**
+ * 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.
+ *
+ * @param 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 keyPressed(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.
+ *
+ * @param 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 keyReleased(int keyCode);
+
+ /**
+ * 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.
+ *
+ * @param 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.
+ *
+ * @param 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 pointerPressed(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.
+ *
+ * @param 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.
+ *
+ * @param 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 pointerReleased(int x, int y);
+
+ /**
+ * 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.
+ *
+ */
+ void showNotify();
+
+ /**
+ * 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.
+ *
+ * @param width the new component width.
+ * @param height the new component height.
+ */
+ void sizeChanged(int width, int height);
+}
+