Java Code Examples for javax.swing.tree.MutableTreeNode

The following are top voted examples for showing how to use javax.swing.tree.MutableTreeNode. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: VASSAL-src   File: ServerStatusView.java   View source code 7 votes vote down vote up
private void refresh(DefaultTreeModel m,
                     ServerStatus.ModuleSummary[] modules) {
  final MutableTreeNode root = (MutableTreeNode) m.getRoot();
  totalPlayers = 0;

  while (root.getChildCount() > 0) {
    m.removeNodeFromParent((MutableTreeNode) root.getChildAt(0));
  }

  if (modules.length == 0) {
    final DefaultMutableTreeNode n = new DefaultMutableTreeNode(
      Resources.getString("Chat.no_connections")); //$NON-NLS-1$
    n.setAllowsChildren(false);
  }
  else {
    for (ServerStatus.ModuleSummary s : modules) {
      m.insertNodeInto(createNode(s), root, root.getChildCount());
    }
  }

  // append total number of players on server to root node
  root.setUserObject(
    Resources.getString(Resources.VASSAL) + " (" + totalPlayers + ")");
}
 
Example 2
Project: AgentWorkbench   File: ThreadInfoStorageTree.java   View source code 6 votes vote down vote up
/**
 * Sort nodes descending.
 *
 * @param node the node
 * @param treeModel the tree model
 */
private void sortNodesDescending(DefaultMutableTreeNode node, DefaultTreeModel treeModel) {
	boolean unsorted = true;

	while (unsorted) {
		unsorted = false;
		for (int i = 0; i < node.getChildCount() - 1; i++) {
			ThreadInfoStorageAgent tiaFirst = (ThreadInfoStorageAgent) ((DefaultMutableTreeNode) node.getChildAt(i)).getUserObject();
			ThreadInfoStorageAgent tiaSecond = (ThreadInfoStorageAgent) ((DefaultMutableTreeNode) node.getChildAt(i+1)).getUserObject();
			
			if (tiaFirst.getXYSeriesMap().get("TOTAL_CPU_SYSTEM_TIME").getMaxY() < tiaSecond.getXYSeriesMap().get("TOTAL_CPU_SYSTEM_TIME").getMaxY()) {
				treeModel.insertNodeInto((MutableTreeNode) node.getChildAt(i+1), node, i);
				unsorted = true;
			}
		}
	}
}
 
Example 3
Project: rapidminer   File: PlotConfigurationTreeModel.java   View source code 6 votes vote down vote up
private void rangeAxisConfigAdded(int index, RangeAxisConfig rangeAxis) {
	RangeAxisConfigTreeNode newChild = new RangeAxisConfigTreeNode(rangeAxis);
	insertNodeInto(newChild, (MutableTreeNode) root, index + NUMBER_OF_PERMANENT_DIMENSIONS);

	List<ValueSource> rangeAxisValueSources = rangeAxis.getValueSources();
	if (rangeAxis.getValueSources().size() > 0) {
		int idx = 0;
		// add new value source child nodes
		for (ValueSource source : rangeAxisValueSources) {
			valueSourceAdded(idx, source, rangeAxis);
			++idx;
		}
	} else {

		// change selection path
		TreePath pathToNewChild = new TreePath(getPathToRoot(newChild));
		makeVisibleAndSelect(pathToNewChild);

	}
}
 
Example 4
Project: rapidminer   File: PlotConfigurationTreeModel.java   View source code 6 votes vote down vote up
private void rangeAxisConfigRemoved(int index, RangeAxisConfig rangeAxis) {
	removeNodeFromParent((MutableTreeNode) root.getChildAt(index + NUMBER_OF_PERMANENT_DIMENSIONS));

	reload();
	plotConfigTree.expandAll();

	// Acquire new selection element
	int childCount = root.getChildCount();
	Object newSelection = null;

	if (childCount > NUMBER_OF_PERMANENT_DIMENSIONS) {
		newSelection = root.getChildAt(childCount - 1);
	} else {
		newSelection = root;
	}

	// change selection path
	TreePath path = new TreePath(getPathToRoot((TreeNode) newSelection));
	makeVisibleAndSelect(path);
}
 
Example 5
Project: call-IDE   File: Parser.java   View source code 6 votes vote down vote up
/**
 * A method to check whether the file has a main method in it or not
 * @param file a parameter to take the file to check
 * @return true if the file has a main method; false, if it hasn't
 */
public boolean hasMain( File file) {
    int index = getRow( file);
    if (index != -1) {
        MutableTreeNode node = ((MutableTreeNode) rootNode.getChildAt(index));
        if (node instanceof ClassNode) {
            for (int i = 0; i < ((ClassNode) node).getChildCount(); i++) {
                TreeNode treeNode = (((ClassNode) node).getChildAt(i));
                if (treeNode instanceof MethodNode) {
                    MethodDeclaration metDec = ((MethodNode) treeNode).metDec;
                    if (metDec.getNameAsString().equals("main") &&
                        metDec.isPublic() && metDec.isStatic()) {
                        ArrayList<Parameter> parameters = new ArrayList<Parameter>(metDec.getParameters());
                        if (parameters.size() == 1 && parameters.get(0).toString().startsWith("String[]"))
                            return true;
                    }
                }
            }
        }
    }
    return false;
}
 
Example 6
Project: ISO8583   File: SortTreeHelper.java   View source code 6 votes vote down vote up
public static void sort(DefaultMutableTreeNode parent) {
	int n = parent.getChildCount();
	for (int i = 0; i < n - 1; i++) {
		int min = i;
		for (int j = i + 1; j < n; j++) {
			if (tnc.compare((DefaultMutableTreeNode) parent.getChildAt(min), (DefaultMutableTreeNode) parent.getChildAt(j)) > 0) {
				min = j;
			}
		}
		if (i != min) {
			MutableTreeNode a = (MutableTreeNode) parent.getChildAt(i);
			MutableTreeNode b = (MutableTreeNode) parent.getChildAt(min);
			parent.insert(b, i);
			parent.insert(a, min);
			
			updateTree = true;
		}
	}
}
 
Example 7
Project: JavaGraph   File: DisplayTreeNode.java   View source code 6 votes vote down vote up
/**
 * Insert child node using a sorting based on the name of the child node (toString)
 * Uses a natural ordering sort
 * @param child Child node to insert.
 */
public void insertSorted(MutableTreeNode child) {
    Comparator<TreeNode> comparator = this.comparator;
    // binary search for the right position to insert
    int lower = 0;
    int upper = getChildCount();
    while (lower < upper) {
        int mid = (lower + upper) / 2;
        TreeNode midChild = getChildAt(mid);
        if (comparator.compare(child, midChild) < 0) {
            upper = mid;
        } else {
            lower = mid + 1;
        }
    }
    insert(child, lower);
}
 
Example 8
Project: Equella   File: BrowseFinder.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void insertInOrder(MutableTreeNode newChild)
{
	if( !Check.isEmpty(children) )
	{
		List<MutableTreeNode> mtns = new ArrayList<MutableTreeNode>(children);
		mtns.add(newChild);
		Collections.sort(mtns, new NumberStringComparator<MutableTreeNode>());

		removeAllChildren();
		for( MutableTreeNode mtn : mtns )
		{
			add(mtn);
		}
	}
	else
	{
		add(newChild);
	}
}
 
Example 9
Project: ISO8583   File: SortTreeHelper.java   View source code 6 votes vote down vote up
public static void sort(DefaultMutableTreeNode parent) {
	int n = parent.getChildCount();
	for (int i = 0; i < n - 1; i++) {
		int min = i;
		for (int j = i + 1; j < n; j++) {
			if (tnc.compare((DefaultMutableTreeNode) parent.getChildAt(min), (DefaultMutableTreeNode) parent.getChildAt(j)) > 0) {
				min = j;
			}
		}
		if (i != min) {
			MutableTreeNode a = (MutableTreeNode) parent.getChildAt(i);
			MutableTreeNode b = (MutableTreeNode) parent.getChildAt(min);
			parent.insert(b, i);
			parent.insert(a, min);
			
			updateTree = true;
		}
	}
}
 
Example 10
Project: spmf   File: ShowTrie.java   View source code 6 votes vote down vote up
/**
 * Method to display graphically the Trie by means of a TreeModel
 * @param model TreeModel when we want to insert the Trie nodes
 * @param p TreeNode for the TreeModel
 */
private static void display(Trie frequentAtomsTrie, DefaultTreeModel model, MutableTreeNode p) {
	List<TrieNode> nodes = frequentAtomsTrie.nodes;
    if (nodes != null) {
        //For each node
        for (int i = 0; i < nodes.size(); i++) {
            TrieNode node = nodes.get(i);
            Trie child = node.getChild();

            //We create a new TreeNode composed of the pair and the list of appearances
            DefaultMutableTreeNode currentNode = new DefaultMutableTreeNode(node.getPair().toString()+" ("+child.getSupport()+")");
            //And we insert it in the TreeModel
            model.insertNodeInto(currentNode, p, i);
            //And we go on doing the same process with the child
            j++;
            if(j <3) {
            	display(child, model, currentNode);
            }
            j--;
        }
    }
}
 
Example 11
Project: spmf   File: Trie.java   View source code 6 votes vote down vote up
/**
 * Method to display graphically the Trie by means of a TreeModel
 * @param model TreeModel when we want to insert the Trie nodes
 * @param p TreeNode for the TreeModel
 */
private void display(DefaultTreeModel model, MutableTreeNode p) {

    if (nodes != null) {
        //For each node
        for (int i = 0; i < nodes.size(); i++) {
            TrieNode node = nodes.get(i);
            Trie child = node.getChild();

            //We create a new TreeNode composed of the pair and the list of appearances
            DefaultMutableTreeNode currentNode = new DefaultMutableTreeNode(node.getPair().toString() + child.appearingIn);
            //And we insert it in the TreeModel
            model.insertNodeInto(currentNode, p, i);
            //And we go on doing the same process with the child
            child.display(model, currentNode);
        }
    }
}
 
Example 12
Project: XM-Miner   File: ServerDirectoryTreeModel.java   View source code 6 votes vote down vote up
public ServerDirectoryTreeModel (MutableTreeNode root, DirectoryType[] dList)
       {
               super(root);
               int currentIndex = 0;
               dirList = dList;
/*
  System.out.println("create directory list .................");
  for (int i=0; i<dList.length; i++) {
	  System.out.print("[ " + i + " ] " + dList[i].nodeName);
	  for (int j=0; j<dList[i].childnodeNames.length; j++)
	  	System.out.print(":" + dList[i].childnodeNames[j]);
	  System.out.println("");
  }
*/
               for (int i=0; i<dirList[0].childnodeNames.length; i++) {
                 currentIndex = addNewNode(root, dirList[0].childnodeNames[i], currentIndex);
               }
       }
 
Example 13
Project: taxonaut   File: UnitedNameTreeNode.java   View source code 6 votes vote down vote up
public void insert(MutableTreeNode newChild, int childIndex)
   {
if(newChild == null)
    return;

if(mappedNodes == null) {
    mappedNodes = createNodeMap();
}
else if(mappedNodes.indexOf(newChild) != -1)
    return;

super.insert(newChild, childIndex);

if (newChild instanceof NameTreeNode)
    mappedNodes.add((NameTreeNode)newChild);
   }
 
