[UI] Tray menu. Blinking on new players added to table. Added window restore on double-click.

This commit is contained in:
magenoxx 2012-07-16 20:23:56 +04:00
parent 9214051279
commit 872ced4344
5 changed files with 213 additions and 14 deletions

View file

@ -100,6 +100,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
private final static String liteModeArg = "-lite"; private final static String liteModeArg = "-lite";
private final static String grayModeArg = "-gray"; private final static String grayModeArg = "-gray";
private static MageFrame instance;
private static Session session; private static Session session;
private ConnectDialog connectDialog; private ConnectDialog connectDialog;
private ErrorDialog errorDialog; private ErrorDialog errorDialog;
@ -152,6 +154,10 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
return version; return version;
} }
public static MageFrame getInstance() {
return instance;
}
/** /**
* Creates new form MageFrame * 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<Card> cards = new HashSet<Card>(CardsStorage.getAllCards()); HashSet<Card> cards = new HashSet<Card>(CardsStorage.getAllCards());
List<Card> notImplemented = CardsStorage.getNotImplementedCards(); List<Card> notImplemented = CardsStorage.getNotImplementedCards();
cards.addAll(notImplemented); cards.addAll(notImplemented);
Plugins.getInstance().downloadImage(cards); 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) { if (JOptionPane.showConfirmDialog(null, "Do you want to download mana symbols?") == JOptionPane.OK_OPTION) {
Plugins.getInstance().downloadSymbols(); Plugins.getInstance().downloadSymbols();
} }
@ -818,7 +824,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
} }
}//GEN-LAST:event_btnConnectActionPerformed }//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(); AboutDialog aboutDialog = new AboutDialog();
desktopPane.add(aboutDialog, JLayeredPane.POPUP_LAYER); desktopPane.add(aboutDialog, JLayeredPane.POPUP_LAYER);
aboutDialog.showDialog(version); aboutDialog.showDialog(version);
@ -828,11 +834,11 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
showCollectionViewer(); showCollectionViewer();
}//GEN-LAST:event_btnCollectionViewerActionPerformed }//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[]{}); PreferencesDialog.main(new String[]{});
}//GEN-LAST:event_btnPreferencesActionPerformed }//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()) { if (!session.isConnected()) {
JOptionPane.showMessageDialog(null, "You may send us feedback only when connected to server.", "Information", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "You may send us feedback only when connected to server.", "Information", JOptionPane.INFORMATION_MESSAGE);
return; return;
@ -982,7 +988,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
splash.update(); splash.update();
} }
} }
new MageFrame().setVisible(true); instance = new MageFrame();
instance.setVisible(true);
} }
}); });
} }

View file

@ -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;
}
}
}

View file

@ -107,6 +107,10 @@ public class MageDialog extends javax.swing.JInternalFrame {
Object source = event.getSource(); Object source = event.getSource();
boolean dispatch = true; boolean dispatch = true;
if (event.getSource() != null && event.getSource() instanceof TrayIcon) {
return;
}
if (event instanceof MouseEvent && event.getSource() instanceof Component) { 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);

View file

@ -34,20 +34,22 @@
package mage.client.dialog; package mage.client.dialog;
import java.util.List; import mage.client.MageFrame;
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.chat.ChatPanel; import mage.client.chat.ChatPanel;
import mage.client.components.MageComponents; import mage.client.components.MageComponents;
import mage.client.components.tray.MageTray;
import mage.remote.Session; import mage.remote.Session;
import mage.view.SeatView; import mage.view.SeatView;
import mage.view.TableView; import mage.view.TableView;
import org.apache.log4j.Logger; 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 * @author BetaSteward_at_googlemail.com
@ -359,6 +361,7 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
private UUID roomId; private UUID roomId;
private UUID tableId; private UUID tableId;
private TableWaitingDialog dialog; private TableWaitingDialog dialog;
private int count = 0;
private final static Logger logger = Logger.getLogger(TableWaitingDialog.class); private final static Logger logger = Logger.getLogger(TableWaitingDialog.class);
@ -380,9 +383,34 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
@Override @Override
protected void process(List<TableView> view) { protected void process(List<TableView> 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 @Override
protected void done() { protected void done() {
try { try {

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB