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"));
startY =
Float.parseFloat(((Element)actionNode).getAttribute("y"));
}
}
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..-tf3770041.html#a10663791
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]