javax.swing.tree.TreeModel Java Examples

The following examples show how to use javax.swing.tree.TreeModel. 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: LastNodeLowerHalfDrop.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected static TreeModel getTreeModel() {
    root = new DefaultMutableTreeNode("Root");

    a = new DefaultMutableTreeNode("A");
    root.add(a);
    a1 = new DefaultMutableTreeNode("a1");
    a.add(a1);

    b = new DefaultMutableTreeNode("B");
    root.add(b);
    b1 = new DefaultMutableTreeNode("b1");
    b.add(b1);
    b2 = new DefaultMutableTreeNode("b2");
    b.add(b2);

    c = new DefaultMutableTreeNode("C");
    root.add(c);
    c1 = new DefaultMutableTreeNode("c1");
    c.add(c1);
    return new DefaultTreeModel(root);
}
 
Example #2
Source File: TreeState.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void applySelectedTo(@Nonnull JTree tree) {
  List<TreePath> selection = new ArrayList<>();
  for (List<PathElement> path : mySelectedPaths) {
    TreeModel model = tree.getModel();
    TreePath treePath = new TreePath(model.getRoot());
    for (int i = 1; treePath != null && i < path.size(); i++) {
      treePath = findMatchedChild(model, treePath, path.get(i));
    }
    ContainerUtil.addIfNotNull(selection, treePath);
  }
  if (selection.isEmpty()) return;
  tree.setSelectionPaths(selection.toArray(TreeUtil.EMPTY_TREE_PATH));
  if (myScrollToSelection) {
    TreeUtil.showRowCentered(tree, tree.getRowForPath(selection.get(0)), true, true);
  }
}
 
Example #3
Source File: TreeExpandCollapse.java    From consulo with Apache License 2.0 6 votes vote down vote up
public int expand(JTree tree, TreePath path) {
  if (myLevelsLeft == 0) return myExpansionLimit;
  TreeModel model = tree.getModel();
  Object node = path.getLastPathComponent();
  int levelDecrement = 0;
  if (!tree.isExpanded(path) && !model.isLeaf(node)) {
    tree.expandPath(path);
    levelDecrement = 1;
    myExpansionLimit--;
  }
  for (int i = 0; i < model.getChildCount(node); i++) {
    Object child = model.getChild(node, i);
    if (model.isLeaf(child)) continue;
    ExpandContext childContext = new ExpandContext(myExpansionLimit, myLevelsLeft - levelDecrement);
    myExpansionLimit = childContext.expand(tree, path.pathByAddingChild(child));
    if (myExpansionLimit <= 0) return 0;
  }
  return myExpansionLimit;
}
 
Example #4
Source File: ProfilerTreeTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void expandPlainPath(int row, int maxChildren) {
    if (tree != null) try {
        markExpansionTransaction();
        
        TreePath tpath = tree.getPathForRow(row);
        if (tpath == null) return;
        
        TreeModel tmodel = tree.getModel();            
        int childCount = tmodel.getChildCount(tpath.getLastPathComponent());
    
        while (childCount > 0 && childCount <= maxChildren) {
            tpath = tpath.pathByAddingChild(tmodel.getChild(tpath.getLastPathComponent(), 0));
            childCount = tmodel.getChildCount(tpath.getLastPathComponent());
        }

        tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, Boolean.TRUE);
        try { tree.expandPath(tpath); selectPath(tpath, true); }
        finally { tree.putClientProperty(UIUtils.PROP_AUTO_EXPANDING, null); }
        
    } finally {
        clearExpansionTransaction();
    }
}
 
Example #5
Source File: FileTree.java    From stendhal with GNU General Public License v2.0 6 votes vote down vote up
public FileTree(final String path) throws FileNotFoundException {
	// Create the JTree itself
	super((TreeModel) null);

	// Use horizontal and vertical lines
	putClientProperty("JTree.lineStyle", "Angled");

	// Create the first node
	final FileTreeNode rootNode = new FileTreeNode(null, path);

	// Populate the root node with its subdirectories
	rootNode.populateDirectories(true);
	setModel(new DefaultTreeModel(rootNode));

	// Listen for Tree Selection Events
	addTreeExpansionListener(new TreeExpansionHandler());
}
 
Example #6
Source File: NodeFileOrFolder.java    From netbeans-mmd-plugin with Apache License 2.0 6 votes vote down vote up
void fireNotifySubtreeChanged(@Nonnull TreeModel model, @Nonnull @MustNotContainNull final List<TreeModelListener> listeners) {
  if (this.parent != null && this.folderFlag) {
    final Object[] childrenObject = new Object[children.size()];
    final int[] indexes = new int[children.size()];
    for (int i = 0; i < this.children.size(); i++) {
      final NodeFileOrFolder c = this.children.get(i);
      childrenObject[i] = c;
      indexes[i] = i;
      c.fireNotifySubtreeChanged(model, listeners);
    }
    final TreeModelEvent event = new TreeModelEvent(model, this.parent.makeTreePath(), indexes, childrenObject);
    for (final TreeModelListener l : listeners) {
      l.treeStructureChanged(event);
    }
  }
}
 
Example #7
Source File: GltfBrowserPanel.java    From JglTF with MIT License 6 votes vote down vote up
/**
 * Translates one TreePath to a new TreeModel. This methods assumes 
 * DefaultMutableTreeNodes, and identifies the path based on the
 * user objects.
 * 
 * This method is similar to 
 * {@link de.javagl.common.ui.JTrees#translatePath(TreeModel, TreePath)},
 * but returns a "partial" path if the new tree model only contains a
 * subset of the given path.
 * 
 * @param newTreeModel The new tree model
 * @param oldPath The old tree path
 * @return The new tree path
 */
private static TreePath translatePathPartial(
    TreeModel newTreeModel, TreePath oldPath)
{
    Object newRoot = newTreeModel.getRoot();
    List<Object> newPath = new ArrayList<Object>();
    newPath.add(newRoot);
    Object newPreviousElement = newRoot;
    for (int i=1; i<oldPath.getPathCount(); i++)
    {
        Object oldElement = oldPath.getPathComponent(i);
        DefaultMutableTreeNode oldElementNode = 
            (DefaultMutableTreeNode)oldElement;
        Object oldUserObject = oldElementNode.getUserObject();
        
        Object newElement = getChildWith(newPreviousElement, oldUserObject);
        if (newElement == null)
        {
            break;
        }
        newPath.add(newElement);
        newPreviousElement = newElement;
    }
    return new TreePath(newPath.toArray());
}
 
Example #8
Source File: ProfilerTreeTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void collapseChildren(int row) {
    if (tree != null) try {
        markExpansionTransaction();
        
        TreePath tpath = tree.getPathForRow(row);
        if (tpath == null || tree.isCollapsed(tpath)) return;
        
        TreeModel tmodel = tree.getModel();
        Object selected = tpath.getLastPathComponent();
        
        int nchildren = tmodel.getChildCount(selected);
        for (int i = 0; i < nchildren; i++)
            tree.collapsePath(tpath.pathByAddingChild(tmodel.getChild(selected, i)));
    
    } finally {
        clearExpansionTransaction();
    }
}
 
Example #9
Source File: ProjectLogicImpl.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public TreeModel createTreeModelForShoppingPeriod(String userId)
{
	//Returns a List that represents the tree/node architecture:
	//  List{ List{node, List<children>}, List{node, List<children>}, ...}.

	List<List> l1 = getTreeListForUser(DelegatedAccessConstants.SHOPPING_PERIOD_USER, false, false, getShoppingPeriodAdminNodesForUser(userId));

	//order tree model:
	orderTreeModel(l1);

	TreeModel treeModel = convertToTreeModel(l1, DelegatedAccessConstants.SHOPPING_PERIOD_USER, getEntireToolsList(), false, null, null, false);
	
	if(sakaiProxy.isActiveSiteFlagEnabled()){
		if(treeModel != null && treeModel.getRoot() != null){
			setActiveFlagForSiteNodes((DefaultMutableTreeNode) treeModel.getRoot());
		}
	}
	
	return treeModel;
}
 
