Properly display unread message count (>9)

This commit is contained in:
Kai S. K. Engelbart 2020-10-22 15:32:06 +02:00
parent aaaf5ef7be
commit e79f60e95e
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13

View File

@ -56,6 +56,8 @@ public final class StatusTrayIcon implements EventListener {
*/ */
private final Image logo; private final Image logo;
private static final Font unreadMessageFont = new Font("sans-serif", Font.PLAIN, 8);
/** /**
* @return {@code true} if the status tray icon is supported on this platform * @return {@code true} if the status tray icon is supported on this platform
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
@ -200,10 +202,18 @@ public final class StatusTrayIcon implements EventListener {
// Draw total amount of unread messages, if any are present // Draw total amount of unread messages, if any are present
if (Chat.getTotalUnreadAmount().get() > 0) { if (Chat.getTotalUnreadAmount().get() > 0) {
// Draw black background circle
g.setColor(Color.BLACK); g.setColor(Color.BLACK);
g.fillOval(size.width / 2, 0, size.width / 2, size.height / 2); g.fillOval(size.width / 2, 0, size.width / 2, size.height / 2);
// Unread amount in white
String unreadAmount = Chat.getTotalUnreadAmount().get() > 9 ? "9+"
: String.valueOf(Chat.getTotalUnreadAmount().get());
g.setColor(Color.WHITE); g.setColor(Color.WHITE);
g.drawString(String.valueOf(Chat.getTotalUnreadAmount().get()), size.width / 2, g.setFont(unreadMessageFont);
g.drawString(unreadAmount,
3 * size.width / 4 - g.getFontMetrics().stringWidth(unreadAmount) / 2,
size.height / 2); size.height / 2);
} }