org.openide.explorer.view.Visualizer Java Examples

The following examples show how to use org.openide.explorer.view.Visualizer. 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: StatefulView.java    From Llunatic with GNU General Public License v3.0 6 votes vote down vote up
public List<String[]> getExpandedPaths() {
    List<String[]> result = new ArrayList<String[]>();
    if (getRootNode() != null) {
        TreeNode rtn = Visualizer.findVisualizer(getRootNode());
        TreePath tp = new TreePath(rtn); // Get the root
        Enumeration exPaths = tree.getExpandedDescendants(tp);
        while (exPaths != null && exPaths.hasMoreElements()) {
            TreePath ep = (TreePath) exPaths.nextElement();
            Node en = Visualizer.findNode(ep.getLastPathComponent());
            String[] path = NodeOp.createPath(en, getRootNode());
            result.add(path);
            if (logger.isTraceEnabled()) logger.trace("Expanded path: " + LoggingUtils.printArray(path));
        }
    }
    return result;

}
 
Example #2
Source File: ClassMemberPanelUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@CheckForNull
@Override
public Node findNode(@NonNull final Point loc) {
    final TreePath path = tree.getPathForLocation( loc.x, loc.y );
    if( null == path ) {
        return null;
    }
    final Node node = Visualizer.findNode( path.getLastPathComponent());
    if (!(node instanceof ElementNode)) {
        return null;
    }
    final ElementNode enode = (ElementNode) node;
    final ElementNode.Description desc = enode.getDescritption();
    //Other and module do not have javadoc
    return desc.kind != ElementKind.OTHER
        && desc.kind != ElementKind.MODULE ?
            node :
            null;
}
 
Example #3
Source File: CheckListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyChar() == ' ') {
        JTree tree = (JTree) e.getSource();
        TreePath path = tree.getSelectionPath();
        if( null == path )
            return;

        Node node = Visualizer.findNode( path.getLastPathComponent() );
        if( null == node )
            return;
        
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
        
        e.consume();
    }
}
 
Example #4
Source File: FileTreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public String getDisplayName (Object o) {
    Node n = Visualizer.findNode(o);
    String value = n.getDisplayName();
    T leafNode = convertNode(n);
    if (leafNode != null) {
        // do not set selected flag, outline view handles color in its own way
        // instead return fg color in getForeground
        String htmlDisplayName = DiffUtils.getHtmlDisplayName(leafNode, isModified(leafNode), false);
        htmlDisplayName = annotateName(leafNode, htmlDisplayName);
        if (htmlDisplayName != null) {
            value = "<html>" + htmlDisplayName; //NOI18N
        }
    }
    return value;
}
 
Example #5
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private int getPrevRow(int row) {
    row = row - 1;
    Outline outline = tablePanel.treeView.getOutline();
    if(row < 0 || row >= outline.getRowCount()) {
        return -1;
    }
    TreePath path = outline.getOutlineModel().getLayout().getPathForRow(row);
    Node node = Visualizer.findNode(path.getLastPathComponent());
    if(node.isLeaf()) {
        if(node instanceof RevisionNode || node instanceof RevisionNode.FileNode) {
            return row;
        } else {
            return -1;
        }
    } else {
        TreePathSupport support = outline.getOutlineModel().getTreePathSupport();
        if(support.isExpanded(path)) {
            return getPrevRow(row);
        } else {
            support.expandPath(path);
            return row + node.getChildren().getNodesCount();
        }
    }
}
 
Example #6
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 #7
Source File: CheckListener.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    if (e.getKeyChar() == ' ') { // NOI18N
        JTree tree = (JTree) e.getSource();
        TreePath path = tree.getSelectionPath();
        if (path == null) {
            return;
        }

        Node node = Visualizer.findNode(path.getLastPathComponent());
        if (node == null) {
            return;
        }

        boolean isSelected = model.isNodeSelected(node);
        model.setNodeSelected(node, !isSelected);
        tree.repaint();

        e.consume();
    }
}
 
Example #8
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private int getNextRow(int row) {
    row = row + 1;
    Outline outline = tablePanel.treeView.getOutline();
    if(row < 0 || row >= outline.getRowCount()) {
        return -1;
    }
    TreePath path = outline.getOutlineModel().getLayout().getPathForRow(row);
    Node node = Visualizer.findNode(path.getLastPathComponent());
    if(node.isLeaf()) {
        if(node instanceof RevisionNode || node instanceof RevisionNode.FileNode) {
            return row;
        } else {
            return -1;
        }
    } else {
        TreePathSupport support = outline.getOutlineModel().getTreePathSupport();
        if(support.isExpanded(path)) {
            return getPrevRow(row);
        } else {
            support.expandPath(path);
            return row + 1;
        }
    }
}
 
Example #9
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 #10
Source File: ResultTreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getTreeCellRendererComponent(JTree tree,
                                                 Object value,
                                                 boolean selected,
                                                 boolean expanded,
                                                 boolean leaf,
                                                 int row,
                                                 boolean hasFocus) {
       boolean isResultRootNode =
                       (value instanceof TreeNode)
                       && (((TreeNode) value).getParent() == null);
// render no icon space an empty icon of a callStackFrame
       boolean isCallstackFrame = false;
       if (null != value) {
           isCallstackFrame = (Visualizer.findNode(value) instanceof CallstackFrameNode);
       }

       TreeCellRenderer renderer = (isResultRootNode || isCallstackFrame)
                                   ? noIconTreeCellRenderer
                                   : defaultTreeCellRenderer;
       return renderer.getTreeCellRendererComponent(
               tree, value, selected, expanded, leaf, row, hasFocus);
   }
 
Example #11
Source File: OutlineTable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Converts path of strings to TreePath if exists null otherwise
 */
private TreePath stringPath2TreePath (String[] sp) {
    ExplorerManager em = ExplorerManager.find (this);
    try {
        Node n = NodeOp.findPath (em.getRootContext (), sp); 
        
        // Create the tree path
        TreeNode tns[] = new TreeNode [sp.length + 1];
        
        for (int i = sp.length; i >= 0; i--) {
            tns[i] = Visualizer.findVisualizer (n);
            n = n.getParentNode ();
        }                
        return new TreePath (tns);
    } catch (NodeNotFoundException e) {
        return null;
    }
}
 
Example #12
Source File: TreeModelRoot.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Object initExpandCollapseNotify(TreeExpansionEvent event) {
    Node node = Visualizer.findNode(event.getPath ().getLastPathComponent());
    Object obj = node.getLookup().lookup(Object.class);
    Object actOn;
    node = node.getParentNode();
    if (node == null) {
        actOn = new Integer(0);
    } else {
        Children ch = node.getChildren();
        if (ch instanceof TreeModelNode.TreeModelChildren) {
            actOn = ((TreeModelNode.TreeModelChildren) ch).getTreeDepth();
        } else {
            actOn = ch;
        }
    }
    Models.CompoundModel model = getModel();
    if (model != null) {
        DefaultTreeExpansionManager.get(model).setChildrenToActOn(actOn);
    }
    return obj;
}
 
Example #13
Source File: SchemaImportGUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of LocationView.
 */
public LocationView() {
    super();
    tree.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            // Invert the selection of the data node, if such a
            // node was clicked on.
            TreePath path = tree.getPathForLocation(e.getX(), e.getY());
            if (path != null) {
                Object comp = path.getLastPathComponent();
                Node node = Visualizer.findNode(comp);
                if (node instanceof ExternalReferenceDataNode) {
                    ExternalReferenceDataNode erdn =
                            (ExternalReferenceDataNode) node;
                    if (erdn.canSelect()) {
                        boolean selected = !erdn.isSelected();
                        erdn.setSelected(selected);
                        //setPrimarySchema(erdn, selected, true);
                        
                    }
                }
            }
        }
    });
}
 
