logo       

Another Newbie question: grouping lines: msg#00008

Subject: Another Newbie question: grouping lines
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" <Thomas.DeWeese@xxxxxxxxx>
To: <batik-dev@xxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxx
> > For additional commands, e-mail: batik-dev-help@xxxxxxxxxxxxxx
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-dev-unsubscribe@xxxxxxxxxxxxxx
> For additional commands, e-mail: batik-dev-help@xxxxxxxxxxxxxx
>
>


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe