diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 7c363da33f..4851b7699e 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -100,6 +100,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { private final static String liteModeArg = "-lite"; private final static String grayModeArg = "-gray"; + private static MageFrame instance; + private static Session session; private ConnectDialog connectDialog; private ErrorDialog errorDialog; @@ -152,6 +154,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { return version; } + public static MageFrame getInstance() { + return instance; + } + /** * Creates new form MageFrame */ @@ -469,14 +475,14 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } } - private void btnImagesActionPerformed(java.awt.event.ActionEvent evt) { + public void btnImagesActionPerformed(java.awt.event.ActionEvent evt) { HashSet cards = new HashSet(CardsStorage.getAllCards()); List notImplemented = CardsStorage.getNotImplementedCards(); cards.addAll(notImplemented); Plugins.getInstance().downloadImage(cards); } - private void btnSymbolsActionPerformed(java.awt.event.ActionEvent evt) { + public void btnSymbolsActionPerformed(java.awt.event.ActionEvent evt) { if (JOptionPane.showConfirmDialog(null, "Do you want to download mana symbols?") == JOptionPane.OK_OPTION) { Plugins.getInstance().downloadSymbols(); } @@ -818,7 +824,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { } }//GEN-LAST:event_btnConnectActionPerformed - private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed + public void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed AboutDialog aboutDialog = new AboutDialog(); desktopPane.add(aboutDialog, JLayeredPane.POPUP_LAYER); aboutDialog.showDialog(version); @@ -828,11 +834,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { showCollectionViewer(); }//GEN-LAST:event_btnCollectionViewerActionPerformed - private void btnPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreferencesActionPerformed + public void btnPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreferencesActionPerformed PreferencesDialog.main(new String[]{}); }//GEN-LAST:event_btnPreferencesActionPerformed - private void btnSendFeedbackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendFeedbackActionPerformed + public void btnSendFeedbackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendFeedbackActionPerformed if (!session.isConnected()) { JOptionPane.showMessageDialog(null, "You may send us feedback only when connected to server.", "Information", JOptionPane.INFORMATION_MESSAGE); return; @@ -982,7 +988,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient { splash.update(); } } - new MageFrame().setVisible(true); + instance = new MageFrame(); + instance.setVisible(true); } }); } diff --git a/Mage.Client/src/main/java/mage/client/components/tray/MageTray.java b/Mage.Client/src/main/java/mage/client/components/tray/MageTray.java new file mode 100644 index 0000000000..9bc0004db8 --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/components/tray/MageTray.java @@ -0,0 +1,160 @@ +package mage.client.components.tray; + +import mage.client.MageFrame; +import org.apache.log4j.Logger; +import org.mage.plugins.card.utils.impl.ImageManagerImpl; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author noxx + */ +public class MageTray { + + private static final MageTray instance = new MageTray(); + + private static final Logger log = Logger.getLogger(MageTray.class); + + private Image mainImage; + private Image flashedImage; + private TrayIcon trayIcon; + + private static int state = 0; + + public static MageTray getInstance() { + return instance; + } + + public void install() { + if (!SystemTray.isSupported()) { + log.warn("SystemTray is not supported"); + return; + } + + try { + mainImage = ImageManagerImpl.getInstance().getAppSmallImage(); + flashedImage = ImageManagerImpl.getInstance().getAppFlashedImage(); + trayIcon = new TrayIcon(mainImage); + trayIcon.setImageAutoSize(true); + + trayIcon.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + stopBlink(); + MageFrame frame = MageFrame.getInstance(); + frame.setVisible(true); + frame.setState(Frame.NORMAL); + } + }); + + final SystemTray tray = SystemTray.getSystemTray(); + + final PopupMenu popup = new PopupMenu(); + + MenuItem imagesItem = new MenuItem("Download images"); + MenuItem iconsItem = new MenuItem("Download icons"); + MenuItem stopBlinkItem = new MenuItem("Stop blinking"); + MenuItem preferencesItem = new MenuItem("Preferences..."); + MenuItem aboutItem = new MenuItem("About Mage"); + MenuItem exitItem = new MenuItem("Exit"); + + imagesItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MageFrame.getInstance().btnImagesActionPerformed(null); + } + }); + + iconsItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MageFrame.getInstance().btnSymbolsActionPerformed(null); + } + }); + + stopBlinkItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + stopBlink(); + } + }); + + preferencesItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MageFrame.getInstance().btnPreferencesActionPerformed(null); + } + }); + + aboutItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MageFrame.getInstance().btnAboutActionPerformed(null); + } + }); + + exitItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MageFrame.getInstance().exitApp(); + } + }); + + popup.add(imagesItem); + popup.add(iconsItem); + popup.add(stopBlinkItem); + popup.add(preferencesItem); + popup.addSeparator(); + popup.add(aboutItem); + popup.addSeparator(); + popup.add(exitItem); + + trayIcon.setPopupMenu(popup); + + try { + tray.add(trayIcon); + } catch (AWTException e) { + log.error("TrayIcon could not be added: ", e); + return; + } + + } catch (Exception e) { + log.error(e); + } + } + + public synchronized void blink() { + if (state == 0) { + synchronized (MageTray.class) { + if (state == 0) { + state = 1; + new Thread(new Runnable() { + @Override + public void run() { + try { + int i = 0; + while (state != 3) { + trayIcon.setImage(i == 0 ? mainImage : flashedImage); + Thread.sleep(600); + i = i == 0 ? 1 : 0; + } + trayIcon.setImage(mainImage); + state = 0; + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + }).start(); + } + } + } + } + + public void stopBlink() { + if (state == 1) { + state = 3; + } + } +} 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 5ff9d6d0c1..bbfc8a6cdb 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/MageDialog.java @@ -107,6 +107,10 @@ public class MageDialog extends javax.swing.JInternalFrame { Object source = event.getSource(); boolean dispatch = true; + if (event.getSource() != null && event.getSource() instanceof TrayIcon) { + return; + } + if (event instanceof MouseEvent && event.getSource() instanceof Component) { MouseEvent e = (MouseEvent) event; MouseEvent m = SwingUtilities.convertMouseEvent((Component) e.getSource(), e, this); diff --git a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java index bdd2a156c0..5b9ea99c66 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/TableWaitingDialog.java @@ -34,20 +34,22 @@ package mage.client.dialog; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CancellationException; -import java.util.concurrent.ExecutionException; -import javax.swing.SwingWorker; -import javax.swing.table.AbstractTableModel; -import mage.client.*; +import mage.client.MageFrame; import mage.client.chat.ChatPanel; import mage.client.components.MageComponents; +import mage.client.components.tray.MageTray; import mage.remote.Session; import mage.view.SeatView; import mage.view.TableView; import org.apache.log4j.Logger; +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.CancellationException; +import java.util.concurrent.ExecutionException; + /** * * @author BetaSteward_at_googlemail.com @@ -359,6 +361,7 @@ class UpdateSeatsTask extends SwingWorker { private UUID roomId; private UUID tableId; private TableWaitingDialog dialog; + private int count = 0; private final static Logger logger = Logger.getLogger(TableWaitingDialog.class); @@ -380,9 +383,34 @@ class UpdateSeatsTask extends SwingWorker { @Override protected void process(List view) { - dialog.update(view.get(0)); + TableView tableView = view.get(0); + if (count == 0) { + count = getPlayersCount(tableView); + } else { + int current = getPlayersCount(tableView); + if (current != count) { + count = current; + if (count > 0) { + MageTray.getInstance().blink(); + } + } + } + dialog.update(tableView); } + private int getPlayersCount(TableView tableView) { + int count = 0; + if (tableView != null) { + for (SeatView seatView: tableView.getSeats()) { + if (seatView.getPlayerId() != null && seatView.getPlayerType().equals("Human")) { + count++; + } + } + } + return count; + } + + @Override protected void done() { try { diff --git a/Mage.Client/src/main/resources/icon-mage-flashed.png b/Mage.Client/src/main/resources/icon-mage-flashed.png new file mode 100644 index 0000000000..588dd79d8e Binary files /dev/null and b/Mage.Client/src/main/resources/icon-mage-flashed.png differ