Example #14
Source File: CheckTreeView.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean toggle( TreePath treePath ) {
    
    if( treePath == null )
        return false;
    
    Node node = Visualizer.findNode( treePath.getLastPathComponent() );
    if( node == null )
        return false ;

    ElementNode.Description description = node.getLookup().lookup(ElementNode.Description.class);
    if (description != null ) {
        if( description.isSelectable()  ) {
            description.setSelected( !description.isSelected() );
            return true;
        } else {
            boolean newState = !description.isSelected();
            toggleChildren( description.getSubs(), newState );
            // first toggle children, then itself. If children were not expanded,
            // the self-toggle will fire appropriate events and controls will be reevaluated.
            description.setSelected(newState);
        }
    }
    
    return false;
}
 
Example #15
Source File: StatefulView.java    From Llunatic with GNU General Public License v3.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 #16
Source File: Navigator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getTree() {
    return BeansTestCase.getTree(getTreeOperator(), new BeansTestCase.NodeConverter() {

        @Override
        public String getDisplayName(TreeNode node) {
            String text = node.toString();
            Node findNode = Visualizer.findNode(node);
            if (findNode instanceof PatternNode) {
                PatternNode patternNode = (PatternNode) findNode;
                if (patternNode.getShortDescription() != null) {
                    text = patternNode.getShortDescription();
                } else if (patternNode.getHtmlDisplayName() != null) {
                    text = patternNode.getHtmlDisplayName();
                }
            }
            return text;
        }
    });        
}
 
Example #17
Source File: DelegatingCellRenderer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static final Node getNodeAt(Outline outline, int rowInUI) {
    Node result = null;
    OutlineModel om = (OutlineModel) outline.getModel();
    int row = outline.convertRowIndexToModel(rowInUI);
    TreePath path = om.getLayout().getPathForRow(row);
    if (path != null) {
        result = Visualizer.findNode(path.getLastPathComponent());
    }
    return result;
}
 
Example #18
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Icon getIcon(Object o) {
    final Node n = Visualizer.findNode(o);
    if(HistoryRootNode.isWait(n)) {
        return delegate.getIcon(o);
    }
    if(getOutline().getOutlineModel().isLeaf(o) || HistoryRootNode.isLoadNext(n))
        return NO_ICON;
    return null;
}
 
Example #19
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isHtmlDisplayName(Object o) {
    Node n = Visualizer.findNode(o);
    if(HistoryRootNode.isLoadNext(n)) {
        return true;
    }
    return delegate.isHtmlDisplayName(o);
}
 
Example #20
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String getDisplayName(Object o) {
    Node n = Visualizer.findNode(o);
    if(HistoryRootNode.isLoadNext(n)) {
        StringBuilder sb = new StringBuilder();
        sb.append("<html>"); // NOI18N
        appendHyperlinkHTMLFont(sb);   
        sb.append(delegate.getDisplayName(o));
        sb.append("</font></html>"); // NOI18N
        return sb.toString();
    }
    return delegate.getDisplayName(o);
}
 
Example #21
Source File: HistoryFileView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void treeExpanded(TreeExpansionEvent event) {
    Object obj = event.getPath().getLastPathComponent();
    if(obj == null) return;
    Node n = Visualizer.findNode(obj);
    if(HistoryRootNode.isLoadNext(n)) { // XXX move to lhrootnode
        loadNextAction.actionPerformed(null);
    }
}
 
Example #22
Source File: DebuggingViewComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether we should scroll to the current thread.
 *
 * @param path Path of node that has been just expanded, or that has new
 * children.
 */
private void checkIfWeShouldScrollToCurrentThread(TreePath path) {
    Node node = Visualizer.findNode(path.getLastPathComponent());
    if (node == null) {
        return;
    }
    DVThread dvThread = node.getLookup().lookup(DVThread.class);
    DVThread currentThread;
    synchronized (lock) {
        currentThread = (debugger != null) ? debugger.getCurrentThread() : null;
    }
    if (currentThread != null && currentThread == dvThread) {
        threadToScrollRef = new WeakReference<DVThread>(dvThread);
    }
}
 
Example #23
Source File: DebugTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get the DVThread or DVThreadGroup instance on the given path.
 * @param path
 * @return an instance of DVThread or DVThreadGroup
 */
