⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editorgraphui.java

📁 JGraph扩展应用。自定义Renderer,自定义视图View实现自定义工作流控件
💻 JAVA
字号:
/**
 * 
 */
package flow.graph.test;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.event.CellEditorListener;

import org.jgraph.graph.CellView;
import org.jgraph.graph.GraphCellEditor;
import org.jgraph.plaf.basic.BasicGraphUI;
import org.jgraph.plaf.basic.BasicGraphUI.MouseInputHandler;

/**
 * @author Administrator
 *
 */
public class EditorGraphUI extends BasicGraphUI {

	protected CellEditorListener cellEditorListener;

	protected JFrame editDialog = null;

	/** 
	* Create the dialog using the cell's editing component. 
	*/
	protected void createEditDialog(Object cell) {
		Dimension editorSize = editingComponent.getPreferredSize();
		editDialog = new JFrame("Edit " + graph.convertValueToString(cell));
		editDialog.setSize(editorSize.width, editorSize.height);
		editDialog.getContentPane().add(editingComponent);
		editingComponent.validate();
		editDialog.pack();
		editDialog.setVisible(true);
	}

	/** 
	* Stops the editing session. If messageStop is true the editor 
	* is messaged with stopEditing, if messageCancel is true the 
	* editor is messaged with cancelEditing. If messageGraph is true 
	* the graphModel is messaged with valueForCellChanged. 
	*/
	protected void completeEditing(
		boolean messageStop,
		boolean messageCancel,
		boolean messageGraph) {
		if (stopEditingInCompleteEditing
			&& editingComponent != null
			&& editDialog != null) {
			Object oldCell = editingCell;
			GraphCellEditor oldEditor = cellEditor;
			Object newValue = oldEditor.getCellEditorValue();
			boolean requestFocus =
				(graph != null
					&& (graph.hasFocus() || editingComponent.hasFocus()));
			editingCell = null;
			editingComponent = null;
			if (messageStop)
				oldEditor.stopCellEditing();
			else if (messageCancel)
				oldEditor.cancelCellEditing();
			editDialog.dispose();
			if (requestFocus)
				graph.requestFocus();
			if (messageGraph) {
				graphLayoutCache.valueForCellChanged(oldCell, newValue);
			}
			updateSize();
			// Remove Editor Listener 
			if (oldEditor != null && cellEditorListener != null)
				oldEditor.removeCellEditorListener(cellEditorListener);
			cellEditor = null;
			editDialog = null;
		}
	}

	/** 
	* Will start editing for cell if there is a cellEditor and 
	* shouldSelectCell returns true.<p> 
	* This assumes that cell is valid and visible. 
	*/
	protected boolean startEditing(Object cell, MouseEvent event) {
		completeEditing();
		if (graph.isCellEditable(cell) && editDialog == null) {

			// Create Editing Component **** ***** 
			CellView tmp = graphLayoutCache.getMapping(cell, false);
			cellEditor = tmp.getEditor();
			editingComponent =
				cellEditor.getGraphCellEditorComponent(
					graph,
					cell,
					graph.isCellSelected(cell));
			if (cellEditor.isCellEditable(event)) {
				editingCell = cell;

				// Create Wrapper Dialog **** ***** 
				createEditDialog(cell);

				// Add Editor Listener 
				if (cellEditorListener == null)
					cellEditorListener = createCellEditorListener();
				if (cellEditor != null && cellEditorListener != null)
					cellEditor.addCellEditorListener(cellEditorListener);

				if (cellEditor.shouldSelectCell(event)) {
					stopEditingInCompleteEditing = false;
					try {
						graph.setSelectionCell(cell);
					} catch (Exception e) {
						System.err.println("Editing exception: " + e);
					}
					stopEditingInCompleteEditing = true;
				}

				if (event instanceof MouseEvent) {
					/* Find the component that will get forwarded all the 
					mouse events until mouseReleased. */
					Point componentPoint =
						SwingUtilities.convertPoint(
							graph,
							new Point(event.getX(), event.getY()),
							editingComponent);

					/* Create an instance of BasicTreeMouseListener to handle 
					passing the mouse/motion events to the necessary 
					component. */
					// We really want similiar behavior to getMouseEventTarget, 
					// but it is package private. 
					Component activeComponent =
						SwingUtilities.getDeepestComponentAt(
							editingComponent,
							componentPoint.x,
							componentPoint.y);
					if (activeComponent != null) {
						new MouseInputHandler(
							graph,
							activeComponent,
							event);
					}
				}
				return true;
			} else
				editingComponent = null;
		}
		return false;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -