Hi, i wrote this code to insert a rect when i click mouse, but in this way my
rect is inserted only when i click on a element present in my loaded file,
so i would that rect is inserted in every point clicked by mouse:
public JButton getProva() {
prova = new JButton();
prova.setText("rect");
prova.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent
e) {
move = false;
rectangle = true;
svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
public void run() {
SVGElement svgRoot =
svgCanvas.getSVGDocument().getRootElement();
EventTarget target =
(EventTarget)svgRoot;
target.addEventListener("click", new mouseClicked(), false);
}
});
}
});
return prova;
}
private class mouseClicked implements EventListener {
public void handleEvent(Event evt) {
if(rectangle == true){
Element rect =
svgCanvas.getSVGDocument().createElementNS(svgNS, "rect");
rect.setAttributeNS(null, "id", "bgrectangle");
rect.setAttributeNS(null, "x",""+
svgCanvas.getMousePosition().x);
rect.setAttributeNS(null, "y",""+
svgCanvas.getMousePosition().y);
rect.setAttributeNS(null, "width", "50");
rect.setAttributeNS(null, "height", "50");
rect.setAttributeNS(null, "pointer-events",
"fill");
rect.setAttributeNS(null, "fill", "rgb("+
newColor.getRed()+ "," +
newColor.getGreen()+","+newColor.getBlue()+")");
rect.setAttributeNS(null, "stroke", "none");
svgRoot.appendChild(rect);
rectangle = false;
}
}
}
--
View this message in context:
http://www.nabble.com/mouse-position-tf2665124.html#a7432595
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]