Example 14
Project: taxonaut   File: AbstractNameTreeNode.java   View source code 6 votes vote down vote up
public void setParent(MutableTreeNode newParent)
   {
super.setParent(newParent);
setToolTipText(null);
if(isLeaf())
    return;

Enumeration<?> descendants = breadthFirstEnumeration();
while(descendants.hasMoreElements()) {
    MutableTreeNode descendant = 
	(MutableTreeNode)descendants.nextElement();
    if(descendant instanceof AbstractNameTreeNode) {
	((AbstractNameTreeNode<?>)descendant).setToolTipText(null);
    }
}
   }
 
Example 15
Project: taxonaut   File: UnitedNameTreeModel.java   View source code 6 votes vote down vote up
protected void removeAllChildren(MutableTreeNode parentNode,
			     DefaultTreeModel tree)
   {
Enumeration<?> enm = parentNode.children();
MutableTreeNode[] toRemove =
    new MutableTreeNode[parentNode.getChildCount()];

int i = 0;
while(enm.hasMoreElements()) {
    toRemove[i++] =
	(MutableTreeNode)enm.nextElement();
}
for(i = 0; i < toRemove.length; i++) {
	tree.removeNodeFromParent(toRemove[i]);
	toRemove[i] = null;
}
toRemove = null;
   }
 
Example 16
Project: tda   File: SunJDKParser.java   View source code 6 votes vote down vote up
private boolean checkForDuplicateThreadItem(Map directChildMap, DefaultMutableTreeNode node1) {
    ThreadInfo mi1 = (ThreadInfo) node1.getUserObject();
    String name1 = mi1.getName();

    for (Iterator iter2 = directChildMap.entrySet().iterator(); iter2.hasNext();) {
        DefaultMutableTreeNode node2 = (DefaultMutableTreeNode) ((Map.Entry) iter2.next()).getValue();
        if (node1 == node2) {
            continue;
        }

        ThreadInfo mi2 = (ThreadInfo) node2.getUserObject();
        if (name1.equals(mi2.getName()) && node2.getChildCount() > 0) {
            node1.add((MutableTreeNode) node2.getFirstChild());
            iter2.remove();
            return true;
        }
    }

    return false;
}
 
Example 17
Project: BlocktopographPC-GUI   File: NBTNode.java   View source code 6 votes vote down vote up
@Override
public void remove(MutableTreeNode removedNode) {
    if (removedNode instanceof NBTNode) {
        Tag removedTag = ((NBTNode) removedNode).getTag();

        switch (selfTag.getType()) {
            case COMPOUND:
                ((CompoundTag) selfTag).getValue().remove(removedTag);
                break;
            case LIST:
                ((ListTag) selfTag).getValue().remove(removedTag);
                break;
        }
    }

    super.remove(removedNode);
}
 
Example 18
Project: SporeModder   File: TreeNode.java   View source code 6 votes vote down vote up
@Override
public MutableTreeNode fillHierarchyTree(DefaultTreeModel model, MutableTreeNode parent, int index) {
	super.fillHierarchyTree(model, parent, index);
	
	if (!childrenNodes.isEmpty()) {
		int ind = 0;
		
		for (int i = 0; i < childrenNodes.size(); i++) {
			if (childrenNodes.get(i) != null) {
				childrenNodes.get(i).fillHierarchyTree(model, node, ind++);
			}
		}
	}
	
	return node;
}
 
Example 19
Project: SporeModder   File: Window.java   View source code 6 votes vote down vote up
@Override
public MutableTreeNode fillHierarchyTree(DefaultTreeModel model, MutableTreeNode parent, int index) {
	if (isLayoutWindow) {
		node = new DefaultMutableTreeNode(this);
		model.setRoot(node);
	}
	else {
		super.fillHierarchyTree(model, parent, index);
	}
	
	int ind = 0;
	
	for (int i = 0; i < modifiers.size(); i++) {
		if (modifiers.get(i) != null) {
			modifiers.get(i).fillHierarchyTree(model, node, ind++);
		}
	}
	
	for (int i = 0; i < children.size(); i++) {
		if (children.get(i) != null) {
			children.get(i).fillHierarchyTree(model, node, ind++);
		}
	}
	
	return node;
}
 
