[UI] Mage tray icon

This commit is contained in:
magenoxx 2012-07-16 19:08:03 +04:00
parent 2de4506ad2
commit 9214051279
5 changed files with 64 additions and 21 deletions

View file

@ -59,7 +59,7 @@ public class TrayIconDemo {
ex.printStackTrace(); ex.printStackTrace();
} }
/* Turn off metal's use of bold fonts */ /* 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: //Schedule a job for the event-dispatching thread:
//adding TrayIcon. //adding TrayIcon.
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@ -77,7 +77,8 @@ public class TrayIconDemo {
} }
final PopupMenu popup = new PopupMenu(); final PopupMenu popup = new PopupMenu();
final TrayIcon trayIcon = 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(); final SystemTray tray = SystemTray.getSystemTray();
// Create a popup menu components // Create a popup menu components
@ -169,6 +170,22 @@ public class TrayIconDemo {
trayIcon.displayMessage("Sun TrayIcon Demo", trayIcon.displayMessage("Sun TrayIcon Demo",
"This is an info message", TrayIcon.MessageType.INFO); "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())) { } else if ("None".equals(item.getLabel())) {
//type = TrayIcon.MessageType.NONE; //type = TrayIcon.MessageType.NONE;
trayIcon.displayMessage("Sun TrayIcon Demo", trayIcon.displayMessage("Sun TrayIcon Demo",

View file

@ -41,6 +41,7 @@ import mage.client.cards.CardsStorage;
import mage.client.chat.ChatPanel; import mage.client.chat.ChatPanel;
import mage.client.components.*; import mage.client.components.*;
import mage.client.components.ext.dlg.DialogManager; import mage.client.components.ext.dlg.DialogManager;
import mage.client.components.tray.MageTray;
import mage.client.constants.Constants.DeckEditorMode; import mage.client.constants.Constants.DeckEditorMode;
import mage.client.deckeditor.DeckEditorPane; import mage.client.deckeditor.DeckEditorPane;
import mage.client.deckeditor.collection.viewer.CollectionViewerPane; import mage.client.deckeditor.collection.viewer.CollectionViewerPane;
@ -70,6 +71,7 @@ import mage.server.Main;
import mage.utils.MageVersion; import mage.utils.MageVersion;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.mage.card.arcane.ManaSymbols; import org.mage.card.arcane.ManaSymbols;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
@ -227,6 +229,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
setBackground(); setBackground();
addMageLabel(); addMageLabel();
setAppIcon(); setAppIcon();
MageTray.getInstance().install();
//PlayerPanelNew n = new PlayerPanelNew(); //PlayerPanelNew n = new PlayerPanelNew();
//n.setBounds(100,100,100,300); //n.setBounds(100,100,100,300);
@ -397,18 +400,9 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
private void setAppIcon() { private void setAppIcon() {
String filename = "/icon-mage.png"; Image image = ImageManagerImpl.getInstance().getAppImage();
try {
InputStream is = this.getClass().getResourceAsStream(filename);
if (is != null) {
BufferedImage image = ImageIO.read(is);
setIconImage(image); setIconImage(image);
} }
} catch (IOException e) {
e.printStackTrace();
}
}
private AbstractButton createWindowsButton() { private AbstractButton createWindowsButton() {
final JToggleButton windowButton = new JToggleButton("Windows"); final JToggleButton windowButton = new JToggleButton("Windows");

View file

@ -34,15 +34,12 @@
package mage.client.dialog; package mage.client.dialog;
import java.awt.AWTEvent; import org.apache.log4j.Logger;
import java.awt.ActiveEvent;
import java.awt.Component; import javax.swing.*;
import java.awt.EventQueue; import java.awt.*;
import java.awt.MenuComponent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.lang.reflect.InvocationTargetException; 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(); Object source = event.getSource();
boolean dispatch = true; boolean dispatch = true;
if (event instanceof MouseEvent) { if (event instanceof MouseEvent && event.getSource() instanceof Component) {
MouseEvent e = (MouseEvent) event; MouseEvent e = (MouseEvent) event;
MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this); MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this);
if (!this.contains(m.getPoint()) && e.getID() != MouseEvent.MOUSE_DRAGGED) { if (!this.contains(m.getPoint()) && e.getID() != MouseEvent.MOUSE_DRAGGED) {

View file

@ -3,6 +3,10 @@ package org.mage.plugins.card.utils;
import java.awt.*; import java.awt.*;
public interface ImageManager { public interface ImageManager {
public Image getAppImage();
public Image getAppSmallImage();
public Image getAppFlashedImage();
public Image getSicknessImage(); public Image getSicknessImage();
public Image getDayImage(); public Image getDayImage();
public Image getNightImage(); public Image getNightImage();

View file

@ -19,6 +19,33 @@ public class ImageManagerImpl implements ImageManager {
return fInstance; 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 @Override
public BufferedImage getSicknessImage() { public BufferedImage getSicknessImage() {
if (imageSickness == null) { if (imageSickness == null) {
@ -144,6 +171,10 @@ public class ImageManagerImpl implements ImageManager {
return image; return image;
} }
private static BufferedImage appImage;
private static BufferedImage appSmallImage;
private static BufferedImage appImageFlashed;
private static BufferedImage imageSickness; private static BufferedImage imageSickness;
private static BufferedImage imageDay; private static BufferedImage imageDay;
private static BufferedImage imageNight; private static BufferedImage imageNight;