added some client window management + suppress calls when TablesPane is not visible

This commit is contained in:
BetaSteward 2011-06-07 22:32:58 -04:00
parent 79583a6ec2
commit d8fca737fd
27 changed files with 239 additions and 196 deletions

View file

@ -38,7 +38,7 @@
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>com.mortennobel</groupId>

View file

@ -110,6 +110,7 @@ public class MageFrame extends javax.swing.JFrame implements Client {
private Rectangle titleRectangle;
private final static MageVersion version = new MageVersion(0, 7, 3);
private UUID clientId;
private static MagePane activeFrame;
private static Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private static Map<UUID, GamePanel> games = new HashMap<UUID, GamePanel>();
@ -368,21 +369,15 @@ public class MageFrame extends javax.swing.JFrame implements Client {
MagePaneMenuItem menuItem;
for (int i = 0; i < windows.length; i++) {
JInternalFrame window = windows[i];
MagePane window = (MagePane) windows[i];
if (window.isVisible()) {
menuItem = new MagePaneMenuItem(window);
menuItem.setState(i == 0);
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
JInternalFrame frame = ((MagePaneMenuItem) ae.getSource()).getFrame();
frame.toFront();
frame.setVisible(true);
//frame.moveToFront();
try {
frame.setSelected(true);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
MagePane frame = ((MagePaneMenuItem) ae.getSource()).getFrame();
setActive(frame);
}
});
menuItem.setIcon(window.getFrameIcon());
@ -418,69 +413,96 @@ public class MageFrame extends javax.swing.JFrame implements Client {
}
}
public static void setActive(MagePane frame) {
if (frame == null)
return;
logger.debug("Setting " + frame.getTitle() + " active");
if (activeFrame != null)
activeFrame.deactivated();
activeFrame = frame;
activeFrame.toFront();
try {
activeFrame.setSelected(true);
} catch (PropertyVetoException ex) {}
activeFrame.activated();
}
public static void deactivate(MagePane frame) {
frame.setVisible(false);
MagePane topmost = getTopMost(frame);
if (activeFrame != frame)
frame.deactivated();
setActive(topmost);
}
private static MagePane getTopMost(MagePane exclude) {
MagePane topmost = null;
int best = Integer.MAX_VALUE;
for (JInternalFrame frame: desktopPane.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER)) {
if (frame.isVisible()) {
int z = desktopPane.getComponentZOrder(frame);
if (z < best) {
best = z;
topmost = (MagePane) frame;
}
}
}
return topmost;
}
public void showGame(UUID gameId, UUID playerId) {
try {
GamePane gamePane = new GamePane();
desktopPane.add(gamePane, javax.swing.JLayeredPane.DEFAULT_LAYER);
desktopPane.add(gamePane, JLayeredPane.DEFAULT_LAYER);
gamePane.setMaximum(true);
gamePane.setVisible(true);
gamePane.toFront();
gamePane.showGame(gameId, playerId);
} catch (PropertyVetoException ex) {
logger.fatal(null, ex);
}
setActive(gamePane);
} catch (PropertyVetoException ex) {}
}
public void watchGame(UUID gameId) {
try {
GamePane gamePane = new GamePane();
desktopPane.add(gamePane, javax.swing.JLayeredPane.DEFAULT_LAYER);
desktopPane.add(gamePane, JLayeredPane.DEFAULT_LAYER);
gamePane.setMaximum(true);
gamePane.setVisible(true);
gamePane.toFront();
gamePane.watchGame(gameId);
} catch (PropertyVetoException ex) {
logger.fatal(null, ex);
}
setActive(gamePane);
} catch (PropertyVetoException ex) {}
}
public void replayGame(UUID gameId) {
try {
GamePane gamePane = new GamePane();
desktopPane.add(gamePane, javax.swing.JLayeredPane.DEFAULT_LAYER);
desktopPane.add(gamePane, JLayeredPane.DEFAULT_LAYER);
gamePane.setMaximum(true);
gamePane.setVisible(true);
gamePane.toFront();
gamePane.replayGame(gameId);
} catch (PropertyVetoException ex) {
logger.fatal(null, ex);
}
setActive(gamePane);
} catch (PropertyVetoException ex) {}
}
public void showDraft(UUID draftId) {
try {
DraftPane draftPane = new DraftPane();
desktopPane.add(draftPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
desktopPane.add(draftPane, JLayeredPane.DEFAULT_LAYER);
draftPane.setMaximum(true);
draftPane.setVisible(true);
draftPane.toFront();
draftPane.showDraft(draftId);
} catch (PropertyVetoException ex) {
logger.fatal(null, ex);
}
setActive(draftPane);
} catch (PropertyVetoException ex) {}
}
public void showTournament(UUID tournamentId) {
try {
TournamentPane tournamentPane = new TournamentPane();
desktopPane.add(tournamentPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
desktopPane.add(tournamentPane, JLayeredPane.DEFAULT_LAYER);
tournamentPane.setMaximum(true);
tournamentPane.setVisible(true);
tournamentPane.toFront();
tournamentPane.showTournament(tournamentId);
} catch (PropertyVetoException ex) {
logger.fatal(null, ex);
}
setActive(tournamentPane);
} catch (PropertyVetoException ex) {}
}
public static boolean connect(Connection connection) {
@ -722,8 +744,8 @@ public class MageFrame extends javax.swing.JFrame implements Client {
private void btnGamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGamesActionPerformed
this.tablesPane.setVisible(true);
this.tablesPane.toFront();
this.tablesPane.showTables();
setActive(tablesPane);
}//GEN-LAST:event_btnGamesActionPerformed
private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed
@ -743,7 +765,7 @@ public class MageFrame extends javax.swing.JFrame implements Client {
private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed
AboutDialog aboutDialog = new AboutDialog();
desktopPane.add(aboutDialog);
desktopPane.add(aboutDialog, JLayeredPane.POPUP_LAYER);
aboutDialog.showDialog(version);
}//GEN-LAST:event_btnAboutActionPerformed
@ -773,7 +795,7 @@ public class MageFrame extends javax.swing.JFrame implements Client {
}
public void hideGames() {
JInternalFrame[] windows = desktopPane.getAllFramesInLayer(javax.swing.JLayeredPane.DEFAULT_LAYER);
JInternalFrame[] windows = desktopPane.getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER);
for (JInternalFrame window: windows) {
if (window instanceof GamePane) {
GamePane gamePane = (GamePane) window;
@ -785,11 +807,11 @@ public class MageFrame extends javax.swing.JFrame implements Client {
public void showDeckEditor(DeckEditorMode mode, Deck deck, UUID tableId, int time) {
try {
DeckEditorPane deckEditorPane = new DeckEditorPane();
desktopPane.add(deckEditorPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
desktopPane.add(deckEditorPane, JLayeredPane.DEFAULT_LAYER);
deckEditorPane.setMaximum(true);
deckEditorPane.setVisible(true);
deckEditorPane.toFront();
deckEditorPane.show(mode, deck, tableId, time);
setActive(deckEditorPane);
} catch (PropertyVetoException ex) {
logger.fatal(null, ex);
}
@ -797,7 +819,7 @@ public class MageFrame extends javax.swing.JFrame implements Client {
public void showCollectionViewer() {
this.collectionViewerPane.setVisible(true);
this.collectionViewerPane.toFront();
setActive(collectionViewerPane);
}
static void renderSplashFrame(Graphics2D g) {
@ -932,14 +954,14 @@ public class MageFrame extends javax.swing.JFrame implements Client {
}
class MagePaneMenuItem extends JCheckBoxMenuItem {
private JInternalFrame frame;
private MagePane frame;
public MagePaneMenuItem(JInternalFrame frame) {
public MagePaneMenuItem(MagePane frame) {
super(frame.getTitle());
this.frame = frame;
}
public JInternalFrame getFrame() {
public MagePane getFrame() {
return frame;
}
}

View file

@ -34,19 +34,16 @@
package mage.client;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLayeredPane;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import javax.swing.plaf.basic.BasicInternalFrameUI;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class MagePane extends javax.swing.JInternalFrame implements InternalFrameListener {
public abstract class MagePane extends javax.swing.JInternalFrame {
private final static Logger logger = Logger.getLogger(MagePane.class);
/** Creates new form MagePane */
public MagePane() {
@ -65,6 +62,17 @@ public class MagePane extends javax.swing.JInternalFrame implements InternalFram
hideTitle();
}
public void hideFrame() {
MageFrame.deactivate(this);
}
public void activated() {
}
public void deactivated() {
}
/** This method is called from within the constructor to
* initialize the form.
@ -95,36 +103,4 @@ public class MagePane extends javax.swing.JInternalFrame implements InternalFram
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
@Override
public void internalFrameOpened(InternalFrameEvent e) {
}
@Override
public void internalFrameClosing(InternalFrameEvent e) {
}
@Override
public void internalFrameClosed(InternalFrameEvent e) {
try {
MageFrame.getDesktop().getAllFramesInLayer(JLayeredPane.DEFAULT_LAYER)[0].setSelected(true);
} catch (PropertyVetoException ex) {
}
}
@Override
public void internalFrameIconified(InternalFrameEvent e) {
}
@Override
public void internalFrameDeiconified(InternalFrameEvent e) {
}
@Override
public void internalFrameActivated(InternalFrameEvent e) {
}
@Override
public void internalFrameDeactivated(InternalFrameEvent e) {
}
}

View file

@ -266,7 +266,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
c = c.getParent();
}
if (c != null)
c.setVisible(false);
((DeckEditorPane)c).hideFrame();
}
private BigCard getBigCard() {

View file

@ -49,7 +49,7 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel3" pref="48" max="32767" attributes="0"/>
<Component id="jLabel3" pref="52" max="32767" attributes="0"/>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Component id="btnOk" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>

View file

@ -34,7 +34,6 @@
package mage.client.dialog;
import mage.client.MageFrame;
import mage.utils.MageVersion;
/**
@ -123,7 +122,7 @@ public class AboutDialog extends MageDialog {
}// </editor-fold>//GEN-END:initComponents
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnOkActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables

View file

@ -189,7 +189,7 @@ public class AddLandDialog extends MageDialog {
}// </editor-fold>//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
@ -213,7 +213,7 @@ public class AddLandDialog extends MageDialog {
for (int i = 0; i < nSwamp; i++) {
deck.getCards().add(Sets.findCard("Swamp", true));
}
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnAddActionPerformed

View file

@ -111,10 +111,11 @@ public class CombatDialog extends MageDialog {
}
}
@Override
public void hideDialog() {
this.lastX = this.getX();
this.lastY = this.getY();
this.setVisible(false);
super.hideDialog();
}
/** This method is called from within the constructor to

View file

@ -204,7 +204,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="pnlProxy" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="30" max="32767" attributes="0"/>
<EmptySpace pref="34" max="32767" attributes="0"/>
<Component id="pnlProxyAuth" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>

View file

@ -41,6 +41,8 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
@ -383,7 +385,7 @@ public class ConnectDialog extends MageDialog {
if (task != null && !task.isDone())
task.cancel(true);
else
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed
@ -443,6 +445,8 @@ public class ConnectDialog extends MageDialog {
@Override
protected void done() {
try {
get();
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
btnConnect.setEnabled(true);
if (result) {
@ -452,13 +456,17 @@ public class ConnectDialog extends MageDialog {
else {
lblStatus.setText("Could not connect");
}
} catch (InterruptedException ex) {
logger.fatal("Update Players Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Players Task error", ex);
} catch (CancellationException ex) {}
}
}
private void connected() {
this.saveSettings();
this.setVisible(false);
this.hideDialog();
}

View file

@ -69,7 +69,7 @@ public class ExileZoneDialog extends MageDialog {
}
}
else {
hide();
this.hideDialog();
}
}

View file

@ -130,7 +130,7 @@ public class JoinTableDialog extends MageDialog {
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.joined = false;
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
@ -140,7 +140,7 @@ public class JoinTableDialog extends MageDialog {
} catch (Exception ex) {
handleError(ex);
}
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnOKActionPerformed
/**

View file

@ -24,7 +24,7 @@
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="310" max="32767" attributes="0"/>
<EmptySpace min="0" pref="314" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>

View file

@ -73,6 +73,7 @@ public class MageDialog extends javax.swing.JInternalFrame {
@Override
public void setVisible(boolean value) {
super.setVisible(value);
if (value)
this.toFront();
if (modal) {
this.setClosable(false);
@ -151,6 +152,10 @@ public class MageDialog extends javax.swing.JInternalFrame {
return this.modal;
}
public void hideDialog() {
this.setVisible(false);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is

View file

@ -301,7 +301,7 @@ public class NewTableDialog extends MageDialog {
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.table = null;
this.playerId = null;
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
@ -332,7 +332,7 @@ public class NewTableDialog extends MageDialog {
}
}
}
this.setVisible(false);
this.hideDialog();
return;
}
} catch (FileNotFoundException ex) {

View file

@ -322,7 +322,7 @@ public class NewTournamentDialog extends MageDialog {
}
}
}
this.setVisible(false);
this.hideDialog();
return;
}
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
@ -333,7 +333,7 @@ public class NewTournamentDialog extends MageDialog {
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.table = null;
this.playerId = null;
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
private void spnNumPlayersStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnNumPlayersStateChanged

View file

@ -132,11 +132,11 @@ public class PickChoiceDialog extends MageDialog {
}// </editor-fold>//GEN-END:initComponents
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnOkActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables

View file

@ -145,12 +145,12 @@ public class PickNumberDialog extends MageDialog {
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
this.cancel = false;
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnOkActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.cancel = true;
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnCancelActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables

View file

@ -119,12 +119,12 @@ public class QuestionDialog extends MageDialog {
private void btnYesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnYesActionPerformed
this.answer = true;
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnYesActionPerformed
private void btnNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNoActionPerformed
this.answer = false;
this.setVisible(false);
this.hideDialog();
}//GEN-LAST:event_btnNoActionPerformed

View file

@ -172,24 +172,19 @@ public class ShowCardsDialog extends MageDialog implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
this.setVisible(false);
}
public void mousePressed(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
this.hideDialog();
}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
}

View file

@ -37,6 +37,8 @@ package mage.client.dialog;
import mage.client.*;
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.components.MageComponents;
@ -134,7 +136,7 @@ public class TableWaitingDialog extends MageDialog {
public void closeDialog() {
if (updateTask != null) updateTask.cancel(true);
this.chatPanel.disconnect();
setVisible(false);
this.hideDialog();
}
@ -379,4 +381,15 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
dialog.update(view.get(0));
}
@Override
protected void done() {
try {
get();
} catch (InterruptedException ex) {
logger.fatal("Update Seats Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Seats Task error", ex);
} catch (CancellationException ex) {}
}
}

View file

@ -133,8 +133,9 @@ public class DraftPanel extends javax.swing.JPanel {
while (c != null && !(c instanceof DraftPane)) {
c = c.getParent();
}
if (c != null)
c.setVisible(false);
if (c != null) {
((DraftPane)c).hideFrame();
}
}
protected void setMessage(String message) {

View file

@ -36,8 +36,6 @@ package mage.client.game;
import mage.client.*;
import java.util.UUID;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
/**
*
@ -48,39 +46,11 @@ public class GamePane extends MagePane {
/** Creates new form GamePane */
public GamePane() {
initComponents();
addInternalFrameListener(new InternalFrameListener()
{
@Override
public void internalFrameOpened(InternalFrameEvent e) { }
@Override
public void internalFrameClosing(InternalFrameEvent e) {
gamePanel.cleanUp();
}
@Override
public void internalFrameClosed(InternalFrameEvent e) { }
@Override
public void internalFrameIconified(InternalFrameEvent e) { }
@Override
public void internalFrameDeiconified(InternalFrameEvent e) { }
@Override
public void internalFrameActivated(InternalFrameEvent e) { }
@Override
public void internalFrameDeactivated(InternalFrameEvent e) { }
});
}
public void showGame(UUID gameId, UUID playerId) {
this.setTitle("Game " + gameId);
gamePanel.showGame(gameId, playerId);
this.toFront();
}
public void hideGame() {
@ -90,13 +60,11 @@ public class GamePane extends MagePane {
public void watchGame(UUID gameId) {
this.setTitle("Watching " + gameId);
gamePanel.watchGame(gameId);
this.toFront();
}
public void replayGame(UUID gameId) {
this.setTitle("Replaying " + gameId);
gamePanel.replayGame(gameId);
this.toFront();
}
/** This method is called from within the constructor to
@ -133,4 +101,9 @@ public class GamePane extends MagePane {
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration//GEN-END:variables
@Override
public void deactivated() {
gamePanel.cleanUp();
}
}

View file

@ -139,13 +139,17 @@ public class GamePanel extends javax.swing.JPanel {
}
public void cleanUp() {
this.chatPanel.disconnect();
this.players.clear();
logger.debug("players clear.");
this.pnlBattlefield.removeAll();
combat.hideDialog();
pickNumber.hide();
pickNumber.hideDialog();
for (ExileZoneDialog exile: exiles.values()) {
exile.hide();
exile.hideDialog();
}
for (ShowCardsDialog reveal: revealed.values()) {
reveal.hide();
reveal.hideDialog();
}
}
@ -160,7 +164,6 @@ public class GamePanel extends javax.swing.JPanel {
this.btnConcede.setVisible(true);
this.pnlReplay.setVisible(false);
this.btnStopWatching.setVisible(false);
this.setVisible(true);
this.chatPanel.clear();
this.chatPanel.connect(session.getGameChatId(gameId));
if (!session.joinGame(gameId))
@ -177,7 +180,6 @@ public class GamePanel extends javax.swing.JPanel {
this.btnConcede.setVisible(false);
this.btnStopWatching.setVisible(true);
this.pnlReplay.setVisible(false);
this.setVisible(true);
this.chatPanel.clear();
this.chatPanel.connect(session.getGameChatId(gameId));
if (!session.watchGame(gameId))
@ -193,24 +195,19 @@ public class GamePanel extends javax.swing.JPanel {
this.btnConcede.setVisible(false);
this.btnStopWatching.setVisible(false);
this.pnlReplay.setVisible(true);
this.setVisible(true);
this.chatPanel.clear();
if (!session.startReplay(gameId))
hideGame();
}
public void hideGame() {
this.chatPanel.disconnect();
this.players.clear();
logger.debug("players clear.");
this.pnlBattlefield.removeAll();
combat.hideDialog();
cleanUp();
Component c = this.getParent();
while (c != null && !(c instanceof GamePane)) {
c = c.getParent();
}
if (c != null)
c.setVisible(false);
((GamePane)c).hideFrame();
}
public synchronized void init(GameView game) {

View file

@ -127,4 +127,13 @@ public class TablesPane extends MagePane {
private mage.client.table.TablesPanel tablesPanel;
// End of variables declaration//GEN-END:variables
@Override
public void activated() {
tablesPanel.startTasks();
}
@Override
public void deactivated() {
tablesPanel.stopTasks();
}
}

View file

@ -58,6 +58,8 @@ import java.awt.event.ActionEvent;
import java.beans.PropertyVetoException;
import java.util.*;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
/**
@ -171,32 +173,49 @@ public class TablesPanel extends javax.swing.JPanel {
}
}
public void startTasks() {
if (session != null) {
if (updateTask == null || updateTask.isDone()) {
updateTask = new UpdateTablesTask(session, roomId, this);
updateTask.execute();
}
if (updatePlayersTask == null || updatePlayersTask.isDone()) {
updatePlayersTask = new UpdatePlayersTask(session, roomId, this.chatPanel);
updatePlayersTask.execute();
}
}
}
public void stopTasks() {
if (updateTask != null)
updateTask.cancel(true);
if (updatePlayersTask != null)
updatePlayersTask.cancel(true);
}
public void showTables(UUID roomId) {
this.roomId = roomId;
session = MageFrame.getSession();
updateTask = new UpdateTablesTask(session, roomId, this);
updatePlayersTask = new UpdatePlayersTask(session, roomId, this.chatPanel);
if (session != null) {
btnQuickStart.setVisible(session.isTestMode());
}
if (newTableDialog == null) {
newTableDialog = new NewTableDialog();
MageFrame.getDesktop().add(newTableDialog);
MageFrame.getDesktop().add(newTableDialog, JLayeredPane.MODAL_LAYER);
}
if (newTournamentDialog == null) {
newTournamentDialog = new NewTournamentDialog();
MageFrame.getDesktop().add(newTournamentDialog);
MageFrame.getDesktop().add(newTournamentDialog, JLayeredPane.MODAL_LAYER);
}
if (joinTableDialog == null) {
joinTableDialog = new JoinTableDialog();
MageFrame.getDesktop().add(joinTableDialog);
MageFrame.getDesktop().add(joinTableDialog, JLayeredPane.MODAL_LAYER);
}
UUID chatRoomId = session.getRoomChatId(roomId);
if (chatRoomId != null) {
this.chatPanel.connect(chatRoomId);
updateTask.execute();
updatePlayersTask.execute();
startTasks();
this.setVisible(true);
this.repaint();
}
@ -213,10 +232,7 @@ public class TablesPanel extends javax.swing.JPanel {
((TableWaitingDialog)component).closeDialog();
}
}
if (updateTask != null)
updateTask.cancel(true);
if (updatePlayersTask != null)
updatePlayersTask.cancel(true);
stopTasks();
this.chatPanel.disconnect();
Component c = this.getParent();
@ -224,7 +240,7 @@ public class TablesPanel extends javax.swing.JPanel {
c = c.getParent();
}
if (c != null)
c.setVisible(false);
((TablesPane)c).hideFrame();
}
private void showTableWaitingDialog(UUID roomId, UUID tableId, boolean isTournament) {
@ -349,8 +365,6 @@ public class TablesPanel extends javax.swing.JPanel {
}//GEN-LAST:event_btnQuickStartActionPerformed
private void btnNewTournamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTournamentActionPerformed
newTournamentDialog = new NewTournamentDialog();
MageFrame.getDesktop().add(newTournamentDialog);
newTournamentDialog.showDialog(roomId);
if (newTournamentDialog.getTable() != null) {
showTableWaitingDialog(roomId, newTournamentDialog.getTable().getTableId(), true);
@ -483,6 +497,18 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
protected void process(List<Collection<TableView>> view) {
panel.update(view.get(0));
}
@Override
protected void done() {
try {
get();
} catch (InterruptedException ex) {
logger.fatal("Update Tables Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Tables Task error", ex);
} catch (CancellationException ex) {}
}
}
class UpdatePlayersTask extends SwingWorker<Void, Collection<String>> {
@ -512,4 +538,16 @@ class UpdatePlayersTask extends SwingWorker<Void, Collection<String>> {
protected void process(List<Collection<String>> players) {
chat.setPlayers(players.get(0));
}
@Override
protected void done() {
try {
get();
} catch (InterruptedException ex) {
logger.fatal("Update Players Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Players Task error", ex);
} catch (CancellationException ex) {}
}
}

View file

@ -115,7 +115,13 @@ public class TournamentPanel extends javax.swing.JPanel implements Observer {
}
public void hideTournament() {
this.setVisible(false);
Component c = this.getParent();
while (c != null && !(c instanceof TournamentPane)) {
c = c.getParent();
}
if (c != null) {
((TournamentPane)c).hideFrame();
}
}
@Override