Java Code Examples for javax.swing.tree.DefaultTreeModel#setRoot()

The following examples show how to use javax.swing.tree.DefaultTreeModel#setRoot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ComponentSelector.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
public void setLogModel(Model value) {
	this.logModel = value;

	DefaultTreeModel model = (DefaultTreeModel) getModel();
	CircuitNode curRoot = (CircuitNode) model.getRoot();
	CircuitState state = logModel == null ? null : logModel.getCircuitState();
	if (state == null) {
		if (curRoot != null)
			model.setRoot(null);
		return;
	}
	if (curRoot == null || curRoot.circuitState != state) {
		curRoot = new CircuitNode(null, state, null);
		model.setRoot(curRoot);
	}
}
 
Example 2
Source File: ViewerJTree.java    From megan-ce with GNU General Public License v3.0 6 votes vote down vote up
/**
 * rescan the jtree
 */
public void update() {
    if (classificationViewer.getTree().getNumberOfNodes() > 1) {
        removeAll();
        id2node.clear();
        inducedTree.clear();
        id2NodesInInducedTree.clear();
        if (classificationViewer.getDocument().getNumberOfReads() > 0)
            classificationViewer.computeInduceTreeWithNoCollapsedNodes(inducedTree, id2NodesInInducedTree);

        final Node root = classificationViewer.getClassification().getFullTree().getRoot();
        final int id = (Integer) root.getInfo();
        final MyJTreeNode node = new MyJTreeNode(root);
        final DefaultTreeModel model = (DefaultTreeModel) getModel();
        model.setRoot(node);
        id2node.put(id, node);
        setRootVisible(true);
        setShowsRootHandles(true);
        addChildren(node);
    }
}
 
Example 3
Source File: AsposeExamplePanel.java    From Aspose.OCR-for-Java with MIT License 6 votes vote down vote up
private void retrieveAPIExamples() {
    final String item = (String) getComponentSelection().getSelectedItem();
    CustomMutableTreeNode top = new CustomMutableTreeNode("");
    DefaultTreeModel model = (DefaultTreeModel) getExamplesTree().getModel();
    model.setRoot(top);
    model.reload(top);
    if (item != null && !item.equals(AsposeConstants.API_DEPENDENCY_NOT_FOUND)) {

        AsposeExampleCallback callback = new AsposeExampleCallback(this, top);
        final ModalTaskImpl modalTask = new ModalTaskImpl(AsposeMavenProjectManager.getInstance().getProjectHandle(), callback, "Please wait...");
        ProgressManager.getInstance().run(modalTask);
        top.setTopTreeNodeText(AsposeConstants.API_NAME);
        model.setRoot(top);
        model.reload(top);
        getExamplesTree().expandPath(new TreePath(top.getPath()));

    }

}
 
Example 4
Source File: NavigatorContent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private TreeModel createTreeModel(DocumentModel dm) {
    DocumentElement rootElement = dm.getRootElement();
    DefaultTreeModel dtm = new DefaultTreeModel(null);
    TreeNodeAdapter rootTna = new TreeNodeAdapter(rootElement, dtm, tree, null);
    dtm.setRoot(rootTna);
    
    return dtm;
}
 
Example 5
Source File: CatalogTree.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public void setNewRootDatasets(List<InvDataset> rootDatasets) {
    final DefaultTreeModel model = (DefaultTreeModel) jTree.getModel();
    final DefaultMutableTreeNode rootNode = CatalogTreeUtils.createRootNode();
    model.setRoot(rootNode);
    appendToNode(jTree, rootDatasets, rootNode, true);
    fireCatalogElementsInsertionFinished();
    expandPath(rootNode);
    leafToParentNode.clear();
}
 
Example 6
Source File: CFunctionSelectionTree.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new function selection tree.
 *
 * @param database The database where the functions come from.
 * @param actionProvider Provides the implementations of the available actions.
 */
public CFunctionSelectionTree(final IDatabase database, final IActionProvider actionProvider) {
  Preconditions.checkNotNull(database, "IE01575: Database argument can not be null");

  Preconditions.checkNotNull(actionProvider, "IE01576: Action provider argument can not be null");

  final DefaultTreeModel model = new DefaultTreeModel(null);
  setModel(model);

  setRootVisible(false);

  // Set the root node of the tree.
  model.setRoot(new CRootNode(database, model, actionProvider));

  // Each node has its own custom icon.
  setCellRenderer(new IconNodeRenderer());

  addMouseListener(new InternalMouseListener());
}
 
Example 7
Source File: CViewSelectionTree.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new view selection tree.
 *
 * @param dialog Parent window used for dialogs.
 * @param container The container that provides the views to select from.
 */
public CViewSelectionTree(final Window dialog, final IViewContainer container)
{
	final DefaultTreeModel model = new DefaultTreeModel(null);
	setModel(model);

	setRootVisible(false);

	// Set the root node of the tree.
	model.setRoot(new CRootNode(dialog, container, model));

	Preconditions.checkNotNull(container, "IE01826: Container argument can not be null");

	setRootVisible(false);

	setCellRenderer(new IconNodeRenderer()); // ATTENTION: UNDER NO CIRCUMSTANCES MOVE THIS LINE ABOVE THE SETROOT LINE

	addMouseListener(new InternalMouseListener());
}
 
Example 8
Source File: BlazerUIView.java    From blazer with GNU General Public License v3.0 4 votes vote down vote up
private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed

        //Discover JARs, Java, Class files recursively in all directories
        List<File> allLibs = new ArrayList<File>();

        File[] selectedFiles = jFileChooser1.getSelectedFiles();

        if (selectedFiles != null && selectedFiles.length > 1) {
            for (int i = 0; i < selectedFiles.length; i++) {
                JavaUtil.findAllLibs(selectedFiles[i], allLibs);
            }
        } else {
            File selectedFile = jFileChooser1.getSelectedFile();
            if (selectedFile != null) {
                JavaUtil.findAllLibs(selectedFile, allLibs);
            }
        }

        //Import resources in Blazer
        Iterator allListIt = allLibs.iterator();
        while (allListIt.hasNext()) {
            File resFile = (File) allListIt.next();
            manager.getTask().setLibraries(resFile);
        }

        //Display resources in Blazer
        jTree4.setModel(null);
        DefaultTreeModel myModel = new DefaultTreeModel(null);
        DefaultMutableTreeNode treeNodeRoot = new DefaultMutableTreeNode("");
        myModel.setRoot(treeNodeRoot);

        Iterator listRes = manager.getTask().getLibraries().iterator();
        if (listRes.hasNext()) {
            while (listRes.hasNext()) {
                File itemRes = (File) listRes.next();
                try {
                    //Display files
                    treeNodeRoot.add(new DefaultMutableTreeNode(itemRes.getCanonicalPath()));
                } catch (IOException iex) {
                    manager.getStdErr().println("[!] LoadTreeNode IOException: " + iex.toString().trim());
                }
            }
            myModel.setRoot(treeNodeRoot);
            jTree4.setModel(myModel);
        }
}