Some changes to userData handling. Added country flag to some dialogs. Saved and restored some more table columns width and order information.

This commit is contained in:
LevelX2 2015-06-28 00:10:38 +02:00
parent cb3b5f895b
commit 87f3978589
32 changed files with 1982 additions and 1699 deletions

View file

@ -63,7 +63,7 @@ import org.mage.card.arcane.ManaSymbols;
* @author BetaSteward_at_googlemail.com, nantuko
*/
public class ChatPanel extends javax.swing.JPanel {
private UUID chatId;
private Session session;
private final List<String> players = new ArrayList<>();
@ -71,7 +71,7 @@ public class ChatPanel extends javax.swing.JPanel {
/**
* Chat message color for opponents.
*/
private static final String OPPONENT_COLOR = "#FF7F50";
private static final String OPPONENT_COLOR = "#FF7F50";
/**
* Chat message color for client player.
*/
@ -123,7 +123,7 @@ public class ChatPanel extends javax.swing.JPanel {
private ChatType chatType = ChatType.DEFAULT;
private static final int[] defaultColumnsWidth = {20, 100, 100, 80};
public enum ChatType {
DEFAULT, GAME, TABLES, TOURNAMENT
@ -142,6 +142,7 @@ public class ChatPanel extends javax.swing.JPanel {
*/
/**
* Creates new form ChatPanel
*
* @param addPlayersTab
*/
public ChatPanel(boolean addPlayersTab) {
@ -151,10 +152,10 @@ public class ChatPanel extends javax.swing.JPanel {
jTablePlayers.setBackground(new Color(0, 0, 0, ALPHA));
jTablePlayers.setForeground(Color.white);
jTablePlayers.setRowSorter(new MageTableRowSorter(userTableModel));
TableUtil.setColumnWidthAndOrder(jTablePlayers, defaultColumnsWidth, KEY_USERS_COLUMNS_WIDTH, KEY_USERS_COLUMNS_ORDER);
jTablePlayers.setDefaultRenderer(Icon.class, new CountryCellRenderer());
if (jScrollPaneTxt != null) {
jScrollPaneTxt.setBackground(new Color(0, 0, 0, ALPHA));
jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, ALPHA));
@ -169,7 +170,7 @@ public class ChatPanel extends javax.swing.JPanel {
}
public void cleanUp() {
TableUtil.saveColumnWidthAndOrderToPrefs(jTablePlayers, KEY_USERS_COLUMNS_WIDTH, KEY_USERS_COLUMNS_ORDER);
TableUtil.saveColumnWidthAndOrderToPrefs(jTablePlayers, KEY_USERS_COLUMNS_WIDTH, KEY_USERS_COLUMNS_ORDER);
}
public ChatType getChatType() {
@ -248,7 +249,7 @@ public class ChatPanel extends javax.swing.JPanel {
}
if (username != null && !username.isEmpty()) {
text.append(getColoredText(userColor, username + userSeparator));
}
}
text.append(getColoredText(textColor, ManaSymbols.replaceSymbolsWithHTML(message, ManaSymbols.Type.PAY)));
this.txtConversation.append(text.toString());
}
@ -262,6 +263,7 @@ public class ChatPanel extends javax.swing.JPanel {
sb.append("</font>");
return sb.toString();
}
public String getText() {
return txtConversation.getText();
}
@ -325,8 +327,8 @@ public class ChatPanel extends javax.swing.JPanel {
}
class UserTableModel extends AbstractTableModel {
private final String[] columnNames = new String[]{" ","Players", "Info", "Games", "Connection"};
private final String[] columnNames = new String[]{"Loc", "Players", "Info", "Games", "Connection"};
private UsersView[] players = new UsersView[0];
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
@ -334,12 +336,12 @@ public class ChatPanel extends javax.swing.JPanel {
this.players = roomUserInfo.getUsersView().toArray(new UsersView[0]);
JTableHeader th = jTablePlayers.getTableHeader();
TableColumnModel tcm = th.getColumnModel();
tcm.getColumn(jTablePlayers.convertColumnIndexToView(1)).setHeaderValue("Players (" + this.players.length + ")");
tcm.getColumn(jTablePlayers.convertColumnIndexToView(3)).setHeaderValue(
"Games " + roomUserInfo.getNumberActiveGames() +
(roomUserInfo.getNumberActiveGames() != roomUserInfo.getNumberGameThreads() ? " (T:" + roomUserInfo.getNumberGameThreads():" (") +
" limit: " + roomUserInfo.getNumberMaxGames() + ")");
"Games " + roomUserInfo.getNumberActiveGames()
+ (roomUserInfo.getNumberActiveGames() != roomUserInfo.getNumberGameThreads() ? " (T:" + roomUserInfo.getNumberGameThreads() : " (")
+ " limit: " + roomUserInfo.getNumberMaxGames() + ")");
th.repaint();
this.fireTableDataChanged();
}
@ -358,7 +360,7 @@ public class ChatPanel extends javax.swing.JPanel {
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return players[arg0].getFlagName();
return players[arg0].getFlagName();
case 1:
return players[arg0].getUserName();
case 2:
@ -389,16 +391,14 @@ public class ChatPanel extends javax.swing.JPanel {
return Icon.class;
default:
return String.class;
}
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
return false;
}
}
public void clear() {
@ -486,9 +486,9 @@ public class ChatPanel extends javax.swing.JPanel {
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jScrollPaneTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)));
.addComponent(jScrollPaneTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)));
jTablePlayers = null;
jScrollPanePlayers = null;
}

View file

@ -1,30 +1,30 @@
/*
* 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.
*/
* 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.
*/
package mage.client.dialog;
import java.util.HashSet;
@ -46,6 +46,7 @@ import mage.cards.repository.ExpansionRepository;
import mage.client.MageFrame;
import mage.client.constants.Constants.DeckEditorMode;
import mage.constants.Rarity;
import org.apache.log4j.Logger;
/**
*
@ -53,12 +54,16 @@ import mage.constants.Rarity;
*/
public class AddLandDialog extends MageDialog {
private static final Logger logger = Logger.getLogger(MageDialog.class);
private Deck deck;
private final Set<String> setCodesland = new HashSet<>();
private static final int DEFAULT_SEALED_DECK_CARD_NUMBER = 40;
/** Creates new form AddLandDialog */
/**
* Creates new form AddLandDialog
*/
public AddLandDialog() {
initComponents();
this.setModal(true);
@ -69,7 +74,7 @@ public class AddLandDialog extends MageDialog {
SortedSet<String> landSets = new TreeSet<>();
if (!mode.equals(DeckEditorMode.FREE_BUILDING)) {
// decide from which sets basic lands are taken from
for (String setCode :deck.getExpansionSetCodes()) {
for (String setCode : deck.getExpansionSetCodes()) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo != null && expansionInfo.hasBasicLands()) {
this.setCodesland.add(expansionInfo.getCode());
@ -79,11 +84,11 @@ public class AddLandDialog extends MageDialog {
// if sets have no basic land, take land from block
if (this.setCodesland.isEmpty()) {
for (String setCode :deck.getExpansionSetCodes()) {
for (String setCode : deck.getExpansionSetCodes()) {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByCode(setCode);
if (expansionInfo != null) {
List<ExpansionInfo> blockSets = ExpansionRepository.instance.getSetsFromBlock(expansionInfo.getBlockName());
for (ExpansionInfo blockSet: blockSets) {
for (ExpansionInfo blockSet : blockSets) {
if (blockSet.hasBasicLands()) {
this.setCodesland.add(blockSet.getCode());
landSets.add(blockSet.getName());
@ -92,22 +97,22 @@ public class AddLandDialog extends MageDialog {
}
}
}
}
}
// if still no set with lands found, add list of all available
if (this.setCodesland.isEmpty()) {
List<ExpansionInfo> basicLandSets = ExpansionRepository.instance.getSetsWithBasicLandsByReleaseDate();
for (ExpansionInfo expansionInfo: basicLandSets) {
for (ExpansionInfo expansionInfo : basicLandSets) {
landSets.add(expansionInfo.getName());
}
}
}
if (landSets.isEmpty()) {
throw new IllegalArgumentException("No set with basic land was found");
}
if(landSets.size() > 1) {
if (landSets.size() > 1) {
landSets.add("<Random lands>");
}
cbLandSet.setModel(new DefaultComboBoxModel(landSets.toArray()));
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
this.setVisible(true);
}
@ -115,7 +120,7 @@ public class AddLandDialog extends MageDialog {
private void addLands(String landName, int number) {
Random random = new Random();
String landSetName = (String) cbLandSet.getSelectedItem();
CardCriteria criteria = new CardCriteria();
if (landSetName.equals("<Random lands>")) {
criteria.setCodes(setCodesland.toArray(new String[setCodesland.size()]));
@ -123,13 +128,17 @@ public class AddLandDialog extends MageDialog {
ExpansionInfo expansionInfo = ExpansionRepository.instance.getSetByName(landSetName);
if (expansionInfo == null) {
throw new IllegalArgumentException("Code of Set " + landSetName + " not found");
}
criteria.setCodes(expansionInfo.getCode());
}
}
criteria.setCodes(expansionInfo.getCode());
}
criteria.rarities(Rarity.LAND).name(landName);
List<CardInfo> cards = CardRepository.instance.findCards(criteria);
if (cards.isEmpty()) {
throw new IllegalArgumentException("No basic lands found in Set: " + landSetName);
logger.error("No basic lands found in Set: " + landSetName);
criteria = new CardCriteria();
criteria.rarities(Rarity.LAND).name(landName);
criteria.setCodes("M15");
cards = CardRepository.instance.findCards(criteria);
}
for (int i = 0; i < number; i++) {
@ -138,10 +147,10 @@ public class AddLandDialog extends MageDialog {
}
}
/** 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.
/**
* 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
@ -298,11 +307,11 @@ public class AddLandDialog extends MageDialog {
}//GEN-LAST:event_btnCancelActionPerformed
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
int nForest = ((Number)spnForest.getValue()).intValue();
int nIsland = ((Number)spnIsland.getValue()).intValue();
int nMountain = ((Number)spnMountain.getValue()).intValue();
int nPlains = ((Number)spnPlains.getValue()).intValue();
int nSwamp = ((Number)spnSwamp.getValue()).intValue();
int nForest = ((Number) spnForest.getValue()).intValue();
int nIsland = ((Number) spnIsland.getValue()).intValue();
int nMountain = ((Number) spnMountain.getValue()).intValue();
int nPlains = ((Number) spnPlains.getValue()).intValue();
int nSwamp = ((Number) spnSwamp.getValue()).intValue();
addLands("Forest", nForest);
addLands("Island", nIsland);
@ -316,7 +325,7 @@ public class AddLandDialog extends MageDialog {
autoAddLands();
}//GEN-LAST:event_btnAutoAddActionPerformed
private void autoAddLands(){
private void autoAddLands() {
int red = 0;
int green = 0;
int black = 0;
@ -324,7 +333,9 @@ public class AddLandDialog extends MageDialog {
int white = 0;
Set<Card> cards = deck.getCards();
int land_number = DEFAULT_SEALED_DECK_CARD_NUMBER - cards.size();
if(land_number < 0) land_number = 0;
if (land_number < 0) {
land_number = 0;
}
for (Card cd : cards) {
Mana m = cd.getManaCost().getMana();
red += m.getRed();
@ -334,14 +345,18 @@ public class AddLandDialog extends MageDialog {
white += m.getWhite();
}
int total = red + green + black + blue + white;
int redcards = Math.round(land_number*((float)red/(float)total));
total -= red; land_number -= redcards;
int greencards = Math.round(land_number*((float)green/(float)total));
total -= green; land_number -= greencards;
int blackcards = Math.round(land_number*((float)black/(float)total));
total -= black; land_number -= blackcards;
int bluecards = Math.round(land_number*((float)blue/(float)total));
total -= blue; land_number -= bluecards;
int redcards = Math.round(land_number * ((float) red / (float) total));
total -= red;
land_number -= redcards;
int greencards = Math.round(land_number * ((float) green / (float) total));
total -= green;
land_number -= greencards;
int blackcards = Math.round(land_number * ((float) black / (float) total));
total -= black;
land_number -= blackcards;
int bluecards = Math.round(land_number * ((float) blue / (float) total));
total -= blue;
land_number -= bluecards;
int whitecards = land_number;
spnMountain.setValue(redcards);
spnForest.setValue(greencards);
@ -349,7 +364,7 @@ public class AddLandDialog extends MageDialog {
spnIsland.setValue(bluecards);
spnPlains.setValue(whitecards);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAdd;
private javax.swing.JButton btnAutoAdd;

View file

@ -1,30 +1,30 @@
/*
* 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.
*/
* 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.
*/
/*
* PreferencesDialog.java
@ -63,10 +63,11 @@ import mage.client.MageFrame;
import mage.client.util.Config;
import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder;
import mage.players.net.UserData;
import mage.players.net.UserGroup;
import mage.players.net.UserSkipPrioritySteps;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import mage.view.UserDataView;
import org.apache.log4j.Logger;
/**
@ -77,7 +78,7 @@ import org.apache.log4j.Logger;
public class PreferencesDialog extends javax.swing.JDialog {
private static final transient Logger log = Logger.getLogger(PreferencesDialog.class);
public static final String KEY_HAND_USE_BIG_CARDS = "handUseBigCards";
public static final String KEY_SHOW_TOOLTIPS_ANY_ZONE = "showTooltipsInAnyZone";
public static final String KEY_SHOW_CARD_NAMES = "showCardNames";
@ -88,7 +89,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_GAME_SHOW_STORM_COUNTER = "gameShowStormCounter";
public static final String KEY_GAME_CONFIRM_EMPTY_MANA_POOL = "gameConfirmEmptyManaPool";
public static final String KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER = "gameAskMoveToGraveORder";
public static final String KEY_GAME_LOG_AUTO_SAVE = "gameLogAutoSave";
public static final String KEY_CARD_IMAGES_USE_DEFAULT = "cardImagesUseDefault";
@ -96,12 +97,12 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_CARD_IMAGES_CHECK = "cardImagesCheck";
public static final String KEY_CARD_IMAGES_SAVE_TO_ZIP = "cardImagesSaveToZip";
public static final String KEY_CARD_IMAGES_PREF_LANGUAGE = "cardImagesPreferedImageLaguage";
public static final String KEY_BACKGROUND_IMAGE = "backgroundImage";
public static final String KEY_BATTLEFIELD_IMAGE = "battlefieldImage";
public static final String KEY_BACKGROUND_IMAGE_DEFAULT = "backgroundImagedDefault";
public static final String KEY_BATTLEFIELD_IMAGE_RANDOM = "battlefieldImagerandom";
public static final String KEY_BATTLEFIELD_IMAGE_DEFAULT = "battlefieldImageDefault";
public static final String KEY_BATTLEFIELD_IMAGE_DEFAULT = "battlefieldImageDefault";
public static final String KEY_SOUNDS_GAME_ON = "soundsOn";
public static final String KEY_SOUNDS_DRAFT_ON = "soundsDraftOn";
@ -112,7 +113,6 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_BIG_CARD_TOGGLED = "bigCardToggled";
// Phases
public static final String UPKEEP_YOU = "upkeepYou";
public static final String DRAW_YOU = "drawYou";
@ -138,15 +138,15 @@ public class PreferencesDialog extends javax.swing.JDialog {
// mana auto payment
public static final String KEY_GAME_MANA_AUTOPAYMENT = "gameManaAutopayment";
public static final String KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE = "gameManaAutopaymentOnlyOne";
// Size of frame to check if divider locations should be used
public static final String KEY_MAGE_PANEL_LAST_SIZE = "gamepanelLastSize";
// pref settings of table settings and filtering
public static final String KEY_TABLES_FILTER_SETTINGS = "tablePanelFilterSettings";
public static final String KEY_TABLES_COLUMNS_WIDTH = "tablePanelColumnWidth";
public static final String KEY_TABLES_COLUMNS_ORDER = "tablePanelColumnSort";
// positions of divider bars
public static final String KEY_TABLES_DIVIDER_LOCATION_1 = "tablePanelDividerLocation1";
public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2";
@ -155,11 +155,20 @@ public class PreferencesDialog extends javax.swing.JDialog {
// user list
public static final String KEY_USERS_COLUMNS_WIDTH = "userPanelColumnWidth";
public static final String KEY_USERS_COLUMNS_ORDER = "userPanelColumnSort";
// table waiting dialog
public static final String KEY_TABLE_WAITING_WIDTH = "tableWaitingPanelWidth";
public static final String KEY_TABLE_WAITING_HEIGHT = "tableWaitingPanelHeight";
public static final String KEY_TABLE_WAITING_COLUMNS_WIDTH = "tableWaitingPanelColumnWidth";
public static final String KEY_TABLE_WAITING_COLUMNS_ORDER = "tableWaitingPanelColumnSort";
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_0 = "gamepanelDividerLocation0";
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_1 = "gamepanelDividerLocation1";
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2";
public static final String KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH = "tournamentPlayerPanelColumnWidth";
public static final String KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER = "tournamentPlayerPanelColumnSort";
public static final String KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH = "tournamentMatchPanelColumnWidth";
public static final String KEY_TOURNAMENT_MATCH_COLUMNS_ORDER = "tournamentMatchPanelColumnSort";
public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_1 = "tournamentPanelDividerLocation1";
public static final String KEY_TOURNAMENT_DIVIDER_LOCATION_2 = "tournamentPanelDividerLocation2";
@ -204,7 +213,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
// used to save and restore the settings for the cardArea (draft, sideboarding, deck builder)
public static final String KEY_DRAFT_VIEW = "draftView";
public static final String KEY_DRAFT_SORT_BY = "draftSortBy";
public static final String KEY_DRAFT_SORT_INDEX = "draftSortIndex";
public static final String KEY_DRAFT_SORT_ASCENDING = "draftSortAscending";
@ -234,10 +243,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_CONNECTION_URL_SERVER_LIST = "connectionURLServerList";
public static final String KEY_AVATAR = "selectedId";
public static final String KEY_CONNECT_AUTO_CONNECT = "autoConnect";
public static final String KEY_CONNECT_FLAG = "connectFlag";
private static final Map<String, String> cache = new HashMap<>();
@ -278,38 +286,37 @@ public class PreferencesDialog extends javax.swing.JDialog {
{
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
}
private final JFileChooser fc_i = new JFileChooser();
{
fc_i.setAcceptAllFileFilterUsed(false);
fc_i.addChoosableFileFilter(new ImageFileFilter());
}
private static class ImageFileFilter extends FileFilter{
private static class ImageFileFilter extends FileFilter {
@Override
public boolean accept(File f) {
String filename = f.getName();
if(f.isDirectory()){
if (f.isDirectory()) {
return true;
}
if(filename != null){
if(filename.endsWith(".jpg") || filename.endsWith(".jpeg") ||
filename.endsWith(".png") || filename.endsWith(".bmp")){
return true;
if (filename != null) {
if (filename.endsWith(".jpg") || filename.endsWith(".jpeg")
|| filename.endsWith(".png") || filename.endsWith(".bmp")) {
return true;
}
}
return false;
}
@Override
public String getDescription() {
return "*.png | *.bmp |*.jpg | *.jpeg";
}
return "*.png | *.bmp |*.jpg | *.jpeg";
}
}
/**
* Creates new form PreferencesDialog
*
@ -322,15 +329,15 @@ public class PreferencesDialog extends javax.swing.JDialog {
txtImageFolderPath.setEditable(false);
cbProxyType.setModel(new DefaultComboBoxModel<>(Connection.ProxyType.values()));
addAvatars();
cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(new String[] {"en","de","fr","it","es","pt","jp","cn","ru","tw","ko"}));
cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(new String[]{"en", "de", "fr", "it", "es", "pt", "jp", "cn", "ru", "tw", "ko"}));
}
/** 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.
/**
* 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
@ -1698,9 +1705,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, dialog.cbUseDefaultImageFolder, KEY_CARD_IMAGES_USE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY);
saveImagesPath(prefs);
save(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbPreferedImageLanguage, KEY_CARD_IMAGES_PREF_LANGUAGE);
save(prefs, dialog.cbUseDefaultBackground, KEY_BACKGROUND_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbUseDefaultBattleImage, KEY_BATTLEFIELD_IMAGE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbUseRandomBattleImage, KEY_BATTLEFIELD_IMAGE_RANDOM, "true", "false", UPDATE_CACHE_POLICY);
@ -1712,7 +1719,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, dialog.cbEnableOtherSounds, KEY_SOUNDS_OTHER_ON, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbEnableBattlefieldBGM, KEY_SOUNDS_MATCH_MUSIC_ON, "true", "false", UPDATE_CACHE_POLICY);
saveSoundPath(prefs);
// connection
save(prefs, dialog.cbProxyType, KEY_PROXY_TYPE);
save(prefs, dialog.txtProxyServer, KEY_PROXY_ADDRESS);
@ -1770,7 +1777,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
private void btnBrowseImageLocationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseImageLocationActionPerformed
int returnVal = fc.showOpenDialog(PreferencesDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
txtImageFolderPath.setText(file.getAbsolutePath());
@ -1803,101 +1810,101 @@ public class PreferencesDialog extends javax.swing.JDialog {
}//GEN-LAST:event_cbEnableGameSoundsActionPerformed
private void cbEnableBattlefieldBGMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbEnableBattlefieldBGMActionPerformed
if(cbEnableBattlefieldBGM.isSelected()){
if (cbEnableBattlefieldBGM.isSelected()) {
txtBattlefieldIBGMPath.setEnabled(true);
btnBattlefieldBGMBrowse.setEnabled(true);
}else{
} else {
txtBattlefieldIBGMPath.setEnabled(false);
btnBattlefieldBGMBrowse.setEnabled(false);
}
}//GEN-LAST:event_cbEnableBattlefieldBGMActionPerformed
private void cbUseDefaultBackgroundActionPerformed(java.awt.event.ActionEvent evt) {
if(cbUseDefaultBackground.isSelected()){
if (cbUseDefaultBackground.isSelected()) {
useDefaultBackgroundImage();
}else{
} else {
useSelectBackgroundImage();
}
}
}
private void useDefaultBackgroundImage(){
private void useDefaultBackgroundImage() {
txtBackgroundImagePath.setEnabled(false);
btnBrowseBackgroundImage.setEnabled(false);
txtBackgroundImagePath.setText("");
}
private void useSelectBackgroundImage(){
private void useSelectBackgroundImage() {
String path = cache.get(KEY_BACKGROUND_IMAGE);
dialog.txtBackgroundImagePath.setText(path);
txtBackgroundImagePath.setEnabled(true);
btnBrowseBackgroundImage.setEnabled(true);
}
private void cbUseDefaultBattleImageActionPerformed(java.awt.event.ActionEvent evt) {
if(cbUseDefaultBattleImage.isSelected()){
if (cbUseDefaultBattleImage.isSelected()) {
useDefaultBattlefield();
}else{
} else {
useSelectedOrRandom();
}
}
private void useDefaultBattlefield(){
}
private void useDefaultBattlefield() {
cbUseRandomBattleImage.setEnabled(false);
txtBattlefieldImagePath.setEnabled(false);
btnBrowseBattlefieldImage.setEnabled(false);
}
private void useSelectedOrRandom(){
private void useSelectedOrRandom() {
cbUseRandomBattleImage.setEnabled(true);
String temp = cache.get(KEY_BATTLEFIELD_IMAGE_RANDOM);
if(temp != null){
if(temp.equals("true")){
if (temp != null) {
if (temp.equals("true")) {
useRandomBattleField();
cbUseRandomBattleImage.setSelected(true);
}else{
} else {
useSelectedBattleField();
cbUseRandomBattleImage.setSelected(false);
}
}else{
useSelectedBattleField();
cbUseRandomBattleImage.setSelected(false);
} else {
useSelectedBattleField();
cbUseRandomBattleImage.setSelected(false);
}
}
private void cbUseRandomBattleImageActionPerformed(java.awt.event.ActionEvent evt) {
if(cbUseRandomBattleImage.isSelected()){
if (cbUseRandomBattleImage.isSelected()) {
useRandomBattleField();
}else{
} else {
useSelectedBattleField();
}
}
}
private void useRandomBattleField(){
private void useRandomBattleField() {
txtBattlefieldImagePath.setEnabled(false);
btnBrowseBattlefieldImage.setEnabled(false);
}
private void useSelectedBattleField(){
private void useSelectedBattleField() {
txtBattlefieldImagePath.setEnabled(true);
btnBrowseBattlefieldImage.setEnabled(true);
}
private void btnBrowseBackgroundImageActionPerformed(java.awt.event.ActionEvent evt) {
int returnVal = fc_i.showOpenDialog(PreferencesDialog.this);
int returnVal = fc_i.showOpenDialog(PreferencesDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc_i.getSelectedFile();
txtBackgroundImagePath.setText(file.getAbsolutePath());
}
}
}
private void btnBrowseBattlefieldImageActionPerformed(java.awt.event.ActionEvent evt) {
int returnVal = fc_i.showOpenDialog(PreferencesDialog.this);
int returnVal = fc_i.showOpenDialog(PreferencesDialog.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc_i.getSelectedFile();
txtBattlefieldImagePath.setText(file.getAbsolutePath());
}
}
}
private void txtBackgroundImagePathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtBackgroundImagePathActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_txtBackgroundImagePathActionPerformed
@ -1995,12 +2002,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
if (cbProxyType.getSelectedItem() == Connection.ProxyType.SOCKS) {
this.pnlProxy.setVisible(true);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
} else if (cbProxyType.getSelectedItem() == Connection.ProxyType.HTTP) {
this.pnlProxy.setVisible(true);
this.pnlProxySettings.setVisible(true);
}
else if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
} else if (cbProxyType.getSelectedItem() == Connection.ProxyType.NONE) {
this.pnlProxy.setVisible(false);
this.pnlProxySettings.setVisible(false);
}
@ -2059,7 +2064,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
private static void loadPhases(Preferences prefs) {
load(prefs, dialog.displayBigCardsInHand, KEY_HAND_USE_BIG_CARDS, "true","true");
load(prefs, dialog.displayBigCardsInHand, KEY_HAND_USE_BIG_CARDS, "true", "true");
load(prefs, dialog.showToolTipsInAnyZone, KEY_SHOW_TOOLTIPS_ANY_ZONE, "true");
load(prefs, dialog.showCardName, KEY_SHOW_CARD_NAMES, "true");
load(prefs, dialog.nonLandPermanentsInOnePile, KEY_PERMANENTS_IN_ONE_PILE, "true");
@ -2072,21 +2077,21 @@ public class PreferencesDialog extends javax.swing.JDialog {
load(prefs, dialog.cbGameLogAutoSave, KEY_GAME_LOG_AUTO_SAVE, "true");
load(prefs, dialog.checkBoxUpkeepYou, UPKEEP_YOU, "on","on");
load(prefs, dialog.checkBoxDrawYou, DRAW_YOU, "on","on");
load(prefs, dialog.checkBoxMainYou, MAIN_YOU, "on","on");
load(prefs, dialog.checkBoxBeforeCYou, BEFORE_COMBAT_YOU, "on","on");
load(prefs, dialog.checkBoxEndOfCYou, END_OF_COMBAT_YOU, "on","on");
load(prefs, dialog.checkBoxMain2You, MAIN_2_YOU, "on","on");
load(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU, "on","on");
load(prefs, dialog.checkBoxUpkeepYou, UPKEEP_YOU, "on", "on");
load(prefs, dialog.checkBoxDrawYou, DRAW_YOU, "on", "on");
load(prefs, dialog.checkBoxMainYou, MAIN_YOU, "on", "on");
load(prefs, dialog.checkBoxBeforeCYou, BEFORE_COMBAT_YOU, "on", "on");
load(prefs, dialog.checkBoxEndOfCYou, END_OF_COMBAT_YOU, "on", "on");
load(prefs, dialog.checkBoxMain2You, MAIN_2_YOU, "on", "on");
load(prefs, dialog.checkBoxEndTurnYou, END_OF_TURN_YOU, "on", "on");
load(prefs, dialog.checkBoxUpkeepOthers, UPKEEP_OTHERS, "on","on");
load(prefs, dialog.checkBoxDrawOthers, DRAW_OTHERS, "on","on");
load(prefs, dialog.checkBoxMainOthers, MAIN_OTHERS, "on","on");
load(prefs, dialog.checkBoxBeforeCOthers, BEFORE_COMBAT_OTHERS, "on","on");
load(prefs, dialog.checkBoxEndOfCOthers, END_OF_COMBAT_OTHERS, "on","on");
load(prefs, dialog.checkBoxMain2Others, MAIN_2_OTHERS, "on","on");
load(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS, "on","on");
load(prefs, dialog.checkBoxUpkeepOthers, UPKEEP_OTHERS, "on", "on");
load(prefs, dialog.checkBoxDrawOthers, DRAW_OTHERS, "on", "on");
load(prefs, dialog.checkBoxMainOthers, MAIN_OTHERS, "on", "on");
load(prefs, dialog.checkBoxBeforeCOthers, BEFORE_COMBAT_OTHERS, "on", "on");
load(prefs, dialog.checkBoxEndOfCOthers, END_OF_COMBAT_OTHERS, "on", "on");
load(prefs, dialog.checkBoxMain2Others, MAIN_2_OTHERS, "on", "on");
load(prefs, dialog.checkBoxEndTurnOthers, END_OF_TURN_OTHERS, "on", "on");
load(prefs, dialog.cbStopAttack, KEY_STOP_ATTACK, "true", "true");
load(prefs, dialog.cbStopBlock, KEY_STOP_BLOCK, "true", "true");
@ -2110,13 +2115,13 @@ public class PreferencesDialog extends javax.swing.JDialog {
load(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true");
load(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true");
dialog.cbPreferedImageLanguage.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_PREF_LANGUAGE, "en"));
//add background load precedure
//add background load precedure
prop = prefs.get(KEY_BACKGROUND_IMAGE_DEFAULT, "true");
if(prop.equals("true")){
if (prop.equals("true")) {
dialog.cbUseDefaultBackground.setSelected(true);
dialog.useDefaultBackgroundImage();
}else{
} else {
dialog.cbUseDefaultBackground.setSelected(false);
dialog.useSelectBackgroundImage();
String path = prefs.get(KEY_BACKGROUND_IMAGE, "");
@ -2124,27 +2129,27 @@ public class PreferencesDialog extends javax.swing.JDialog {
updateCache(KEY_BACKGROUND_IMAGE, path);
}
prop = prefs.get(KEY_BATTLEFIELD_IMAGE_DEFAULT, "true");
if(prop.equals("true")){
if (prop.equals("true")) {
dialog.cbUseDefaultBattleImage.setSelected(true);
dialog.useDefaultBattlefield();
}else{
dialog.useDefaultBattlefield();
} else {
dialog.cbUseDefaultBattleImage.setSelected(false);
dialog.useSelectedOrRandom();
}
prop = prefs.get(KEY_BATTLEFIELD_IMAGE_RANDOM, "true");
if(dialog.cbUseRandomBattleImage.isEnabled()) {
if(prop.equals("true")){
if (dialog.cbUseRandomBattleImage.isEnabled()) {
if (prop.equals("true")) {
dialog.cbUseRandomBattleImage.setSelected(true);
dialog.useRandomBattleField();
}else{
} else {
dialog.cbUseRandomBattleImage.setSelected(false);
dialog.useSelectedBattleField();
String path = prefs.get(KEY_BATTLEFIELD_IMAGE, "");
dialog.txtBattlefieldImagePath.setText(path);
updateCache(KEY_BATTLEFIELD_IMAGE, path);
}
}
}
}
private static void loadSoundSettings(Preferences prefs) {
@ -2200,7 +2205,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
loadPhases(MageFrame.getPreferences());
}
UserSkipPrioritySteps userSkipPrioritySteps = new UserSkipPrioritySteps();
userSkipPrioritySteps.getYourTurn().setUpkeep(dialog.checkBoxUpkeepYou.isSelected());
userSkipPrioritySteps.getYourTurn().setDraw(dialog.checkBoxDrawYou.isSelected());
userSkipPrioritySteps.getYourTurn().setMain1(dialog.checkBoxMainYou.isSelected());
@ -2216,7 +2221,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
userSkipPrioritySteps.getOpponentTurn().setEndOfCombat(dialog.checkBoxEndOfCOthers.isSelected());
userSkipPrioritySteps.getOpponentTurn().setMain2(dialog.checkBoxMain2Others.isSelected());
userSkipPrioritySteps.getOpponentTurn().setEndOfTurn(dialog.checkBoxEndTurnOthers.isSelected());
userSkipPrioritySteps.setStopOnDeclareAttackersDuringSkipActions(dialog.cbStopAttack.isSelected());
userSkipPrioritySteps.setStopOnDeclareBlockerIfNoneAvailable(dialog.cbStopBlock.isSelected());
userSkipPrioritySteps.setStopOnAllEndPhases(dialog.cbStopOnAllEnd.isSelected());
@ -2235,7 +2240,6 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
}
private static void saveImagesPath(Preferences prefs) {
if (!dialog.cbUseDefaultImageFolder.isSelected()) {
String path = dialog.txtImageFolderPath.getText();
@ -2243,19 +2247,19 @@ public class PreferencesDialog extends javax.swing.JDialog {
updateCache(KEY_CARD_IMAGES_PATH, path);
}
// background path save precedure
if(!dialog.cbUseDefaultBackground.isSelected()){
if (!dialog.cbUseDefaultBackground.isSelected()) {
String path = dialog.txtBackgroundImagePath.getText();
prefs.put(KEY_BACKGROUND_IMAGE, path);
updateCache(KEY_BACKGROUND_IMAGE, path);
}
if(!dialog.cbUseDefaultBattleImage.isSelected() && !dialog.cbUseRandomBattleImage.isSelected()){
if (!dialog.cbUseDefaultBattleImage.isSelected() && !dialog.cbUseRandomBattleImage.isSelected()) {
String path = dialog.txtBattlefieldImagePath.getText();
prefs.put(KEY_BATTLEFIELD_IMAGE, path);
updateCache(KEY_BATTLEFIELD_IMAGE, path);
}
}
private static void saveSoundPath(Preferences prefs){
private static void saveSoundPath(Preferences prefs) {
String path = dialog.txtBattlefieldIBGMPath.getText();
prefs.put(KEY_SOUNDS_MATCH_MUSIC_PATH, path);
updateCache(KEY_SOUNDS_MATCH_MUSIC_PATH, path);
@ -2294,13 +2298,14 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
public static void setPrefValue(String key, boolean value) {
switch(key) {
switch (key) {
case KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS:
dialog.cbAllowRequestToShowHandCards.setSelected(value);
save(MageFrame.getPreferences(), dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true", "false", UPDATE_CACHE_POLICY);
break;
}
}
}
private static void save(Preferences prefs, JCheckBox checkBox, String propName, String yesValue, String noValue, boolean updateCache) {
prefs.put(propName, checkBox.isSelected() ? yesValue : noValue);
if (updateCache) {
@ -2356,7 +2361,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
try {
addAvatar(jPanel10, 51, true, false);
addAvatar(jPanel13, 13, false, false);
addAvatar(jPanel11, 9, false, false);
addAvatar(jPanel11, 9, false, false);
addAvatar(jPanel12, 53, false, false);
addAvatar(jPanel14, 10, false, false);
addAvatar(jPanel15, 39, false, false);
@ -2409,25 +2414,25 @@ public class PreferencesDialog extends javax.swing.JDialog {
public void mousePressed(MouseEvent e) {
if (selectedAvatarId != id) {
setSelectedId(id);
MageFrame.getSession().updatePreferencesForServer(getUserData());
MageFrame.getSession().updatePreferencesForServer(getUserData());
}
}
});
}
}
public static UserDataView getUserData(){
return new UserDataView(
getSelectedAvatar(),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_ANY_ZONE, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true").equals("true"),
getUserSkipPrioritySteps(),
MageFrame.getPreferences().get(KEY_CONNECT_FLAG, "world"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true").equals("true")
public static UserData getUserData() {
return new UserData(UserGroup.PLAYER,
getSelectedAvatar(),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_ANY_ZONE, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_CONFIRM_EMPTY_MANA_POOL, "true").equals("true"),
getUserSkipPrioritySteps(),
MageFrame.getPreferences().get(KEY_CONNECT_FLAG, "world"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ASK_MOVE_TO_GRAVE_ORDER, "true").equals("true")
);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnBattlefieldBGMBrowse;
private javax.swing.JButton btnBrowseBackgroundImage;

View file

@ -1,50 +1,54 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
/*
* TableWaitingDialog.java
*
* Created on Dec 16, 2009, 10:27:44 AM
*/
package mage.client.dialog;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.Icon;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
import mage.client.components.MageComponents;
import mage.client.components.tray.MageTray;
import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_ORDER;
import static mage.client.dialog.PreferencesDialog.KEY_TABLE_WAITING_COLUMNS_WIDTH;
import mage.client.util.audio.AudioManager;
import mage.client.util.gui.TableUtil;
import mage.client.util.gui.countryBox.CountryCellRenderer;
import mage.remote.Session;
import mage.view.SeatView;
import mage.view.TableView;
@ -64,8 +68,11 @@ public class TableWaitingDialog extends MageDialog {
private Session session;
private final TableWaitModel tableWaitModel;
private UpdateSeatsTask updateTask;
private static final int[] defaultColumnsWidth = {20, 50, 100, 100};
/** Creates new form TableWaitingDialog */
/**
* Creates new form TableWaitingDialog
*/
public TableWaitingDialog() {
session = MageFrame.getSession();
@ -73,8 +80,17 @@ public class TableWaitingDialog extends MageDialog {
initComponents();
int prefWidth = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLE_WAITING_WIDTH, "500"));
int prefHeight = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLE_WAITING_HEIGHT, "400"));
if (prefWidth > 40 && prefHeight > 40) {
this.setSize(prefWidth, prefHeight);
}
chatPanel.useExtendedView(ChatPanel.VIEW_MODE.NONE);
tableSeats.createDefaultColumnsFromModel();
TableUtil.setColumnWidthAndOrder(tableSeats, defaultColumnsWidth, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER);
tableSeats.setDefaultRenderer(Icon.class, new CountryCellRenderer());
MageFrame.getUI().addButton(MageComponents.TABLE_WAITING_START_BUTTON, btnStart);
}
@ -97,11 +113,14 @@ public class TableWaitingDialog extends MageDialog {
return;
}
int row = this.tableSeats.getSelectedRow();
if (getTitle().equals("Waiting for players")) {
this.title = getTitle() + " - " + table.getDeckType() + " / " + table.getGameType();
this.repaint();
}
tableWaitModel.loadData(table);
this.tableSeats.repaint();
this.tableSeats.getSelectionModel().setSelectionInterval(row, row);
}
else {
} else {
closeDialog();
}
} catch (Exception ex) {
@ -131,8 +150,7 @@ public class TableWaitingDialog extends MageDialog {
this.setModal(false);
this.setLocation(100, 100);
this.setVisible(true);
}
else {
} else {
closeDialog();
}
}
@ -144,14 +162,15 @@ public class TableWaitingDialog extends MageDialog {
this.chatPanel.disconnect();
MageFrame.getUI().removeButton(MageComponents.TABLE_WAITING_START_BUTTON);
this.removeDialog();
TableUtil.saveColumnWidthAndOrderToPrefs(tableSeats, KEY_TABLE_WAITING_COLUMNS_WIDTH, KEY_TABLE_WAITING_COLUMNS_ORDER);
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLE_WAITING_WIDTH, Integer.toString(getWidth()));
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLE_WAITING_HEIGHT, Integer.toString(getHeight()));
}
/** 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.
/**
* 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
@ -248,12 +267,11 @@ public class TableWaitingDialog extends MageDialog {
if (session.startMatch(roomId, tableId)) {
closeDialog();
}
}
else {
} else {
if (session.startTournament(roomId, tableId)) {
closeDialog();
}
}
}
}//GEN-LAST:event_btnStartActionPerformed
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
@ -285,7 +303,6 @@ public class TableWaitingDialog extends MageDialog {
}
}//GEN-LAST:event_btnMoveUpActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnMoveDown;
@ -300,7 +317,8 @@ public class TableWaitingDialog extends MageDialog {
}
class TableWaitModel extends AbstractTableModel {
private final String[] columnNames = new String[]{"Seat Num", "Player Name", "Player Type"};
private final String[] columnNames = new String[]{"Seat", "Loc", "Player Name", "Player Type"};
private SeatView[] seats = new SeatView[0];
public void loadData(TableView table) {
@ -324,14 +342,15 @@ class TableWaitModel extends AbstractTableModel {
if (arg1 == 0) {
return Integer.toString(arg0 + 1);
}
}
else {
} else {
switch (arg1) {
case 0:
return Integer.toString(arg0 + 1);
case 1:
return seats[arg0].getPlayerName();
return seats[arg0].getFlagName();
case 2:
return seats[arg0].getPlayerName();
case 3:
return seats[arg0].getPlayerType();
}
}
@ -350,8 +369,13 @@ class TableWaitModel extends AbstractTableModel {
}
@Override
public Class getColumnClass(int columnIndex){
return String.class;
public Class getColumnClass(int columnIndex) {
switch (columnIndex) {
case 1:
return Icon.class;
default:
return String.class;
}
}
@Override
@ -413,7 +437,7 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
private int getPlayersCount(TableView tableView) {
int playerCount = 0;
if (tableView != null) {
for (SeatView seatView: tableView.getSeats()) {
for (SeatView seatView : tableView.getSeats()) {
if (seatView.getPlayerId() != null && seatView.getPlayerType().equals("Human")) {
playerCount++;
}
@ -422,7 +446,6 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
return playerCount;
}
@Override
protected void done() {
try {
@ -431,7 +454,8 @@ class UpdateSeatsTask extends SwingWorker<Void, TableView> {
logger.fatal("Update Seats Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Seats Task error", ex);
} catch (CancellationException ex) {}
} catch (CancellationException ex) {
}
}
}
}

View file

@ -1,30 +1,30 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.game;
import java.awt.Color;
@ -37,7 +37,6 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.lang.reflect.Field;
import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
@ -72,21 +71,23 @@ public class PlayAreaPanel extends javax.swing.JPanel {
private boolean playingMode = true;
private final GamePanel gamePanel;
private final PlayAreaPanelOptions options;
private JCheckBoxMenuItem manaPoolMenuItem1;
private JCheckBoxMenuItem manaPoolMenuItem2;
private JCheckBoxMenuItem allowViewHandCardsMenuItem;
public static final int PANEL_HEIGHT = 242;
public static final int PANEL_HEIGHT_SMALL = 190;
/** Creates new form PlayAreaPanel
/**
* Creates new form PlayAreaPanel
*
* @param player
* @param bigCard
* @param gameId
* @param priorityTime
* @param gamePanel
* @param options
* @param options
*/
public PlayAreaPanel(PlayerView player, BigCard bigCard, UUID gameId, int priorityTime, GamePanel gamePanel, PlayAreaPanelOptions options) {
this.gamePanel = gamePanel;
@ -97,7 +98,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
popupMenu = new JPopupMenu();
if (options.isPlayer) {
addPopupMenuPlayer(player.getUserData().allowRequestShowHandCards());
addPopupMenuPlayer(player.getUserData().isAllowRequestShowHandCards());
} else {
addPopupMenuWatcher();
}
@ -109,15 +110,14 @@ public class PlayAreaPanel extends javax.swing.JPanel {
public void CleanUp() {
battlefieldPanel.cleanUp();
playerPanel.cleanUp();
for (ActionListener al : btnCheat.getActionListeners() ) {
for (ActionListener al : btnCheat.getActionListeners()) {
btnCheat.removeActionListener(al);
}
// Taken form : https://community.oracle.com/thread/2183145
// removed the internal focus of a popupMenu data to allow GC before another popup menu is selected
for(ChangeListener listener : MenuSelectionManager.defaultManager().getChangeListeners()) {
for (ChangeListener listener : MenuSelectionManager.defaultManager().getChangeListeners()) {
if (listener.getClass().getName().contains("MenuKeyboardHelper")) {
try {
Field field = listener.getClass().getDeclaredField("menuInputMap");
@ -130,7 +130,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
}
}
for (MouseListener ml :battlefieldPanel.getMainPanel().getMouseListeners()) {
for (MouseListener ml : battlefieldPanel.getMainPanel().getMouseListeners()) {
battlefieldPanel.getMainPanel().removeMouseListener(ml);
}
popupMenu.getUI().uninstallUI(this);
@ -170,11 +170,11 @@ public class PlayAreaPanel extends javax.swing.JPanel {
case "F9": {
gamePanel.getSession().sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId, null);
break;
}
}
}
}
};
menuItem = new JMenuItem("<html><b>F2</b> - Confirm current request");
menuItem.setActionCommand("F2");
menuItem.setMnemonic(KeyEvent.VK_O);
@ -187,11 +187,10 @@ public class PlayAreaPanel extends javax.swing.JPanel {
popupMenu.add(menuItem);
menuItem.addActionListener(skipListener);
JMenu skipMenu = new JMenu("Skip");
skipMenu.setMnemonic(KeyEvent.VK_S);
popupMenu.add(skipMenu);
String tooltipText = "<html>This skip actions stops if something goes to <br><b>stack</b> and if <b>attackers</b> or <b>blocker</b> have to be <b>declared</b>.";
menuItem = new JMenuItem("<html><b>F4</b> - Phases until next turn");
menuItem.setActionCommand("F4");
@ -213,7 +212,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
menuItem.setMnemonic(KeyEvent.VK_M);
skipMenu.add(menuItem);
menuItem.addActionListener(skipListener);
menuItem = new JMenuItem("<html><b>F9</b> - Everything until your own next turn");
menuItem.setActionCommand("F9");
menuItem.setToolTipText(tooltipText);
@ -222,50 +221,50 @@ public class PlayAreaPanel extends javax.swing.JPanel {
menuItem.addActionListener(skipListener);
popupMenu.addSeparator();
JMenu manaPoolMenu = new JMenu("Mana payment");
manaPoolMenu.setMnemonic(KeyEvent.VK_M);
manaPoolMenu.setMnemonic(KeyEvent.VK_M);
popupMenu.add(manaPoolMenu);
manaPoolMenuItem1 = new JCheckBoxMenuItem("Automatically", true);
manaPoolMenuItem1.setMnemonic(KeyEvent.VK_A);
manaPoolMenuItem1.setToolTipText("<html>If not active, produced mana goes only to the mana pool<br>"
+ "and you have to click the type of mana you want to use <br>"
+ "in the player mana pool panel for payment.");
+ "and you have to click the type of mana you want to use <br>"
+ "in the player mana pool panel for payment.");
manaPoolMenu.add(manaPoolMenuItem1);
// Auto pay mana from mana pool
manaPoolMenuItem1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean manaPoolAutomatic = ((JCheckBoxMenuItem)e.getSource()).getState();
PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT, manaPoolAutomatic ? "true": "false");
boolean manaPoolAutomatic = ((JCheckBoxMenuItem) e.getSource()).getState();
PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT, manaPoolAutomatic ? "true" : "false");
gamePanel.setMenuStates(manaPoolAutomatic, manaPoolMenuItem2.getState());
gamePanel.getSession().sendPlayerAction(manaPoolAutomatic ? PlayerAction.MANA_AUTO_PAYMENT_ON: PlayerAction.MANA_AUTO_PAYMENT_OFF, gameId, null);
gamePanel.getSession().sendPlayerAction(manaPoolAutomatic ? PlayerAction.MANA_AUTO_PAYMENT_ON : PlayerAction.MANA_AUTO_PAYMENT_OFF, gameId, null);
}
});
manaPoolMenuItem2 = new JCheckBoxMenuItem("No automatic usage for mana already in the pool", true);
manaPoolMenuItem2.setMnemonic(KeyEvent.VK_N);
manaPoolMenuItem2.setToolTipText("<html>Mana that is already in the mana pool as you start casting a spell or activating an ability<br>"
+ " needs to be payed manually. So you use the mana in the pool only by clicking on the related<br>"
+ " mana symbols of mana pool area.");
+ " needs to be payed manually. So you use the mana in the pool only by clicking on the related<br>"
+ " mana symbols of mana pool area.");
manaPoolMenu.add(manaPoolMenuItem2);
// Auto pay mana from mana pool
manaPoolMenuItem2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean manaPoolAutomaticRestricted = ((JCheckBoxMenuItem)e.getSource()).getState();
PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, manaPoolAutomaticRestricted ? "true": "false");
boolean manaPoolAutomaticRestricted = ((JCheckBoxMenuItem) e.getSource()).getState();
PreferencesDialog.saveValue(KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE, manaPoolAutomaticRestricted ? "true" : "false");
gamePanel.setMenuStates(manaPoolMenuItem1.getState(), manaPoolAutomaticRestricted);
gamePanel.getSession().sendPlayerAction(manaPoolAutomaticRestricted ? PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_ON: PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_OFF, gameId, null);
gamePanel.getSession().sendPlayerAction(manaPoolAutomaticRestricted ? PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_ON : PlayerAction.MANA_AUTO_PAYMENT_RESTRICTED_OFF, gameId, null);
}
});
JMenu automaticConfirmsMenu = new JMenu("Automatic confirms");
automaticConfirmsMenu.setMnemonic(KeyEvent.VK_U);
popupMenu.add(automaticConfirmsMenu);
menuItem = new JMenuItem("Replacement effects - reset auto select");
menuItem.setMnemonic(KeyEvent.VK_R);
menuItem.setToolTipText("Reset all effects that were added to the list of auto select replacement effects this game.");
@ -281,7 +280,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
JMenu handCardsMenu = new JMenu("Cards on hand");
handCardsMenu.setMnemonic(KeyEvent.VK_H);
popupMenu.add(handCardsMenu);
if (!options.playerItself) {
menuItem = new JMenuItem("Request permission to see the hand cards");
menuItem.setMnemonic(KeyEvent.VK_P);
@ -304,9 +303,9 @@ public class PlayAreaPanel extends javax.swing.JPanel {
allowViewHandCardsMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean requestsAllowed = ((JCheckBoxMenuItem)e.getSource()).getState();
boolean requestsAllowed = ((JCheckBoxMenuItem) e.getSource()).getState();
PreferencesDialog.setPrefValue(KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, requestsAllowed);
gamePanel.getSession().sendPlayerAction(requestsAllowed ? PlayerAction.PERMISSION_REQUESTS_ALLOWED_ON: PlayerAction.PERMISSION_REQUESTS_ALLOWED_OFF, gameId, null);
gamePanel.getSession().sendPlayerAction(requestsAllowed ? PlayerAction.PERMISSION_REQUESTS_ALLOWED_ON : PlayerAction.PERMISSION_REQUESTS_ALLOWED_OFF, gameId, null);
}
});
@ -323,7 +322,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
}
});
}
if (options.rollbackTurnsAllowed) {
ActionListener rollBackActionListener = new ActionListener() {
@Override
@ -332,44 +331,42 @@ public class PlayAreaPanel extends javax.swing.JPanel {
gamePanel.getSession().sendPlayerAction(PlayerAction.ROLLBACK_TURNS, gameId, turnsToRollBack);
}
};
JMenu rollbackMainItem = new JMenu("Roll back");
rollbackMainItem.setMnemonic(KeyEvent.VK_R);
rollbackMainItem.setToolTipText("The game will be rolled back to the start of the requested turn if all players agree.");
popupMenu.add(rollbackMainItem);
menuItem = new JMenuItem("To the start of the current turn");
menuItem.setMnemonic(KeyEvent.VK_C);
menuItem.setActionCommand("0");
menuItem.addActionListener(rollBackActionListener);
menuItem.addActionListener(rollBackActionListener);
rollbackMainItem.add(menuItem);
menuItem = new JMenuItem("To the start of the previous turn");
menuItem.setMnemonic(KeyEvent.VK_P);
menuItem.setActionCommand("1");
menuItem.addActionListener(rollBackActionListener);
menuItem.addActionListener(rollBackActionListener);
rollbackMainItem.add(menuItem);
menuItem = new JMenuItem("The current turn and the 2 turns before");
menuItem.setMnemonic(KeyEvent.VK_2);
menuItem.setActionCommand("2");
menuItem.addActionListener(rollBackActionListener);
menuItem.addActionListener(rollBackActionListener);
rollbackMainItem.add(menuItem);
menuItem = new JMenuItem("The current turn and the 3 turns before");
menuItem.setMnemonic(KeyEvent.VK_3);
menuItem.setActionCommand("3");
menuItem.addActionListener(rollBackActionListener);
menuItem.addActionListener(rollBackActionListener);
rollbackMainItem.add(menuItem);
}
}
JMenu concedeMenu = new JMenu("Concede");
concedeMenu.setMnemonic(KeyEvent.VK_C);
popupMenu.add(concedeMenu);
ActionListener concedeListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@ -377,19 +374,19 @@ public class PlayAreaPanel extends javax.swing.JPanel {
case "Game": {
if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to concede the game?", "Confirm concede game", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
MageFrame.getSession().sendPlayerAction(PlayerAction.CONCEDE, gameId, null);
}
}
break;
}
case "Match": {
if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to concede the complete match?", "Confirm concede match", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
MageFrame.getSession().quitMatch(gameId);
}
}
break;
}
}
}
};
// Concede Game
menuItem = new JMenuItem("Game");
menuItem.setMnemonic(KeyEvent.VK_G);
@ -397,7 +394,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
menuItem.setToolTipText("Concedes only the current game and after that the next game of the match is started if there is another game needed.");
concedeMenu.add(menuItem);
menuItem.addActionListener(concedeListener);
// Concede Match
menuItem = new JMenuItem("Match");
menuItem.setMnemonic(KeyEvent.VK_M);
@ -406,20 +403,19 @@ public class PlayAreaPanel extends javax.swing.JPanel {
concedeMenu.add(menuItem);
menuItem.addActionListener(concedeListener);
battlefieldPanel.getMainPanel().addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent Me) {
this.checkMenu(Me);
}
// neccessary for linux and mac systems
@Override
public void mousePressed(MouseEvent Me) {
this.checkMenu(Me);
}
private void checkMenu(MouseEvent Me){
private void checkMenu(MouseEvent Me) {
if (Me.isPopupTrigger() && playingMode) {
popupMenu.show(Me.getComponent(), Me.getX(), Me.getY());
}
@ -461,13 +457,14 @@ public class PlayAreaPanel extends javax.swing.JPanel {
public void mouseReleased(MouseEvent Me) {
this.checkMenu(Me);
}
// neccessary for linux and mac systems
@Override
public void mousePressed(MouseEvent Me) {
this.checkMenu(Me);
}
private void checkMenu(MouseEvent Me){
private void checkMenu(MouseEvent Me) {
if (Me.isPopupTrigger() && playingMode) {
popupMenu.show(Me.getComponent(), Me.getX(), Me.getY());
}
@ -483,8 +480,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
if (MageFrame.getSession().isTestMode()) {
this.playerId = player.getPlayerId();
this.btnCheat.setVisible(true);
}
else {
} else {
this.btnCheat.setVisible(false);
}
}
@ -493,7 +489,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
this.playerPanel.update(player);
this.battlefieldPanel.update(player.getBattlefield());
if (this.allowViewHandCardsMenuItem != null) {
this.allowViewHandCardsMenuItem.setSelected(player.getUserData().allowRequestShowHandCards());
this.allowViewHandCardsMenuItem.setSelected(player.getUserData().isAllowRequestShowHandCards());
}
}
@ -506,7 +502,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
}
private void initComponents() {
setBorder(BorderFactory.createLineBorder(new Color(0,0,0,0)));
setBorder(BorderFactory.createLineBorder(new Color(0, 0, 0, 0)));
playerPanel = new PlayerPanelExt();
btnCheat = new javax.swing.JButton();
//jScrollPane1 = new javax.swing.JScrollPane();
@ -525,16 +521,15 @@ public class PlayAreaPanel extends javax.swing.JPanel {
//Border empty = new EmptyBorder(0,0,0,0);
//jScrollPane1.setBorder(empty);
//jScrollPane1.setViewportBorder(empty);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
layout.setHorizontalGroup(
layout.createSequentialGroup()
layout.createSequentialGroup()
.addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(battlefieldPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING)
layout.createParallelGroup(Alignment.LEADING)
.addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(battlefieldPanel, GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
);
@ -548,8 +543,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
this.playerPanel.setPreferredSize(new Dimension(92, PANEL_HEIGHT_SMALL));
//this.jScrollPane1.setPreferredSize(new Dimension(160, 160));
this.battlefieldPanel.setPreferredSize(new Dimension(160, PANEL_HEIGHT_SMALL));
}
else {
} else {
this.playerPanel.setPreferredSize(new Dimension(92, PANEL_HEIGHT));
//this.jScrollPane1.setPreferredSize(new Dimension(160, 212));
this.battlefieldPanel.setPreferredSize(new Dimension(160, PANEL_HEIGHT));
@ -576,7 +570,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
manaPoolMenuItem2.setSelected(manaPoolAutomaticRestricted);
}
}
private mage.client.game.BattlefieldPanel battlefieldPanel;
private javax.swing.JButton btnCheat;
//private javax.swing.JScrollPane jScrollPane1;

View file

@ -36,6 +36,7 @@ package mage.client.game;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
@ -67,6 +68,7 @@ import mage.client.util.CardsViewUtil;
import mage.client.util.Command;
import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder;
import mage.client.util.gui.countryBox.CountryUtil;
import mage.components.ImagePanel;
import mage.constants.ManaType;
import mage.remote.Session;
@ -103,6 +105,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
private static final Border emptyBorder = BorderFactory.createEmptyBorder(0, 0, 0, 0);
private int avatarId = -1;
private String flagName = "";
private PriorityTimer timer;
@ -234,6 +237,11 @@ public class PlayerPanelExt extends javax.swing.JPanel {
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
this.avatar.update("player", resized, resized, resized, resized, r);
}
if (!player.getUserData().getFlagName().equals(flagName)) {
flagName = player.getUserData().getFlagName();
this.avatarFlag.setIcon(CountryUtil.getCountryFlagIcon(flagName));
avatar.repaint();
}
}
this.avatar.setText(player.getName());
if (this.timer != null) {
@ -298,6 +306,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
panelBackground = new MageRoundPane();
panelBackground.setPreferredSize(new Dimension(PANEL_WIDTH - 2, PANEL_HEIGHT));
Rectangle r = new Rectangle(80, 80);
avatarFlag = new JLabel();
timerLabel = new JLabel();
lifeLabel = new JLabel();
handLabel = new JLabel();
@ -315,6 +324,14 @@ public class PlayerPanelExt extends javax.swing.JPanel {
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
avatar = new HoverButton("player", resized, resized, resized, r);
avatar.setLayout(new GridLayout(4, 1, 0, 0));
avatar.add(new JLabel());
avatar.add(new JLabel());
avatar.add(avatarFlag);
avatar.setAlignmentY(CENTER_ALIGNMENT);
avatarFlag.setHorizontalAlignment(JLabel.CENTER);
avatarFlag.setVerticalAlignment(JLabel.BOTTOM);
avatar.add(new JLabel());
String showPlayerNamePermanently = MageFrame.getPreferences().get(PreferencesDialog.KEY_SHOW_PLAYER_NAMES_PERMANENTLY, "true");
if (showPlayerNamePermanently.equals("true")) {
avatar.setTextAlwaysVisible(true);
@ -326,6 +343,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
session.sendPlayerUUID(gameId, playerId);
}
});
// timer area /small layout)
timerLabel.setToolTipText("Time left");
timerLabel.setSize(80, 12);
@ -637,6 +655,8 @@ public class PlayerPanelExt extends javax.swing.JPanel {
.addComponent(btnPlayer, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(timerLabel, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(avatar, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))
// .addGroup(gl_panelBackground.createSequentialGroup()
// .addComponent(avatarFlag, GroupLayout.PREFERRED_SIZE, 16, GroupLayout.PREFERRED_SIZE))
.addGap(14))
.addGroup(gl_panelBackground.createSequentialGroup()
.addGap(6)
@ -748,12 +768,14 @@ public class PlayerPanelExt extends javax.swing.JPanel {
protected void sizePlayerPanel(boolean smallMode) {
if (smallMode) {
avatar.setVisible(false);
avatarFlag.setVisible(false);
btnPlayer.setVisible(true);
timerLabel.setVisible(true);
panelBackground.setPreferredSize(new Dimension(PANEL_WIDTH - 2, PANEL_HEIGHT_SMALL));
panelBackground.setBounds(0, 0, PANEL_WIDTH - 2, PANEL_HEIGHT_SMALL);
} else {
avatar.setVisible(true);
avatarFlag.setVisible(true);
btnPlayer.setVisible(false);
timerLabel.setVisible(false);
panelBackground.setPreferredSize(new Dimension(PANEL_WIDTH - 2, PANEL_HEIGHT));
@ -791,6 +813,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
}
private HoverButton avatar;
private JLabel avatarFlag;
private JButton btnPlayer;
private ImagePanel life;
private ImagePanel poison;

View file

@ -31,7 +31,6 @@
*
* Created on 20-Jan-2011, 9:18:30 PM
*/
package mage.client.tournament;
import java.awt.Component;
@ -45,14 +44,21 @@ import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
import mage.client.dialog.PreferencesDialog;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_MATCH_COLUMNS_ORDER;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER;
import static mage.client.dialog.PreferencesDialog.KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH;
import mage.client.util.ButtonColumn;
import mage.client.util.Format;
import mage.client.util.gui.TableUtil;
import mage.client.util.gui.countryBox.CountryCellRenderer;
import mage.remote.Session;
import mage.view.RoundView;
import mage.view.TournamentGameView;
@ -76,7 +82,12 @@ public class TournamentPanel extends javax.swing.JPanel {
private UpdateTournamentTask updateTask;
private final DateFormat df;
/** Creates new form TournamentPanel */
private static final int[] defaultColumnsWidthPlayers = {30, 150, 150, 60, 400};
private static final int[] defaultColumnsWidthMatches = {60, 140, 140, 400, 80};
/**
* Creates new form TournamentPanel
*/
public TournamentPanel() {
playersModel = new TournamentPlayersTableModel();
matchesModel = new TournamentMatchesTableModel();
@ -84,28 +95,29 @@ public class TournamentPanel extends javax.swing.JPanel {
initComponents();
this.restoreDividerLocations();
btnQuitTournament.setVisible(false);
df = DateFormat.getDateTimeInstance();
tablePlayers.createDefaultColumnsFromModel();
TableUtil.setColumnWidthAndOrder(tablePlayers, defaultColumnsWidthPlayers, KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH, KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER);
tablePlayers.setDefaultRenderer(Icon.class, new CountryCellRenderer());
tableMatches.createDefaultColumnsFromModel();
TableUtil.setColumnWidthAndOrder(tableMatches, defaultColumnsWidthMatches, KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH, KEY_TOURNAMENT_MATCH_COLUMNS_ORDER);
chatPanel1.useExtendedView(ChatPanel.VIEW_MODE.NONE);
chatPanel1.setChatType(ChatPanel.ChatType.TOURNAMENT);
Action action = new AbstractAction()
{
Action action = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e)
{
int modelRow = Integer.valueOf( e.getActionCommand() );
String state = (String)tableMatches.getValueAt(modelRow, 2);
String actionText = (String)tableMatches.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN);
UUID tableId = UUID.fromString((String)matchesModel.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN +1));
UUID gameId = UUID.fromString((String)matchesModel.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN +3));
public void actionPerformed(ActionEvent e) {
int modelRow = Integer.valueOf(e.getActionCommand());
String state = (String) tableMatches.getValueAt(modelRow, 2);
String actionText = (String) tableMatches.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN);
UUID tableId = UUID.fromString((String) matchesModel.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN + 1));
UUID gameId = UUID.fromString((String) matchesModel.getValueAt(modelRow, TournamentMatchesTableModel.ACTION_COLUMN + 3));
// if (state.equals("Finished") && action.equals("Replay")) {
// logger.info("Replaying game " + gameId);
// session.replayGame(gameId);
@ -127,6 +139,7 @@ public class TournamentPanel extends javax.swing.JPanel {
if (this.chatPanel1 != null) {
this.chatPanel1.disconnect();
}
}
private void saveDividerLocations() {
@ -167,8 +180,7 @@ public class TournamentPanel extends javax.swing.JPanel {
startTasks();
this.setVisible(true);
this.repaint();
}
else {
} else {
hideTournament();
}
@ -182,12 +194,15 @@ public class TournamentPanel extends javax.swing.JPanel {
stopTasks();
this.chatPanel1.disconnect();
this.saveDividerLocations();
TableUtil.saveColumnWidthAndOrderToPrefs(tablePlayers, KEY_TOURNAMENT_PLAYER_COLUMNS_WIDTH, KEY_TOURNAMENT_PLAYER_COLUMNS_ORDER);
TableUtil.saveColumnWidthAndOrderToPrefs(tableMatches, KEY_TOURNAMENT_MATCH_COLUMNS_WIDTH, KEY_TOURNAMENT_MATCH_COLUMNS_ORDER);
Component c = this.getParent();
while (c != null && !(c instanceof TournamentPane)) {
c = c.getParent();
}
if (c != null) {
((TournamentPane)c).removeTournament();
((TournamentPane) c).removeTournament();
}
}
@ -201,21 +216,21 @@ public class TournamentPanel extends javax.swing.JPanel {
c = c.getParent();
}
if (c != null) {
((TournamentPane)c).setTitle("Tournament [" + tournament.getTournamentName() +"]");
((TournamentPane) c).setTitle("Tournament [" + tournament.getTournamentName() + "]");
}
txtName.setText(tournament.getTournamentName());
txtType.setText(tournament.getTournamentType());
txtStartTime.setText(df.format(tournament.getStartTime()));
txtEndTime.setText("running...");
firstInitDone = true;
}
switch (tournament.getTournamentState()) {
case "Constructing":
String timeLeft = "";
if (tournament.getStepStartTime() != null) {
timeLeft = Format.getDuration(tournament.getConstructionTime() - (tournament.getServerTime().getTime() - tournament.getStepStartTime().getTime())/1000);
timeLeft = Format.getDuration(tournament.getConstructionTime() - (tournament.getServerTime().getTime() - tournament.getStepStartTime().getTime()) / 1000);
}
txtTournamentState.setText(new StringBuilder(tournament.getTournamentState()).append(" (").append(timeLeft).append(")").toString());
break;
@ -223,7 +238,7 @@ public class TournamentPanel extends javax.swing.JPanel {
case "Drafting":
String usedTime = "";
if (tournament.getStepStartTime() != null) {
usedTime = Format.getDuration((tournament.getServerTime().getTime() - tournament.getStepStartTime().getTime())/1000);
usedTime = Format.getDuration((tournament.getServerTime().getTime() - tournament.getStepStartTime().getTime()) / 1000);
}
txtTournamentState.setText(tournament.getTournamentState() + " (" + usedTime + ") " + tournament.getRunningInfo());
break;
@ -238,7 +253,7 @@ public class TournamentPanel extends javax.swing.JPanel {
if (txtEndTime.getText().equals("running...") && tournament.getEndTime() != null) {
txtEndTime.setText(df.format(tournament.getEndTime()));
}
playersModel.loadData(tournament);
matchesModel.loadData(tournament);
this.tablePlayers.repaint();
@ -274,10 +289,10 @@ public class TournamentPanel extends javax.swing.JPanel {
}
}
/** 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.
/**
* 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
@ -505,7 +520,6 @@ public class TournamentPanel extends javax.swing.JPanel {
// TODO add your handling code here:
}//GEN-LAST:event_txtNameActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel actionPanel;
private javax.swing.JButton btnCloseWindow;
@ -532,7 +546,8 @@ public class TournamentPanel extends javax.swing.JPanel {
}
class TournamentPlayersTableModel extends AbstractTableModel {
private final String[] columnNames = new String[]{"Player Name", "State", "Points", "Results"};
private final String[] columnNames = new String[]{"Loc", "Player Name", "State", "Points", "Results"};
private TournamentPlayerView[] players = new TournamentPlayerView[0];
public void loadData(TournamentView tournament) {
@ -554,12 +569,14 @@ class TournamentPlayersTableModel extends AbstractTableModel {
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return players[arg0].getName();
return players[arg0].getFlagName();
case 1:
return players[arg0].getState();
return players[arg0].getName();
case 2:
return Integer.toString(players[arg0].getPoints());
return players[arg0].getState();
case 3:
return Integer.toString(players[arg0].getPoints());
case 4:
return players[arg0].getResults();
}
return "";
@ -577,8 +594,13 @@ class TournamentPlayersTableModel extends AbstractTableModel {
}
@Override
public Class getColumnClass(int columnIndex){
return String.class;
public Class getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0:
return Icon.class;
default:
return String.class;
}
}
@Override
@ -599,8 +621,8 @@ class TournamentMatchesTableModel extends AbstractTableModel {
public void loadData(TournamentView tournament) {
List<TournamentGameView> views = new ArrayList<>();
watchingAllowed = tournament.isWatchingAllowed();
for (RoundView round: tournament.getRounds()) {
for (TournamentGameView game: round.getGames()) {
for (RoundView round : tournament.getRounds()) {
for (TournamentGameView game : round.getGames()) {
views.add(game);
}
}
@ -660,7 +682,7 @@ class TournamentMatchesTableModel extends AbstractTableModel {
}
@Override
public Class getColumnClass(int columnIndex){
public Class getColumnClass(int columnIndex) {
return String.class;
}
@ -688,7 +710,7 @@ class UpdateTournamentTask extends SwingWorker<Void, TournamentView> {
@Override
protected Void doInBackground() throws Exception {
while (!isCancelled()) {
this.publish(session.getTournament(tournamentId));
this.publish(session.getTournament(tournamentId));
Thread.sleep(2000);
}
return null;
@ -709,7 +731,8 @@ class UpdateTournamentTask extends SwingWorker<Void, TournamentView> {
logger.fatal("Update Tournament Task error", ex);
} catch (ExecutionException ex) {
logger.fatal("Update Tournament Task error", ex);
} catch (CancellationException ex) {}
} catch (CancellationException ex) {
}
}
}

View file

@ -8,7 +8,6 @@ package mage.client.util.gui;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
import mage.client.dialog.PreferencesDialog;
import org.mage.card.arcane.Util;
/**
*
@ -17,25 +16,29 @@ import org.mage.card.arcane.Util;
public class TableUtil {
/**
*
*
* @param table
* @param defaultColumnsWidth
* @param widthPrefKey
* @param orderPrefKey
* @param defaultColumnsWidth
* @param widthPrefKey
* @param orderPrefKey
*/
static public void setColumnWidthAndOrder(JTable table, int[] defaultColumnsWidth, String widthPrefKey, String orderPrefKey) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// set the column width from saved value or defaults
// set the column width from saved value or defaults
int[] widths = getIntArrayFromString(PreferencesDialog.getCachedValue(widthPrefKey, null));
int i = 0;
for (int width : defaultColumnsWidth) {
if (widths != null && widths.length > i) {
width = widths[i];
}
TableColumn column = table.getColumnModel().getColumn(i++);
column.setWidth(width);
column.setPreferredWidth(width);
if (table.getColumnModel().getColumnCount() >= i) {
TableColumn column = table.getColumnModel().getColumn(i++);
column.setWidth(width);
column.setPreferredWidth(width);
} else {
break;
}
}
// set the column order
@ -47,7 +50,7 @@ public class TableUtil {
}
}
static public void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) {
// Column width
StringBuilder columnWidthSettings = new StringBuilder();
@ -68,8 +71,7 @@ public class TableUtil {
PreferencesDialog.saveValue(orderPrefKey, columnOrderSettings.toString());
}
public static int[] getIntArrayFromString(String stringData) {
int[] intArray = null;
if (stringData != null && !stringData.isEmpty()) {
@ -79,9 +81,10 @@ public class TableUtil {
for (int i = 0; i < lengthW; i++) {
try {
intArray[i] = Integer.parseInt(items[i]);
} catch (NumberFormatException nfe) {}
} catch (NumberFormatException nfe) {
}
}
}
}
return intArray;
}
}
}

View file

@ -25,56 +25,28 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.util.gui.countryBox;
import java.awt.Component;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import org.apache.log4j.Logger;
/**
*
* @author LevelX2
*/
public class CountryCellRenderer extends DefaultTableCellRenderer {
private static final Logger logger = Logger.getLogger(CountryCellRenderer.class);
private final Map<String, ImageIcon> flagIconCache = new HashMap<>();
private final Map<String, String> countryMap = new HashMap<>();
public CountryCellRenderer() {
for( int i = 0; i <= CountryComboBox.countryList.length - 1; i++) {
countryMap.put(CountryComboBox.countryList[i][1],CountryComboBox.countryList[i][0]);
}
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if(table.convertColumnIndexToView(0) == column) {
label.setToolTipText(countryMap.get((String)value));
label.setIcon(getCountryFlagIcon((String)value));
label.setText("");
}
return label;
}
private ImageIcon getCountryFlagIcon(String countryCode) {
ImageIcon flagIcon = flagIconCache.get(countryCode);
if (flagIcon == null) {
flagIcon = new javax.swing.ImageIcon(getClass().getResource("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" :".png")));
if (flagIcon.getImage() == null) {
logger.warn("Country flag resource not found: " + countryCode);
} else {
flagIconCache.put(countryCode, flagIcon);
}
JLabel label = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value == null || ((String) value).isEmpty()) {
value = (String) "world";
}
return flagIcon;
}
label.setToolTipText(CountryUtil.getCountryName((String) value));
label.setIcon(CountryUtil.getCountryFlagIcon((String) value));
label.setText("");
return label;
}
}

View file

@ -0,0 +1,49 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.client.util.gui.countryBox;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import org.apache.log4j.Logger;
/**
*
* @author LevelX2
*/
public class CountryUtil {
private static final Logger logger = Logger.getLogger(CountryUtil.class);
private static final Map<String, ImageIcon> flagIconCache = new HashMap<>();
private static final Map<String, String> countryMap = new HashMap<>();
public static ImageIcon getCountryFlagIcon(String countryCode) {
ImageIcon flagIcon = flagIconCache.get(countryCode);
if (flagIcon == null) {
URL url = CountryUtil.class.getResource("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png"));
if (url != null) {
flagIcon = new javax.swing.ImageIcon(url);
}
if (flagIcon == null || flagIcon.getImage() == null) {
logger.warn("Country flag resource not found: " + countryCode);
flagIconCache.put(countryCode, flagIcon);
} else {
flagIconCache.put(countryCode, flagIcon);
}
}
return flagIcon;
}
public static String getCountryName(String countryCode) {
if (countryMap.isEmpty()) {
for (int i = 0; i <= CountryComboBox.countryList.length - 1; i++) {
countryMap.put(CountryComboBox.countryList[i][1], CountryComboBox.countryList[i][0]);
}
}
return countryMap.get(countryCode);
}
}