📄 excelmappingdiagram.java
字号:
package cn.myapps.core.dynaform.dts.excelimport;
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Label;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import netscape.javascript.JSObject;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import cn.myapps.core.dynaform.dts.excelimport.utility.CommonUtil;
public class ExcelMappingDiagram extends Canvas {
private static HashMap IMG_RESOURCE = new HashMap(10);
private int _statues; // 鼠标状态
static final int ACTION_NORMAL = 0x00000000;
static final int ACTION_REMOVE = 0x00000001;
static final int ACTION_ADD_ACTOR = 0x00000010;
static final int ACTION_ADD_NODE = 0x00000100;
static final int ACTION_ADD_RELATION = 0x00001000;
static final int ACTION_ADD_GROUP = 0x00010000;
static final int ACTION_EDIT_ACTOR = 0x10000010;
static final int ACTION_EDIT_NODE = 0x10000100;
static final int ACTION_EDIT_RELATION = 0x10001000;
static final int ACTION_EDIT_GROUP = 0x10010000;
static final int ACTION_BREAK_LINE = 0x00100000;
static final int PROCESSOR_TYPE_ACTOR = 1;
static final int PROCESSOR_TYPE_PERSON = 2;
static final int PROCESSOR_TYPE_GROUP = 3;
static final int PROCESSOR_TYPE_TIMER = 4;
private Vector _elems = new Vector();
private XMLOperate _xmlopt;
private Element _selected;
private Element _currToEdit;
Image _tmpimg;
private ExcelMappingPanel _fpanel;
public int flowstatus = FlowType.FLOWSTATUS_OPEN_NOSTART;
public String flowpath = "";;
public String deleteMSG;
private boolean _changed = false;
private String _startnodeid; // 用于在开始流程时设置currnodeid
JSObject win = null;
/**
* @roseuid 3E0428D90248
*/
public ExcelMappingDiagram() {
// _tmpimg = this.createImage(this.size().width, this.size().height);
if (this.getSize().width <= 0 || this.getSize().height <= 0) {
this.setSize(1000, 600);
}
_tmpimg = new BufferedImage(this.getSize().width,
this.getSize().height, BufferedImage.TYPE_INT_RGB);
_statues = ACTION_NORMAL;
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
public Image getImageResource(String filename) {
Object obj = IMG_RESOURCE.get(filename);
Image img = null;
if (obj == null) {
URL uri = null;
uri = this.getClass().getResource(filename);
try {
obj = Toolkit.getDefaultToolkit().createImage(uri);
IMG_RESOURCE.put(filename, obj);
} catch (Exception e) {
obj = getImageResource("unknow.gif");
}
}
img = (Image) obj;
return img;
}
public void setJSObject(JSObject win) {
this.win = win;
}
public int get_statues() {
return this._statues;
}
// 编辑时用到的接口
public Element getCurrToEdit() {
return _currToEdit;
}
public boolean getChanged() {
return this._changed;
}
public void editNode(Node grp) {
this._selected = grp;
}
/**
* @param id
* @param name
* @param description
* @roseuid 3E0406A90239
*/
public void editRelation(Relation rlt) {
this._selected = rlt;
}
public boolean isCurrentSelected(Element em) {
if (em != null && _selected != null && em.equals(_selected)) {
return true;
} else {
return false;
}
}
public boolean isCurrentToEdit(Element em) {
if (em != null && _currToEdit != null && em.equals(_currToEdit)) {
return true;
} else {
return false;
}
}
public boolean isContain(Vector all, Node beforeNode) {
if (all != null) {
Enumeration enm = all.elements();
while (enm.hasMoreElements()) {
Object item = (Object) enm.nextElement();
if (item instanceof Node) {
Node n = (Node) item;
if (n.id == beforeNode.id) {
return true;
}
}
}
}
return false;
}
public void addRelation() {
Relation rlt = new Relation(this);
this.appendElement(rlt);
editRelation(rlt);
}
/**
* @param id
* @roseuid 3E0406B003D4
*/
public void delRelation(String id) {
delElement(id);
}
/**
* 改变鼠标状态
*
* @param statues
* @roseuid 3E0A6E1A0258
*/
public void changeStatues(int statues) {
this._statues = statues;
switch (_statues) {
case ACTION_NORMAL:
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
break;
case ACTION_REMOVE:
this.setCursor(new Cursor(Cursor.N_RESIZE_CURSOR));
break;
case ACTION_ADD_ACTOR:
this.setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
break;
case ACTION_ADD_NODE:
this.setCursor(new Cursor(Cursor.MOVE_CURSOR));
break;
case ACTION_BREAK_LINE: // add by gusd
this.setCursor(new Cursor(Cursor.SW_RESIZE_CURSOR));
break; // end
default:
this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
}
/**
* @param id
* @roseuid 3E0A6E1A03DF
*/
private void delElement(String id) {
for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
Element em = (Element) e.nextElement();
if (em.id != null && em.id.equals(id)) {
_elems.removeElement(em);
}
}
}
/**
* @param g
* @roseuid 3E0A6E1B0047
*/
public void update(Graphics g) {
update(g, true);
}
public void update(Graphics g, boolean fillWiteColor) {
Graphics tg = _tmpimg.getGraphics();
if (fillWiteColor) {
tg.setColor(Color.WHITE);
tg.fillRect(0, 0, this.size().width, this.size().height);
} else {
tg.clearRect(0, 0, this.size().width, this.size().height);
}
for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
Element em = (Element) e.nextElement();
em.paint(tg);
}
g.drawImage(_tmpimg, 0, 0, this);
}
/**
* @param g
* @roseuid 3E0A6E1B0065
*/
public void paint(Graphics g) {
update(g);
}
public String toXML() {
String rslt = "";
try {
Class cls = this.getClass();
rslt = "<" + cls.getName() + ">\n";
Field[] flds = cls.getFields();
for (int i = 0; i < flds.length; i++) {
Field field = flds[i];
String fieldval = "";
Class type = field.getType();
if (field != null) {
if (type.equals(Long.TYPE)) { // Long
fieldval = field.getLong(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
} else if (type.equals(Integer.TYPE)) { // Int
fieldval = field.getInt(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
} else if (type.equals(Short.TYPE)) { // Short
fieldval = field.getShort(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
} else if (type.equals(Double.TYPE)) { // Double
fieldval = field.getDouble(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
} else if (type.equals(Class.forName("java.lang.String"))) { // String
fieldval = (String) field.get(this);
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
}
else if (type.equals(Float.TYPE)) { // Float
fieldval = field.getFloat(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
}
else if (type.equals(Boolean.TYPE)) { // Boolean
fieldval = field.getBoolean(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
}
else if (type.equals(Class.forName("java.sql.Date"))) { // Date
fieldval = field.get(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
}
else if (type.equals(Class.forName("java.util.Date"))) { // java.util.Date
fieldval = field.get(this) + "";
rslt += "<" + flds[i].getName() + ">" + fieldval + "</"
+ flds[i].getName() + ">\n";
continue;
}
}
}
// rslt += ">\n";
// 递归调用SUBELEMENT的TOXML方法
for (java.util.Enumeration em = this._elems.elements(); em
.hasMoreElements();) {
Element subelm = (Element) em.nextElement();
rslt += subelm.toXML();
}
rslt += "</" + cls.getName() + ">\n";
} catch (Exception e) {
}
return rslt;
}
/**
* @param e
* @roseuid 3E0A6E1B0097
*/
void removeElement(Element emn) {
if (emn != null) {
if (emn instanceof Node) {
Vector v = getAllElements();
for (Enumeration e = v.elements(); e.hasMoreElements();) {
Element elem = (Element) e.nextElement();
if (elem instanceof Relation) {
Relation r = (Relation) elem;
if ((r.startnodeid != null && r.startnodeid
.equals(emn.id))
|| (r.endnodeid != null && r.endnodeid
.equals(emn.id))) {
Node n = r.getStartnode();
_elems.removeElement(r);
}
}
}
_elems.removeElement(emn);
} else {
Relation r = (Relation) emn;
_elems.removeElement(r);
}
}
}
/**
* @param id
* @roseuid 3E0A6E1B00AB
*/
void removeElement(String id) {
for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
Element em = (Element) e.nextElement();
if (em.id != null && em.id.equals(id)) {
_elems.removeElement(em);
}
}
}
/**
* @param x
* @param y
* @return excelimport.Element
* @roseuid 3E0A6E1B00C9
*/
public Element chkSelectedElement(int x, int y) {
Vector v = getAllElements();
for (Enumeration e = v.elements(); e.hasMoreElements();) {
Element em = (Element) e.nextElement();
if (em.isSelected(x, y)) {
return em;
}
}
return null;
}
public int getFlowstatus() {
return this.flowstatus;
}
/**
* 设置流程运转路径
*
* @param
*/
public void setFlowpath(String path) {
if (this.flowpath == null || this.flowpath.trim().length() <= 0) {
this.flowpath = path;
} else {
this.flowpath = this.flowpath + ";" + path;
}
}
/**
* @return java.util.Vector
* @roseuid 3E0A6E1B00E7
*/
public Vector getAllElements() {
Vector vct = new Vector();
for (Enumeration e = _elems.elements(); e.hasMoreElements();) {
Element em = (Element) e.nextElement();
vct.addElement(em);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -