Skip to content

Commit aa80a48

Browse files
committed
More work on centralizing icon loading to ImageUtilities.
This is a follow-up on #8114 and #8109 . To render at full HiDPI resolution, Icon/Image instances must be created via the methods in ImageUtilities rather than, in particular, the constructors of ImageIcon. This PR, combined with the previously mentioned PRs, handles most of the remaining cases. Specifically: * Search for 'new ImageIcon(' and rewrite each case to use ImageUtilities to load icons instead. * Search for 'instanceof ImageIcon' and generalize to 'instanceof Icon' when appropriate. * Search for 'getLookAndFeel*getDisabledIcon' and switch to ImageUtilities.createDisabledIcon.
1 parent 4de8ce2 commit aa80a48

64 files changed

Lines changed: 204 additions & 447 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/InputDialog.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
4949
import org.openide.awt.Mnemonics;
5050
import org.openide.util.HelpCtx;
51+
import org.openide.util.ImageUtilities;
5152

5253

5354
/* A modal dialog object with Ok, Cancel, Help buttons and an optional required
@@ -287,7 +288,7 @@ public void showErrors() {
287288

288289
// Add warning message
289290
JLabel label = new JLabel();
290-
label.setIcon(Util.warningMessageIcon);
291+
label.setIcon(ImageUtilities.loadIcon("org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/resources/warningIcon.png"));
291292
label.setText("<html>" + message + "</html>"); // NOI18N
292293
label.getAccessibleContext().setAccessibleName(bundle.getString("ASCN_WarningMessage")); // NOI18N
293294
label.getAccessibleContext().setAccessibleDescription(message);
@@ -308,7 +309,7 @@ public void showErrors() {
308309

309310
// Add error message
310311
JLabel label = new JLabel();
311-
label.setIcon(Util.errorMessageIcon);
312+
label.setIcon(ImageUtilities.loadIcon("org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/resources/errorIcon.png"));
312313
label.setText("<html>" + message + "</html>"); // NOI18N
313314
label.getAccessibleContext().setAccessibleName(bundle.getString("ASCN_ErrorMessage")); // NOI18N
314315
label.getAccessibleContext().setAccessibleDescription(message);

enterprise/j2ee.sun.ddui/src/org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/Util.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@
2020
package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common;
2121

2222
import java.awt.Color;
23-
import javax.swing.ImageIcon;
2423
import javax.swing.UIManager;
25-
import org.netbeans.modules.j2ee.sun.share.configbean.Utils;
26-
import org.openide.ErrorManager;
2724

2825

2926
/**
@@ -35,34 +32,6 @@ public class Util {
3532
private Util() {
3633
}
3734

38-
/** Error/warning message icons.
39-
*/
40-
private static final String errorIconPath =
41-
"org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/resources/errorIcon.png"; // NOI18N
42-
private static final String warningIconPath =
43-
"org/netbeans/modules/j2ee/sun/share/configbean/customizers/common/resources/warningIcon.png"; // NOI18N
44-
45-
public static ImageIcon errorMessageIcon;
46-
public static ImageIcon warningMessageIcon;
47-
48-
static {
49-
// Diagnostic test code to try to get more information about a suspicious intermittant exception
50-
// (This is circa NB 4.1, so it may not be necessary anymore).
51-
try {
52-
errorMessageIcon = new ImageIcon(Utils.getResourceURL(errorIconPath, InputDialog.class));
53-
} catch(NullPointerException ex) {
54-
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
55-
errorMessageIcon = null;
56-
}
57-
try {
58-
warningMessageIcon = new ImageIcon(Utils.getResourceURL(warningIconPath, InputDialog.class));
59-
} catch(NullPointerException ex) {
60-
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
61-
warningMessageIcon = null;
62-
}
63-
}
64-
65-
6635
/** !PW Foreground color for error message text when in the NetBeans IDE.
6736
* See http://ui.netbeans.org/docs/inline_errors/index.html, about
6837
* halfway down, for specification. (Was light blue: [89, 79, 191])

enterprise/web.beans/src/org/netbeans/modules/web/beans/actions/InterceptorPanel.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,13 @@
2424
*/
2525
package org.netbeans.modules.web.beans.actions;
2626

27-
import java.net.MalformedURLException;
28-
import java.net.URL;
29-
30-
import javax.swing.ImageIcon;
3127
import javax.swing.JButton;
3228
import javax.swing.event.DocumentEvent;
3329
import javax.swing.event.DocumentListener;
3430
import javax.swing.text.BadLocationException;
3531

3632
import org.openide.filesystems.FileObject;
33+
import org.openide.util.ImageUtilities;
3734
import org.openide.util.NbBundle;
3835
import org.openide.util.Utilities;
3936

@@ -58,14 +55,7 @@ public InterceptorPanel( JButton approveButton, String bindingName,
5855
myInterceptorName.getDocument().addDocumentListener(
5956
createValidationListener( approveButton ) );
6057
myInterceptorName.setText( getProposedName() );
61-
URL errorUrl;
62-
try {
63-
errorUrl = new URL("nbresloc:/org/netbeans/modules/dialogs/error.gif");
64-
myStatusLbl.setIcon( new ImageIcon( errorUrl ));
65-
}
66-
catch (MalformedURLException e) {
67-
assert false;
68-
}
58+
myStatusLbl.setIcon(ImageUtilities.loadIcon("org/netbeans/modules/dialogs/error.gif"));
6959

7060
myStatusLbl.setVisible( false );
7161
}

enterprise/web.monitor/src/org/netbeans/modules/web/monitor/client/SortButton.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import java.awt.event.ActionListener;
2828
import java.util.logging.Logger;
2929
import javax.swing.Icon;
30-
import javax.swing.ImageIcon;
30+
import org.openide.util.ImageUtilities;
3131
import javax.swing.JButton;
3232

3333
import org.openide.util.NbBundle;
@@ -41,12 +41,9 @@ class SortButton extends JButton {
4141

4242
public SortButton(final DisplayTable dt) {
4343
super();
44-
icon[0] = new ImageIcon(TransactionView.class.getResource
45-
("/org/netbeans/modules/web/monitor/client/icons/unsorted.gif")); // NOI18N)
46-
icon[1] = new ImageIcon(TransactionView.class.getResource
47-
("/org/netbeans/modules/web/monitor/client/icons/a2z.gif")); // NOI18N
48-
icon[2] = new ImageIcon(TransactionView.class.getResource
49-
("/org/netbeans/modules/web/monitor/client/icons/z2a.gif")); // NOI18N
44+
icon[0] = ImageUtilities.loadIcon("org/netbeans/modules/web/monitor/client/icons/unsorted.gif"); // NOI18N)
45+
icon[1] = ImageUtilities.loadIcon("org/netbeans/modules/web/monitor/client/icons/a2z.gif"); // NOI18N
46+
icon[2] = ImageUtilities.loadIcon("org/netbeans/modules/web/monitor/client/icons/z2a.gif"); // NOI18N
5047
setIcon(icon[state]);
5148
setBorder(null);
5249
setBorderPainted(false);

enterprise/web.monitor/src/org/netbeans/modules/web/monitor/client/TransactionView.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import org.openide.util.NbBundle;
6262
import org.openide.util.RequestProcessor;
6363
import org.netbeans.modules.web.monitor.data.DataRecord;
64+
import org.openide.util.ImageUtilities;
6465

6566
/**
6667
* Update title does not work like it should. Maybe there is a getName
@@ -127,8 +128,7 @@ public HelpCtx getHelpCtx() {
127128
* retrieve any data until the Monitor is opened.
128129
*/
129130
private TransactionView() {
130-
setIcon(new ImageIcon(TransactionView.class.getResource
131-
("/org/netbeans/modules/web/monitor/client/icons/menuitem.gif")).getImage());
131+
setIcon(ImageUtilities.loadImage("org/netbeans/modules/web/monitor/client/icons/menuitem.gif"));
132132
setToolTipText(NbBundle.getMessage(TransactionView.class, "MON_Window_Tooltip"));
133133
controller = Controller.getInstance();
134134
initialize();
@@ -285,16 +285,16 @@ private void createLogPanel() {
285285
));
286286
buttonPanel.setFloatable (false);
287287

288-
JButton updateButton = new JButton(new ImageIcon(TransactionView.class.getResource
289-
("/org/netbeans/modules/web/monitor/client/icons/update.gif"))); // NOI18N
288+
JButton updateButton = new JButton(ImageUtilities.loadIcon(
289+
"org/netbeans/modules/web/monitor/client/icons/update.gif")); // NOI18N
290290
updateButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Reload_all_17"));
291291
updateButton.addActionListener(new ActionListener() {
292292
public void actionPerformed(ActionEvent e) {
293293
controller.getTransactions();
294294
}});
295295

296-
timeAButton = new JToggleButton(new ImageIcon(
297-
TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/timesortA.gif")), false);
296+
timeAButton = new JToggleButton(ImageUtilities.loadIcon(
297+
"org/netbeans/modules/web/monitor/client/icons/timesortA.gif"), false);
298298
timeAButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Order_transactions_15"));
299299

300300
timeAButton.addActionListener(new ActionListener() {
@@ -310,8 +310,8 @@ public void actionPerformed(ActionEvent e) {
310310
}
311311
}});
312312

313-
timeDButton = new JToggleButton(new ImageIcon(
314-
TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/timesortB.gif")), true);
313+
timeDButton = new JToggleButton(ImageUtilities.loadIcon(
314+
"org/netbeans/modules/web/monitor/client/icons/timesortB.gif"), true);
315315
timeDButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Order_transactions_16"));
316316
timeDButton.addActionListener(new ActionListener() {
317317
public void actionPerformed(ActionEvent e) {
@@ -327,8 +327,8 @@ public void actionPerformed(ActionEvent e) {
327327

328328
}});
329329

330-
alphaButton = new JToggleButton(new ImageIcon(
331-
TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/a2z.gif")), false);
330+
alphaButton = new JToggleButton(ImageUtilities.loadIcon(
331+
"org/netbeans/modules/web/monitor/client/icons/a2z.gif"), false);
332332
alphaButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Order_transactions_14"));
333333
alphaButton.addActionListener(new ActionListener() {
334334
public void actionPerformed(ActionEvent e) {
@@ -345,10 +345,9 @@ public void actionPerformed(ActionEvent e) {
345345
}});
346346

347347

348-
timestampButton = new
349-
JToggleButton(new ImageIcon(
350-
TransactionView.class.getResource("/org/netbeans/modules/web/monitor/client/icons/timestamp.gif")),
351-
TransactionNode.showTimeStamp());
348+
timestampButton = new JToggleButton(
349+
ImageUtilities.loadIcon("org/netbeans/modules/web/monitor/client/icons/timestamp.gif"),
350+
TransactionNode.showTimeStamp());
352351
timestampButton.setToolTipText(NbBundle.getBundle(TransactionView.class).getString("MON_Show_time_25"));
353352
timestampButton.addActionListener(new ActionListener() {
354353
public void actionPerformed(ActionEvent e) {

enterprise/websvc.design/src/org/netbeans/modules/websvc/design/view/widget/ButtonWidget.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import java.util.HashMap;
3737
import java.util.Map;
3838
import javax.swing.Action;
39-
import javax.swing.ImageIcon;
39+
import javax.swing.Icon;
4040
import javax.swing.JButton;
4141
import org.netbeans.api.visual.action.ActionFactory;
4242
import org.netbeans.api.visual.action.SelectProvider;
@@ -47,6 +47,7 @@
4747
import org.netbeans.api.visual.model.ObjectState;
4848
import org.netbeans.api.visual.widget.Scene;
4949
import org.netbeans.api.visual.widget.Widget;
50+
import org.openide.util.ImageUtilities;
5051

5152
/**
5253
* @author Ajit Bhate
@@ -261,7 +262,7 @@ private static String getActionName(Action action) {
261262

262263
private static Image getActionIcon(Action action) {
263264
Object icon = action.getValue(Action.SMALL_ICON);
264-
return (icon instanceof ImageIcon ? ((ImageIcon)icon).getImage(): null);
265+
return (icon instanceof Icon ? ImageUtilities.icon2Image((Icon)icon): null);
265266
}
266267

267268
private static String getActionTooltip(Action action) {

extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/loader/AntActionInstance.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,9 @@
2626
import java.io.File;
2727
import java.io.IOException;
2828
import java.io.ObjectInputStream;
29-
import java.net.MalformedURLException;
30-
import java.net.URL;
3129
import java.util.Arrays;
3230
import javax.swing.AbstractAction;
3331
import javax.swing.Action;
34-
import javax.swing.ImageIcon;
3532
import javax.swing.JButton;
3633
import javax.swing.JComponent;
3734
import javax.swing.JMenuItem;
@@ -49,6 +46,7 @@
4946
import org.openide.cookies.InstanceCookie;
5047
import org.openide.filesystems.FileObject;
5148
import org.openide.filesystems.FileUtil;
49+
import org.openide.util.ImageUtilities;
5250
import org.openide.util.actions.Presenter;
5351
import org.openide.util.RequestProcessor;
5452
import org.openide.util.WeakListeners;
@@ -163,11 +161,7 @@ public void run() {
163161
return Actions.cutAmpersand(pname);
164162
}
165163
} else if (Action.SMALL_ICON.equals (key)) {
166-
try {
167-
return new ImageIcon(new URL("nbresloc:/org/apache/tools/ant/module/resources/AntIcon.gif"));
168-
} catch (MalformedURLException e) {
169-
throw new AssertionError(e);
170-
}
164+
return ImageUtilities.loadImageIcon("org/apache/tools/ant/module/resources/AntIcon.gif", false);
171165
} else if (Action.MNEMONIC_KEY.equals (key)) {
172166
Element el = proj.getProjectElement ();
173167
if (el != null) {

extide/o.apache.tools.ant.module/src/org/apache/tools/ant/module/run/TargetExecutor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import org.openide.filesystems.FileRenameEvent;
6565
import org.openide.filesystems.FileUtil;
6666
import org.openide.util.Cancellable;
67+
import org.openide.util.ImageUtilities;
6768
import org.openide.util.Mutex;
6869
import org.openide.util.NbBundle;
6970
import org.openide.util.Pair;
@@ -203,7 +204,7 @@ public StopAction() {
203204
@Override
204205
public Object getValue(String key) {
205206
if (key.equals(Action.SMALL_ICON)) {
206-
return new ImageIcon(TargetExecutor.class.getResource("/org/apache/tools/ant/module/resources/stop.png"));
207+
return ImageUtilities.loadImageIcon("org/apache/tools/ant/module/resources/stop.png", false);
207208
} else if (key.equals(Action.SHORT_DESCRIPTION)) {
208209
return NbBundle.getMessage(TargetExecutor.class, "TargetExecutor.StopAction.stop");
209210
} else {
@@ -259,9 +260,9 @@ private void reinit(TargetExecutor prototype) {
259260
public Object getValue(String key) {
260261
if (key.equals(Action.SMALL_ICON)) {
261262
if (withModifications) {
262-
return new ImageIcon(TargetExecutor.class.getResource("/org/apache/tools/ant/module/resources/rerun-mod.png"));
263+
return ImageUtilities.loadImageIcon("org/apache/tools/ant/module/resources/rerun-mod.png", false);
263264
} else {
264-
return new ImageIcon(TargetExecutor.class.getResource("/org/apache/tools/ant/module/resources/rerun.png"));
265+
return ImageUtilities.loadImageIcon("org/apache/tools/ant/module/resources/rerun.png", false);
265266
}
266267
} else if (key.equals(Action.SHORT_DESCRIPTION)) {
267268
if (withModifications) {
@@ -332,7 +333,7 @@ private static final class OptionsAction extends AbstractAction { // #59396
332333
@Override
333334
public Object getValue(String key) {
334335
if (key.equals(Action.SMALL_ICON)) {
335-
return new ImageIcon(TargetExecutor.class.getResource("/org/apache/tools/ant/module/resources/options.png"));
336+
return ImageUtilities.loadImageIcon("org/apache/tools/ant/module/resources/options.png", false);
336337
} else if (key.equals(Action.SHORT_DESCRIPTION)) {
337338
return NbBundle.getMessage(TargetExecutor.class, "TargetExecutor.OptionsAction");
338339
} else {

ide/csl.api/src/org/netbeans/modules/csl/editor/completion/GsfCompletionItem.java

Lines changed: 0 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -237,88 +237,8 @@ protected ImageIcon getIcon() {
237237
ImageIcon imageIcon = org.netbeans.modules.csl.navigation.Icons.getElementIcon(item.getKind(), item.getModifiers());
238238
// TODO - cache!
239239
return imageIcon;
240-
//
241-
//
242-
// ElementKind kind = item.getKind();
243-
// switch (kind) {
244-
// case CONSTRUCTOR:
245-
// case METHOD:
246-
// return getMethodIcon();
247-
// case ATTRIBUTE:
248-
// case FIELD:
249-
// return getFieldIcon();
250-
// case CLASS:
251-
// case INTERFACE:
252-
// return getClassIcon();
253-
// case MODULE:
254-
// return getModuleIcon();
255-
// case CONSTANT:
256-
// return getConstantIcon();
257-
// case VARIABLE:
258-
// return getVariableIcon();
259-
// case KEYWORD:
260-
// return getKeywordIcon();
261-
// case OTHER:
262-
// }
263-
//
264-
// return null;
265240
}
266241

267-
// protected ImageIcon getMethodIcon() {
268-
// Set<Modifier> modifiers = item.getModifiers();
269-
//
270-
// boolean isStatic = modifiers.contains(Modifier.STATIC);
271-
//// int level = getProtectionLevel(elem.getModifiers());
272-
//
273-
// ImageIcon cachedIcon = icon[isStatic?1:0][level];
274-
// if (cachedIcon != null) {
275-
// return cachedIcon;
276-
// }
277-
//
278-
// String iconPath = METHOD_PUBLIC;
279-
// if (isStatic) {
280-
// switch (level) {
281-
// case PRIVATE_LEVEL:
282-
// iconPath = METHOD_ST_PRIVATE;
283-
// break;
284-
//
285-
// case PACKAGE_LEVEL:
286-
// iconPath = METHOD_ST_PACKAGE;
287-
// break;
288-
//
289-
// case PROTECTED_LEVEL:
290-
// iconPath = METHOD_ST_PROTECTED;
291-
// break;
292-
//
293-
// case PUBLIC_LEVEL:
294-
// iconPath = METHOD_ST_PUBLIC;
295-
// break;
296-
// }
297-
// }else{
298-
// switch (level) {
299-
// case PRIVATE_LEVEL:
300-
// iconPath = METHOD_PRIVATE;
301-
// break;
302-
//
303-
// case PACKAGE_LEVEL:
304-
// iconPath = METHOD_PACKAGE;
305-
// break;
306-
//
307-
// case PROTECTED_LEVEL:
308-
// iconPath = METHOD_PROTECTED;
309-
// break;
310-
//
311-
// case PUBLIC_LEVEL:
312-
// iconPath = METHOD_PUBLIC;
313-
// break;
314-
// }
315-
// }
316-
// ImageIcon newIcon = new ImageIcon(org.openide.util.Utilities.loadImage(iconPath));
317-
// icon[isStatic?1:0][level] = newIcon;
318-
// return newIcon;
319-
// }
320-
321-
322242
@Override
323243
protected void substituteText(final JTextComponent c, int offset, int len, String toAdd) {
324244
if (completionResult != null) {

0 commit comments

Comments
 (0)