Java Code Examples for org.openide.nodes.Node.getIcon()

The following are Jave code examples for showing how to use getIcon() of the org.openide.nodes.Node class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: incubator-netbeans   File: IconPanel.java   Source Code and License Vote up 6 votes
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Node node = Visualizer.findNode(value);
    thumbImage = node.getIcon(BeanInfo.ICON_COLOR_32x32);
    this.selected = isSelected;
    label.setOpaque(selected);
    if (selected) {
      label.setBackground(UIManager.getColor("List.selectionBackground"));
      label.setForeground(UIManager.getColor("List.selectionForeground"));
    } else {
      label.setBackground(UIManager.getColor("Label.background"));
      label.setForeground(UIManager.getColor("Label.foreground"));
    }
    this.focused = cellHasFocus;
    this.label.setText(node.getDisplayName());

    return this;
}
 
Example 2
Project: incubator-netbeans   File: BreadCrumbComponent.java   Source Code and License Vote up 6 votes
private void configureForNode(Node node) {
    renderer.reset();
    
    Image nodeIcon = node.getIcon(BeanInfo.ICON_COLOR_16x16);
    Icon icon = nodeIcon != null && nodeIcon != BreadcrumbsController.NO_ICON ? ImageUtilities.image2Icon(nodeIcon) : null;
    int width = icon != null ? icon.getIconWidth() : 0;
    if (width > 0) {
        renderer.setIcon(icon);
        renderer.setIconTextGap(ICON_TEXT_SEPARATOR);
    } else {
        renderer.setIcon(null);
        renderer.setIconTextGap(0);
    }
    String html = node.getHtmlDisplayName();
    if (html != null) {
        renderer.setHtml(true);
        renderer.setText(html);
    } else {
        renderer.setHtml(false);
        renderer.setText(node.getDisplayName());
    }
    renderer.setFont(getFont());
}
 
Example 3
Project: incubator-netbeans   File: UINodeTest.java   Source Code and License Vote up 6 votes
public void testIconOfTheNode() throws Exception {
    LogRecord r = new LogRecord(Level.INFO, "icon_msg");
    r.setResourceBundleName("org.netbeans.modules.uihandler.TestBundle");
    r.setResourceBundle(ResourceBundle.getBundle("org.netbeans.modules.uihandler.TestBundle"));
    r.setParameters(new Object[] { new Integer(1), "Ahoj" });
    
    Node n = UINode.create(r);
    assertEquals("Name is taken from the message", "icon_msg", n.getName());
    
    if (!n.getDisplayName().matches(".*Ahoj.*")) {
        fail("wrong display name, shall contain Ahoj: " + n.getDisplayName());
    }
    
    Image img = n.getIcon(BeanInfo.ICON_COLOR_32x32);
    assertNotNull("Some icon", img);
    IconInfo imgReal = new IconInfo(img);
    IconInfo template = new IconInfo(getClass().getResource("testicon.png"));
    assertEquals("Icon from ICON_BASE used", template, imgReal);
    
    assertSerializedWell(n);
}
 
Example 4
Project: incubator-netbeans   File: BookmarkNodeRenderer.java   Source Code and License Vote up 6 votes
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

    Icon icon = null;
    BookmarksTableModel model = (BookmarksTableModel) table.getModel();
    BookmarkNode bNode = model.getEntry(row);
    BookmarkInfo bookmark = bNode.getBookmarkInfo();
    Node fNode = bNode.getParentNode();
    if (fNode != null) {
        if (!isSelected) {
            String text = fNode.getHtmlDisplayName();
            if (text != null) {
                text = bookmark.getDescription(text, forHistoryPopup, forHistoryPopup, true);
                setText("<html>" + text + "</html>");
            } // else leave original text set by "super"
        }
        Image image = fNode.getIcon(BeanInfo.ICON_COLOR_16x16);
        if (image != null) {
            icon = ImageUtilities.image2Icon(image);
        }
    }
    setIcon(icon);
    return this;

}
 
Example 5
Project: incubator-netbeans   File: SearchScopeNodeSelection.java   Source Code and License Vote up 6 votes
@Override
public Icon getIcon() {
    Node[] nodes = getNodes();
    if (nodes.length > 1) {
        return MULTI_SELECTION_ICON;
    } else if (nodes.length == 1 && nodes[0] != null) {
        Node n = nodes[0];
        Image image = n.getIcon(BeanInfo.ICON_COLOR_16x16);
        if (image != null) {
            return ImageUtilities.image2Icon(image);
        } else {
            return null;
        }
    } else {
        return null;
    }
}
 
Example 6
Project: incubator-netbeans   File: NodeRenderDataProvider.java   Source Code and License Vote up 5 votes
public javax.swing.Icon getIcon(Object o) {
    if (!showIcons) {
        return emptyIcon;
    }
    Node n = Visualizer.findNode(o);
    if (n == null) {
        throw new IllegalStateException("TreeNode must be VisualizerNode but was: " + o + " of class " + o.getClass().getName());
    }
    boolean expanded = false;
    if (o instanceof TreeNode) {
        TreeNode tn = (TreeNode)o;
        ArrayList<TreeNode> al = new ArrayList<TreeNode> ();
        while (tn != null) {
            al.add(tn);
            tn = tn.getParent();
        }
        Collections.reverse(al);
        TreePath tp = new TreePath(al.toArray());
        AbstractLayoutCache layout = table.getLayoutCache();
        expanded = layout.isExpanded(tp);
    }
    java.awt.Image image = null;
    if (expanded) {
        image = n.getOpenedIcon(java.beans.BeanInfo.ICON_COLOR_16x16);
    } else {
        image = n.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16);
    }
    return new ImageIcon(image);
}
 
