use of com.centurylink.mdw.designer.display.GraphFragment 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();
}
use of com.centurylink.mdw.designer.display.GraphFragment 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);
}
}
use of com.centurylink.mdw.designer.display.GraphFragment 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;
}
use of com.centurylink.mdw.designer.display.GraphFragment in project mdw-designer by CenturyLinkCloud.
the class FlowchartPage method actionPerformed.
public void actionPerformed(ActionEvent event) {
String cmd = event.getActionCommand();
if (cmd.equals(Constants.ACTION_DELETE)) {
if (process.isReadonly()) {
return;
}
if (canvas.getSelectedObject() != null) {
if (canvas.getSelectedObject() instanceof Node) {
if (getConfirmation("Are you sure you want to delete the node?")) {
process.removeNode((Node) canvas.getSelectedObject(), this.recordchange);
}
} else if (canvas.getSelectedObject() instanceof Link) {
if (getConfirmation("Are you sure you want to delete the link?")) {
process.removeLink((Link) canvas.getSelectedObject(), this.recordchange);
}
} else if (canvas.getSelectedObject() instanceof SubGraph) {
if (getConfirmation("Are you sure you want to delete the handler?")) {
process.removeSubGraph((SubGraph) canvas.getSelectedObject());
}
} else if (canvas.getSelectedObject() instanceof GraphFragment) {
if (getConfirmation("Are you sure you want to delete the selected objects?")) {
GraphFragment frag = (GraphFragment) canvas.getSelectedObject();
for (Link l : frag.links) {
process.removeLink(l, recordchange);
}
for (Node n : frag.nodes) {
process.removeNode(n, recordchange);
}
for (SubGraph sg : frag.subgraphs) {
// TODO record changes
process.removeSubGraph(sg);
}
}
} else if (canvas.getSelectedObject() instanceof TextNote) {
if (getConfirmation("Are you sure you want to delete the note?")) {
process.removeTextNote((TextNote) canvas.getSelectedObject());
}
}
canvas.setSelectedObject(null);
canvas.repaint();
}
} else if (cmd.equals(Constants.ACTION_TIPMODE)) {
JCheckBox tipMode = (JCheckBox) event.getSource();
showtip = tipMode.isSelected();
} else if (cmd.equals(ACTION_RECORD_CHANGES)) {
JCheckBox checkbox = (JCheckBox) event.getSource();
recordchange = checkbox.isSelected();
} else if (cmd.equals(ACTION_SHOW_ID)) {
if (process != null) {
JComboBox showId = (JComboBox) event.getSource();
process.setNodeIdType((String) showId.getSelectedItem());
canvas.repaint();
}
// else during init
} else if (cmd.equals(Constants.ACTION_START)) {
showStartProcessDialog(null);
} else if (cmd.equals(ACTION_RUN_ACTIVITY)) {
if (model.canExecuteProcess(process.getProcessVO())) {
Node node = (Node) canvas.getSelectedObject();
showStartProcessDialog(node);
} else
this.showError("You are not authorized to run processes");
} else if (cmd.equals(ACTION_ARROWTYPE)) {
JComboBox arrowType = (JComboBox) event.getSource();
ImageIcon arrowTypeIcon = (ImageIcon) arrowType.getSelectedItem();
setArrowStyle(arrowTypeIcon.getDescription());
} else if (cmd.equals(ACTION_NODETYPE)) {
JComboBox nodeType = (JComboBox) event.getSource();
ImageIcon nodeTypeIcon = (ImageIcon) nodeType.getSelectedItem();
setNodeStyle(nodeTypeIcon.getDescription());
} else if (cmd.equals(ACTION_ZOOM)) {
int zoomLevel = Graph.zoomLevels[zoomWidget.getSelectedIndex()];
canvas.zoom(process, zoomLevel);
} else if (cmd.equals(ACTION_ALL_LINK_STYLE_CHANGE)) {
process.changeAllLinkStyle(this.linktype);
canvas.repaint();
} else if (cmd.equals(ACTION_COMMIT_CHANGES)) {
if (process.isReadonly()) {
return;
}
if (getConfirmation("This will commit recorded changes. Proceed?")) {
process.commitChanges();
canvas.repaint();
}
} else if (cmd.equals(ACTION_MARK_AS_NEW)) {
markChangeType(Changes.NEW);
} else if (cmd.equals(ACTION_MARK_AS_DELETED)) {
markChangeType(Changes.DELETE);
} else if (cmd.equals(ACTION_MARK_AS_NOCHANGE)) {
markChangeType(Changes.NONE);
} else if (cmd.equals(ACTION_LINEUP_HORIZONTAL)) {
lineUpActivities(false);
} else if (cmd.equals(ACTION_LINEUP_VERTICAL)) {
lineUpActivities(true);
} else if (cmd.equals(ACTION_ADD_NOTE)) {
if (process.isReadonly()) {
return;
}
addNote();
} else {
super.actionPerformed(event);
}
}
use of com.centurylink.mdw.designer.display.GraphFragment in project mdw-designer by CenturyLinkCloud.
the class FlowchartPage method lineUpActivities.
private void lineUpActivities(boolean vertical) {
Object selectedObj = canvas.getSelectedObject();
if (selectedObj == null || !(selectedObj instanceof GraphFragment)) {
this.showError("You need to select at least 2 activities to line up");
return;
}
GraphFragment marquee = (GraphFragment) selectedObj;
if (marquee.nodes.size() < 2) {
this.showError("You need to select at least 2 activities to line up");
return;
}
if (vertical) {
Node topmost = null;
for (Node n : marquee.nodes) {
if (topmost == null || n.y < topmost.y)
topmost = n;
}
for (Node n : marquee.nodes) {
if (n == topmost)
continue;
if (topmost != null)
n.x = topmost.x + topmost.w / 2 - n.w / 2;
process.recalcLinkPosition(n, process.arrowstyle);
}
canvas.repaint();
} else {
Node leftmost = null;
for (Node n : marquee.nodes) {
if (leftmost == null || n.x < leftmost.x)
leftmost = n;
}
for (Node n : marquee.nodes) {
if (n == leftmost)
continue;
if (leftmost != null)
n.y = leftmost.y + leftmost.h / 2 - n.h / 2;
process.recalcLinkPosition(n, process.arrowstyle);
}
canvas.repaint();
}
}
Aggregations