Example #10
Source File: ProfilerTreeTable.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void collapseChildren(int row) {
    if (tree != null) try {
        markExpansionTransaction();
        
        TreePath tpath = tree.getPathForRow(row);
        if (tpath == null || tree.isCollapsed(tpath)) return;
        
        TreeModel tmodel = tree.getModel();
        Object selected = tpath.getLastPathComponent();
        
        int nchildren = tmodel.getChildCount(selected);
        for (int i = 0; i < nchildren; i++)
            tree.collapsePath(tpath.pathByAddingChild(tmodel.getChild(selected, i)));
    
    } finally {
        clearExpansionTransaction();
    }
}
 
Example #11
Source File: ProjectTab.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void scrollToNode(final Node n) {
        // has to be delayed to be sure that events for Visualizers
        // were processed and TreeNodes are already in hierarchy
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                TreeNode tn = Visualizer.findVisualizer(n);
                if (tn == null) {
                    return;
                }
                TreeModel model = tree.getModel();
                if (!(model instanceof DefaultTreeModel)) {
                    return;
                }
                TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
                Rectangle r = tree.getPathBounds(path);
                if (r != null) {
                    tree.scrollRectToVisible(r);
                }
            }
        });
}
 
Example #12
Source File: ObjectTrees.java    From JglTF with MIT License 6 votes vote down vote up
/**
 * Find the nodes that are <code>DefaultMutableTreeNode</code> with
 * a user object that is a {@link NodeEntry} that has the given value,
 * and return them as a (possibly unmodifiable) list.<br>
 * <br>
 * If the given tree model contains elements that are not
 * <code>DefaultMutableTreeNode</code> instances, or contain
 * user objects that are not {@link NodeEntry} instances,
 * then a warning will be printed, and the respective nodes
 * will be omitted in the returned list.
 * 
 * @param treeModel The tree model
 * @param nodeEntryValue The {@link NodeEntry} value
 * @return The nodes 
 */
static List<DefaultMutableTreeNode> findNodesWithNodeEntryValue(
    TreeModel treeModel, Object nodeEntryValue)
{
    Object root = treeModel.getRoot();
    if (!(root instanceof DefaultMutableTreeNode))
    {
        logger.warning("Unexpected node type: "+root.getClass());
        return Collections.emptyList();
    }
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)root;
    List<DefaultMutableTreeNode> result = 
        new ArrayList<DefaultMutableTreeNode>();
    findNodesWithNodeEntryValue(rootNode, nodeEntryValue, result);
    return result;
}
 
Example #13
Source File: Tab.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void scrollNodeToVisible( final Node n ) {
    EventQueue.invokeLater(new Runnable() {

        @Override
        public void run() {
            TreeNode tn = Visualizer.findVisualizer(n);
            if (tn == null) {
                return;
            }
            TreeModel model = tree.getModel();
            if (!(model instanceof DefaultTreeModel)) {
                return;
            }
            TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn));
            if( null == path )
                return;
            Rectangle r = tree.getPathBounds(path);
            if (r != null) {
                tree.scrollRectToVisible(r);
            }
        }
    });
}
 
