Search in sources :

Example 6 with GraphFragment

use of com.centurylink.mdw.designer.display.GraphFragment 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 7 with GraphFragment

use of com.centurylink.mdw.designer.display.GraphFragment 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 8 with GraphFragment

use of com.centurylink.mdw.designer.display.GraphFragment 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)

Example 9 with GraphFragment

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

the class CanvasCommon method keyReleased.

protected void keyReleased(KeyEvent arg0, Graph main_graph, boolean recordchange) {
    if (useLabelEditor && arg0.getSource() == labelEditor) {
        if (main_graph.isReadonly())
            return;
        if (updateLabelWhileTyping)
            editing_obj.setText(labelEditor.getText());
        if (labelEditor.adjustSize())
            repaint();
    } else {
        int keycode = arg0.getKeyCode();
        if (keycode != KeyEvent.VK_CONTROL) {
            if (arg0.isControlDown()) {
                if (keycode == KeyEvent.VK_C) {
                    if (selected_obj != null) {
                        GraphClipboard cb = GraphClipboard.getInstance();
                        cb.put(selected_obj);
                    }
                } else if (keycode == KeyEvent.VK_V || keycode == KeyEvent.VK_X) {
                    if (main_graph.isReadonly())
                        return;
                    GraphClipboard cb = GraphClipboard.getInstance();
                    GraphFragment frag = cb.get();
                    if (frag != null) {
                        performPaste(frag, main_graph, recordchange);
                    }
                } else {
                    if (selected_obj instanceof Node) {
                        handleActivityMenuShortCut((Node) selected_obj, keycode);
                    }
                }
            }
        }
    }
}
Also used : GraphClipboard(com.centurylink.mdw.designer.utils.GraphClipboard) Node(com.centurylink.mdw.designer.display.Node) GraphFragment(com.centurylink.mdw.designer.display.GraphFragment)

Example 10 with GraphFragment

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

the class GraphClipboard method put.

public void put(Object obj) {
    ProcessTransferVO transfer;
    GraphFragment fragment;
    if (obj instanceof Node) {
        fragment = new GraphFragment(((Node) obj).graph.getProcessVO().getProcessId());
        fragment.nodes.add((Node) obj);
    } else if (obj instanceof SubGraph) {
        fragment = new GraphFragment(((SubGraph) obj).getGraph().getId());
        fragment.subgraphs.add((SubGraph) obj);
    } else if (obj instanceof GraphFragment) {
        fragment = (GraphFragment) obj;
    } else
        return;
    transfer = new ProcessTransferVO(fragment);
    clipboard.setContents(transfer, this);
}
Also used : Node(com.centurylink.mdw.designer.display.Node) GraphFragment(com.centurylink.mdw.designer.display.GraphFragment) SubGraph(com.centurylink.mdw.designer.display.SubGraph)

Aggregations

GraphFragment (com.centurylink.mdw.designer.display.GraphFragment)11 Node (com.centurylink.mdw.designer.display.Node)10 SubGraph (com.centurylink.mdw.designer.display.SubGraph)8 Link (com.centurylink.mdw.designer.display.Link)7 TextNote (com.centurylink.mdw.designer.display.TextNote)5 Rectangle (java.awt.Rectangle)3 Graph (com.centurylink.mdw.designer.display.Graph)2 Label (com.centurylink.mdw.designer.display.Label)1 GraphClipboard (com.centurylink.mdw.designer.utils.GraphClipboard)1 Point (java.awt.Point)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 HashMap (java.util.HashMap)1 ImageIcon (javax.swing.ImageIcon)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JPopupMenu (javax.swing.JPopupMenu)1 JTextArea (javax.swing.JTextArea)1