Search in sources :

Example 1 with TextNote

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

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

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

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

the class CanvasCommon method closeLabelEditor.

private void closeLabelEditor() {
    if (useLabelEditor) {
        if (editing_obj != null && !updateLabelWhileTyping) {
            editing_obj.setText(labelEditor.getText());
            if (editing_obj instanceof TextNote) {
                int w = labelEditor.getWidth();
                int h = labelEditor.getHeight();
                if (w < 80)
                    w = 80;
                if (h < 20)
                    h = 20;
                TextNote textNote = (TextNote) editing_obj;
                textNote.w = w + 2;
                textNote.h = h + 2;
                textNote.textarea.setSize(w, h);
            }
        }
        editing_obj = null;
        if (labelEditor != null)
            labelEditor.setVisible(false);
    } else {
        if (textEditor != null) {
            textEditor.setVisible(false);
            textEditor = null;
        }
    }
}
Also used : TextNote(com.centurylink.mdw.designer.display.TextNote)

Example 5 with TextNote

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

TextNote (com.centurylink.mdw.designer.display.TextNote)13 SubGraph (com.centurylink.mdw.designer.display.SubGraph)9 Link (com.centurylink.mdw.designer.display.Link)8 Node (com.centurylink.mdw.designer.display.Node)8 Graph (com.centurylink.mdw.designer.display.Graph)5 GraphFragment (com.centurylink.mdw.designer.display.GraphFragment)5 Rectangle (java.awt.Rectangle)3 Label (com.centurylink.mdw.designer.display.Label)1 ProcessInstanceVO (com.centurylink.mdw.model.value.process.ProcessInstanceVO)1 ActivityInstanceVO (com.centurylink.mdw.model.value.work.ActivityInstanceVO)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 Graphics2D (java.awt.Graphics2D)1 Point (java.awt.Point)1 ImageIcon (javax.swing.ImageIcon)1