Java Code Examples for javax.swing.tree.DefaultMutableTreeNode

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project Android-DB-Editor, under directory /src/com/troido/dbeditor/.

Source file: AndroidDBEditor.java

  22 
vote

public JTree createDeviceTree(List<Device> devices){
  DefaultMutableTreeNode top=new DefaultMutableTreeNode("Devices");
  TreePath path=new TreePath(top);
  JTree tree=new JTree(top);
  for (  Device device : devices)   top.add(createNodes(device));
  tree.expandPath(path);
  tree.setRootVisible(false);
  tree.setCellRenderer(new CellRenderer());
  tree.addMouseListener(new TreeMouseListener());
  return tree;
}
 

Example 2

From project codjo-segmentation, under directory /codjo-segmentation-gui/src/main/java/net/codjo/segmentation/gui/settings/.

Source file: AxisTreeModel.java

  22 
vote

/** 
 * Mise  jour des sleeveCode pour tous les noeuds (et ses fils) apr? suppression d'un noeud.
 * @param childAfter : point de d?art de la mise  jour.
 * @param parentNode
 */
private void updateSleeveCodes(DefaultMutableTreeNode childAfter,final DefaultMutableTreeNode parentNode){
  while (childAfter != null) {
    final String newSleevCode=updateSleeveCode(childAfter);
    final Row row=((Sleeve)childAfter).getRow();
    final int rowIndex=sonDataSource.getLoadResult().getRowIndex(row);
    sonDataSource.setValue(rowIndex,"sleeveCode",newSleevCode);
    Enumeration children=childAfter.children();
    while (children.hasMoreElements()) {
      DefaultMutableTreeNode child=(DefaultMutableTreeNode)children.nextElement();
      updateSleeveCodes(child,childAfter);
    }
    childAfter=(DefaultMutableTreeNode)parentNode.getChildAfter(childAfter);
  }
}
 

Example 3

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DefaultTreeView.java

  22 
vote

/** 
 * Returns a list of all user objects that traverses the subtree rooted at this node in breadth-first order..
 * @param node the node to start with.
 */
private final List<Object> breadthFirstUserObjects(TreeNode node){
  if (node == null) {
    return null;
  }
  Vector<Object> list=new Vector<Object>();
  DefaultMutableTreeNode theNode=null;
  Enumeration<?> local_enum=((DefaultMutableTreeNode)node).breadthFirstEnumeration();
  while (local_enum.hasMoreElements()) {
    theNode=(DefaultMutableTreeNode)local_enum.nextElement();
    list.add(theNode.getUserObject());
  }
  return list;
}
 

Example 4

From project dawn-isencia, under directory /com.isencia.passerelle.commons/src/main/java/com/isencia/util/swing/components/.

Source file: DynamicTree.java

  22 
vote

/** 
 * Remove the currently selected node. 
 */