Example 20
Project: SporeModder   File: WinTreeView.java   View source code 6 votes vote down vote up
@Override
public MutableTreeNode fillHierarchyTree(DefaultTreeModel model, MutableTreeNode parent, int index) {
	super.fillHierarchyTree(model, parent, index);
	
	if (!childrenNodes.isEmpty()) {
		int ind = 0;
		
		for (int i = 0; i < childrenNodes.size(); i++) {
			if (childrenNodes.get(i) != null) {
				childrenNodes.get(i).fillHierarchyTree(model, node, ind++);
			}
		}
	}
	
	return node;
}
 
Example 21
Project: rapidminer-studio   File: PlotConfigurationTreeModel.java   View source code 6 votes vote down vote up
private void rangeAxisConfigAdded(int index, RangeAxisConfig rangeAxis) {
	RangeAxisConfigTreeNode newChild = new RangeAxisConfigTreeNode(rangeAxis);
	insertNodeInto(newChild, (MutableTreeNode) root, index + NUMBER_OF_PERMANENT_DIMENSIONS);

	List<ValueSource> rangeAxisValueSources = rangeAxis.getValueSources();
	if (rangeAxis.getValueSources().size() > 0) {
		int idx = 0;
		// add new value source child nodes
		for (ValueSource source : rangeAxisValueSources) {
			valueSourceAdded(idx, source, rangeAxis);
			++idx;
		}
	} else {

		// change selection path
		TreePath pathToNewChild = new TreePath(getPathToRoot(newChild));
		makeVisibleAndSelect(pathToNewChild);

	}
}
 
Example 22
Project: rapidminer-studio   File: PlotConfigurationTreeModel.java   View source code 6 votes vote down vote up
private void rangeAxisConfigRemoved(int index, RangeAxisConfig rangeAxis) {
	removeNodeFromParent((MutableTreeNode) root.getChildAt(index + NUMBER_OF_PERMANENT_DIMENSIONS));

	reload();
	plotConfigTree.expandAll();

	// Acquire new selection element
	int childCount = root.getChildCount();
	Object newSelection = null;

	if (childCount > NUMBER_OF_PERMANENT_DIMENSIONS) {
		newSelection = root.getChildAt(childCount - 1);
	} else {
		newSelection = root;
	}

	// change selection path
	TreePath path = new TreePath(getPathToRoot((TreeNode) newSelection));
	makeVisibleAndSelect(path);
}
 
Example 23
Project: tinyMediaManager   File: TvShowSeasonTreeNode.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void insert(MutableTreeNode newChild, int childIndex) {
  if (this.children != null) {
    int index = Collections.binarySearch(this.children, newChild, nodeComparator);
    if (index < 0) {
      super.insert(newChild, -index - 1);
    }
    else if (index >= 0) {
      super.insert(newChild, index);
    }
  }
  else {
    super.insert(newChild, childIndex);
  }
}
 
Example 24
Project: ultimate-pastebin-intellij-plugin   File: PasteNodeUtil.java   View source code 6 votes vote down vote up
/**
 * <p>Creates a {@link MutableTreeNode} representing a {@link Paste} and its infos, wrapping the data in {@link PasteNode} and {@link PasteInfoNode}</p>
 *
 * @param paste The {@link Paste} used to create the nodes.
 * @return a {@link MutableTreeNode} with the info.
 */
public static MutableTreeNode createNodeForPaste(Paste paste) {
  Objects.requireNonNull(paste);

  final DefaultMutableTreeNode pasteNode = new DefaultMutableTreeNode(new PasteNode(paste));

  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.key", paste.getKey()))));
  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.url", paste.getUrl()))));
  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.visibility", paste.getVisibility().name()))));
  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.createddate", formatDateTime(paste.getLocalPasteDate())))));
  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.expiration", paste.getExpiration().name()))));
  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.expirationdate", paste.getExpiration() == NEVER ? getMessage("ultimatepastebin.paste.expiration.never") : formatDateTime(paste.getLocalExpirationDate())))));
  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.views", paste.getHits()))));
  pasteNode.add(new DefaultMutableTreeNode(new PasteInfoNode(getMessage("ultimatepastebin.paste.highlight", paste.getHighLight().name()))));

  return pasteNode;
}
 
Example 25
Project: ultimate-pastebin-intellij-plugin   File: PasteTreeRenderer.java   View source code 6 votes vote down vote up
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
  Component component = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);

  if (component instanceof WrappingIconPanel && value instanceof MutableTreeNode) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;

    // When is the root, i return, because there is no need
    // to do anything, the root isn't being shown anyway
    if (node.isRoot())
      return component;

    updateIcon((WrappingIconPanel) component, node);
  }

  return component;
}
 
Example 26
Project: bigtable-sql   File: HelpViewerWindow.java   View source code 6 votes vote down vote up
public void add(MutableTreeNode node)
{
	super.add(node);
	if (node instanceof DocumentNode)
	{
		final DocumentNode dn = (DocumentNode) node;
		final URL docURL = dn.getURL();
		if (docURL != null)
		{
			String docTitle = dn.toString();
			if (StringUtils.isEmpty(docTitle))
			{
				docTitle = docURL.toExternalForm();
			}
			_docTitles.add(docTitle);
			_docURLs.add(docURL);
		}
	}
}
 
Example 27
Project: thread-dump-analysis   File: SunJDKParser.java   View source code 6 votes vote down vote up
private boolean checkForDuplicateThreadItem(Map directChildMap, DefaultMutableTreeNode node1) {
    ThreadInfo mi1 = (ThreadInfo) node1.getUserObject();
    String name1 = mi1.getName();

    for (Iterator iter2 = directChildMap.entrySet().iterator(); iter2.hasNext();) {
        DefaultMutableTreeNode node2 = (DefaultMutableTreeNode) ((Map.Entry) iter2.next()).getValue();
        if (node1 == node2) {
            continue;
        }

        ThreadInfo mi2 = (ThreadInfo) node2.getUserObject();
        if (name1.equals(mi2.getName()) && node2.getChildCount() > 0) {
            node1.add((MutableTreeNode) node2.getFirstChild());
            iter2.remove();
            return true;
        }
    }

    return false;
}
 
Example 28
Project: swingx   File: PainterDemo.java   View source code 6 votes vote down vote up
private MutableTreeNode createGlossPainterDemos() {
    DefaultMutableTreeNode node = createInfoNode("Gloss Painter Demos",
            null);

    RectanglePainter rp = new RectanglePainter(20, 20, 20,
            20, 20, 20);
    rp.setFillPaint(Color.RED);
    rp.setBorderPaint(Color.RED.darker());
    rp.setStyle(RectanglePainter.Style.BOTH);
    rp.setBorderWidth(5);
    rp.setAntialiasing(true);
    CompoundPainter<Object> cp = new CompoundPainter<Object>(rp, new GlossPainter());
    node.add(createInfoNode("Gloss on top of rectangle", cp));

    rp = new RectanglePainter(20, 20, 20, 20, 20, 20, true,
            Color.RED, 5f, Color.RED.darker());
    rp.setAntialiasing(true);
    cp = new CompoundPainter<Object>(rp, new GlossPainter(GlossPosition.BOTTOM));
    node.add(createInfoNode("Gloss on bottom of rectangle", cp));

    return node;
}
 
