Search in sources :

Example 1 with SubGraph

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

the class CanvasCommon method objectAt.

public Object objectAt(Graph process, int x, int y, Graphics g) {
    Node node;
    Link link;
    if (selected_obj != null) {
        if (selected_obj instanceof Node) {
            node = (Node) selected_obj;
            if (onSelectableAnchor(x, y, node.x, node.y, node.w, node.h))
                return node;
            else if (node.labelOnPoint(g, x, y)) {
                at_anchor = -2;
                delta_x = x - node.x;
                delta_y = y - node.y;
                return node;
            }
        } else if (selected_obj instanceof Link) {
            link = (Link) selected_obj;
            int cx, cy, n = link.getNumberOfControlPoints();
            for (int i = 0; i < n; i++) {
                cx = link.getControlPointX(i);
                cy = link.getControlPointY(i);
                if (Math.abs(cx - x) <= 3 && Math.abs(cy - y) <= 3) {
                    at_anchor = i;
                    delta_x = x - cx;
                    delta_y = y - cy;
                    return link;
                }
            }
            if (link.labelOnPoint(g, x, y)) {
                at_anchor = -2;
                delta_x = x - link.lx;
                delta_y = y - link.ly;
                return link;
            }
        } else if (selected_obj instanceof SubGraph) {
            SubGraph subgraph = (SubGraph) selected_obj;
            if (subgraph.isSwimLane()) {
                if (onSelectableAnchor(x, y, subgraph.x, subgraph.y, SubGraph.SWIMLANE_LABEL_BAR_WIDTH, subgraph.h))
                    return subgraph;
            } else {
                if (onSelectableAnchor(x, y, subgraph.x, subgraph.y, subgraph.w, subgraph.h))
                    return subgraph;
            }
        } else if (selected_obj instanceof Graph) {
            if (onSelectableAnchor(x, y, process.lx, process.ly, process.lw, process.lh))
                return process;
        } else if (selected_obj instanceof TextNote) {
            TextNote note = (TextNote) selected_obj;
            if (onSelectableAnchor(x, y, note.x, note.y, note.w, note.h))
                return note;
        }
    }
    at_anchor = -1;
    Object obj = process.objectAt(x, y, g);
    if (obj != null) {
        if (obj instanceof Node) {
            delta_x = x - ((Node) obj).x;
            delta_y = y - ((Node) obj).y;
        } else if (obj instanceof SubGraph) {
            delta_x = x - ((SubGraph) obj).x;
            delta_y = y - ((SubGraph) obj).y;
        } else if (obj instanceof Graph) {
            delta_x = x - ((Graph) obj).lx;
            delta_y = y - ((Graph) obj).ly;
        } else if (obj instanceof TextNote) {
            delta_x = x - ((TextNote) obj).x;
            delta_y = y - ((TextNote) obj).y;
        }
        return obj;
    }
    return null;
}
Also used : Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Node(com.centurylink.mdw.designer.display.Node) TextNote(com.centurylink.mdw.designer.display.TextNote) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Link(com.centurylink.mdw.designer.display.Link)

Example 2 with SubGraph

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

the class CanvasCommon method mousePressed.

protected void mousePressed(MouseEvent arg0, Graph main_graph) {
    closeLabelEditor();
    int x = arg0.getX();
    int y = arg0.getY();
    if (main_graph.zoom != 100) {
        x = x * 100 / main_graph.zoom;
        y = y * 100 / main_graph.zoom;
    }
    Object obj = objectAt(main_graph, x, y, getGraphics());
    if (selected_obj != null && selected_obj instanceof GraphFragment && obj != null && ((GraphFragment) selected_obj).contains(obj)) {
        // dragging to move
        drag_x = x;
        drag_y = y;
    } else if (selected_obj != null && obj != null && obj instanceof Node && arg0.isControlDown()) {
        GraphFragment frag;
        if (selected_obj instanceof Node) {
            frag = new GraphFragment(main_graph.getId());
            frag.nodes.add((Node) selected_obj);
            selected_obj = frag;
        } else if (selected_obj instanceof SubGraph) {
            frag = new GraphFragment(main_graph.getId());
            frag.subgraphs.add((SubGraph) selected_obj);
            selected_obj = frag;
        } else if (selected_obj instanceof Link) {
            frag = new GraphFragment(main_graph.getId());
            frag.links.add((Link) selected_obj);
            selected_obj = frag;
        } else if (selected_obj instanceof GraphFragment) {
            frag = (GraphFragment) selected_obj;
        } else
            frag = null;
        if (frag != null)
            frag.nodes.add((Node) obj);
        repaint();
    } else if (obj != null) {
        selected_obj = obj;
        if (obj instanceof Node) {
            if (arg0.isShiftDown() && !main_graph.isReadonly()) {
                drag_to_create_link = true;
            }
        }
        // closeLabelEditor(true);
        repaint();
    } else if (selected_obj != null) {
        selected_obj = null;
        // closeLabelEditor(true);
        repaint();
        marquee = new Rectangle(arg0.getX(), arg0.getY(), 0, 0);
    } else {
        marquee = new Rectangle(arg0.getX(), arg0.getY(), 0, 0);
    }
    this.requestFocus();
}
Also used : Node(com.centurylink.mdw.designer.display.Node) GraphFragment(com.centurylink.mdw.designer.display.GraphFragment) Rectangle(java.awt.Rectangle) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Link(com.centurylink.mdw.designer.display.Link)

Example 3 with SubGraph

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

the class CanvasCommon method draw_graph.

