📄 workflow_rtcview.java
字号:
package treedoc;
/*
* to redisplay a gxl file to JGraph ,we need read it to mem and use some methods
* to
*
*/
/**
* 增加一些方法,实现RT监控流程节点状态,并在图中显示
* 还原显示GXL文件成JGRAPH图的类.....
* 这个文件里面有些被注释了的代码是从解析流程图类中继承过来的类中不用的
*/
/**
* 名称 : WORKFLOW_RTCVIEW
* 描述 : WWW.FANGFA.NET 工作流管理系统--"实时"显示流程图的状态类
* 版权信息 : Copyright (c) 2004 COMSCI
* @作者 : COMSCI Sichuan Fangfa Digital
* @版本 : 0.9 builder 2004091910
* @日期 : 2004/09/19
*/
import java.io.*;
import java.util.*;
import java.util.List;
import javax.xml.parsers.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
import org.jgraph.*;
import org.jgraph.graph.*;
import org.jgraph.pad.*;
import org.w3c.dom.*;
public class workflow_RTCView
extends workflow_AbstractActionDefault {
String files;
workflow_StepMain ws;
String fid;
String gi;
Map node_attrs;
public workflow_RTCView(String file) {
files = file;
ws = new workflow_StepMain("");
}
public void actionPerformed(ActionEvent e) {
try {
JGraph graph = getCurrentGraph();
parseGXLFileInto_RTC(files, graph, fid);
}
catch (Exception ex) {
System.out.println(ex);
}
}
// 开始进行GXL文件解析............
/**
* Extracts visual properties of the node from the child 'view' element
* Currently recognized properties: 目前可以识别的属性如下
* - font, attrs: name, size, style(plain, bold, italic)
* - color
* - background-color
* - autosize
*/
static void fetchNodeViewProperties_RTC(Node gnode, Map gnode_attrs) {
NodeList gnode_children = gnode.getChildNodes();
for (int gnode_child_i = 0; gnode_child_i < gnode_children.getLength();
gnode_child_i++) {
Node gnode_child = gnode_children.item(gnode_child_i);
if (gnode_child.getNodeName().equals("view")) { // 获得顶点的属性
Element node_view = (Element) gnode_child;
Font font = GraphConstants.DEFAULTFONT;
String fontName = null;
if (node_view.getAttribute("font-name") != null) {
fontName = node_view.getAttribute("font-name").toString();
}
float fontSize = font.getSize2D();
if (node_view.getAttribute("font-size") != null) {
try {
fontSize = Float.parseFloat(node_view.getAttribute("font-size"));
}
catch (NumberFormatException nfe) {
}
}
int styleMask = 0;
if (node_view.getAttribute("font-style") != null) {
String style = node_view.getAttribute("font-style");
if (style.equals("plain")) {
styleMask = Font.PLAIN;
}
if (style.indexOf("italic") != -1) {
styleMask += Font.ITALIC;
}
if (style.indexOf("bold") != -1) {
styleMask += Font.BOLD;
}
}
if (fontName != null) {
font = new Font(fontName, styleMask, (int) fontSize);
}
else {
font = font.deriveFont(styleMask, fontSize);
}
GraphConstants.setFont(gnode_attrs, font);
if (node_view.getAttribute("color") != null) {
try {
int color = Integer.parseInt(node_view.getAttribute("color"));
GraphConstants.setForeground(gnode_attrs, new Color(color));
GraphConstants.setBorderColor(gnode_attrs, new Color(color));
GraphConstants.setLineColor(gnode_attrs, new Color(color));
}
catch (NumberFormatException nfe) {
}
}
if (node_view.getAttribute("background-color") != null) {
try {
int color = Integer.parseInt(node_view.getAttribute(
"background-color"));
GraphConstants.setBackground(gnode_attrs, new Color(color));
}
catch (NumberFormatException nfe) {
}
}
if (node_view.getAttribute("auto-size") != null) {
GraphConstants.setAutoSize(gnode_attrs,
"true".equals(node_view.
getAttribute("auto-size")));
}
}
}
}
static void fetchEdgeViewProperties_RTC(Node enode, Map enode_attrs) {
fetchNodeViewProperties_RTC(enode, enode_attrs);
GraphConstants.setLineEnd(enode_attrs, GraphConstants.ARROW_SIMPLE);
GraphConstants.setLineStyle(enode_attrs, GraphConstants.STYLE_BEZIER);
}
public void parseGXLFileInto_RTC(
String name,
JGraph graph, String fid) throws Exception {
String defaultLayout = null;
GraphModel model = graph.getModel();
File f = new File(name);
Object[] oldCells = graph.getRoots();
if (oldCells != null) {
oldCells =
DefaultGraphModel.getDescendants(model, oldCells).toArray();
model.remove(oldCells);
}
//初始化DOM类并开始创建DOM的实例
// Create a DocumentBuilderFactory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// Create a DocumentBuilder
DocumentBuilder db = dbf.newDocumentBuilder();
// Parse the input file to get a Document object
Document doc = db.parse(f);
// Get the first child (the graph-element)
// List for the new Cells
graph.setAntiAliased(true);
graph.setEditable(false);
graph.setDragEnabled(false);
graph.setDropEnabled(false);
Element gxl = (Element) doc.getDocumentElement(); // 第一个GXL文件元素
List newCells = new ArrayList();
// ConnectionSet for the Insert method
ConnectionSet cs = new ConnectionSet();
// Hashtable for the ID lookup (ID to Vertex)
Map ids = new Hashtable();
// Hashtable for Attributes (Vertex to Map)
Hashtable attributes = new Hashtable();
NodeList graph_list = gxl.getChildNodes();
if (graph_list.getLength() == 0) {
return;
}
for (int graph_index = 0; graph_index < graph_list.getLength();
graph_index++) {
Node graph_node = graph_list.item(graph_index);
if (graph_node.getNodeName().equals("graph")) {
Element graph_elem = (Element) graph_node;
NodeList list = graph_elem.getChildNodes();
boolean defaultDirected = "directed".equals(graph_elem.getAttribute(
"edgemode")) ||
"defaultdirected".equals(graph_elem.getAttribute("edgemode"));
// Get Graph's Child Nodes (the cells)
// Loop Children
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
// Fetch Label
String label = getLabel_RTC(node);
// 取该label对应的stepid,通过stepid获得活动状态,step_detail中的信息
// 然后调用相应的绘制节点方法...
// 如果顶点元素有效
if (node.getAttributes() != null && node.getNodeName() != null) {
// Fetch Type
String type = node.getNodeName().toString().toLowerCase();
// 创建一个顶点元素
if (type.equals("node")) {
// Fetch ID Node
String id = null;
Node tmp = node.getAttributes().getNamedItem("id");
// Fetch ID Value
if (tmp != null) {
id = tmp.getNodeValue();
// 获得一个有效的唯一的顶点ID
}
if (id != null && !ids.keySet().contains(id)) {
// Create Vertex with label
DefaultGraphCell vertex = new DefaultGraphCell(new
GPUserObject(
label));
// Add One Floating Port
vertex.add(new DefaultPort());
// Add ID, Vertex pair to Hashtable
ids.put(id, vertex);
// Add Default Attributes
if (this.ws.active_step(id, fid)) {
//如果该点是活动的........
node_attrs = createActiveAttributes_RTC(); //特殊活动显示属性
gi = "a";
}
else if (!this.ws.active_step(id, fid)) {
node_attrs = createDefaultAttributes_RTC(); //普通属性
gi = "b";
}
if (this.ws.return_action_status(id, fid).equals("1")) { //已经被处理过
node_attrs = createactionAttributes_RTC();
// gi = "c";
}
// 获得GXL中的顶点位置元素
int idd = 0;
int iddd[] = {
0, 0, 0, 0};
for (Enumeration e = getBound_RTC(node).elements();
e.hasMoreElements(); ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -