2 messages in org.netbeans.graph.usersRe: Overlapping connections
FromSent OnAttachments
BSE DeveloperMay 21, 2007 11:13 pm.png
David KasparMay 22, 2007 12:59 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Overlapping connectionsActions...
From:David Kaspar (Davi@Sun.COM)
Date:May 22, 2007 12:59:28 am
List:org.netbeans.graph.users

Hi Bernd,

The problem is that the anchor just defines a location of source and target point of the connection. The connection is painted as a line with defined stroke between the calculated points. Therefore the connection is painted this way. This is a limitation of the library, therefore you cannot specify the "clipping" of the connection by the anchors only.

To fix it, you have to create your own custom AnchorShape. There you can specify a "cut-distance" of particular end of a connection. See: AnchorShape.getCutDistance javadoc for details. Since in your case, you are not using any end-point shape, it is enough you implement the AnchorShape as: isLineOriented : return true; getRadius : return connection-stroke-width; getCutDistance : return connection-stroke-width; paint : <empty-body> Then set this shape using ConnectionWidget.setSourceAnchorShape and ConnectionWidget.setTargetAnchorShape methods.

Or you can use 2px-width line borders for your widgets, then the connection widget will not exceed a widget border.

Regards, David

BSE Developer wrote:

Hello,

I use a ConnectionWidget with a line width > 1 to connect two widgets. The result is shown in the attached picture. The problem is the overlapping connection into the widgets. The connection should end at the border (beyond) of the widgets. How can I achieve this representation ?

Regards, Bernd

Here is the modified ConnectionDemo code I use to create the picture:

public static void main (String[] args) { Scene scene = new Scene ();

LayerWidget mainLayer = new LayerWidget (scene); scene.addChild(mainLayer);

ImageWidget first = new ImageWidget (scene); first.setImage (Utilities.loadImage ("javaone/resources/a.png")); first.setPreferredLocation(new Point (100, 100)); first.getActions().addAction(ActionFactory.createMoveAction ()); first.setBorder(BorderFactory.createLineBorder(Color.RED, 1)); mainLayer.addChild(first);

ImageWidget second = new ImageWidget (scene); second.setImage (Utilities.loadImage ("javaone/resources/b.png")); second.setPreferredLocation(new Point (300, 200)); second.getActions().addAction(ActionFactory.createMoveAction ()); second.setBorder(BorderFactory.createLineBorder(Color.RED, 3)); mainLayer.addChild(second);

LayerWidget connectionLayer = new LayerWidget (scene); scene.addChild(connectionLayer);

ConnectionWidget connection = new ConnectionWidget (scene); connection.setSourceAnchor(AnchorFactory.createCircularAnchor (first, 32)); connection.setTargetAnchor (AnchorFactory.createCircularAnchor (second, 32)); connection.setStroke(new BasicStroke(5)); connection.setForeground(Color.GREEN);

connectionLayer.addChild(connection);

SceneSupport.show (scene.createView ()); }