Java源码示例:org.openide.explorer.view.Visualizer

示例1
@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;
}
 
示例2
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;
        }
    });        
}
 
示例3
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;
}
 
示例4
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);
            }
        }
    });
}
 
示例5
@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();
    }
}
 
示例6
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);
                }
            }
        });
}
 
示例7
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();
    }
}
 
示例8
@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;
}
 
示例9
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();
        }
    }
}
 
示例10
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;
        }
    }
}
 
示例11
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);
   }
 
示例12
/** 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;
    }
}
 
示例13
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;
}
 
示例14
/**
 * 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);
                        
                    }
                }
            }
        }
    });
}
 
示例15
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);
            }
        }
    });
}
 
示例16
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;

}
 
示例17
private void browseTree(Object root, TreeModel model, String string) {
    Object node = Visualizer.findNode(root);
    if (node instanceof Node) {
        Node n = (Node) node;
        System.out.println(n.getDisplayName());
    }
    System.out.println(string + node.getClass().getName());
    int childCount = model.getChildCount(root);
    for (int i = 0; i < childCount; i++) {
        browseTree(model.getChild(root, i), model, string + "  ");
    }
}
 
示例18
private boolean toggle( TreePath treePath ) {
            
            if( treePath == null )
                return false;
            
            Node node = Visualizer.findNode( treePath.getLastPathComponent() );
            if( node == null )
                return false ;

            Collection<? extends FixDescription> fixes = node.getLookup().lookupAll(FixDescription.class);
            if (!fixes.isEmpty()) {
                State s = CheckRenderer.getCheckState(fixes);
                boolean select = s != State.SELECTED;
                for (FixDescription fd : fixes) {
                    fd.setSelected(select);
                }
                return true;
//                if( description.isSelectable()  ) {
//                    description.setSelected( !description.isSelected() );
//                    return true;
//                } else {
//                    boolean newState = !description.isSelected();
//                    description.setSelected(newState);
//                    toggleChildren( description.getSubs(), newState );
//                }
            }
            
            return false;
        }
 
示例19
@Override
public void treeExpanded(TreeExpansionEvent event) {
    if (!expansionListenerEnabled) {
        return;
    }
    Object lpc = event.getPath().getLastPathComponent();
    Node node = Visualizer.findNode(lpc);
    if (node != null) {
        expandOnlyChilds(node);
    }
}
 
示例20
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) {
        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()]);
}
 
示例21
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;
}
 
示例22
/**
 * Updates the set of highlighted nodes.
 */
final void updateHighlight() {
    synchronized (highlightedTreeNodes) {
        highlightedTreeNodes.clear();
        for (Node node : pageModel.getHighlightedNodes()) {
            TreeNode visualizer = Visualizer.findVisualizer(node);
            highlightedTreeNodes.add(visualizer);
        }
    }
    treeView.repaint();
}
 
示例23
/**
 * Retuns DOM tree path to selected element and its ID and Class attributes
 *
 * @return sample output {@code [root, html, body]body#foo.bar}
 */
public String getFocusedElement() {
    StringBuilder sb = new StringBuilder();
    TreePath tp = treeDOM().getSelectionPath();
    sb.append(tp.toString().replaceFirst("\\[#document, ", "["));// ignore root in path
    org.openide.nodes.Node node = Visualizer.findNode(treeDOM().getLastSelectedPathComponent());
    return sb.toString();
}
 
示例24
@Override
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 (path == null) {
        return;
    }

    Node node = Visualizer.findNode(path.getLastPathComponent());
    if (node == null) {
        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 = model.isNodeSelected(node);
        model.setNodeSelected(node, !isSelected);
        tree.repaint();
    }
}
 
示例25
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();
    }
}
 
示例26
@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();
    }
}
 
示例27
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;
}
 
示例28
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()]);
}
 
示例29
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;
}
 
示例30
@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;
}