You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Peppe <pe...@gmail.com> on 2006/11/05 20:33:00 UTC

insert a rect into JSVGCanvas

Hi, i must to insert a rect into JSVGCanvas. This is the code that i wrote
but it doesn't nothing:

private JButton getProva() {
		if (prova == null) {
			prova = new JButton();
			prova.setBounds(new Rectangle(446, 13, 110, 35));
			prova.setText("pro");
			prova.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					SVGDocument doc = JSVGCanvas.getSVGDocument();
					SVGElement svgRoot = doc.getRootElement();
					JSVGCanvas.setDocument(doc);
					String svgNS = "http://www.w3.org/2000/svg";
					Element elem = doc.createElementNS(svgNS, "rect");
					elem.setAttributeNS(null, "id", "bgrectangle");
		            elem.setAttributeNS(null, "x", "200");
		            elem.setAttributeNS(null, "y", "100");
		            elem.setAttributeNS(null, "width", "100%");
		            elem.setAttributeNS(null, "height", "100%");
		            elem.setAttributeNS(null, "pointer-events", "fill");
		            elem.setAttributeNS(null, "style", "fill:none;stroke:none"); 
		            svgRoot.appendChild(elem);
				}
			});
		}
		return prova;
	}

"prova" is a JButton...
-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7188691
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: insert a rect into JSVGCanvas

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Peppe.

Peppe:
> Hi, i must to insert a rect into JSVGCanvas. This is the code that i wrote
> but it doesn't nothing:

When you set the document to be shown with .setDocument(doc), it is
asynchronously parsed and rendered.  You should wait until the document
has been built before performing the update.  See:

  http://xmlgraphics.apache.org/batik/svgcanvas.html#eventhandling

When performing the DOM modification in response to this event, you
should schedule it to be done in the canvas’ update thread.  See:

  http://xmlgraphics.apache.org/batik/javaScripting.html#Threads

Alternatively, if you only make modifications once, initially, you could
do them before the call to setDocument.

Cameron

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

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


RE: insert a rect into JSVGCanvas

Posted by th...@kodak.com.
Hi Peppe,

Peppe <pe...@gmail.com> wrote on 11/09/2006 04:14:12 AM:

> Please, someone can help me? it is important for me....i don't know what
> version i use of batik, trunk or branches? i know only that i use batik 
1.6

   Then the bug I mentioned can't be affecting you.  There is likely a bug 

in your code, I've looked over your code and it isn't obvious to me. 

   I would suggest adding println's to print the 'id' of the element that
is clicked on, to print the transform before you set it, etc...

   Good luck.

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


RE: insert a rect into JSVGCanvas

Posted by Peppe <pe...@gmail.com>.
Please, someone can help me? it is important for me....i don't know what
version i use of batik, trunk or branches? i know only that i use batik 1.6

-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7254794
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: insert a rect into JSVGCanvas

Posted by Peppe <pe...@gmail.com>.
I use the last version of Batik, version 1.6. Perhaps i wrong something in
file loading?...see my post "appendchild, error?"...thanks

