Search in sources :

Example 16 with Link

use of com.centurylink.mdw.designer.display.Link in project mdw-designer by CenturyLinkCloud.

the class CanvasCommon method keyPressed.

protected void keyPressed(KeyEvent arg0, Graph main_graph, DesignerPage page, boolean recordchange) {
    if (useLabelEditor && arg0.getSource() == labelEditor) {
        return;
    }
    if (main_graph.isReadonly())
        return;
    int keycode = arg0.getKeyCode();
    char ch = arg0.getKeyChar();
    if (selected_obj != null) {
        if ((useLabelEditor && editing_obj != null) || (!useLabelEditor && textEditor != null)) {
        // do not need to do any thing - handled by editor
        } else if (selected_obj instanceof Node) {
            if (keycode == KeyEvent.VK_DELETE) {
                if (page.getConfirmation("Are you sure you want to delete the node?")) {
                    main_graph.removeNode((Node) selected_obj, recordchange);
                    selected_obj = null;
                    repaint();
                }
            } else if (ch != KeyEvent.CHAR_UNDEFINED && !arg0.isControlDown()) {
                String label = ((Node) selected_obj).getName();
                if (label == null)
                    label = "";
                if (keycode != KeyEvent.VK_BACK_SPACE) {
                    label = label + ch;
                    updateLabel(selected_obj, label, main_graph);
                }
                openLabelEditor((Node) selected_obj, main_graph.zoom);
                repaint();
            } else {
                if (keycode == KeyEvent.VK_DOWN || keycode == KeyEvent.VK_UP || keycode == KeyEvent.VK_LEFT || keycode == KeyEvent.VK_RIGHT) {
                    handleArrowKey(keycode, arg0, (Node) selected_obj, main_graph);
                }
            }
        } else if (selected_obj instanceof Link) {
            if (keycode == KeyEvent.VK_DELETE) {
                if (page.getConfirmation("Are you sure you want to delete the link?")) {
                    main_graph.removeLink((Link) selected_obj, recordchange);
                    selected_obj = null;
                    repaint();
                }
            } else if (ch != KeyEvent.CHAR_UNDEFINED) {
                String label = ((Link) selected_obj).getLabelAndEventType();
                if (label == null)
                    label = "";
                if (label.length() == 0)
                    ((Link) selected_obj).calcLinkLabelPosition();
                if (keycode != KeyEvent.VK_BACK_SPACE) {
                    label = label + ch;
                    updateLabel(selected_obj, label, main_graph);
                }
                openLabelEditor((Link) selected_obj, main_graph.zoom);
                repaint();
            } else {
                if (keycode == KeyEvent.VK_DOWN || keycode == KeyEvent.VK_UP || keycode == KeyEvent.VK_LEFT || keycode == KeyEvent.VK_RIGHT) {
                    if (at_anchor >= 0) {
                        Link link = (Link) selected_obj;
                        int x = link.getControlPointX(at_anchor);
                        int y = link.getControlPointY(at_anchor);
                        switch(keycode) {
                            case KeyEvent.VK_UP:
                                y--;
                                break;
                            case KeyEvent.VK_DOWN:
                                y++;
                                break;
                            case KeyEvent.VK_LEFT:
                                x--;
                                break;
                            case KeyEvent.VK_RIGHT:
                                x++;
                                break;
                        }
                        link.moveControlPoint(at_anchor, x, y, main_graph.arrowstyle);
                        arg0.consume();
                        repaint();
                    }
                }
            }
        } else if (selected_obj instanceof SubGraph) {
            if (keycode == KeyEvent.VK_DELETE) {
                if (page.getConfirmation("Are you sure you want to delete the embedded process?")) {
                    main_graph.removeSubGraph((SubGraph) selected_obj);
                    selected_obj = null;
                    repaint();
                }
            }
        } else if (selected_obj instanceof GraphFragment) {
            if (keycode == KeyEvent.VK_DELETE) {
                if (page.getConfirmation("Are you sure you want to delete the selected objects?")) {
                    GraphFragment frag = (GraphFragment) selected_obj;
                    for (Link l : frag.links) {
                        main_graph.removeLink(l, recordchange);
                    }
                    for (Node n : frag.nodes) {
                        main_graph.removeNode(n, recordchange);
                    }
                    for (SubGraph sg : frag.subgraphs) {
                        main_graph.removeSubGraph(sg);
                    }
                    selected_obj = null;
                    repaint();
                }
            }
        } else if (selected_obj instanceof TextNote) {
            if (keycode == KeyEvent.VK_DELETE) {
                if (page.getConfirmation("Are you sure you want to delete the selected note?")) {
                    main_graph.removeTextNote((TextNote) selected_obj);
                    selected_obj = null;
                    repaint();
                }
            }
        }
    }
}
Also used : Node(com.centurylink.mdw.designer.display.Node) GraphFragment(com.centurylink.mdw.designer.display.GraphFragment) TextNote(com.centurylink.mdw.designer.display.TextNote) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Link(com.centurylink.mdw.designer.display.Link)

Example 17 with Link

use of com.centurylink.mdw.designer.display.Link in project mdw-designer by CenturyLinkCloud.

the class CanvasCommon method paintDraggingAndSelection.

protected void paintDraggingAndSelection(Graphics g) {
    if (dragging && drag_to_create_link) {
        if (selected_obj instanceof Node) {
            g.setColor(Color.GREEN);
            g.drawLine(((Node) selected_obj).x + delta_x, ((Node) selected_obj).y + delta_y, drag_x, drag_y);
        }
    } else if (selected_obj != null) {
        if (selected_obj instanceof Node) {
            drawSelectionBox(g, (Node) selected_obj);
        } else if (selected_obj instanceof Link) {
            drawSelectionBox(g, (Link) selected_obj);
        } else if (selected_obj instanceof SubGraph) {
            drawSelectionBox(g, (SubGraph) selected_obj);
        } else if (selected_obj instanceof Graph) {
            drawSelectionBox(g, (Graph) selected_obj);
        } else if (selected_obj instanceof GraphFragment) {
            drawSelectionBox(g, (GraphFragment) selected_obj);
        } else if (selected_obj instanceof TextNote) {
            drawSelectionBox(g, (TextNote) selected_obj);
        }
    }
    if (useLabelEditor && selected_obj != null) /*&& at_anchor==-2 */
    {
        if (labelEditor.isVisible()) {
            Rectangle rect = labelEditor.getBounds();
            g.drawRect(rect.x - 1, rect.y - 1, rect.width + 2, rect.height + 2);
        } else {
            Label label;
            int lx, ly;
            if (selected_obj instanceof Node) {
            // label = ((Node)selected_obj).label;
            // lx = ((Node)selected_obj).lx;
            // ly = ((Node)selected_obj).ly;
            // g.drawRect(lx-1, ly-1, label.width+2, label.height+2);
            } else if (selected_obj instanceof Link) {
                label = ((Link) selected_obj).label;
                if (label != null) {
                    lx = ((Link) selected_obj).lx;
                    ly = ((Link) selected_obj).ly;
                    g.drawRect(lx - 1, ly - 1, label.width + 2, label.height + 2);
                }
            } else if (selected_obj instanceof TextNote) {
                JTextArea textarea = ((TextNote) selected_obj).textarea;
                lx = ((TextNote) selected_obj).x;
                ly = ((TextNote) selected_obj).y;
                g.drawRect(lx - 1, ly - 1, textarea.getWidth() + 2, textarea.getHeight() + 2);
            }
        // else GraphSegment
        }
    }
}
Also used : Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) JTextArea(javax.swing.JTextArea) Node(com.centurylink.mdw.designer.display.Node) GraphFragment(com.centurylink.mdw.designer.display.GraphFragment) Rectangle(java.awt.Rectangle) Label(com.centurylink.mdw.designer.display.Label) TextNote(com.centurylink.mdw.designer.display.TextNote) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Link(com.centurylink.mdw.designer.display.Link)

Example 18 with Link

use of com.centurylink.mdw.designer.display.Link in project mdw-designer by CenturyLinkCloud.

the class CanvasCommon method performPaste.

