当前位置: 首页>>代码示例>>Java>>正文


Java DefaultMutableTreeNode类代码示例

本文整理汇总了Java中javax.swing.tree.DefaultMutableTreeNode的典型用法代码示例。如果您正苦于以下问题:Java DefaultMutableTreeNode类的具体用法?Java DefaultMutableTreeNode怎么用?Java DefaultMutableTreeNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DefaultMutableTreeNode类属于javax.swing.tree包,在下文中一共展示了DefaultMutableTreeNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRoot

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
public static TreeNode getRoot() {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode("root");
    DefaultMutableTreeNode first = new DefaultMutableTreeNode("first");
    DefaultMutableTreeNode second = new DefaultMutableTreeNode("second");
    DefaultMutableTreeNode third = new DefaultMutableTreeNode("third");

    first.add(new DefaultMutableTreeNode("1.1"));
    first.add(new DefaultMutableTreeNode("1.2"));
    first.add(new DefaultMutableTreeNode("1.3"));

    second.add(new DefaultMutableTreeNode("2.1"));
    second.add(new DefaultMutableTreeNode("2.2"));
    second.add(new DefaultMutableTreeNode("2.3"));

    third.add(new DefaultMutableTreeNode("3.1"));
    third.add(new DefaultMutableTreeNode("3.2"));
    third.add(new DefaultMutableTreeNode("3.3"));

    node.add(first);
    node.add(second);
    node.add(third);

    return node;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:Test4631471.java

示例2: run

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
@Override
public void run() {
    Thread.currentThread().setUncaughtExceptionHandler(this);

    DefaultMutableTreeNode root = new DefaultMutableTreeNode();
    DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
    DefaultTreeModel model = new DefaultTreeModel(root);

    this.tree = new JTree();
    this.tree.setModel(model);

    JFrame frame = new JFrame(getClass().getSimpleName());
    frame.add(this.tree);

    model.addTreeModelListener(this); // frame is not visible yet
    model.insertNodeInto(child, root, root.getChildCount());
    model.removeNodeFromParent(child);

    frame.setSize(640, 480);
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    frame.setVisible(true);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:Test8015926.java

示例3: PlotConfigurationTreeModel

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
/**
 * @param root
 */
public PlotConfigurationTreeModel(DefaultMutableTreeNode root, PlotConfiguration plotConfig,
		PlotConfigurationTree plotConfigTree) {
	super(root);
	this.plotConfig = plotConfig;
	this.plotConfigTree = plotConfigTree;

	if (root != null) {
		fillNewPlotConfigNode(plotConfig);
	}

	if (plotConfig != null) {
		plotConfig.addPlotConfigurationListener(this);
	}

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:19,代码来源:PlotConfigurationTreeModel.java

示例4: createRamoptionNode

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
private DefaultMutableTreeNode createRamoptionNode(Ramoption ramoption) {
    DefaultMutableTreeNode dmtNode = new DefaultMutableTreeNode("ramoption");

    String value = ramoption.getValue();
    if (value != null && !value.isEmpty()) {
        dmtNode.add(new DefaultMutableTreeNode("value" + valueDivider + value));
    }

    String aDefault = ramoption.getDefault();
    if (aDefault != null && !aDefault.isEmpty()) {
        dmtNode.add(new DefaultMutableTreeNode("default" + valueDivider + aDefault));
    }

    return dmtNode;
}
 
开发者ID:phweda,项目名称:MFM,代码行数:16,代码来源:MAMEtoJTree.java

示例5: getTreeCellRendererComponent

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf,
		int row, boolean hasFocus) {
	super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
	DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
	if (node.getChildCount() > 0) {
		setIcon(this.pack);
	} else if (getFileName(node).endsWith(".class") || getFileName(node).endsWith(".java")) {
		setIcon(this.java_image);
	} else if (getFileName(node).endsWith(".yml") || getFileName(node).endsWith(".yaml")) {
		setIcon(this.yml_image);
	} else {
		setIcon(this.file_image);
	}

	return this;
}
 
开发者ID:KevinPriv,项目名称:Luyten4Forge,代码行数:18,代码来源:CellRenderer.java

示例6: addSubTrees

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void addSubTrees(DefaultMutableTreeNode root) {
    DefaultMutableTreeNode parent
        = new DefaultMutableTreeNode(new ColopediaTreeItem(this, getId(),
                getName(), null));

    List<NationType> nations = new ArrayList<>();
    nations.addAll(getSpecification().getEuropeanNationTypes());
    nations.addAll(getSpecification().getREFNationTypes());
    nations.addAll(getSpecification().getIndianNationTypes());
    ImageIcon icon = new ImageIcon(ImageLibrary.getMiscImage(ImageLibrary.BELLS, ImageLibrary.ICON_SIZE));
    for (NationType type : nations) {
        parent.add(buildItem(type, icon));
    }
    root.add(parent);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:20,代码来源:NationTypeDetailPanel.java

示例7: retrieveDeletedFiles

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
private void retrieveDeletedFiles(final Node[] activatedNodes, final RevertPanel p) {
    VCSContext ctx = VCSContext.forNodes(activatedNodes);
    Set<VCSFileProxy> rootSet = ctx.getRootFiles();        
    if(rootSet == null || rootSet.size() < 1) { 
        return;
    }                                        
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
    for (VCSFileProxy root : rootSet) {            
        PlainFileNode rfn = new PlainFileNode(root);
        populateNode(rfn, root, !VersioningSupport.isFlat(root));
        if(rfn.getChildCount() > 0) {
            rootNode.add(rfn);
        }
    }
    if(rootNode.getChildCount() > 0) {
        p.setRootNode(rootNode);
    } else {
        p.setRootNode(null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:RevertDeletedAction.java

示例8: editRayAction

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
/**
 * Shows the a dialog allowing the user to edit the ray.
 */
private void editRayAction() {
    // getProperty the currently selected body
    TreePath path = this.tree.getSelectionPath();
    // make sure something is selected
    if (path != null) {
        // getProperty the selected node
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
        // make sure its a ray that is selected
        if (node.getUserObject() instanceof SandboxRay) {
            // getProperty the ray from the node
            SandboxRay ray = (SandboxRay) node.getUserObject();
            // show the right dialog
            synchronized (Simulation.LOCK) {
                SandboxRay nRay = EditRayDialog.show(ControlUtilities.getParentWindow(this), ray);
                this.simulation.getRays().remove(ray);
                this.simulation.getRays().add(nRay);
                node.setUserObject(nRay);
            }
        }
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:25,代码来源:SimulationTreePanel.java

示例9: 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();
		}
	}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:40,代码来源:ThreadInfoStorageTree.java

示例10: childIndex

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
/**
 * Returns the index of a child of a given node, provided its string value.
 * 
 * @param node The node to search its children.
 * @param childValue The value of the child to compare with.
 * @return The index.
 */
private int childIndex(final DefaultMutableTreeNode node, final String childValue) {
  @SuppressWarnings("unchecked")
  Enumeration<DefaultMutableTreeNode> children = node.children();
  DefaultMutableTreeNode child = null;
  int index = -1;

  while (children.hasMoreElements() && index < 0) {
    child = children.nextElement();

    if (child.getUserObject() != null && childValue.equals(child.getUserObject())) {
      index = node.getIndex(child);
    }
  }

  return index;
}
 
开发者ID:oxygenxml,项目名称:oxygen-dita-translation-package-builder,代码行数:24,代码来源:PreviewDialog.java

示例11: 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();
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:26,代码来源:OptionGroupUI.java

示例12: 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());
              }
          }
  }
	}
}
 
开发者ID:guilhebl,项目名称:routerapp,代码行数:27,代码来源:NavigationView.java

示例13: actionPerformed

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
  Runnable runner = new Runnable() {
    @Override
    public void run() {
      TreePath[] paths = resourcesTree.getSelectionPaths();
      for(TreePath path : paths) {
        final Object userObject = ((DefaultMutableTreeNode)
          path.getLastPathComponent()).getUserObject();
        if(userObject instanceof NameBearerHandle) {
          SwingUtilities.invokeLater(new Runnable() { @Override
          public void run() {
            ((NameBearerHandle)userObject).getCloseAction()
              .actionPerformed(null);
          }});
        }
      }
    }
  };
  Thread thread = new Thread(runner, "CloseSelectedResourcesAction");
  thread.setPriority(Thread.MIN_PRIORITY);
  thread.start();
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:24,代码来源:MainFrame.java

示例14: getMultipleNodesAvailable

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
/**
 * Provides the Vector of all currently available nodes of the same kind as the current node.
 *
 * @param currNode The current node of the object structure
 * @return the multiple nodes available
 */
private Vector<DefaultMutableTreeNode> getMultipleNodesAvailable(DefaultMutableTreeNode currNode) {
	
	// --- The result vector of all needed nodes ------------------------------------ 
	Vector<DefaultMutableTreeNode> nodesFound = new Vector<DefaultMutableTreeNode>();
	// --- Can we find the number of similar nodes to the current one? -------------- 
	DynType currDT = (DynType) currNode.getUserObject();
	
	// --- The current parentNode and the position of the current node --------------
	DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) currNode.getParent();

	// --- Search for all similar nodes --------------------------------------------- 
	for (int i = 0; i < parentNode.getChildCount(); i++) {
		DefaultMutableTreeNode checkNode = (DefaultMutableTreeNode) parentNode.getChildAt(i);
		DynType checkDT = (DynType) checkNode.getUserObject();
		if (checkDT.equals(currDT)) {
			nodesFound.add(checkNode);
		} 
	}
	return nodesFound;

}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:28,代码来源:DynFormBase.java

示例15: FileTree

import javax.swing.tree.DefaultMutableTreeNode; //导入依赖的package包/类
/** Construct a FileTree */
 public FileTree(File dir) {
   setLayout(new BorderLayout());
   applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
   setBorder(null);

   // Make a tree list with all the nodes, and make it a JTree
   JTree tree = new JTree(addNodes(null, dir));
   tree.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

   // Add a listener
   tree.addTreeSelectionListener(new TreeSelectionListener() {
     public void valueChanged(TreeSelectionEvent e) {
       DefaultMutableTreeNode node = (DefaultMutableTreeNode) e
           .getPath().getLastPathComponent();
     }
   });

   add(BorderLayout.CENTER, tree);
   
   JScrollPane scrollBarExplorer = new JScrollPane();
   scrollBarExplorer.getViewport().add(tree);
   scrollBarExplorer.setBorder(null);
add(scrollBarExplorer, BorderLayout.CENTER);

 }
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:27,代码来源:FileTree.java


注:本文中的javax.swing.tree.DefaultMutableTreeNode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。