You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by "Wilkins, Rob" <RW...@tandbergtv.com> on 2004/03/02 10:48:05 UTC

JSVGCanvas interactors

Hello,
 
We've written an application that allows the user to place objects on top of
an object derived from a JSVGCanvas object (using the JSVGCanvas.add()). The
derived object is placed within a JSVGScrollPane. This all works really
well.
 
However, we've noticed that should the user trigger the use of one of the
Interactors (for example the rubber band zoom interactor) when the mouse
moves over one of our overlayed objects the interaction via the Interactor
is terminated.
 
What do we need to do to allow the mouse to move over our overlayed objects
but maintain the interaction that is already in progress (if there is one)?
 
Thanks,
 
Rob
 
-------------------------------------------------------------------
Rob Wilkins,
Tandberg Television,  Control & Management Software,
Strategic Park, Comines Way, Hedge End, Southampton, 
Hampshire, SO30 4DA.
 
Tel: (023) 8057 3116 (Int. Ex 3116) Fax: (023)  8057 3341 
E-Mail:   <ma...@tandbergtv.com> rwilkins@tandbergtv.com
 


***********************************************************************************
This email, its content and any attachments is PRIVATE AND
CONFIDENTIAL to TANDBERG Television. If received in error please
notify the sender and destroy the original message and attachments.

www.tandbergtv.com
***********************************************************************************


Re: Another Newbie question: grouping lines

Posted by Tonny Kohar <to...@kiyut.com>.
Hi,

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

How about like this draw your freehand stroke object using Java Shape,
then convert that Shape.pathIterator into SVG Path Element in one go.

or Put that separate joined lines into under single <g> element.

Regards
Tonny Kohar
-- 
Sketsa 
SVG Graphics Editor
http://www.kiyut.com



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Another Newbie question: grouping lines

Posted by Danny Browne <da...@eircom.net>.
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" <Th...@Kodak.com>
To: <ba...@xml.apache.org>
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: batik-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: batik-dev-help@xml.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: Newbie question: painting delays?

Posted by Thomas DeWeese <Th...@Kodak.com>.
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: batik-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-dev-help@xml.apache.org
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Newbie question: painting delays?

Posted by Danny Browne <da...@eircom.net>.
small question.

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.

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: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org


Re: JSVGCanvas interactors

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Rob,

    I suspect that this is a awt/swing issue.  So you need to change
the default swing event dispatching in the JSVGCanvas so that when
an interactor is active it doesn't dispatch events to child
components.  To be honest I don't know exactly how this would be done,
it might be that you could override getComponentAt(...) to always
return this when interactor!= null.

Wilkins, Rob wrote:

> 
> 
> Hello,
> 
>  
> 
> We’ve written an application that allows the user to place objects on 
> top of an object derived from a JSVGCanvas object (using the 
> JSVGCanvas.add()). The derived object is placed within a JSVGScrollPane. 
> This all works really well.
> 
>  
> 
> However, we’ve noticed that should the user trigger the use of one of 
> the Interactors (for example the rubber band zoom interactor) when the 
> mouse moves over one of our overlayed objects the interaction via the 
> Interactor is terminated.
> 
>  
> 
> What do we need to do to allow the mouse to move over our overlayed 
> objects but maintain the interaction that is already in progress (if 
> there is one)?
> 
>  
> 
> Thanks,
> 
>  
> 
> Rob
> 
>  
> 
> -------------------------------------------------------------------
> 
> Rob Wilkins,
> 
> Tandberg Television,  Control & Management Software,
> 
> Strategic Park, Comines Way , Hedge End, Southampton ,
> 
> Hampshire , SO30 4DA .
> 
>  
> 
> Tel: (023) 8057 3116 (Int. Ex 3116) Fax: (023)  8057 3341
> 
> E-Mail:  rwilkins@tandbergtv.com <ma...@tandbergtv.com>
> 
>  
> 
> 
> 
> ***********************************************************************************
> This email, its content and any attachments is PRIVATE AND
> CONFIDENTIAL to TANDBERG Television. If received in error please
> notify the sender and destroy the original message and attachments.
> 
> www.tandbergtv.com
> ***********************************************************************************



---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-dev-help@xml.apache.org