Thanks Thomas.

one final question. when drawing a freehand stroke i had been using the
mouseDragged action listener to run the paint method to draw a consecutive
straight lines from one point to the next (as i had always asumed it would
be done) however they are not recognised as one single stroke but as a
series of seperate joined lines which means they cannot be selected in their
entirity witha mouse click.

long story short.... is there another way to draw a freehand stroke to avoid
this? grouping the lines somehow??

As i said before im new to both java and svg so im sorry about what are
probably pretty stupid questions.

----- Original Message ----- 
From: "Thomas DeWeese" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, March 07, 2004 4:04 PM
Subject: Re: Newbie question: painting delays?


> Danny Browne wrote:
>
> > when adding an element to an svg document i am getting a short delay.
ie. it
> > takes a second or two for the element to appear after the mouse is
clicked.
> > This in it's self is not a major issue but when attempting to draw a
free
> > hand line dragging the mouse to quickly causes gaps to be created in the
> > line.
>
>     For complex SVG documents it might take a second or two for
> it to update after an element was added.  However I suspect that
> the problem is that you are not making your changes in the
> UpdateManager thread.
>
>     It looks like you probably want to run the 'paint' function
> in the UpdateManager thread:
>
>     final <sometype> myObject=this;
>     svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater
>        (new Runnable() {
> public void run() {
>    myOBject->paint(....);
>          });
>
> > am i doing this correctly? is there some code i am missing? can this be
> > rectified? my code is below and is rather hap hazzard any pointers on
> > cleaning it up would be appreciated...
> >
> > kind regards
> >
> > Danny Browne
> >
> >  public void registerListeners(){
> >
> >         // Set the canvas mouse listeners
> >         svgCanvas.addMouseListener(new java.awt.event.MouseAdapter() {
> >              public void mousePressed(java.awt.event.MouseEvent e) {
> >
> >              statusLabel.setText("Pressed......");
> >              startPoint = e;
> >
> >              }
> >
> >              public void mouseReleased(java.awt.event.MouseEvent e) {
> >
> >               int x = startPoint.getX();
> >               String sx = new Integer(x).toString();
> >               int y = startPoint.getY();
> >               String sy = new Integer(y).toString();
> >
> >               int w = e.getX();
> >               String sw = new Integer(w).toString();
> >               int h = e.getY();
> >               String sh = new Integer(h).toString();
> >
> >               w = w-x;
> >               h = h-y;
> >
> >
> >               paint(sx,sy,sw,sh);
> >
> >            }
> >         });
> >
> >         svgCanvas.addMouseMotionListener(new
> > java.awt.event.MouseMotionAdapter() {
> >              public void mouseDragged(java.awt.event.MouseEvent e) {
> >
> >                  int x = startPoint.getX();
> >                  String sx = new Integer(x).toString();
> >                  int y = startPoint.getY();
> >                  String sy = new Integer(y).toString();
> >                  int x2 = e.getX();
> >                  String sx2 = new Integer(x2).toString();
> >                  int y2 = e.getY();
> >                  String sy2 = new Integer(y2).toString();
> >
> >                  paint(sx,sy,sx2,sy2);
> >
> >                  startPoint = e;
> >              }
> >         });
> >
> >     }
> >
> >
> >
> > which calls this method paint method.
> >
> >
> >
> > public void paint (String sx, String sy, String sw, String sh){
> >
> >         toolType = getTool();
> >
> >         if (toolType == 1){
> >
> >           statusLabel.setText("Select Tool Selsected...");
> >
> >         }
> >
> >         else if (toolType == 2){
> >
> >           Document doc = svgCanvas.getSVGDocument();
> >
> >           String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> >
> >           // get the root element (the svg element)
> >           Element svgRoot = doc.getDocumentElement();
> >           // create the rectangle
> >           Element line = doc.createElementNS(svgNS, "line");
> >           line.setAttributeNS(null, "x", sx);
> >           line.setAttributeNS(null, "y", sy);
> >           line.setAttributeNS(null, "y2", sw);
> >           line.setAttributeNS(null, "y2", sh);
> >           line.setAttributeNS(null, "style",
"stroke:black;stroke-width:2");
> >           //attach the rectangle to the svg root element
> >           svgRoot.appendChild(line);
> >
> >         }
> >
> >         else if (toolType == 3){
> >
> >             statusLabel.setText("Paint Tool Selsected...");
> >
> >         }
> >
> >         else if (toolType == 4){
> >
> >           Document doc = svgCanvas.getSVGDocument();
> >
> >           String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> >
> >           statusLabel.setText("w: " +sw+ " h: " +sh+ " x: " +sx+ " y: "
> > +sy);
> >
> >           // get the root element (the svg element)
> >           Element svgRoot = doc.getDocumentElement();
> >           // create the rectangle
> >           Element line = doc.createElementNS(svgNS, "line");
> >           line.setAttributeNS(null, "x", sx);
> >           line.setAttributeNS(null, "y", sy);
> >           line.setAttributeNS(null, "y2", sw);
> >           line.setAttributeNS(null, "y2", sh);
> >           line.setAttributeNS(null, "style",
"stroke:black;stroke-width:2");
> >           //attach the rectangle to the svg root element
> >           svgRoot.appendChild(line);
> >
> >         }
> >
> >         else if (toolType == 5){
> >
> >           Document doc = svgCanvas.getSVGDocument();
> >
> >           String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> >
> >           // get the root element (the svg element)
> >           Element svgRoot = doc.getDocumentElement();
> >           // create the rectangle
> >           Element rectangle = doc.createElementNS(svgNS, "rect");
> >           rectangle.setAttributeNS(null, "x", sx);
> >           rectangle.setAttributeNS(null, "y", sy);
> >           rectangle.setAttributeNS(null, "width", sw);
> >           rectangle.setAttributeNS(null, "height", sh);
> >           rectangle.setAttributeNS(null, "fill", "black");
> >           //attach the rectangle to the svg root element
> >           svgRoot.appendChild(rectangle);
> >
> >         }
> >
> >         else if (toolType == 6){
> >
> >           Document doc = svgCanvas.getSVGDocument();
> >
> >           String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> >
> >           // get the root element (the svg element)
> >           Element svgRoot = doc.getDocumentElement();
> >           // create the rectangle
> >           Element circle = doc.createElementNS(svgNS, "circle");
> >           circle.setAttributeNS(null, "cx", sx);
> >           circle.setAttributeNS(null, "r", "25");
> >           circle.setAttributeNS(null, "cy", sy);
> >           circle.setAttributeNS(null, "style", "fill:crimson");
> >           //attach the rectangle to the svg root element
> >           svgRoot.appendChild(circle);
> >
> >         }
> >
> >     }
> >
> >
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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]
>
>



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

Reply via email to