public void removeCurrentNode(){
  TreePath currentSelection=tree.getSelectionPath();
  if (currentSelection != null) {
    DefaultMutableTreeNode currentNode=(DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
    MutableTreeNode parent=(MutableTreeNode)(currentNode.getParent());
    if (parent != null) {
      treeModel.removeNodeFromParent(currentNode);
      return;
    }
  }
  toolkit.beep();
}
 

Example 5

From project encog-java-workbench, under directory /src/main/java/org/encog/workbench/dialogs/.

Source file: DirChooser.java

  22 
vote

/** 
 * Write the dir selection in the text field.
 */
public void valueChanged(TreeSelectionEvent e){
  TreePath path=e.getPath();
  if (path != null) {
    DefaultMutableTreeNode node=(DefaultMutableTreeNode)path.getLastPathComponent();
    File dir=(File)node.getUserObject();
    dirText.setText(dir.getAbsolutePath());
  }
}
 

Example 6

From project extension_libero_manufacturing, under directory /extension/eevolution/libero/src/main/java/org/eevolution/form/bom/.

Source file: BOMTreeCellRenderer.java

  22 
vote

protected ImageIcon getIcon(Object value){
  DefaultMutableTreeNode node=(DefaultMutableTreeNode)value;
  ImageIcon icon=null;
  if (node.isLeaf()) {
    icon=Env.getImageIcon("Product10.gif");
  }
  return icon;
}
 

Example 7

From project freemind, under directory /freemind/freemind/modes/mindmapmode/attributeactors/.

Source file: ImportAttributesDialog.java

  22 
vote

private void createAttributeSubTrees(DefaultMutableTreeNode mapInfo,AttributeRegistry attributes){
  for (int i=0; i < attributes.size(); i++) {
    AttributeRegistryElement element=attributes.getElement(i);
    TreeNodeInfo treeNodeInfo=new AttributeTreeNodeInfo(element.getKey().toString(),element.isRestricted());
    DefaultMutableTreeNode attributeInfo=new DefaultMutableTreeNode(treeNodeInfo);
    createValueSubTrees(attributeInfo,element,currentAttributes);
    if (attributeInfo.getChildCount() != 0) {
      mapInfo.add(attributeInfo);
    }
  }
}
 

Example 8

From project glg2d, under directory /src/test/java/glg2d/.

Source file: UIDemo.java

  22 
vote

JComponent createTreeComponent(){
  DefaultMutableTreeNode root=new DefaultMutableTreeNode("Root");
  root.add(new DefaultMutableTreeNode("A"));
  DefaultMutableTreeNode b=new DefaultMutableTreeNode("B");
  b.add(new DefaultMutableTreeNode("b"));
  b.add(new DefaultMutableTreeNode("beta"));
  root.add(b);
  root.add(new DefaultMutableTreeNode("C"));
  root.add(new DefaultMutableTreeNode("D"));
  return new JTree(new DefaultTreeModel(root));
}
 

Example 9

From project Holo-Edit, under directory /holoedit/gui/.

Source file: DynamicTree.java

  22 
vote

/** 
 * Remove the currently selected node. 
 */
public void removeCurrentNode(){
  TreePath currentSelection=tree.getSelectionPath();
  if (currentSelection != null) {
    DefaultMutableTreeNode currentNode=(DefaultMutableTreeNode)(currentSelection.getLastPathComponent());
    MutableTreeNode parent=(MutableTreeNode)(currentNode.getParent());
    if (parent != null) {
      treeModel.removeNodeFromParent(currentNode);
      return;
    }
  }
  toolkit.beep();
}
 

Example 10

From project ISAcreator, under directory /src/main/java/org/isatools/isacreator/common/filterableTree/.

Source file: FilterableJTree.java

  22 
vote

public Set<String> getExpandedTreePaths(){
  Set<String> expandedPaths=new HashSet<String>();
  TreeNode rootNode=(TreeNode)getModel().getRoot();
  Enumeration children=rootNode.children();
  while (children.hasMoreElements()) {
    DefaultMutableTreeNode childNode=(DefaultMutableTreeNode)children.nextElement();
    TreePath path=new TreePath(childNode.getPath());
    if (isExpanded(path)) {
      expandedPaths.add(childNode.toString());
    }
  }
  return expandedPaths;
}
 

Example 11

From project JaamSim, under directory /com/sandwell/JavaSimulation3D/.

Source file: EntityPallet.java

  22 
vote

private static DefaultMutableTreeNode createTree(){
  DefaultMutableTreeNode root=new DefaultMutableTreeNode();
  for (  Palette p : Palette.getAll()) {
    DefaultMutableTreeNode packNode=new DefaultMutableTreeNode(p.getName(),true);
    for (    ObjectType type : ObjectType.getAll()) {
      if (type.getPalette() != p || !type.isDragAndDrop())       continue;
      DefaultMutableTreeNode classNode=new DefaultMutableTreeNode(type,true);
      packNode.add(classNode);
    }
    root.add(packNode);
  }
  return root;
}
 

Example 12

From project james-mime4j, under directory /examples/src/main/java/org/apache/james/mime4j/samples/tree/.

Source file: MessageTree.java

  22 
vote

/** 
 * Create a node given a Multipart body. Add the Preamble, all Body parts and the Epilogue to the node.
 * @param multipart the Multipart.
 * @return the root node of the tree.
 */
private DefaultMutableTreeNode createNode(Header header){
  DefaultMutableTreeNode node=new DefaultMutableTreeNode(new ObjectWrapper("Header",header));
  for (  Field field : header.getFields()) {
    String name=field.getName();
    node.add(new DefaultMutableTreeNode(new ObjectWrapper(name,field)));
  }
  return node;
}
 

Example 13

From project ceres, under directory /ceres-ui/src/test/java/com/bc/ceres/swing/.

Source file: TreeCellExtenderTest.java

  21 
vote

/** 
 * Creates and returns a sample <code>TreeModel</code>. Used primarily for beanbuilders to show something interesting.
 * @return the default <code>TreeModel</code>
 */
protected static TreeModel getDefaultTreeModel(){
  DefaultMutableTreeNode root=new DefaultMutableTreeNode("JTree");
  DefaultMutableTreeNode parent;
  parent=new DefaultMutableTreeNode("colors colors colors colors colors");
  root.add(parent);
  parent.add(new DefaultMutableTreeNode("blue"));
  parent.add(new DefaultMutableTreeNode("violet"));
  parent.add(new DefaultMutableTreeNode("red"));
  parent.add(new DefaultMutableTreeNode("yellow"));
  parent=new DefaultMutableTreeNode("sports sports sports sports sports sports");
  root.add(parent);
  parent.add(new DefaultMutableTreeNode("basketball"));
  parent.add(new DefaultMutableTreeNode("soccer"));
  parent.add(new DefaultMutableTreeNode("football football football football football football"));
  parent.add(new DefaultMutableTreeNode("hockey"));
  parent=new DefaultMutableTreeNode("food");
  root.add(parent);
  parent.add(new DefaultMutableTreeNode("hot dogs"));
  parent.add(new DefaultMutableTreeNode("pizza"));
  parent.add(new DefaultMutableTreeNode("ravioli ravioli ravioli ravioli ravioli ravioli ravioli ravioli ravioli ravioli ravioli ravioli"));
  parent.add(new DefaultMutableTreeNode("bananas"));
  return new DefaultTreeModel(root);
}
 

Example 14

From project Clotho-Core, under directory /ClothoApps/Grapevine/src/org/clothocad/tool/grapevine/.

Source file: BrowseNotes.java

  21 
vote

public LabNode(ObjLink alab){
  super(alab.name);
  dummynode=new DefaultMutableTreeNode("Loading...");
  DefaultTreeModel model=(DefaultTreeModel)collectionTree.getModel();
  MutableTreeNode node=(MutableTreeNode)LabNode.this;
  model.insertNodeInto(dummynode,node,0);
  mylink=alab;
}
 

Example 15

From project CloudReports, under directory /src/main/java/cloudreports/gui/.

Source file: CloudTree.java

  21 
vote

/** 
 * Creates a new CloudTree. 
 */
public CloudTree(){
  super(new DefaultMutableTreeNode("CloudReports"));
  DatacenterRegistryDAO drDAO=new DatacenterRegistryDAO();
  String[] datacenterNames=drDAO.getAllDatacentersNames();
  for (  String datacenterName : datacenterNames) {
    providerTreeNode.add(new DefaultMutableTreeNode(datacenterName,false));
  }
  CustomerRegistryDAO crDAO=new CustomerRegistryDAO();
  String[] customerNames=crDAO.getCustomersNames();
  for (  String customerName : customerNames) {
    customersTreeNode.add(new DefaultMutableTreeNode(customerName,false));
  }
  this.expandPath(new TreePath(getCloudTreeNode()));
}
 

Example 16

From project codjo-standalone-common, under directory /src/main/java/net/codjo/gui/.

Source file: ExplorerByStepTreeBuilder.java

  21 
vote

/** 
 * Retourne le renderer.
 * @param tree     -
 * @param value    -
 * @param sel      -
 * @param expanded -
 * @param leaf     -
 * @param row      -
 * @param hasFocus -
 * @return The TreeCellRendererComponent value
 */
public Component getTreeCellRendererComponent(JTree tree,Object value,boolean sel,boolean expanded,boolean leaf,int row,boolean hasFocus){
  DefaultMutableTreeNode node=(DefaultMutableTreeNode)value;
  if (node.getUserObject().getClass() != Table.class) {
    leaf=false;
  }
  super.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
  if (leaf) {
    if (isFinalTable(value)) {
      setIcon(finalTable);
    }
 else {
      setIcon(workTable);
    }
  }
  return this;
}
 

Example 17

From project CommunityCase, under directory /src/org/community/intellij/plugins/communitycase/checkin/.

Source file: PushActiveBranchesDialog.java

  21 
vote

/** 
 * Create UI components for the dialog
 */
private void createUIComponents(){
  myTreeRoot=new CheckedTreeNode("ROOT");
  myCommitTree=new CheckboxTree(new CheckboxTree.CheckboxTreeCellRenderer(){
    @Override public void customizeRenderer(    JTree tree,    Object value,    boolean selected,    boolean expanded,    boolean leaf,    int row,    boolean hasFocus){
      if (UIUtil.isUnderGTKLookAndFeel()) {
        final Color background=selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
        UIUtil.changeBackGround(this,background);
      }
      ColoredTreeCellRenderer r=getTextRenderer();
      if (!(value instanceof DefaultMutableTreeNode)) {
        renderUnknown(r,value);
        return;
      }
      DefaultMutableTreeNode node=(DefaultMutableTreeNode)value;
      if (!(node.getUserObject() instanceof Node)) {
        renderUnknown(r,node.getUserObject());
        return;
      }
      ((Node)node.getUserObject()).render(r);
    }
    /** 
 * Render unknown node
 * @param r     a renderer to use
 * @param value the unknown value
 */
    private void renderUnknown(    ColoredTreeCellRenderer r,    Object value){
      r.append("UNSUPPORTED NODE TYPE: " + (value == null ? "null" : value.getClass().getName()),SimpleTextAttributes.ERROR_ATTRIBUTES);
    }
  }
,myTreeRoot){
    @Override protected void onNodeStateChanged(    CheckedTreeNode node){
      updateButtons();
      super.onNodeStateChanged(node);
    }
  }
;
}
 

Example 18

From project crammer, under directory /src/main/java/uk/ac/ebi/ena/sra/cram/impl/.

Source file: RecordCodecFactory.java

  21 
vote

public static CodecStats getCodecStats(DefaultMutableTreeNode node){
  Object codec=node.getUserObject();
  CodecStats stats=new CodecStats();
  if (codec instanceof MeasuringCodec<?>) {
    stats.name=((MeasuringCodec)codec).getName();
    stats.bitsWritten=((MeasuringCodec)codec).getWrittenBits();
    stats.objectsWritten=((MeasuringCodec)codec).getWrittenObjects();
  }
 else {
    stats.name=((ByteArrayBitCodec)codec).getName();
    stats.bitsWritten=((ByteArrayBitCodec)codec).getStats().nofBis;
    stats.objectsWritten=((ByteArrayBitCodec)codec).getStats().bytesWritten;
  }
  stats.children=new TreeMap<String,RecordCodecFactory.CodecStats>();
  Enumeration e=node.children();
  while (e.hasMoreElements()) {
    DefaultMutableTreeNode child=(DefaultMutableTreeNode)e.nextElement();
    CodecStats childStats=getCodecStats(child);
    stats.children.put(childStats.name,childStats);
  }
  return stats;
}
 

Example 19

From project dawn-tango, under directory /org.dawb.tango.extensions/src/org/dawb/tango/extensions/editors/.

Source file: MultiScanComponent.java

  21 
vote

public void refresh(final String scanName){
  if (dataViewer != null && !dataViewer.getControl().isDisposed()) {
    final Object element=this.data.updateNode(scanName);
    this.dataViewer.refresh();
    if (element != null) {
      final TreeNode root=(TreeNode)dataViewer.getInput();
      for (int i=0; i < root.getChildCount(); i++) {
        final DefaultMutableTreeNode n=(DefaultMutableTreeNode)root.getChildAt(i);
        if (!n.getUserObject().equals(scanName)) {
          this.dataViewer.setChecked(n,false);
          this.dataViewer.setSubtreeChecked(n,false);
        }
      }
      this.dataViewer.setChecked(element,true);
      this.dataViewer.setExpandedElements(new Object[]{element});
      this.dataViewer.setSubtreeChecked(element,true);
      final List<AbstractDataset> selections=new IdentityList<AbstractDataset>();
      final TreeNode node=(TreeNode)element;
      for (int i=0; i < node.getChildCount(); i++) {
        selections.add((AbstractDataset)((DefaultMutableTreeNode)node.getChildAt(i)).getUserObject());
      }
      fireDatasetListeners(selections);
    }
  }
}
 

Example 20

From project harmony, under directory /phosphorus-gmpls/src/main/java/org/opennaas/extensions/gmpls/client/.

Source file: GmplsClient.java

  20 
vote

/** 
 * Initializes a JTree for navigation in the client.
 * @return javax.swing.JTree
 */
private JTree getJTree(){
  if (this.treeNavigation == null) {
    this.top=new DefaultMutableTreeNode("Elements");
    this.gmpls=new DefaultMutableTreeNode("GMPLS");
    this.createPathGmpls=new DefaultMutableTreeNode("create Path");
    this.gmpls.add(this.createPathGmpls);
    this.showPathGmpls=new DefaultMutableTreeNode("show/delete Paths");
    this.gmpls.add(this.showPathGmpls);
    this.top.add(this.gmpls);
    this.nspNavigation=new DefaultMutableTreeNode("NSP");
    this.createPathNSP=new DefaultMutableTreeNode("create Path");
    this.nspNavigation.add(this.createPathNSP);
    this.showPathNSP=new DefaultMutableTreeNode("show/delete Paths");
    this.nspNavigation.add(this.showPathNSP);
    this.top.add(this.nspNavigation);
    this.treeNavigation=new JTree(this.top);
    this.treeNavigation.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.treeNavigation.addTreeSelectionListener(this);
  }
  return this.treeNavigation;
}
 

Example 21

From project imageflow, under directory /src/de/danielsenff/imageflow/controller/.

Source file: BasicUnitXMLLoader.java

  19 
vote

/** 
 * Adds a XML unit to the unit tree and the menu.
 */
static void addUnitDelegate(final MutableTreeNode parentNode,final URL url){
  final boolean withinJar=url.getProtocol().equals("jar");
  final UnitDescription unitDescription=new UnitDescription(url);
  try {
    unitDescription.readXML();
    final UnitDelegate unitDelegate=new UnitDelegate(unitDescription,withinJar);
    if (DelegatesController.getInstance().getDelegate(unitDelegate.getName()) == null) {
      ((DefaultMutableTreeNode)parentNode).add(unitDelegate);
      unitDelegate.setParent(parentNode);
      DelegatesController.getInstance().addDelegate(unitDelegate);
    }
 else {
      for (int i=0; i < parentNode.getChildCount(); i++) {
        if (parentNode.getChildAt(i) instanceof UnitDelegate) {
          final UnitDelegate child=(UnitDelegate)parentNode.getChildAt(i);
          if (child.getName().equals(unitDelegate.getName())) {
            parentNode.remove(i);
            parentNode.insert(unitDelegate,i);
          }
        }
      }
      DelegatesController.getInstance().replaceDelegate(unitDelegate);
    }
  }
 catch (  JDOMException e) {
    String message="There has been a problem parsing a XML unit description." + '\n' + e.getMessage()+ '\n'+ "The program start will continue without this unit.";
    showErrorDialog("XML parsing error",message);
  }
catch (  IOException e) {
    String message="There has been a problem opening the xml definition for file " + url + "."+ '\n'+ "The program start will continue without this unit.";
    showErrorDialog("XML dataformat error",message);
  }
catch (  DataFormatException e) {
    String message="There has been a data format problem in a XML unit description." + '\n' + "The error ocures in "+ url+ "."+ '\n'+ "The program start will continue without this unit.";
    showErrorDialog("XML dataformat error",message);
  }
}
 

Example 22

From project ISAconfigurator, under directory /src/main/java/org/isatools/isacreatorconfigurator/ontologyconfigurationtool/.

Source file: SearchAndDefinitionUI.java

  19 
vote

public void notifyOfSelection(){
  if (viewTerm != null) {
    if (viewTerm.isShowing()) {
      viewTerm.setContent(((OntologyTreeItem)((DefaultMutableTreeNode)ontologyTree.getSelectionPath().getLastPathComponent()).getUserObject()).getBranch(),ontologyToQuery,getOntologyClient());
    }
  }
}