📄 graphmarqueehandler.java
字号:
package org.enhydra.jawe.components.graph;import java.awt.Color;import java.awt.Component;import java.awt.Cursor;import java.awt.Graphics;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.MouseEvent;import java.awt.geom.Rectangle2D;import java.util.ArrayList;import java.util.HashSet;import java.util.List;import java.util.Set;import java.util.Vector;import javax.swing.JMenuItem;import javax.swing.JOptionPane;import javax.swing.JPopupMenu;import javax.swing.SwingUtilities;import org.enhydra.jawe.BarFactory;import org.enhydra.jawe.JaWEConstants;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.Utils;import org.enhydra.jawe.base.controller.JaWEController;import org.enhydra.jawe.base.controller.JaWEFrame;import org.enhydra.shark.xpdl.XMLElement;import org.enhydra.shark.xpdl.XMLUtil;import org.enhydra.shark.xpdl.XPDLConstants;import org.enhydra.shark.xpdl.elements.Activities;import org.enhydra.shark.xpdl.elements.Activity;import org.enhydra.shark.xpdl.elements.ExtendedAttribute;import org.enhydra.shark.xpdl.elements.Participant;import org.enhydra.shark.xpdl.elements.Participants;import org.enhydra.shark.xpdl.elements.Transition;import org.enhydra.shark.xpdl.elements.Transitions;import org.jgraph.JGraph;import org.jgraph.graph.AbstractCellView;import org.jgraph.graph.BasicMarqueeHandler;import org.jgraph.graph.CellView;import org.jgraph.graph.DefaultGraphCell;import org.jgraph.graph.GraphConstants;/** * Implementation of a marquee handler for Process Editor. This is also a place * where (after mouse click or release) participants, activities (normal, subflows, * block activities) and transitions are inserted, where persistent mode is achived and * where mouse cursors are changing, and where popup menu is implemented. When * inserting cells it calls WorkflowManager. */public class GraphMarqueeHandler extends BasicMarqueeHandler { protected Point start; // Starting point (where mouse was pressed). protected Point current; // Current point (where mouse was dragged). protected GraphPortViewInterface port; // Current port (when mouse was pressed). protected GraphPortViewInterface firstPort; // First port (when mouse was pressed). protected GraphPortViewInterface lastPort; // Last port (when mouse was dragged). protected Vector points = new Vector(); protected Point popupPoint; // A point where popup window has been created last time protected GraphController graphController; protected String mainType = GraphEAConstants.SELECT_TYPE; protected String subType = GraphEAConstants.SELECT_TYPE_DEFAULT; /** * Creates custom marquee handler. */ public GraphMarqueeHandler (GraphController graphController) { this.graphController=graphController; // if (!JaWEConfig.getInstance().getUseBubblesStatus()) {// enableBubblesButtons(false);// } } /** Return true if this handler should be preferred over other handlers. */ public boolean isForceMarqueeEvent(MouseEvent e) { boolean isSelectButtonSelected=isSelectButtonSelected(); return ((isSelectButtonSelected && SwingUtilities.isRightMouseButton(e)) || !isSelectButtonSelected || super.isForceMarqueeEvent(e)); } /** * We don't want special cursor */ public void mousePressed(MouseEvent e) { startPoint = e.getPoint(); marqueeBounds = new Rectangle2D.Double(startPoint.getX(), startPoint.getY(), 0, 0); if (e != null) { if (!(e.getSource() instanceof JGraph)) throw new IllegalArgumentException( "MarqueeHandler cannot handle event from unknown source: " + e); } } public void mouseReleased(MouseEvent ev) { try { if (ev != null && marqueeBounds != null) { Rectangle2D bounds = getGraph().fromScreen(marqueeBounds);// HM, JGraph3.4.1 CellView[] rootViews = getGraph().getGraphLayoutCache().getRoots(bounds); // added - getting all views in model (except forbidden objects) CellView[] views = AbstractCellView.getDescendantViews(rootViews); ArrayList wholeList = new ArrayList(); ArrayList participantList = new ArrayList(); ArrayList otherList = new ArrayList(); for (int i = 0; i < views.length; i++) { if (bounds.contains(views[i].getBounds())) { if (views[i].getCell() instanceof DefaultGraphCell && !(((DefaultGraphCell) views[i].getCell()).getUserObject() instanceof Participant)) { otherList.add(views[i].getCell()); } else { participantList.add(views[i].getCell()); } wholeList.add(views[i].getCell()); } } Object[] cells = wholeList.toArray(); getGraph().getUI().selectCellsForEvent(getGraph(), cells, ev); Rectangle dirty = marqueeBounds.getBounds();// HM, JGraph3.4.1 dirty.width++; dirty.height++;// HM, JGraph3.4.1 getGraph().repaint(dirty); } } finally { currentPoint = null; startPoint = null; marqueeBounds = null; } } // // PopupMenu // /** * Creates popup menu and adds a various actions (depending of where * mouse was pressed - which cell(s) is/are selected). */ protected JPopupMenu createPopupMenu(final Object cell) { boolean isWorkflowElement=(cell instanceof WorkflowElement); String type=null; String subtype = null; String userSpec = null; if (isWorkflowElement) { XMLElement el = (XMLElement)((DefaultGraphCell)cell).getUserObject(); if (cell instanceof GraphActivityInterface && !(cell instanceof GraphBubbleActivityInterface)) { type=JaWEConstants.ACTIVITY_TYPE; subtype = Utils.getActivityStringType(((Activity)el).getActivityType()); userSpec = JaWEManager.getInstance().getJaWEController().getTypeResolver().getJaWEType(el).getTypeId(); } if (cell instanceof GraphParticipantInterface) { type=JaWEConstants.PARTICIPANT_TYPE; subtype = JaWEManager.getInstance().getJaWEController().getTypeResolver().getJaWEType(el).getTypeId(); } if (cell instanceof GraphTransitionInterface) { type=JaWEConstants.TRANSITION_TYPE; subtype = JaWEManager.getInstance().getJaWEController().getTypeResolver().getJaWEType(el).getTypeId(); } if (cell instanceof GraphBubbleActivityInterface) { if (((GraphBubbleActivityInterface)cell).isStart()) { type=GraphEAConstants.START_TYPE; } else { type=GraphEAConstants.END_TYPE; } subtype = ((GraphBubbleActivityInterface)cell).getType(); } } else { type=GraphEAConstants.SELECT_TYPE; } JPopupMenu retMenu = BarFactory.createPopupMenu(type, graphController); if (subtype != null) { JPopupMenu specMenu = BarFactory.createPopupMenu(subtype, graphController); Component[] spec = specMenu.getComponents(); if (spec.length != 0) retMenu.addSeparator(); for (int i = 0; i < spec.length; i++) { retMenu.add(spec[i]); } } if (subtype != null && userSpec != null && !subtype.equals(userSpec)) { JPopupMenu specMenu = BarFactory.createPopupMenu(userSpec, graphController); Component[] spec = specMenu.getComponents(); if (spec.length != 0) retMenu.addSeparator(); for (int i = 0; i < spec.length; i++) { retMenu.add(spec[i]); } } if (cell instanceof GraphParticipantInterface && ((WorkflowElement)cell).getPropertyObject() instanceof CommonExpressionParticipant) {// System.err.println("CSPEC FIR CEP"); JMenuItem se=BarFactory.createMenuItem(getGraphController().getSettings().getAction(("SetPerformerExpression")), getGraphController(), false); retMenu.addSeparator(); retMenu.add(se);// System.err.println("CSPEC FIR CEP CREATED"); } return retMenu; } /** * Gets the point of last popup menu creation. */ public Point getPopupPoint () { return popupPoint; } public boolean validateSource (GraphPortViewInterface pPort) { // if port is a valid if (pPort!=null && pPort.getCell()!=null // and it is a port && (pPort.getCell() instanceof GraphPortInterface)) { // return if it accepts to be a source or a target GraphActivityInterface sourceActivity = pPort.getGraphActivity(); if (!sourceActivity.acceptsSource()) return false; boolean isExceptionalTrans=getSubType().equals(JaWEConstants.TRANSITION_TYPE_EXCEPTION); if (!(sourceActivity instanceof GraphBubbleActivityInterface) && !JaWEManager.getInstance().getTransitionHandler().acceptsSource((Activity)sourceActivity.getUserObject(),isExceptionalTrans)) { JOptionPane.showMessageDialog(getJaWEFrame(),getGraphController().getSettings().getLanguageDependentString( "WarningCannotAcceptMoreOutgoingTransitions"), getJaWEFrame().getAppTitle(), JOptionPane.INFORMATION_MESSAGE); return false; } return true; } return false; } /** * Returns <code>true</code> if parent cell of given port accepts source or target, depending * on <code>source</code> parameter. */ public boolean validateConnection (GraphPortViewInterface pFirstPort,GraphPortViewInterface pSecondPort, Transition t) { // if ports are valid if (pFirstPort!=null && pFirstPort.getCell()!=null && (pFirstPort.getCell() instanceof GraphPortInterface) && pSecondPort!=null && pSecondPort.getCell()!=null && (pSecondPort.getCell() instanceof GraphPortInterface)) { // return if it accepts to be a source or a target GraphActivityInterface sourceActivity=pFirstPort.getGraphActivity(); GraphActivityInterface targetActivity=pSecondPort.getGraphActivity();// System.out.println("Processing accept source for act "+sourceActivity+", target act="+targetActivity); if (!targetActivity.acceptsTarget()) {//System.err.println("acceptTarget = false"); return false; } boolean isExceptionalTrans=XMLUtil.isExceptionalTransition(t) || getSubType().equals(JaWEConstants.TRANSITION_TYPE_EXCEPTION); // do not allow start-end connection if ((sourceActivity instanceof GraphBubbleActivityInterface) && (targetActivity instanceof GraphBubbleActivityInterface)) { JOptionPane.showMessageDialog(getJaWEFrame(),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -