Hi, i want to add polygon to my svgCanvas...i wrote this code but there is a
problem: when i click button "polygon" this activate 3 listener,
initializing flag = true, create = true and elem = 6. When i click on
svgCanvas point clicked is saved into a string "points", then when i reclick
the point is saved (concat) into "points", when i click 2 times string
"points" is add to attribute "points" and polygon is created. But when i
reclick button "polygon" and then when i click on svgCanvas the points is
saved 2 times into string "points"...
for example:
insert first polygon
points = 192,168 340,430 ...
when i reclick button polygon
points = 156,402 156,402 304,170 304,170 ....
why?
private class OnDownAction implements EventListener {
public void handleEvent(Event evt) {
Element svgRoot =
svgCanvas.getSVGDocument().getRootElement();
if(create == true){
DOMMouseEvent elEvt = (DOMMouseEvent)evt;
actionNode = elEvt.getTarget();
action = DRAG;
Node n = ((Element)elEvt.getTarget());
startPt = localPt((Element)n, elEvt.getClientX(),
elEvt.getClientY());
if(elem == 6){
if(flag = true){
points =
points+startPt.getX()+","+startPt.getY()+" ";
System.out.println(points);
if(elEvt.getDetail() == 2){
flag = false;
polygon =
svgCanvas.getSVGDocument().createElementNS(svgNS,
"polygon");
polygon.setAttributeNS(null, "id",
"bgpolygon");
polygon.setAttributeNS(null, "points",
points);
polygon.setAttributeNS(null, "style",
"fill:rgb("+
newColor.getRed()+ "," + newColor.getGreen()+","+newColor.getBlue()+");
stroke:none; stroke-width:0");
svgRoot.appendChild(polygon);
create = false;
actionNode = null;
elem = 0;
points = "";
}
}
}
}
}
}
private class OnUpAction implements EventListener {
public void handleEvent(Event evt) {
if(create == true && elem != 6){
Element svgRoot =
svgCanvas.getSVGDocument().getRootElement();
if(elem == 5){
Element text ....
....
}
if(elem != 6){
create = false;
actionNode = null;
elem = 0;
}
}
}
}
private class OnMoveAction implements EventListener {
public void handleEvent(Event evt) {
if(create == true && elem != 6){
Element svgRoot =
svgCanvas.getSVGDocument().getRootElement();
doc = svgCanvas.getSVGDocument();
if (actionNode == null)return;
DOMMouseEvent elEvt = (DOMMouseEvent)evt;
if (action == DRAG) {
Element ee = (Element)actionNode;
pt = localPt((Element)ee.getParentNode(),
elEvt.getClientX(), elEvt.getClientY());
dx = pt.getX() - startPt.getX();
dy = pt.getY() - startPt.getY();
switch(elem){
case 1:
rect...
break;
case 2:
circle...
break;
case 3:
ellipse...
break;
case 4:
line...
break;
}
}
}
}
}
--
View this message in context:
http://www.nabble.com/insert-polygon-tf2810417.html#a7842554
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]