本文整理汇总了Java中javax.swing.tree.TreePath类的典型用法代码示例。如果您正苦于以下问题:Java TreePath类的具体用法?Java TreePath怎么用?Java TreePath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TreePath类属于javax.swing.tree包,在下文中一共展示了TreePath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: installForOR
import javax.swing.tree.TreePath; //导入依赖的package包/类
public static TreeSearch installForOR(JTree tree) {
return new TreeSearch(tree) {
@Override
public void selectAndSrollTo(TreeNode node) {
if (node instanceof ORObjectInf) {
TreePath path = ((ORObjectInf) node).getTreePath();
tree.setSelectionPath(path);
tree.scrollPathToVisible(path);
} else {
super.selectAndSrollTo(node);
}
}
};
}
示例2: areSiblingsSelected
import javax.swing.tree.TreePath; //导入依赖的package包/类
private boolean areSiblingsSelected(TreePath path) {
TreePath parent = path.getParentPath();
if (parent == null) {
return true;
}
Object node = path.getLastPathComponent();
Object parentNode = parent.getLastPathComponent();
int childCount = model.getChildCount(parentNode);
for (int i = 0; i < childCount; i++) {
Object childNode = model.getChild(parentNode, i);
if (childNode == node) {
continue;
}
if (!isPathSelected(parent.pathByAddingChild(childNode))) {
return false;
}
}
return true;
}
示例3: toggle
import javax.swing.tree.TreePath; //导入依赖的package包/类
private boolean toggle( TreePath treePath ) {
if( treePath == null )
return false;
Node node = Visualizer.findNode( treePath.getLastPathComponent() );
if( node == null )
return false ;
ElementNode.Description description = node.getLookup().lookup(ElementNode.Description.class);
if (description != null ) {
if( description.isSelectable() ) {
description.setSelected( !description.isSelected() );
return true;
} else {
boolean newState = !description.isSelected();
toggleChildren( description.getSubs(), newState );
// first toggle children, then itself. If children were not expanded,
// the self-toggle will fire appropriate events and controls will be reevaluated.
description.setSelected(newState);
}
}
return false;
}
示例4: selectPath
import javax.swing.tree.TreePath; //导入依赖的package包/类
void selectPath(TreePath path, boolean scrollToVisible) {
internal = true;
markExpansionTransaction();
try {
// tree.expandPath(path); // actually should not be needed, automatically expands the node further down
tree.setSelectionPath(path);
// Clear and select again to make sure the underlying tree is ready
tree.setSelectionPath(null);
tree.setSelectionPath(path);
} finally {
clearExpansionTransaction();
internal = false;
}
if (scrollToVisible) {
Rectangle bounds = tree.getPathBounds(path);
if (bounds != null) scrollRectToVisible(bounds);
}
}
示例5: expandAllPaths
import javax.swing.tree.TreePath; //导入依赖的package包/类
/**
* Opens all paths in the given node and all nodes below that.
*
* @param path
* the tree path to the node to expand
* @param treeModel
* the tree model
* @see JTree#expandPath(TreePath)
*/
protected void expandAllPaths(TreePath path, TreeModel treeModel) {
expandPath(path);
final Object node = path.getLastPathComponent();
final int n = treeModel.getChildCount(node);
for (int index = 0; index < n; index++) {
final Object child = treeModel.getChild(node, index);
expandAllPaths(path.pathByAddingChild(child));
}
}
示例6: sortTree
import javax.swing.tree.TreePath; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public static void sortTree(PnlGuiConfig pnlGuiConfig, DefaultMutableTreeNode root, JTree treeTypes) {
if (root != null) {
Enumeration e = root.depthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (!node.isLeaf()) {
sort(node); //selection sort
}
}
//Atualizando a arvore
if (updateTree) {
TreePath treePath = treeTypes.getSelectionPath();
DefaultTreeModel model = (DefaultTreeModel) treeTypes.getModel();
model.reload();
treeTypes.setSelectionPath(treePath);
updateTree = false;
}
pnlGuiConfig.getPnlFieldCondition().ckDynamicClick();
}
}
示例7: getSelectedNodes
import javax.swing.tree.TreePath; //导入依赖的package包/类
/**
* @return {@link List} of the currently selected nodes
*/
public List<String> getSelectedNodes() {
TreePath[] paths = tree.getSelectionPaths();
List<String> selectedNodes = new ArrayList<String>();
if (paths != null) {
for (TreePath path : paths) {
StringBuilder sb = new StringBuilder();
Object[] pathArray = path.getPath();
for (Object o : pathArray) {
String nodeName = o.toString();
if (nodeName.length() > 0) {
sb.append("/");
sb.append(o.toString());
}
}
selectedNodes.add(sb.toString());
}
}
return selectedNodes;
}
示例8: CheckboxTree
import javax.swing.tree.TreePath; //导入依赖的package包/类
/**
* Constructs a tree, with cell renderer and editor set by
* {@link #createRenderer()} and {@link #createEditor()}.
*/
public CheckboxTree() {
setCellRenderer(createRenderer());
setCellEditor(createEditor());
setEditable(true);
setRootVisible(false);
setShowsRootHandles(true);
// make sure the checkbox never selects the label
// note that the BasicTreeUI may not be what is used in the current LAF,
// but I don't know any other way to modify the selection behaviour
BasicTreeUI ui = new BasicTreeUI() {
@Override
protected void selectPathForEvent(TreePath path, MouseEvent event) {
if (!isOverCheckBox(path, event.getPoint().x)) {
super.selectPathForEvent(path, event);
}
}
};
setUI(ui);
// initialise the tree model
this.topNode = new DefaultMutableTreeNode();
this.treeModel = new DefaultTreeModel(this.topNode);
setModel(this.treeModel);
// set selection mode
getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
}
示例9: synchronizeExploredContext
import javax.swing.tree.TreePath; //导入依赖的package包/类
/** Synchronize the explored context from the manager of this Explorer.
*/
final void synchronizeExploredContext() {
final Node n = manager.getExploredContext();
if (n == null) {
return;
}
// run safely to be sure all preceding events are processed (especially VisualizerEvent.Added)
// otherwise VisualizerNodes may not be in hierarchy yet (see #140629)
VisualizerNode.runSafe(new Runnable() {
@Override
public void run() {
final TreePath tp = getTreePath(n);
LOG.log(Level.FINE, "synchronizeExploredContext {0} path {1}", new Object[] { n, tp });
showPath(tp);
}
});
}
示例10: OurTree
import javax.swing.tree.TreePath; //导入依赖的package包/类
/** Construct a Tree object with the given font size. */
public OurTree(int fontSize) {
Font font = OurUtil.getVizFont().deriveFont((float)fontSize);
OurTreeRenderer renderer = new OurTreeRenderer(fontSize);
renderer.setFont(font);
renderer.invalidate();
renderer.validate();
setRowHeight(0); // To allow variable row height on Mac OS X
setCellRenderer(renderer);
setFont(font);
setBorder(new EmptyBorder(8, 8, 2, 2));
getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
putClientProperty("JTree.lineStyle", "Angled");
setRootVisible(true);
setForeground(Color.BLACK);
setBackground(Color.WHITE);
setOpaque(true);
addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent e) {
TreePath path = OurTree.this.getSelectionPath();
if (path!=null) OurTree.this.listeners.fire(OurTree.this, Listener.Event.CLICK, path.getLastPathComponent());
}
});
}
示例11: valueChanged
import javax.swing.tree.TreePath; //导入依赖的package包/类
@Override
public void valueChanged(TreeSelectionEvent ev) {
TreePath[] paths = tree.getSelectionPaths();
if (paths == null) {
// part of bugfix #37279, if DnD is active then is useless select a nearby node
if (ExplorerDnDManager.getDefault().isDnDActive()) {
return;
}
callSelectionChanged(new Node[0]);
} else {
// we need to force no changes to nodes hierarchy =>
// we are requesting read request, but it is not necessary
// to execute the next action immediatelly, so postReadRequest
// should be enough
readAccessPaths = paths;
Children.MUTEX.postReadRequest(this);
}
}
示例12: canPerformAction
import javax.swing.tree.TreePath; //导入依赖的package包/类
@Override
public boolean canPerformAction(JTree targetTree, Object draggedNode, int action, Point location) {
TreePath pathTarget = targetTree.getPathForLocation(location.x, location.y);
if (pathTarget == null) {
targetTree.setSelectionPath(null);
return false;
}
targetTree.setSelectionPath(pathTarget);
if (action == DnDConstants.ACTION_COPY) {
return false;
} else if (action == DnDConstants.ACTION_MOVE) {
Object targetNode = pathTarget.getLastPathComponent();
return canMove(draggedNode, targetNode);
} else {
return false;
}
}
示例13: treeNodesRemoved
import javax.swing.tree.TreePath; //导入依赖的package包/类
@Override
public void treeNodesRemoved(TreeModelEvent e) {
// called to removed from JTree.expandedState
super.treeNodesRemoved(e);
boolean wasSelected = removedNodeWasSelected;
removedNodeWasSelected = false;
// part of bugfix #37279, if DnD is active then is useless select a nearby node
if (ExplorerDnDManager.getDefault().isDnDActive()) {
return;
}
if (wasSelected && tree.getSelectionCount() == 0) {
TreePath path = findSiblingTreePath(e.getTreePath(), e.getChildIndices());
// bugfix #39564, don't select again the same object
if ((path == null) || e.getChildIndices().length == 0) {
return;
} else if (path.getPathCount() > 0) {
tree.setSelectionPath(path);
}
}
}
示例14: applyForceAction
import javax.swing.tree.TreePath; //导入依赖的package包/类
/**
* Applies a force to the given body if the user accepts the input.
*/
private void applyForceAction() {
// the current selection should have the body selected
TreePath path = this.tree.getSelectionPath();
// make sure that something is selected
if (path != null) {
// getProperty the currently selected node
DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
// make sure the selected node is a body
if (node.getUserObject() instanceof SandboxBody) {
// getProperty the body from the node
SandboxBody body = (SandboxBody) node.getUserObject();
// show the force input dialog
Vector2 f = ApplyForceDialog.show(ControlUtilities.getParentWindow(this));
// make sure the user accepted the input
if (f != null) {
synchronized (Simulation.LOCK) {
body.applyForce(f);
}
}
}
}
}
示例15: AvailableTreeTable
import javax.swing.tree.TreePath; //导入依赖的package包/类
public AvailableTreeTable() {
super();
setTreeTableModel(new AvailableTreeTableModel(data.getRoot()));
sizeColumns();
setRowHeight(CELL_HEIGHT);
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
getTableHeader().setReorderingAllowed(false);
addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
TreePath path = e.getPath();
TreeTableNode node = (TreeTableNode) path.getLastPathComponent();
if ("template".equals(node.getType())) {
tempDownload.setEnabled(true);
} else {
tempDownload.setEnabled(false);
}
}
});
}