Hi Peppe,

Peppe <[EMAIL PROTECTED]> wrote on 11/19/2006 02:37:52 PM:

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

   Then add an element that will sit behind all of the elements
in the canvas, you can color it or make it transparent:

        <rect x="-1000%" y="-1000%" width="3000%" height="3000%"
              fill="none" stroke="none" pointer-events="fill"/>

    Typically this should be the first element after 
the root '<svg>'.

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to