📄 jxtatreemodel.java
字号:
return columnNames[column]; } /** * Get the name of the indicated column * * @param column the index of the column * * @return the name for the indicated column */ public Class getColumnClass(int column) { return columnTypes[column]; } /** * Get the object that represents the indicated column for the * indicated node. * * @param node the node for which to get the object * @param column the column which we want to print * * @return an object that represents the indicated column for the * indicated node */ public Object getValueAt(Object node, int column) { Object o = null; switch (column) { case 0: o = (JxtaNode)node; break; case 1: o = ((JxtaNode)node).getDescription(); break; } return o; } /** * Returns the path to the indicated node * * @return the path to the indicated node */ public JxtaNode[] getPath(Object node) { return ((JxtaNode)node).getPath(); } public String getNormalizedPath(JxtaNode node) { return node.getNormalizedPath(); } public JxtaNode getNodeFromNormalizedPath(String path) { List<String> l = new ArrayList<String>(); int i = 0; int j = i; StringBuffer b = null; while (j > -1 && (i = path.indexOf(JxtaNode.DELIMITER, j)) > -1) { j = path.indexOf(JxtaNode.DELIMITER, i + 1); if (j > -1) { if (path.charAt(j - 1) != JxtaNode.ESCAPE) { if (b == null) { b = new StringBuffer(); } b.append(path.substring(b.length() == 0 ? i + 1 : i, j)); l.add(b.toString()); b = null; } else { if (b == null) { b = new StringBuffer(); } b.append(path.substring(i + 1, j - 1)); } } else { if (b == null) { b = new StringBuffer(); } b.append(path.substring(b.length() == 0 ? i + 1 : i)); l.add(b.toString()); } } String id = null; JxtaNode n = null; JxtaNode p = null; for (Iterator<String> ni = l.iterator(); ni.hasNext(); ) { id = ni.next(); if (n == null) { n = (JxtaNode)getRoot(); } if (! n.getId().equals(id)) { p = null; for (Iterator c = n.getChildren(); c.hasNext() && p == null; ) { p = (JxtaNode)c.next(); if (! p.getId().equals(id)) { p = null; } } n = p; if (n == null) { break; } } } return n; } /** * Visit all nodes and change their inactive/active status */ public void checkStatus() { JxtaNode n = (JxtaNode)getRoot(); for (Iterator i = n.getChildren(); i.hasNext(); ) { checkNodeStatus((JxtaNode)i.next()); } } public void addListener(JxtaTreeModelListener l) { if (this.listeners == null || ! this.listeners.contains(l)) { if (this.listeners == null) { this.listeners = new ArrayList<JxtaTreeModelListener>(); } this.listeners.add(l); } } public Iterator getListeners() { return this.listeners != null ? this.listeners.iterator() : Collections.EMPTY_LIST.iterator(); } public JxtaTreeModelListener removeListener(JxtaTreeModelListener l) { int i = this.listeners != null ? this.listeners.indexOf(l) : -1; if (i>-1){ return this.listeners.remove(i); } return null; } /** * Find the group node to which we want to add this Group instance * * @param group the group for which to locate the parent GroupNode * @return the parent GroupNode */ protected JxtaNode getParentNode(Group group) { JxtaNode n = null; if (group != null && group.isVisible()) { JxtaNode p = null; Group pg = group.getParentGroup(); if (pg != null && pg.isVisible()) { p = getParentNode(pg); n = new GroupNode(group); } else { p = (JxtaNode)getRoot(); n = new GroupNode(group); } int i = p.getIndexOf(n); if (i > -1) { n = (GroupNode)p.getChildAt(i); } else { addTreeNode(p, n); } } return n; } /** * Add a child node to the indicated parent and notify the model * that the tree structure changed * * @param parent the node to which to add the child * @param child the child to add * @return true if the node was added to the tree, false * if the node already existed in the tree */ private boolean addTreeNode(JxtaNode parent, JxtaNode child) { boolean isAdded = false; int changedIndex[] = new int[1]; JxtaNode changedNodes[] = new JxtaNode[1]; boolean firstNode = false; if (parent == root && parent.getChildrenCount() == 0) { firstNode = true; } if (parent.contains(child)) { // we reparent to make sure that JxtaNode parent structure // is in sync with JTree structure. // This is needed as getParentNode creates new instances. // Therefore it needs to be done before the check of // parent.contains as that depends on ID value not on instance child.setParent(parent); // inform the child node that it is being accessed // and inform the tree if this is a status change changedIndex[0] = parent.getIndexOf(child); changedNodes[0] = (JxtaNode)parent.getChildAt(changedIndex[0]); if (changedNodes[0].informAccessed()) { fireTreeNodesChanged(this, parent.getPath(), changedIndex, changedNodes); } isAdded = false; } else { parent.add(child); child.setParent(parent); // see comment in if block changedNodes[0] = child; changedIndex[0] = parent.getIndexOf(child); // the very first node changes the structure // if we just call fireTreeNodesInserted the tree // does not get updated if (firstNode) { fireTreeStructureChanged(this, parent.getPath(), changedIndex, changedNodes); } else { fireTreeNodesInserted(this, parent.getPath(), changedIndex, changedNodes); } isAdded = true; } return isAdded; } private void checkNodeStatus(JxtaNode n) { int changedIndex[] = new int[1]; JxtaNode changedNodes[] = new JxtaNode[1]; JxtaNode parent = (JxtaNode)n.getParent(); if (n.checkStatus()) { changedNodes[0] = n; changedIndex[0] = parent.getIndexOf(n); fireTreeNodesChanged(this, parent.getPath(), changedIndex, changedNodes); } for (Iterator i = n.getChildren(); i.hasNext(); ) { checkNodeStatus((JxtaNode)i.next()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -