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

The following examples show how to use org.openide.nodes.Node#getIcon() . 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: IconPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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
Source File: SearchScopeNodeSelection.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 3
Source File: BookmarkNodeRenderer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: BreadCrumbComponent.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 5
Source File: UISupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Image computeIcon(ServerIcon serverIcon) {
    // get the default folder icon
    Node folderNode = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
    Image folder;
    if (serverIcon == ServerIcon.EJB_OPENED_FOLDER || serverIcon == ServerIcon.WAR_OPENED_FOLDER 
            || serverIcon == ServerIcon.EAR_OPENED_FOLDER) {
        folder = folderNode.getOpenedIcon(BeanInfo.ICON_COLOR_16x16);
    } else {
        folder = folderNode.getIcon(BeanInfo.ICON_COLOR_16x16);
    }
    Image badge;
    if (serverIcon == ServerIcon.EJB_FOLDER || serverIcon == ServerIcon.EJB_OPENED_FOLDER) {
        badge = ImageUtilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/ejbBadge.png"); // NOI18N
    } else if (serverIcon == ServerIcon.WAR_FOLDER || serverIcon == ServerIcon.WAR_OPENED_FOLDER) {
        badge = ImageUtilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/warBadge.png"); // NOI18N
    } else if (serverIcon == ServerIcon.EAR_FOLDER || serverIcon == ServerIcon.EAR_OPENED_FOLDER) {
        badge = ImageUtilities.loadImage("org/netbeans/modules/j2ee/deployment/impl/ui/resources/earBadge.png" ); // NOI18N
    } else {
        return null;
    }
    return ImageUtilities.mergeImages(folder, badge, 7, 7);
}
 
Example 6
Source File: UINodeTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 7
Source File: Hk2ItemNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a badge to an open or closed folder icon.
 * <p/>
 * @param badge  Badge image for folder.
 * @param opened Use open or closed folder.
 * @return An image of the badged folder.
 */
public static Image badgeFolder(Image badge, boolean opened) {
    Node folderNode = getIconDelegate();
    Image folder = opened
            ? folderNode.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)
            : folderNode.getIcon(BeanInfo.ICON_COLOR_16x16);
    return ImageUtilities.mergeImages(folder, badge, 7, 7);
}
 
Example 8
Source File: Hk2ItemNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Applies a badge to an open or closed folder icon.
 * <p/>
 * @param badge  Badge image for folder.
 * @param opened Use open or closed folder.
 * @return An image of the badged folder.
 */
public static Image badgeFolder(Image badge, boolean opened) {
    Node folderNode = getIconDelegate();
    Image folder = opened
            ? folderNode.getOpenedIcon(BeanInfo.ICON_COLOR_16x16)
            : folderNode.getIcon(BeanInfo.ICON_COLOR_16x16);
    return ImageUtilities.mergeImages(folder, badge, 7, 7);
}
 
Example 9
Source File: SystemFileSystemTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** @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
Source File: ServerResourceNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Image getIcon(int type) {
    Image image = null;
    Node imageDelegate = getImageDelegate();
    if (imageDelegate != null) {
        image = imageDelegate.getIcon(type);
    }
    if (image == null) {
        image = super.getIcon(type);
    }
    return image;
}
 
Example 11
Source File: ExitDialog.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@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 12
Source File: SystemFileSystemTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 13
Source File: AsynchronousTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 14
Source File: NodeRenderDataProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 ImageUtilities.image2Icon(image);
}
 
Example 15
Source File: CommandCompletionProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected ImageIcon getIcon() {
    if (insertText.endsWith("/")) { // NOI18N
        return ImageUtilities.loadImageIcon(ICON_FOLDER, false);
    } else if (fileResource != null) {
        return ImageUtilities.loadImageIcon(fileResource, true);
    } else if (icon != null) {
        return icon;
    } else {
        Path p = basePath.resolve(insertText);
        if (p != null) {
            FileObject f = FileUtil.toFileObject(p.toFile());
            if (f != null) {
                Node n;
                
                try {
                    DataObject d = DataObject.find(f);
                    n = d.getNodeDelegate();
                } catch (DataObjectNotFoundException ex) {
                    n = f.getLookup().lookup(Node.class);
                }
                if (n != null) {
                    return new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
                }
            }
        }
        return icon = ImageUtilities.loadImageIcon(ICON_FILE, false);
    }
}
 
Example 16
Source File: ArchiveViews.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Image computeIcon( boolean opened, int type ) {
    Node folderNode = getOriginal();
    Image image = opened ? folderNode.getOpenedIcon( type ) : folderNode.getIcon( type );
    return ImageUtilities.mergeImages( image, CONFIGURATION_FILES_BADGE, 7, 7 );
}
 
Example 17
Source File: J2eeProjectView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private Image computeIcon( boolean opened, int type ) {
    Node folderNode = getOriginal();
    Image image = opened ? folderNode.getOpenedIcon( type ) : folderNode.getIcon( type );
    return ImageUtilities.mergeImages( image, CONFIGURATION_FILES_BADGE, 7, 7 );
}
 
Example 18
Source File: FileTreeView.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Icon getIcon (Object o) {
    Node n = Visualizer.findNode(o);
    return new ImageIcon(n.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16));
}
 
Example 19
Source File: CoverageReportTopComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
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;
}