Example #14
Source File: ChooserTreeView.java    From pdfxtk with Apache License 2.0 6 votes vote down vote up
public ChooserTreeView(TreeModel model, TreePath rootPath) {
  setLayout(new BorderLayout());
  JScrollPane pathSP = new JScrollPane(pathView);
  pathView.addChangeListener(this);
  pathSP.setHorizontalScrollBarPolicy(pathSP.HORIZONTAL_SCROLLBAR_ALWAYS);
  pathSP.setVerticalScrollBarPolicy(pathSP.VERTICAL_SCROLLBAR_NEVER); 
  add(pathSP, BorderLayout.NORTH);
  csp = new JScrollPane(content);
  csp.setHorizontalScrollBarPolicy(csp.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  csp.setVerticalScrollBarPolicy(csp.VERTICAL_SCROLLBAR_NEVER); 
  add(csp, BorderLayout.CENTER);
  if(model != null) setModel(model, rootPath);

  content.setCellRenderer(new CellRenderer());    
  content.addMouseListener(Awt.asyncWrapper(mouseAdapter));
  content.setUI(new MultiColumnListUI());
}
 
Example #15
Source File: DefaultTreeCheckingModel.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
/**
        * Sets the specified tree model. The current cheking is cleared.
        */
   public void setTreeModel(TreeModel newModel) {
TreeModel oldModel = this.model;
if (oldModel != null) {
    oldModel.removeTreeModelListener(this.propagateCheckingListener);
}
this.model = newModel;
if (newModel != null) {
    newModel.addTreeModelListener(this.propagateCheckingListener);
}
clearChecking();
   }
 
Example #16
Source File: RepositoryManager.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Add a filter to hide parts of the {@link Repository}
 *
 * @param filter
 * 		a custom filter
 * @since 9.3
 */
public void registerRepositoryFilter(RepositoryFilter filter) {
	if (!RapidMiner.getExecutionMode().isHeadless() && filter != null) {
		repositoryFilters.add(filter);
		filter.notificationCallback(() -> {
			TreeModel treeModel = RapidMinerGUI.getMainFrame().getRepositoryBrowser().getRepositoryTree().getModel();
			if (treeModel instanceof RepositoryTreeModel) {
				((RepositoryTreeModel) treeModel).notifyTreeStructureChanged();
			}
		});
	}
}
 
Example #17
Source File: WebProjectValidation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void dumpNode(TreeModel model, Object node, int offset) {
    for (int i = 0; i < offset; i++) {
        getRef().print("\t");
    }
    getRef().println(node.toString());
    if (model.isLeaf(node)) {
        return;
    }
    for (int i = 0; i < model.getChildCount(node); i++) {
        Object object = model.getChild(node, i);
        dumpNode(model, object, offset + 1);
    }
}
 
Example #18
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private static TreeModel makeModel() {
  DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
  root.add(new DefaultMutableTreeNode("Introduction"));
  root.add(makePart());
  root.add(makePart());
  return new DefaultTreeModel(root);
}
 
Example #19
Source File: ShelvedChangesViewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private TreeModel buildChangesModel() {
  myRoot = new DefaultMutableTreeNode(ROOT_NODE_VALUE);   // not null for TreeState matching to work
  DefaultTreeModel model = new DefaultTreeModel(myRoot);
  final List<ShelvedChangeList> changeLists = new ArrayList<ShelvedChangeList>(myShelveChangesManager.getShelvedChangeLists());
  Collections.sort(changeLists, ChangelistComparator.getInstance());
  if (myShelveChangesManager.isShowRecycled()) {
    ArrayList<ShelvedChangeList> recycled =
            new ArrayList<ShelvedChangeList>(myShelveChangesManager.getRecycledShelvedChangeLists());
    Collections.sort(recycled, ChangelistComparator.getInstance());
    changeLists.addAll(recycled);
  }
  myMoveRenameInfo.clear();

  for(ShelvedChangeList changeList: changeLists) {
    DefaultMutableTreeNode node = new DefaultMutableTreeNode(changeList);
    model.insertNodeInto(node, myRoot, myRoot.getChildCount());

    final List<Object> shelvedFilesNodes = new ArrayList<Object>();
    List<ShelvedChange> changes = changeList.getChanges(myProject);
    for(ShelvedChange change: changes) {
      putMovedMessage(change.getBeforePath(), change.getAfterPath());
      shelvedFilesNodes.add(change);
    }
    List<ShelvedBinaryFile> binaryFiles = changeList.getBinaryFiles();
    for(ShelvedBinaryFile file: binaryFiles) {
      putMovedMessage(file.BEFORE_PATH, file.AFTER_PATH);
      shelvedFilesNodes.add(file);
    }
    Collections.sort(shelvedFilesNodes, ShelvedFilePatchComparator.getInstance());
    for (int i = 0; i < shelvedFilesNodes.size(); i++) {
      final Object filesNode = shelvedFilesNodes.get(i);
      final DefaultMutableTreeNode pathNode = new DefaultMutableTreeNode(filesNode);
      model.insertNodeInto(pathNode, node, i);
    }
  }
  return model;
}
 
Example #20
Source File: ProfilerTreeTable.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static TreePath getSimilarPath(TreePath oldPath, TreeModel currentModel) {
        if (oldPath == null || oldPath.getPathCount() < 1) return null;

//        TreeModel currentModel = getModel();
        Object currentRoot = currentModel.getRoot();
        if (!currentRoot.equals(oldPath.getPathComponent(0))) return null;

        TreePath p = new TreePath(currentRoot);
        Object[] op = oldPath.getPath();
        Object n = currentRoot;

        for (int i = 1; i < op.length; i++) {
            Object nn = null;

            for (int ii = 0; ii < currentModel.getChildCount(n); ii++) {
                Object c = currentModel.getChild(n, ii);
                if (c.equals(op[i])) {
                    nn = c;
                    break;
                }
            }

            if (nn == null) return null;

            n = nn;
            p = p.pathByAddingChild(n);
        }
//        System.err.println(">>> Similar path for " + oldPath + " is " + p);
        return p;
    }
 
Example #21
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private static void searchTreeNode(JTree tree, Object name) {
  TreeModel model = tree.getModel();
  DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
  // Java 9: Collections.list(root.preorderEnumeration()).stream()
  Collections.list((Enumeration<?>) root.preorderEnumeration()).stream()
      .filter(DefaultMutableTreeNode.class::isInstance)
      .map(DefaultMutableTreeNode.class::cast)
      .filter(node -> Objects.equals(name, Objects.toString(node.getUserObject())))
      .findFirst()
      .ifPresent(node -> {
        tree.setEnabled(false);
        TreePath path = new TreePath(node.getPath());
        tree.setSelectionPath(path);
        tree.scrollPathToVisible(path);
        tree.setEnabled(true);
      });
  // // Java 9: Enumeration<TreeNode> e = root.preorderEnumeration();
  // Enumeration<?> e = root.preorderEnumeration();
  // while (e.hasMoreElements()) {
  //   DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement();
  //   if (node != null && Objects.equals(name, node.toString())) {
  //     tree.setEnabled(false);
  //     TreePath path = new TreePath(node.getPath());
  //     tree.setSelectionPath(path);
  //     tree.scrollPathToVisible(path);
  //     tree.setEnabled(true);
  //     return;
  //   }
  // }
}
 
Example #22
Source File: EmbeddedHierarchicalInstancePage.java    From ontopia with Apache License 2.0 5 votes vote down vote up
protected IModel<TreeModel> createTreeModel(final TopicModel<Topic> hierarchyTopicModel, final TopicModel<Topic> currentNodeModel) {
  final TreeModel treeModel;
  Topic hierarchyTopic = hierarchyTopicModel.getTopic();
  Topic currentNode = currentNodeModel.getTopic();
  
  // find hierarchy definition query for topic
  String query = (hierarchyTopic == null ? null : getDefinitionQuery(hierarchyTopic));

  if (query != null) {
    Map<String,TopicIF> params = new HashMap<String,TopicIF>(2);
    params.put("hierarchyTopic", hierarchyTopic.getTopicIF());
    params.put("currentNode", currentNode.getTopicIF());
    treeModel = TreeModels.createQueryTreeModel(currentNode.getTopicMap(), query, params);
  } else if (currentNode.isTopicType()) {
    // if no definition query found, then show topic in instance hierarchy
    treeModel = TreeModels.createTopicTypesTreeModel(currentNode.getTopicMap(), isAnnotationEnabled(), isAdministrationEnabled());
  } else {
    treeModel = TreeModels.createInstancesTreeModel(OntopolyUtils.getDefaultTopicType(currentNode), isAdministrationEnabled());
  }
  
  return new AbstractReadOnlyModel<TreeModel>() {
    @Override
    public TreeModel getObject() {
      return treeModel;
    }
  };
}
 
Example #23
Source File: LibraryTreePanel.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the font level.
 *
 * @param level the desired font level
 */
protected void setFontLevel(int level) {

Object[] toSize = new Object[] {
		splitPane, editorPanel, editorbar, authorField, contactField, keywordsField,
		authorLabel, contactLabel, keywordsLabel, metadataLabel, metadataDropdown};
FontSizer.setFonts(toSize, level);
EntryField.font = authorField.getFont();

// resize treeNodeRenderer and LibraryResource icons
treeNodeRenderer.resizableOpenIcon.resize(FontSizer.getIntegerFactor());
treeNodeRenderer.resizableClosedIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.trackerIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.ejsIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.imageIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.videoIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.htmlIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.pdfIcon.resize(FontSizer.getIntegerFactor());
LibraryResource.unknownIcon.resize(FontSizer.getIntegerFactor());

// resize LibraryResource stylesheet font sizes
LibraryResource.bodyFont = FontSizer.getResizedFont(LibraryResource.bodyFont, level);
LibraryResource.h1Font = FontSizer.getResizedFont(LibraryResource.h1Font, level);
LibraryResource.h2Font = FontSizer.getResizedFont(LibraryResource.h2Font, level);

// clear htmlPanesByNode to force new HTML code with new stylesheets
htmlPanesByNode.clear();

// refresh the tree structure
TreeModel model = tree.getModel();
if (model instanceof DefaultTreeModel) {
	LibraryTreeNode selectedNode = getSelectedNode();
	DefaultTreeModel treeModel = (DefaultTreeModel)model;
	treeModel.nodeStructureChanged(rootNode);
	setSelectedNode(selectedNode);
}
refreshGUI();

}
 
Example #24
Source File: DependencyViewer.java    From gradle-view with Apache License 2.0 5 votes vote down vote up
public void updateView(GradleNode rootDependency, final GradleNode selectedDependency) {
    // TODO replace this hack with something that populates the GradleNode graph

    DefaultMutableTreeNode fullRoot = new DefaultMutableTreeNode(new GradleNode("Project Dependencies"));
    if(rootDependency == null) {
        DefaultMutableTreeNode loading = new DefaultMutableTreeNode(new GradleNode("Loading..."));
        fullRoot.add(loading);
    } else {
        DefaultMutableTreeNode flattenedRoot = convertToSortedTreeNode(rootDependency);
        DefaultMutableTreeNode hierarchyRoot = convertToHierarchyTreeNode(rootDependency);
        fullRoot.add(flattenedRoot);
        fullRoot.add(hierarchyRoot);
    }

    TreeModel treeModel = new DefaultTreeModel(fullRoot);
    final SimpleTree fullTree = new SimpleTree(treeModel);
    fullTree.setCellRenderer(dependencyCellRenderer);

    // expand path for first level from root
    //fullTree.expandPath(new TreePath(hierarchyRoot.getNextNode().getPath()));

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if(gradleBaseDir != null) {
                toolWindow.setTitle("- " + gradleBaseDir);
            }
            splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(fullTree));
            splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(information));
        }
    });
}
 
Example #25
Source File: ElementTreePanel.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the tree based on the event type. This will invoke either
 * updateTree with the root element, or handleChange.
 */
protected void updateTree(DocumentEvent event) {
    updatingSelection = true;
    try {
        TreeModel model = getTreeModel();
        Object root = model.getRoot();

        for (int counter = model.getChildCount(root) - 1; counter >= 0;
                counter--) {
            updateTree(event, (Element) model.getChild(root, counter));
        }
    } finally {
        updatingSelection = false;
    }
}
 
Example #26
Source File: IconView.java    From RobotBuilder with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public IconView(Palette palette) {
    this.palette = palette;

    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    TreeModel model = palette.getPaletteModel();
    Enumeration children = ((DefaultMutableTreeNode) model.getRoot()).children();
    while (children.hasMoreElements()) {
        DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
        add(new IconSection(child));
    }
}
 
Example #27
Source File: ProjectTreeDnDHandler.java    From mzmine2 with GNU General Public License v2.0 5 votes vote down vote up
public boolean canImport(TransferSupport info) {

    ProjectTree projectTree = (ProjectTree) info.getComponent();
    TreeModel treeModel = projectTree.getModel();

    // Get location where we are dropping
    JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();

    // We want to insert between existing items, in such case the child
    // index is always >= 0
    if (dl.getChildIndex() < 0)
      return false;

    // Get the path of the item where we are dropping
    TreePath dropPath = dl.getPath();
    DefaultMutableTreeNode droppedLocationNode =
        (DefaultMutableTreeNode) dropPath.getLastPathComponent();
    Object dropTargetObject = droppedLocationNode.getUserObject();

    // If the target is "Raw data files" item, accept the drop
    if (dropTargetObject == RawDataTreeModel.dataFilesNodeName)
      return true;

    // If the target is last item AFTER "Raw data files" item, accept
    // the drop
    if ((droppedLocationNode == treeModel.getRoot()) && (dl.getChildIndex() == 1))
      return true;

    // If the target is "Feature lists" item, accept the drop
    if (dropTargetObject == PeakListTreeModel.peakListsNodeName)
      return true;

    // If the target is last item AFTER "Feature lists" item, accept the
    // drop
    if ((droppedLocationNode == treeModel.getRoot()) && (dl.getChildIndex() == 2))
      return true;

    return false;
  }
 
Example #28
Source File: JTreeTable.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public TreeTableCellRenderer(TreeModel model) {
    super(model);

    offsetX = 0;
    setOpaque(false);
    treeCellRenderer = new EnhancedTreeCellRenderer();
    setCellRenderer(treeCellRenderer);
    unselectedBackground = UIUtils.getProfilerResultsBackground();
    darkerUnselectedBackground = UIUtils.getDarker(unselectedBackground);
}
 
Example #29
Source File: JTreeOperator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Maps {@code JTree.setModel(TreeModel)} through queue
 */
public void setModel(final TreeModel treeModel) {
    runMapping(new MapVoidAction("setModel") {
        @Override
        public void map() {
            ((JTree) getSource()).setModel(treeModel);
        }
    });
}
 
Example #30
Source File: OutlineNavigatorTest.java    From jlibs with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public static void main(String[] args) throws Exception{
    String url = JOptionPane.showInputDialog("File/URL", "http://schemas.xmlsoap.org/wsdl/");
    if(url==null)
        return;
    XSModel model = new XSParser().parse(url);
    MyNamespaceSupport nsSupport = XSUtil.createNamespaceSupport(model);

    Navigator navigator1 = new FilteredTreeNavigator(new XSNavigator(), new XSDisplayFilter());
    Navigator navigator = new PathNavigator(navigator1);
    XSPathDiplayFilter filter = new XSPathDiplayFilter(navigator1);
    navigator = new FilteredTreeNavigator(navigator, filter);
    TreeModel treeModel = new NavigatorTreeModel(new Path(model), navigator);
    RowModel rowModel = new DefaultRowModel(new DefaultColumn("Detail", String.class, new XSDisplayValueVisitor(nsSupport))/*, new ClassColumn()*/);
    
    OutlineNavigatorTest test = new OutlineNavigatorTest("Navigator Test");
    Outline outline = test.getOutline();
    outline.setShowGrid(false);
    outline.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));
    outline.setModel(DefaultOutlineModel.createOutlineModel(treeModel, rowModel));
    outline.getColumnModel().getColumn(1).setMinWidth(150);

    DefaultRenderDataProvider dataProvider = new DefaultRenderDataProvider();
    dataProvider.setDisplayNameVisitor(new XSDisplayNameVisitor(nsSupport, filter));
    dataProvider.setForegroundVisitor(new XSColorVisitor(filter));
    dataProvider.setFontStyleVisitor(new XSFontStyleVisitor(filter));
    outline.setRenderDataProvider(dataProvider);
    
    test.setVisible(true);
}