workflow在java中_workflow_graphed.java 源代码在线查看 - 用java实现的工作流 资源下载 虫虫电子下载站...

package treedoc;/*** 增加一些添加节点的方法 流程图主要工作类............ *//** * 名称 : WORKFLOW_GRAPHED * 描述 : WWW.FANGFA.NET 工作流管理系统--流程拓扑图处理类 * 版权信息 : 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; } // 插入新节点 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, "新节点"); 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); } // 插入固定结束定点 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, "工作结束"); Hashtable attributes = new Hashtable(); attributes.put(vertex, map);// 添加顶点属性 graph.getGraphLayoutCache().insert( 在新的LAYOUT中插入新的顶点 new Object[] {vertex} , attributes, null, null, null); } // 在SOURCE和目的节点中插入一条边 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); } } } }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值