public void collapsePath(TreePath p) { treeState.setExpandedState(p, false); fireTreeCollapsed(p); reload(); }
/** Reëexpand descendants of a newly expanded path which were * expanded the last time their parent was expanded */ private void updateExpandedDescendants(TreePath path) { getLayout().setExpandedState(path, true); TreePath[] descendants = getTreePathSupport().getExpandedDescendants(path); if(descendants.length > 0) { for (int i=0; i < descendants.length; i++) { getLayout().setExpandedState(descendants[i], true); } } }
/** Expand a path. Notifies the layout cache of the change, * stores the expanded path info (so reexpanding a parent node also reexpands * this path if a parent node containing it is later collapsed). Fires * TreeWillExpand and TreeExpansion events. */ public void expandPath (TreePath path) { if (Boolean.TRUE.equals(expandedPaths.get(path))) { //It's already expanded, don't waste cycles firing bogus events return; } TreeExpansionEvent e = new TreeExpansionEvent (this, path); try { fireTreeWillExpand(e, true); expandedPaths.put(path, Boolean.TRUE); layout.setExpandedState(path, true); fireTreeExpansion(e, true); } catch (ExpandVetoException eve) { fireTreeExpansionVetoed (e, eve); } }
/** Collapse a path. Notifies the layout cache of the change, * stores the expanded path info (so reexpanding a parent node also reexpands * this path if a parent node containing it is later collapsed). Fires * TreeWillExpand and TreeExpansion events. */ public void collapsePath (TreePath path) { if (Boolean.FALSE.equals(expandedPaths.get(path))) { //It's already collapsed, don't waste cycles firing bogus events return; } TreeExpansionEvent e = new TreeExpansionEvent (this, path); try { fireTreeWillExpand(e, false); expandedPaths.put(path, Boolean.FALSE); layout.setExpandedState(path, false); fireTreeExpansion(e, false); } catch (ExpandVetoException eve) { fireTreeExpansionVetoed (e, eve); } }
public void setModel(TreeModel m) { TreeModel oldVal = this.model; if (model != null && treeModelListener != null) model.removeTreeModelListener(treeModelListener); model = m; treeState.setModel(m); if (model != null) { if (treeModelListener == null) treeModelListener = createTreeModelListener(); if (treeModelListener != null) model.addTreeModelListener(treeModelListener); // Mark the root as expanded, if it isn't a leaf. if (!model.isLeaf(model.getRoot())) treeState.setExpandedState(new TreePath(model.getRoot()), true); fireViewportChanged(false); reload(); } propertyChangeSupport.firePropertyChange("model", oldVal, this.model); }
/** * Expand this tree row. * If tree is inside a {@link SScrollPane} try to * adjust pane, so that as much as possible new * nodes are visible. * @param p the TreePath to expand */ public void expandPath(TreePath p) { treeState.setExpandedState(p, true); if (viewport != null) { Rectangle area = new Rectangle(viewport); area.y = treeState.getRowForPath(p); area.height = model.getChildCount(p.getLastPathComponent()) + 1; scrollRectToVisible(area); } fireTreeExpanded(p); reload(); }
public void treeCollapsed(TreeExpansionEvent event) { assert SwingUtilities.isEventDispatchThread(); log ("treeExpanded", event); //FixedHeightLayoutCache tests if the event is null. //Don't know how it could be, but there's probably a reason... if(event != null) { TreePath path = event.getPath(); //Tell the layout about the change if(path != null && getTreePathSupport().isVisible(path)) { getLayout().setExpandedState(path, false); } } log ("about to fire", pendingExpansionEvent); //Now fire a change on the owning row so its display is updated (it //may have just become an expandable node) TreePath path = event.getPath(); int row = getLayout().getRowForPath(path); TableModelEvent evt = new TableModelEvent (getModel(), row, row, 0, TableModelEvent.UPDATE); fireTableChange(new TableModelEvent[] {evt, pendingExpansionEvent}); pendingExpansionEvent = null; inProgressEvent = null; }