📄 flowdiagram.java
字号:
}
}
return null;
}
/**
* 获取流程流转Relation
*
* @param
*/
public Element getElementByBeginEndNodeID(String startid, String endid) {
if (startid == null || startid.trim().length() == 0 || endid == null
|| endid.trim().length() == 0) {
return null;
}
for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
Element em = (Element) e.nextElement();
if (em._subelems != null) {
for (Enumeration sube = em._subelems.elements(); sube
.hasMoreElements();) {
Element subem = (Element) sube.nextElement();
if (subem instanceof Relation) {
Relation relation = (Relation) subem;
if (relation.id != null
&& relation.startnodeid.equals(startid)
&& relation.endnodeid.equals(endid)) {
return subem;
}
}
}
}
}
return null;
}
/**
* @throws java.lang.Exception
* @roseuid 3E0A6E1B010F
*/
private void jbInit() throws Exception {
this.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(ComponentEvent e) {
this_componentResized(e);
}
});
this.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
this_mouseMoved(e);
}
public void mouseDragged(MouseEvent e) {
this_mouseDragged(e);
}
});
this.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(MouseEvent e) {
this_mouseClicked(e);
}
public void mousePressed(MouseEvent e) {
this_mousePressed(e);
}
public void mouseReleased(MouseEvent e) {
this_mouseReleased(e);
}
public void mouseEntered(MouseEvent e) {
this_mouseEntered(e);
}
});
}
/**
* @param e
* @roseuid 3E0A6E1B0123
*/
void this_mouseClicked(MouseEvent e) {
int x = getDiagramX(e);
int y = getDiagramY(e);
if (e.getClickCount() >= 2) {
Element em = this.chkSelectedElement(x, y);
if (em != null) {
win.eval("javascript:editElement()");
}
}
}
/**
* @param e
* @roseuid 3E0A6E1B0137
*/
void this_mousePressed(MouseEvent e) {
int x = getDiagramX(e);
int y = getDiagramY(e);
switch (this._statues) {
case ACTION_ADD_ABORTNODE:
addAbortNode("", x, y);
break;
case ACTION_ADD_AUTONODE:
addAutoNode("", x, y);
break;
case ACTION_ADD_COMPLETENODE:
addCompleteNode("", x, y);
break;
case ACTION_ADD_MANUALNODE:
addManualNode("", x, y);
break;
case ACTION_ADD_RELATION:
addRelation("", "", "", "", "");
break;
case ACTION_ADD_STARTNODE:
addStartNode("", x, y);
break;
case ACTION_ADD_SUSPENDNODE:
addSuspendNode("", x, y);
break;
case ACTION_ADD_TERMINATENODE:
addTerminateNode("", x, y);
break;
default:
break;
}
boolean isChangeCursor = false;
PaintElement em = this.chkSelectedElement(x, y);
if (em != null) {
if (em instanceof Node) {// 设置抓取点
((Node) em)._handlePoint.x = x - ((Node) em).x;
((Node) em)._handlePoint.y = y - ((Node) em).y;
}
_changed = true;
if (_statues == ACTION_REMOVE) {
deleteMSG = null;
if (em instanceof Relation) {
Relation r = (Relation) em;
if (r.ispassed) {
deleteMSG = "相关流程已处理,不能删除!";
}
}
if (em instanceof Node) {
Node nd = (Node) em;
if (em.id != null && nd._iscurrent) {
deleteMSG = "当前节点在处理中,不能删除!";
} else {
for (Enumeration el = this.getAllElements().elements(); deleteMSG == null
&& el.hasMoreElements();) {
Element elem = (Element) el.nextElement();
if (elem instanceof Relation) {
Relation rl = (Relation) elem;
if (((rl.startnodeid != null && rl.startnodeid
.equals(em.id)) || (rl.endnodeid != null && rl.endnodeid
.equals(em.id)))
&& rl.ispassed) {
deleteMSG = "相关流程已处理,不能删除!";
}
}
}
}
}
if (deleteMSG == null) {
this.removeElement(em);
}
} else if (_statues == ACTION_BREAK_LINE) { // add by gusd
if (em instanceof Relation) {
_selected = (PaintElement) em;
Relation relation = (Relation) _selected;
relation.setBreakpoint(new Point(x, y));
isChangeCursor = true;
}
} // add by gusd
else {
if (_selected instanceof Relation && em instanceof Node) {
Relation r = (Relation) _selected;
if (r.getStartnode() == null && em != null) {
r.setStartnode((Node) em);
Node node = (Node) em;
Point point = new Point(node.x, node.y);
r.addVector((Object) point);
}
} else if (em instanceof Relation) {
this.changeStatues(ACTION_BREAK_LINE);
_selected = (PaintElement) em;
Relation relation = (Relation) _selected;
relation.setChangevector(-1);
int pos = relation.checkWhichpoint(new Point(x, y)); // 检查按下点是否恰好在该流程线的原有折点上,如果是,返回该折点的位置
relation.setBreakpoint(new Point(x, y));
relation.setCurrentselect(true);
isChangeCursor = true;
} else {
this._selected = em;
_selected.moveTo(x, y);
}
}
repaint();
} else {
if ((_statues == this.ACTION_ADD_RELATION)
&& (_selected instanceof Relation)) {
Relation r = (Relation) _selected;
if (r.getStartnode() == null) {
this.removeElement(r);
r = null;
_selected = null;
}
}
}
if (!isChangeCursor) { // isChangeCursor为true时,用户准备拖拉流程线,不释放鼠标指针的拖拉样式
this.changeStatues(this.ACTION_NORMAL);
isChangeCursor = false;
}
}
/**
* @param e
* @roseuid 3E0A6E1B0155
*/
void this_mouseReleased(MouseEvent e) {
int x = getDiagramX(e);
int y = getDiagramY(e);
Element em = this.chkSelectedElement(x, y);
if (_selected != null && _selected instanceof Relation
&& (em == null || em instanceof Node)) {
Relation r = (Relation) _selected;
r.setCurrentselect(false);
if (r.getEndnode() == null) {
if (em != null) {
_changed = true;
r.setEndnode((Node) em);
Node node = (Node) em;
Point point = new Point(node.x, node.y);
r.addVector((Object) point);
}
if (em == null || r.getStartnode().id.equals(r.getEndnode().id)) {
_elems.removeElement(r);
}
} else {
// 忽略掉10个像素差异
int nx = Math.round(x / 10) * 10;
int ny = Math.round(y / 10) * 10;
int pos = r.getChangevector();
r.setCurrentselect(false);
if (pos == -1) { // 原先按下的点不是原有折点
boolean bool = r.checkDistance(new Point(nx, ny));
if (!bool) { // 检查鼠标释放的点拖拉的距离是否小于一个常量,如果是,则当作没有拖拉
r.addVector(new Point(nx, ny)); // 如果鼠标释放的点拖拉的距离大于一个常量,则当作一个新的折点
}
} else { // 原先按下的点为原有折点,鼠标释放后要改变原有折点的坐标
r.changeVector(new Point(nx, ny));
r.setChangevector(-1);
}
}
}
// 设置当前选中
if (_selected != null && em != null && _selected.equals(em)) {
_currToEdit = em;
if (em instanceof Node) {
Node nd = (Node) em;
Point p = new Point((int) (nd.x + nd._imgrect.width / 2),
(int) (nd.y + nd._imgrect.height / 2));
// 忽略掉10个像素差异
int nx = p.x;
int ny = p.y;
nx = Math.round(nx / 10) * 10;
ny = Math.round(ny / 10) * 10;
((Node) em).x = nx - nd._imgrect.width / 2;
((Node) em).y = ny - nd._imgrect.height / 2;
}
}
this.changeStatues(this.ACTION_NORMAL);
_selected = null;
this.repaint();
}
/**
* @param e
* @roseuid 3E0A6E1B0169
*/
void this_mouseMoved(MouseEvent e) {
int x = getDiagramX(e);
int y = getDiagramY(e);
if (this._statues == ACTION_BREAK_LINE) {
}
else {
Graphics tg = _tmpimg.getGraphics();
tg.setColor(java.awt.Color.black);
PaintElement em = this.chkSelectedElement(x, y);
if ((em != null) && !(em instanceof Relation)) {
this.changeStatues(this._statues);
// if(this._statues == ACTION_REMOVE){
// }
Node nd = (Node) em;
if (em.isSelected(x, y)) {
String snote = "";
if (nd.note == null || nd.note.equals("null")) {
snote = "";
} else if (nd.note.getBytes().length <= 18) {
snote = nd.note;
} else {
snote = nd.note.substring(0, 9) + "...";
}
nd.showTips(tg); // 显示注释
paintScreen(this.getGraphics());
}
} else {
this.repaint();
}
}
}
/**
* @param e
* @roseuid 3E0A6E1B0187
*/
void this_mouseDragged(MouseEvent e) {
int x = getDiagramX(e);
int y = getDiagramY(e);
if (this._selected != null && this._statues != ACTION_BREAK_LINE
&& this._selected instanceof Relation) { // 从一个结点到另一个结点画流程的拖拉过程中
Relation r = (Relation) this._selected;
if (r.getEndnode() == null) {
_selected.moveTo(x, y);
this.repaint();
}
} else if (this._selected != null && this._statues != ACTION_BREAK_LINE) {
_selected.moveTo(x, y);
this.repaint();
} else if (this._selected != null && this._selected instanceof Relation
&& this._statues == ACTION_BREAK_LINE) { // 拖拉流程线产生折点的过程
Relation r = (Relation) this._selected;
Point p = new Point(x, y);
int pos = r.getChangevector(); // 检查拖拉点是否原有折点
r.setCurrentselect(true);
if (pos == -1) { // 拖拉点不是原有折点,把鼠标移动点作为临时的_movepoint
r.setMovepoint(p);
} else { // 拖拉点是原有折点,鼠标移动点当作原有折点的新位置
r.changeVector(p);
}
this.repaint();
} // end
}
/**
* @param e
* @roseuid 3E0A6E1B019B
*/
void this_componentResized(ComponentEvent e) {
_tmpimg = this.createImage(this.size().width, this.size().height);
}
public boolean isAssignBack(Node node) { // 删除节点时判断此节点是否为指定回退节点
boolean isAssignBack = false;
for (Enumeration e = this.getAllElements().elements(); e
.hasMoreElements();) {
Element em = (Element) e.nextElement();
if (em != null && em instanceof ManualNode) {
ManualNode nd = (ManualNode) em;
if (nd.exceedaction != null
&& nd.exceedaction.trim().equals(FlowType.DOBACKTONODE)
&& nd.backnodeid.equals(node.id)) {
return true;
}
}
}
return isAssignBack;
}
void this_mouseEntered(MouseEvent e) {
}
public static void main(String[] args) {
FlowDiagram fd = new FlowDiagram();
try {
System.out.println(fd.getFlowstatus());
// fd.setFlowstatus(FLOWSTATUS_OPEN_START);
System.out.println("FLOWSTATUS_OPEN_START");
fd.setFlowstatus(FlowType.FLOWSTATUS_OPEN_RUN_RUNNING);
System.out.println("FLOWSTATUS_OPEN_RUN_RUNNING");
fd.setFlowstatus(FlowType.FLOWSTATUS_OPEN_RUN_SUSPEND);
System.out.println("FLOWSTATUS_OPEN_RUN_SUSPEND");
fd.setFlowstatus(FlowType.FLOWSTATUS_OPEN_RUN_SUSPEND);
System.out.println("FLOWSTATUS_OPEN_RUN_SUSPEND");
fd.setFlowstatus(FlowType.FLOWSTATUS_OPEN_RUN_RUNNING);
System.out.println("FLOWSTATUS_OPEN_RUN_RUNNING");
fd.setFlowstatus(FlowType.FLOWSTATUS_OPEN_RUN_RUNNING);
System.out.println("FLOWSTATUS_OPEN_RUN_RUNNING");
fd.setFlowstatus(FlowType.FLOWSTATUS_CLOSE_COMPLETE);
System.out.println("FLOWSTATUS_CLOSE_COMPLETE");
System.out.println("FLOWSTATUS-->" + fd.getFlowstatus());
} catch (Exception e) {
System.out.println("error!");
e.printStackTrace();
}
}
/**
* 获取当前节点关联的所有下一个节点
*
* @param currnodeid
* @return
*/
public Collection getNextNodeList(String currnodeid) {
Element em = this.getElementByID(currnodeid);
if (em instanceof Node) {
Node node = (Node) em;
Vector relations = this.getNodeNextRelation(node);
Collection colls = new ArrayList();
if (relations != null) {
Iterator it = relations.iterator();
while (it.hasNext()) {
Node nextNode = this.getNextNode((Relation) it.next());
if (nextNode != null) {
colls.add(nextNode);
}
}
}
return colls;
}
return null;
}
/**
* 获取所有后续节点列表
*/
public Collection getAllFollowNodeOnPath(String nodeid) {
class FollowNodeOnPath {
Collection list = new ArrayList();
Collection getAllFollowNodeOnPath(Node beginNode) {
Collection nextNodeList = getNextNodeList(beginNode.id);
for (Iterator iter = nextNodeList.iterator(); iter.hasNext();) {
Node node = (Node) iter.next();
if (!list.contains(node)) {
list.add(node);
list.addAll(getAllFollowNodeOnPath(node));
}
}
return list;
}
}
Element em = getElementByID(nodeid);
if (em != null && em instanceof Node) {
Node node = (Node) getElementByID(nodeid);
return (new FollowNodeOnPath()).getAllFollowNodeOnPath(node);
}
return null;
}
/**
* 获取当前节点列表关联的所有下一个节点
*/
public Collection getNextNodeList(Collection nodelist) {
ArrayList rtn = new ArrayList();
if (nodelist != null) {
for (Iterator iter = nodelist.iterator(); iter.hasNext();) {
Node nd = (Node) iter.next();
String currid = nd.id;
Collection colls = getNextNodeList(currid);
rtn.addAll(colls);
}
}
return rtn;
}
/**
* 获取结点列表
*/
public Collection getNodeListByIds(String[] ids) {
ArrayList rtn = new ArrayList();
if (ids != null) {
for (int i = 0; i < ids.length; i++) {
Element em = this.getElementByID(ids[i]);
if (em instanceof Node) {
rtn.add(em);
}
}
}
return rtn;
}
int getDiagramX(MouseEvent e) {
return (int) (e.getX() * _zoomrate);
}
int getDiagramY(MouseEvent e) {
return (int) (e.getY() * _zoomrate);
}
/**
* 获取指定结点上一结点列表
*/
/*
* public Collection getPreviousNodeList(String currid) { ArrayList rtn =
* new ArrayList(); if (currid!=null) { Element em =
* this.getaElementByID(currid); } return null; }
*/
public void toJpegImage(File file) throws Exception {
FileOutputStream out = new FileOutputStream(file);
toJpegImage(out);
out.close();
}
public void toJpegImage(OutputStream out) throws Exception {
this.setSize(1000, 600);
// BufferedImage image = new BufferedImage(this.getSize().width, this
// .getSize().height, BufferedImage.TYPE_INT_RGB);
//
BufferedImage image = (BufferedImage) _tmpimg;
Graphics g = image.getGraphics();
//
// this._tmpimg = image;
update(g, true);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -