org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor Java Examples

The following examples show how to use org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AdjustIdentityAnchorCommand.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
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);
		}
	}
}
 
Example #2
Source File: DiagramElementsModifierTest.java    From txtUML with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}