in the Demo1View.java,instead of insertPointIntoLink(),I want to insert a JGOBasicNode at the point and relink them.the code is below but it dosn’t work,and the new inserted JGOBasicNode can’t be moved.
void insertBasicNodeintoLink()
{
if (getSelection().getPrimarySelection() instanceof JGoLink) {
JGoLink s = (JGoLink)getSelection().getPrimarySelection();
int i = s.getSegmentNearPoint(myMouseUpDocPoint);
if (s.getNumPoints() > 3) {
if (i < 1)
i = 1; // don't add to first segment
else if (i >= s.getNumPoints()-2)
i = s.getNumPoints()-3; // don't add to last segment
}
Point a = s.getPoint(i);
Point b = s.getPoint(i+1);
Point closest = new Point((a.x+b.x)/2, (a.y+b.y)/2);
getDocument().startTransaction();
JGoBasicNode bnode = new JGoBasicNode("3");
JGoRectangle rect = new JGoRectangle();
rect.setSize(20, 20);
bnode.setDrawable(rect);
bnode.setLocation(closest);
bnode.setBrush(JGoBrush.makeStockBrush(JGoBrush.ColorOrange));
bnode.setLabelSpot(JGoObject.Center);
bnode.setDraggable(true);
getDocument().getFirstLayer().addObjectAtTail(bnode);
JGoLabeledLink newlink=new JGoLabeledLink(bnode.getPort(),s.getToPort());
s.setToPort(bnode.getPort());
getDocument().getLinksLayer().addObjectAtTail(newlink);
s.insertPoint(i+1, closest);
//if (s.isOrthogonal()) // when orthogonal, gotta insert two points
//s.insertPoint(i+1, closest);
//getSelection().toggleSelection(s);
//selectObject(s);
getDocument().endTransaction("inserted node into link stroke");
}
}
{
if (getSelection().getPrimarySelection() instanceof JGoLink) {
JGoLink s = (JGoLink)getSelection().getPrimarySelection();
int i = s.getSegmentNearPoint(myMouseUpDocPoint);
if (s.getNumPoints() > 3) {
if (i < 1)
i = 1; // don't add to first segment
else if (i >= s.getNumPoints()-2)
i = s.getNumPoints()-3; // don't add to last segment
}
Point a = s.getPoint(i);
Point b = s.getPoint(i+1);
Point closest = new Point((a.x+b.x)/2, (a.y+b.y)/2);
getDocument().startTransaction();
JGoBasicNode bnode = new JGoBasicNode("3");
JGoRectangle rect = new JGoRectangle();
rect.setSize(20, 20);
bnode.setDrawable(rect);
bnode.setLocation(closest);
bnode.setBrush(JGoBrush.makeStockBrush(JGoBrush.ColorOrange));
bnode.setLabelSpot(JGoObject.Center);
bnode.setDraggable(true);
getDocument().getFirstLayer().addObjectAtTail(bnode);
JGoLabeledLink newlink=new JGoLabeledLink(bnode.getPort(),s.getToPort());
s.setToPort(bnode.getPort());
getDocument().getLinksLayer().addObjectAtTail(newlink);
s.insertPoint(i+1, closest);
//if (s.isOrthogonal()) // when orthogonal, gotta insert two points
//s.insertPoint(i+1, closest);
//getSelection().toggleSelection(s);
//selectObject(s);
getDocument().endTransaction("inserted node into link stroke");
}
}