private void performPaste(GraphFragment sourcefrag, Graph process, boolean recordchange) {
    if (sourcefrag.isEmpty())
        return;
    Rectangle visibleRect = this.getVisibleRect();
    Rectangle boundingRect = sourcefrag.getBoundary();
    process.save_temp_vars();
    GraphFragment targetfrag = new GraphFragment(process.getId());
    Map<Long, Long> nodeIdMap = new HashMap<Long, Long>();
    int xoff = 0, yoff = 0;
    if (visibleRect.intersects(boundingRect)) {
        if (sourcefrag.getSourceProcessId().equals(process.getId())) {
            xoff = 40;
            yoff = 40;
        } else {
            for (SubGraph subgraph : process.subgraphs) {
                if (sourcefrag.getSourceProcessId().equals(subgraph.getId())) {
                    xoff = 40;
                    yoff = 40;
                    break;
                }
            }
        }
    } else {
        xoff = visibleRect.x - boundingRect.x + 100;
        yoff = visibleRect.y - boundingRect.y + 100;
    }
    for (Node sourcenode : sourcefrag.nodes) {
        Node node = process.addNode(process, sourcenode.nodet, xoff, yoff, recordchange, true);
        targetfrag.nodes.add(node);
        nodeIdMap.put(sourcenode.getActivityId(), node.getActivityId());
        if (recordchange)
            node.getChanges().setChangeType(Changes.NEW);
    }
    for (Link sourcelink : sourcefrag.links) {
        Link link = process.addLink(process, sourcelink.conn, nodeIdMap.get(sourcelink.conn.getFromWorkId()), nodeIdMap.get(sourcelink.conn.getToWorkId()), xoff, yoff, recordchange, true);
        targetfrag.links.add(link);
        if (recordchange)
            link.getChanges().setChangeType(Changes.NEW);
    }
    for (SubGraph sourceSubgraph : sourcefrag.subgraphs) {
        // if (xoff>0) yoff = sourceSubgraph.h + 15;
        SubGraph subgraph = process.addSubGraph(sourceSubgraph.getProcessVO(), xoff, yoff, recordchange);
        if (subgraph != null) {
            targetfrag.subgraphs.add(subgraph);
            // TODO below only mark the entire subgraph as new
            if (recordchange)
                subgraph.getChanges().setChangeType(Changes.NEW);
        }
    }
    if (targetfrag.isNode())
        selected_obj = targetfrag.getOnlyNode();
    else if (targetfrag.isSubGraph())
        selected_obj = targetfrag.getOnlySubGraph();
    else
        selected_obj = targetfrag;
    repaint();
}
Also used : HashMap(java.util.HashMap) Node(com.centurylink.mdw.designer.display.Node) Rectangle(java.awt.Rectangle) GraphFragment(com.centurylink.mdw.designer.display.GraphFragment) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Link(com.centurylink.mdw.designer.display.Link)

Aggregations

Link (com.centurylink.mdw.designer.display.Link)18 SubGraph (com.centurylink.mdw.designer.display.SubGraph)15 Node (com.centurylink.mdw.designer.display.Node)14 Graph (com.centurylink.mdw.designer.display.Graph)9 TextNote (com.centurylink.mdw.designer.display.TextNote)8 GraphFragment (com.centurylink.mdw.designer.display.GraphFragment)7 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)3 WorkTransitionInstanceVO (com.centurylink.mdw.model.value.work.WorkTransitionInstanceVO)3 Rectangle (java.awt.Rectangle)3 ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)2 Graphics2D (java.awt.Graphics2D)2 Label (com.centurylink.mdw.designer.display.Label)1 Selectable (com.centurylink.mdw.designer.display.Selectable)1 Activity (com.centurylink.mdw.plugin.designer.model.Activity)1 ActivityImpl (com.centurylink.mdw.plugin.designer.model.ActivityImpl)1 EmbeddedSubProcess (com.centurylink.mdw.plugin.designer.model.EmbeddedSubProcess)1 Note (com.centurylink.mdw.plugin.designer.model.Note)1 Transition (com.centurylink.mdw.plugin.designer.model.Transition)1 BasicStroke (java.awt.BasicStroke)1 Dimension (java.awt.Dimension)1