remove games from list when finished + added name and owner to tables

This commit is contained in:
BetaSteward 2011-05-09 23:02:54 -04:00
parent 2f515e242b
commit 017b2b4339
12 changed files with 770 additions and 624 deletions

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<Properties>
@ -23,22 +23,15 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="395" max="32767" attributes="0"/>
<Component id="btnOK" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="lbDeckType" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="463" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="cbGameType" alignment="0" max="32767" attributes="1"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="btnOK" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblNumPlayers" min="-2" max="-2" attributes="0"/>
<Component id="spnNumPlayers" min="-2" pref="57" max="-2" attributes="0"/>
@ -51,7 +44,7 @@
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblAttack" min="-2" max="-2" attributes="0"/>
<Component id="cbAttackOption" pref="235" max="32767" attributes="0"/>
<Component id="cbAttackOption" pref="287" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
@ -59,41 +52,50 @@
<Component id="lblNumWins" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="lblGameType" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="cbDeckType" alignment="0" max="32767" attributes="1"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jSeparator2" pref="555" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="player1Panel" pref="555" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace min="-2" pref="16" max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lbDeckType" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblGameType" alignment="1" min="-2" max="-2" attributes="0"/>
<Component id="lblName" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="cbDeckType" alignment="0" pref="487" max="32767" attributes="1"/>
<Component id="cbGameType" alignment="1" pref="487" max="32767" attributes="1"/>
<Component id="txtName" alignment="1" pref="487" max="32767" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="pnlOtherPlayers" alignment="1" pref="555" max="32767" attributes="0"/>
<Component id="jSeparator1" alignment="0" pref="555" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jSeparator2" pref="503" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="433" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="player1Panel" pref="503" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="436" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jSeparator1" pref="503" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="pnlOtherPlayers" alignment="0" min="-2" pref="486" max="-2" attributes="0"/>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jSeparator3" pref="503" max="32767" attributes="0"/>
<Component id="jSeparator3" pref="555" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -103,14 +105,21 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="lbDeckType" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="cbDeckType" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="lblGameType" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="cbGameType" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lbDeckType" min="-2" max="-2" attributes="0"/>
<Component id="cbDeckType" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cbGameType" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblGameType" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" alignment="1" attributes="0">
@ -144,21 +153,21 @@
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlOtherPlayers" pref="97" max="32767" attributes="0"/>
<Component id="pnlOtherPlayers" pref="136" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jSeparator1" pref="19" max="32767" attributes="0"/>
<Component id="jSeparator1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnOK" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="103" rootIndex="1" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="223" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="201" max="-2" attributes="0"/>
<Component id="jSeparator3" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="159" max="32767" attributes="0"/>
<EmptySpace pref="207" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
@ -167,7 +176,7 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="lblGameType">
<Properties>
<Property name="text" type="java.lang.String" value="Game Type"/>
<Property name="text" type="java.lang.String" value="Game Type:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbGameType">
@ -177,7 +186,7 @@
</Component>
<Component class="javax.swing.JLabel" name="lbDeckType">
<Properties>
<Property name="text" type="java.lang.String" value="Deck Type"/>
<Property name="text" type="java.lang.String" value="Deck Type:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbDeckType">
@ -285,5 +294,15 @@
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumWinsnumPlayersChanged"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="txtName">
</Component>
<Component class="javax.swing.JLabel" name="lblName">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="txtName"/>
</Property>
<Property name="text" type="java.lang.String" value="Name:"/>
</Properties>
</Component>
</SubComponents>
</Form>

View file

@ -47,7 +47,6 @@ import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import mage.Constants.MultiplayerAttackOption;
import mage.Constants.RangeOfInfluence;
import mage.cards.decks.DeckCardLists;
import mage.client.components.MageComponents;
import mage.client.remote.Session;
import mage.client.table.TablePlayerPanel;
@ -112,10 +111,12 @@ public class NewTableDialog extends MageDialog {
jLabel2 = new javax.swing.JLabel();
lblNumWins = new javax.swing.JLabel();
spnNumWins = new javax.swing.JSpinner();
txtName = new javax.swing.JTextField();
lblName = new javax.swing.JLabel();
setTitle("New Table");
lblGameType.setText("Game Type");
lblGameType.setText("Game Type:");
cbGameType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -123,7 +124,7 @@ public class NewTableDialog extends MageDialog {
}
});
lbDeckType.setText("Deck Type");
lbDeckType.setText("Deck Type:");
btnOK.setText("OK");
btnOK.addActionListener(new java.awt.event.ActionListener() {
@ -171,25 +172,22 @@ public class NewTableDialog extends MageDialog {
}
});
lblName.setLabelFor(txtName);
lblName.setText("Name:");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(395, Short.MAX_VALUE)
.addComponent(btnOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lbDeckType)
.addContainerGap(463, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(cbGameType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(btnOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblNumPlayers)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE))
@ -200,52 +198,61 @@ public class NewTableDialog extends MageDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblAttack)
.addComponent(cbAttackOption, 0, 235, Short.MAX_VALUE))
.addComponent(cbAttackOption, 0, 287, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblNumWins)))
.addComponent(lblGameType)
.addComponent(cbDeckType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(player1Panel, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup()
.addGap(16, 16, 16)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lbDeckType)
.addComponent(lblGameType)
.addComponent(lblName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(cbDeckType, javax.swing.GroupLayout.Alignment.LEADING, 0, 487, Short.MAX_VALUE)
.addComponent(cbGameType, 0, 487, Short.MAX_VALUE)
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE))))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addContainerGap(433, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(player1Panel, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addContainerGap(436, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
.addContainerGap())
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 486, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 503, Short.MAX_VALUE)
.addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 555, Short.MAX_VALUE)
.addContainerGap()))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(lbDeckType)
.addGap(0, 0, 0)
.addComponent(cbDeckType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblName)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblGameType)
.addGap(0, 0, 0)
.addComponent(cbGameType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lbDeckType)
.addComponent(cbDeckType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbGameType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblGameType))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
@ -274,19 +281,19 @@ public class NewTableDialog extends MageDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
.addComponent(btnOK))
.addGap(6, 6, 6))
.addContainerGap())
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(223, 223, 223)
.addGap(201, 201, 201)
.addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(159, Short.MAX_VALUE)))
.addContainerGap(207, Short.MAX_VALUE)))
);
pack();
@ -300,7 +307,7 @@ public class NewTableDialog extends MageDialog {
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
GameTypeView gameType = (GameTypeView) cbGameType.getSelectedItem();
MatchOptions options = new MatchOptions("Quick Start Game", gameType.getName());
MatchOptions options = new MatchOptions(this.txtName.getText(), gameType.getName());
options.getPlayerTypes().add("Human");
for (TablePlayerPanel player: players) {
options.getPlayerTypes().add(player.getPlayerType());
@ -447,6 +454,7 @@ public class NewTableDialog extends MageDialog {
private javax.swing.JLabel lbDeckType;
private javax.swing.JLabel lblAttack;
private javax.swing.JLabel lblGameType;
private javax.swing.JLabel lblName;
private javax.swing.JLabel lblNumPlayers;
private javax.swing.JLabel lblNumWins;
private javax.swing.JLabel lblRange;
@ -454,6 +462,7 @@ public class NewTableDialog extends MageDialog {
private javax.swing.JPanel pnlOtherPlayers;
private javax.swing.JSpinner spnNumPlayers;
private javax.swing.JSpinner spnNumWins;
private javax.swing.JTextField txtName;
// End of variables declaration//GEN-END:variables
}

View file

@ -22,27 +22,35 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="pnlPacks" alignment="1" pref="525" max="32767" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<Component id="pnlPacks" alignment="1" pref="563" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnNumPlayers" min="-2" pref="45" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlDraftOptions" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="lblName" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="1" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="txtName" pref="470" max="32767" attributes="0"/>
<Component id="cbTournamentType" alignment="0" pref="470" max="32767" attributes="0"/>
</Group>
</Group>
<Group type="102" alignment="1" attributes="0">
<Component id="btnOk" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" pref="113" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbTournamentType" pref="408" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnNumPlayers" min="-2" pref="45" max="-2" attributes="0"/>
</Group>
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -51,28 +59,35 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblName" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cbTournamentType" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Component id="pnlPacks" pref="49" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="spnNumPlayers" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="pnlPacks" pref="57" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="spnNumPlayers" alignment="0" max="32767" attributes="1"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="pnlDraftOptions" max="32767" attributes="1"/>
</Group>
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Component id="jPanel1" max="32767" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnOk" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -139,15 +154,15 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="pnlOtherPlayers" alignment="0" pref="525" max="32767" attributes="0"/>
<Component id="pnlOtherPlayers" alignment="0" pref="563" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="445" max="-2" attributes="0"/>
<EmptySpace pref="483" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPlayer1Name" pref="490" max="32767" attributes="0"/>
<Component id="txtPlayer1Name" pref="528" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
@ -164,7 +179,7 @@
<Component id="txtPlayer1Name" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="pnlOtherPlayers" pref="60" max="32767" attributes="0"/>
<Component id="pnlOtherPlayers" pref="91" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -206,5 +221,55 @@
<Property name="text" type="java.lang.String" value="Packs"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtName">
</Component>
<Component class="javax.swing.JLabel" name="lblName">
<Properties>
<Property name="text" type="java.lang.String" value="Name:"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlDraftOptions">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel6" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbDraftTiming" min="-2" pref="107" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
<Component id="cbDraftTiming" alignment="3" max="32767" attributes="1"/>
<Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="text" type="java.lang.String" value="Timing:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbDraftTiming">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -1,448 +1,466 @@
/*
* Copyright 2011 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.
*/
/*
* NewTournamentDialog.java
*
* Created on Jan 28, 2011, 12:15:56 PM
*/
package mage.client.dialog;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import mage.Constants.MultiplayerAttackOption;
import mage.Constants.RangeOfInfluence;
import mage.cards.ExpansionSet;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.table.TournamentPlayerPanel;
import mage.game.draft.DraftOptions;
import mage.game.draft.DraftOptions.TimingOption;
import mage.game.tournament.LimitedOptions;
import mage.game.tournament.TournamentOptions;
import mage.sets.Sets;
import mage.util.Logging;
import mage.view.TableView;
import mage.view.TournamentTypeView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class NewTournamentDialog extends MageDialog {
private final static Logger logger = Logging.getLogger(NewTournamentDialog.class.getName());
private TableView table;
private UUID playerId;
private UUID roomId;
private Session session;
private List<TournamentPlayerPanel> players = new ArrayList<TournamentPlayerPanel>();
private List<JComboBox> packs = new ArrayList<JComboBox>();
/** Creates new form NewTournamentDialog */
public NewTournamentDialog() {
initComponents();
}
public void showDialog(UUID roomId) {
this.roomId = roomId;
session = MageFrame.getSession();
this.txtPlayer1Name.setText(session.getUserName());
cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray()));
cbDraftTiming.setModel(new DefaultComboBoxModel(DraftOptions.TimingOption.values()));
this.setModal(true);
setTournamentOptions();
this.setLocation(150, 100);
this.setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
cbTournamentType = new javax.swing.JComboBox();
spnNumPlayers = new javax.swing.JSpinner();
jLabel2 = new javax.swing.JLabel();
btnOk = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
pnlPacks = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
txtPlayer1Name = new javax.swing.JTextField();
pnlOtherPlayers = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
pnlDraftOptions = new javax.swing.JPanel();
cbDraftTiming = new javax.swing.JComboBox();
jLabel6 = new javax.swing.JLabel();
setTitle("New Tournament");
jLabel1.setText("Tournament Type:");
cbTournamentType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbTournamentType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbTournamentTypeActionPerformed(evt);
}
});
spnNumPlayers.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spnNumPlayersStateChanged(evt);
}
});
jLabel2.setText("Players:");
btnOk.setText("OK");
btnOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOkActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
pnlPacks.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel3.setText("Player 1 (You)");
jLabel4.setText("Name:");
txtPlayer1Name.setEditable(false);
pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 445, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel5.setText("Packs");
cbDraftTiming.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jLabel6.setText("Timing:");
javax.swing.GroupLayout pnlDraftOptionsLayout = new javax.swing.GroupLayout(pnlDraftOptions);
pnlDraftOptions.setLayout(pnlDraftOptionsLayout);
pnlDraftOptionsLayout.setHorizontalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createSequentialGroup()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbDraftTiming, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(232, Short.MAX_VALUE))
);
pnlDraftOptionsLayout.setVerticalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbDraftTiming, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlPacks, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbTournamentType, 0, 408, Short.MAX_VALUE))
.addComponent(jLabel5)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(cbTournamentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(3, 3, 3)
.addComponent(jLabel5)
.addGap(1, 1, 1)
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spnNumPlayers)
.addComponent(jLabel2)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnCancel)
.addComponent(btnOk))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void cbTournamentTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTournamentTypeActionPerformed
setTournamentOptions();
}//GEN-LAST:event_cbTournamentTypeActionPerformed
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
TournamentOptions tOptions = new TournamentOptions(tournamentType.getName());
tOptions.setTournamentType(tournamentType.getName());
tOptions.getPlayerTypes().add("Human");
for (TournamentPlayerPanel player: players) {
tOptions.getPlayerTypes().add((String) player.getPlayerType().getSelectedItem());
}
if (tournamentType.isDraft()) {
DraftOptions options = new DraftOptions();
options.setDraftType("");
options.setTiming((TimingOption) this.cbDraftTiming.getSelectedItem());
tOptions.setLimitedOptions(options);
}
if (tournamentType.isLimited()) {
if (tOptions.getLimitedOptions() == null)
tOptions.setLimitedOptions(new LimitedOptions());
for (JComboBox pack: packs) {
tOptions.getLimitedOptions().getSets().add((ExpansionSet) pack.getSelectedItem());
}
}
tOptions.getMatchOptions().setDeckType("Limited");
tOptions.getMatchOptions().setWinsNeeded(2);
tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
table = session.createTournamentTable(roomId, tOptions);
if (session.joinTournamentTable(roomId, table.getTableId(), this.txtPlayer1Name.getText(), "Human", 1)) {
for (TournamentPlayerPanel player: players) {
if (!player.getPlayerType().equals("Human")) {
if (!player.joinTournamentTable(roomId, table.getTableId())) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
session.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
this.setVisible(false);
return;
}
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
session.removeTable(roomId, table.getTableId());
table = null;
}//GEN-LAST:event_btnOkActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.table = null;
this.playerId = null;
this.setVisible(false);
}//GEN-LAST:event_btnCancelActionPerformed
private void spnNumPlayersStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnNumPlayersStateChanged
int numPlayers = (Integer)this.spnNumPlayers.getValue() - 1;
createPlayers(numPlayers);
}//GEN-LAST:event_spnNumPlayersStateChanged
private void setTournamentOptions() {
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
this.spnNumPlayers.setModel(new SpinnerNumberModel(tournamentType.getMinPlayers(), tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
createPlayers(tournamentType.getMinPlayers() - 1);
if (tournamentType.isLimited()) {
this.pnlPacks.setVisible(true);
createPacks(tournamentType.getNumBoosters());
}
else {
this.pnlPacks.setVisible(false);
}
this.pnlDraftOptions.setVisible(tournamentType.isDraft());
}
private void createPacks(int numPacks) {
while (packs.size() < numPacks) {
JComboBox pack = new JComboBox();
pack.setModel(new DefaultComboBoxModel(Sets.getInstance().values().toArray()));
pnlPacks.add(pack);
packs.add(pack);
pack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
packActionPerformed(evt);
}
});
}
this.pack();
this.revalidate();
this.repaint();
}
private void packActionPerformed(java.awt.event.ActionEvent evt) {
boolean start = false;
int selectedIndex = 0;
for (JComboBox pack: packs) {
if (!start) {
if (evt.getSource().equals(pack)) {
start = true;
selectedIndex = pack.getSelectedIndex();
}
}
else {
pack.setSelectedIndex(selectedIndex);
}
}
}
private void createPlayers(int numPlayers) {
if (numPlayers > players.size()) {
while (players.size() != numPlayers) {
TournamentPlayerPanel playerPanel = new TournamentPlayerPanel();
playerPanel.init(players.size() + 2);
players.add(playerPanel);
}
}
else if (numPlayers < players.size()) {
while (players.size() != numPlayers) {
players.remove(players.size() - 1);
}
}
drawPlayers();
}
private void drawPlayers() {
this.pnlOtherPlayers.removeAll();
for (TournamentPlayerPanel panel: players) {
this.pnlOtherPlayers.add(panel);
panel.getPlayerType().addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
playerActionPerformed(evt);
}
});
}
this.pack();
this.revalidate();
this.repaint();
}
private void playerActionPerformed(java.awt.event.ActionEvent evt) {
boolean start = false;
int selectedIndex = 0;
for (TournamentPlayerPanel player: players) {
if (!start) {
if (evt.getSource().equals(player.getPlayerType())) {
start = true;
selectedIndex = player.getPlayerType().getSelectedIndex();
}
}
else {
player.getPlayerType().setSelectedIndex(selectedIndex);
}
}
}
public TableView getTable() {
return table;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOk;
private javax.swing.JComboBox cbDraftTiming;
private javax.swing.JComboBox cbTournamentType;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel pnlDraftOptions;
private javax.swing.JPanel pnlOtherPlayers;
private javax.swing.JPanel pnlPacks;
private javax.swing.JSpinner spnNumPlayers;
private javax.swing.JTextField txtPlayer1Name;
// End of variables declaration//GEN-END:variables
}
/*
* Copyright 2011 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.
*/
/*
* NewTournamentDialog.java
*
* Created on Jan 28, 2011, 12:15:56 PM
*/
package mage.client.dialog;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.SpinnerNumberModel;
import mage.Constants.MultiplayerAttackOption;
import mage.Constants.RangeOfInfluence;
import mage.cards.ExpansionSet;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.table.TournamentPlayerPanel;
import mage.game.draft.DraftOptions;
import mage.game.draft.DraftOptions.TimingOption;
import mage.game.tournament.LimitedOptions;
import mage.game.tournament.TournamentOptions;
import mage.sets.Sets;
import mage.util.Logging;
import mage.view.TableView;
import mage.view.TournamentTypeView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class NewTournamentDialog extends MageDialog {
private final static Logger logger = Logging.getLogger(NewTournamentDialog.class.getName());
private TableView table;
private UUID playerId;
private UUID roomId;
private Session session;
private List<TournamentPlayerPanel> players = new ArrayList<TournamentPlayerPanel>();
private List<JComboBox> packs = new ArrayList<JComboBox>();
/** Creates new form NewTournamentDialog */
public NewTournamentDialog() {
initComponents();
}
public void showDialog(UUID roomId) {
this.roomId = roomId;
session = MageFrame.getSession();
this.txtPlayer1Name.setText(session.getUserName());
cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray()));
cbDraftTiming.setModel(new DefaultComboBoxModel(DraftOptions.TimingOption.values()));
this.setModal(true);
setTournamentOptions();
this.setLocation(150, 100);
this.setVisible(true);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
cbTournamentType = new javax.swing.JComboBox();
spnNumPlayers = new javax.swing.JSpinner();
jLabel2 = new javax.swing.JLabel();
btnOk = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
pnlPacks = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
txtPlayer1Name = new javax.swing.JTextField();
pnlOtherPlayers = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
txtName = new javax.swing.JTextField();
lblName = new javax.swing.JLabel();
pnlDraftOptions = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
cbDraftTiming = new javax.swing.JComboBox();
setTitle("New Tournament");
jLabel1.setText("Tournament Type:");
cbTournamentType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbTournamentType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbTournamentTypeActionPerformed(evt);
}
});
spnNumPlayers.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
spnNumPlayersStateChanged(evt);
}
});
jLabel2.setText("Players:");
btnOk.setText("OK");
btnOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnOkActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
pnlPacks.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel3.setText("Player 1 (You)");
jLabel4.setText("Name:");
txtPlayer1Name.setEditable(false);
pnlOtherPlayers.setLayout(new java.awt.GridLayout(0, 1, 2, 0));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 483, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(txtPlayer1Name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 91, Short.MAX_VALUE))
);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel5.setText("Packs");
lblName.setText("Name:");
jLabel6.setText("Timing:");
cbDraftTiming.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
javax.swing.GroupLayout pnlDraftOptionsLayout = new javax.swing.GroupLayout(pnlDraftOptions);
pnlDraftOptions.setLayout(pnlDraftOptionsLayout);
pnlDraftOptionsLayout.setHorizontalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbDraftTiming, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pnlDraftOptionsLayout.setVerticalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbDraftTiming)
.addComponent(jLabel6))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(lblName)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(txtName, javax.swing.GroupLayout.DEFAULT_SIZE, 470, Short.MAX_VALUE)
.addComponent(cbTournamentType, javax.swing.GroupLayout.Alignment.LEADING, 0, 470, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblName))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(cbTournamentType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, 57, Short.MAX_VALUE)
.addGap(11, 11, 11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spnNumPlayers)
.addComponent(jLabel2))
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOk)
.addComponent(btnCancel)))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void cbTournamentTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbTournamentTypeActionPerformed
setTournamentOptions();
}//GEN-LAST:event_cbTournamentTypeActionPerformed
private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
TournamentOptions tOptions = new TournamentOptions(this.txtName.getText());
tOptions.setTournamentType(tournamentType.getName());
tOptions.getPlayerTypes().add("Human");
for (TournamentPlayerPanel player: players) {
tOptions.getPlayerTypes().add((String) player.getPlayerType().getSelectedItem());
}
if (tournamentType.isDraft()) {
DraftOptions options = new DraftOptions();
options.setDraftType("");
options.setTiming((TimingOption) this.cbDraftTiming.getSelectedItem());
tOptions.setLimitedOptions(options);
}
if (tournamentType.isLimited()) {
if (tOptions.getLimitedOptions() == null)
tOptions.setLimitedOptions(new LimitedOptions());
for (JComboBox pack: packs) {
tOptions.getLimitedOptions().getSets().add((ExpansionSet) pack.getSelectedItem());
}
}
tOptions.getMatchOptions().setDeckType("Limited");
tOptions.getMatchOptions().setWinsNeeded(2);
tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
table = session.createTournamentTable(roomId, tOptions);
if (session.joinTournamentTable(roomId, table.getTableId(), this.txtPlayer1Name.getText(), "Human", 1)) {
for (TournamentPlayerPanel player: players) {
if (!player.getPlayerType().equals("Human")) {
if (!player.joinTournamentTable(roomId, table.getTableId())) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
session.removeTable(roomId, table.getTableId());
table = null;
return;
}
}
}
this.setVisible(false);
return;
}
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error joining tournament.", "Error", JOptionPane.ERROR_MESSAGE);
session.removeTable(roomId, table.getTableId());
table = null;
}//GEN-LAST:event_btnOkActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.table = null;
this.playerId = null;
this.setVisible(false);
}//GEN-LAST:event_btnCancelActionPerformed
private void spnNumPlayersStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_spnNumPlayersStateChanged
int numPlayers = (Integer)this.spnNumPlayers.getValue() - 1;
createPlayers(numPlayers);
}//GEN-LAST:event_spnNumPlayersStateChanged
private void setTournamentOptions() {
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
this.spnNumPlayers.setModel(new SpinnerNumberModel(tournamentType.getMinPlayers(), tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
createPlayers(tournamentType.getMinPlayers() - 1);
if (tournamentType.isLimited()) {
this.pnlPacks.setVisible(true);
createPacks(tournamentType.getNumBoosters());
}
else {
this.pnlPacks.setVisible(false);
}
this.pnlDraftOptions.setVisible(tournamentType.isDraft());
}
private void createPacks(int numPacks) {
while (packs.size() > numPacks) {
pnlPacks.remove(packs.get(packs.size() - 1));
packs.remove(packs.size() - 1);
}
while (packs.size() < numPacks) {
JComboBox pack = new JComboBox();
pack.setModel(new DefaultComboBoxModel(Sets.getInstance().values().toArray()));
pnlPacks.add(pack);
packs.add(pack);
pack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
packActionPerformed(evt);
}
});
}
this.pack();
this.revalidate();
this.repaint();
}
private void packActionPerformed(java.awt.event.ActionEvent evt) {
boolean start = false;
int selectedIndex = 0;
for (JComboBox pack: packs) {
if (!start) {
if (evt.getSource().equals(pack)) {
start = true;
selectedIndex = pack.getSelectedIndex();
}
}
else {
pack.setSelectedIndex(selectedIndex);
}
}
}
private void createPlayers(int numPlayers) {
if (numPlayers > players.size()) {
while (players.size() != numPlayers) {
TournamentPlayerPanel playerPanel = new TournamentPlayerPanel();
playerPanel.init(players.size() + 2);
players.add(playerPanel);
}
}
else if (numPlayers < players.size()) {
while (players.size() != numPlayers) {
players.remove(players.size() - 1);
}
}
drawPlayers();
}
private void drawPlayers() {
this.pnlOtherPlayers.removeAll();
for (TournamentPlayerPanel panel: players) {
this.pnlOtherPlayers.add(panel);
panel.getPlayerType().addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
playerActionPerformed(evt);
}
});
}
this.pack();
this.revalidate();
this.repaint();
}
private void playerActionPerformed(java.awt.event.ActionEvent evt) {
boolean start = false;
int selectedIndex = 0;
for (TournamentPlayerPanel player: players) {
if (!start) {
if (evt.getSource().equals(player.getPlayerType())) {
start = true;
selectedIndex = player.getPlayerType().getSelectedIndex();
}
}
else {
player.getPlayerType().setSelectedIndex(selectedIndex);
}
}
}
public TableView getTable() {
return table;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOk;
private javax.swing.JComboBox cbDraftTiming;
private javax.swing.JComboBox cbTournamentType;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JPanel jPanel1;
private javax.swing.JLabel lblName;
private javax.swing.JPanel pnlDraftOptions;
private javax.swing.JPanel pnlOtherPlayers;
private javax.swing.JPanel pnlPacks;
private javax.swing.JSpinner spnNumPlayers;
private javax.swing.JTextField txtName;
private javax.swing.JTextField txtPlayer1Name;
// End of variables declaration//GEN-END:variables
}

View file

@ -93,10 +93,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
public void actionPerformed(ActionEvent e)
{
int modelRow = Integer.valueOf( e.getActionCommand() );
UUID tableId = UUID.fromString((String)tableModel.getValueAt(modelRow, 0));
UUID gameId = (UUID)tableModel.getValueAt(modelRow, 6);
String state = (String)tableModel.getValueAt(modelRow, 4);
boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, 5);
UUID tableId = (UUID)tableModel.getValueAt(modelRow, 8);
UUID gameId = (UUID)tableModel.getValueAt(modelRow, 7);
String state = (String)tableModel.getValueAt(modelRow, 5);
boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, 6);
if (state.equals("Join")) {
if (isTournament) {
@ -120,7 +120,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
}
};
ButtonColumn buttonColumn = new ButtonColumn(tableTables, join, 4);
ButtonColumn buttonColumn = new ButtonColumn(tableTables, join, 5);
jSplitPane1.setOpaque(false);
jScrollPane1.setOpaque(false);
@ -344,7 +344,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
}
class TableTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Table Id", "Game Type", "Deck Type", "Status", "Action"};
private String[] columnNames = new String[]{"Table Name", "Owner", "Game Type", "Deck Type", "Status", "Action"};
private TableView[] tables = new TableView[0];
@ -367,14 +367,16 @@ class TableTableModel extends AbstractTableModel {
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return tables[arg0].getTableId().toString();
return tables[arg0].getTableName();
case 1:
return tables[arg0].getGameType().toString();
return tables[arg0].getControllerName();
case 2:
return tables[arg0].getDeckType().toString();
return tables[arg0].getGameType().toString();
case 3:
return tables[arg0].getTableState().toString();
return tables[arg0].getDeckType().toString();
case 4:
return tables[arg0].getTableState().toString();
case 5:
switch (tables[arg0].getTableState()) {
case WAITING:
return "Join";
@ -385,12 +387,14 @@ class TableTableModel extends AbstractTableModel {
default:
return "";
}
case 5:
return tables[arg0].isTournament();
case 6:
return tables[arg0].isTournament();
case 7:
if (!tables[arg0].getGames().isEmpty())
return tables[arg0].getGames().get(0);
return null;
case 8:
return tables[arg0].getTableId();
}
return "";
}
@ -412,7 +416,7 @@ class TableTableModel extends AbstractTableModel {
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex != 4)
if (columnIndex != 5)
return false;
return true;
}

View file

@ -47,6 +47,8 @@ public class TableView implements Serializable {
private UUID tableId;
private String gameType;
private String deckType;
private String tableName;
private String controllerName;
private TableState tableState;
private boolean isTournament;
private List<SeatView> seats = new ArrayList<SeatView>();
@ -55,6 +57,8 @@ public class TableView implements Serializable {
public TableView(Table table) {
this.tableId = table.getId();
this.gameType = table.getGameType();
this.tableName = table.getName();
this.controllerName = table.getControllerName();
this.deckType = table.getDeckType();
this.tableState = table.getState();
this.isTournament = table.isTournament();
@ -72,6 +76,14 @@ public class TableView implements Serializable {
return tableId;
}
public String getTableName() {
return tableName;
}
public String getControllerName() {
return controllerName;
}
public String getGameType() {
return gameType;
}

View file

@ -1,5 +1,5 @@
#default levels
log4j.rootLogger=debug, logfile
log4j.rootLogger=debug, console
#console log
log4j.appender.console=org.apache.log4j.ConsoleAppender

View file

@ -66,26 +66,29 @@ public class TableController {
private UUID sessionId;
private UUID chatId;
private String controllerName;
private Table table;
private Match match;
private MatchOptions options;
private Tournament tournament;
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
public TableController(UUID sessionId, MatchOptions options) {
public TableController(UUID roomId, UUID sessionId, MatchOptions options) {
this.sessionId = sessionId;
chatId = ChatManager.getInstance().createChatSession();
this.options = options;
match = GameFactory.getInstance().createMatch(options.getGameType(), options);
table = new Table(options.getGameType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
controllerName = SessionManager.getInstance().getSession(sessionId).getUsername();
table = new Table(roomId, options.getGameType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getDeckType()), options.getPlayerTypes(), match);
init();
}
public TableController(UUID sessionId, TournamentOptions options) {
public TableController(UUID roomId, UUID sessionId, TournamentOptions options) {
this.sessionId = sessionId;
chatId = ChatManager.getInstance().createChatSession();
tournament = TournamentFactory.getInstance().createTournament(options.getTournamentType(), options);
table = new Table(options.getTournamentType(), options.getName(), DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
controllerName = SessionManager.getInstance().getSession(sessionId).getUsername();
table = new Table(roomId, options.getTournamentType(), options.getName(), controllerName, DeckValidatorFactory.getInstance().createDeckValidator(options.getMatchOptions().getDeckType()), options.getPlayerTypes(), tournament);
}
private void init() {
@ -320,7 +323,7 @@ public class TableController {
UUID choosingPlayerId = match.getChooser();
match.endGame();
table.endGame();
GameManager.getInstance().saveGame(match.getGame().getId());
// GameManager.getInstance().saveGame(match.getGame().getId());
GameManager.getInstance().removeGame(match.getGame().getId());
try {
if (!match.isMatchOver()) {
@ -328,6 +331,9 @@ public class TableController {
match.sideboard();
startGame(choosingPlayerId);
}
else {
GamesRoomManager.getInstance().getRoom(table.getRoomId()).removeTable(sessionId, table.getId());
}
} catch (GameException ex) {
logger.fatal(null, ex);
}

View file

@ -58,22 +58,22 @@ public class TableManager {
return INSTANCE;
}
public Table createTable(UUID sessionId, MatchOptions options) {
TableController tableController = new TableController(sessionId, options);
public Table createTable(UUID roomId, UUID sessionId, MatchOptions options) {
TableController tableController = new TableController(roomId, sessionId, options);
controllers.put(tableController.getTable().getId(), tableController);
tables.put(tableController.getTable().getId(), tableController.getTable());
return tableController.getTable();
}
public Table createTable(MatchOptions options) {
TableController tableController = new TableController(UUID.randomUUID(), options);
public Table createTable(UUID roomId, MatchOptions options) {
TableController tableController = new TableController(roomId, UUID.randomUUID(), options);
controllers.put(tableController.getTable().getId(), tableController);
tables.put(tableController.getTable().getId(), tableController.getTable());
return tableController.getTable();
}
public Table createTournamentTable(UUID sessionId, TournamentOptions options) {
TableController tableController = new TableController(sessionId, options);
public Table createTournamentTable(UUID roomId, UUID sessionId, TournamentOptions options) {
TableController tableController = new TableController(roomId, sessionId, options);
controllers.put(tableController.getTable().getId(), tableController);
tables.put(tableController.getTable().getId(), tableController.getTable());
return tableController.getTable();

View file

@ -73,7 +73,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
@Override
public TableView createTable(UUID sessionId, MatchOptions options) {
Table table = TableManager.getInstance().createTable(sessionId, options);
Table table = TableManager.getInstance().createTable(this.getRoomId(), sessionId, options);
tables.put(table.getId(), table);
return new TableView(table);
}
@ -89,7 +89,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
@Override
public TableView createTournamentTable(UUID sessionId, TournamentOptions options) {
Table table = TableManager.getInstance().createTournamentTable(sessionId, options);
Table table = TableManager.getInstance().createTournamentTable(this.getRoomId(), sessionId, options);
tables.put(table.getId(), table);
return new TableView(table);
}

View file

@ -44,6 +44,7 @@ import mage.game.tournament.TournamentPairing;
import mage.game.tournament.TournamentPlayer;
import mage.server.ChatManager;
import mage.server.TableManager;
import mage.server.game.GamesRoomManager;
import mage.server.util.ThreadExecutor;
import mage.view.ChatMessage.MessageColor;
import mage.view.TournamentView;
@ -169,7 +170,7 @@ public class TournamentController {
private void startMatch(TournamentPairing pair, MatchOptions matchOptions) {
try {
TableManager tableManager = TableManager.getInstance();
Table table = tableManager.createTable(matchOptions);
Table table = tableManager.createTable(GamesRoomManager.getInstance().getMainRoomId(), matchOptions);
TournamentPlayer player1 = pair.getPlayer1();
TournamentPlayer player2 = pair.getPlayer2();
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());

View file

@ -47,7 +47,9 @@ import mage.players.Player;
public class Table implements Serializable {
private UUID tableId;
private UUID roomId;
private String name;
private String controllerName;
private String gameType;
private Seat[] seats;
private int numSeats;
@ -59,23 +61,25 @@ public class Table implements Serializable {
protected TableEventSource tableEventSource = new TableEventSource();
public Table(String gameType, String name, DeckValidator validator, List<String> playerTypes, Tournament tournament) {
this(gameType, name, validator, playerTypes);
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, Tournament tournament) {
this(roomId, gameType, name, controllerName, validator, playerTypes);
this.tournament = tournament;
this.isTournament = true;
}
public Table(String gameType, String name, DeckValidator validator, List<String> playerTypes, Match match) {
this(gameType, name, validator, playerTypes);
public Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes, Match match) {
this(roomId, gameType, name, controllerName, validator, playerTypes);
this.match = match;
this.isTournament = false;
}
protected Table(String gameType, String name, DeckValidator validator, List<String> playerTypes) {
protected Table(UUID roomId, String gameType, String name, String controllerName, DeckValidator validator, List<String> playerTypes) {
tableId = UUID.randomUUID();
this.roomId = roomId;
this.numSeats = playerTypes.size();
this.gameType = gameType;
this.name = name;
this.controllerName = controllerName;
createSeats(playerTypes);
this.validator = validator;
}
@ -93,6 +97,10 @@ public class Table implements Serializable {
return tableId;
}
public UUID getRoomId() {
return roomId;
}
public void initGame() {
state = TableState.DUELING;
}
@ -194,4 +202,8 @@ public class Table implements Serializable {
return tournament;
}
public String getControllerName() {
return controllerName;
}
}