/* * for use with CustomBorderPort testing */ private void connect( BorderPortTestNode source, int sourcePort, BorderPortTestNode target, int targetPort) { CustomConnectionWidget connection = new CustomConnectionWidget(this); Widget src = source.getOutputPort(sourcePort); Widget tgt = target.getInputPort(targetPort); connection.setSourceAnchor(AnchorFactory.createCircularAnchor(src, 2)); connection.setTargetAnchor(AnchorFactory.createCircularAnchor(tgt, 2)); addEdge(connection); connections.add(new Connection(source, sourcePort, target, targetPort, connection)); }
@Override public State keyPressed(Widget widget, WidgetKeyEvent event) { VisualScene scene = (VisualScene) widget; if (event.getKeyCode() == KeyEvent.VK_N) { // type 'n' to create a new object BorderPortTestNode node = new BorderPortTestNode(scene.getVisualScene()); node.setPreferredLocation(new Point((int) scene.getMouseX(), (int) scene.getMouseY())); scene.setLastPointCreatedAt(new Point((int) scene.getMouseX(), (int) scene.getMouseY())); scene.addNode(node); } if (event.getKeyCode() == KeyEvent.VK_F) { // type 'f' to create a new object // VisualNode node = new FloatDisplay(scene.getScene(), // scene.getDataScene()); // node.setPreferredLocation(new Point((int) scene.getMouseX(), (int) // scene.getMouseY())); // scene.setLastPointCreatedAt(new Point((int) scene.getMouseX(), (int) // scene.getMouseY())); // scene.addNode(node); } if (event.isAltDown() && event.getKeyCode() == KeyEvent.VK_A) { // alt + 'a' for align mode toggle scene.setAlignMode(); scene.removeHoverActions(); } if (event.isAltDown() && event.getKeyCode() == KeyEvent.VK_E) { // alt + 'e' for edit/use mode toggle scene.setEditMode(); } if (event.isAltDown() && event.getKeyCode() == KeyEvent.VK_R) { // alt + 'r' route selected selectedObjects scene.routeSelectedEdges(); } if (event.isAltDown() && event.isShiftDown() && event.getKeyCode() == KeyEvent.VK_R) { scene.unrouteSelectedEdges(); } //// use arrows to move selected objects if (getSelectedObjects().size() > 0) { Set array = getSelectedObjects(); if (event.getKeyCode() == KeyEvent.VK_UP) { for (Iterator i = array.iterator(); i.hasNext(); ) { try { BorderPortTestNode node = (BorderPortTestNode) i.next(); node.setPreferredLocation( new Point(node.getPreferredLocation().x, node.getPreferredLocation().y - 2)); } catch (java.lang.ClassCastException e) { } } } if (event.getKeyCode() == KeyEvent.VK_DOWN) { for (Iterator i = array.iterator(); i.hasNext(); ) { try { BorderPortTestNode node = (BorderPortTestNode) i.next(); node.setPreferredLocation( new Point(node.getPreferredLocation().x, node.getPreferredLocation().y + 2)); } catch (java.lang.ClassCastException e) { } } } if (event.getKeyCode() == KeyEvent.VK_LEFT) { for (Iterator i = array.iterator(); i.hasNext(); ) { try { BorderPortTestNode node = (BorderPortTestNode) i.next(); node.setPreferredLocation( new Point(node.getPreferredLocation().x - 2, node.getPreferredLocation().y)); } catch (java.lang.ClassCastException e) { } } } if (event.getKeyCode() == KeyEvent.VK_RIGHT) { for (Iterator i = array.iterator(); i.hasNext(); ) { try { BorderPortTestNode node = (BorderPortTestNode) i.next(); node.setPreferredLocation( new Point(node.getPreferredLocation().x + 2, node.getPreferredLocation().y)); } catch (java.lang.ClassCastException e) { } } } } if (event.getKeyCode() == KeyEvent.VK_E) { widget.getScene().setActiveTool(EDGE_CONTROL_MODE); scene.addEdgeSelectionAction(); } else if (event.getKeyCode() == KeyEvent.VK_DELETE) { // need to add object and edge deletion } return State.REJECTED; }