protected void draw_graph(Graphics g, Graph process, boolean drawStatus) {
    if (g instanceof Graphics2D && normal_stroke == null) {
        normal_stroke = ((Graphics2D) g).getStroke();
        line_stroke = new BasicStroke(3.0f);
        float[] dash = { 10.0f, 10.0f };
        dash_stroke = new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 10.0f, dash, 0.0f);
        grid_stroke = new BasicStroke(0.2f);
    }
    if (editable) {
        Dimension canvas_size = this.getSize();
        g.setColor(Color.GRAY);
        ((Graphics2D) g).setStroke(grid_stroke);
        for (int x = grid_size; x < canvas_size.width; x += grid_size) {
            g.drawLine(x, 0, x, canvas_size.height);
        }
        for (int y = grid_size; y < canvas_size.height; y += grid_size) {
            g.drawLine(0, y, canvas_size.width, y);
        }
    }
    g.setFont(normal_font);
    if (drawStatus) {
        for (Link conn : process.links) {
            if (!conn.isHidden() && conn.getColor() == Color.LIGHT_GRAY)
                drawConnector(g, process, conn);
        }
        for (Link conn : process.links) {
            if (!conn.isHidden() && conn.getColor() != Color.LIGHT_GRAY)
                drawConnector(g, process, conn);
        }
    } else {
        for (Link conn : process.links) {
            if (!conn.isHidden())
                drawConnector(g, process, conn);
        }
    }
    drawMainProcess(g, process);
    for (Node node : process.nodes) {
        drawNode(node, g, drawStatus, process.nodestyle);
    }
    for (SubGraph subgraph : process.subgraphs) {
        draw_subgraph(g, process, subgraph, drawStatus);
    }
    if (process.notes != null) {
        for (TextNote note : process.notes) {
            draw_textnote(g, note);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Node(com.centurylink.mdw.designer.display.Node) TextNote(com.centurylink.mdw.designer.display.TextNote) Dimension(java.awt.Dimension) SubGraph(com.centurylink.mdw.designer.display.SubGraph) Link(com.centurylink.mdw.designer.display.Link) Graphics2D(java.awt.Graphics2D)

Example 4 with SubGraph

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

the class CanvasCommon method mouseDragged.

protected void mouseDragged(MouseEvent arg0, Graph main_graph) {
    int x = arg0.getX();
    int y = arg0.getY();
    if (selected_obj != null) {
        if (main_graph.zoom != 100) {
            x = x * 100 / main_graph.zoom;
            y = y * 100 / main_graph.zoom;
        }
        dragging = true;
        if (at_anchor >= 0) {
            if (selected_obj instanceof Node) {
                resizeNode(x, y, main_graph);
            } else if (selected_obj instanceof Link) {
                ((Link) selected_obj).moveControlPoint(at_anchor, x - delta_x, y - delta_y, main_graph.arrowstyle);
                if (!main_graph.isReadonly())
                    main_graph.setDirtyLevel(Graph.GEOCHANGE);
            } else if (selected_obj instanceof SubGraph) {
                resizeSubGraph(x, y);
            } else if (selected_obj instanceof TextNote) {
                resizeTextNote(x, y, main_graph);
            }
        } else {
            if (drag_to_create_link) {
                drag_x = x;
                drag_y = y;
            } else if (selected_obj instanceof Node) {
                moveNode(x, y);
            } else if (selected_obj instanceof Link && at_anchor == -2) {
                // move link label
                Link link = (Link) selected_obj;
                link.lx = x - delta_x;
                link.ly = y - delta_y;
            } else if (selected_obj instanceof SubGraph) {
                if (((SubGraph) selected_obj).isSwimLane())
                    moveSubgraph(0, y);
                else
                    moveSubgraph(x, y);
            } else if (selected_obj instanceof Graph) {
                moveGraphLabel(x, y);
            } else if (selected_obj instanceof GraphFragment) {
                ((GraphFragment) selected_obj).shift(main_graph, x - drag_x, y - drag_y, main_graph.arrowstyle);
                drag_x = x;
                drag_y = y;
                if (!main_graph.isReadonly())
                    main_graph.setDirtyLevel(Graph.GEOCHANGE);
            } else if (selected_obj instanceof TextNote) {
                moveTextNote(x, y);
            }
        }
        repaint();
    } else if (marquee != null) {
        if (x < 0)
            x = 0;
        else if (x > this.getWidth())
            x = this.getWidth();
        if (y < 0)
            y = 0;
        else if (y > this.getHeight())
            y = this.getHeight();
        drawRubberBand(marquee, x - marquee.x, y - marquee.y);
    }
}
Also used : Graph(com.centurylink.mdw.designer.display.Graph) SubGraph(com.centurylink.mdw.designer.display.SubGraph) 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 5 with SubGraph

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

the class CanvasCommon method mouseReleased.

protected void mouseReleased(MouseEvent arg0, Graph main_graph, String curr_link_type, DesignerPage page, boolean recordchange) {
    // if (main_graph.isReadonly()) return;
    int x = arg0.getX();
    int y = arg0.getY();
    if (main_graph.zoom != 100) {
        x = x * 100 / main_graph.zoom;
        y = y * 100 / main_graph.zoom;
    }
    Object obj = main_graph.objectAt(x, y, getGraphics());
    if (arg0.getButton() != 1) {
        if (arg0.isPopupTrigger() && obj != null) {
            JPopupMenu popup;
            if (obj instanceof Node) {
                popup = this.popup_activity;
                selected_obj = obj;
            } else if (obj instanceof Link) {
                popup = this.popup_transition;
                selected_obj = obj;
            } else
                popup = null;
            if (popup != null) {
                popup.show(this, arg0.getX(), arg0.getY());
            }
        }
        return;
    }
    if (dragging) {
        if (drag_to_create_link) {
            Node startnode = (Node) selected_obj;
            Node endnode = (obj != null && (obj instanceof Node)) ? (Node) obj : null;
            if (endnode != null && endnode.graph.equals(startnode.graph)) {
                int ctrl_pts = 2;
                String linktype = curr_link_type;
                if (endnode == startnode) {
                    linktype = Link.CURVE;
                } else if (linktype.equals(Link.CURVE)) {
                    ctrl_pts = 4;
                }
                Link conn = main_graph.addLink(startnode, endnode, EventType.FINISH, linktype, ctrl_pts, recordchange);
                selected_obj = conn;
            } else
                selected_obj = null;
        } else if (selected_obj instanceof Link && at_anchor >= 0) {
            Link link = (Link) selected_obj;
            Node node = (obj != null && (obj instanceof Node)) ? (Node) obj : null;
            if (link.to == link.from) {
                // a link to the node itself
                if (at_anchor == 0 && (node == null || node != link.from)) {
                    // move back to the node
                    moveBackFrom(link, main_graph.arrowstyle);
                }
            } else if (at_anchor == 0) {
                if (node == null || node == link.to) {
                    // move back to the node
                    moveBackFrom(link, main_graph.arrowstyle);
                } else if (node != link.from && node.graph.equals(link.from.graph)) {
                    // change 'from'
                    link.setFrom(node);
                }
            // else do nothing
            } else if (at_anchor == link.getNumberOfControlPoints() - 1) {
                if (node == null || node == link.from) {
                    // move back to the node
                    moveBackTo(link, main_graph.arrowstyle);
                } else if (node != link.to && node.graph.equals(link.to.graph)) {
                    // change 'to'
                    link.setTo(node);
                }
            // else do nothing
            } else {
                // a middle link
                if (link.isElbowType()) {
                    if (at_anchor == 1) {
                        moveBackFrom(link, main_graph.arrowstyle);
                    }
                    if (at_anchor == link.getNumberOfControlPoints() - 2) {
                        moveBackTo(link, main_graph.arrowstyle);
                    }
                }
            }
        } else if (selected_obj instanceof SubGraph) {
            mouseReleased_subgraph();
        } else if (selected_obj instanceof Node && at_anchor < 0) {
            // move node
            checkIfMoveIntoSubprocess((Node) selected_obj, x, y, page, recordchange);
        }
        repaint();
        dragging = false;
    // } else if (useLabelEditor && editing_obj!=null) {
    // labelEditor.setZoom(main_graph.zoom);
    // labelEditor.setVisible(true);
    // repaint();  // TODO do we need this?
    } else if (useLabelEditor && obj != null && at_anchor == -2) {
        if (obj instanceof Node) {
            if (!main_graph.isReadonly()) {
                openLabelEditor((Node) obj, main_graph.zoom);
            }
        } else if (obj instanceof Link) {
            if (!main_graph.isReadonly()) {
                openLabelEditor((Link) obj, main_graph.zoom);
            }
        }
    // else not possible (TextNote never has at_anchor==-2)
    } else if (useLabelEditor && obj instanceof TextNote || !useLabelEditor && textEditor != null) {
        if (!main_graph.isReadonly()) {
            openLabelEditor((TextNote) obj, main_graph.zoom);
        }
    } else if (marquee != null) {
        GraphFragment frag = new GraphFragment(main_graph, marquee);
        if (!frag.isEmpty()) {
            if (frag.isNode())
                selected_obj = frag.getOnlyNode();
            else if (frag.isSubGraph())
                selected_obj = frag.getOnlySubGraph();
            else
                selected_obj = frag;
        }
        marquee = null;
        repaint();
    }
    drag_to_create_link = false;
}
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) JPopupMenu(javax.swing.JPopupMenu) Link(com.centurylink.mdw.designer.display.Link)

Aggregations

SubGraph (com.centurylink.mdw.designer.display.SubGraph)25 Node (com.centurylink.mdw.designer.display.Node)17 Graph (com.centurylink.mdw.designer.display.Graph)14 Link (com.centurylink.mdw.designer.display.Link)13 GraphFragment (com.centurylink.mdw.designer.display.GraphFragment)8 TextNote (com.centurylink.mdw.designer.display.TextNote)8 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)4 Rectangle (java.awt.Rectangle)4 HashMap (java.util.HashMap)3 VariableVO (com.centurylink.mdw.model.value.variable.VariableVO)2 Paragraph (com.lowagie.text.Paragraph)2 Graphics2D (java.awt.Graphics2D)2 AuthenticationException (com.centurylink.mdw.auth.AuthenticationException)1 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)1 TranslationException (com.centurylink.mdw.common.exception.TranslationException)1 DataAccessOfflineException (com.centurylink.mdw.dataaccess.DataAccessOfflineException)1 DesignerDataAccess (com.centurylink.mdw.designer.DesignerDataAccess)1 GraphCommon (com.centurylink.mdw.designer.display.GraphCommon)1 Label (com.centurylink.mdw.designer.display.Label)1 ProcessInstanceLoader (com.centurylink.mdw.designer.runtime.ProcessInstanceLoader)1