📄 contenttree.java
字号:
package g2w.app.gchm.gui;
import java.util.Iterator;
import java.util.List;
import javax.swing.JTree;
import javax.swing.tree.TreePath;
/**
* The tree to display the content of the chm document.
*
* @author GreatGhoul
* @version 030 2009-3-20 15:13:15
*/
public class ContentTree extends JTree {
/**
* Constructs a tree using a xml document.
* @param model
*/
public ContentTree(ContentTreeModel model) {
super(model);
}
public void updateModel(ContentTreeNode parent) {
ContentElement parentElem = parent.getUserObject();
List<ContentElement> childElems = parentElem.getChildren();
Iterator<ContentElement> iterator = childElems.iterator();
while (iterator.hasNext()) {
ContentElement childElem = iterator.next();
ContentTreeNode child = new ContentTreeNode(childElem);
parent.add(child);
updateModel(child);
}
}
/**
* Returns the selection node.If no selection found, returns null.
*
* @return The selection node.
*/
public ContentTreeNode getSelectionNode() {
try {
return (ContentTreeNode) getSelectionPath().getLastPathComponent();
} catch (NullPointerException e) {
return null;
}
}
/**
* Create a new topic node with the name "新标题".
*
* @return A new topic node.
*/
public static ContentTreeNode createNewTopicNode() {
return new ContentTreeNode(ContentElement.createTopic("新标题", ""));
}
/**
* Set the selection.
*
* @param node The node to select.
*/
public void setSelection(ContentTreeNode node) {
try {
ContentTreeModel model = (ContentTreeModel) getModel();
TreePath path = new TreePath(model.getPathToRoot(node));
setSelectionPath(path);
} catch (Exception e) {}
}
@Override
public void collapsePath(TreePath path) {
try {
ContentTreeNode node = (ContentTreeNode) path.getLastPathComponent();
if (node.isRoot()) return;
super.collapsePath(path);
} catch (Exception e) {}
}
@Override
public void collapseRow(int row)
{
TreePath path = getPathForRow(row);
ContentTreeNode node = (ContentTreeNode) path.getLastPathComponent();
if (node.isRoot()) return;
super.collapseRow(row);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -