added tournaments - drafts are now a variant of tournament

This commit is contained in:
BetaSteward 2011-02-06 11:09:25 -05:00
parent 78e60ce457
commit ffc7b5bfd8
88 changed files with 3768 additions and 311 deletions

View file

@ -75,6 +75,7 @@ import java.util.prefs.Preferences;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
import mage.client.draft.DraftPane;
import mage.client.tournament.TournamentPane;
/**
* @author BetaSteward_at_googlemail.com
@ -155,6 +156,14 @@ public class MageFrame extends javax.swing.JFrame {
e1.printStackTrace();
}
tournamentPane = new TournamentPane();
desktopPane.add(tournamentPane, javax.swing.JLayeredPane.DEFAULT_LAYER);
try {
tournamentPane.setMaximum(true);
} catch (java.beans.PropertyVetoException e1) {
e1.printStackTrace();
}
addTooltipContainer();
setBackground();
addMageLabel();
@ -407,6 +416,12 @@ public class MageFrame extends javax.swing.JFrame {
this.draftPane.showDraft(draftId);
}
public void showTournament(UUID tournamentId) {
this.tournamentPane.setVisible(true);
this.tournamentPane.toFront();
this.tournamentPane.showTournament(tournamentId);
}
public static boolean connect(String userName, String serverName, int port) {
return session.connect(userName, serverName, port);
}
@ -746,6 +761,7 @@ public class MageFrame extends javax.swing.JFrame {
private static final long serialVersionUID = -9104885239063142218L;
private ImagePanel backgroundPane;
private DraftPane draftPane;
private TournamentPane tournamentPane;
public void setStatusText(String status) {
this.lblStatus.setText(status);

View file

@ -1,6 +1,29 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
* 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.
*/
/*
@ -14,11 +37,9 @@ package mage.client.cards;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.UUID;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.client.MageFrame;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.view.CardView;
@ -97,13 +118,6 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
@Override
public void mouseClicked(MouseEvent e) {
/*if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume();
Object obj = e.getSource();
if (obj instanceof MageCard) {
this.cardEventSource.doubleClick(((MageCard)obj).getOriginal().getId(), "double-click");
}
}*/
}
@Override

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.JPanelFormInfo">
<AuxValues>

View file

@ -35,13 +35,9 @@
package mage.client.dialog;
import java.awt.Cursor;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.util.Config;
import mage.util.Logging;
@ -212,9 +208,6 @@ public class ConnectDialog extends MageDialog {
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
this.setVisible(false);
}
else {
JOptionPane.showMessageDialog(rootPane, "Unable to connect to server");
}
}
finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

View file

@ -0,0 +1,210 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<Properties>
<Property name="title" type="java.lang.String" value="New Tournament"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" 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"/>
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<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>
</Group>
</DimensionLayout>
<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="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"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="1" max="-2" attributes="0"/>
<Component id="pnlPacks" pref="47" 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"/>
</Group>
<EmptySpace min="-2" pref="19" max="-2" attributes="0"/>
<Component id="jPanel1" max="32767" attributes="0"/>
<EmptySpace min="-2" 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" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="text" type="java.lang.String" value="Tournament Type:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbTournamentType">
<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>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbTournamentTypeActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JSpinner" name="spnNumPlayers">
<Events>
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumPlayersStateChanged"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Players:"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnOk">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOkActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnCancel">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCancelActionPerformed"/>
</Events>
</Component>
<Container class="javax.swing.JPanel" name="pnlPacks">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
<Property name="columns" type="int" value="1"/>
<Property name="horizontalGap" type="int" value="2"/>
<Property name="rows" type="int" value="0"/>
</Layout>
</Container>
<Container class="javax.swing.JPanel" name="jPanel1">
<Layout>
<DimensionLayout dim="0">
<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"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="445" 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"/>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="jLabel4" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtPlayer1Name" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="pnlOtherPlayers" pref="58" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Player 1 (You)"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel4">
<Properties>
<Property name="text" type="java.lang.String" value="Name:"/>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtPlayer1Name">
<Properties>
<Property name="editable" type="boolean" value="false"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlOtherPlayers">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
<Property name="columns" type="int" value="1"/>
<Property name="horizontalGap" type="int" value="2"/>
<Property name="rows" type="int" value="0"/>
</Layout>
</Container>
</SubComponents>
</Container>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Packs"/>
</Properties>
</Component>
</SubComponents>
</Form>

View file

@ -0,0 +1,359 @@
/*
* 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.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()));
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();
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, 58, Short.MAX_VALUE))
);
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel5.setText("Packs");
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(pnlPacks, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 525, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, 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))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel5))
.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, 47, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(19, 19, 19)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.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(player.getPlayerType());
}
if (tournamentType.isDraft()) {
tOptions.getDraftOptions().setDraftType("");
tOptions.getDraftOptions().setTiming(DraftOptions.TimingOption.REGULAR);
for (JComboBox pack: packs) {
tOptions.getDraftOptions().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())) {
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);
createPacks(tournamentType.getNumBoosters());
}
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);
}
this.pack();
this.revalidate();
this.repaint();
}
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);
}
this.pack();
this.revalidate();
this.repaint();
}
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 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.JPanel jPanel1;
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
}

View file

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<Properties>
@ -39,7 +39,7 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jSplitPane1" pref="247" max="32767" attributes="0"/>
<Component id="jSplitPane1" pref="251" 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

@ -60,6 +60,7 @@ public class TableWaitingDialog extends MageDialog implements Observer {
private UUID tableId;
private UUID roomId;
private boolean isTournament;
private Session session;
private TableWaitModel tableWaitModel;
private SeatsWatchdog seatsWatchdog = new SeatsWatchdog();
@ -105,9 +106,10 @@ public class TableWaitingDialog extends MageDialog implements Observer {
}
}
public void showDialog(UUID roomId, UUID tableId) {
public void showDialog(UUID roomId, UUID tableId, boolean isTournament) {
this.roomId = roomId;
this.tableId = tableId;
this.isTournament = isTournament;
session = MageFrame.getSession();
if (session.isTableOwner(roomId, tableId)) {
this.btnStart.setVisible(true);
@ -235,7 +237,10 @@ public class TableWaitingDialog extends MageDialog implements Observer {
private void btnStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStartActionPerformed
closeDialog();
session.startGame(roomId, tableId);
if (!isTournament)
session.startGame(roomId, tableId);
else
session.startTournament(roomId, tableId);
}//GEN-LAST:event_btnStartActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed

View file

@ -86,6 +86,10 @@ public class Client implements CallbackClient {
GameManager.getInstance().setCurrentPlayerUUID(message.getPlayerId());
gameStarted(message.getGameId(), message.getPlayerId());
}
else if(callback.getMethod().equals("startTournament")) {
TableClientMessage message = (TableClientMessage) callback.getData();
tournamentStarted(message.getGameId(), message.getPlayerId());
}
else if(callback.getMethod().equals("startDraft")) {
TableClientMessage message = (TableClientMessage) callback.getData();
draftStarted(message.getGameId(), message.getPlayerId());
@ -171,6 +175,9 @@ public class Client implements CallbackClient {
TableClientMessage message = (TableClientMessage) callback.getData();
construct(message.getDeck(), message.getTableId());
}
else if (callback.getMethod().equals("draftOver")) {
session.getDraft().hideDraft();
}
else if (callback.getMethod().equals("draftPick")) {
DraftClientMessage message = (DraftClientMessage) callback.getData();
session.getDraft().loadBooster(message.getDraftPickView());
@ -189,6 +196,9 @@ public class Client implements CallbackClient {
else if (callback.getMethod().equals("draftInit")) {
session.ack("draftInit");
}
else if (callback.getMethod().equals("tournamentInit")) {
session.ack("tournamentInit");
}
messageId = callback.getMessageId();
}
catch (Exception ex) {
@ -202,7 +212,7 @@ public class Client implements CallbackClient {
return clientId;
}
protected void gameStarted(UUID gameId, UUID playerId) {
protected void gameStarted(final UUID gameId, final UUID playerId) {
try {
frame.showGame(gameId, playerId);
logger.info("Game " + gameId + " started for player " + playerId);
@ -210,7 +220,7 @@ public class Client implements CallbackClient {
catch (Exception ex) {
handleException(ex);
}
if (Plugins.getInstance().isCounterPluginLoaded()) {
Plugins.getInstance().addGamesPlayed();
}
@ -226,6 +236,16 @@ public class Client implements CallbackClient {
}
}
protected void tournamentStarted(UUID tournamentId, UUID playerId) {
try {
frame.showTournament(tournamentId);
logger.info("Tournament " + tournamentId + " started for player " + playerId);
}
catch (Exception ex) {
handleException(ex);
}
}
protected void watchGame(UUID gameId) {
try {
frame.watchGame(gameId);

View file

@ -46,17 +46,20 @@ import mage.client.chat.ChatPanel;
import mage.client.components.MageUI;
import mage.client.draft.DraftPanel;
import mage.client.game.GamePanel;
import mage.client.tournament.TournamentPanel;
import mage.client.util.Config;
import mage.game.GameException;
import mage.game.draft.DraftOptions;
import mage.interfaces.MageException;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.interfaces.Server;
import mage.interfaces.ServerState;
import mage.interfaces.callback.CallbackClientDaemon;
import mage.util.Logging;
import mage.view.GameTypeView;
import mage.view.TableView;
import mage.view.TournamentTypeView;
import mage.view.TournamentView;
/**
*
@ -75,6 +78,7 @@ public class Session {
private Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private GamePanel game;
private DraftPanel draft;
private TournamentPanel tournament;
private CallbackClientDaemon callbackDaemon;
private MageUI ui = new MageUI();
@ -101,6 +105,7 @@ public class Session {
return true;
} catch (MageException ex) {
logger.log(Level.SEVERE, null, ex);
JOptionPane.showMessageDialog(frame, "Unable to connect to server. " + ex.getMessage());
} catch (RemoteException ex) {
logger.log(Level.SEVERE, "Unable to connect to server - ", ex);
} catch (NotBoundException ex) {
@ -156,6 +161,10 @@ public class Session {
return serverState.getDeckTypes();
}
public List<TournamentTypeView> getTournamentTypes() {
return serverState.getTournamentTypes();
}
public boolean isTestMode() {
return serverState.isTestMode();
}
@ -180,6 +189,10 @@ public class Session {
draft = draftPanel;
}
public void setTournament(TournamentPanel tournament) {
this.tournament = tournament;
}
public UUID getMainRoomId() {
try {
return server.getMainRoomId();
@ -272,9 +285,9 @@ public class Session {
return false;
}
public boolean joinDraftTable(UUID roomId, UUID tableId, String playerName) {
public boolean joinTournamentTable(UUID roomId, UUID tableId, String playerName) {
try {
return server.joinDraftTable(sessionId, roomId, tableId, playerName);
return server.joinTournamentTable(sessionId, roomId, tableId, playerName);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
@ -297,6 +310,29 @@ public class Session {
}
}
public TournamentView getTournament(UUID tournamentId) throws MageRemoteException {
try {
return server.getTournament(tournamentId);
} catch (RemoteException ex) {
handleRemoteException(ex);
throw new MageRemoteException();
} catch (MageException ex) {
handleMageException(ex);
throw new MageRemoteException();
}
}
public UUID getTournamentChatId(UUID tournamentId) {
try {
return server.getTournamentChatId(tournamentId);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return null;
}
public boolean sendPlayerUUID(UUID gameId, UUID data) {
try {
server.sendPlayerUUID(gameId, sessionId, data);
@ -419,6 +455,18 @@ public class Session {
return false;
}
public boolean joinTournament(UUID tournamentId) {
try {
server.joinTournament(tournamentId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean watchGame(UUID gameId) {
try {
server.watchGame(gameId, sessionId);
@ -454,9 +502,9 @@ public class Session {
return null;
}
public TableView createDraftTable(UUID roomId, DraftOptions draftOptions) {
public TableView createTournamentTable(UUID roomId, TournamentOptions tournamentOptions) {
try {
return server.createDraftTable(sessionId, roomId, draftOptions);
return server.createTournamentTable(sessionId, roomId, tournamentOptions);
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
@ -524,9 +572,9 @@ public class Session {
return false;
}
public boolean startDraft(UUID roomId, UUID tableId) {
public boolean startTournament(UUID roomId, UUID tableId) {
try {
server.startDraft(sessionId, roomId, tableId);
server.startTournament(sessionId, roomId, tableId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
@ -650,4 +698,5 @@ public class Session {
public MageUI getUI() {
return ui;
}
}

View file

@ -34,30 +34,15 @@
package mage.client.table;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.filechooser.FileFilter;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.client.MageFrame;
import mage.client.deck.generator.DeckGenerator;
import mage.client.util.Config;
import mage.client.util.gui.ColorsChooser;
import mage.sets.Sets;
/**
*
@ -119,8 +104,8 @@ public class NewPlayerPanel extends javax.swing.JPanel {
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
// </editor-fold>//GEN-END:initComponents
// <editor-fold defaultstate="collapsed" desc="Generated Code">
// </editor-fold>
private void initComponents() {
lblPlayerName = new javax.swing.JLabel();

View file

@ -40,10 +40,10 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="btnNewTable" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="6" max="-2" attributes="0"/>
<Component id="btnNewDraft" min="-2" max="-2" attributes="0"/>
<Component id="btnNewTournament" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnQuickStart" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="450" max="32767" attributes="0"/>
<EmptySpace pref="416" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -54,7 +54,7 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnNewTable" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnQuickStart" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnNewDraft" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnNewTournament" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="16" max="32767" attributes="0"/>
</Group>
@ -78,12 +78,12 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnQuickStartActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnNewDraft">
<Component class="javax.swing.JButton" name="btnNewTournament">
<Properties>
<Property name="text" type="java.lang.String" value="New Draft"/>
<Property name="text" type="java.lang.String" value="New Tournament"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnNewDraftActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnNewTournamentActionPerformed"/>
</Events>
</Component>
</SubComponents>

View file

@ -58,6 +58,9 @@ import java.awt.event.ActionListener;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.client.dialog.NewTournamentDialog;
import mage.game.draft.DraftOptions;
import mage.game.tournament.TournamentOptions;
/**
@ -73,6 +76,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
private TablesWatchdog tablesWatchdog = new TablesWatchdog();
private JoinTableDialog joinTableDialog;
private NewTableDialog newTableDialog;
private NewTournamentDialog newTournamentDialog;
private TableWaitingDialog tableWaitingDialog;
private Session session;
@ -99,7 +103,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
joinTableDialog.showDialog(roomId, tableId);
if (joinTableDialog.isJoined())
tableWaitingDialog.showDialog(roomId, tableId);
tableWaitingDialog.showDialog(roomId, tableId, false);
} else if (state.equals("Watch")) {
logger.info("Watching table " + tableId);
if (!session.watchTable(roomId, tableId))
@ -152,6 +156,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
newTableDialog = new NewTableDialog();
MageFrame.getDesktop().add(newTableDialog);
}
if (newTournamentDialog == null) {
newTournamentDialog = new NewTournamentDialog();
MageFrame.getDesktop().add(newTournamentDialog);
}
if (joinTableDialog == null) {
joinTableDialog = new JoinTableDialog();
MageFrame.getDesktop().add(joinTableDialog);
@ -201,7 +209,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
jPanel1 = new javax.swing.JPanel();
btnNewTable = new javax.swing.JButton();
btnQuickStart = new javax.swing.JButton();
btnNewDraft = new javax.swing.JButton();
btnNewTournament = new javax.swing.JButton();
jSplitPane1 = new javax.swing.JSplitPane();
chatPanel = new mage.client.chat.ChatPanel();
jScrollPane1 = new javax.swing.JScrollPane();
@ -221,14 +229,12 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
}
});
btnNewDraft.setText("New Draft");
btnNewDraft.addActionListener(new java.awt.event.ActionListener() {
btnNewTournament.setText("New Tournament");
btnNewTournament.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNewDraftActionPerformed(evt);
btnNewTournamentActionPerformed(evt);
}
});
//FIXME: removed on released 0.6 version
btnNewDraft.setVisible(false);
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
@ -238,10 +244,10 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
.addContainerGap()
.addComponent(btnNewTable)
.addGap(6, 6, 6)
.addComponent(btnNewDraft)
.addComponent(btnNewTournament)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnQuickStart)
.addContainerGap(450, Short.MAX_VALUE))
.addContainerGap(416, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -250,7 +256,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnNewTable)
.addComponent(btnQuickStart)
.addComponent(btnNewDraft))
.addComponent(btnNewTournament))
.addContainerGap(16, Short.MAX_VALUE))
);
@ -284,7 +290,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
private void btnNewTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTableActionPerformed
newTableDialog.showDialog(roomId);
if (newTableDialog.getTable() != null) {
tableWaitingDialog.showDialog(roomId, newTableDialog.getTable().getTableId());
tableWaitingDialog.showDialog(roomId, newTableDialog.getTable().getTableId(), false);
}
}//GEN-LAST:event_btnNewTableActionPerformed
@ -318,9 +324,12 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
}
}//GEN-LAST:event_btnQuickStartActionPerformed
private void btnNewDraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewDraftActionPerformed
}//GEN-LAST:event_btnNewDraftActionPerformed
private void btnNewTournamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTournamentActionPerformed
newTournamentDialog.showDialog(roomId);
if (newTournamentDialog.getTable() != null) {
tableWaitingDialog.showDialog(roomId, newTournamentDialog.getTable().getTableId(), true);
}
}//GEN-LAST:event_btnNewTournamentActionPerformed
private void handleError(Exception ex) {
logger.log(Level.SEVERE, "Error loading deck", ex);
@ -329,8 +338,8 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnNewDraft;
private javax.swing.JButton btnNewTable;
private javax.swing.JButton btnNewTournament;
private javax.swing.JButton btnQuickStart;
private mage.client.chat.ChatPanel chatPanel;
private javax.swing.JPanel jPanel1;

View file

@ -0,0 +1,105 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lblPlayerNum" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbPlayerType" min="-2" pref="175" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlPlayerName" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="2" attributes="0">
<Component id="lblPlayerNum" alignment="2" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="2" min="-2" max="-2" attributes="0"/>
<Component id="cbPlayerType" alignment="2" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="pnlPlayerName" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel1">
<Properties>
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
<ComponentRef name="cbPlayerType"/>
</Property>
<Property name="text" type="java.lang.String" value="Type:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbPlayerType">
<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>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbPlayerTypeActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblPlayerNum">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="Tahoma" size="11" style="1"/>
</Property>
<Property name="text" type="java.lang.String" value="Player Num:"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlPlayerName">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" 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="txtPlayerName" pref="189" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="txtPlayerName" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JTextField" name="txtPlayerName">
</Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" value="Name:"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -0,0 +1,168 @@
/*
* 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.
*/
/*
* TournamentPlayerPanel.java
*
* Created on Jan 28, 2011, 1:50:29 PM
*/
package mage.client.table;
import java.util.UUID;
import javax.swing.DefaultComboBoxModel;
import mage.client.MageFrame;
import mage.client.remote.Session;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPlayerPanel extends javax.swing.JPanel {
private Session session;
/** Creates new form TournamentPlayerPanel */
public TournamentPlayerPanel() {
initComponents();
this.pnlPlayerName.setVisible(false);
}
public void init(int playerNum) {
session = MageFrame.getSession();
cbPlayerType.setModel(new DefaultComboBoxModel(session.getPlayerTypes()));
this.lblPlayerNum.setText("Player " + playerNum);
}
public String getPlayerType() {
return (String) this.cbPlayerType.getSelectedItem();
}
public boolean joinTournamentTable(UUID roomId, UUID tableId) {
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
return session.joinTournamentTable(roomId, tableId, this.txtPlayerName.getText());
}
return 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();
cbPlayerType = new javax.swing.JComboBox();
lblPlayerNum = new javax.swing.JLabel();
pnlPlayerName = new javax.swing.JPanel();
txtPlayerName = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel1.setLabelFor(cbPlayerType);
jLabel1.setText("Type:");
cbPlayerType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbPlayerType.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbPlayerTypeActionPerformed(evt);
}
});
lblPlayerNum.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
lblPlayerNum.setText("Player Num:");
jLabel2.setText("Name:");
javax.swing.GroupLayout pnlPlayerNameLayout = new javax.swing.GroupLayout(pnlPlayerName);
pnlPlayerName.setLayout(pnlPlayerNameLayout);
pnlPlayerNameLayout.setHorizontalGroup(
pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPlayerNameLayout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPlayerName, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
);
pnlPlayerNameLayout.setVerticalGroup(
pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPlayerNameLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblPlayerNum)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbPlayerType, javax.swing.GroupLayout.PREFERRED_SIZE, 175, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlPlayerName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(lblPlayerNum)
.addComponent(jLabel1)
.addComponent(cbPlayerType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(pnlPlayerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
}// </editor-fold>//GEN-END:initComponents
private void cbPlayerTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbPlayerTypeActionPerformed
if (!this.cbPlayerType.getSelectedItem().equals("Human")) {
this.pnlPlayerName.setVisible(true);
if (this.txtPlayerName.getText().length() == 0) {
this.txtPlayerName.setText("Computer " + this.lblPlayerNum.getText());
}
}
else {
this.pnlPlayerName.setVisible(false);
}
this.revalidate();
this.repaint();
}//GEN-LAST:event_cbPlayerTypeActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox cbPlayerType;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel lblPlayerNum;
private javax.swing.JPanel pnlPlayerName;
private javax.swing.JTextField txtPlayerName;
// End of variables declaration//GEN-END:variables
}

View file

@ -0,0 +1,35 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JInternalFrameFormInfo">
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="tournamentPanel1" alignment="0" pref="758" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="tournamentPanel1" alignment="0" pref="522" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="mage.client.tournament.TournamentPanel" name="tournamentPanel1">
</Component>
</SubComponents>
</Form>

View file

@ -0,0 +1,87 @@
/*
* 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.
*/
/*
* TournamentPane.java
*
* Created on 22-Jan-2011, 11:41:47 PM
*/
package mage.client.tournament;
import java.util.UUID;
import mage.client.MagePane;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPane extends MagePane {
/** Creates new form TournamentPane */
public TournamentPane() {
initComponents();
}
public void showTournament(UUID tournamentId) {
this.setTitle("Tournament " + tournamentId);
this.tournamentPanel1.showTournament(tournamentId);
this.repaint();
}
/** 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() {
tournamentPanel1 = new mage.client.tournament.TournamentPanel();
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tournamentPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(tournamentPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.tournament.TournamentPanel tournamentPanel1;
// End of variables declaration//GEN-END:variables
}

View file

@ -0,0 +1,76 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="jScrollPane1" pref="573" max="32767" attributes="2"/>
<Component id="jScrollPane2" alignment="1" pref="573" max="32767" attributes="2"/>
</Group>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="chatPanel1" min="-2" pref="215" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="jScrollPane1" min="-2" pref="262" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="jScrollPane2" pref="260" max="32767" attributes="0"/>
</Group>
<Component id="chatPanel1" alignment="0" pref="522" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="mage.client.chat.ChatPanel" name="chatPanel1">
</Component>
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="tablePlayers">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="this.playersModel" type="code"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="tableMatches">
<Properties>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="matchesModel" type="code"/>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -0,0 +1,300 @@
/*
* 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.
*/
/*
* TournamentPanel.java
*
* Created on 20-Jan-2011, 9:18:30 PM
*/
package mage.client.tournament;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.UUID;
import javax.swing.Timer;
import javax.swing.table.AbstractTableModel;
import mage.client.MageFrame;
import mage.client.remote.MageRemoteException;
import mage.client.remote.Session;
import mage.view.RoundView;
import mage.view.TournamentGameView;
import mage.view.TournamentPlayerView;
import mage.view.TournamentView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TournamentPanel extends javax.swing.JPanel implements Observer {
private UUID tournamentId;
private Session session;
private TournamentPlayersTableModel playersModel;
private TournamentMatchesTableModel matchesModel;
private TournamentWatchdog tournamentWatchdog = new TournamentWatchdog();
/** Creates new form TournamentPanel */
public TournamentPanel() {
playersModel = new TournamentPlayersTableModel();
matchesModel = new TournamentMatchesTableModel();
initComponents();
tablePlayers.createDefaultColumnsFromModel();
tableMatches.createDefaultColumnsFromModel();
}
public synchronized void showTournament(UUID tournamentId) {
this.tournamentId = tournamentId;
session = MageFrame.getSession();
session.setTournament(this);
UUID chatRoomId = session.getTournamentChatId(tournamentId);
if (session.joinTournament(tournamentId) && chatRoomId != null) {
this.chatPanel1.connect(chatRoomId);
tournamentWatchdog.addObserver(this);
this.setVisible(true);
this.repaint();
}
else {
hideTournament();
}
}
public void hideTournament() {
this.setVisible(false);
}
@Override
public void update(Observable arg0, Object arg1) {
TournamentView tournament;
try {
tournament = MageFrame.getSession().getTournament(tournamentId);
playersModel.loadData(tournament);
matchesModel.loadData(tournament);
this.tablePlayers.repaint();
this.tableMatches.repaint();
} catch (MageRemoteException ex) {
hideTournament();
}
}
/** 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() {
chatPanel1 = new mage.client.chat.ChatPanel();
jScrollPane1 = new javax.swing.JScrollPane();
tablePlayers = new javax.swing.JTable();
jScrollPane2 = new javax.swing.JScrollPane();
tableMatches = new javax.swing.JTable();
tablePlayers.setModel(this.playersModel);
jScrollPane1.setViewportView(tablePlayers);
tableMatches.setModel(matchesModel);
jScrollPane2.setViewportView(tableMatches);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE))
.addGap(0, 0, 0)
.addComponent(chatPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 260, Short.MAX_VALUE))
.addComponent(chatPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.chat.ChatPanel chatPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable tableMatches;
private javax.swing.JTable tablePlayers;
// End of variables declaration//GEN-END:variables
}
class TournamentPlayersTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Player Name", "Points", "Results"};
private TournamentPlayerView[] players = new TournamentPlayerView[0];
public void loadData(TournamentView tournament) {
players = tournament.getPlayers().toArray(new TournamentPlayerView[0]);
this.fireTableDataChanged();
}
@Override
public int getRowCount() {
return players.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return players[arg0].getName();
case 1:
return Integer.toString(players[arg0].getPoints());
case 2:
return players[arg0].getResults();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
colName = columnNames[columnIndex];
return colName;
}
@Override
public Class getColumnClass(int columnIndex){
return String.class;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
class TournamentMatchesTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Round Number", "Players", "Match Id", "Game Id", "State", "Result"};
private TournamentGameView[] games = new TournamentGameView[0];
public void loadData(TournamentView tournament) {
List<TournamentGameView> views = new ArrayList<TournamentGameView>();
for (RoundView round: tournament.getRounds()) {
for (TournamentGameView game: round.getGames()) {
views.add(game);
}
}
games = views.toArray(new TournamentGameView[0]);
this.fireTableDataChanged();
}
@Override
public int getRowCount() {
return games.length;
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return Integer.toString(games[arg0].getRoundNum());
case 1:
return games[arg0].getPlayers();
case 2:
return games[arg0].getMatchId().toString();
case 3:
return games[arg0].getGameId().toString();
case 4:
return games[arg0].getState();
case 5:
return games[arg0].getResult();
}
return "";
}
@Override
public String getColumnName(int columnIndex) {
String colName = "";
if (columnIndex <= getColumnCount())
colName = columnNames[columnIndex];
return colName;
}
@Override
public Class getColumnClass(int columnIndex){
return String.class;
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
class TournamentWatchdog extends Observable implements ActionListener {
Timer t = new Timer(1000, this); // check every second
public TournamentWatchdog() {
t.start();
}
@Override
public void actionPerformed(ActionEvent arg0) {
setChanged();
notifyObservers();
}
}