public Object getThreadObject(TreePath path) {
    Node node = Visualizer.findNode(path.getLastPathComponent());
    DVThread dvThread = node.getLookup().lookup(DVThread.class);
    if (dvThread != null) {
        return dvThread;
    }
    DVThreadGroup dvThreadGroup = node.getLookup().lookup(DVThreadGroup.class);
    return dvThreadGroup;
}
 
Example #24
Source File: CheckNodeListModel.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public CheckNode getCheckNodeAt(int index) {
    Object item = getElementAt(index);
    if (item != null) {
        return (CheckNode) Visualizer.findNode(item);
    }
    return null;
}
 
Example #25
Source File: FileTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Color getForeground (Object o) {
    Color c = null;
    Node n = Visualizer.findNode(o);
    T leafNode = convertNode(n);
    if (leafNode != null) {
        c = leafNode.getAnnotatedFontColor();
    }
    return c;
}
 
Example #26
Source File: Browser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void treeExpanded(TreeExpansionEvent event) {
    Object obj = event.getPath().getLastPathComponent();
    if(obj == null) return;
    Node n = Visualizer.findNode(obj);
    if(n instanceof RepositoryPathNode) {
        RepositoryPathNode node = (RepositoryPathNode) n;
        node.expand();
    }
}
 
Example #27
Source File: FileTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean testNodeInRow(Outline outline, Node node, int i) {
    int modelIndex = outline.convertRowIndexToModel(i);
    if (modelIndex != -1) {
        Object o = outline.getModel().getValueAt(modelIndex, 0);
        Node n = Visualizer.findNode(o);
        if (n == node) {
            return true;
        }
    }
    return false;
}
 
Example #28
Source File: FileTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Node getNodeAt( int rowIndex ) {
    Node result = null;
    TreePath path = view.getOutline().getOutlineModel().getLayout().getPathForRow(rowIndex);
    if (path != null) {
        result = Visualizer.findNode(path.getLastPathComponent());
    }
    return result;
}
 
Example #29
Source File: CheckListener.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    // todo (#pf): we need to solve problem between click and double
    // click - click should be possible only on the check box area
    // and double click should be bordered by title text.
    // we need a test how to detect where the mouse pointer is
    JTree tree = (JTree) e.getSource();
    Point p = e.getPoint();
    int x = e.getX();
    int y = e.getY();
    int row = tree.getRowForLocation(x, y);
    TreePath path = tree.getPathForRow(row);

    // if path exists and mouse is clicked exactly once
    if( null == path )
        return;
    
    Node node = Visualizer.findNode( path.getLastPathComponent() );
    if( null == node )
        return;
    
    Rectangle chRect = CheckRenderer.getCheckBoxRectangle();
    Rectangle rowRect = tree.getPathBounds(path);
    chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y);
    if (e.getClickCount() == 1 && chRect.contains(p)) {
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
    }
}
 
Example #30
Source File: FileTreeView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Node[] getChildrenInDisplayedOrder(Node parent,
        OutlineView outlineView) {

    Outline outline = outlineView.getOutline();
    Node[] unsortedChildren = parent.getChildren().getNodes(true);
    int rows = outlineView.getOutline().getRowCount();
    int start = findRowIndexInOutline(parent, outline, rows);
    if (start == -1 && parent != ExplorerManager.find(outlineView).getRootContext()) {
        return unsortedChildren;
    }
    List<Node> children = new LinkedList<Node>();
    for (int j = start + 1; j < rows; j++) {
        int childModelIndex = outline.convertRowIndexToModel(j);
        if (childModelIndex == -1) {
            continue;
        }
        Object childObject = outline.getModel().getValueAt(
                childModelIndex, 0);
        Node childNode = Visualizer.findNode(childObject);
        if (childNode.getParentNode() == parent) {
            children.add(childNode);
        } else if (children.size() == unsortedChildren.length) {
            break;
        }
    }
    return children.toArray(new Node[children.size()]);
}