Example 29
Project: incubator-taverna-engine   File: AbstractIterationStrategyNode.java   View source code 6 votes vote down vote up
@Override
public synchronized void insert(MutableTreeNode child, int index) {
	if (!getAllowsChildren())
		throw new IllegalStateException("Node does not allow children");
	if (!(child instanceof IterationStrategyNode))
		throw new IllegalArgumentException(
				"Child not an instance of IterationStrategyNode: " + child);
	if (child == this)
		throw new IllegalArgumentException("Can't be it's own parent");

	// Check if it is already there (in case we'll just move it)
	int alreadyExistsIndex = children.indexOf(child);

	children.add(index, (IterationStrategyNode) child);

	if (alreadyExistsIndex > -1) {
		// Remove it from the old position
		if (index < alreadyExistsIndex
				&& alreadyExistsIndex + 1 < children.size())
			alreadyExistsIndex++;
		children.remove(alreadyExistsIndex);
	}
	if (child.getParent() != this)
		child.setParent(this);
}
 
Example 30
Project: mindraider   File: TrashJPanel.java   View source code 6 votes vote down vote up
/**
 * 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;
        }
    }

    // Either there was no selection, or the root was selected.
    toolkit.beep();
}
 
Example 31
Project: aibench-project   File: ClassBrowser.java   View source code 6 votes vote down vote up
MutableTreeNode makeNode(Map map, String nodeName) {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode(nodeName);
        Iterator it = map.keySet().iterator();
        while (it.hasNext()) {
                String name = (String) it.next();
                Map val = (Map) map.get(name);
                if (val.size() == 0) {
                        DefaultMutableTreeNode leaf = new DefaultMutableTreeNode(name);
                        root.add(leaf);
                } else {
                        MutableTreeNode node = makeNode(val, name);
                        root.add(node);
                }
        }
        return root;
}
 
Example 32
Project: HTML5_WebSite   File: ChartTree.java   View source code 6 votes vote down vote up
private MutableTreeNode createGanttChartsNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(
        "Gantt Charts"
    );

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
        new DemoDescription("edu.ucla.stat.SOCR.chart.demo.GanttDemo1", "GanttDemo1")
    );
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
        new DemoDescription("edu.ucla.stat.SOCR.chart.demo.GanttDemo2", "GanttDemo2")
    );
    
    root.add(n1);
    root.add(n2);
    
    return root;
}
 
Example 33
Project: HTML5_WebSite   File: ChartTree.java   View source code 6 votes vote down vote up
private MutableTreeNode createCrosshairChartsNode() {
      DefaultMutableTreeNode root = new DefaultMutableTreeNode("Crosshairs");

      DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
              new DemoDescription("edu.ucla.stat.SOCR.chart.demo.CrosshairDemo1", 
              "CrosshairDemo1"));
      DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
              new DemoDescription("edu.ucla.stat.SOCR.chart.demo.CrosshairDemo2", 
              "CrosshairDemo2"));
      DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(
              new DemoDescription("edu.ucla.stat.SOCR.chart.demo.CrosshairDemo3", 
              "CrosshairDemo3"));
      DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
              new DemoDescription("edu.ucla.stat.SOCR.chart.demo.CrosshairDemo4", 
              "CrosshairDemo4"));
      
      root.add(n1);
//        root.add(n2);
      root.add(n3);
      root.add(n4);
      
      return root;
  }
 
Example 34
Project: tinyMediaManager   File: TvShowRootTreeNode.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public synchronized void insert(MutableTreeNode newChild, int childIndex) {
  if (this.children != null) {
    int index = Collections.binarySearch(this.children, newChild, nodeComparator);
    if (index < 0) {
      super.insert(newChild, -index - 1);
    }
    else if (index >= 0) {
      super.insert(newChild, index);
    }
  }
  else {
    super.insert(newChild, childIndex);
  }
}
 
Example 35
Project: HTML5_WebSite   File: ChartTree.java   View source code 6 votes vote down vote up
private MutableTreeNode createMarkersNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("Markers");
    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
        new DemoDescription("edu.ucla.stat.SOCR.chart.demo.CategoryMarkerDemo1", 
        "CategoryMarkerDemo1"));
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
        new DemoDescription("edu.ucla.stat.SOCR.chart.demo.CategoryMarkerDemo2", 
        "CategoryMarkerDemo2"));
    DefaultMutableTreeNode n3 = new DefaultMutableTreeNode(
        new DemoDescription("edu.ucla.stat.SOCR.chart.demo.MarkerDemo1", "MarkerDemo1"));
    DefaultMutableTreeNode n4 = new DefaultMutableTreeNode(
        new DemoDescription("edu.ucla.stat.SOCR.chart.demo.MarkerDemo2", "MarkerDemo2"));
    root.add(n1);
    root.add(n2);
    root.add(n3);
    root.add(n4);
    return root;
}
 
Example 36
Project: HTML5_WebSite   File: ChartTree.java   View source code 6 votes vote down vote up
private MutableTreeNode createOrientationNode() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode(
        "Plot Orientation"
    );

    DefaultMutableTreeNode n1 = new DefaultMutableTreeNode(
        new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.PlotOrientationDemo1", "PlotOrientationDemo1"
        )
    );
    DefaultMutableTreeNode n2 = new DefaultMutableTreeNode(
        new DemoDescription(
            "edu.ucla.stat.SOCR.chart.demo.PlotOrientationDemo2", "PlotOrientationDemo2"
        )
    );
   
    root.add(n1);
    root.add(n2);
    
    return root;
}
 
Example 37
Project: tinyMediaManager   File: TvShowTreeNode.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void insert(MutableTreeNode newChild, int childIndex) {
  if (this.children != null) {
    int index = Collections.binarySearch(this.children, newChild, nodeComparator);
    if (index < 0) {
      super.insert(newChild, -index - 1);
    }
    else if (index >= 0) {
      super.insert(newChild, index);
    }
  }
  else {
    super.insert(newChild, childIndex);
  }
}
 
Example 38
Project: incubator-netbeans   File: HintsPanel.java   View source code 5 votes vote down vote up
public HintMetadata getSelectedHint() {
        TreePath selectionPath = errorTree.getSelectionModel().getSelectionPath();
        if (selectionPath==null) {
            return null;
}
        DefaultMutableTreeNode lastPathComponent = (DefaultMutableTreeNode) (MutableTreeNode) (TreeNode) selectionPath.getLastPathComponent();
        if (lastPathComponent!= null && lastPathComponent.getUserObject() instanceof HintMetadata)
            return (HintMetadata) lastPathComponent.getUserObject();
        return null;
    }
 
Example 39
Project: incubator-netbeans   File: PathsCustomizer.java   View source code 5 votes vote down vote up
@Override
public void intervalAdded(ListDataEvent e) {
    for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
        Object obj = listModel.getElementAt(i);
        if (obj instanceof ClassPathSupport.Item) {
            DefaultMutableTreeNode node = toTreeNode(obj);
            treeModel.insertNodeInto(node, (MutableTreeNode)treeModel.getRoot(), e.getIndex0());
            TreePath path = new TreePath(node.getPath());
            tree.setSelectionPath(path);
            tree.makeVisible(path);
        }
    }
}
 
Example 40
Project: incubator-netbeans   File: PathsCustomizer.java   View source code 5 votes vote down vote up
@Override
public void intervalAdded(ListDataEvent e) {
    for (int i = e.getIndex1(); i >= e.getIndex0(); i--) {
        Object obj = listModel.getElementAt(i);
        if (obj instanceof ClassPathSupport.Item) {
            DefaultMutableTreeNode node = toTreeNode(obj);
            treeModel.insertNodeInto(node, (MutableTreeNode)treeModel.getRoot(), e.getIndex0());
            TreePath path = new TreePath(node.getPath());
            tree.setSelectionPath(path);
            tree.makeVisible(path);
        }
    }
}