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 ImageIcon use in more places, to preserve HiDPI icon resolution #7472

Merged
merged 1 commit into from
Jul 2, 2024
Merged
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 @@ -46,14 +46,14 @@ public abstract class NotificationDisplayer {
* Priority of Notification
*/
public static enum Priority {
HIGH(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_high.png"))), //NOI18N
NORMAL(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_normal.png"))), //NOI18N
LOW(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_low.png"))), //NOI18N
HIGH(ImageUtilities.image2Icon(ImageUtilities.loadImage("org/openide/awt/resources/priority_high.png"))), //NOI18N
NORMAL(ImageUtilities.image2Icon(ImageUtilities.loadImage("org/openide/awt/resources/priority_normal.png"))), //NOI18N
LOW(ImageUtilities.image2Icon(ImageUtilities.loadImage("org/openide/awt/resources/priority_low.png"))), //NOI18N
/** Priority that shows the notification without details.
* Details shall be shown only later, per user request.
* @since 7.18
*/
SILENT(new ImageIcon(ImageUtilities.loadImage("org/openide/awt/resources/priority_silent.png"))); //NOI18N
SILENT(ImageUtilities.image2Icon(ImageUtilities.loadImage("org/openide/awt/resources/priority_silent.png"))); //NOI18N

private final Icon icon;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.awt.event.MouseListener;
import javax.accessibility.AccessibleRole;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JComponent.AccessibleJComponent;
Expand Down Expand Up @@ -114,7 +113,7 @@ private void init() {
} else {
Image help = ImageUtilities.loadImage("org/openide/resources/propertysheet/propertySheetHelp.png", true); //NOI18N

btn = new JButton(new ImageIcon(help));
btn = new JButton(ImageUtilities.image2Icon(help));
btn.addActionListener(this);

toolbar = new JToolBar ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import org.openide.nodes.Node.Property;
import org.openide.util.ImageUtilities;
import org.openide.util.Utilities;

import java.awt.Color;
import java.awt.Component;
Expand Down Expand Up @@ -507,7 +506,7 @@ private InplaceEditor createInplaceEditor() {
Object o = getProperty().getValue("valueIcon"); //NOI18N

if (o instanceof Image) {
ic = new ImageIcon((Image) o);
ic = ImageUtilities.image2Icon((Image) o);
} else {
ic = (Icon) o;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
Expand All @@ -66,7 +65,6 @@
import org.openide.awt.HtmlRenderer;
import org.openide.nodes.Node.Property;
import org.openide.util.ImageUtilities;
import org.openide.util.Utilities;
import org.openide.util.WeakListeners;

/**
Expand Down Expand Up @@ -972,7 +970,7 @@ public void reset() {
}

if (i != null) {
setIcon(new ImageIcon(i));
setIcon(ImageUtilities.image2Icon(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import org.openide.util.ImageUtilities;


/** An implementation of SheetCellRenderer that wraps custom InplaceEditors
Expand Down Expand Up @@ -123,7 +124,7 @@ public Component getTableCellRendererComponent(
if (o instanceof Icon) {
lbl.setIcon((Icon) o);
} else if (o instanceof Image) {
lbl.setIcon(new ImageIcon((Image) o));
lbl.setIcon(ImageUtilities.image2Icon((Image) o));
} else {
lbl.setIcon(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@

import java.io.*;

import java.net.URL;

import java.util.*;

import javax.swing.*;
import javax.swing.event.*;
import org.openide.util.ImageUtilities;


/** An explorer view that shows the context hierarchy in
Expand Down Expand Up @@ -524,7 +522,7 @@ public void doClick(int time) {
static void initialize(final JMenuItem item, final Node node) {
final class NI implements Runnable, NodeListener, ItemListener {
public void run() {
item.setIcon(new ImageIcon(node.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16)));
item.setIcon(ImageUtilities.image2Icon(node.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16)));
item.setText(node.getDisplayName());

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public Item(DataObject template) {
if (template == null) {
setIcon (NewTemplateAction.this.getIcon());
} else {
setIcon (new ImageIcon(template.getNodeDelegate().getIcon(java.beans.BeanInfo.ICON_COLOR_16x16)));
setIcon (ImageUtilities.image2Icon(template.getNodeDelegate().getIcon(java.beans.BeanInfo.ICON_COLOR_16x16)));
}

addActionListener(this);
Expand Down
12 changes: 4 additions & 8 deletions platform/openide.loaders/src/org/openide/awt/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.logging.Logger;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JMenu;
Expand All @@ -63,6 +62,7 @@
import org.openide.nodes.NodeMemberEvent;
import org.openide.nodes.NodeReorderEvent;
import org.openide.util.Exceptions;
import org.openide.util.ImageUtilities;
import org.openide.util.Mutex;
import org.openide.util.NbBundle;
import org.openide.util.Task;
Expand Down Expand Up @@ -99,11 +99,6 @@ public class MenuBar extends JMenuBar implements Externalizable {
/** the folder which represents and loads content of the menubar */
private MenuBarFolder menuBarFolder;

/*
private static final Icon BLANK_ICON = new ImageIcon(
Utilities.loadImage("org/openide/loaders/empty.gif")); // NOI18N
*/

static final long serialVersionUID =-4721949937356581268L;
static {
try {
Expand Down Expand Up @@ -656,8 +651,9 @@ private void updateProps() {
// set the text and be aware of mnemonics
Node n = master.getNodeDelegate ();
Mnemonics.setLocalizedText(this, n.getDisplayName());
if (icon) setIcon (new ImageIcon (
n.getIcon (java.beans.BeanInfo.ICON_COLOR_16x16)));
if (icon) {
setIcon(ImageUtilities.image2Icon(n.getIcon(java.beans.BeanInfo.ICON_COLOR_16x16)));
}
} else {
setText(master.getName());
setIcon(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.beans.PropertyChangeListener;
import java.util.Collection;
import javax.swing.Action;
import javax.swing.ImageIcon;

/**
* An action which operates in the global <i>selection context</i> (a
Expand Down Expand Up @@ -172,7 +171,7 @@ protected ContextAction(Class<T> type, String displayName, Image icon) {
putValue (Action.NAME, displayName);
}
if (icon != null) {
putValue (Action.SMALL_ICON, new ImageIcon (icon));
putValue (Action.SMALL_ICON, ImageUtilities.image2Icon(icon));
}
putValue ("noIconInMenu", true);
}
Expand Down
Loading