List Info

Thread: Re: a few questions..




Re: a few questions..
country flaguser name
Germany
2007-05-17 08:20:08
Hello shydisturbedboy,

> 1. how do i convert the coordinates of a rotated rect?
when i drag the
> rotated rect, it does not follow the mouse.. what
should i do?
maybe you post us at least your svg? and then, what mouse?
Did you
program sth like an editor yourself or are you using an svg
editor?


> 2. i have many <g> in my svg and they are all
overlapping.. how do i select
> an element under an element?
I think you meant nested, overlapping is not possible in an
xml-based
format. You can use XPath to shorten access to certain
elements or use
id's on the elements you want to access and use the
DOM-method
getElementById.

Cheers,

    Robert

------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org


Re: a few questions..
country flaguser name
United States
2007-05-17 08:06:22
i am trying to program it..

here are some snippets...

this is how i draw the rect:

    private void drawCell(float x, float y, float width,
float length) {
    	Element g = doc.getElementById("cell");
    	shape = doc.createElementNS(svgNS, "rect");
    	
    	shape.setAttributeNS(null, "x", x +
"");
    	shape.setAttributeNS(null, "y", y +
"");
    	shape.setAttributeNS(null, "width", width +
"");
    	shape.setAttributeNS(null, "height", length +
"");
    	shape.setAttribute("style",
"fill:#7cc576; stroke:#289728;
stroke-width:1.5; stroke-dasharray:3.3;fill-opacity:0.2;
stroke-opacity:0.8");
    	shape.setAttribute("transform",
"rotate(45 " + (x+width/2) + " " +
(y+length/2) + ")");
    	
    	g.appendChild(shape);
    }

and here is how i drag:

	private class OnDownAction implements EventListener {
        public void handleEvent(Event evt) {
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            actionNode = elEvt.getTarget();
            Node n = ((Element)elEvt.getTarget());
            startPt = convertPt((Element)n,
elEvt.getClientX(),
elEvt.getClientY());
            
            if(action == "DRAG") {
            	if(n.getLocalName() == "circle") {
            		startX =
Float.parseFloat(((Element)n).getAttribute("cx"));

            		startY =
Float.parseFloat(((Element)n).getAttribute("cy"));

            	}
            	else {
            		startX =
Float.parseFloat(((Element)actionNode).getAttribute("x&
quot;));
        			startY =
Float.parseFloat(((Element)actionNode).getAttribute("y&
quot;));
            	}
            }
            else if(action == "CELL") {
            	drawCell(startPt.getX(), startPt.getY(), 0,
0);
            }
        }
    }
    
    private class OnUpAction implements EventListener {
        public void handleEvent(Event evt) {
            if (actionNode != null) {
            	DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            	Element ee = (Element)elEvt.getTarget();
            	if(action == "CELL" && shape
!= null && endPt != null) {
            		shape.setAttribute("style",
"fill:#7cc576; stroke:#289728;
stroke-width:1.5;fill-opacity:0.2;
stroke-opacity:0.8");
            		shape = null;
            	}
                actionNode = null;
            }
        }
    }
    
    private class OnMoveAction implements EventListener {
    	public void handleEvent(Event evt) {
            Element ee = null;
            DOMMouseEvent elEvt = (DOMMouseEvent)evt;
            
            if (actionNode == null)
            	return;
            
            if (action == "DRAG") {
                ee = (Element)actionNode;
                if (ee.getParentNode() != null &&
ee.getParentNode()
instanceof Element &&
((Element)actionNode).getAttribute("id") !=
"mapBG") {
                    SVGPoint pt =
convertPt((Element)ee.getParentNode(),
elEvt.getClientX(), elEvt.getClientY());
                    moveElement(ee, pt.getX(), pt.getY());
                }
            }
            else if(action == "CELL") {
            	ee = (Element)actionNode;
            	endPt = convertPt((Element)ee.getParentNode(),
elEvt.getClientX(), elEvt.getClientY());
            	redrawCell(shape, endPt.getX(), endPt.getY());
            }
        }
    }
    
    private SVGPoint convertPt(Element elem, float x, float
y) {
        SVGDocument svgDocument =
svgCanvas.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 void moveElement(Element ee, float x, float y)
{
    	if(ee.getNodeName() == "circle") {
    		ee.setAttribute("cx", x - startPt.getX() +
startX + "");
    		ee.setAttribute("cy", y - startPt.getY() +
startY + "");
    	}
    	else {
    		ee.setAttribute("x", x - startPt.getX() +
startX + "");
    		ee.setAttribute("y", y - startPt.getY() +
startY + "");
    		System.out.println();
    	}
    }
-- 
View this message in context: http://www.nabble.com/a-few-questions..-tf377004
1.html#a10663791
Sent from the Batik - Users mailing list archive at
Nabble.com.


------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org


Re: a few questions..
country flaguser name
United States
2007-05-17 09:33:12
i also need guidance in loading/creating an svg in a
servlet.. please..
-- 
View this message in context: http://www.nabble.com/a-few-questions..-tf377004
1.html#a10665360
Sent from the Batik - Users mailing list archive at
Nabble.com.


------------------------------------------------------------
---------
To unsubscribe, e-mail: batik-users-unsubscribexmlgraphics.apache.org
For additional commands, e-mail: batik-users-helpxmlgraphics.apache.org


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )