mikekh
August 29, 2006, 5:50am
1
Apologies for the elementary nature of this question but my brain keeps having a stack overflow!
I have an extension of JGoIconicNode and I want to attach to it a port.
The image in the node is 40x40 pixels and I want the center of the port
to be mid-way along the bottom of the image and 10 pixels
vertically outside of the image.
I have tried modifying my code based on the examples but without success - I think I’m missing the point somewhere.
Many thanks
Mike
walter
August 29, 2006, 7:53am
2
public class TwoPortIconicNode extends JGoIconicNode { public TwoPortIconicNode() { super(); }
public TwoPortIconicNode(String s) { super(s); // create and add an extra port myExtraPort = createExtraPort(); addObjectAtHead(myExtraPort); }
protected JGoPort createExtraPort() { JGoPort p = new JGoPort(); p.setSize(8, 8); p.setStyle(JGoPort.StyleDiamond); p.setPen(JGoPen.blue); p.setBrush(JGoBrush.white); p.setFromSpot(BottomCenter); p.setToSpot(BottomCenter); return p; }
protected void copyChildren(JGoArea newarea, JGoCopyEnvironment env) { TwoPortIconicNode newobj = (TwoPortIconicNode)newarea; super.copyChildren(newarea, env); newobj.myExtraPort = (JGoPort)env.get(myExtraPort); }
public void layoutChildren(JGoObject childchanged) { if (isInitializing()) return; // move label to the top, centered if (getLabel() != null && getIcon() != null) { setLabelOffset(getIcon().getWidth() / 2 - getLabel().getWidth() / 2, -getLabel().getHeight()); } super.layoutChildren(childchanged); // positions Label and Port // position extra port below the bottom if (getExtraPort() != null && getIcon() != null) { Point p = getIcon().getSpotLocation(BottomCenter); getExtraPort().setSpotLocation(Center, p.x, p.y + 10); } }
public JGoPort getExtraPort() { return myExtraPort; }
private JGoPort myExtraPort; }
mikekh
August 30, 2006, 5:05am
3
Thanks Walter, I understand now.