-
Notifications
You must be signed in to change notification settings - Fork 868
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
More work on centralizing icon loading to ImageUtilities #8194
base: master
Are you sure you want to change the base?
Conversation
d1f3095
to
26e9b10
Compare
This is a follow-up on apache#8114 and apache#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.
26e9b10
to
5d2e131
Compare
…orms that were constructed with the Matisse form builder. (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.) These cases were put in a separate commit since they involved re-generation of auto-generated code. To keep the patch simple, I excluded some reformatting of unrelated code that Matisse did when regenerating initComponents().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. Wondering if you considered using jackpot for (some of) the migration rules?
enterprise/web.monitor/src/org/netbeans/modules/web/monitor/client/TransactionView.java
Show resolved
Hide resolved
...ml.editor/src/org/netbeans/modules/html/editor/completion/HtmlPaletteCompletionProvider.java
Outdated
Show resolved
Hide resolved
@mbien Didn't know about Jackpot rules! I did these edits manually, in particular since there were a lot of small variations in how loading was done or how simplifications could be made. In any case I think this is the last batch of bulk changes to ImageIcon-related stuff. |
yeah I didn't mention it earlier for that reason. But jackpot rules can be quite useful sometimes and I feel not enough know about them - so I make sure to point that out when the opportunity arises ;) They could be also put into the meta-inf of a module and used to help with migration third party code too. For personal use, they can be put into conf/rules. I have a bunch of them active most of the time. for example try putting this into a hint file in conf/rules and open new javax.swing.ImageIcon(org.openide.util.ImageUtilities.mergeImages($a.getImage(), $b.getImage(), $c, $d))
=>
org.openide.util.ImageUtilities.icon2ImageIcon(org.openide.util.ImageUtilities.mergeIcons($a, $b, $c, $d))
;; |
@mbien Oh, that's neat! I got that to work. Note that the folder in the home directory is called "config" rather than "conf", at least in my case. (Would also be useful in your readme to say "config/rules/" with a slash at the end to make it clear that I know it's off-topic but there's one Jackpot rule I would love to have, which is similar to "Assign Return Value to New Variable", except using the return value as an iterable for a for loop. E.g. "Iterate over Expression in for Loop":
becomes
Is that a rule you would know how to write off the top of your head? (Ideally it would work when FooType has generic parameters, too.) |
thanks for pointing this out. will fix it.
this might be difficult to do with the hint files. But NB has a template which comes really close to what you want. type |
@mbien Oh, that works! I learned a new NetBeans feature today... |
This is a follow-up on the separate work in #8114 and #8109 . To render at full HiDPI resolution, with SVG icon substitutions where available, 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:
new ImageIcon(
and rewrite each relevant case to useImageUtilities
to load icons instead.new ImageIcon(SomeClassInCurrentModule.class.getResource("/package/folders/path/to/icon.png"))
toImageUtilities.loadIcon("package/folders/path/to/icon.png")
. I verified visually in the IDE that this worked in one case (the Print dialog), to make sure this is a valid transformation. In cases where a relative path was previously used, I replaced it with an absolute path that I looked up manually (this page is helpful for this). Note that ImageUtilities does not want leading slashes.instanceof ImageIcon
and generalize toinstanceof Icon
when appropriate.getLookAndFeel*getDisabledIcon
and switch toImageUtilities.createDisabledIcon
.loadImageIcon("/
and remove the leading slash in some cases (which would produce a warning log entry). Also switch to loadIcon if possible if I'm already changing these lines.Places where uses of
new ImageIcon
were left unmodified include:Icon
instances.It'll be good to test these changes in development builds for a while, in case icon loading breaks accidentally somewhere. I'll start doing so in my own working IDE now. (I already tested the separate changes in #8109 for three weeks.)