本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode.isLeaf方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode.isLeaf方法的具体用法?Java DefaultMutableTreeNode.isLeaf怎么用?Java DefaultMutableTreeNode.isLeaf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.DefaultMutableTreeNode
的用法示例。
在下文中一共展示了DefaultMutableTreeNode.isLeaf方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filterNode
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Removes non-agents from DefaultMutableTreeNode.
*
* @param node the node
* @param key the key
*/
private void filterNode(DefaultMutableTreeNode node){
Vector<DefaultMutableTreeNode> toDeleteVect= new Vector<DefaultMutableTreeNode>();
@SuppressWarnings("unchecked")
Enumeration<DefaultMutableTreeNode> e = node.depthFirstEnumeration();
if(e != null){
while (e.hasMoreElements()){
DefaultMutableTreeNode actualElement = e.nextElement();
if (actualElement.isLeaf() == true && matchAgentClass(actualElement) == false) {
//--- immediate removal invalidates the enumeration ---
// actualElement.removeFromParent();
// --- remember for later removal ---
toDeleteVect.add(actualElement);
}
}
}
//--- delete nodes ---
for( int i=0; i < toDeleteVect.size(); i++){
toDeleteVect.get(i).removeFromParent();
}
}
示例2: filterNodeByKey
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Filter node by key.
*
* @param node the node
* @param key the key
*/
private void filterNodeByKey(DefaultMutableTreeNode node, String key){
Vector<DefaultMutableTreeNode> toDeleteVect= new Vector<DefaultMutableTreeNode>();
@SuppressWarnings("unchecked")
Enumeration<DefaultMutableTreeNode> e = node.breadthFirstEnumeration();
if(e != null){
while (e.hasMoreElements()){
DefaultMutableTreeNode actualElement = e.nextElement();
if (actualElement.isLeaf() == true && key.isEmpty() == false && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == false) {
//--- immediate removal invalidates the enumeration ---
// actualElement.removeFromParent();
// --- remember for later removal ---
toDeleteVect.add(actualElement);
}
if(actualElement.isLeaf() == true && actualElement.toString().toLowerCase().contains(key.toLowerCase()) == true){
//--- (re)expand collapsed parent if search string matches ---
int level = actualElement.getLevel() -1;
StringBuilder sb = new StringBuilder();
sb.append(level -1).append(",");
String levelString = sb.toString();
if(expansionState.contains(levelString) == false){
levelString = sb.append(level).append(",").toString();
expansionState = expansionState.concat(levelString);
}
}
}
}
//--- delete nodes ---
for( int i=0; i < toDeleteVect.size(); i++){
toDeleteVect.get(i).removeFromParent();
}
}
示例3: sortThreads
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
public void sortThreads() {
DefaultMutableTreeNode tempNode = (DefaultMutableTreeNode) copyNode((DefaultMutableTreeNode) getModel().getRoot());
// --- save expansion state ---
expansionState = saveExpansionState();
// --- sort and update ---
@SuppressWarnings("rawtypes")
Enumeration e = tempNode.breadthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (node.isLeaf() == true) {
sortNodesDescending((DefaultMutableTreeNode) node.getParent(),
(DefaultTreeModel) getModel());
}
}
((DefaultTreeModel) getModel()).setRoot(tempNode);
// --- restore expansion ---
restoreExpansionState(expansionState);
}
示例4: itemSelected
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* @param e
*/
protected void itemSelected(MouseEvent e) {
if (e.getClickCount() == 2) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node != null) {
if (node.isLeaf())
if (node.getParent() != null) {
if (node.getParent().toString().equals("graphs")) {
for (int i=0 ; i<observers.size() ; i++)
(observers.get(i)).graphSelected(node.toString());
}
else if (node.getParent().toString().equals("animations")) {
for (int i=0 ; i<observers.size() ; i++)
(observers.get(i)).animationSelected(node.toString());
}
else if (node.getParent().toString().equals("algorithms")) {
for (int i=0 ; i<observers.size() ; i++)
(observers.get(i)).algorithmSelected(node.toString());
}
}
}
}
}
示例5: valueChanged
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/** Required by TreeSelectionListener interface. */
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node == null)
return;
Object nodeInfo = node.getUserObject();
if (node.isLeaf()) {
BookInfo book = (BookInfo) nodeInfo;
displayURL(book.bookURL);
if (DEBUG) {
System.out.print(book.bookURL + ": \n ");
}
} else {
displayURL(helpURL);
}
if (DEBUG) {
System.out.println(nodeInfo.toString());
}
}
示例6: valueChanged
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/** Required by TreeSelectionListener interface. */
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node == null) return;
Object nodeInfo = node.getUserObject();
if (node.isLeaf()) {
BookInfo book = (BookInfo)nodeInfo;
displayURL(book.bookURL);
if (DEBUG) {
System.out.print(book.bookURL + ": \n ");
}
} else {
displayURL(helpURL);
}
if (DEBUG) {
System.out.println(nodeInfo.toString());
}
}
示例7: sortTree
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的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();
}
}
示例8: valueChanged
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* This function analyses a tree selection event and calls the
* right methods to take care of building the requested unit's
* details.
*
* @param event The incoming TreeSelectionEvent.
*/
@Override
public void valueChanged(TreeSelectionEvent event) {
detailPanel.removeAll();
DefaultMutableTreeNode node
= (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node != null) {
if (node.isLeaf()) {
OptionGroup group = (OptionGroup) node.getUserObject();
for (Option option : group.getOptions()) {
addOptionUI(option, editable && group.isEditable());
}
} else {
tree.expandPath(event.getPath());
}
}
detailPanel.revalidate();
detailPanel.repaint();
}
示例9: copyNode
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/**
* Gets a copy of DefaultMutableTreeNode.
*
* @param OriginNode the origin node
* @return the object
*/
private Object copyNode(DefaultMutableTreeNode OriginNode){
DefaultMutableTreeNode Copy = new DefaultMutableTreeNode(OriginNode.getUserObject());
if(OriginNode.isLeaf()){
return Copy;
}else{
int cc = OriginNode.getChildCount();
for(int i=0;i<cc;i++){
Copy.add((MutableTreeNode) copyNode((DefaultMutableTreeNode)OriginNode.getChildAt(i)));
}
return Copy;
}
}
示例10: valueChanged
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
/** Required by TreeSelectionListener interface. */
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if (node != null && node.isLeaf()) {
int pos = workspace.getDividerLocation();
workspace.setTopComponent((JPanel) node.getUserObject());
workspace.setDividerLocation(pos);
}
}
示例11: expandTree
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
private void expandTree(JTree tree) {
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel()
.getRoot();
Enumeration e = root.breadthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
if (node.isLeaf()) {
continue;
}
int row = tree.getRowForPath(new TreePath(node.getPath()));
tree.expandRow(row);
}
}
示例12: traverseTree
import javax.swing.tree.DefaultMutableTreeNode; //导入方法依赖的package包/类
public void traverseTree(DefaultMutableTreeNode root, JMenu rootMenu) {
for (Enumeration e = root.children(); e.hasMoreElements(); ) {
DefaultMutableTreeNode child = (DefaultMutableTreeNode)e.nextElement();
if ( child.isLeaf() ) {
JMenuItem childMI = new JMenuItem(child.toString());
rootMenu.add(childMI);
childMI.addActionListener(this);
} else {
JMenu nextRootMenu = new JMenu(child.toString());
traverseTree(child, nextRootMenu);
rootMenu.add(nextRootMenu);
}
}
}