Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid remaining trivial uses of new ImageIcon(Image), for HiDPI icons #8109

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ private final class Info implements ProjectInformation {

@Override
public Icon getIcon() {
Image image = ImageUtilities.loadImage(GrailsConstants.GRAILS_ICON_16x16);
return image == null ? null : new ImageIcon(image);
return ImageUtilities.loadIcon(GrailsConstants.GRAILS_ICON_16x16);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public Image getOpenedIcon( int type ) {
static synchronized Icon getFolderIcon (boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public CustomSectionNodePanel(final SectionNode node) {
}

public void setTitleIcon(String iconBase) {
Image iconImage = ImageUtilities.loadImage(iconBase, true);
getTitleButton().setIcon(iconImage != null ? new ImageIcon(iconImage) : null);
getTitleButton().setIcon(ImageUtilities.loadImageIcon(iconBase, true));
}

// @Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import org.openide.awt.NotificationDisplayer;
import org.openide.awt.NotificationDisplayer.Category;
Expand All @@ -44,7 +43,7 @@ public static void showChangelog() {
int version = Integer.parseInt(NbBundle.getMessage(ChangelogWildflyPlugin.class, VERSION_PREF));
if (prefs.getInt(VERSION_PREF, 5) < version) {
NotificationDisplayer.getDefault().notify(NbBundle.getMessage(ChangelogWildflyPlugin.class, "MSG_CHANGES_TITLE"),
new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/javaee/wildfly/resources/wildfly.png")),
ImageUtilities.loadImageIcon("org/netbeans/modules/javaee/wildfly/resources/wildfly.png", false),
new JLabel(NbBundle.getMessage(ChangelogWildflyPlugin.class, "MSG_CHANGES_SUMMARY")),
new JLabel(NbBundle.getMessage(ChangelogWildflyPlugin.class, "MSG_CHANGES_DESC")),
NotificationDisplayer.Priority.NORMAL, Category.INFO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private java.awt.Image getServicesImage() {
private Icon getFolderIcon (boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ private java.awt.Image getServicesImage() {
private Icon getFolderIcon (boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
package org.netbeans.modules.web.jsf.navigation;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
Expand All @@ -44,7 +43,7 @@
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import org.openide.util.ImageUtilities;
Expand Down Expand Up @@ -194,7 +193,7 @@ public void itemStateChanged(ItemEvent event) {
scopeBox = comboBox;
return comboBox;
}
private static final Image LAYOUT_ICON = ImageUtilities.loadImage("org/netbeans/modules/web/jsf/navigation/resources/navigation.gif"); // NOI18N
private static final Icon LAYOUT_ICON = ImageUtilities.loadIcon("org/netbeans/modules/web/jsf/navigation/resources/navigation.gif"); // NOI18N
private JButton layoutButton = null;

/**
Expand All @@ -209,7 +208,7 @@ public JButton createLayoutButton() {
return layoutButton;
}

layoutButton = new JButton(new ImageIcon(LAYOUT_ICON));
layoutButton = new JButton(LAYOUT_ICON);
//Set the appropriate size of the combo box so it doesn't take up the whole page.
// Dimension prefSize = layoutButton.getPreferredSize();
// layoutButton.setMinimumSize(prefSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ private java.awt.Image getServicesImage() {
private Icon getFolderIcon(boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ private java.awt.Image getServicesImage() {
private Icon getFolderIcon (boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ private java.awt.Image getServicesImage() {
private Icon getFolderIcon (boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.netbeans.modules.websvc.design.view;

import java.awt.Dimension;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
Expand All @@ -30,7 +29,7 @@
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JScrollPane;
Expand All @@ -41,7 +40,6 @@
import org.netbeans.api.visual.widget.Scene;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;

/**
* Manages the zoom level for a particular Scene instance.
Expand Down Expand Up @@ -497,9 +495,9 @@ public FitDiagramAction(ZoomManager manager) {
this.manager = manager;
String path = NbBundle.getMessage(FitDiagramAction.class,
"IMG_FitDiagramAction");
Image img = ImageUtilities.loadImage(path);
if (img != null) {
putValue(Action.SMALL_ICON, new ImageIcon(img));
Icon icon = ImageUtilities.loadIcon(path);
if (icon != null) {
putValue(Action.SMALL_ICON, icon);
}
String desc = NbBundle.getMessage(FitDiagramAction.class,
"LBL_FitDiagramAction");
Expand Down Expand Up @@ -543,9 +541,9 @@ public FitWidthAction(ZoomManager manager) {
this.manager = manager;
String path = NbBundle.getMessage(FitWidthAction.class,
"IMG_FitWidthAction");
Image img = ImageUtilities.loadImage(path);
if (img != null) {
putValue(Action.SMALL_ICON, new ImageIcon(img));
Icon icon = ImageUtilities.loadIcon(path);
if (icon != null) {
putValue(Action.SMALL_ICON, icon);
}
String desc = NbBundle.getMessage(FitWidthAction.class,
"LBL_FitWidthAction");
Expand Down Expand Up @@ -586,9 +584,9 @@ public ZoomDefaultAction(ZoomManager manager) {
this.manager = manager;
String path = NbBundle.getMessage(ZoomDefaultAction.class,
"IMG_ZoomDefaultAction");
Image img = ImageUtilities.loadImage(path);
if (img != null) {
putValue(Action.SMALL_ICON, new ImageIcon(img));
Icon icon = ImageUtilities.loadIcon(path);
if (icon != null) {
putValue(Action.SMALL_ICON, icon);
}
String desc = NbBundle.getMessage(ZoomDefaultAction.class,
"LBL_ZoomDefaultAction");
Expand Down Expand Up @@ -618,9 +616,9 @@ public ZoomInAction(ZoomManager manager) {
this.manager = manager;
String path = NbBundle.getMessage(ZoomInAction.class,
"IMG_ZoomInAction");
Image img = ImageUtilities.loadImage(path);
if (img != null) {
putValue(Action.SMALL_ICON, new ImageIcon(img));
Icon icon = ImageUtilities.loadIcon(path);
if (icon != null) {
putValue(Action.SMALL_ICON, icon);
}
String desc = NbBundle.getMessage(ZoomInAction.class,
"LBL_ZoomInAction");
Expand Down Expand Up @@ -657,9 +655,9 @@ public ZoomOutAction(ZoomManager manager) {
this.manager = manager;
String path = NbBundle.getMessage(ZoomOutAction.class,
"IMG_ZoomOutAction");
Image img = ImageUtilities.loadImage(path);
if (img != null) {
putValue(Action.SMALL_ICON, new ImageIcon(img));
Icon icon = ImageUtilities.loadIcon(path);
if (icon != null) {
putValue(Action.SMALL_ICON, icon);
}
String desc = NbBundle.getMessage(ZoomOutAction.class,
"LBL_ZoomOutAction");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public Image getOpenedIcon( int type ) {
static synchronized Icon getFolderIcon (boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public Image getOpenedIcon(int type) {
static synchronized Icon getFolderIcon(boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public Image getOpenedIcon( int type ) {
static synchronized Icon getFolderIcon (boolean opened) {
if (openedFolderIconCache == null) {
Node n = DataFolder.findFolder(FileUtil.getConfigRoot()).getNodeDelegate();
openedFolderIconCache = new ImageIcon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = new ImageIcon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
openedFolderIconCache = ImageUtilities.image2Icon(n.getOpenedIcon(BeanInfo.ICON_COLOR_16x16));
folderIconCache = ImageUtilities.image2Icon(n.getIcon(BeanInfo.ICON_COLOR_16x16));
}
if (opened) {
return openedFolderIconCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void setupScope() {
} catch (DataObjectNotFoundException ex) {
} // Not important, only for Icon.
customScope = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CustomScope"), pi.getIcon(), SwingConstants.LEFT); //NOI18N
currentFile = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CurrentFile", fo.getNameExt()), currentFileDo != null ? new ImageIcon(currentFileDo.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)) : pi.getIcon(), SwingConstants.LEFT); //NOI18N
currentFile = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CurrentFile", fo.getNameExt()), currentFileDo != null ? ImageUtilities.image2Icon(currentFileDo.getNodeDelegate().getIcon(BeanInfo.ICON_COLOR_16x16)) : pi.getIcon(), SwingConstants.LEFT); //NOI18N
currentPackage = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CurrentPackage", packageName), ImageUtilities.loadImageIcon(PACKAGE, false), SwingConstants.LEFT); //NOI18N
currentProject = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_CurrentProject", pi.getDisplayName()), pi.getIcon(), SwingConstants.LEFT); //NOI18N
allProjects = new JLabel(NbBundle.getMessage(WhereUsedPanel.class, "LBL_AllProjects"), pi.getIcon(), SwingConstants.LEFT); //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public void requestFocus() {
if (borderColor == null) borderColor = UIManager.getColor("controlShadow"); // NOI18N
tableScrollPane.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, borderColor));

ImageIcon ic = new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/bugtracking/commons/resources/columns_16.png", true)); // NOI18N
ImageIcon ic = ImageUtilities.loadImageIcon("org/netbeans/modules/bugtracking/commons/resources/columns_16.png", true); // NOI18N
colsButton = new javax.swing.JButton(ic);
colsButton.getAccessibleContext().setAccessibleName(NbBundle.getMessage(TreeTableView.class, "ACN_ColumnsSelector")); //NOI18N
colsButton.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(TreeTableView.class, "ACD_ColumnsSelector")); //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class QueryTableCellRenderer extends DefaultTableCellRenderer {
private final IssueTable issueTable;

private static final int VISIBLE_START_CHARS = 0;
private static final Icon seenValueIcon = new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/bugtracking/commons/resources/seen-value.png")); // NOI18N
private static final Icon seenValueIcon = ImageUtilities.loadIcon("org/netbeans/modules/bugtracking/commons/resources/seen-value.png"); // NOI18N

private static final MessageFormat issueNewFormat = getFormat("issueNewFormat", UIUtils.getTaskNewColor()); //NOI18N
private static final MessageFormat issueObsoleteFormat = getFormat("issueObsoleteFormat", UIUtils.getTaskObsoleteColor()); //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class QueryTableHeaderRenderer extends DefaultTableCellRenderer {

private final JLabel seenCell = new JLabel();

private static final Icon seenHeaderIcon = new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/bugtracking/commons/resources/seen-header.png")); // NOI18N
private static final Icon seenHeaderIcon = ImageUtilities.loadIcon("org/netbeans/modules/bugtracking/commons/resources/seen-header.png"); // NOI18N
private final TableCellRenderer delegate;
private final IssueTable issueTable;
private boolean isSaved;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public int compare(Object o1, Object o2) {
}
};

private final Icon ICON_ASCENDING = new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/openide/explorer/columnsSortedAsc.gif", true)); // NOI18N
private final Icon ICON_DESCENDING = new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/openide/explorer/columnsSortedDesc.gif", true)); // NOI18N
private final Icon ICON_ASCENDING = ImageUtilities.loadImageIcon("org/netbeans/modules/openide/explorer/columnsSortedAsc.gif", true); // NOI18N
private final Icon ICON_DESCENDING = ImageUtilities.loadImageIcon("org/netbeans/modules/openide/explorer/columnsSortedDesc.gif", true); // NOI18N

private Row[] viewToModel;
private int[] modelToView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ErrorNode(String text, Action refreshAction) {
this.defaultAction = refreshAction;
btnRefresh = new LinkButton(NbBundle.getMessage(ErrorNode.class, "LBL_Retry"), refreshAction); //NOI18N
lblMessage = new TreeLabel(text);
lblMessage.setIcon(new ImageIcon(ImageUtilities.loadImage("org/netbeans/modules/bugtracking/tasks/resources/error.png"))); //NOI18N
lblMessage.setIcon(ImageUtilities.loadImageIcon("org/netbeans/modules/bugtracking/tasks/resources/error.png", false)); //NOI18N
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,13 @@ Collection<QueryImpl> getQueries() {
return repository.getQueries();
}

ImageIcon getIcon() {
Icon getIcon() {
Image icon = repository.getIcon();
ImageIcon imageIcon;
if (icon == null) {
imageIcon = ImageUtilities.loadImageIcon("org/netbeans/modules/bugtracking/tasks/resources/remote_repo.png", true);
return ImageUtilities.loadImageIcon("org/netbeans/modules/bugtracking/tasks/resources/remote_repo.png", true);
} else {
imageIcon = new ImageIcon(icon);
return ImageUtilities.image2Icon(icon);
}
return imageIcon;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.awt.Image;
import javax.swing.DefaultListCellRenderer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import org.netbeans.modules.bugtracking.RepositoryImpl;
import org.netbeans.modules.bugtracking.api.Repository;
import org.openide.util.ImageUtilities;
import org.openide.util.NbBundle;

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ public Component getListCellRendererComponent(JList list, Object value, int inde
if(icon instanceof Icon) {
label.setIcon((Icon) icon);
} else if(icon instanceof Image) {
label.setIcon(new ImageIcon(icon));
label.setIcon(ImageUtilities.image2Icon(icon));
}
} else {
Font font = label.getFont();
Expand Down
Loading
Loading