mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-01 11:16:11 -04:00
Add scaling for system tray icon (#242)
This commit is contained in:
parent
704230fbdd
commit
d146a5a338
1 changed files with 17 additions and 13 deletions
|
@ -17,11 +17,13 @@
|
||||||
|
|
||||||
package io.bitsquare.gui;
|
package io.bitsquare.gui;
|
||||||
|
|
||||||
|
import io.bitsquare.BitsquareException;
|
||||||
import io.bitsquare.gui.util.ImageUtil;
|
import io.bitsquare.gui.util.ImageUtil;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.IOException;
|
||||||
|
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
@ -29,6 +31,8 @@ import javafx.stage.Stage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* There is no JavaFX support yet, so we need to use AWT.
|
* There is no JavaFX support yet, so we need to use AWT.
|
||||||
*/
|
*/
|
||||||
|
@ -43,7 +47,6 @@ public class SystemTray {
|
||||||
|
|
||||||
private final Stage stage;
|
private final Stage stage;
|
||||||
private final Runnable onExit;
|
private final Runnable onExit;
|
||||||
private final TrayIcon trayIcon = createTrayIcon();
|
|
||||||
private final MenuItem toggleShowHideItem = new MenuItem(HIDE_WINDOW_LABEL);
|
private final MenuItem toggleShowHideItem = new MenuItem(HIDE_WINDOW_LABEL);
|
||||||
|
|
||||||
public SystemTray(Stage stage, Runnable onExit) {
|
public SystemTray(Stage stage, Runnable onExit) {
|
||||||
|
@ -73,14 +76,20 @@ public class SystemTray {
|
||||||
popupMenu.addSeparator();
|
popupMenu.addSeparator();
|
||||||
popupMenu.add(exitItem);
|
popupMenu.add(exitItem);
|
||||||
|
|
||||||
|
String path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;
|
||||||
|
try {
|
||||||
|
BufferedImage trayIconImage = ImageIO.read(getClass().getResource(path));
|
||||||
|
int trayIconWidth = new TrayIcon(trayIconImage).getSize().width;
|
||||||
|
TrayIcon trayIcon = new TrayIcon(trayIconImage.getScaledInstance(trayIconWidth, -1, Image.SCALE_SMOOTH));
|
||||||
trayIcon.setPopupMenu(popupMenu);
|
trayIcon.setPopupMenu(popupMenu);
|
||||||
trayIcon.setToolTip("Bitsquare: The decentralized bitcoin exchange");
|
trayIcon.setToolTip("Bitsquare: The decentralized bitcoin exchange");
|
||||||
|
|
||||||
java.awt.SystemTray self = java.awt.SystemTray.getSystemTray();
|
java.awt.SystemTray self = java.awt.SystemTray.getSystemTray();
|
||||||
try {
|
|
||||||
self.add(trayIcon);
|
self.add(trayIcon);
|
||||||
} catch (AWTException ex) {
|
} catch (AWTException e1) {
|
||||||
log.error("Icon could not be added to system tray.", ex);
|
log.error("Icon could not be added to system tray.", e1);
|
||||||
|
} catch (IOException e2) {
|
||||||
|
throw new BitsquareException(e2);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleShowHideItem.addActionListener(e -> {
|
toggleShowHideItem.addActionListener(e -> {
|
||||||
|
@ -101,9 +110,4 @@ public class SystemTray {
|
||||||
stage.hide();
|
stage.hide();
|
||||||
toggleShowHideItem.setLabel(SHOW_WINDOW_LABEL);
|
toggleShowHideItem.setLabel(SHOW_WINDOW_LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TrayIcon createTrayIcon() {
|
|
||||||
String path = ImageUtil.isRetina() ? ICON_HI_RES : ICON_LO_RES;
|
|
||||||
return new TrayIcon(new ImageIcon(getClass().getResource(path)).getImage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue