Skip to content

ImageUtilities code cleanup#8235

Merged
mbien merged 1 commit intoapache:masterfrom
mbien:imageutilities-cleanup
Feb 12, 2025
Merged

ImageUtilities code cleanup#8235
mbien merged 1 commit intoapache:masterfrom
mbien:imageutilities-cleanup

Conversation

@mbien
Copy link
Copy Markdown
Member

@mbien mbien commented Feb 11, 2025

  • simplify if/else image loading cascade
  • remove redundant logger with same name
  • java 17 language level upgrade, dead code removal etc

to shrink my stash a bit :)

Originally I only intended to simplify the loading method and remove the logger - but there will be more eyes on this class due to all the usage refactoring so why not do a more complete cleanup. This might be easier to review in the IDE side-by-side view.

@mbien mbien added Code cleanup Label for cleanup done on the Netbeans IDE Platform [ci] enable platform tests (platform/*) UI User Interface labels Feb 11, 2025
@mbien mbien added this to the NB26 milestone Feb 11, 2025
@mbien mbien requested a review from eirikbakke February 11, 2025 23:47
Copy link
Copy Markdown
Contributor

@eirikbakke eirikbakke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, only question is whether we should also remove hashCode() from the two hashmap key classes that became records.

Comment thread platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
Comment thread platform/openide.util.ui/src/org/openide/util/ImageUtilities.java
 - simplify if/else image loading cascade
 - remove redundant logger with same name
 - java 17 language level upgrade, dead code removal etc
@mbien mbien force-pushed the imageutilities-cleanup branch from d7d2132 to e967887 Compare February 12, 2025 02:19
@mbien
Copy link
Copy Markdown
Member Author

mbien commented Feb 12, 2025

@eirikbakke btw while testing I noticed those log lines:

WARNING [org.openide.util.ImageUtilities]: loadImage(URI) called with unusual URI: nbres:/org/netbeans/modules/form/resources/palette/panel_16.png

seems to come from the form designer palette window.

the utility only accounts for nbresloc but not for nbres.

if (scheme.equals("nbresloc")) { // NOI18N
// Apply our dedicated handling logic. Omit the initial slash of the path.
return loadImage(uri.getPath().substring(1), false);
} else {
if (!(scheme.equals("file") ||
scheme.equals("jar") && uri.toString().startsWith("jar:file:") ||
scheme.equals("file")))
{
LOGGER.log(Level.WARNING, "loadImage(URI) called with unusual URI: {0}", uri);
}

@mbien
Copy link
Copy Markdown
Member Author

mbien commented Feb 12, 2025

checked a few things and everything worked -> merging

thanks for review @eirikbakke!

@eirikbakke
Copy link
Copy Markdown
Contributor

eirikbakke commented Feb 12, 2025

Nice catch regarding nbresloc vs. nbres! We should handle both. There is an explanation of the difference here:
https://netbeans.apache.org/wiki/main/netbeansdevelopperfaq/DevFaqUriVsUrl/

Apparently, nbresloc should use localization while nbres should not. So they should be handled the same except with a different second argument to loadImage(String,boolean).

Perhaps you could just add this as part of this PR? Maybe also update the Javadoc of loadImage(URI) to refer to say "nbres or nbresloc protocols" instead of just "nbresloc".

@mbien mbien merged commit b63567b into apache:master Feb 12, 2025
@mbien
Copy link
Copy Markdown
Member Author

mbien commented Feb 12, 2025

@eirikbakke oops I didn't see your message before merging. Lets add this in a separate PR to not mix cleanup with other changes.

@eirikbakke
Copy link
Copy Markdown
Contributor

Yeah, sure. I can make the PR and request your review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code cleanup Label for cleanup done on the Netbeans IDE Platform [ci] enable platform tests (platform/*) UI User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants