From 9214051279506b4d4c534b131e873aec41e159c5 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Mon, 16 Jul 2012 19:08:03 +0400 Subject: [PATCH] [UI] Mage tray icon --- .../src/main/java/mage/TrayIconDemo.java | 21 +++++++++++-- .../src/main/java/mage/client/MageFrame.java | 16 +++------- .../java/mage/client/dialog/MageDialog.java | 13 +++----- .../mage/plugins/card/utils/ImageManager.java | 4 +++ .../card/utils/impl/ImageManagerImpl.java | 31 +++++++++++++++++++ 5 files changed, 64 insertions(+), 21 deletions(-) diff --git a/Mage.Client/src/main/java/mage/TrayIconDemo.java b/Mage.Client/src/main/java/mage/TrayIconDemo.java index 6494b74297..08acd61546 100644 --- a/Mage.Client/src/main/java/mage/TrayIconDemo.java +++ b/Mage.Client/src/main/java/mage/TrayIconDemo.java @@ -59,7 +59,7 @@ public class TrayIconDemo { ex.printStackTrace(); } /* Turn off metal's use of bold fonts */ - UIManager.put("swing.boldMetal", Boolean.FALSE); + //UIManager.put("swing.boldMetal", Boolean.FALSE); //Schedule a job for the event-dispatching thread: //adding TrayIcon. SwingUtilities.invokeLater(new Runnable() { @@ -77,7 +77,8 @@ public class TrayIconDemo { } final PopupMenu popup = new PopupMenu(); final TrayIcon trayIcon = - new TrayIcon(createImage("images/bulb.gif", "tray icon")); + new TrayIcon(createImage("images/icon-mage.png", "tray icon")); + trayIcon.setImageAutoSize(true); final SystemTray tray = SystemTray.getSystemTray(); // Create a popup menu components @@ -169,6 +170,22 @@ public class TrayIconDemo { trayIcon.displayMessage("Sun TrayIcon Demo", "This is an info message", TrayIcon.MessageType.INFO); + new Thread(new Runnable() { + @Override + public void run() { + try { + for (int i = 0; i < 15; i++) { + trayIcon.setImage(createImage(i % 2 == 0 ? "images/icon-mage.png" : "images/icon-mage-flashed.png", "tray icon")); + Thread.sleep(600); + } + } catch (InterruptedException e1) { + e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. + } + + } + }).start(); + + } else if ("None".equals(item.getLabel())) { //type = TrayIcon.MessageType.NONE; trayIcon.displayMessage("Sun TrayIcon Demo", diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 0add859c76..7c363da33f 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -41,6 +41,7 @@ import mage.client.cards.CardsStorage; import mage.client.chat.ChatPanel; import mage.client.components.*; import mage.client.components.ext.dlg.DialogManager; +import mage.client.components.tray.MageTray; import mage.client.constants.Constants.DeckEditorMode; import mage.client.deckeditor.DeckEditorPane; import mage.client.deckeditor.collection.viewer.CollectionViewerPane; @@ -70,6 +71,7 @@ import mage.server.Main; import mage.utils.MageVersion; import org.apache.log4j.Logger; import org.mage.card.arcane.ManaSymbols; +import org.mage.plugins.card.utils.impl.ImageManagerImpl; import javax.imageio.ImageIO; import javax.swing.*; @@ -227,6 +229,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { setBackground(); addMageLabel(); setAppIcon(); + MageTray.getInstance().install(); //PlayerPanelNew n = new PlayerPanelNew(); //n.setBounds(100,100,100,300); @@ -397,17 +400,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } private void setAppIcon() { - String filename = "/icon-mage.png"; - try { - InputStream is = this.getClass().getResourceAsStream(filename); - - if (is != null) { - BufferedImage image = ImageIO.read(is); - setIconImage(image); - } - } catch (IOException e) { - e.printStackTrace(); - } + Image image = ImageManagerImpl.getInstance().getAppImage(); + setIconImage(image); } private AbstractButton createWindowsButton() { diff --git a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java index 9d1614968d..5ff9d6d0c1 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java @@ -34,15 +34,12 @@ package mage.client.dialog; -import java.awt.AWTEvent; -import java.awt.ActiveEvent; -import java.awt.Component; -import java.awt.EventQueue; -import java.awt.MenuComponent; +import org.apache.log4j.Logger; + +import javax.swing.*; +import java.awt.*; import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; -import javax.swing.SwingUtilities; -import org.apache.log4j.Logger; /** * @@ -110,7 +107,7 @@ public class MageDialog extends javax.swing.JInternalFrame { Object source = event.getSource(); boolean dispatch = true; - if (event instanceof MouseEvent) { + if (event instanceof MouseEvent && event.getSource() instanceof Component) { MouseEvent e = (MouseEvent) event; MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this); if (!this.contains(m.getPoint()) && e.getID() != MouseEvent.MOUSE_DRAGGED) { diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java index 00552aa489..6cee5ca9af 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/ImageManager.java @@ -3,6 +3,10 @@ package org.mage.plugins.card.utils; import java.awt.*; public interface ImageManager { + public Image getAppImage(); + public Image getAppSmallImage(); + public Image getAppFlashedImage(); + public Image getSicknessImage(); public Image getDayImage(); public Image getNightImage(); diff --git a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java index d13b54d26b..0a3dce7846 100644 --- a/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java +++ b/Mage.Client/src/main/java/org/mage/plugins/card/utils/impl/ImageManagerImpl.java @@ -19,6 +19,33 @@ public class ImageManagerImpl implements ImageManager { return fInstance; } + @Override + public Image getAppImage() { + if (appImage == null) { + Image image = getBufferedImageFromResource("/icon-mage.png"); + appImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } + return appImage; + } + + @Override + public Image getAppSmallImage() { + if (appSmallImage == null) { + Image image = getImageFromResourceTransparent("/icon-mage.png", Color.WHITE, new Rectangle(16, 16)); + appSmallImage = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } + return appSmallImage; + } + + @Override + public Image getAppFlashedImage() { + if (appImageFlashed == null) { + Image image = getImageFromResourceTransparent("/icon-mage-flashed.png", Color.WHITE, new Rectangle(16, 16)); + appImageFlashed = BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB); + } + return appImageFlashed; + } + @Override public BufferedImage getSicknessImage() { if (imageSickness == null) { @@ -144,6 +171,10 @@ public class ImageManagerImpl implements ImageManager { return image; } + private static BufferedImage appImage; + private static BufferedImage appSmallImage; + private static BufferedImage appImageFlashed; + private static BufferedImage imageSickness; private static BufferedImage imageDay; private static BufferedImage imageNight;