dustinkredmond / FXTrayIcon

Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.
MIT License
327 stars 26 forks source link

FXTrayIcon constructor with Image arg and setGraphic overload #19

Closed atelechev closed 3 years ago

atelechev commented 3 years ago

Hello Dustin,

Thank you very much for this compact and useful FXTrayIcon project!

I'm going to use your lib in my project and would like to suggest a minor adjustment for the API of the FXTrayIcon object.

Use Case

The use case is the following: there are several images pre-loaded from local files and stored in an object. These images will be used as tray icons set in runtime, depending on the state of my application.

Current Implementation

The current implementation of FXTrayIcon allows to instantiate it only with image file paths typed as URL.

Changing the icon in runtime is possible with javafx.scene.image.Image type only, but the target type is the good old java.awt.Image.

Suggested Changes

Add a constructor which takes java.awt.Image as an argument with pre-loaded image data. The two existing constructors with URLs can be chained to it.

Add an overload for the setGraphic method, which takes a java.awt.Image as its arg. The existing setGraphic is chained to this overload, because it was transforming a FX image instance into an AWT image.

Other changes: flattened the constructor logic by extracting the methods ensureSystemTraySupported(), attemptSetSystemLookAndFeel() and loadImageFromFile(), making the constructor shorter and simpler.

dustinkredmond commented 3 years ago

@atelechev Thank you for the pull request. I appreciate your contribution; at first glance, this looks perfect. I will further review (and most probably merge). Again, thank you!

dustinkredmond commented 3 years ago

Looks great! Merging this now. Will try to add it to a release in the near future.