📄 jzjtreemodel.java
字号:
package org.jr.jzj;
/**
* <p>Copyright: Copyright (c) 2002-2003</p>
* <p>Company: JavaResearch(http://www.javaresearch.org)</p>
* <p>最后更新日期:2003年3月20日
* @author Brain,Cherami,Barney
* @version 0.8
*/
import java.util.*;
import javax.swing.tree.*;
/**
* 显示树形内容的模型。
*/
public class JZJTreeModel
extends DefaultTreeModel {
private static JZJLogger logger = new JZJLogger(JZJTreeModel.class);
private JZJResources resource = JZJResources.getResources();
private String t_allrecords = resource.getString("t_allrecords");
private String t_treemode = resource.getString("t_treemode");
private DefaultMutableTreeNode root;
private DefaultMutableTreeNode allRecords;
private JZJTreeObject allRecordsObject = new JZJTreeObject(t_allrecords);
private DefaultMutableTreeNode treeMode;
private JZJTreeObject treeModeObject = new JZJTreeObject(t_treemode);
/**
* 构造一个JZJTreeModel。
*/
public JZJTreeModel() {
super(new DefaultMutableTreeNode("")); //not visible
init();
}
/**
* 初始化方法。
*/
private void init() {
allRecords = new DefaultMutableTreeNode(allRecordsObject);
treeMode = new DefaultMutableTreeNode(treeModeObject);
root = (DefaultMutableTreeNode) (super.root);
root.add(allRecords);
root.add(treeMode);
}
/**
* 添加记录。
* @param records 记录数组
*/
public void addRecords(JZJFileRecord[] records) {
for (int i = 0; i < records.length; i++) {
addTree(treeMode, (String) (records[i].entry.getName()), records[i]);
allRecordsObject.addEntry(records[i]);
}
}
/**
* 添加一个节点
* @param root 根节点
* @param node 节点名
* @param record 记录
*/
private void addTree(DefaultMutableTreeNode root, String node,
JZJFileRecord record) {
if (node == null || root == null || node.equals("")) {
return;
}
int i = node.indexOf( (int) '/');
if (i < 0) {
JZJTreeObject o = new JZJTreeObject(node);
( (JZJTreeObject) (root.getUserObject())).addEntry(record);
//root.add( new DefaultMutableTreeNode( o ) );
}
else {
String parent = node.substring(0, i);
Enumeration children = root.children();
while (children.hasMoreElements()) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.
nextElement();
if (child.toString().equals(parent)) {
addTree(child, node.substring(i + 1), record);
return;
}
}
DefaultMutableTreeNode parentNode = new DefaultMutableTreeNode(new
JZJTreeObject(parent));
root.add(parentNode);
addTree(parentNode, node.substring(i + 1), record);
}
}
/**
* 清除所有节点。
*/
public void removeAll() {
treeMode.removeAllChildren();
treeModeObject.removeAll();
allRecordsObject.removeAll();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -