📄 concepttreemodel.java
字号:
package org.impact.stars.appclient.concept.model;
/**
* Insert the type's description here.
* Creation date: (7/26/00 3:05:52 PM)
* @author: Jian Cai
*/
import javax.swing.event.*;
import javax.swing.tree.*;
import java.util.Vector;
public class ConceptTreeModel implements TreeModel {
private boolean showAncestors;
private Vector treeModelListeners = new Vector();
private Conceptnode rootConcept;
/**
* ConceptTreeModel constructor comment.
*/
public ConceptTreeModel() {
super();
}
public ConceptTreeModel(Conceptnode root) {
showAncestors = false;
rootConcept = root;
}
//////////////// TreeModel interface implementation ///////////////////////
/**
* Adds a listener for the TreeModelEvent posted after the tree changes.
*/
public void addTreeModelListener(TreeModelListener l) {
treeModelListeners.addElement(l);
}
//////////////// Fire events //////////////////////////////////////////////
/**
* The only event raised by this model is TreeStructureChanged with the
* root as path, i.e. the whole tree has changed.
*/
protected void fireTreeStructureChanged(Conceptnode oldRoot) {
int len = treeModelListeners.size();
TreeModelEvent e = new TreeModelEvent(this,
new Object[] {oldRoot});
for (int i = 0; i < len; i++) {
((TreeModelListener)treeModelListeners.elementAt(i)).
treeStructureChanged(e);
}
}
/**
* Returns the child of parent at index index in the parent's child array.
*/
public Object getChild(Object parent, int index) {
Conceptnode p = (Conceptnode)parent;
/* if (showAncestors) {
if ((index > 0) && (p.getparentconcept() != null)) {
return p.getMother();
}
return p.getparentconcept();
}*/
return p.getChildAt(index);
}
/**
* Returns the number of subconcept of parent.
*/
public int getChildCount(Object parent) {
Conceptnode p = (Conceptnode)parent;
/*if (showAncestors) {
int count = 0;
if (p.getparentconcept() != null) {
count++;
}
if (p.getMother() != null) {
count++;
}
return count;
}*/
return p.getChildCount();
}
/**
* Returns the index of child in parent.
*/
public int getIndexOfChild(Object parent, Object child) {
Conceptnode p = (Conceptnode)parent;
/*if (showAncestors) {
int count = 0;
Conceptnode parentconcept = p.getparentconcept();
if (parentconcept != null) {
count++;
if (parentconcept == child) {
return 0;
}
}
if (p.getMother() != child) {
return count;
}
return -1;
}*/
return p.getIndexOfChild((Conceptnode)child);
}
/**
* Returns the root of the tree.
*/
public Object getRoot() {
return rootConcept;
}
/**
* Returns true if node is a leaf.
*/
public boolean isLeaf(Object node) {
Conceptnode p = (Conceptnode)node;
if (showAncestors) {
return ((p.getparentConceptnode() == null));
// && (p.getMother() == null));
}
return p.getChildCount() == 0;
}
/**
* Removes a listener previously added with addTreeModelListener().
*/
public void removeTreeModelListener(TreeModelListener l) {
treeModelListeners.removeElement(l);
}
/**
* Used to toggle between show ancestors/show descendant and
* to change the root of the tree.
*/
public void showAncestor(boolean b, Object newRoot) {
showAncestors = b;
Conceptnode oldRoot = rootConcept;
if (newRoot != null) {
rootConcept = (Conceptnode)newRoot;
}
fireTreeStructureChanged(oldRoot);
}
/**
* Messaged when the user has altered the value for the item
* identified by path to newValue. Not used by this model.
*/
public void valueForPathChanged(TreePath path, Object newValue) {
System.out.println("*** valueForPathChanged : "
+ path + " --> " + newValue);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -