private void expandAll(JTree tree, TreePath path, boolean expand) {
TreeNode node = (TreeNode) path.getLastPathComponent();
if (node.getChildCount() >= 0) {
Enumeration enumeration = node.children();
while (enumeration.hasMoreElements()) {
TreeNode n = (TreeNode) enumeration.nextElement();
TreePath p = path.pathByAddingChild(n);
expandAll(tree, p, expand);
}
}
if (expand) {
tree.expandPath(path);
} else {
tree.collapsePath(path);
}
}
java类javax.swing.tree.TreeNode的实例源码
TreePanel.java 文件源码
项目:hml
阅读 31
收藏 0
点赞 0
评论 0
ASTBrowserTopComponent.java 文件源码
项目:incubator-netbeans
阅读 21
收藏 0
点赞 0
评论 0
private void initChildren () {
if (children != null) return;
children = new ArrayList<TreeNode> ();
map = new HashMap<ASTItem,TreeNode> ();
if (astItem == null) return;
List<ASTItem> chList = astItem.getChildren ();
if (chList != null) {
Iterator<ASTItem> it = chList.iterator ();
while (it.hasNext ()) {
ASTItem item = it.next ();
TreeNode tn = new TNode (this, item);
children.add (tn);
map.put (item, tn);
}
}
}
ProfilerTreeTable.java 文件源码
项目:incubator-netbeans
阅读 25
收藏 0
点赞 0
评论 0
private Comparator getComparator() {
SortOrder sortOrder = getSortOrder();
if (SortOrder.UNSORTED.equals(sortOrder)) return null;
final boolean ascending = SortOrder.ASCENDING.equals(sortOrder);
final int sortColumn = getSortColumn();
boolean sortingTree = JTree.class.equals(model.getColumnClass(sortColumn));
final Comparator comparator = sortingTree ? null : getComparator(sortColumn);
return new Comparator() {
public int compare(Object o1, Object o2) {
int result;
if (comparator == null) {
String s1 = o1.toString();
String s2 = o2.toString();
result = s1.compareTo(s2);
} else {
Object v1 = model.getValueAt((TreeNode)o1, sortColumn);
Object v2 = model.getValueAt((TreeNode)o2, sortColumn);
result = comparator.compare(v1, v2);
}
return ascending ? result : result * -1;
}
};
}
ASTBrowserTopComponent.java 文件源码
项目:incubator-netbeans
阅读 25
收藏 0
点赞 0
评论 0
public void caretUpdate (CaretEvent e) {
if (rootNode == null) return;
ASTPath path = rootNode.findPath (e.getDot ());
if (path == null) return;
TreeNode tNode = (TreeNode) tree.getModel ().getRoot ();
List<TreeNode> treePath = new ArrayList<TreeNode> ();
Iterator it = path.listIterator ();
if (!it.hasNext ()) return;
it.next ();
treePath.add (tNode);
while (tNode instanceof TNode && it.hasNext ()) {
tNode = ((TNode) tNode).getTreeNode (it.next ());
if (tNode == null) throw new NullPointerException ();
treePath.add (tNode);
}
TreePath treePath2 = new TreePath (treePath.toArray ());
DefaultTreeModel model = new DefaultTreeModel ((TreeNode) tree.getModel ().getRoot ());
tree.setModel (model);
tree.setSelectionPath (treePath2);
tree.scrollPathToVisible (treePath2);
}
ElementTreePanel.java 文件源码
项目:openjdk-jdk10
阅读 23
收藏 0
点赞 0
评论 0
/**
* Invoke this method after you've changed how node is to be
* represented in the tree.
*/
@Override
public void nodeChanged(TreeNode node) {
if (listenerList != null && node != null) {
TreeNode parent = node.getParent();
if (parent == null && node != root) {
parent = root;
}
if (parent != null) {
int anIndex = getIndexOfChild(parent, node);
if (anIndex != -1) {
int[] cIndexs = new int[1];
cIndexs[0] = anIndex;
nodesChanged(parent, cIndexs);
}
}
}
}
AssertionTreeNode.java 文件源码
项目:marathonv5
阅读 24
收藏 0
点赞 0
评论 0
@Override public TreeNode getChildAt(int index) {
if (object instanceof List) {
return getNodeForList((List<?>) object, index);
}
if (object instanceof Map) {
return getNodeForMap((Map<?, ?>) object, index);
}
Method method;
if (object instanceof RComponent) {
Method o = ((RComponent) object).getMethods().get(index);
method = o;
} else {
method = getMethods(object).get(index);
}
return getNodeForMethod(method);
}
Model.java 文件源码
项目:Luyten4Forge
阅读 23
收藏 0
点赞 0
评论 0
@Override
public void treeExpanded(final TreeExpansionEvent event) {
final TreePath treePath = event.getPath();
final Object expandedTreePathObject = treePath.getLastPathComponent();
if (!(expandedTreePathObject instanceof TreeNode)) {
return;
}
final TreeNode expandedTreeNode = (TreeNode) expandedTreePathObject;
if (expandedTreeNode.getChildCount() == 1) {
final TreeNode descendantTreeNode = expandedTreeNode.getChildAt(0);
if (descendantTreeNode.isLeaf()) {
return;
}
final TreePath nextTreePath = treePath.pathByAddingChild(descendantTreeNode);
tree.expandPath(nextTreePath);
}
}
OutlineView152857Test.java 文件源码
项目:incubator-netbeans
阅读 30
收藏 0
点赞 0
评论 0
public void testRemoveNodeInOutlineView () throws InterruptedException {
StringKeys children = new StringKeys (true);
children.doSetKeys (new String [] {"1", "3", "2"});
Node root = new TestNode (children, "root");
comp = new OutlineViewComponent (root);
ETableColumnModel etcm = (ETableColumnModel) comp.getOutlineView ().getOutline ().getColumnModel ();
ETableColumn etc = (ETableColumn) etcm.getColumn (0); // tree column
etcm.setColumnSorted (etc, true, 1); // ascending order
TreeNode ta = Visualizer.findVisualizer(root);
DialogDescriptor dd = new DialogDescriptor (comp, "", false, null);
Dialog d = DialogDisplayer.getDefault ().createDialog (dd);
d.setVisible (true);
Thread.sleep (1000);
((StringKeys) root.getChildren ()).doSetKeys (new String [] {"1", "2"});
Thread.sleep (1000);
assertEquals ("Node on 0nd position is '1'", "1", ta.getChildAt (0).toString ());
assertEquals ("Node on 1st position is '2'", "2", ta.getChildAt (1).toString ());
d.setVisible (false);
}
TreeTableView152857Test.java 文件源码
项目:incubator-netbeans
阅读 22
收藏 0
点赞 0
评论 0
public void testRemoveNodeInTTV () throws InterruptedException {
StringKeys children = new StringKeys (true);
children.doSetKeys (new String [] {"1", "3", "2"});
Node root = new TestNode (children, "root");
view = new TTV (root);
TreeNode ta = Visualizer.findVisualizer(root);
DialogDescriptor dd = new DialogDescriptor (view, "", false, null);
Dialog d = DialogDisplayer.getDefault ().createDialog (dd);
makeVisible(d);
((StringKeys) root.getChildren ()).doSetKeys (new String [] {"1", "2"});
Thread.sleep (1000);
assertEquals ("Node on 0nd position is '1'", "1", ta.getChildAt (0).toString ());
assertEquals ("Node on 1st position is '2'", "2", ta.getChildAt (1).toString ());
d.setVisible (false);
}
JCheckBoxTree.java 文件源码
项目:Cognizant-Intelligent-Test-Scripter
阅读 21
收藏 0
点赞 0
评论 0
/**
* iterate through every child and do the action
*
* @param parent
* @param expand
*/
private void expandAll(TreePath parent, boolean expand) {
TreeNode node = (TreeNode) parent.getLastPathComponent();
if (getChildCount(node) >= 0) {
for (int i = 0; i < getChildCount(node); i++) {
TreePath path = parent.pathByAddingChild(getChildAt(node, i));
expandAll(path, expand);
}
}
if (expand) {
expandPath(parent);
} else {
collapsePath(parent);
}
}
StateTree.java 文件源码
项目:JavaGraph
阅读 24
收藏 0
点赞 0
评论 0
/**
* Retrieves the child of a given parent node that is
* a numbered tree node with a given number, if any.
* @return the correctly numbered child, or {@code null} if there
* is none such
*/
private NumberedTreeNode find(TreeNode parent, int number) {
NumberedTreeNode result = null;
int lower = 0;
int upper = parent.getChildCount() - 1;
boolean found = false;
while (!found && lower <= upper) {
int mid = (lower + upper) / 2;
result = (NumberedTreeNode) parent.getChildAt(mid);
int resultNumber = result.getNumber();
if (result.contains(number)) {
found = true;
} else if (resultNumber < number) {
lower = mid + 1;
} else if (resultNumber > number) {
upper = mid - 1;
}
}
return found ? result : null;
}
ManageInspectionsOperatot.java 文件源码
项目:incubator-netbeans
阅读 21
收藏 0
点赞 0
评论 0
private TreeNode[] getPath(Object node, String deap, String item, boolean debug) {
if (node instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) node;
if (debug) {
System.out.println(deap + dmtn.toString());
}
if (dmtn.toString().equals(item)) {
if (debug) {
System.out.println("EQUAL!!! <" + item + ">");
}
return dmtn.getPath();
}
TreeNode[] curPath;
for (int i = 0; i < dmtn.getChildCount(); i++) {
curPath = getPath(dmtn.getChildAt(i), deap + "__", item, debug);
if (curPath != null) {
return curPath;
}
}
}
return null;
}
Tab.java 文件源码
项目:incubator-netbeans
阅读 23
收藏 0
点赞 0
评论 0
private void scrollNodeToVisible( final Node n ) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
TreeNode tn = Visualizer.findVisualizer(n);
if (tn == null) {
return;
}
TreeModel model = tree.getModel();
if (!(model instanceof DefaultTreeModel)) {
return;
}
TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
if( null == path )
return;
Rectangle r = tree.getPathBounds(path);
if (r != null) {
tree.scrollRectToVisible(r);
}
}
});
}
DirectoryChooserUI.java 文件源码
项目:incubator-netbeans
阅读 27
收藏 0
点赞 0
评论 0
private void applyEdit(DirectoryNode node) {
TreeNode[] nodes = model.getPathToRoot(node);
TreePath editingPath = new TreePath(nodes);
tree.setEditable(true);
tree.makeVisible(editingPath);
tree.scrollPathToVisible(editingPath);
tree.setSelectionPath(editingPath);
tree.startEditingAtPath(editingPath);
JTextField editField = DirectoryCellEditor.getTextField();
editField.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
editField.setRequestFocusEnabled(true);
editField.requestFocus();
editField.setSelectionStart(0);
editField.setSelectionEnd(editField.getText().length());
}
AllocTreeTableView.java 文件源码
项目:incubator-netbeans
阅读 25
收藏 0
点赞 0
评论 0
protected SearchUtils.TreeHelper getSearchHelper() {
return new SearchUtils.TreeHelper() {
public int getNodeType(TreeNode tnode) {
PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)tnode;
CCTNode parent = node.getParent();
if (parent == null) return SearchUtils.TreeHelper.NODE_SKIP_DOWN; // invisible root
if (parent.getParent() == null) {
if (searchObjects) {
return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
SearchUtils.TreeHelper.NODE_SEARCH_NEXT;
} else {
return searchAllocations ? SearchUtils.TreeHelper.NODE_SKIP_DOWN :
SearchUtils.TreeHelper.NODE_SKIP_NEXT;
}
}
return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
SearchUtils.TreeHelper.NODE_SKIP_NEXT;
}
};
}
JCheckBoxTree.java 文件源码
项目:Cognizant-Intelligent-Test-Scripter
阅读 21
收藏 0
点赞 0
评论 0
private void resetCheckingState() {
nodesCheckingState = new HashMap<>();
checkedPaths = new ArrayList<TreePath>() {
@Override
public boolean add(TreePath e) {
if (!contains(e)) {
return super.add(e);
}
return false;
}
};
if (getModel() == null) {
return;
}
TreeNode node = (TreeNode) getModel().getRoot();
if (node == null) {
return;
}
addSubtreeToCheckingStateTracking(node);
}
LivenessTreeTableView.java 文件源码
项目:incubator-netbeans
阅读 19
收藏 0
点赞 0
评论 0
protected SearchUtils.TreeHelper getSearchHelper() {
return new SearchUtils.TreeHelper() {
public int getNodeType(TreeNode tnode) {
PresoObjAllocCCTNode node = (PresoObjAllocCCTNode)tnode;
CCTNode parent = node.getParent();
if (parent == null) return SearchUtils.TreeHelper.NODE_SKIP_DOWN; // invisible root
if (parent.getParent() == null) {
if (searchObjects) {
return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
SearchUtils.TreeHelper.NODE_SEARCH_NEXT;
} else {
return searchAllocations ? SearchUtils.TreeHelper.NODE_SKIP_DOWN :
SearchUtils.TreeHelper.NODE_SKIP_NEXT;
}
}
return searchAllocations ? SearchUtils.TreeHelper.NODE_SEARCH_DOWN :
SearchUtils.TreeHelper.NODE_SKIP_NEXT;
}
};
}
LivenessTreeTableView.java 文件源码
项目:incubator-netbeans
阅读 23
收藏 0
点赞 0
评论 0
public Object getValueAt(TreeNode node, int columnIndex) {
PresoObjLivenessCCTNode livenessNode = (PresoObjLivenessCCTNode)node;
if (selection == null) columnIndex++;
if (columnIndex == 1) {
return livenessNode.getNodeName();
} else if (columnIndex == 2) {
return livenessNode.totalObjSize;
} else if (columnIndex == 3) {
return livenessNode.nLiveObjects;
} else if (columnIndex == 4) {
return livenessNode.nCalls;
} else if (columnIndex == 5) {
return livenessNode.avgObjectAge;
} else if (columnIndex == 6) {
return livenessNode.survGen;
} else if (columnIndex == 7) {
return livenessNode.nTotalAllocObjects;
} else if (columnIndex == 0) {
if (selection.isEmpty()) return Boolean.FALSE;
return selection.contains(nodesMap.get(node));
}
return null;
}
PlotConfigurationTreeTransferHandler.java 文件源码
项目:rapidminer
阅读 24
收藏 0
点赞 0
评论 0
/**
* @param container
* @param comp
* @param childIndex
* @param container2
*/
private String canImportRangeAxis(Component container, TreeNode treeNode, int childIndex, Component container2) {
String importAction = I18N.getGUILabel("plotter.drag_and_drop.axis_drop.move_axis");
// RangeAxisConfigTreeNode can only be dropped on PlotConfigTreeNodes
if (!(treeNode instanceof PlotConfigurationTreeNode)) {
updateToolTip(container, I18N.getGUILabel("plotter.drag_and_drop.axis_drop.cant_drop_axis_config"));
return null;
}
// can only be dropped below static dimension configs
if (childIndex > -1 && childIndex < PlotConfigurationTreeModel.NUMBER_OF_PERMANENT_DIMENSIONS) {
updateToolTip(container, I18N.getGUILabel("plotter.drag_and_drop.axis_drop.only_below_dims"));
return null;
}
if (childIndex == -1) {
return I18N.getGUILabel("plotter.drag_and_drop.axis_drop.move_to_end");
}
return importAction;
}
ElementTreePanel.java 文件源码
项目:OpenJSharp
阅读 23
收藏 0
点赞 0
评论 0
/**
* Invoke this method after you've changed how node is to be
* represented in the tree.
*/
@Override
public void nodeChanged(TreeNode node) {
if (listenerList != null && node != null) {
TreeNode parent = node.getParent();
if (parent == null && node != root) {
parent = root;
}
if (parent != null) {
int anIndex = getIndexOfChild(parent, node);
if (anIndex != -1) {
int[] cIndexs = new int[1];
cIndexs[0] = anIndex;
nodesChanged(parent, cIndexs);
}
}
}
}
DisplayTreeNode.java 文件源码
项目:JavaGraph
阅读 21
收藏 0
点赞 0
评论 0
@Override
public int compare(TreeNode o1, TreeNode o2) {
int result = compare(o1 instanceof RecipeTreeNode, o2 instanceof RecipeTreeNode);
if (result != 0) {
return result;
}
result = compare(o1 instanceof ActionTreeNode, o2 instanceof ActionTreeNode);
if (result != 0) {
return result;
}
if (o1 instanceof ActionTreeNode) {
result =
compare(((ActionTreeNode) o2).isProperty(), ((ActionTreeNode) o1).isProperty());
if (result != 0) {
return result;
}
}
return stringComparator.compare(o1.toString(), o2.toString());
}
JCheckBoxTree.java 文件源码
项目:Cognizant-Intelligent-Test-Scripter
阅读 20
收藏 0
点赞 0
评论 0
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
TreeNode node = (TreeNode) value;
TreePath tp = new TreePath(getPath(node));
CheckedNode cn = nodesCheckingState.get(tp);
checkBox.setIcon(getIcon(value));
if (cn == null) {
return this;
}
checkBox.setSelected(cn.isSelected);
checkBox.setText(node.toString());
checkBox.setOpaque(cn.isSelected && cn.hasChildren && !cn.allChildrenSelected);
return this;
}
ProfilerTreeTable.java 文件源码
项目:incubator-netbeans
阅读 30
收藏 0
点赞 0
评论 0
TreePath getNextPath(TreePath path, boolean down) {
TreeModel _model = model.treeModel;
TreeNode node = (TreeNode)path.getLastPathComponent();
if (down && _model.getChildCount(node) > 0)
return path.pathByAddingChild(_model.getChild(node, 0));
TreePath parentPath = path.getParentPath();
if (!down && parentPath == null)
return path.pathByAddingChild(_model.getChild(node, 0));
TreeNode parent = (TreeNode)parentPath.getLastPathComponent();
int idx = _model.getIndexOfChild(parent, node) + 1;
if (_model.getChildCount(parent) > idx)
return parentPath.pathByAddingChild(_model.getChild(parent, idx));
if (!down && parentPath.getParentPath() == null) {
return parentPath.pathByAddingChild(_model.getChild(parent, 0));
} else {
return getNextPath(parentPath, false);
}
}
DefaultSelectionTreeModel.java 文件源码
项目:alevin-svn2
阅读 21
收藏 0
点赞 0
评论 0
@Override
public Object getChild(Object parent, int index) {
if (parent instanceof IProxy)
return ((IProxy) parent).getChildAt(index);
else if (parent instanceof TreeNode)
return ((TreeNode) parent).getChildAt(index);
else
return null;
}
DefaultSelectionTreeModel.java 文件源码
项目:alevin-svn2
阅读 22
收藏 0
点赞 0
评论 0
@Override
public int getChildCount(Object parent) {
if (parent instanceof IProxy)
return ((IProxy) parent).getChildCount();
else if (parent instanceof TreeNode)
return ((TreeNode) parent).getChildCount();
else
return 0;
}
ResourceTree.java 文件源码
项目:JavaGraph
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void mouseReleased(MouseEvent evt) {
// find the node that belongs to this event
TreeNode selected = getMousedNode(evt);
// show popup menu
if (evt.isPopupTrigger()) {
showPopupMenu(selected, evt);
}
}
ProfilerTreeTable.java 文件源码
项目:incubator-netbeans
阅读 24
收藏 0
点赞 0
评论 0
public final boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof TreePathKey)) return false;
TreeNode[] _pathToRoot = ((TreePathKey)o).pathToRoot;
if (pathToRoot.length != _pathToRoot.length) return false;
for (int i = pathToRoot.length - 1; i >= 0 ; i--)
if (!pathToRoot[i].equals(_pathToRoot[i])) return false;
return true;
}
TreeView.java 文件源码
项目:incubator-netbeans
阅读 21
收藏 0
点赞 0
评论 0
/** Expands all paths.
*/
public void expandAll() {
try {
tree.setUI(null);
TreeNode root = (TreeNode) tree.getModel().getRoot();
expandOrCollapseAll(new TreePath(root), true);
} finally {
tree.updateUI();
}
}
AssertionTreeNode.java 文件源码
项目:marathonv5
阅读 21
收藏 0
点赞 0
评论 0
private TreeNode getNodeForMethod(Method method) {
Object r = null;
try {
method.setAccessible(true);
r = method.invoke(object, new Object[] {});
} catch (Throwable t) {
}
String p = getPropertyName(method.getName());
return getNewNode(r, p);
}
VisualizerSpeed95364Test.java 文件源码
项目:incubator-netbeans
阅读 21
收藏 0
点赞 0
评论 0
private void doTest() {
TreeNode tn = null;
for (int i = 0; i < 100000; i++) {
tn = toCheck.getChildAt(size/2);
}
assertEquals("One node created + 50 at begining", 51, chK.cnt);
}