Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notifications when Operation finishes
- Loading branch information
Showing
6 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package at.esque.kafka.handlers; | ||
|
||
import at.esque.kafka.alerts.ErrorAlert; | ||
import com.google.inject.Singleton; | ||
import javafx.application.Platform; | ||
import javafx.stage.Stage; | ||
|
||
import java.awt.*; | ||
|
||
@Singleton | ||
public class TrayHandler { | ||
|
||
private final boolean traySupported; | ||
private final TrayIcon trayIcon; | ||
private final SystemTray systemTray; | ||
private Stage primaryStage; | ||
|
||
public TrayHandler() { | ||
traySupported = SystemTray.isSupported(); | ||
if (traySupported) { | ||
|
||
systemTray = SystemTray.getSystemTray(); | ||
Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/icons/trayIcon.png")); | ||
trayIcon = new TrayIcon(image, "KafkaEsque"); | ||
trayIcon.setImageAutoSize(true); | ||
trayIcon.setToolTip("KafkaEsque"); | ||
|
||
PopupMenu popupMenu = new PopupMenu(); | ||
MenuItem exitItem = new MenuItem("Exit"); | ||
exitItem.addActionListener(e -> { | ||
Platform.exit(); | ||
}); | ||
|
||
MenuItem showStageItem = new MenuItem("Open"); | ||
showStageItem.addActionListener(e -> { | ||
Platform.runLater(() -> primaryStage.show()); | ||
}); | ||
|
||
MenuItem hideStageItem = new MenuItem("Hide"); | ||
hideStageItem.addActionListener(e -> { | ||
Platform.runLater(() -> primaryStage.hide()); | ||
}); | ||
|
||
popupMenu.add(exitItem); | ||
popupMenu.add(showStageItem); | ||
popupMenu.add(hideStageItem); | ||
try { | ||
trayIcon.setPopupMenu(popupMenu); | ||
systemTray.add(trayIcon); | ||
Platform.setImplicitExit(false); | ||
} catch (AWTException e) { | ||
ErrorAlert.show(e); | ||
} | ||
} else { | ||
systemTray = null; | ||
trayIcon = null; | ||
} | ||
} | ||
|
||
public void showInfoNotification(String title, String message) { | ||
if (traySupported) { | ||
trayIcon.displayMessage(title, message, TrayIcon.MessageType.INFO); | ||
} | ||
} | ||
|
||
public void showWarningNotification(String title, String message) { | ||
if (traySupported) { | ||
trayIcon.displayMessage(title, message, TrayIcon.MessageType.WARNING); | ||
} | ||
} | ||
|
||
public void showErrorNotification(String title, String message) { | ||
if (traySupported) { | ||
trayIcon.displayMessage(title, message, TrayIcon.MessageType.ERROR); | ||
} | ||
} | ||
|
||
public void shutdown() { | ||
if (traySupported) { | ||
systemTray.remove(trayIcon); | ||
} | ||
} | ||
|
||
public Stage getPrimaryStage() { | ||
return primaryStage; | ||
} | ||
|
||
public void setPrimaryStage(Stage primaryStage) { | ||
this.primaryStage = primaryStage; | ||
} | ||
|
||
public boolean isTraySupported() { | ||
return traySupported; | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.