changes for public server

This commit is contained in:
BetaSteward 2011-05-04 23:18:13 -04:00
parent 1fdc50570f
commit b81938210a
46 changed files with 218 additions and 281 deletions

View file

@ -95,7 +95,7 @@ public class MageFrame extends javax.swing.JFrame {
private static Preferences prefs = Preferences.userNodeForPackage(MageFrame.class);
private JLabel title;
private Rectangle titleRectangle;
private static MageVersion version = new MageVersion(0, 7, 2);
private final static MageVersion version = new MageVersion(0, 7, 2);
/**
* @return the session
@ -728,6 +728,10 @@ public class MageFrame extends javax.swing.JFrame {
btnDeckEditor.setEnabled(true);
}
public void hideTables() {
this.tablesPane.hideTables();
}
public void showDeckEditor(DeckEditorMode mode, Deck deck, UUID tableId, int time) {
try {
DeckEditorPane deckEditorPane = new DeckEditorPane();

View file

@ -1,85 +0,0 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
//package mage.client.chat;
//
//import java.io.Serializable;
//import java.rmi.RemoteException;
//import java.rmi.server.UnicastRemoteObject;
//import java.util.UUID;
//import java.util.logging.Level;
//import java.util.logging.Logger;
//import javax.swing.JTextArea;
//import mage.interfaces.ChatClient;
//import mage.util.Logging;
//
//
///**
// *
// * @author BetaSteward_at_googlemail.com
// */
//public class ChatClientImpl implements ChatClient, Serializable {
//
// private final static Logger logger = Logging.getLogger(ChatClientImpl.class.getName());
//
// private JTextArea textArea;
// private String userName;
// private UUID clientId;
//
// public ChatClientImpl(String userName, JTextArea textArea) {
// this.clientId = UUID.randomUUID();
// this.textArea = textArea;
// try {
// this.userName = userName;
// UnicastRemoteObject.exportObject(this, 0);
// } catch (RemoteException ex) {
// logger.log(Level.SEVERE, null, ex);
// }
// }
//
// @Override
// public void receiveMessage(String message) throws RemoteException {
// this.textArea.append(message + "\n");
// textArea.setCaretPosition(textArea.getText().length() - 1);
// }
//
// @Override
// public String getName() throws RemoteException {
// return userName;
// }
//
// @Override
// public UUID getId() throws RemoteException {
// return clientId;
// }
//
// public UUID getIdLocal() {
// return clientId;
// }
//
//}

View file

@ -59,6 +59,7 @@ public class JoinTableDialog extends MageDialog {
/** Creates new form JoinTableDialog */
public JoinTableDialog() {
initComponents();
newPlayerPanel.showLevel(false);
}
public void showDialog(UUID roomId, UUID tableId) {

View file

@ -78,6 +78,7 @@ public class NewTableDialog extends MageDialog {
/** Creates new form NewTableDialog */
public NewTableDialog() {
initComponents();
player1Panel.showLevel(false);
this.spnNumWins.setModel(new SpinnerNumberModel(1, 1, 5, 1));
}

View file

@ -39,7 +39,7 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jSplitPane1" pref="251" max="32767" attributes="0"/>
<Component id="jSplitPane1" pref="255" max="32767" attributes="0"/>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnMoveDown" alignment="3" min="-2" max="-2" attributes="0"/>

View file

@ -79,29 +79,33 @@ public class TableWaitingDialog extends MageDialog implements Observer {
@Override
public void update(Observable arg0, Object arg1) {
TableView table = session.getTable(roomId, tableId);
if (table != null) {
switch (table.getTableState()) {
case STARTING:
this.btnStart.setEnabled(true);
this.btnMoveDown.setEnabled(true);
this.btnMoveUp.setEnabled(true);
break;
case WAITING:
this.btnStart.setEnabled(false);
this.btnMoveDown.setEnabled(false);
this.btnMoveUp.setEnabled(false);
break;
default:
closeDialog();
return;
try {
TableView table = session.getTable(roomId, tableId);
if (table != null) {
switch (table.getTableState()) {
case STARTING:
this.btnStart.setEnabled(true);
this.btnMoveDown.setEnabled(true);
this.btnMoveUp.setEnabled(true);
break;
case WAITING:
this.btnStart.setEnabled(false);
this.btnMoveDown.setEnabled(false);
this.btnMoveUp.setEnabled(false);
break;
default:
closeDialog();
return;
}
int row = this.tableSeats.getSelectedRow();
tableWaitModel.loadData(table);
this.tableSeats.repaint();
this.tableSeats.getSelectionModel().setSelectionInterval(row, row);
}
int row = this.tableSeats.getSelectedRow();
tableWaitModel.loadData(table);
this.tableSeats.repaint();
this.tableSeats.getSelectionModel().setSelectionInterval(row, row);
}
else {
else {
closeDialog();
}
} catch (Exception ex) {
closeDialog();
}
}

View file

@ -110,6 +110,8 @@ public class Session {
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
} catch (RemoteException ex) {
logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
disconnect();
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
} catch (NotBoundException ex) {
logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
}
@ -120,9 +122,15 @@ public class Session {
if (isConnected()) {
try {
frame.hideTables();
for (UUID chatId: chats.keySet()) {
server.leaveChat(chatId, sessionId);
}
}
catch (Exception ex) {
//swallow all exceptions at this point
}
try {
//TODO: stop daemon
server.deregisterClient(sessionId);
server = null;

View file

@ -100,6 +100,11 @@ public class NewPlayerPanel extends javax.swing.JPanel {
return Integer.valueOf((String)this.cbLevel.getSelectedItem());
}
public void showLevel(boolean show) {
this.cbLevel.setVisible(show);
this.lblLevel.setVisible(show);
}
/** 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

@ -112,12 +112,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
}
} else if (state.equals("Watch")) {
logger.info("Watching table " + tableId);
if (!session.watchTable(roomId, tableId))
hideTables();
session.watchTable(roomId, tableId);
} else if (state.equals("Replay")) {
logger.info("Replaying game " + gameId);
if (!session.replayGame(gameId))
hideTables();
session.replayGame(gameId);
}
}
};
@ -146,7 +144,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
try {
tableModel.loadData(MageFrame.getSession().getTables(roomId));
this.tableTables.repaint();
} catch (MageRemoteException ex) {
} catch (Exception ex) {
hideTables();
}
}
@ -313,7 +311,6 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
table = session.createTable(roomId, options);
session.joinTable(roomId, table.getTableId(), "Human", "Human", 1, Sets.loadDeck("test.dck"));
session.joinTable(roomId, table.getTableId(), "Computer", "Computer - default", 1, Sets.loadDeck("test.dck"));
hideTables();
session.startGame(roomId, table.getTableId());
} catch (Exception ex) {
handleError(ex);