mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
[UI] Tray menu. Blinking on new players added to table. Added window restore on double-click.
This commit is contained in:
parent
9214051279
commit
872ced4344
5 changed files with 213 additions and 14 deletions
|
@ -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<Card> cards = new HashSet<Card>(CardsStorage.getAllCards());
|
||||
List<Card> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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<Void, TableView> {
|
|||
private UUID roomId;
|
||||
private UUID tableId;
|
||||
private TableWaitingDialog dialog;
|
||||
private int count = 0;
|
||||
|
||||
private final static Logger logger = Logger.getLogger(TableWaitingDialog.class);
|
||||
|
||||
|
@ -380,8 +383,33 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
|
|||
|
||||
@Override
|
||||
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
|
||||
protected void done() {
|
||||
|
|
BIN
Mage.Client/src/main/resources/icon-mage-flashed.png
Normal file
BIN
Mage.Client/src/main/resources/icon-mage-flashed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
Loading…
Reference in a new issue