use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class LocationControlImpl method handleArrowKeys.
private void handleArrowKeys(final KeyboardEvent.Key... keys) {
final int selectedIDsCount = selectedIDs.size();
if (selectedIDsCount == 0) {
return;
}
double movementDistance = NORMAL_DISTANCE;
if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.CONTROL)) {
movementDistance = LARGE_DISTANCE;
} else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.SHIFT)) {
movementDistance = SHORT_DISTANCE;
}
double horizontalDistance = 0d;
double verticalDistance = 0d;
if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_LEFT)) {
horizontalDistance = -movementDistance;
} else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_RIGHT)) {
horizontalDistance = movementDistance;
}
if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_UP)) {
verticalDistance = -movementDistance;
} else if (KeysMatcher.isKeyMatch(keys, KeyboardEvent.Key.ARROW_DOWN)) {
verticalDistance = movementDistance;
}
if (verticalDistance == 0 && horizontalDistance == 0) {
return;
}
List<Element> moveNodes = new ArrayList<>();
List<Point2D> movePositions = new ArrayList<>();
for (String uuid : selectedIDs) {
final Node<View<?>, Edge> node = canvasHandler.getGraphIndex().getNode(uuid);
if (node != null) {
final Point2D nodePosition = GraphUtils.getPosition(node.getContent());
final Point2D movePosition = new Point2D(nodePosition.getX() + horizontalDistance, nodePosition.getY() + verticalDistance);
moveNodes.add(node);
movePositions.add(movePosition);
}
}
move(moveNodes.toArray(new Element[] {}), movePositions.toArray(new Point2D[] {}));
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class ConnectionAcceptorControlImplTest method testCreateConnections.
@Test
public void testCreateConnections() {
// New default connection for a graph element.
Element element = mock(Element.class);
View<?> content = mock(View.class);
BoundsImpl bounds = new BoundsImpl(new BoundImpl(0d, 0d), new BoundImpl(10d, 20d));
when(element.getContent()).thenReturn(content);
when(content.getBounds()).thenReturn(bounds);
MagnetConnection c1 = ConnectionAcceptorControlImpl.createConnection(element);
assertEquals(5, c1.getLocation().getX(), 0);
assertEquals(10, c1.getLocation().getY(), 0);
assertEquals(MagnetConnection.MAGNET_CENTER, c1.getMagnetIndex().getAsInt());
assertFalse(c1.isAuto());
// New default connection for wires.
WiresConnection wiresConnection = mock(WiresConnection.class);
when(wiresConnection.isAutoConnection()).thenReturn(true);
WiresMagnet wiresMagnet = mock(WiresMagnet.class);
when(wiresMagnet.getX()).thenReturn(122d);
when(wiresMagnet.getY()).thenReturn(543d);
when(wiresMagnet.getIndex()).thenReturn(7);
MagnetConnection c2 = ConnectionAcceptorControlImpl.createConnection(wiresConnection, wiresMagnet);
assertEquals(122, c2.getLocation().getX(), 0);
assertEquals(543, c2.getLocation().getY(), 0);
assertEquals(7, c2.getMagnetIndex().getAsInt());
assertTrue(c2.isAuto());
// Connections (view magnets) can be nullified.
assertNull(ConnectionAcceptorControlImpl.createConnection(null));
assertNull(ConnectionAcceptorControlImpl.createConnection(wiresConnection, null));
assertNull(ConnectionAcceptorControlImpl.createConnection(null, null));
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class DiagramPresenterFactoryImpl method newViewer.
@Override
@SuppressWarnings("unchecked")
public DiagramViewer<Diagram, ?> newViewer(final Diagram diagram) {
final CanvasFactory<AbstractCanvas, AbstractCanvasHandler> canvasFactory = shapeManager.getCanvasFactory(diagram);
final AbstractCanvas canvas = canvasFactory.newCanvas();
final AbstractCanvasHandler canvasHandler = canvasFactory.newCanvasHandler();
final ZoomControl<AbstractCanvas> zoomControl = canvasFactory.newControl(ZoomControl.class);
final SelectionControl<AbstractCanvasHandler, Element> selectionControl = canvasFactory.newControl(SelectionControl.class);
return new DiagramViewerImpl<>(canvas, canvasHandler, viewInstances.get(), zoomControl, selectionControl, canvasControlDisposer);
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class TextEditorBoxImplTest method init.
@Before
@SuppressWarnings("unchecked")
public void init() {
this.textPropertyProvider = new DefaultTextPropertyProviderImpl(definitionUtils, canvasCommandFactory);
when(element.getContent()).thenReturn(definition);
when(definition.getDefinition()).thenReturn(objectDefinition);
when(definitionUtils.getName(objectDefinition)).thenReturn(NAME);
when(definitionUtils.getNameIdentifier(objectDefinition)).thenReturn(ID);
when(commandProvider.getCommandManager()).thenReturn(canvasCommandManager);
when(canvasHandler.getTextPropertyProviderFactory()).thenReturn(textPropertyProviderFactory);
when(textPropertyProviderFactory.getProvider(any(Element.class))).thenReturn(textPropertyProvider);
presenter = new TextEditorBoxImpl(view);
presenter.setup();
verify(view).init(presenter);
presenter.initialize(canvasHandler, closeCallback);
presenter.setCommandManagerProvider(commandProvider);
presenter.getElement();
verify(view).getElement();
presenter.show(element);
verify(view).show(NAME);
}
use of org.kie.workbench.common.stunner.core.graph.Element in project kie-wb-common by kiegroup.
the class SessionPreviewCanvasHandlerProxyTest method checkAddChildDelegatesToWrapped.
@Test
public void checkAddChildDelegatesToWrapped() {
final Element parent = mock(Element.class);
final Element child = mock(Element.class);
proxy.addChild(parent, child);
verify(wrapped).addChild(eq(parent), eq(child));
}
Aggregations