Java源码示例:org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor

示例1
private void handleEdge(Edge edge, EditPart editPart, boolean sourceAnchor) {
	Anchor anchorToModify;
	if (sourceAnchor) {
		anchorToModify = edge.getSourceAnchor();
	} else {
		anchorToModify = edge.getTargetAnchor();
	}
	String terminalString = composeTerminalString(DEFAULT_POINT);
	if (anchorToModify instanceof IdentityAnchor) {
		terminalString = ((IdentityAnchor) anchorToModify).getId();
	}
	PrecisionPoint anchorPoint = BaseSlidableAnchor.parseTerminalString(terminalString);
	PrecisionPoint newPoint = computeNewAnchor(anchorPoint, editPart);
	String newTerminalString = new SlidableAnchor(null, newPoint).getTerminal();
	if (anchorToModify instanceof IdentityAnchor) {
		((IdentityAnchor) anchorToModify).setId(newTerminalString);
	} else if (anchorToModify == null) {
		// Create a new one
		IdentityAnchor newAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
		newAnchor.setId(newTerminalString);
		if (sourceAnchor) {
			edge.setSourceAnchor(newAnchor);
		} else {
			edge.setTargetAnchor(newAnchor);
		}
	}
}
 
示例2
/**
 * Test for setConnectionAnchors
 */
@Test
public void setConnectionAnchorsTest() {
	Pair<String, Class<?>> A = new Pair<String, Class<?>>("ClassA",
			org.eclipse.uml2.uml.Class.class);
	Pair<String, Class<?>> B = new Pair<String, Class<?>>("ClassB",
			org.eclipse.uml2.uml.Class.class);

	List<Pair<String, Class<?>>> objects = Arrays.asList(A, B);
	List<Pair<Pair<String, Class<?>>, Pair<String, Class<?>>>> associations = Arrays
			.asList(new Pair<Pair<String, Class<?>>, Pair<String, Class<?>>>(
					A, B));

	init(objects, associations);
	@SuppressWarnings("unchecked")
	List<EditPart> eps = getDiagramEditPart().getChildren();
	ClassEditPart classAEp = (ClassEditPart) eps.get(0);
	ClassEditPart classBEp = (ClassEditPart) eps.get(1);

	@SuppressWarnings("unchecked")
	List<ConnectionEditPart> conns = classBEp.getSourceConnections();
	ConnectionEditPart assoc = conns.get(0);
	DiagramElementsModifier.setConnectionAnchors(assoc, "(1, 0.5)",
			"(0, 0.5)");

	ConnectionAnchor source = classAEp.getSourceConnectionAnchor(assoc);
	ConnectionAnchor target = classBEp.getTargetConnectionAnchor(assoc);
	Point sourceReferencePoint = ((SlidableAnchor) source)
			.getReferencePoint();
	Point targetReferencePoint = ((SlidableAnchor) target)
			.getReferencePoint();
	PrecisionPoint sourceAnchor = SlidableAnchor.getAnchorRelativeLocation(
			sourceReferencePoint, source.getOwner().getBounds());
	PrecisionPoint targetAnchor = SlidableAnchor.getAnchorRelativeLocation(
			targetReferencePoint, target.getOwner().getBounds());

	Assert.assertEquals(new PrecisionPoint(1, 0.5), sourceAnchor);
	Assert.assertEquals(new PrecisionPoint(0, 0.5), targetAnchor);
}