mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Show country flag icon in user table. Save and restore column width and order.
This commit is contained in:
parent
8ae9293c98
commit
132ded19f6
8 changed files with 418 additions and 320 deletions
|
@ -37,20 +37,31 @@ import java.awt.Color;
|
||||||
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import javax.swing.Icon;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.JTableHeader;
|
import javax.swing.table.JTableHeader;
|
||||||
import javax.swing.table.TableColumnModel;
|
import javax.swing.table.TableColumnModel;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
|
import mage.client.dialog.PreferencesDialog;
|
||||||
|
import static mage.client.dialog.PreferencesDialog.KEY_TABLES_COLUMNS_ORDER;
|
||||||
|
import static mage.client.dialog.PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH;
|
||||||
|
import static mage.client.dialog.PreferencesDialog.KEY_USERS_COLUMNS_ORDER;
|
||||||
|
import static mage.client.dialog.PreferencesDialog.KEY_USERS_COLUMNS_WIDTH;
|
||||||
import mage.client.util.MageTableRowSorter;
|
import mage.client.util.MageTableRowSorter;
|
||||||
|
import mage.client.util.gui.TableUtil;
|
||||||
import mage.remote.MageRemoteException;
|
import mage.remote.MageRemoteException;
|
||||||
import mage.remote.Session;
|
import mage.remote.Session;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
import mage.view.ChatMessage.MessageColor;
|
||||||
import mage.view.ChatMessage.MessageType;
|
import mage.view.ChatMessage.MessageType;
|
||||||
import mage.view.RoomUsersView;
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.UsersView;
|
import mage.view.UsersView;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
import org.mage.card.arcane.ManaSymbols;
|
import org.mage.card.arcane.ManaSymbols;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +69,9 @@ import org.mage.card.arcane.ManaSymbols;
|
||||||
* @author BetaSteward_at_googlemail.com, nantuko
|
* @author BetaSteward_at_googlemail.com, nantuko
|
||||||
*/
|
*/
|
||||||
public class ChatPanel extends javax.swing.JPanel {
|
public class ChatPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(ChatPanel.class);
|
||||||
|
|
||||||
private UUID chatId;
|
private UUID chatId;
|
||||||
private Session session;
|
private Session session;
|
||||||
private final List<String> players = new ArrayList<>();
|
private final List<String> players = new ArrayList<>();
|
||||||
|
@ -117,6 +130,8 @@ public class ChatPanel extends javax.swing.JPanel {
|
||||||
*/
|
*/
|
||||||
private ChatType chatType = ChatType.DEFAULT;
|
private ChatType chatType = ChatType.DEFAULT;
|
||||||
|
|
||||||
|
private static final int[] defaultColumnsWidth = {20, 100, 100, 80};
|
||||||
|
|
||||||
public enum ChatType {
|
public enum ChatType {
|
||||||
|
|
||||||
DEFAULT, GAME, TABLES, TOURNAMENT
|
DEFAULT, GAME, TABLES, TOURNAMENT
|
||||||
|
@ -144,6 +159,9 @@ public class ChatPanel extends javax.swing.JPanel {
|
||||||
jTablePlayers.setBackground(new Color(0, 0, 0, ALPHA));
|
jTablePlayers.setBackground(new Color(0, 0, 0, ALPHA));
|
||||||
jTablePlayers.setForeground(Color.white);
|
jTablePlayers.setForeground(Color.white);
|
||||||
jTablePlayers.setRowSorter(new MageTableRowSorter(tableModel));
|
jTablePlayers.setRowSorter(new MageTableRowSorter(tableModel));
|
||||||
|
|
||||||
|
TableUtil.setColumnWidthAndOrder(jTablePlayers, defaultColumnsWidth, KEY_USERS_COLUMNS_WIDTH, KEY_USERS_COLUMNS_ORDER);
|
||||||
|
|
||||||
if (jScrollPaneTxt != null) {
|
if (jScrollPaneTxt != null) {
|
||||||
jScrollPaneTxt.setBackground(new Color(0, 0, 0, ALPHA));
|
jScrollPaneTxt.setBackground(new Color(0, 0, 0, ALPHA));
|
||||||
jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, ALPHA));
|
jScrollPaneTxt.getViewport().setBackground(new Color(0, 0, 0, ALPHA));
|
||||||
|
@ -157,6 +175,10 @@ public class ChatPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanUp() {
|
||||||
|
TableUtil.saveColumnWidthAndOrderToPrefs(jTablePlayers, KEY_USERS_COLUMNS_WIDTH, KEY_USERS_COLUMNS_ORDER);
|
||||||
|
}
|
||||||
|
|
||||||
public ChatType getChatType() {
|
public ChatType getChatType() {
|
||||||
return chatType;
|
return chatType;
|
||||||
}
|
}
|
||||||
|
@ -311,8 +333,11 @@ public class ChatPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
class TableModel extends AbstractTableModel {
|
class TableModel extends AbstractTableModel {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private final String[] columnNames = new String[]{" ","Players", "Info", "Games", "Connection"};
|
private final String[] columnNames = new String[]{" ","Players", "Info", "Games", "Connection"};
|
||||||
private UsersView[] players = new UsersView[0];
|
private UsersView[] players = new UsersView[0];
|
||||||
|
private Map<String, ImageIcon> flagIconCache = new HashMap<>();
|
||||||
|
|
||||||
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
|
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
|
||||||
RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
|
||||||
|
@ -343,7 +368,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
||||||
public Object getValueAt(int arg0, int arg1) {
|
public Object getValueAt(int arg0, int arg1) {
|
||||||
switch (arg1) {
|
switch (arg1) {
|
||||||
case 0:
|
case 0:
|
||||||
return players[arg0].getFlagName();
|
return getCountryFlagIcon(players[arg0].getFlagName());
|
||||||
case 1:
|
case 1:
|
||||||
return players[arg0].getUserName();
|
return players[arg0].getUserName();
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -369,13 +394,32 @@ public class ChatPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getColumnClass(int columnIndex) {
|
public Class getColumnClass(int columnIndex) {
|
||||||
return String.class;
|
switch (columnIndex) {
|
||||||
|
case 0:
|
||||||
|
return Icon.class;
|
||||||
|
default:
|
||||||
|
return String.class;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ImageIcon getCountryFlagIcon(String countryCode) {
|
||||||
|
ImageIcon flagIcon = flagIconCache.get(countryCode);
|
||||||
|
if (flagIcon == null) {
|
||||||
|
flagIcon = new javax.swing.ImageIcon(getClass().getResource("/flags/" + countryCode +".png"));
|
||||||
|
if (flagIcon.getImage() == null) {
|
||||||
|
logger.warn("Country flag resource not found: " + countryCode);
|
||||||
|
} else {
|
||||||
|
flagIconCache.put(countryCode, flagIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flagIcon;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
|
|
@ -65,6 +65,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_AUTO_CONNECT;
|
import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_AUTO_CONNECT;
|
||||||
import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_FLAG;
|
import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_FLAG;
|
||||||
|
import mage.client.util.gui.countryBox.CountryItemEditor;
|
||||||
import mage.remote.Connection.ProxyType;
|
import mage.remote.Connection.ProxyType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,7 +102,7 @@ public class ConnectDialog extends MageDialog {
|
||||||
this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get(KEY_CONNECT_AUTO_CONNECT, "false")));
|
this.chkAutoConnect.setSelected(Boolean.parseBoolean(MageFrame.getPreferences().get(KEY_CONNECT_AUTO_CONNECT, "false")));
|
||||||
this.chkForceUpdateDB.setSelected(false); // has always to be set manually to force comparison
|
this.chkForceUpdateDB.setSelected(false); // has always to be set manually to force comparison
|
||||||
|
|
||||||
String selectedFlag = MageFrame.getPreferences().get(KEY_CONNECT_FLAG, "world.png");
|
String selectedFlag = MageFrame.getPreferences().get(KEY_CONNECT_FLAG, "world");
|
||||||
// set the selected country/flag
|
// set the selected country/flag
|
||||||
for (int i = 0; i < cbFlag.getItemCount(); i++) {
|
for (int i = 0; i < cbFlag.getItemCount(); i++) {
|
||||||
String[] name = (String[])cbFlag.getItemAt(i);
|
String[] name = (String[])cbFlag.getItemAt(i);
|
||||||
|
@ -292,7 +293,7 @@ public class ConnectDialog extends MageDialog {
|
||||||
|
|
||||||
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
|
||||||
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
|
||||||
MageFrame.getPreferences().put(KEY_CONNECT_FLAG, (String)cbFlag.getSelectedItem());
|
MageFrame.getPreferences().put(KEY_CONNECT_FLAG, ((CountryItemEditor)cbFlag.getEditor()).getImageItem());
|
||||||
if (task != null && !task.isDone()) {
|
if (task != null && !task.isDone()) {
|
||||||
task.cancel(true);
|
task.cancel(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -328,7 +329,7 @@ public class ConnectDialog extends MageDialog {
|
||||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||||
connection.setUsername(this.txtUserName.getText().trim());
|
connection.setUsername(this.txtUserName.getText().trim());
|
||||||
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected());
|
connection.setForceDBComparison(this.chkForceUpdateDB.isSelected());
|
||||||
MageFrame.getPreferences().put(KEY_CONNECT_FLAG, (String)cbFlag.getSelectedItem());
|
MageFrame.getPreferences().put(KEY_CONNECT_FLAG, ((CountryItemEditor)cbFlag.getEditor()).getImageItem());
|
||||||
|
|
||||||
ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
|
ProxyType configProxyType = Connection.ProxyType.valueByText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PROXY_TYPE, "None"));
|
||||||
|
|
||||||
|
|
|
@ -150,6 +150,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2";
|
public static final String KEY_TABLES_DIVIDER_LOCATION_2 = "tablePanelDividerLocation2";
|
||||||
public static final String KEY_TABLES_DIVIDER_LOCATION_3 = "tablePanelDividerLocation3";
|
public static final String KEY_TABLES_DIVIDER_LOCATION_3 = "tablePanelDividerLocation3";
|
||||||
|
|
||||||
|
// user list
|
||||||
|
public static final String KEY_USERS_COLUMNS_WIDTH = "userPanelColumnWidth";
|
||||||
|
public static final String KEY_USERS_COLUMNS_ORDER = "userPanelColumnSort";
|
||||||
|
|
||||||
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_0 = "gamepanelDividerLocation0";
|
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_1 = "gamepanelDividerLocation1";
|
||||||
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2";
|
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2";
|
||||||
|
|
|
@ -64,12 +64,10 @@ import javax.swing.JInternalFrame;
|
||||||
import javax.swing.JLayeredPane;
|
import javax.swing.JLayeredPane;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JTable;
|
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.JToggleButton;
|
||||||
import javax.swing.RowFilter;
|
import javax.swing.RowFilter;
|
||||||
import javax.swing.SwingWorker;
|
import javax.swing.SwingWorker;
|
||||||
import javax.swing.table.AbstractTableModel;
|
import javax.swing.table.AbstractTableModel;
|
||||||
import javax.swing.table.TableColumn;
|
|
||||||
import mage.cards.decks.importer.DeckImporterUtil;
|
import mage.cards.decks.importer.DeckImporterUtil;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.chat.ChatPanel;
|
import mage.client.chat.ChatPanel;
|
||||||
|
@ -78,10 +76,13 @@ import mage.client.dialog.JoinTableDialog;
|
||||||
import mage.client.dialog.NewTableDialog;
|
import mage.client.dialog.NewTableDialog;
|
||||||
import mage.client.dialog.NewTournamentDialog;
|
import mage.client.dialog.NewTournamentDialog;
|
||||||
import mage.client.dialog.PreferencesDialog;
|
import mage.client.dialog.PreferencesDialog;
|
||||||
|
import static mage.client.dialog.PreferencesDialog.KEY_TABLES_COLUMNS_ORDER;
|
||||||
|
import static mage.client.dialog.PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH;
|
||||||
import mage.client.dialog.TableWaitingDialog;
|
import mage.client.dialog.TableWaitingDialog;
|
||||||
import mage.client.util.ButtonColumn;
|
import mage.client.util.ButtonColumn;
|
||||||
import mage.client.util.MageTableRowSorter;
|
import mage.client.util.MageTableRowSorter;
|
||||||
import mage.client.util.gui.GuiDisplayUtil;
|
import mage.client.util.gui.GuiDisplayUtil;
|
||||||
|
import mage.client.util.gui.TableUtil;
|
||||||
import mage.constants.MatchTimeLimit;
|
import mage.constants.MatchTimeLimit;
|
||||||
import mage.constants.MultiplayerAttackOption;
|
import mage.constants.MultiplayerAttackOption;
|
||||||
import mage.constants.RangeOfInfluence;
|
import mage.constants.RangeOfInfluence;
|
||||||
|
@ -93,7 +94,6 @@ import mage.view.MatchView;
|
||||||
import mage.view.RoomUsersView;
|
import mage.view.RoomUsersView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.mage.card.arcane.Util;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -120,9 +120,11 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
JToggleButton[] filterButtons;
|
JToggleButton[] filterButtons;
|
||||||
|
|
||||||
|
private static final int[] defaultColumnsWidth = {35, 150, 120, 180, 80, 120, 80, 60, 60};
|
||||||
|
|
||||||
/** Creates new form TablesPanel */
|
/** Creates new form TablesPanel */
|
||||||
public TablesPanel() {
|
public TablesPanel() {
|
||||||
|
|
||||||
tableModel = new TableTableModel();
|
tableModel = new TableTableModel();
|
||||||
matchesModel = new MatchesTableModel();
|
matchesModel = new MatchesTableModel();
|
||||||
gameChooser = new GameChooser();
|
gameChooser = new GameChooser();
|
||||||
|
@ -135,7 +137,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
activeTablesSorter = new MageTableRowSorter(tableModel);
|
activeTablesSorter = new MageTableRowSorter(tableModel);
|
||||||
tableTables.setRowSorter(activeTablesSorter);
|
tableTables.setRowSorter(activeTablesSorter);
|
||||||
|
|
||||||
TableTableModel.setColumnWidthAndOrder(tableTables);
|
TableUtil.setColumnWidthAndOrder(tableTables, defaultColumnsWidth,
|
||||||
|
PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, PreferencesDialog.KEY_TABLES_COLUMNS_ORDER);
|
||||||
|
|
||||||
tableCompleted.setRowSorter(new MageTableRowSorter(matchesModel));
|
tableCompleted.setRowSorter(new MageTableRowSorter(matchesModel));
|
||||||
|
|
||||||
|
@ -276,6 +279,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
chatPanel.cleanUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveDividerLocations() {
|
private void saveDividerLocations() {
|
||||||
|
@ -311,23 +315,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_FILTER_SETTINGS, formatSettings.toString());
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_FILTER_SETTINGS, formatSettings.toString());
|
||||||
|
|
||||||
// Column width
|
TableUtil.saveColumnWidthAndOrderToPrefs(tableTables, KEY_TABLES_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_ORDER);
|
||||||
StringBuilder columnWidthSettings = new StringBuilder();
|
|
||||||
StringBuilder columnOrderSettings = new StringBuilder();
|
|
||||||
boolean firstValue = true;
|
|
||||||
for (int i = 0; i < tableTables.getColumnModel().getColumnCount(); i++) {
|
|
||||||
TableColumn column = tableTables.getColumnModel().getColumn(tableTables.convertColumnIndexToView(i));
|
|
||||||
if (!firstValue) {
|
|
||||||
columnWidthSettings.append(",");
|
|
||||||
columnOrderSettings.append(",");
|
|
||||||
} else {
|
|
||||||
firstValue = false;
|
|
||||||
}
|
|
||||||
columnWidthSettings.append(column.getWidth());
|
|
||||||
columnOrderSettings.append(tableTables.convertColumnIndexToModel(i));
|
|
||||||
}
|
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, columnWidthSettings.toString());
|
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_COLUMNS_ORDER, columnOrderSettings.toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void restoreDividerLocations() {
|
private void restoreDividerLocations() {
|
||||||
|
@ -1157,6 +1145,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
options.setWinsNeeded(1);
|
options.setWinsNeeded(1);
|
||||||
options.setMatchTimeLimit(MatchTimeLimit.NONE);
|
options.setMatchTimeLimit(MatchTimeLimit.NONE);
|
||||||
options.setFreeMulligans(2);
|
options.setFreeMulligans(2);
|
||||||
|
options.setSkillLevel(SkillLevel.CASUAL);
|
||||||
table = session.createTable(roomId, options);
|
table = session.createTable(roomId, options);
|
||||||
|
|
||||||
session.joinTable(roomId, table.getTableId(), "Human", "Human", 1, DeckImporterUtil.importDeck("test.dck"),"");
|
session.joinTable(roomId, table.getTableId(), "Human", "Human", 1, DeckImporterUtil.importDeck("test.dck"),"");
|
||||||
|
@ -1262,8 +1251,7 @@ class TableTableModel extends AbstractTableModel {
|
||||||
public static final int ACTION_COLUMN = 8; // column the action is located (starting with 0)
|
public static final int ACTION_COLUMN = 8; // column the action is located (starting with 0)
|
||||||
|
|
||||||
private final String[] columnNames = new String[]{"M/T","Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Created / Started", "Skill Level", "Action"};
|
private final String[] columnNames = new String[]{"M/T","Deck Type", "Owner / Players", "Game Type", "Info", "Status", "Created / Started", "Skill Level", "Action"};
|
||||||
private static final int[] defaultColumnsWidth = {35, 150, 120, 180, 80, 120, 80, 60, 60};
|
|
||||||
|
|
||||||
private TableView[] tables = new TableView[0];
|
private TableView[] tables = new TableView[0];
|
||||||
private static final DateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");;
|
private static final DateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");;
|
||||||
|
|
||||||
|
@ -1272,32 +1260,7 @@ class TableTableModel extends AbstractTableModel {
|
||||||
public void loadData(Collection<TableView> tables) throws MageRemoteException {
|
public void loadData(Collection<TableView> tables) throws MageRemoteException {
|
||||||
this.tables = tables.toArray(new TableView[0]);
|
this.tables = tables.toArray(new TableView[0]);
|
||||||
this.fireTableDataChanged();
|
this.fireTableDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void setColumnWidthAndOrder(JTable table) {
|
|
||||||
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
|
||||||
|
|
||||||
// set the column width from saved value or defaults
|
|
||||||
int[] widths = Util.getIntArrayFromString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_COLUMNS_WIDTH, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// set the column order
|
|
||||||
int[] order = Util.getIntArrayFromString(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_TABLES_COLUMNS_ORDER, null));
|
|
||||||
if (order != null && order.length == table.getColumnCount()) {
|
|
||||||
for (int j = 0; j < table.getColumnCount(); j++) {
|
|
||||||
table.moveColumn(table.convertColumnIndexToView(order[j]), j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRowCount() {
|
public int getRowCount() {
|
||||||
|
|
|
@ -0,0 +1,87 @@
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import javax.swing.JTable;
|
||||||
|
import javax.swing.table.TableColumn;
|
||||||
|
import mage.client.dialog.PreferencesDialog;
|
||||||
|
import org.mage.card.arcane.Util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author LevelX2
|
||||||
|
*/
|
||||||
|
public class TableUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param table
|
||||||
|
* @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
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the column order
|
||||||
|
int[] order = getIntArrayFromString(PreferencesDialog.getCachedValue(orderPrefKey, null));
|
||||||
|
if (order != null && order.length == table.getColumnCount()) {
|
||||||
|
for (int j = 0; j < table.getColumnCount(); j++) {
|
||||||
|
table.moveColumn(table.convertColumnIndexToView(order[j]), j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void saveColumnWidthAndOrderToPrefs(JTable table, String widthPrefKey, String orderPrefKey) {
|
||||||
|
// Column width
|
||||||
|
StringBuilder columnWidthSettings = new StringBuilder();
|
||||||
|
StringBuilder columnOrderSettings = new StringBuilder();
|
||||||
|
boolean firstValue = true;
|
||||||
|
for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) {
|
||||||
|
TableColumn column = table.getColumnModel().getColumn(table.convertColumnIndexToView(i));
|
||||||
|
if (!firstValue) {
|
||||||
|
columnWidthSettings.append(",");
|
||||||
|
columnOrderSettings.append(",");
|
||||||
|
} else {
|
||||||
|
firstValue = false;
|
||||||
|
}
|
||||||
|
columnWidthSettings.append(column.getWidth());
|
||||||
|
columnOrderSettings.append(table.convertColumnIndexToModel(i));
|
||||||
|
}
|
||||||
|
PreferencesDialog.saveValue(widthPrefKey, columnWidthSettings.toString());
|
||||||
|
PreferencesDialog.saveValue(orderPrefKey, columnOrderSettings.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int[] getIntArrayFromString(String stringData) {
|
||||||
|
int[] intArray = null;
|
||||||
|
if (stringData != null && !stringData.isEmpty()) {
|
||||||
|
String[] items = stringData.split(",");
|
||||||
|
int lengthW = items.length;
|
||||||
|
intArray = new int[lengthW];
|
||||||
|
for (int i = 0; i < lengthW; i++) {
|
||||||
|
try {
|
||||||
|
intArray[i] = Integer.parseInt(items[i]);
|
||||||
|
} catch (NumberFormatException nfe) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return intArray;
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,252 +40,252 @@ public class CountryComboBox extends JComboBox {
|
||||||
private final DefaultComboBoxModel model;
|
private final DefaultComboBoxModel model;
|
||||||
|
|
||||||
public static String[][] countryList = {
|
public static String[][] countryList = {
|
||||||
{"Afghanistan", "af.png"},
|
{"Afghanistan", "af"},
|
||||||
{"Åland Islands", "ax.png"},
|
{"Åland Islands", "ax"},
|
||||||
{"Albania", "al.png"},
|
{"Albania", "al"},
|
||||||
{"Algeria", "dz.png"},
|
{"Algeria", "dz"},
|
||||||
{"American Samoa", "as.png"},
|
{"American Samoa", "as"},
|
||||||
{"Andorra", "ad.png"},
|
{"Andorra", "ad"},
|
||||||
{"Angola", "an.png"},
|
{"Angola", "an"},
|
||||||
{"Anguilla", "ai.png"},
|
{"Anguilla", "ai"},
|
||||||
{"Antarctica", "ao.png"},
|
{"Antarctica", "ao"},
|
||||||
{"Antigua and Barbuda", "ag.png"},
|
{"Antigua and Barbuda", "ag"},
|
||||||
{"Argentina", "ar.png"},
|
{"Argentina", "ar"},
|
||||||
{"Armenia", "am.png"},
|
{"Armenia", "am"},
|
||||||
{"Aruba", "aw.png"},
|
{"Aruba", "aw"},
|
||||||
{"Australia", "au.png"},
|
{"Australia", "au"},
|
||||||
{"Austria", "at.png"},
|
{"Austria", "at"},
|
||||||
{"Azerbaijan", "az.png"},
|
{"Azerbaijan", "az"},
|
||||||
{"Bahamas", "bs.png"},
|
{"Bahamas", "bs"},
|
||||||
{"Bahrain", "bh.png"},
|
{"Bahrain", "bh"},
|
||||||
{"Bangladesh", "bd.png"},
|
{"Bangladesh", "bd"},
|
||||||
{"Barbados", "bb.png"},
|
{"Barbados", "bb"},
|
||||||
{"Belarus", "by.png"},
|
{"Belarus", "by"},
|
||||||
{"Belgium", "be.png"},
|
{"Belgium", "be"},
|
||||||
{"Belize", "bz.png"},
|
{"Belize", "bz"},
|
||||||
{"Benin", "bj.png"},
|
{"Benin", "bj"},
|
||||||
{"Bermuda", "bm.png"},
|
{"Bermuda", "bm"},
|
||||||
{"Bhutan", "bt.png"},
|
{"Bhutan", "bt"},
|
||||||
{"Bolivia, Plurinational State of", "bo.png"},
|
{"Bolivia, Plurinational State of", "bo"},
|
||||||
{"Bosnia and Herzegovina", "ba.png"},
|
{"Bosnia and Herzegovina", "ba"},
|
||||||
{"Botswana", "bw.png"},
|
{"Botswana", "bw"},
|
||||||
{"Bouvet Island", "bv.png"},
|
{"Bouvet Island", "bv"},
|
||||||
{"Brazil", "br.png"},
|
{"Brazil", "br"},
|
||||||
{"British Indian Ocean Territory", "io.png"},
|
{"British Indian Ocean Territory", "io"},
|
||||||
{"Brunei Darussalam", "bn.png"},
|
{"Brunei Darussalam", "bn"},
|
||||||
{"Bulgaria", "bg.png"},
|
{"Bulgaria", "bg"},
|
||||||
{"Burkina Faso", "bf.png"},
|
{"Burkina Faso", "bf"},
|
||||||
{"Burundi", "bi.png"},
|
{"Burundi", "bi"},
|
||||||
{"Cabo Verde", "cv.png"},
|
{"Cabo Verde", "cv"},
|
||||||
{"Cambodia", "kh.png"},
|
{"Cambodia", "kh"},
|
||||||
{"Cameroon", "cm.png"},
|
{"Cameroon", "cm"},
|
||||||
{"Canada", "ca.png"},
|
{"Canada", "ca"},
|
||||||
{"Catalonia", "catalonia.png"},
|
{"Catalonia", "catalonia"},
|
||||||
{"Cayman Islands", "ky.png"},
|
{"Cayman Islands", "ky"},
|
||||||
{"Central African Republic", "cf.png"},
|
{"Central African Republic", "cf"},
|
||||||
{"Chad", "td.png"},
|
{"Chad", "td"},
|
||||||
{"Chile", "cl.png"},
|
{"Chile", "cl"},
|
||||||
{"China", "cn.png"},
|
{"China", "cn"},
|
||||||
{"Christmas Island", "cx.png"},
|
{"Christmas Island", "cx"},
|
||||||
{"Cocos (Keeling) Islands", "cc.png"},
|
{"Cocos (Keeling) Islands", "cc"},
|
||||||
{"Colombia", "co.png"},
|
{"Colombia", "co"},
|
||||||
{"Comoros", "km.png"},
|
{"Comoros", "km"},
|
||||||
{"Congo", "cg.png"},
|
{"Congo", "cg"},
|
||||||
{"Congo, the Democratic Republic of the", "cd.png"},
|
{"Congo, the Democratic Republic of the", "cd"},
|
||||||
{"Cook Islands", "ck.png"},
|
{"Cook Islands", "ck"},
|
||||||
{"Costa Rica", "cr.png"},
|
{"Costa Rica", "cr"},
|
||||||
{"Côte d'Ivoire", "ci.png"},
|
{"Côte d'Ivoire", "ci"},
|
||||||
{"Croatia", "hr.png"},
|
{"Croatia", "hr"},
|
||||||
{"Cuba", "cu.png"},
|
{"Cuba", "cu"},
|
||||||
{"Cyprus", "cy.png"},
|
{"Cyprus", "cy"},
|
||||||
{"Czech Republic", "cz.png"},
|
{"Czech Republic", "cz"},
|
||||||
{"Denmark", "dk.png"},
|
{"Denmark", "dk"},
|
||||||
{"Djibouti", "dj.png"},
|
{"Djibouti", "dj"},
|
||||||
{"Dominica", "dm.png"},
|
{"Dominica", "dm"},
|
||||||
{"Dominican Republic", "do.png"},
|
{"Dominican Republic", "do"},
|
||||||
{"Ecuador", "ec.png"},
|
{"Ecuador", "ec"},
|
||||||
{"Egypt", "eg.png"},
|
{"Egypt", "eg"},
|
||||||
{"El Salvador", "sv.png"},
|
{"El Salvador", "sv"},
|
||||||
{"England", "england.png"},
|
{"England", "england"},
|
||||||
{"Equatorial Guinea", "gq.png"},
|
{"Equatorial Guinea", "gq"},
|
||||||
{"Eritrea", "er.png"},
|
{"Eritrea", "er"},
|
||||||
{"Estonia", "ee.png"},
|
{"Estonia", "ee"},
|
||||||
{"Ethiopia", "et.png"},
|
{"Ethiopia", "et"},
|
||||||
{"European Union", "europeanunion.png"},
|
{"European Union", "europeanunion"},
|
||||||
{"Falkland Islands (Malvinas)", "fk.png"},
|
{"Falkland Islands (Malvinas)", "fk"},
|
||||||
{"Faroe Islands", "fo.png"},
|
{"Faroe Islands", "fo"},
|
||||||
{"Fiji", "fj.png"},
|
{"Fiji", "fj"},
|
||||||
{"Finland", "fi.png"},
|
{"Finland", "fi"},
|
||||||
{"France", "fr.png"},
|
{"France", "fr"},
|
||||||
{"French Guiana", "gf.png"},
|
{"French Guiana", "gf"},
|
||||||
{"French Polynesia", "pf.png"},
|
{"French Polynesia", "pf"},
|
||||||
{"French Southern Territories", "tf.png"},
|
{"French Southern Territories", "tf"},
|
||||||
{"Gabon", "ga.png"},
|
{"Gabon", "ga"},
|
||||||
{"Gambia", "gm.png"},
|
{"Gambia", "gm"},
|
||||||
{"Georgia", "ge.png"},
|
{"Georgia", "ge"},
|
||||||
{"Germany", "de.png"},
|
{"Germany", "de"},
|
||||||
{"Ghana", "gh.png"},
|
{"Ghana", "gh"},
|
||||||
{"Gibraltar", "gi.png"},
|
{"Gibraltar", "gi"},
|
||||||
{"Greece", "gr.png"},
|
{"Greece", "gr"},
|
||||||
{"Greenland", "gl.png"},
|
{"Greenland", "gl"},
|
||||||
{"Grenada", "gd.png"},
|
{"Grenada", "gd"},
|
||||||
{"Guadeloupe", "gp.png"},
|
{"Guadeloupe", "gp"},
|
||||||
{"Guam", "gu.png"},
|
{"Guam", "gu"},
|
||||||
{"Guatemala", "gt.png"},
|
{"Guatemala", "gt"},
|
||||||
{"Guinea", "gn.png"},
|
{"Guinea", "gn"},
|
||||||
{"Guinea-Bissau", "gw.png"},
|
{"Guinea-Bissau", "gw"},
|
||||||
{"Guyana", "gy.png"},
|
{"Guyana", "gy"},
|
||||||
{"Haiti", "ht.png"},
|
{"Haiti", "ht"},
|
||||||
{"Heard Island and McDonald Islands", "hm.png"},
|
{"Heard Island and McDonald Islands", "hm"},
|
||||||
{"Holy See", "va.png"},
|
{"Holy See", "va"},
|
||||||
{"Honduras", "hn.png"},
|
{"Honduras", "hn"},
|
||||||
{"Hong Kong", "hk.png"},
|
{"Hong Kong", "hk"},
|
||||||
{"Hungary", "hu.png"},
|
{"Hungary", "hu"},
|
||||||
{"Iceland", "is.png"},
|
{"Iceland", "is"},
|
||||||
{"India", "in.png"},
|
{"India", "in"},
|
||||||
{"Indonesia", "id.png"},
|
{"Indonesia", "id"},
|
||||||
{"Iran, Islamic Republic of", "ir.png"},
|
{"Iran, Islamic Republic of", "ir"},
|
||||||
{"Iraq", "iq.png"},
|
{"Iraq", "iq"},
|
||||||
{"Ireland", "ie.png"},
|
{"Ireland", "ie"},
|
||||||
{"Israel", "il.png"},
|
{"Israel", "il"},
|
||||||
{"Italy", "it.png"},
|
{"Italy", "it"},
|
||||||
{"Jamaica", "jm.png"},
|
{"Jamaica", "jm"},
|
||||||
{"Japan", "jp.png"},
|
{"Japan", "jp"},
|
||||||
{"Jordan", "jo.png"},
|
{"Jordan", "jo"},
|
||||||
{"Kazakhstan", "kz.png"},
|
{"Kazakhstan", "kz"},
|
||||||
{"Kenya", "ke.png"},
|
{"Kenya", "ke"},
|
||||||
{"Kiribati", "ki.png"},
|
{"Kiribati", "ki"},
|
||||||
{"Korea, Democratic People's Republic of", "kp.png"},
|
{"Korea, Democratic People's Republic of", "kp"},
|
||||||
{"Korea, Republic of", "kr.png"},
|
{"Korea, Republic of", "kr"},
|
||||||
{"Kuwait", "kw.png"},
|
{"Kuwait", "kw"},
|
||||||
{"Kyrgyzstan", "kg.png"},
|
{"Kyrgyzstan", "kg"},
|
||||||
{"Lao People's Democratic Republic", "la.png"},
|
{"Lao People's Democratic Republic", "la"},
|
||||||
{"Latvia", "lv.png"},
|
{"Latvia", "lv"},
|
||||||
{"Lebanon", "lb.png"},
|
{"Lebanon", "lb"},
|
||||||
{"Lesotho", "ls.png"},
|
{"Lesotho", "ls"},
|
||||||
{"Liberia", "lr.png"},
|
{"Liberia", "lr"},
|
||||||
{"Libya", "ly.png"},
|
{"Libya", "ly"},
|
||||||
{"Liechtenstein", "li.png"},
|
{"Liechtenstein", "li"},
|
||||||
{"Lithuania", "lt.png"},
|
{"Lithuania", "lt"},
|
||||||
{"Luxembourg", "lu.png"},
|
{"Luxembourg", "lu"},
|
||||||
{"Macao", "mo.png"},
|
{"Macao", "mo"},
|
||||||
{"Macedonia, the former Yugoslav Republic of", "mk.png"},
|
{"Macedonia, the former Yugoslav Republic of", "mk"},
|
||||||
{"Madagascar", "mg.png"},
|
{"Madagascar", "mg"},
|
||||||
{"Malawi", "mw.png"},
|
{"Malawi", "mw"},
|
||||||
{"Malaysia", "my.png"},
|
{"Malaysia", "my"},
|
||||||
{"Maldives", "mv.png"},
|
{"Maldives", "mv"},
|
||||||
{"Mali", "ml.png"},
|
{"Mali", "ml"},
|
||||||
{"Malta", "mt.png"},
|
{"Malta", "mt"},
|
||||||
{"Marshall Islands", "mh.png"},
|
{"Marshall Islands", "mh"},
|
||||||
{"Martinique", "mq.png"},
|
{"Martinique", "mq"},
|
||||||
{"Mauritania", "mr.png"},
|
{"Mauritania", "mr"},
|
||||||
{"Mauritius", "mu.png"},
|
{"Mauritius", "mu"},
|
||||||
{"Mayotte", "yt.png"},
|
{"Mayotte", "yt"},
|
||||||
{"Mexico", "mx.png"},
|
{"Mexico", "mx"},
|
||||||
{"Micronesia, Federated States of", "fm.png"},
|
{"Micronesia, Federated States of", "fm"},
|
||||||
{"Moldova, Republic of", "md.png"},
|
{"Moldova, Republic of", "md"},
|
||||||
{"Monaco", "mc.png"},
|
{"Monaco", "mc"},
|
||||||
{"Mongolia", "mn.png"},
|
{"Mongolia", "mn"},
|
||||||
{"Montenegro", "me.png"},
|
{"Montenegro", "me"},
|
||||||
{"Montserrat", "ms.png"},
|
{"Montserrat", "ms"},
|
||||||
{"Morocco", "ma.png"},
|
{"Morocco", "ma"},
|
||||||
{"Mozambique", "mz.png"},
|
{"Mozambique", "mz"},
|
||||||
{"Myanmar", "mm.png"},
|
{"Myanmar", "mm"},
|
||||||
{"Namibia", "na.png"},
|
{"Namibia", "na"},
|
||||||
{"Nauru", "nr.png"},
|
{"Nauru", "nr"},
|
||||||
{"Nepal", "np.png"},
|
{"Nepal", "np"},
|
||||||
{"Netherlands", "nl.png"},
|
{"Netherlands", "nl"},
|
||||||
{"New Caledonia", "nc.png"},
|
{"New Caledonia", "nc"},
|
||||||
{"New Zealand", "nz.png"},
|
{"New Zealand", "nz"},
|
||||||
{"Nicaragua", "ni.png"},
|
{"Nicaragua", "ni"},
|
||||||
{"Niger", "ne.png"},
|
{"Niger", "ne"},
|
||||||
{"Nigeria", "ng.png"},
|
{"Nigeria", "ng"},
|
||||||
{"Niue", "nu.png"},
|
{"Niue", "nu"},
|
||||||
{"Norfolk Island", "nf.png"},
|
{"Norfolk Island", "nf"},
|
||||||
{"Northern Mariana Islands", "mp.png"},
|
{"Northern Mariana Islands", "mp"},
|
||||||
{"Norway", "no.png"},
|
{"Norway", "no"},
|
||||||
{"Oman", "om.png"},
|
{"Oman", "om"},
|
||||||
{"Pakistan", "pk.png"},
|
{"Pakistan", "pk"},
|
||||||
{"Palau", "pw.png"},
|
{"Palau", "pw"},
|
||||||
{"Palestine, State of", "ps.png"},
|
{"Palestine, State of", "ps"},
|
||||||
{"Panama", "pa.png"},
|
{"Panama", "pa"},
|
||||||
{"Papua New Guinea", "pg.png"},
|
{"Papua New Guinea", "pg"},
|
||||||
{"Paraguay", "py.png"},
|
{"Paraguay", "py"},
|
||||||
{"Peru", "pe.png"},
|
{"Peru", "pe"},
|
||||||
{"Philippines", "ph.png"},
|
{"Philippines", "ph"},
|
||||||
{"Pitcairn", "pn.png"},
|
{"Pitcairn", "pn"},
|
||||||
{"Poland", "pl.png"},
|
{"Poland", "pl"},
|
||||||
{"Portugal", "pt.png"},
|
{"Portugal", "pt"},
|
||||||
{"Puerto Rico", "pr.png"},
|
{"Puerto Rico", "pr"},
|
||||||
{"Qatar", "qa.png"},
|
{"Qatar", "qa"},
|
||||||
{"Réunion", "re.png"},
|
{"Réunion", "re"},
|
||||||
{"Romania", "ro.png"},
|
{"Romania", "ro"},
|
||||||
{"Russian Federation", "ru.png"},
|
{"Russian Federation", "ru"},
|
||||||
{"Rwanda", "rw.png"},
|
{"Rwanda", "rw"},
|
||||||
{"Saint Helena, Ascension and Tristan da Cunha", "sh.png"},
|
{"Saint Helena, Ascension and Tristan da Cunha", "sh"},
|
||||||
{"Saint Kitts and Nevis", "kn.png"},
|
{"Saint Kitts and Nevis", "kn"},
|
||||||
{"Saint Lucia", "lc.png"},
|
{"Saint Lucia", "lc"},
|
||||||
{"Saint Pierre and Miquelon", "pm.png"},
|
{"Saint Pierre and Miquelon", "pm"},
|
||||||
{"Saint Vincent and the Grenadines", "vc.png"},
|
{"Saint Vincent and the Grenadines", "vc"},
|
||||||
{"Samoa", "ws.png"},
|
{"Samoa", "ws"},
|
||||||
{"San Marino", "sm.png"},
|
{"San Marino", "sm"},
|
||||||
{"Sao Tome and Principe", "st.png"},
|
{"Sao Tome and Principe", "st"},
|
||||||
{"Saudi Arabia", "sa.png"},
|
{"Saudi Arabia", "sa"},
|
||||||
{"Scotland", "scotland.png"},
|
{"Scotland", "scotland"},
|
||||||
{"Senegal", "sn.png"},
|
{"Senegal", "sn"},
|
||||||
{"Serbia", "rs.png"},
|
{"Serbia", "rs"},
|
||||||
{"Seychelles", "sc.png"},
|
{"Seychelles", "sc"},
|
||||||
{"Sierra Leone", "sl.png"},
|
{"Sierra Leone", "sl"},
|
||||||
{"Singapore", "sg.png"},
|
{"Singapore", "sg"},
|
||||||
{"Slovakia", "sk.png"},
|
{"Slovakia", "sk"},
|
||||||
{"Slovenia", "si.png"},
|
{"Slovenia", "si"},
|
||||||
{"Solomon Islands", "sb.png"},
|
{"Solomon Islands", "sb"},
|
||||||
{"Somalia", "so.png"},
|
{"Somalia", "so"},
|
||||||
{"South Africa", "za.png"},
|
{"South Africa", "za"},
|
||||||
{"South Georgia and the South Sandwich Islands", "gs.png"},
|
{"South Georgia and the South Sandwich Islands", "gs"},
|
||||||
{"Spain", "es.png"},
|
{"Spain", "es"},
|
||||||
{"Sri Lanka", "lk.png"},
|
{"Sri Lanka", "lk"},
|
||||||
{"Sudan", "sd.png"},
|
{"Sudan", "sd"},
|
||||||
{"Suriname", "sr.png"},
|
{"Suriname", "sr"},
|
||||||
{"Svalbard and Jan Mayen", "sj.png"},
|
{"Svalbard and Jan Mayen", "sj"},
|
||||||
{"Swaziland", "sz.png"},
|
{"Swaziland", "sz"},
|
||||||
{"Sweden", "se.png"},
|
{"Sweden", "se"},
|
||||||
{"Switzerland", "ch.png"},
|
{"Switzerland", "ch"},
|
||||||
{"Syrian Arab Republic", "sy.png"},
|
{"Syrian Arab Republic", "sy"},
|
||||||
{"Taiwan, Province of China", "tw.png"},
|
{"Taiwan, Province of China", "tw"},
|
||||||
{"Tajikistan", "tj.png"},
|
{"Tajikistan", "tj"},
|
||||||
{"Tanzania, United Republic of", "tz.png"},
|
{"Tanzania, United Republic of", "tz"},
|
||||||
{"Thailand", "th.png"},
|
{"Thailand", "th"},
|
||||||
{"Timor-Leste", "tl.png"},
|
{"Timor-Leste", "tl"},
|
||||||
{"Togo", "tg.png"},
|
{"Togo", "tg"},
|
||||||
{"Tokelau", "tk.png"},
|
{"Tokelau", "tk"},
|
||||||
{"Tonga", "to.png"},
|
{"Tonga", "to"},
|
||||||
{"Trinidad and Tobago", "tt.png"},
|
{"Trinidad and Tobago", "tt"},
|
||||||
{"Tunisia", "tn.png"},
|
{"Tunisia", "tn"},
|
||||||
{"Turkey", "tr.png"},
|
{"Turkey", "tr"},
|
||||||
{"Turkmenistan", "tm.png"},
|
{"Turkmenistan", "tm"},
|
||||||
{"Turks and Caicos Islands", "tc.png"},
|
{"Turks and Caicos Islands", "tc"},
|
||||||
{"Tuvalu", "tv.png"},
|
{"Tuvalu", "tv"},
|
||||||
{"Uganda", "ug.png"},
|
{"Uganda", "ug"},
|
||||||
{"Ukraine", "ua.png"},
|
{"Ukraine", "ua"},
|
||||||
{"United Arab Emirates", "ae.png"},
|
{"United Arab Emirates", "ae"},
|
||||||
{"United Kingdom of Great Britain and Northern Ireland", "gb.png"},
|
{"United Kingdom of Great Britain and Northern Ireland", "gb"},
|
||||||
{"United States Minor Outlying Islands", "um.png"},
|
{"United States Minor Outlying Islands", "um"},
|
||||||
{"United States of America", "us.png"},
|
{"United States of America", "us"},
|
||||||
{"Uruguay", "uy.png"},
|
{"Uruguay", "uy"},
|
||||||
{"Uzbekistan", "uz.png"},
|
{"Uzbekistan", "uz"},
|
||||||
{"Vanuatu", "vu.png"},
|
{"Vanuatu", "vu"},
|
||||||
{"Venezuela, Bolivarian Republic of", "ve.png"},
|
{"Venezuela, Bolivarian Republic of", "ve"},
|
||||||
{"Viet Nam", "vn.png"},
|
{"Viet Nam", "vn"},
|
||||||
{"Virgin Islands, British", "vg.png"},
|
{"Virgin Islands, British", "vg"},
|
||||||
{"Virgin Islands, U.S.", "vi.png"},
|
{"Virgin Islands, U.S.", "vi"},
|
||||||
{"Wales", "wales.png"},
|
{"Wales", "wales"},
|
||||||
{"Wallis and Futuna", "wf.png"},
|
{"Wallis and Futuna", "wf"},
|
||||||
{"World", "world.png"},
|
{"World", "world"},
|
||||||
{"Western Sahara", "eh.png"},
|
{"Western Sahara", "eh"},
|
||||||
{"Yemen", "ye.png"},
|
{"Yemen", "ye"},
|
||||||
{"Zambia", "zm.png"},
|
{"Zambia", "zm"},
|
||||||
{"Zimbabwe", "zw.png"},
|
{"Zimbabwe", "zw"},
|
||||||
};
|
};
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -310,6 +310,11 @@ public class CountryComboBox extends JComboBox {
|
||||||
model.addElement(anItem);
|
model.addElement(anItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getSelectedItem() {
|
||||||
|
return super.getSelectedItem(); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import java.awt.Insets;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.border.LineBorder;
|
||||||
import javax.swing.plaf.basic.BasicComboBoxEditor;
|
import javax.swing.plaf.basic.BasicComboBoxEditor;
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,20 +48,23 @@ public class CountryItemEditor extends BasicComboBoxEditor {
|
||||||
private final JPanel panel = new JPanel();
|
private final JPanel panel = new JPanel();
|
||||||
private final JLabel labelItem = new JLabel();
|
private final JLabel labelItem = new JLabel();
|
||||||
private String selectedValue;
|
private String selectedValue;
|
||||||
|
private String selectedImage;
|
||||||
|
|
||||||
public CountryItemEditor() {
|
public CountryItemEditor() {
|
||||||
panel.setLayout(new GridBagLayout());
|
panel.setLayout(new GridBagLayout());
|
||||||
GridBagConstraints constraints = new GridBagConstraints();
|
GridBagConstraints constraints = new GridBagConstraints();
|
||||||
constraints.fill = GridBagConstraints.HORIZONTAL;
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
||||||
constraints.weightx = 1.0;
|
constraints.weightx = 1.0;
|
||||||
constraints.insets = new Insets(2, 5, 2, 2);
|
// constraints.insets = new Insets(2, 5, 2, 2);
|
||||||
|
constraints.insets = new Insets(0, 5, 0, 0);
|
||||||
|
|
||||||
labelItem.setOpaque(false);
|
labelItem.setOpaque(false);
|
||||||
labelItem.setHorizontalAlignment(JLabel.LEFT);
|
labelItem.setHorizontalAlignment(JLabel.LEFT);
|
||||||
labelItem.setForeground(Color.WHITE);
|
labelItem.setForeground(Color.WHITE);
|
||||||
|
|
||||||
panel.add(labelItem, constraints);
|
panel.add(labelItem, constraints);
|
||||||
panel.setBackground(new Color(0,104,139, 0));
|
// panel.setBackground(Color.WHITE);
|
||||||
|
panel.setBackground(new Color(0, 100,190, 255));
|
||||||
selectedValue = null;
|
selectedValue = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +78,9 @@ public class CountryItemEditor extends BasicComboBoxEditor {
|
||||||
return this.selectedValue;
|
return this.selectedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getImageItem() {
|
||||||
|
return this.selectedImage;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setItem(Object item) {
|
public void setItem(Object item) {
|
||||||
if (item == null || !(item instanceof String[])) {
|
if (item == null || !(item instanceof String[])) {
|
||||||
|
@ -81,7 +88,8 @@ public class CountryItemEditor extends BasicComboBoxEditor {
|
||||||
}
|
}
|
||||||
String[] countryItem = (String[]) item;
|
String[] countryItem = (String[]) item;
|
||||||
selectedValue = countryItem[0];
|
selectedValue = countryItem[0];
|
||||||
|
selectedImage = countryItem[1];
|
||||||
labelItem.setText(selectedValue);
|
labelItem.setText(selectedValue);
|
||||||
labelItem.setIcon(new ImageIcon(getClass().getResource("/flags/"+ countryItem[1])));
|
labelItem.setIcon(new ImageIcon(getClass().getResource("/flags/"+ countryItem[1] + ".png")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,19 +89,5 @@ public class Util {
|
||||||
throw new RuntimeException("Error invoking runnable in UI thread.", ex);
|
throw new RuntimeException("Error invoking runnable in UI thread.", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] getIntArrayFromString(String stringData) {
|
|
||||||
int[] intArray = null;
|
|
||||||
if (stringData != null && !stringData.isEmpty()) {
|
|
||||||
String[] items = stringData.split(",");
|
|
||||||
int lengthW = items.length;
|
|
||||||
intArray = new int[lengthW];
|
|
||||||
for (int i = 0; i < lengthW; i++) {
|
|
||||||
try {
|
|
||||||
intArray[i] = Integer.parseInt(items[i]);
|
|
||||||
} catch (NumberFormatException nfe) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return intArray;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue