當前位置: 首頁>>代碼示例>>Java>>正文


Java TreePath類代碼示例

本文整理匯總了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);
            }
        }
    };
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:15,代碼來源:TreeSearch.java

示例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;
}
 
開發者ID:zeng198821,項目名稱:CodeGenerate,代碼行數:21,代碼來源:CheckTreeSelectionModel.java

示例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;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:CheckTreeView.java

示例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);
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:ProfilerTreeTable.java

示例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));
	}
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:19,代碼來源:PlotConfigurationTree.java

示例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();
	}
}
 
開發者ID:adelbs,項目名稱:ISO8583,代碼行數:24,代碼來源:SortTreeHelper.java

示例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;
}
 
開發者ID:didichuxing2,項目名稱:https-github.com-apache-zookeeper,代碼行數:23,代碼來源:ZooInspectorTreeViewer.java

示例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);
}
 
開發者ID:meteoorkip,項目名稱:JavaGraph,代碼行數:30,代碼來源:CheckboxTree.java

示例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);
        }
    });
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:TreeView.java

示例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());
      }
   });
}
 
開發者ID:ModelWriter,項目名稱:Tarski,代碼行數:25,代碼來源:OurTree.java

示例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);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:TreeView.java

示例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;
	}
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:18,代碼來源:ProjectExplorer.java

示例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);
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:24,代碼來源:TreeView.java

示例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);
                }
            }
        }
    }
}
 
開發者ID:dmitrykolesnikovich,項目名稱:featurea,代碼行數:26,代碼來源:SimulationTreePanel.java

示例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);
			}
		}
	});
}
 
開發者ID:max6cn,項目名稱:jmt,代碼行數:22,代碼來源:TemplateAddingPanel.java


注:本文中的javax.swing.tree.TreePath類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。