Example 7
Project: incubator-netbeans   File: ExitDialog.java   Source Code and License Vote up 5 votes
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)    // the list and the cell have the focus
{
    final DataObject obj = (DataObject)value;
    if (!obj.isValid()) {
        // #17059: it might be invalid already.
        // #18886: but if so, remove it later, otherwise BasicListUI gets confused.
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                listModel.removeElement(obj);
            }
        });
        setText("");
        return this;
    }

    Node node = obj.getNodeDelegate();

    ImageIcon icon = new ImageIcon(node.getIcon(BeanInfo.ICON_COLOR_16x16));
    super.setIcon(icon);

    setText(node.getDisplayName());
    if (isSelected){
        this.setBackground(UIManager.getColor("List.selectionBackground")); // NOI18N
        this.setForeground(UIManager.getColor("List.selectionForeground")); // NOI18N
    }
    else {
        this.setBackground(list.getBackground());
        this.setForeground(list.getForeground());
    }

    this.setBorder(cellHasFocus ? hasFocusBorder : noFocusBorder);

    return this;
}
 
Example 8
Project: incubator-netbeans   File: SystemFileSystemTest.java   Source Code and License Vote up 5 votes
public void testIconFromURL() throws Exception {
    FileObject bar = FileUtil.getConfigFile("foo/bar.txt");
    Node n = DataObject.find(bar).getNodeDelegate();
    Image reference = Toolkit.getDefaultToolkit().createImage(new URL("jar:" + satJar.toURL() + "!/sfs_attr_test/main.gif"));
    Image tested = n.getIcon(BeanInfo.ICON_COLOR_16x16);
    int h1 = imageHash("main.gif", reference, 16, 16);
    int h2 = imageHash("bar.txt icon", tested, 16, 16);
    assertEquals("correct icon", h1, h2);
}
 
Example 9
Project: incubator-netbeans   File: SystemFileSystemTest.java   Source Code and License Vote up 5 votes
/** @see "#18832" */
public void testIconFromImageMethod() throws Exception {
    FileObject baz = FileUtil.getConfigFile("foo/baz.txt");
    Node n = DataObject.find(baz).getNodeDelegate();
    Image reference = Toolkit.getDefaultToolkit().createImage(new URL("jar:" + satJar.toURL() + "!/sfs_attr_test/main-plus-badge.gif"));
    Image tested = n.getIcon(BeanInfo.ICON_COLOR_16x16);
    int h1 = imageHash("main-plus-badge.gif", reference, 16, 16);
    int h2 = imageHash("baz.txt icon", tested, 16, 16);
    assertEquals("correct icon", h1, h2);
}
 
Example 10
Project: incubator-netbeans   File: AsynchronousTest.java   Source Code and License Vote up 5 votes
private void inspectNode(Node n) {
    n.getDisplayName();
    n.getHtmlDisplayName();
    n.getShortDescription();
    n.getIcon(BeanInfo.ICON_COLOR_16x16);
    n.canCopy();
    n.canCut();
    n.canRename();
    n.getNewTypes();
    n.getActions(true);
    n.getPreferredAction();
    inspectProperties(n);
}
 
Example 11
Project: incubator-netbeans   File: FileTreeView.java   Source Code and License Vote up 4 votes
@Override
public Icon getIcon (Object o) {
    Node n = Visualizer.findNode(o);
    return new ImageIcon(n.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16));
}
 
Example 12
Project: incubator-netbeans   File: CoverageReportTopComponent.java   Source Code and License Vote up 4 votes
public Component getTableCellRendererComponent(JTable table, Object value,
        boolean isSelected, boolean hasFocus, int row, int column) {
    if (value == null) {
        return new DefaultTableCellRenderer().getTableCellRendererComponent(table, value,
                isSelected, hasFocus, row, column);
    }

    if (isSelected) {
        super.setForeground(table.getSelectionForeground());
        super.setBackground(table.getSelectionBackground());
    } else {
        super.setForeground(table.getForeground());
        super.setBackground(table.getBackground());
    }

    setFont(table.getFont());

    if (hasFocus) {
        Border border = null;
        if (isSelected) {
            border = UIManager.getBorder("Table.focusSelectedCellHighlightBorder"); // NOI18N
        }
        if (border == null) {
            border = UIManager.getBorder("Table.focusCellHighlightBorder"); // NOI18N
        }
        setBorder(border);
    } else {
        setBorder(new EmptyBorder(1, 1, 1, 1));
    }


    FileCoverageSummary summary = (FileCoverageSummary) table.getValueAt(row, -1);
    FileObject file = summary.getFile();

    setText(summary.getDisplayName());
    if (file != null && file.isValid()) {
        try {
            DataObject dobj = DataObject.find(file);
            Node node = dobj.getNodeDelegate();
            Image icon = node.getIcon(BeanInfo.ICON_COLOR_32x32);
            setIcon(new ImageIcon(icon));
        } catch (DataObjectNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
    } else {
        setIcon(null);
    }


    return this;
}