📄 jawegraphui.java
字号:
package org.enhydra.jawe.components.graph;import java.awt.Graphics;import java.awt.Point;import java.awt.Rectangle;import java.awt.event.KeyAdapter;import java.awt.event.KeyEvent;import java.awt.event.KeyListener;import java.awt.event.MouseEvent;import java.awt.event.MouseListener;import java.awt.geom.Point2D;import java.awt.geom.Rectangle2D;import java.io.Serializable;import java.util.Map;import javax.swing.Action;import javax.swing.KeyStroke;import javax.swing.SwingUtilities;import org.enhydra.jawe.JaWEManager;import org.enhydra.jawe.base.controller.JaWEActions;import org.enhydra.shark.xpdl.XMLElement;import org.enhydra.shark.xpdl.XMLUtil;import org.enhydra.shark.xpdl.XPDLConstants;import org.enhydra.shark.xpdl.elements.Activity;import org.enhydra.shark.xpdl.elements.ActivitySet;import org.enhydra.shark.xpdl.elements.WorkflowProcess;import org.jgraph.JGraph;import org.jgraph.event.GraphLayoutCacheEvent;import org.jgraph.event.GraphLayoutCacheListener;import org.jgraph.event.GraphModelEvent;import org.jgraph.event.GraphModelListener;import org.jgraph.graph.CellHandle;import org.jgraph.graph.CellView;import org.jgraph.graph.DefaultGraphModel;import org.jgraph.graph.GraphConstants;import org.jgraph.graph.GraphContext;import org.jgraph.graph.GraphLayoutCache;import org.jgraph.plaf.basic.BasicGraphUI;/** * This class and it's inner classes controls mouse actions and clipboard. * It is addapted to get wanted editing cell behaviour, selection behaviour * , to implement cell overlaping, to implement right participant adjustment * after cell (or group of cells) is moved, and to implement proper copying * and pasting/cloning of cells, as well as pasting at wanted location (along * with right participant adjustment). */public class JaWEGraphUI extends BasicGraphUI { public final static int SELECTION = 0; public final static int MULTIPLE_SELECTION = 1; public final static int INSERT_ELEMENT = 2; public final static int INSERT_PARTICIPANT = 3; public final static int INSERT_SPEC_ELEMENT = 4; public final static int INSERT_TRANSITION_START = 5; public final static int INSERT_TRANSITION_POINTS = 6; protected int status; protected boolean aborted = false; protected boolean selectOnRelease = false; /** * Returns graph. */ public Graph getGraph() { return (Graph)graph; } public GraphController getGraphController () { return ((GraphMarqueeHandler)marquee).getGraphController(); } /** * Paint the background of this graph. Calls paintGrid. */ protected void paintBackground(Graphics g) { Rectangle pageBounds = new Rectangle(0,0,graph.getWidth(),graph.getHeight()); if (graph.isGridVisible()) { paintGrid(graph.getGridSize(),g,pageBounds); } } /** * This method is called by EditAction class, as well as by * pressing F2 or clicking a mouse on a cell. */ protected boolean startEditing(Object cell, MouseEvent event) { if (cell instanceof WorkflowElement) { XMLElement el=((WorkflowElement)cell).getPropertyObject(); if (el instanceof Activity) { Activity act=(Activity)el; if (act.getActivityType()==XPDLConstants.ACTIVITY_TYPE_SUBFLOW) { WorkflowProcess wp=XMLUtil.getSubflowProcess(JaWEManager.getInstance().getXPDLHandler(), act); if (wp != null) getGraphController().selectGraphForElement(wp); return true; } else if (act.getActivityType()==XPDLConstants.ACTIVITY_TYPE_BLOCK) { ActivitySet as = XMLUtil.getBlockActivitySet(act); if (as != null) getGraphController().selectGraphForElement(as); return true; } } else if (el instanceof FreeTextExpressionParticipant || el instanceof CommonExpressionParticipant) { return true; } JaWEManager.getInstance().getJaWEController().getJaWEActions().getAction(JaWEActions.EDIT_PROPERTIES_ACTION).actionPerformed(null); return true; } return false; } // FIXED by xxp - there was a problem when zooming-out activity public void startEditingAtCell(JGraph pGraph,Object cell) { if(cell!=null) startEditing(cell,null); } /** * Creates the listener responsible for updating the selection based on * mouse events. */ protected MouseListener createMouseListener() { return new PEMouseHandler(); } /** * Handles selection in a way that we expect. */ public class PEMouseHandler extends MouseHandler { public void mousePressed(MouseEvent e) { if (!graph.hasFocus()) graph.requestFocus(); aborted = false; selectOnRelease = false; if (status == SELECTION && graph.isSelectionEnabled()) { // find where was clicked... int s = graph.getTolerance(); Rectangle2D r = graph.fromScreen(new Rectangle(e.getX() - s, e.getY() - s, 2 * s, 2 * s)); focus = (focus != null && focus.intersects(graph, r)) ? focus : null; Point2D point = graph.fromScreen(new Point(e.getPoint())); // changed from original because of overlapping if (focus == null) { cell = graph.getNextViewAt(focus, point.getX(), point.getY()); focus = cell; } else { cell = focus; } // if it's right mouse button show popup menu, otherwise user whish to select something if (SwingUtilities.isRightMouseButton(e)) { // POPUP if (cell != null) { if (!graph.isCellSelected(cell.getCell())) { selectCellForEvent(cell.getCell(), e); } } else { graph.clearSelection(); } ((GraphMarqueeHandler) marquee).popupMenu(e.getPoint()); } else { // SIMPLE SELECTION if (cell != null) { if (e.getClickCount() == 2) { startEditing(cell.getCell(), e); } else { if (graph.isCellSelected(cell.getCell()) && !e.isControlDown() && graph.getSelectionCells().length>1) { selectOnRelease = true; } else { if (!graph.isCellSelected(cell.getCell()) || e.isControlDown()) { selectCellForEvent(cell.getCell(), e); } } if (handle != null) { handle.mousePressed(e); } } } else { // MULTIPLE SELECTION marquee.mousePressed(e); status = MULTIPLE_SELECTION; } } } if (SwingUtilities.isRightMouseButton(e)) { if (status == INSERT_TRANSITION_POINTS) { status = INSERT_TRANSITION_START; ((GraphMarqueeHandler) marquee).reset(); } else { ((GraphMarqueeHandler) marquee).setSelectionMode(); status = SELECTION; } } else { if (graph.isEditable()) { if (status == INSERT_PARTICIPANT) { // maybe latter we can add inserting participants where user choose, not at end... ((GraphMarqueeHandler) marquee).insertParticipant(); } else if (status == INSERT_SPEC_ELEMENT) { // this is reserved for special buttons... like block or process. Maybe we should move them somewhere. ((GraphMarqueeHandler) marquee).insertSpecialElement(); } else if (status == INSERT_ELEMENT) { ((GraphMarqueeHandler) marquee).insertElement((Point) getGraph().fromScreen(e.getPoint())); } else if (status == INSERT_TRANSITION_START) { GraphPortViewInterface gpvi = (GraphPortViewInterface) graph.getPortViewAt(e.getX(), e.getY()); if (gpvi != null) { if (((GraphMarqueeHandler) marquee).insertTransitionFirstPort(gpvi)) { status = INSERT_TRANSITION_POINTS; } } } else if (status == INSERT_TRANSITION_POINTS) { GraphPortViewInterface gpvi = (GraphPortViewInterface) graph.getPortViewAt(e.getX(), e.getY()); if (gpvi == null) { ((GraphMarqueeHandler) marquee).addPoint(e.getPoint()); ((GraphMarqueeHandler) marquee).drawTransition(e); } else { if (((GraphMarqueeHandler) marquee).insertTransitionSecondPort(gpvi)) { status = INSERT_TRANSITION_START; ((GraphMarqueeHandler) marquee).reset(); } } } } else { // maybe display info... external package so can't be edited... } } e.consume(); } public void mouseMoved(MouseEvent e) { if (status == INSERT_TRANSITION_START || status == INSERT_TRANSITION_POINTS) { ((GraphMarqueeHandler) marquee).drawTransition(e); } e.consume(); } public void mouseDragged(MouseEvent e) { if (status == SELECTION && !aborted) { // added - if one of selected cell is Participant there must be no dragging Object[] sc = graph.getSelectionCells(); if (sc != null) { for (int i = 0; i < sc.length; i++) { if (sc[i] instanceof GraphParticipantInterface) { e.consume(); return; } } } selectOnRelease = false; autoscroll(graph, e.getPoint()); if (handle!=null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -