Yes, I tried something like that. Coding is:
Element e = document.getElementById("arect");
Double x = Double.parseDouble(e.getAttributeNS(null, "x"));
System.out.println(x);
However, all I'm getting is the orginal coordinates.
Here is my test coding:
public class SVGApplication implements MouseListener {
public static void main(String[] args) {
new SVGApplication();
}
JFrame frame;
JSVGCanvas canvas;
Document document;
Window window;
int pressed;
UpdateManager um;
JLabel label = new JLabel();
public SVGApplication() {
SVGTest svgTest = new SVGTest();
svgTest.testing();
document = svgTest.getDocument();
document.setDocumentURI(svgTest.getSVGNS());
frame = new JFrame("SVG Application");
canvas = new JSVGCanvas();
JPanel jPanelA = new JPanel(new BorderLayout());
JPanel jPanelB = new JPanel(new FlowLayout(FlowLayout.TRAILING));
canvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
canvas.setDisableInteractions(false);
jPanelB.add(label);
jPanelB.setBackground(Color.WHITE);
jPanelA.add(jPanelB, BorderLayout.PAGE_END);
jPanelA.add(canvas, BorderLayout.CENTER);
canvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
public void gvtBuildStarted(GVTTreeBuilderEvent e) {
label.setText("Build Started...");
}
public void gvtBuildCompleted(GVTTreeBuilderEvent e) {
label.setText("Build Completed...");
//frame.pack();
}
});
canvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
label.setText("Rendering Started...");
}
public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
label.setText("Rendering Completed...");
um = canvas.getUpdateManager();
um.getUpdateRunnableQueue().invokeLater(new Runnable(){
public void run() {
update();
}
});
}
});
canvas.addMouseListener(this);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
frame.getContentPane().add(jPanelA);
frame.setSize(400,400);
frame.setVisible(true);
canvas.setDocument(document);
}
public void mousePressed(MouseEvent e) {
pressed += e.getClickCount();
label.setText("Mouse Pressed " + pressed + " times!!!");
um.getUpdateRunnableQueue().invokeLater(new Runnable(){
public void run() {
update();
}
});
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseClicked(MouseEvent e) {
}
public void update() {
Element e = document.getElementById("arect");
Double x = Double.parseDouble(e.getAttributeNS(null, "x"));
System.out.println(x);
}
}
What am I doing wrong?
Phil Wright-2 wrote:
>
> Are you trying something like:
>
> Element e = document.getElementById (svgID);
> Double x = Double.parseDouble(e..getAttributeNS(null, "x"));
> Double y = Double.parseDouble(e..getAttributeNS(null, "y"));
>
> Of course all that presumes that you have assigned your Elements unique
> IDs
> such that getElementByID() has something to work with.
>
> Phil
>
> On 12/4/06, vyang <[EMAIL PROTECTED]> wrote:
>>
>>
>> I tried something like yours, however I can't seem to get the coordinates
>> of
>> my rectangles when I moved them in JSVGCanvas. How do I retrieve the
>> location/coordinates of the new rectangles from the canvas?
>>
>>
>>
>> Phil Wright-2 wrote:
>> >
>> > Hi V,
>> >
>> > I do it this way:
>> >
>> > public void moveTo(String svgID, Point2D.Double location,
>> JSVGCanvas
>> > canvas) {
>> > SVGDocument document = canvas.getSVGDocument();
>> > final Element e = document.getElementById(svgID);
>> > final Point2D.Double newLoc = location;
>> >
>> > canvas.getUpdateManager
>> ().getUpdateRunnableQueue().invokeLater(new
>> > Runnable() {
>> > public void run() {
>> > e.setAttributeNS(null, "x", "" + newLoc.x);
>> > e.setAttributeNS(null, "y", "" + newLoc.y);
>> > }
>> > });
>> > }
>> >
>> > This particular method is specifically for moving "rect"
>> elements. Other
>> > elements can be handled similarly.
>> >
>> > Hope that helps,
>> >
>> > Phil
>> >
>> > On 12/1/06, vyang <[EMAIL PROTECTED]> wrote:
>> >>
>> >>
>> >> Hello;
>> >>
>> >> I was wondering how I would update a document using JSVGCanvas. I
>> have
>> >> written a simple java file that creates a document that has 2
>> rectangles
>> >> in
>> >> them. I then use JSVGCanvas to display it. I load the document into
>> >> JSVGCanvas using setDocument(). Now what I want to do is that when I
>> >> move(or do things in JSVGCanvas) I would like that to update to my
>> >> document.
>> >> How would I go about doing that? Any help would be much appreciated.
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/JSVGCanvas-Update-tf2740725.html#a7646942
>> >> Sent from the Batik - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >> For additional commands, e-mail:
>> [EMAIL PROTECTED]
>> >>
>> >>
>> >
>> >
>> > --
>> > Visit http://www.darkisle.com for photos of castles, cairns and other
>> > historic sites in the British Isles.
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/JSVGCanvas-Update-tf2740725.html#a7684465
>> Sent from the Batik - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
> --
> Visit http://www.darkisle.com for photos of castles, cairns and other
> historic sites in the British Isles.
>
>
--
View this message in context:
http://www.nabble.com/JSVGCanvas-Update-tf2740725.html#a7700328
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]