@Override public void actionPerformed(ActionEvent e) { if (checkBoxTree.getSelectionPath() != null) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) checkBoxTree.getSelectionPath().getLastPathComponent(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) selectedNode.getParent(); if (parentNode != null) { DefaultMutableTreeNode immediateSiblingNode = directionUp ? (DefaultMutableTreeNode) parentNode.getChildBefore(selectedNode) : (DefaultMutableTreeNode) parentNode.getChildAfter(selectedNode); if (immediateSiblingNode != null) { parentNode.insert(immediateSiblingNode, parentNode.getIndex(selectedNode)); ((DefaultTreeModel) checkBoxTree.getModel()).nodeStructureChanged(parentNode); checkBoxTree.setSelectionPath(new TreePath(selectedNode.getPath())); } } } } }
@Override public int getIndex(TreeNode aChild) { return super.getIndex(aChild); }
public int getIndex(TreeNode node) { loadChildrenIfNecessary(); return super.getIndex(node); }
@Override public int getIndexOfChild(Object parent, Object child) { if (parent instanceof DefaultMutableTreeNode && child instanceof DefaultMutableTreeNode) { return ((DefaultMutableTreeNode) parent).getIndex( (DefaultMutableTreeNode) child); } else if (parent instanceof Node && child instanceof Spatial) { return ((Node)parent).getChildIndex((Spatial)child); } else { return -1; } }
public int getIndex(TreeNode node) { loadChildrenIfNecessary(); return super.getIndex(node); }
public int getIndex(TreeNode aNode) { ensureInited(); return super.getIndex(aNode); }
public int getIndex(TreeNode node) { loadChildrenIfNecessary(); return super.getIndex(node); }
public int getIndex(TreeNode node) { loadChildrenIfNecessary(); return super.getIndex(node); }
/** Returns the index of the specified child in this node's child array. * If the specified node is not a child of this node, returns * <code>-1</code>. This method performs a linear search and is O(n) * where n is the number of children. * * @param aChild the TreeNode to search for among this node's children * @exception IllegalArgumentException if <code>aChild</code> * is null * @return an int giving the index of the node in this node's child * array, or <code>-1</code> if the specified node is a not * a child of this node * */ public int getIndex(TreeNode aChild) { int retValue; loadKidsIfNeeded(); retValue = super.getIndex(aChild); return retValue; }
/** * Adds a group to consolidate mods. * * TODO: Trigger a rename. */ public void addGroup() { DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)treeModel.getRoot(); DefaultMutableTreeNode groupNode = new DefaultMutableTreeNode( "New Group", true ); rootNode.add( groupNode ); treeModel.nodesWereInserted( rootNode, new int[]{rootNode.getIndex( groupNode )} ); }
private String getAnonymousName(DefaultMutableTreeNode node) { StringBuilder name = new StringBuilder(); TreeNode[] path = node.getPath(); for(int i=0; i<path.length; i++) { DefaultMutableTreeNode tmp = (DefaultMutableTreeNode)path[i]; if(tmp.getUserObject() != null) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode)tmp.getParent(); int index = parent.getIndex(tmp); name.append(index+1); if(i < path.length-1) name.append("."); } } return name.toString(); }
protected Component getPrevious(final DefaultMutableTreeNode childNode) { final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) childNode.getParent(); if (parentNode == null || parentNode.getUserObject() == null) { return null; } final int childNodeIndex = parentNode.getIndex(childNode); final Component c = getPrevious(parentNode, childNodeIndex - 1); if (c == null) { return getPrevious(parentNode); } return c; }
protected void removePath(TreePath path) { DefaultMutableTreeNode node, parent, removed; int index; node = (DefaultMutableTreeNode)path.getLastPathComponent(); parent = (DefaultMutableTreeNode)node.getParent(); index = parent.getIndex(node); removed = (DefaultMutableTreeNode)parent.getChildAt(index); selectedJTreeModel.removeNodeFromParent(removed); }
private void onUp() { DefaultMutableTreeNode selNode = null; if(null != _pnlPrefs.treBookmarks.getSelectionPath()) { selNode = (DefaultMutableTreeNode) _pnlPrefs.treBookmarks.getSelectionPath().getLastPathComponent(); } if ( null == selNode || false == selNode.getUserObject() instanceof Bookmark || 0 == _nodeUserMarks.getIndex(selNode)) { return; } int selIx = _nodeUserMarks.getIndex(selNode); _nodeUserMarks.insert(selNode, selIx - 1); ((DefaultTreeModel)_pnlPrefs.treBookmarks.getModel()).nodeStructureChanged(_nodeUserMarks); selectNode(selNode); }
public void intervalRemoved(ListDataEvent e) { // compare PageList with TitleNodeMap to find out what is missing Set<String> set = _titleNodeMap.keySet(); Vector<String> toBeRemoved = new Vector<String>(); for (String title : set) { if (_pageList.getPageByFullTitle(title) == null) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) _titleNodeMap.get(title); if (treeNode != null) { toBeRemoved.add(title); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) treeNode.getParent(); if (parentNode != null) { int index = parentNode.getIndex(treeNode); parentNode.remove(treeNode); ((DefaultTreeModel) _tree.getModel()).nodesWereRemoved(parentNode, new int[]{index}, new Object[]{treeNode}); } } } } for (String o : toBeRemoved) { _titleNodeMap.remove(o); } }
private void onDown() { DefaultMutableTreeNode selNode = null; if(null != _pnlPrefs.treBookmarks.getSelectionPath()) { selNode = (DefaultMutableTreeNode) _pnlPrefs.treBookmarks.getSelectionPath().getLastPathComponent(); } if ( null == selNode || false == selNode.getUserObject() instanceof Bookmark || _nodeUserMarks.getChildCount() - 1 == _nodeUserMarks.getIndex(selNode)) { return; } int selIx = _nodeUserMarks.getIndex(selNode); _nodeUserMarks.insert(selNode, selIx + 1); ((DefaultTreeModel)_pnlPrefs.treBookmarks.getModel()).nodeStructureChanged(_nodeUserMarks); selectNode(selNode); }
/** * Set the value at a specific column. * @param column The column. * @param value The new value. */ public void setValue(int column, Object value) { values.put(type.getColumns()[column], value); if(getModel()!=null && (getParent()==null || getParent() instanceof DefaultMutableTreeNode)) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode)getParent(); getModel().fireTreeNodesChanged(this, parent==null ? new Object[0] : parent.getPath(), new int[]{parent==null ? 0 : parent.getIndex(this)}, new Object[]{this}); } }
/** * Set all values at once. * @param values The new values. */ public void setValues(Map values) { this.values = values; if(getModel()!=null && (getParent()==null || getParent() instanceof DefaultMutableTreeNode)) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode)getParent(); getModel().fireTreeNodesChanged(this, parent==null ? new Object[]{this} : parent.getPath(), new int[]{parent==null ? 0 : parent.getIndex(this)}, new Object[]{this}); } }
protected void handleUpAction(ActionEvent event) { TreePath paths[] = selectedJTree.getSelectionPaths(); sortTreePaths(paths); for (int i = 0; i < paths.length; i++) { TreePath path = paths[i]; DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent(); int index = parent.getIndex(node); if (index == 0) { continue; } DefaultMutableTreeNode removed = (DefaultMutableTreeNode)parent.getChildAt(index); boolean wasExpanded = selectedJTree.isExpanded(path); selectedJTreeModel.removeNodeFromParent(removed); selectedJTreeModel.insertNodeInto(removed, parent, index - 1); if (wasExpanded && removed.getChildCount() > 0) { DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode)removed.getFirstChild(); selectedJTree.makeVisible(new TreePath(firstChild.getPath())); } } selectedJTree.setSelectionPaths(paths); }
protected void handleDownAction(ActionEvent event) { TreePath[] paths = selectedJTree.getSelectionPaths(); sortTreePaths(paths); for (int i = paths.length - 1; i >= 0; i--) { TreePath path = paths[i]; DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode)node.getParent(); int index = parent.getIndex(node); if ((index + 1) == parent.getChildCount()) { continue; } DefaultMutableTreeNode removed = (DefaultMutableTreeNode)parent.getChildAt(index); boolean wasExpanded = selectedJTree.isExpanded(path); selectedJTreeModel.removeNodeFromParent(removed); selectedJTreeModel.insertNodeInto(removed, parent, index + 1); if (wasExpanded && removed.getChildCount() > 0) { DefaultMutableTreeNode firstChild = (DefaultMutableTreeNode)removed.getFirstChild(); selectedJTree.makeVisible(new TreePath(firstChild.getPath())); } } selectedJTree.setSelectionPaths(paths); }