thomas.deweese wrote:
> 
> Hi Peppe,
> 
> Peppe <pe...@gmail.com> wrote on 11/08/2006 04:07:02 AM:
> 
>> Thank you for answer. I use this code, wrote by another user to move my 
> rect,
>> but there is a problem: rect create in my JSVGCanvas don't move but the
>> elements in svg file loaded yes...why?
> 
>    Hmm, what Batik are you using?  Trunk?  If so you might be
> hitting a recently introduced bug in the animated transform support.
> You might try 'batik/branches/svg11' which is more stable but
> less feature right (most notably it lacks sXBL and animation
> support).
> 
>> in my code i do
>> svgRoot.appendChild(elem)....:
>> 
>> public JButton getProva() {
>>       if (prova == null) {
>>          prova = new JButton();
>>          prova.setBounds(new Rectangle(6, 139, 92, 31));
>>          prova.setText("rect");
>>          prova.addActionListener(new java.awt.event.ActionListener() {
>>             public void actionPerformed(java.awt.event.ActionEvent e) {  
> 
>> 
>> JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
>> Runnable() {
>>                   public void run() {
>>                         SVGDocument doc = JSVGCanvas.getSVGDocument();
>>                             JSVGCanvas.setDocument(doc);
>>                         SVGElement svgRoot = doc.getRootElement();
>>                         Element elem = doc.createElementNS(svgNS, 
> "rect");
>>                         elem.setAttributeNS(null, "id", "bgrectangle");
>>                         elem.setAttributeNS(null, "x","200");
>>                         elem.setAttributeNS(null, "y","100");
>>                         elem.setAttributeNS(null, "width", "50");
>>                         elem.setAttributeNS(null, "height", "50");
>>                         elem.setAttributeNS(null, "pointer-events", 
> "fill");
>>                         elem.setAttributeNS(null, "style", 
> "fill:red;stroke:none"); 
>>                         svgRoot.appendChild(elem);
>>                   }
>>                     });
>>                JSVGCanvas.repaint();
>>             }
>> 
>>          });
>>       }
>>       return prova;
>>    }
>> 
>>    private SVGPoint localPt(Element elem, int x, int y) {
>>         SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
>>         SVGMatrix mat = ((SVGLocatable)elem).getScreenCTM();
>>         SVGMatrix imat = mat.inverse();
>>         SVGPoint cPt = svgDocument.getRootElement().createSVGPoint();
>>         cPt.setX(x);
>>         cPt.setY(y);
>>         cPt = cPt.matrixTransform(imat);
>>         return cPt;
>>     }
>> 
>> 
>>     private class OnDownAction implements EventListener {
>>         public void handleEvent(Event evt) {
>>             DOMMouseEvent elEvt = (DOMMouseEvent)evt;
>>             actionNode = elEvt.getTarget();
>>             action = DRAG;
>>             Node n = ((Element)elEvt.getTarget()).getParentNode();
>>             startPt = localPt((Element)n, elEvt.getClientX(),
>> elEvt.getClientY
>> ());
>>             dragged = false;
>>         }
>>     }
>> 
>>     private class OnUpAction implements EventListener {
>>         public void handleEvent(Event evt) {
>>             if (actionNode != null) {
>>                 actionNode = null;
>>             }
>>         }
>>     }
>> 
>>     private class OnMoveAction implements EventListener {
>>         public void handleEvent(Event evt) {
>>             SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
>>             if (actionNode == null)return;
>>             dragged = true;
>>             DOMMouseEvent elEvt = (DOMMouseEvent)evt;
>>             if (action == DRAG) {
>>                 Element ee = 
> (Element)((Element)actionNode).getParentNode();
>>                 if (ee.getParentNode() != null && ee.getParentNode()
>> instanceof Element) {
>>                     SVGPoint pt = localPt((Element)ee.getParentNode(),
>> elEvt.getClientX(), elEvt.getClientY());
>>                     float dx = pt.getX() - startPt.getX();
>>                     float dy = pt.getY() - startPt.getY();
>>                     ee.setAttribute("transform", "translate(" + dx + ", 
> " +
>> dy
>> + ")");
>>                 }
>>             }
>>         }
>>     }
>> 
>>    /**
>>     * This method initializes muovi 
>>     * 
>>     * @return javax.swing.JToggleButton 
>>     */
>>    private JToggleButton getMuovi() {
>>       if (muovi == null) {
>>          muovi = new JToggleButton();
>>          muovi.setBounds(new Rectangle(6, 178, 94, 30));
>>          muovi.setText("muovi");
>>          muovi.addItemListener(new MuoviItemListener());
>>       }
>>       return muovi;
>>    }
>> 
>> public class MuoviItemListener implements ItemListener { 
>>    public void itemStateChanged(ItemEvent e) {
>>       int status = e.getStateChange(); 
>>       if(status == ItemEvent.SELECTED){
>>          SVGElement svgRoot = 
> JSVGCanvas.getSVGDocument().getRootElement();
>>          EventTarget t = (EventTarget)svgRoot;
>>          t.addEventListener("mousemove", new OnMoveAction(), false);
>>          t.addEventListener("mousedown", new OnDownAction(), false);
>>          t.addEventListener("mouseup", new OnUpAction(), false);
>>       }
>>    }
>> } 
>> 
>> 
>> -- 
>> View this message in context: http://www.nabble.com/insert-a-rect-into-
>> JSVGCanvas-tf2578737.html#a7234967
>> Sent from the Batik - Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7239182
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: insert a rect into JSVGCanvas

Posted by th...@kodak.com.
Hi Peppe,

Peppe <pe...@gmail.com> wrote on 11/08/2006 04:07:02 AM:

> Thank you for answer. I use this code, wrote by another user to move my 
rect,
> but there is a problem: rect create in my JSVGCanvas don't move but the
> elements in svg file loaded yes...why?

   Hmm, what Batik are you using?  Trunk?  If so you might be
hitting a recently introduced bug in the animated transform support.
You might try 'batik/branches/svg11' which is more stable but
less feature right (most notably it lacks sXBL and animation
support).

> in my code i do
> svgRoot.appendChild(elem)....:
> 
> public JButton getProva() {
>       if (prova == null) {
>          prova = new JButton();
>          prova.setBounds(new Rectangle(6, 139, 92, 31));
>          prova.setText("rect");
>          prova.addActionListener(new java.awt.event.ActionListener() {
>             public void actionPerformed(java.awt.event.ActionEvent e) {  

> 
> JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
> Runnable() {
>                   public void run() {
>                         SVGDocument doc = JSVGCanvas.getSVGDocument();
>                             JSVGCanvas.setDocument(doc);
>                         SVGElement svgRoot = doc.getRootElement();
>                         Element elem = doc.createElementNS(svgNS, 
"rect");
>                         elem.setAttributeNS(null, "id", "bgrectangle");
>                         elem.setAttributeNS(null, "x","200");
>                         elem.setAttributeNS(null, "y","100");
>                         elem.setAttributeNS(null, "width", "50");
>                         elem.setAttributeNS(null, "height", "50");
>                         elem.setAttributeNS(null, "pointer-events", 
"fill");
>                         elem.setAttributeNS(null, "style", 
"fill:red;stroke:none"); 
>                         svgRoot.appendChild(elem);
>                   }
>                     });
>                JSVGCanvas.repaint();
>             }
> 
>          });
>       }
>       return prova;
>    }
> 
>    private SVGPoint localPt(Element elem, int x, int y) {
>         SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
>         SVGMatrix mat = ((SVGLocatable)elem).getScreenCTM();
>         SVGMatrix imat = mat.inverse();
>         SVGPoint cPt = svgDocument.getRootElement().createSVGPoint();
>         cPt.setX(x);
>         cPt.setY(y);
>         cPt = cPt.matrixTransform(imat);
>         return cPt;
>     }
> 
> 
>     private class OnDownAction implements EventListener {
>         public void handleEvent(Event evt) {
>             DOMMouseEvent elEvt = (DOMMouseEvent)evt;
>             actionNode = elEvt.getTarget();
>             action = DRAG;
>             Node n = ((Element)elEvt.getTarget()).getParentNode();
>             startPt = localPt((Element)n, elEvt.getClientX(),
> elEvt.getClientY
> ());
>             dragged = false;
>         }
>     }
> 
>     private class OnUpAction implements EventListener {
>         public void handleEvent(Event evt) {
>             if (actionNode != null) {
>                 actionNode = null;
>             }
>         }
>     }
> 
>     private class OnMoveAction implements EventListener {
>         public void handleEvent(Event evt) {
>             SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
>             if (actionNode == null)return;
>             dragged = true;
>             DOMMouseEvent elEvt = (DOMMouseEvent)evt;
>             if (action == DRAG) {
>                 Element ee = 
(Element)((Element)actionNode).getParentNode();
>                 if (ee.getParentNode() != null && ee.getParentNode()
> instanceof Element) {
>                     SVGPoint pt = localPt((Element)ee.getParentNode(),
> elEvt.getClientX(), elEvt.getClientY());
>                     float dx = pt.getX() - startPt.getX();
>                     float dy = pt.getY() - startPt.getY();
>                     ee.setAttribute("transform", "translate(" + dx + ", 
" +
> dy
> + ")");
>                 }
>             }
>         }
>     }
> 
>    /**
>     * This method initializes muovi 
>     * 
>     * @return javax.swing.JToggleButton 
>     */
>    private JToggleButton getMuovi() {
>       if (muovi == null) {
>          muovi = new JToggleButton();
>          muovi.setBounds(new Rectangle(6, 178, 94, 30));
>          muovi.setText("muovi");
>          muovi.addItemListener(new MuoviItemListener());
>       }
>       return muovi;
>    }
> 
> public class MuoviItemListener implements ItemListener { 
>    public void itemStateChanged(ItemEvent e) {
>       int status = e.getStateChange(); 
>       if(status == ItemEvent.SELECTED){
>          SVGElement svgRoot = 
JSVGCanvas.getSVGDocument().getRootElement();
>          EventTarget t = (EventTarget)svgRoot;
>          t.addEventListener("mousemove", new OnMoveAction(), false);
>          t.addEventListener("mousedown", new OnDownAction(), false);
>          t.addEventListener("mouseup", new OnUpAction(), false);
>       }
>    }
> } 
> 
> 
> -- 
> View this message in context: http://www.nabble.com/insert-a-rect-into-
> JSVGCanvas-tf2578737.html#a7234967
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


RE: insert a rect into JSVGCanvas

Posted by Peppe <pe...@gmail.com>.
Thank you for answer. I use this code, wrote by another user to move my rect,
but there is a problem: rect create in my JSVGCanvas don't move but the
elements in svg file loaded yes...why? in my code i do
svgRoot.appendChild(elem)....:

public JButton getProva() {
		if (prova == null) {
			prova = new JButton();
			prova.setBounds(new Rectangle(6, 139, 92, 31));
			prova.setText("rect");
			prova.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {	
                   
JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
						public void run() {
								SVGDocument doc = JSVGCanvas.getSVGDocument();
	                			JSVGCanvas.setDocument(doc);
								SVGElement svgRoot = doc.getRootElement();
								Element elem = doc.createElementNS(svgNS, "rect");
								elem.setAttributeNS(null, "id", "bgrectangle");
								elem.setAttributeNS(null, "x","200");
								elem.setAttributeNS(null, "y","100");
								elem.setAttributeNS(null, "width", "50");
								elem.setAttributeNS(null, "height", "50");
								elem.setAttributeNS(null, "pointer-events", "fill");
								elem.setAttributeNS(null, "style", "fill:red;stroke:none"); 
								svgRoot.appendChild(elem);
						}
                    });
					JSVGCanvas.repaint();
				}

			});
		}
		return prova;
	}
	
	private SVGPoint localPt(Element elem, int x, int y) {
        SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
        SVGMatrix mat = ((SVGLocatable)elem).getScreenCTM();
        SVGMatrix imat = mat.inverse();
        SVGPoint cPt = svgDocument.getRootElement().createSVGPoint();
        cPt.setX(x);
        cPt.setY(y);
        cPt = cPt.matrixTransform(imat);
        return cPt;
    }


    private class OnDownAction implements EventListener {
        public void handleEvent(Event evt) {
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            actionNode = elEvt.getTarget();
            action = DRAG;
            Node n = ((Element)elEvt.getTarget()).getParentNode();
            startPt = localPt((Element)n, elEvt.getClientX(),
elEvt.getClientY
());
            dragged = false;
        }
    }

    private class OnUpAction implements EventListener {
        public void handleEvent(Event evt) {
            if (actionNode != null) {
                actionNode = null;
            }
        }
    }

    private class OnMoveAction implements EventListener {
        public void handleEvent(Event evt) {
            SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
            if (actionNode == null)return;
            dragged = true;
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            if (action == DRAG) {
                Element ee = (Element)((Element)actionNode).getParentNode();
                if (ee.getParentNode() != null && ee.getParentNode()
instanceof Element) {
                    SVGPoint pt = localPt((Element)ee.getParentNode(),
elEvt.getClientX(), elEvt.getClientY());
                    float dx = pt.getX() - startPt.getX();
                    float dy = pt.getY() - startPt.getY();
                    ee.setAttribute("transform", "translate(" + dx + ", " +
dy
+ ")");
                }
            }
        }
    }

	/**
	 * This method initializes muovi	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getMuovi() {
		if (muovi == null) {
			muovi = new JToggleButton();
			muovi.setBounds(new Rectangle(6, 178, 94, 30));
			muovi.setText("muovi");
			muovi.addItemListener(new MuoviItemListener());
		}
		return muovi;
	}

public class MuoviItemListener implements ItemListener { 
	public void itemStateChanged(ItemEvent e) {
		int status = e.getStateChange(); 
		if(status == ItemEvent.SELECTED){
			SVGElement svgRoot = JSVGCanvas.getSVGDocument().getRootElement();
			EventTarget t = (EventTarget)svgRoot;
			t.addEventListener("mousemove", new OnMoveAction(), false);
			t.addEventListener("mousedown", new OnDownAction(), false);
			t.addEventListener("mouseup", new OnUpAction(), false);
		}
	}
} 


-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7234967
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: insert a rect into JSVGCanvas

Posted by Peppe <pe...@gmail.com>.
Thank you for answer. I use this code, wrote by another user to move my rect,
but there is a problem: rect create in my JSVGCanvas don't move but the
elements in svg file loaded yes...why? in my code i do
svgRoot.appendChild(elem)....:

public JButton getProva() {
		if (prova == null) {
			prova = new JButton();
			prova.setBounds(new Rectangle(6, 139, 92, 31));
			prova.setText("rect");
			prova.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {	
                   
JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
						public void run() {
								SVGDocument doc = JSVGCanvas.getSVGDocument();
	                			JSVGCanvas.setDocument(doc);
								SVGElement svgRoot = doc.getRootElement();
								Element elem = doc.createElementNS(svgNS, "rect");
								elem.setAttributeNS(null, "id", "bgrectangle");
								elem.setAttributeNS(null, "x","200");
								elem.setAttributeNS(null, "y","100");
								elem.setAttributeNS(null, "width", "50");
								elem.setAttributeNS(null, "height", "50");
								elem.setAttributeNS(null, "pointer-events", "fill");
								elem.setAttributeNS(null, "style", "fill:red;stroke:none"); 
								svgRoot.appendChild(elem);
						}
                    });
					JSVGCanvas.repaint();
				}

			});
		}
		return prova;
	}
	
	private SVGPoint localPt(Element elem, int x, int y) {
        SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
        SVGMatrix mat = ((SVGLocatable)elem).getScreenCTM();
        SVGMatrix imat = mat.inverse();
        SVGPoint cPt = svgDocument.getRootElement().createSVGPoint();
        cPt.setX(x);
        cPt.setY(y);
        cPt = cPt.matrixTransform(imat);
        return cPt;
    }


    private class OnDownAction implements EventListener {
        public void handleEvent(Event evt) {
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            actionNode = elEvt.getTarget();
            action = DRAG;
            Node n = ((Element)elEvt.getTarget()).getParentNode();
            startPt = localPt((Element)n, elEvt.getClientX(),
elEvt.getClientY
());
            dragged = false;
        }
    }

    private class OnUpAction implements EventListener {
        public void handleEvent(Event evt) {
            if (actionNode != null) {
                actionNode = null;
            }
        }
    }

    private class OnMoveAction implements EventListener {
        public void handleEvent(Event evt) {
            SVGDocument svgDocument = JSVGCanvas.getSVGDocument();
            if (actionNode == null)return;
            dragged = true;
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            if (action == DRAG) {
                Element ee = (Element)((Element)actionNode).getParentNode();
                if (ee.getParentNode() != null && ee.getParentNode()
instanceof Element) {
                    SVGPoint pt = localPt((Element)ee.getParentNode(),
elEvt.getClientX(), elEvt.getClientY());
                    float dx = pt.getX() - startPt.getX();
                    float dy = pt.getY() - startPt.getY();
                    ee.setAttribute("transform", "translate(" + dx + ", " +
dy
+ ")");
                }
            }
        }
    }

	/**
	 * This method initializes muovi	
	 * 	
	 * @return javax.swing.JToggleButton	
	 */
	private JToggleButton getMuovi() {
		if (muovi == null) {
			muovi = new JToggleButton();
			muovi.setBounds(new Rectangle(6, 178, 94, 30));
			muovi.setText("muovi");
			muovi.addItemListener(new MuoviItemListener());
		}
		return muovi;
	}

public class MuoviItemListener implements ItemListener { 
	public void itemStateChanged(ItemEvent e) {
		int status = e.getStateChange(); 
		if(status == ItemEvent.SELECTED){
			SVGElement svgRoot = JSVGCanvas.getSVGDocument().getRootElement();
			EventTarget t = (EventTarget)svgRoot;
			t.addEventListener("mousemove", new OnMoveAction(), false);
			t.addEventListener("mousedown", new OnDownAction(), false);
			t.addEventListener("mouseup", new OnUpAction(), false);
		}
	}
} 
-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7219892
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: insert a rect into JSVGCanvas

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
The short answer is yes.  You'd record the point on mousePressed, record the point on mouseReleased and then transform them from screen coordinates to document coordinates and render the rectangle accordingly.
 
Michael Bishop

________________________________

From: Peppe [mailto:peppe.delia@gmail.com]
Sent: Tue 11/7/2006 4:09 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: insert a rect into JSVGCanvas





Finally with this code a rect shows in my JSVGCanvas; but in this way rect
shows in x=10 and y=10 position, there is a method where i can specify the
position and dimension via mouse?

private JButton getProva() {
                if (prova == null) {
                        prova = new JButton();
                        prova.setBounds(new Rectangle(446, 13, 110, 35));
                        prova.setText("rect");
                        prova.addActionListener(new java.awt.event.ActionListener() {
                                public void actionPerformed(java.awt.event.ActionEvent e) {
                                        JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
                                                public void run() {
                                                                SVGDocument doc = JSVGCanvas.getSVGDocument();
                                                                SVGElement svgRoot = doc.getRootElement();
                                                                JSVGCanvas.setDocument(doc);
                                                                String svgNS = "http://www.w3.org/2000/svg";
                                                                Element elem = doc.createElementNS(svgNS, "rect");
                                                                elem.setAttributeNS(null, "id", "bgrectangle");
                                                                elem.setAttributeNS(null, "x","10");
                                                                elem.setAttributeNS(null, "y","10");
                                                                elem.setAttributeNS(null, "width", "50");
                                                                elem.setAttributeNS(null, "height", "50");
                                                                elem.setAttributeNS(null, "pointer-events", "fill");
                                                                elem.setAttributeNS(null, "style", "fill:red;stroke:none");
                                                                svgRoot.appendChild(elem);
                                        }
                                });
                                        JSVGCanvas.repaint();
                                }
                        });
                }
                return prova;
        }
--
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7214836
Sent from the Batik - Users mailing list archive at Nabble.com.


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



RE: insert a rect into JSVGCanvas

Posted by Peppe <pe...@gmail.com>.

Finally with this code a rect shows in my JSVGCanvas; but in this way rect
shows in x=10 and y=10 position, there is a method where i can specify the
position and dimension via mouse?

private JButton getProva() {
		if (prova == null) {
			prova = new JButton();
			prova.setBounds(new Rectangle(446, 13, 110, 35));
			prova.setText("rect");
			prova.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
						public void run() {
								SVGDocument doc = JSVGCanvas.getSVGDocument();
								SVGElement svgRoot = doc.getRootElement();
								JSVGCanvas.setDocument(doc); 
								String svgNS = "http://www.w3.org/2000/svg";
								Element elem = doc.createElementNS(svgNS, "rect");
								elem.setAttributeNS(null, "id", "bgrectangle");
								elem.setAttributeNS(null, "x","10");
								elem.setAttributeNS(null, "y","10");
								elem.setAttributeNS(null, "width", "50");
								elem.setAttributeNS(null, "height", "50");
								elem.setAttributeNS(null, "pointer-events", "fill");
								elem.setAttributeNS(null, "style", "fill:red;stroke:none"); 
								svgRoot.appendChild(elem);
					}
				});
					JSVGCanvas.repaint();
				}
			});
		}
		return prova;
	}
-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7214836
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: insert a rect into JSVGCanvas

Posted by Peppe <pe...@gmail.com>.
This is the code where i load the svg image:

private JButton getJButton() {
		
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(10, 5, 59, 28));
			jButton.setText("load");
			jButton.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent ae) {
	                JFileChooser fc = new JFileChooser(".");
	                int choice = fc.showOpenDialog(panel);
	                if (choice == JFileChooser.APPROVE_OPTION) {
	                    File f = fc.getSelectedFile();
	                    try{
	                    	JSVGCanvas.setURI(f.toURL().toString());  //carica
l'immagine dal file all'interno del canvas
	                		
	                    	//JSVGCanvas listener
	                        JSVGCanvas.addSVGDocumentLoaderListener(new
SVGDocumentLoaderAdapter() {
	                            public void
documentLoadingStarted(SVGDocumentLoaderEvent e) {
	                                label.setText("Caricamento immagine...");
	                            }
	                            public void
documentLoadingCompleted(SVGDocumentLoaderEvent e) {
	                                label.setText("Immagine caricata");
	                            }
	                        });

	                        JSVGCanvas.addGVTTreeBuilderListener(new
GVTTreeBuilderAdapter() {
	                            public void gvtBuildStarted(GVTTreeBuilderEvent
e) {
	                                label.setText("Build Started...");
	                            }
	                            public void
gvtBuildCompleted(GVTTreeBuilderEvent e) {
	                                label.setText("Build Done.");
	                            }
	                        });

	                        JSVGCanvas.addGVTTreeRendererListener(new
GVTTreeRendererAdapter() {
	                            public void
gvtRenderingPrepare(GVTTreeRendererEvent e) {
	                                label.setText("Rendering Started...");
	                            }
	                            public void
gvtRenderingCompleted(GVTTreeRendererEvent e) {
	                                label.setText("");
	                            }
	                        });
	                    }catch(IOException error){
	                    	error.printStackTrace();
	                    }
	                }
	                }
	            });
		}
		return jButton;
	}


when i press JButton "prova" my console shows this error:
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
	at cnr.itd.thesis.delia.tesi$4.actionPerformed(tesi.java:230)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

where tesi.java:230 is the following line:
JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
 

-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7197300
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: insert a rect into JSVGCanvas

Posted by th...@kodak.com.
Hi Peppe,

    I noticed a few things that look problematic in your example.
First I don't see where you load the base document.  In which case
getDocument()

Peppe <pe...@gmail.com> wrote on 11/06/2006 06:15:46 AM:

> Set the JSVGCanvas's state to ALWAYS_DYNAMIC and run the code that 
modifies
> the document in the JSVGCanvas's RunnableQueue.

>                         SVGDocument doc = JSVGCanvas.getSVGDocument();

   So this would return null.

>                         Point2D pt2d = null;
>                         SVGElement svgRoot = doc.getRootElement();

>                         JSVGCanvas.setDocument(doc);

   You should not call 'setDocument'.

>                         String svgNS = "http://www.w3.org/2000/svg";
>                         Element elem = doc.createElementNS(svgNS, 
"rect");
>                         elem.setAttributeNS(null, "id", "bgrectangle");
>                         elem.setAttributeNS(null, "x",""+pt2d.getX());

   Isn't 'pt2d' null here?  You null it out above and I don't see where
you assign it.

   All of which leads me to believe that you are not looking at the
error messages the JVM is spitting out.  I understand you are running
in an Applet but usually there is a way to show the error log from
the browser.


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


RE: insert a rect into JSVGCanvas

Posted by Peppe <pe...@gmail.com>.


Set the JSVGCanvas's state to ALWAYS_DYNAMIC and run the code that modifies
the document in the JSVGCanvas's RunnableQueue.
 
Michael Bishop

Thank you for your answers, i modified code in this way but it doesn't
works....sorry but it's my first time that i use batik:

//This code is wrote in a JApplet class

private JSVGCanvas getJSVGCanvas() {
		if (JSVGCanvas == null) {
			JSVGCanvas = new JSVGCanvas();
			JSVGCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); 
			JSVGCanvas.setBounds(new Rectangle(114, 54, 476, 333));
			JSVGCanvas.getInteractors().add(rotateInteractor);
			JSVGCanvas.getInteractors().add(zoomInteractor);
		}
		return JSVGCanvas;
	} 

private JButton getProva() {
		if (prova == null) {
			prova = new JButton();
			prova.setBounds(new Rectangle(446, 13, 110, 35));
			prova.setText("pro");
			prova.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JSVGCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
						public void run() {
								SVGDocument doc = JSVGCanvas.getSVGDocument();
								Point2D pt2d = null;
								SVGElement svgRoot = doc.getRootElement();
								JSVGCanvas.setDocument(doc);
								String svgNS = "http://www.w3.org/2000/svg";
								Element elem = doc.createElementNS(svgNS, "rect");
								elem.setAttributeNS(null, "id", "bgrectangle");
								elem.setAttributeNS(null, "x",""+pt2d.getX());
								elem.setAttributeNS(null, "y",""+pt2d.getY());
								elem.setAttributeNS(null, "width", "100%");
								elem.setAttributeNS(null, "height", "100%");
								elem.setAttributeNS(null, "pointer-events", "fill");
								elem.setAttributeNS(null, "style", "fill:none;stroke:none"); 
								svgRoot.appendChild(elem);
					}
				});
					JSVGCanvas.repaint();
				}
			});
		}
		return prova;
	}
-- 
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7196933
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: insert a rect into JSVGCanvas

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
Set the JSVGCanvas's state to ALWAYS_DYNAMIC and run the code that modifies the document in the JSVGCanvas's RunnableQueue.
 
Michael Bishop

________________________________

From: Peppe [mailto:peppe.delia@gmail.com]
Sent: Sun 11/5/2006 2:33 PM
To: batik-users@xmlgraphics.apache.org
Subject: insert a rect into JSVGCanvas




Hi, i must to insert a rect into JSVGCanvas. This is the code that i wrote
but it doesn't nothing:

private JButton getProva() {
                if (prova == null) {
                        prova = new JButton();
                        prova.setBounds(new Rectangle(446, 13, 110, 35));
                        prova.setText("pro");
                        prova.addActionListener(new java.awt.event.ActionListener() {
                                public void actionPerformed(java.awt.event.ActionEvent e) {
                                        SVGDocument doc = JSVGCanvas.getSVGDocument();
                                        SVGElement svgRoot = doc.getRootElement();
                                        JSVGCanvas.setDocument(doc);
                                        String svgNS = "http://www.w3.org/2000/svg";
                                        Element elem = doc.createElementNS(svgNS, "rect");
                                        elem.setAttributeNS(null, "id", "bgrectangle");
                            elem.setAttributeNS(null, "x", "200");
                            elem.setAttributeNS(null, "y", "100");
                            elem.setAttributeNS(null, "width", "100%");
                            elem.setAttributeNS(null, "height", "100%");
                            elem.setAttributeNS(null, "pointer-events", "fill");
                            elem.setAttributeNS(null, "style", "fill:none;stroke:none");
                            svgRoot.appendChild(elem);
                                }
                        });
                }
                return prova;
        }

"prova" is a JButton...
--
View this message in context: http://www.nabble.com/insert-a-rect-into-JSVGCanvas-tf2578737.html#a7188691
Sent from the Batik - Users mailing list archive at Nabble.com.


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