📄 pvnodefactory.java
字号:
package com.icbcsdc.ddlexp.pub.util;
/**
* 使用XML创建树的实用类
*
* @author zhangp
* @version 1.0 使用 Logger 示例 1.创建树: JPVTree tree
* =XmlTreeUtil.creatFrom("com/mysqlecc/pub/xml/tree.xml");
* 2.添加子树的方法(将xml文档中的节点挂到当前树节点下面) InputStream is=new
* FileInputStream("com/mysqlecc/pub/xml/tree.xml"); or InputStream
* is=new StringBufferInputStream(xmlBuffer);//xmlBuffer为xml字符串
* XmlTreeUtil.addSubTree(parentNode,is); //(PVNode)TreeNode
*
*/
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Properties;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import pv.jfcx.PVNode;
import com.icbcsdc.ddlexp.pub.staticLog.Logger;
import com.icbcsdc.ddlexp.pub.xml.nodeinfo.XMLNode;
public class PVNodeFactory {
public static Hashtable images = new Hashtable();
private static int NodeHeight = 20; //设置节点的高度
private static String NodeTypeFileName = "cfg/nodetype.cfg";
/*
* type: network,nodes,node,dbs,db,os
*/
static {
Properties prop = null;
try {
InputStream is = new FileInputStream(NodeTypeFileName);
prop = new Properties();
prop.load(is);
is.close();
} catch (Exception e) {//FileNotFoundException,IOException
Logger.log(Logger.FATAL, e.getMessage());
System.exit(1);
}
Enumeration enum = prop.propertyNames();
while (enum.hasMoreElements()) {
String key = enum.nextElement().toString();
String value = prop.getProperty(key);
//加载图片
images.put(key, new ImageIcon(value));
}
}
//根据obj创建PVNde,设置图标
/*
* setImageAt(Icon,int) id state of node. Range: 0..5
* pv.jfcx.JPVTree.CLOSED=0
* pv.jfcx.JPVTree.OPENED=1
* pv.jfcx.JPVTree.LEAF=2
* pv.jfcx.JPVTree.CLOSED_SEL=3
* pv.jfcx.JPVTree.OPENED_SEL4
* pv.jfcx.JPVTree.LEAF_SEL=5
*/
public static synchronized PVNode createNode(XMLNode userObject) {
PVNode node = new PVNode(userObject);
node.setHeight(NodeHeight);
String type = ""+userObject.getCompareStatus()+"_";
if(userObject.isOverflow())
type="6_";
for (int i = 0; i <=5; i++) {
Object icon = images.get(type + String.valueOf(i));
if (icon != null) {
//System.out.println(""+i+":"+type + String.valueOf(i));
node.setImageAt((Icon) icon, i);
}
}
return node;
}
public static void main(String[] args) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -