In your Overlay's paint method, clear the rectangle first.

g2d.clearRect(0, 0, width, height);

Michael Bishop 

> -----Original Message-----
> From: javaNoob [mailto:[EMAIL PROTECTED] 
> Sent: Sunday, July 06, 2008 1:39 AM
> To: batik-users@xmlgraphics.apache.org
> Subject: Re: Select an element and draw it on the canvas 
> without updating the svg
> 
> 
> help!! how can i drag a shape on an overlay properly? i can 
> drag a shape but i cannot erase the previously paited shape..
> 
> here is my code:
> 
> import java.awt.Color;
> import java.awt.Graphics;
> import java.awt.Graphics2D;
> import java.awt.event.InputEvent;
> import java.awt.event.MouseEvent;
> 
> import org.apache.batik.swing.gvt.InteractorAdapter;
> import org.apache.batik.swing.gvt.JGVTComponent;
> import org.apache.batik.swing.gvt.Overlay;
> 
> public class CustomInteractor extends InteractorAdapter {
> 
>     protected boolean finished = true;
>     protected Overlay overlay = new MyOverlay();
>     int x = 0;
>     int y = 0;
> 
>     @Override
>     public boolean startInteraction(InputEvent ie) {
>         return true;
>     }
> 
>     @Override
>     public boolean endInteraction() {
>         return finished;
>     }
> 
>     @Override
>     public void mousePressed(MouseEvent e) {
>         x = e.getX();
>         y = e.getY();
>         JGVTComponent c = (JGVTComponent) e.getSource();
>         c.getOverlays().add(overlay);
>     }
> 
>     @Override
>     public void mouseReleased(MouseEvent e) {
>         x = e.getX();
>         y = e.getY();
>         finished = true;
>         JGVTComponent c = (JGVTComponent) e.getSource();
>         c.getOverlays().remove(overlay);
>     }
> 
>     @Override
>     public void mouseDragged(MouseEvent e) {
>         x = e.getX();
>         y = e.getY();
>         JGVTComponent c = (JGVTComponent) e.getSource();
>         overlay.paint(c.getGraphics());
>     }
> 
>     protected class MyOverlay implements Overlay {
> 
>         public void paint(Graphics g) {
>             Graphics2D g2d = (Graphics2D) g;
>             g2d.setColor(new Color(255, 0, 0, 128));
>             g2d.fillRect(x - 5, y - 5, 10, 10);
>         }
>     }
> }
> --
> View this message in context: 
> http://www.nabble.com/Select-an-element-and-draw-it-on-the-can
> vas-without-updating-the-svg-tp18189565p18299068.html
> 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