?? workflow_graphed.java
字號:
package treedoc;
/**
*
增加一些添加節(jié)點的方法
流程圖主要工作類............
*/
/**
* 名稱 : WORKFLOW_GRAPHED
* 描述 : WWW.FANGFA.NET 工作流管理系統(tǒng)--流程拓?fù)鋱D處理類
* 版權(quán)信息 : Copyright (c) 2004 COMSCI
* @作者 : COMSCI Sichuan Fangfa Digital
* @版本 : 0.9 builder 2004091910
* @日期 : 2004/09/19
*/
import java.net.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import javax.swing.event.*;
import org.jgraph.*;
import org.jgraph.event.*;
import org.jgraph.graph.*;
import org.jgraph.graph.EdgeView.*;
public class workflow_GraphEd
extends JPanel
implements GraphSelectionListener, KeyListener {
// JGraph instance
public JGraph graph;
workflow_Graph2Gxl he = new workflow_Graph2Gxl("");
// Undo Manager
protected GraphUndoManager undoManager;
public workflow_GraphEd_ChangeCellAttribute_Dialog ed;
Icon image2, image3, start, end;
private String status1 = "";
// Actions which Change State
protected Action undo,
redo,
remove,
group,
ungroup,
tofront,
toback,
cut,
copy,
export,
paste;
//
// Main
//
// Main Method
/* public static void main(String[] args) {
try {
LookAndFeel alloyLnF = new com.incors.plaf.alloy.AlloyLookAndFeel();
UIManager.setLookAndFeel(alloyLnF);
Enumeration enum = UIManager.getDefaults().keys();
String str;
while (enum.hasMoreElements()) {
str = (String) enum.nextElement();
if (str.endsWith("font")) {
UIManager.put(str, new Font("宋體", 0, 12));
}
}
}
catch (Exception e) {}
JFrame frame = new JFrame("GraphEd");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new workflow_GraphEd());
URL jgraphUrl = workflow_GraphEd.class.getClassLoader().getResource(
"resources/jgraph.gif");
if (jgraphUrl != null) {
ImageIcon jgraphIcon = new ImageIcon(jgraphUrl);
frame.setIconImage(jgraphIcon.getImage());
}
frame.setSize(520, 390);
frame.show();
}
*/
//
// Editor Panel
//
// Construct an Editor Panel
public workflow_GraphEd(String status) {
status1 = status;
// Use Border Layout
image2 = new ImageIcon("resources/ren1.gif");
image3 = new ImageIcon("resources/icon2.gif");
start = new ImageIcon("resources/start.gif");
end = new ImageIcon("resources/end.gif");
setLayout(new BorderLayout());
// Construct the Graph
graph = new MyGraph(new MyModel());
// graph.setOpaque(true);
// ed = new GraphEd_ChangeCellAttribute_Dialog(this);
// Construct Command History
//
// Create a GraphUndoManager which also Updates the ToolBar
undoManager = new GraphUndoManager() {
// Override Superclass
public void undoableEditHappened(UndoableEditEvent e) {
// First Invoke Superclass
super.undoableEditHappened(e);
// Then Update Undo/Redo Buttons
updateHistoryButtons();
}
};
// Add Listeners to Graph
//
// Register UndoManager with the Model
// Update ToolBar based on Selection Changes
// graph.setGridColor(Color.BLACK);
// Construct Panel
//
// Add a ToolBar
if (status.equals("")) {
add(createToolBar(), BorderLayout.NORTH);
graph.getModel().addUndoableEditListener(undoManager);
graph.getSelectionModel().addGraphSelectionListener(this);
// Listen for Delete Keystroke when the Graph has Focus
graph.addKeyListener(this);
graph.setGridEnabled(true);
graph.setGridVisible(true);
graph.setAntiAliased(true);
graph.setPortsVisible(false);
}
else {
// do nothing
graph.setGridEnabled(true);
graph.setGridVisible(true);
graph.setAntiAliased(true);
add(createToolBar1(), BorderLayout.NORTH);
}
// Add the Graph as Center Component
JScrollPane jsc = new JScrollPane(graph);
jsc.setVerticalScrollBarPolicy(jsc.VERTICAL_SCROLLBAR_ALWAYS);
jsc.setHorizontalScrollBarPolicy(jsc.HORIZONTAL_SCROLLBAR_ALWAYS);
// jsc.HORIZONTAL_SCROLLBAR_ALWAYS
add(jsc, BorderLayout.CENTER);
}
//
public boolean Edit() {
boolean result = false;
return result;
}
// 插入新節(jié)點
public void insert(Point2D point) {
DefaultGraphCell vertex = new DefaultGraphCell();
vertex.add(new DefaultPort());
Map map = new Hashtable();
// Snap the Point to the Grid
point = graph.snap( (Point2D) point.clone());
// Default Size for the new Vertex
Dimension size = new Dimension(42, 60);
// GraphConstants.setAutoSize(map,true);
GraphConstants.setBounds(map, new Rectangle2D.Double(
point.getX(), point.getY(), size.width, size.height));
GraphConstants.setIcon(map, image2);
// GraphConstants.setBorderColor(map, Color.black);
// GraphConstants.setBackground(map, Color.lightGray);
// GraphConstants.setBorder(map, BorderFactory.createRaisedBevelBorder());
GraphConstants.setOpaque(map, true);
GraphConstants.setValue(map, "新節(jié)點");
GraphConstants.setLabelAlongEdge(map, true);
GraphConstants.setLineStyle(map, GraphConstants.STYLE_BEZIER);
// GraphConstants.STYLE_BEZIER
Hashtable attributes = new Hashtable();
attributes.put(vertex, map);
// 添加頂點屬性
graph.getGraphLayoutCache().insert( ////在新的LAYOUT中插入新的頂點
new Object[] {vertex}
, attributes, null,
null,
null);
}
// 插入固定開始定點//
public void insert_start(Point2D point) {
DefaultGraphCell vertex = new DefaultGraphCell();
vertex.add(new DefaultPort());
Map map = new Hashtable();
// Snap the Point to the Grid
point = graph.snap( (Point2D) point.clone());
// Default Size for the new Vertex
Dimension size = new Dimension(60, 78);
// 添加頂點屬性
GraphConstants.setBounds(map, new Rectangle2D.Double(
point.getX(), point.getY(), size.width, size.height));
// GraphConstants.setAutoSize(map,true);
GraphConstants.setIcon(map, start);
// GraphConstants.setBorderColor(map, Color.black);
// GraphConstants.setBackground(map, Color.blue);
GraphConstants.setOpaque(map, true);
GraphConstants.setValue(map, "工作開始");
Hashtable attributes = new Hashtable();
attributes.put(vertex, map);
graph.getGraphLayoutCache().insert( ////在新的LAYOUT中插入新的頂點
new Object[] {vertex}
, attributes, null,
null,
null);
}
// 插入固定結(jié)束定點
public void insert_end(Point2D point) {
DefaultGraphCell vertex = new DefaultGraphCell();
vertex.add(new DefaultPort());
Map map = new Hashtable();
// Snap the Point to the Grid
point = graph.snap( (Point2D) point.clone());
// Default Size for the new Vertex
Dimension size = new Dimension(60, 78);
// GraphConstants.setAutoSize(map,true);
GraphConstants.setBounds(map, new Rectangle2D.Double(
point.getX(), point.getY(), size.width, size.height));
GraphConstants.setIcon(map, end);
// GraphConstants.setBorderColor(map, Color.black);
// GraphConstants.setBackground(map, Color.blue);
GraphConstants.setOpaque(map, true);
GraphConstants.setValue(map, "工作結(jié)束");
Hashtable attributes = new Hashtable();
attributes.put(vertex, map);
// 添加頂點屬性
graph.getGraphLayoutCache().insert( ////在新的LAYOUT中插入新的頂點
new Object[] {vertex}
, attributes, null,
null,
null);
}
// 在SOURCE和目的節(jié)點中插入一條邊
public void connect(Port source, Port target) {
ConnectionSet cs = new ConnectionSet();
DefaultEdge edge = new DefaultEdge();
cs.connect(edge, source, target);
Map map = new Hashtable();
// Add a Line End Attribute
GraphConstants.setLineEnd(map, GraphConstants.ARROW_SIMPLE);
// Add a label along edge attribute
GraphConstants.setLabelAlongEdge(map, true);
// Construct a Map from cells to Maps (for insert)
Hashtable attributes = new Hashtable();
// Associate the Edge with its Attributes
attributes.put(edge, map);
// Insert the Edge and its Attributes
graph.getGraphLayoutCache().insert(
new Object[] {edge}
, attributes, cs,
null,
null);
}
// Create a Group that Contains the Cells
public void group(Object[] cells) {
// Order Cells by View Layering
cells = graph.getGraphLayoutCache().order(cells);
// If Any Cells in View
if (cells != null && cells.length > 0) {
// Create Group Cell
int count = getCellCount(graph);
DefaultGraphCell group =
new DefaultGraphCell(new Integer(count - 1));
// Create Change Information
ParentMap map = new ParentMap();
// Insert Child Parent Entries
for (int i = 0; i < cells.length; i++) {
map.addEntry(cells[i], group);
// Insert into model
}
graph.getGraphLayoutCache().insert(
new Object[] {group}
,
null,
null,
map,
null);
}
}
// Returns the total number of cells in a graph
protected int getCellCount(JGraph graph) {
Object[] cells = graph.getDescendants(graph.getRoots());
return cells.length;
}
// Ungroup the Groups in Cells and Select the Children
public void ungroup(Object[] cells) {
// If any Cells
if (cells != null && cells.length > 0) {
// List that Holds the Groups
ArrayList groups = new ArrayList();
// List that Holds the Children
ArrayList children = new ArrayList();
// Loop Cells
for (int i = 0; i < cells.length; i++) {
// If Cell is a Group
if (isGroup(cells[i])) {
// Add to List of Groups
groups.add(cells[i]);
// Loop Children of Cell
for (int j = 0;
j < graph.getModel().getChildCount(cells[i]);
j++) {
// Get Child from Model
Object child = graph.getModel().getChild(cells[i], j);
// If Not Port
if (! (child instanceof Port)) {
// Add to Children List
children.add(child);
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -