Hi, Here is the sample code I'm using which doesn't work.
Thank you.
On 9/20/07, Cameron McCormack <[EMAIL PROTECTED]> wrote:
> Qian Li:
> > I have download the SVN from
> > http://svn.apache.org/repos/asf/xmlgraphics/batik/trunk/
> >
> > I have used ant jars to generate jar files, and I use
> > batik-1.7/batik.jar as my library.
> > However the mouse click getButton() still always returns me 1.
> >
> > Do you know what maybe wrong? Do you mind send me the related jar file
> > which I can use? Thank you so much for your help.
>
> Do you have an example document/program that doesn't work? This
> document works for me, for example:
>
> <svg xmlns='http://www.w3.org/2000/svg' width='400' height='300'>
> <rect width='100' height='100' onclick='alert(evt.button)'/>
> </svg>
>
> --
> Cameron McCormack, http://mcc.id.au/
> xmpp:[EMAIL PROTECTED] ▪ ICQ 26955922 ▪ MSN [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
/*
* TestBatikMouseClick.java
*
* Created on September 18, 2007, 5:18 PM
*/
package testsvg;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.swing.JSVGCanvas;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.EventTarget;
/**
*
* @author qianli
*/
public class TestBatikMouseClick extends javax.swing.JFrame {
Document doc;
Element svgRoot;
JSVGCanvas svgCanvas;
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
/** Creates new form TestBatikMouseClick */
public TestBatikMouseClick() {
initComponents();
svgCanvas = new JSVGCanvas();
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
doc = impl.createDocument(svgNS, "svg", null);
svgRoot = doc.getDocumentElement();
svgRoot.setAttribute("viewBox","0 0 500 500");
svgRoot.setAttribute("preserveAspectRatio","xMinYMin meet");
svgRoot.setAttributeNS(svgNS, "width", "500");
svgRoot.setAttributeNS(svgNS, "height", "500");
Element basicElement = doc.createElementNS(svgNS, "rect");
basicElement.setAttributeNS(null, "x", "20");
basicElement.setAttributeNS(null, "y", "20");
basicElement.setAttributeNS(null, "height", "100");
basicElement.setAttributeNS(null, "width", "100");
//basicElement.setAttributeNS(null, "style", "fill:white;stroke:black;stroke-width:5;opacity:0.5");
svgRoot.appendChild(basicElement);
EventTarget t = (EventTarget)basicElement;
t.addEventListener("click", new EventListener(){
public void handleEvent(org.w3c.dom.events.Event evt) {
doMouseClickEvent(evt); }
}, false);
svgCanvas.setDocument(doc);
jPanelMain.add(svgCanvas);
}
public void doMouseClickEvent(org.w3c.dom.events.Event evt){
org.w3c.dom.events.MouseEvent mEvt = (org.w3c.dom.events.MouseEvent)evt;
System.out.println("[BasicElementSVG::doMouseClickEvent] element Mouse Clicked -- type="+mEvt.getType()+" button="+mEvt.getButton());
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanelMain = new javax.swing.JPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanelMain.setLayout(new java.awt.BorderLayout());
jPanelMain.setPreferredSize(new java.awt.Dimension(500, 500));
getContentPane().add(jPanelMain, java.awt.BorderLayout.CENTER);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TestBatikMouseClick().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel jPanelMain;
// End of variables declaration//GEN-END:variables
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]