All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.yaoqiang.graph.action.GraphActions Maven / Gradle / Ivy

There is a newer version: 2.2.18
Show newest version
package org.yaoqiang.graph.action;

import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.print.PageFormat;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import javax.swing.AbstractAction;
import javax.swing.JColorChooser;
import javax.swing.JOptionPane;
import javax.swing.TransferHandler;

import org.yaoqiang.graph.layout.BPMNLayout;
import org.yaoqiang.graph.model.YGraphModel;
import org.yaoqiang.graph.swing.YGraphComponent;
import org.yaoqiang.graph.util.Constants;
import org.yaoqiang.graph.util.Utils;
import org.yaoqiang.graph.view.YGraph;

import com.mxgraph.layout.mxIGraphLayout;
import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGeometry;
import com.mxgraph.model.mxGraphModel;
import com.mxgraph.model.mxICell;
import com.mxgraph.swing.util.mxMorphing;
import com.mxgraph.util.mxConstants;
import com.mxgraph.util.mxEvent;
import com.mxgraph.util.mxEventObject;
import com.mxgraph.util.mxEventSource.mxIEventListener;
import com.mxgraph.util.mxResources;
import com.mxgraph.util.mxUtils;

/**
 * GraphActions
 * 
 * @author Shi Yaoqiang([email protected])
 */
public class GraphActions extends AbstractAction {

	private static final long serialVersionUID = 1L;

	public static final int ZOOM = 001;
	public static final int ZOOM_IN = 002;
	public static final int ZOOM_OUT = 003;
	public static final int ZOOM_ACTUAL = 004;
	public static final int ZOOM_FIT_PAGE = 005;
	public static final int ZOOM_FIT_WIDTH = 006;
	public static final int ZOOM_CUSTOM = 007;

	public static final int EDIT = 101;
	public static final int PASTE = 102;
	public static final int DUPLICATE = 103;
	public static final int DELETE = 104;
	public static final int PAGE_SETUP = 105;
	public static final int PRINT = 106;

	public static final int SELECT_ALL = 201;
	public static final int SELECT_NONE = 202;
	public static final int SELECT_VERTICES = 203;
	public static final int SELECT_EDGES = 204;
	public static final int SELECT_PREVIOUS = 205;
	public static final int SELECT_NEXT = 206;
	public static final int SELECT_PARENT = 207;
	public static final int SELECT_CHILD = 208;

	public static final int ALIGN_LEFT = 301;
	public static final int ALIGN_CENTER = 302;
	public static final int ALIGN_RIGHT = 303;
	public static final int ALIGN_TOP = 304;
	public static final int ALIGN_MIDDLE = 305;
	public static final int ALIGN_BOTTOM = 306;
	public static final int DISTRIBUTE_HORIZONTALLY = 307;
	public static final int DISTRIBUTE_VERTICALLY = 308;
	public static final int SAME = 309;
	public static final int SAME_HEIGHT = 310;
	public static final int SAME_WIDTH = 311;
	public static final int MOVE_UP = 312;
	public static final int MOVE_DOWN = 313;
	public static final int MOVE_RIGHT = 314;
	public static final int MOVE_LEFT = 315;

	public static final int BACKGROUND = 408;
	public static final int ADD_PAGE = 409;
	public static final int REMOVE_PAGE = 410;

	public static final int DEBUG_STYLE = 500;
	public static final int FOLD_CELLS = 502;
	public static final int ROTATE_SWIMLANE = 503;
	public static final int MOVE_LANE = 504;
	public static final int PROMPT_VALUE = 508;
	public static final int TOGGLE = 509;
	public static final int STYLE = 510;
	public static final int INIT_PART = 511;
	public static final int MULTI_PART = 512;
	public static final int ADD_PART = 513;
	public static final int DEL_PART = 514;
	public static final int SWAP_PART = 515;
	public static final int DEF_SF = 516;
	public static final int RESET_BACKGROUND = 517;
	public static final int AUTO_LAYOUT = 518;

	public static final int HOME = 701;
	public static final int ENTER_GROUP = 702;
	public static final int EXIT_GROUP = 703;
	public static final int GROUP = 704;
	public static final int UNGROUP = 705;

	private int type;

	private boolean booleanValue;

	private double doubleValue;

	private String stringValue;

	private String stringValue2;

	private Object objectValue;

	private Object objectValue2;

	public GraphActions(int type) {
		this.type = type;
	}

	public static GraphActions getAction(int type) {
		return new GraphActions(type);
	}

	public static GraphActions getScaleAction(double value) {
		return new GraphActions(ZOOM).setDoubleValue(value);
	}

	public static GraphActions getMoveLaneAction(double value) {
		return new GraphActions(MOVE_LANE).setDoubleValue(value);
	}

	public static GraphActions getAddPageAction(boolean horizontal) {
		return new GraphActions(ADD_PAGE).setBooleanValue(horizontal);
	}

	public static GraphActions getRemovePageAction(boolean horizontal) {
		return new GraphActions(REMOVE_PAGE).setBooleanValue(horizontal);
	}

	public static GraphActions getPromptValueAction(String key, String message) {
		return new GraphActions(PROMPT_VALUE).setStringValue(key).setStringValue2(message);
	}

	public static GraphActions getToggleAction(String key) {
		return getToggleAction(key, false);
	}

	public static GraphActions getToggleAction(String key, boolean defaultValue) {
		return new GraphActions(TOGGLE).setStringValue(key).setBooleanValue(defaultValue);
	}

	public static GraphActions getStyleAction(String value) {
		return new GraphActions(STYLE).setStringValue(value);
	}

	public static GraphActions getStyleAction(Object cell, String value) {
		return new GraphActions(STYLE).setObjectValue(cell).setStringValue(value);
	}

	public static GraphActions getInitPartAction(Object parent, String id) {
		return new GraphActions(INIT_PART).setObjectValue(parent).setStringValue(id);
	}

	public static GraphActions getMultiPartAction(String id, String multi) {
		return new GraphActions(MULTI_PART).setStringValue(id).setStringValue2(multi);
	}

	public static GraphActions getAddPartAction(Object parent, boolean toTop) {
		return new GraphActions(ADD_PART).setObjectValue(parent).setBooleanValue(toTop);
	}

	public static GraphActions getDelPartAction(Object parent, Object cell) {
		return new GraphActions(DEL_PART).setObjectValue(parent).setObjectValue2(cell);
	}

	public static GraphActions getSwapPartAction() {
		return new GraphActions(SWAP_PART);
	}

	public static GraphActions getDefaultSequenceFlowAction(Object cell, Object edge) {
		return new GraphActions(DEF_SF).setObjectValue(cell).setObjectValue2(edge);
	}

	public static GraphActions getResetBackgroundAction() {
		return new GraphActions(RESET_BACKGROUND);
	}

	public static GraphActions getAutoLayoutAction() {
		return new GraphActions(AUTO_LAYOUT);
	}

	public static GraphActions getAutoLayoutAction(String value) {
		return new GraphActions(AUTO_LAYOUT).setStringValue(value);
	}

	public void actionPerformed(ActionEvent e) {
		YGraphComponent graphComponent = (YGraphComponent) e.getSource();
		final YGraph graph = graphComponent.getGraph();
		YGraphModel model = graph.getModel();
		Object cell = graph.getSelectionCell();

		if (type == ZOOM) {
			if (doubleValue > 0) {
				graphComponent.zoomTo(doubleValue, graphComponent.isCenterZoom());
			}
		} else if (type == ZOOM_IN) {
			graphComponent.zoomIn();
		} else if (type == ZOOM_OUT) {
			graphComponent.zoomOut();
		} else if (type == ZOOM_ACTUAL) {
			graphComponent.zoomActual();
		} else if (type == ZOOM_FIT_PAGE) {
			graphComponent.setZoomPolicy(YGraphComponent.ZOOM_POLICY_PAGE);
		} else if (type == ZOOM_FIT_WIDTH) {
			graphComponent.setZoomPolicy(YGraphComponent.ZOOM_POLICY_WIDTH);
		} else if (type == ZOOM_CUSTOM) {
			double scale = 0;
			String value = (String) JOptionPane.showInputDialog(graphComponent, mxResources.get("value"), mxResources.get("scale") + " (%)",
					JOptionPane.PLAIN_MESSAGE, null, null, "100");

			if (value != null) {
				scale = Double.parseDouble(value.replace("%", "")) / 100;
			}
			if (scale > 0) {
				graphComponent.zoomTo(scale, graphComponent.isCenterZoom());
			}
		} else if (type == EDIT) {
			graphComponent.startEditing();
		} else if (type == PASTE) {
			graphComponent.setPasteToPoint(graphComponent.getPopupPoint());
			TransferHandler.getPasteAction().actionPerformed(e);
			graphComponent.setPasteToPoint(null);
		} else if (type == DUPLICATE) {
			TransferHandler.getCopyAction().actionPerformed(e);
			TransferHandler.getPasteAction().actionPerformed(e);
		} else if (type == DELETE) {
			graph.removeCells();
		} else if (type == PAGE_SETUP) {
			PrinterJob pj = PrinterJob.getPrinterJob();
			PageFormat format = pj.pageDialog(graphComponent.getPageFormat());
			if (format != null) {
				Constants.SWIMLANE_WIDTH = (int) (format.getWidth() * 1.25 + (model.getHorizontalPageCount() - 1)
						* (Constants.SWIMLANE_START_POINT + format.getWidth() * 1.25));
				Constants.SWIMLANE_HEIGHT = (int) (format.getHeight() * 1.2 + (model.getPageCount() - 1)
						* (Constants.SWIMLANE_START_POINT + format.getHeight() * 1.2));
				graphComponent.setPageFormat(format);
				model.setPageFormat(format);

				Utils.arrangeAllSwimlaneLength(graph, true);
				graphComponent.zoomAndCenter();
			}
		} else if (type == PRINT) {
			PrinterJob pj = PrinterJob.getPrinterJob();
			if (pj.printDialog()) {
				PageFormat pf = graphComponent.getPageFormat();
				pj.setPrintable(graphComponent, pf);

				try {
					pj.print();
				} catch (PrinterException e2) {
					System.out.println(e2);
				}
			}
		} else if (type == SELECT_ALL) {
			graph.selectAll();
		} else if (type == SELECT_NONE) {
			graph.clearSelection();
		} else if (type == SELECT_VERTICES) {
			graph.selectVertices();
		} else if (type == SELECT_EDGES) {
			graph.selectEdges();
		} else if (type == SELECT_PREVIOUS) {
			graph.selectPreviousCell();
		} else if (type == SELECT_NEXT) {
			graph.selectNextCell();
		} else if (type == SELECT_PARENT) {
			graph.selectParentCell();
		} else if (type == SELECT_CHILD) {
			graph.selectChildCell();
		} else if (type == MOVE_UP) {
			graph.moveCells("up");
		} else if (type == MOVE_DOWN) {
			graph.moveCells("down");
		} else if (type == MOVE_RIGHT) {
			graph.moveCells("right");
		} else if (type == MOVE_LEFT) {
			graph.moveCells("left");
		} else if (type == ALIGN_LEFT) {
			graph.alignCells(mxConstants.ALIGN_LEFT);
		} else if (type == ALIGN_CENTER) {
			graph.alignCells(mxConstants.ALIGN_CENTER);
		} else if (type == ALIGN_RIGHT) {
			graph.alignCells(mxConstants.ALIGN_RIGHT);
		} else if (type == ALIGN_TOP) {
			graph.alignCells(mxConstants.ALIGN_TOP);
		} else if (type == ALIGN_MIDDLE) {
			graph.alignCells(mxConstants.ALIGN_MIDDLE);
		} else if (type == ALIGN_BOTTOM) {
			graph.alignCells(mxConstants.ALIGN_BOTTOM);
		} else if (type == DISTRIBUTE_HORIZONTALLY) {
			graph.distributeCells(mxConstants.ALIGN_CENTER);
		} else if (type == DISTRIBUTE_VERTICALLY) {
			graph.distributeCells(mxConstants.ALIGN_MIDDLE);
		} else if (type == SAME) {
			graph.sameCells("");
		} else if (type == SAME_HEIGHT) {
			graph.sameCells(Constants.HEIGHT);
		} else if (type == SAME_WIDTH) {
			graph.sameCells(Constants.WIDTH);
		} else if (type == BACKGROUND) {
			Color newColor = JColorChooser.showDialog(graphComponent, mxResources.get("background"), null);
			if (newColor != null) {
				graphComponent.getViewport().setOpaque(true);
				graphComponent.getViewport().setBackground(newColor);
				graphComponent.getGraph().getModel().setBackgroundColor(newColor);
			}
			graphComponent.repaint();
		} else if (type == ADD_PAGE || type == REMOVE_PAGE) {
			int verticalCount = graphComponent.getVerticalPageCount();
			int horizontalCount = graphComponent.getHorizontalPageCount();
			if (type == ADD_PAGE) {
				if (booleanValue) {
					graphComponent.setHorizontalPageCount(horizontalCount + 1);
				} else {
					graphComponent.setVerticalPageCount(verticalCount + 1);
				}
			} else {
				if (booleanValue) {
					if (horizontalCount > 1)
						graphComponent.setHorizontalPageCount(horizontalCount - 1);
				} else {
					if (verticalCount > 1)
						graphComponent.setVerticalPageCount(verticalCount - 1);
				}
			}
			if (booleanValue) {
				model.setHorizontalPageCount(graphComponent.getHorizontalPageCount());
			} else {
				model.setPageCount(graphComponent.getVerticalPageCount());
			}
			PageFormat format = model.getPageFormat();
			Constants.SWIMLANE_WIDTH = (int) (format.getWidth() * 1.25 + (model.getHorizontalPageCount() - 1)
					* (Constants.SWIMLANE_START_POINT + format.getWidth() * 1.25));
			Constants.SWIMLANE_HEIGHT = (int) (format.getHeight() * 1.2 + (model.getPageCount() - 1)
					* (Constants.SWIMLANE_START_POINT + format.getHeight() * 1.2));
			Utils.arrangeAllSwimlaneLength(graphComponent.getGraph(), true);
			graphComponent.zoomAndCenter();
		} else if (type == DEBUG_STYLE) {
			String initial = graph.getModel().getStyle(cell);
			String value = (String) JOptionPane.showInputDialog(graphComponent, mxResources.get("style"), mxResources.get("style"), JOptionPane.PLAIN_MESSAGE,
					null, null, initial);

			if (value != null) {
				graph.setCellStyle(value);
			}
		} else if (type == FOLD_CELLS) {
			if (graph != null && graph.getSelectionCount() == 1) {
				if (graph.isSubChoreography(cell)) {
					cell = Utils.getChoreographyActivity(graph, cell);
				}
				graph.foldCells(!graph.isCellCollapsed(cell), false, new Object[] { cell });
			}
		} else if (type == ROTATE_SWIMLANE) {
			Utils.rotateSwimlane(graphComponent);
		} else if (type == HOME) {
			graph.home();
			graph.fireEvent(new mxEventObject(Constants.EXIT_GROUP, "cell", cell));
		} else if (type == ENTER_GROUP) {
			graph.enterGroup();
			graph.fireEvent(new mxEventObject(Constants.ENTER_GROUP, "cell", cell));
		} else if (type == EXIT_GROUP) {
			graph.exitGroup();
			graph.fireEvent(new mxEventObject(Constants.EXIT_GROUP, "cell", cell));
		} else if (type == GROUP) {
			graph.setSelectionCell(graph.groupCells(null, 20));
		} else if (type == UNGROUP) {
			graph.ungroupCells();
		} else if (type == TOGGLE) {
			graph.toggleCellStyles(stringValue, booleanValue);
		} else if (type == PROMPT_VALUE) {
			String value = (String) JOptionPane.showInputDialog((Component) e.getSource(), mxResources.get("value"), stringValue2, JOptionPane.PLAIN_MESSAGE,
					null, null, "");

			if (value != null) {
				if (value.equals(mxConstants.NONE)) {
					value = null;
				}

				graph.setCellStyles(stringValue, value);
			}
		} else if (type == DEF_SF) {
			model.beginUpdate();
			if (objectValue2 != null) {
				model.setStyle(objectValue2, Constants.EDGE_TYPE_DEFAULT_SEQUENCE_FLOW);
			}
			List sfList = new ArrayList();
			for (Object edge : graph.getOutgoingEdges(objectValue)) {
				if (graph.isSequenceFlow(edge) && !graph.isConditionalSequenceFlow(edge)) {
					sfList.add(edge);
				}
			}
			for (Object sf : sfList) {
				if (sf != objectValue2) {
					if (objectValue2 == null && graph.isDefaultSequenceFlow(sf)) {
						objectValue2 = sf;
					}
					model.setStyle(sf, Constants.EDGE_TYPE_SEQUENCE_FLOW);
				}
			}
			model.endUpdate();
			graph.fireEvent(new mxEventObject(Constants.EVENT_ATTR_CHANGED, "cells", new Object[] { objectValue2 }));

		} else if (type == MULTI_PART) {
			String partId = stringValue.substring(stringValue.indexOf("_part_"));
			List parts = new ArrayList();
			for (Entry entry : model.getCells().entrySet()) {
				if (entry.getKey().endsWith(partId)) {
					parts.add(entry.getValue());
				}
			}
			graph.setCellStyles(Constants.ACTIVITY_STYLE_LOOP_MI, stringValue2, parts.toArray());
			graph.fireEvent(new mxEventObject(Constants.EVENT_ATTR_CHANGED, "cells", parts.toArray()));
			graph.resetSelection();
		} else if (type == DEL_PART) {
			graph.removeCells(new Object[] { objectValue2 });
			mxGeometry geo = model.getGeometry(objectValue);
			geo.setHeight(geo.getHeight() - model.getGeometry(objectValue2).getHeight());
			model.setGeometry(objectValue, geo);
			Utils.arrangeChoreography(graph, objectValue, false);
			graph.refresh();
			graph.resetSelection();
		} else if (type == SWAP_PART) {
			Object[] partCells = mxGraphModel.getChildVertices(model, cell);
			List cells = new ArrayList();
			model.beginUpdate();
			mxCell topPart = null;
			mxCell bottomPart = null;
			for (int i = 0; i < partCells.length; i++) {
				if (!graph.isAdditionalChoreographyParticipant(partCells[i])) {
					cells.add(partCells[i]);
					if (graph.isTopChoreographyParticipant(partCells[i])) {
						topPart = (mxCell) partCells[i];
						if (graph.isInitiatingChoreographyParticipant(topPart)) {
							graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, "", new Object[] { topPart });
						} else {
							graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, Constants.STYLE_COLOR_INITIATING, new Object[] { topPart });
						}
					} else if (graph.isBottomChoreographyParticipant(partCells[i])) {
						bottomPart = (mxCell) partCells[i];
						if (graph.isInitiatingChoreographyParticipant(bottomPart)) {
							graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, "", new Object[] { bottomPart });
						} else {
							graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, Constants.STYLE_COLOR_INITIATING, new Object[] { bottomPart });
						}
					}
				}
			}
			String tmpId = topPart.getId();
			Object tmp = topPart.getValue();
			topPart.setId(bottomPart.getId());
			model.setValue(topPart, bottomPart.getValue());
			bottomPart.setId(tmpId);
			model.setValue(bottomPart, tmp);
			model.getCells().put(topPart.getId(), topPart);
			model.getCells().put(bottomPart.getId(), bottomPart);
			model.endUpdate();
			graph.fireEvent(new mxEventObject(mxEvent.CHANGE, "cells", cells.toArray()));
		} else if (type == INIT_PART) {
			Object[] partCells = mxGraphModel.getChildVertices(model, objectValue);
			List cells = new ArrayList();
			model.beginUpdate();
			for (int i = 0; i < partCells.length; i++) {
				if (graph.isChoreographyParticipant(partCells[i])) {
					String partId = ((mxCell) partCells[i]).getId();
					if (partId.equals(stringValue)) {
						graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, Constants.STYLE_COLOR_INITIATING, new Object[] { partCells[i] });
					} else {
						graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, "", new Object[] { partCells[i] });
					}
					cells.add(partCells[i]);
				}
			}
			model.endUpdate();
			graph.fireEvent(new mxEventObject(mxEvent.CHANGE, "cells", cells.toArray()));
		} else if (type == ADD_PART) {
			double yOffset = 0;
			String style = "";

			mxCell subprocess = Utils.getChoreographyActivity(graph, objectValue);
			String id = subprocess.getId() + "_part_" + model.createId(null);
			mxGeometry subgeo = model.getGeometry(subprocess);
			if (booleanValue) {
				yOffset = subgeo.getY() - 1;
				style = "participantAdditionalTop";
			} else {
				yOffset = subgeo.getY() + subgeo.getHeight() - 1;
				style = "participantAdditionalBottom";
			}
			if (graph.isCallChoreography(objectValue)) {
				style += ";strokeWidth=3";
			}
			String value = "Participant";
			Map participants = graph.getAllParticipants();
			int i = 1;
			while (participants.get(value) != null) {
				value = value.substring(0, 11) + " " + i++;
			}

			mxCell participantCell = new mxCell(value, new mxGeometry(0, yOffset, Constants.ACTIVITY_WIDTH, Constants.PARTICIPANT_HEIGHT), style);
			participantCell.setId(id);
			participantCell.setVertex(true);
			graph.addCell(participantCell, (mxICell) objectValue);

			mxGeometry geo = model.getGeometry(objectValue);
			geo.setHeight(geo.getHeight() + Constants.PARTICIPANT_HEIGHT);
			model.setGeometry(objectValue, geo);

			Utils.arrangeChoreography(graph, objectValue, false);
			graph.refresh();
			graph.resetSelection();
		} else if (type == MOVE_LANE) {
			if (graph != null && !graph.isSelectionEmpty()) {
				Object lane = graph.getSelectionCell();
				Object parent = model.getParent(lane);
				int lanesize = model.getChildCount(parent);

				int index = 0;
				for (int i = 0; i < lanesize; i++) {
					Object child = model.getChildAt(parent, i);
					if (child == lane) {
						index = i;
						break;
					}
				}

				if (doubleValue == 0) {
					if (index == 0) {
						graph.cellsAdded(new Object[] { lane }, parent, lanesize, null, null, true);
					} else {
						graph.cellsAdded(new Object[] { lane }, parent, index, null, null, true);
					}
				} else {
					if (index == lanesize - 1) {
						graph.cellsAdded(new Object[] { lane }, parent, 1, null, null, true);
					} else {
						graph.cellsAdded(new Object[] { lane }, parent, index + 2, null, null, true);
					}
				}

			}
		} else if (type == STYLE) {
			model.beginUpdate();
			if (objectValue == null) {
				objectValue = graph.getSelectionCell();
			}
			if (stringValue.equals(mxConstants.ELBOW_HORIZONTAL) || stringValue.equals(mxConstants.ELBOW_VERTICAL)) {
				graph.setCellStyles(mxConstants.STYLE_SHAPE, mxUtils.getString(graph.getCellStyle(objectValue), mxConstants.STYLE_SHAPE));
				graph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ELBOW);
				graph.setCellStyles(mxConstants.STYLE_ELBOW, stringValue);
			} else if (stringValue.equals(Constants.FLOW_STYLE_STRAIGHT)) {
				graph.setCellStyles(mxConstants.STYLE_SHAPE, mxUtils.getString(graph.getCellStyle(objectValue), mxConstants.STYLE_SHAPE));
				graph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.NONE);
			} else if (stringValue.equals(mxConstants.SHAPE_CURVE)) {
				graph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ELBOW);
				graph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CURVE);
			} else if (stringValue.equals("resetEdgeStyle")) {
				graph.setCellStyles(mxConstants.STYLE_EDGE, mxConstants.EDGESTYLE_ELBOW);
				graph.setCellStyles(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
			} else if (stringValue.equals(Constants.EDGE_TYPE_SEQUENCE_FLOW)) {
				model.setStyle(objectValue, Constants.EDGE_TYPE_SEQUENCE_FLOW);
			} else if (stringValue.equals(Constants.EDGE_TYPE_DEFAULT_SEQUENCE_FLOW)) {
				model.setStyle(objectValue, Constants.EDGE_TYPE_DEFAULT_SEQUENCE_FLOW);
			} else if (stringValue.equals(Constants.EDGE_TYPE_CONDITION_SEQUENCE_FLOW)) {
				model.setStyle(objectValue, Constants.EDGE_TYPE_CONDITION_SEQUENCE_FLOW);
			} else if (stringValue != null && stringValue.split("=").length > 1 && stringValue.lastIndexOf(";whiteSpace=") == -1) {
				graph.setCellStyles(stringValue.split("=")[0], stringValue.split("=")[1], new Object[] { objectValue });
				if (stringValue.split("=")[0].equals(Constants.STYLE_LOOP) || stringValue.split("=")[0].equals(Constants.STYLE_COMPENSATION)
						|| stringValue.split("=")[0].equals(Constants.STYLE_TYPE)) {
					if (stringValue.split("=").length > 3) {
						graph.setCellStyles(stringValue.split("=")[2], stringValue.split("=")[3], new Object[] { objectValue });
					}
				}
			} else if (graph.isTask(objectValue)) {
				Map oldstyle = graph.getCellStyle(objectValue);
				String loop = mxUtils.getString(oldstyle, Constants.STYLE_LOOP);
				String loopImage = mxUtils.getString(oldstyle, Constants.STYLE_LOOP_IMAGE);
				String compensation = mxUtils.getString(oldstyle, Constants.STYLE_COMPENSATION);
				String compensationImage = mxUtils.getString(oldstyle, Constants.STYLE_COMPENSATION_IMAGE);

				model.setStyle(objectValue, stringValue);
				if (stringValue != null && (stringValue.startsWith("task") || stringValue.startsWith("call"))) {
					graph.setCellStyles(Constants.STYLE_LOOP, loop);
					graph.setCellStyles(Constants.STYLE_LOOP_IMAGE, loopImage);
					graph.setCellStyles(Constants.STYLE_COMPENSATION, compensation);
					graph.setCellStyles(Constants.STYLE_COMPENSATION_IMAGE, compensationImage);
				}
			} else {
				model.setStyle(objectValue, stringValue);
				if (graph.isStartEvent(objectValue) && graph.isEventSubProcess(model.getParent(objectValue))) {
					int endIndex = stringValue.lastIndexOf("Event");
					if (endIndex != -1) {
						String trigger = stringValue.substring(5, endIndex);
						graph.setCellStyles("trigger", trigger, new Object[] { model.getParent(objectValue) });
					}
				}
			}
			model.endUpdate();
			graph.fireEvent(new mxEventObject(mxEvent.MOVE_CELLS, "cells", new Object[] { objectValue }));
			if (stringValue.startsWith(Constants.STYLE_LOOP + "=")) {
				graph.fireEvent(new mxEventObject(Constants.EVENT_LOOPTYPE_CHANGED, "cells", new Object[] { objectValue }));
			} else if (stringValue.startsWith(Constants.STYLE_INSTANTIATE) || stringValue.startsWith(Constants.STYLE_COMPENSATION)
					|| stringValue.startsWith(Constants.ACTIVITY_STYLE_LOOP_MI) || stringValue.startsWith(Constants.STYLE_LOOP_IMAGE)) {
				graph.fireEvent(new mxEventObject(Constants.EVENT_ATTR_CHANGED, "cells", new Object[] { objectValue }));
			} else {
				if (!model.isEdge(objectValue)) {
					graph.fireEvent(new mxEventObject(mxEvent.CHANGE, "cells", new Object[] { objectValue }));
				}
			}
		} else if (type == RESET_BACKGROUND) {
			graph.setCellStyles(mxConstants.STYLE_FILLCOLOR, null);
			graph.setCellStyles(mxConstants.STYLE_GRADIENTCOLOR, null);
			graph.setCellStyles(mxConstants.STYLE_OPACITY, null);
		} else if (type == AUTO_LAYOUT) {
			final mxIGraphLayout layout = new BPMNLayout(graph);
			if (layout instanceof BPMNLayout) {
				int nodeDistance = Integer.parseInt(Constants.SETTINGS.getProperty("nodeDistance", "20"));
				int levelDistance = Integer.parseInt(Constants.SETTINGS.getProperty("levelDistance", "40"));
				((BPMNLayout) layout).setNodeDistance(nodeDistance);
				((BPMNLayout) layout).setLevelDistance(levelDistance);
			}

			List lanesAndSubprocesses = graph.getAllLanesAndSubprocesses();
			if (stringValue != null) {
				lanesAndSubprocesses = Arrays.asList(graph.getSelectionCells());
			}
			for (Object container : lanesAndSubprocesses) {
				graph.getModel().beginUpdate();
				try {
					if (graph.isSwimlane(container)) {
						if (graph.isVerticalSwimlane(container)) {
							((BPMNLayout) layout).setHorizontal(false);
						} else {
							((BPMNLayout) layout).setHorizontal(true);
						}
					} else if ("org".equals(graphComponent.getName())) {
						((BPMNLayout) layout).setHorizontal(false);
					} else {
						((BPMNLayout) layout).setHorizontal("1".equals(Constants.SETTINGS.getProperty("orientation", "1")));
					}
					layout.execute(container);
				} finally {
					mxMorphing morph = new mxMorphing(graphComponent, 20, 1.2, 20);
					morph.addListener(mxEvent.DONE, new mxIEventListener() {
						public void invoke(Object sender, mxEventObject evt) {
							graph.getModel().endUpdate();
						}
					});
					morph.startAnimation();
				}
			}

			Utils.arrangeSwimlanePosition(graphComponent);
		}

	}

	public GraphActions setBooleanValue(boolean value) {
		this.booleanValue = value;
		return this;
	}

	public GraphActions setDoubleValue(double value) {
		this.doubleValue = value;
		return this;
	}

	public GraphActions setStringValue(String value) {
		this.stringValue = value;
		return this;
	}

	public GraphActions setStringValue2(String value) {
		this.stringValue2 = value;
		return this;
	}

	public GraphActions setObjectValue(Object value) {
		this.objectValue = value;
		return this;
	}

	public GraphActions setObjectValue2(Object value) {
		this.objectValue2 = value;
		return this;
	}

}