Show country flag icon in user table. Save and restore column width and order.

This commit is contained in:
LevelX2 2015-06-11 00:11:40 +02:00
parent 8ae9293c98
commit 132ded19f6
8 changed files with 418 additions and 320 deletions

View file

@ -37,20 +37,31 @@ import java.awt.Color;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
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.gui.TableUtil;
import mage.remote.MageRemoteException;
import mage.remote.Session;
import mage.view.ChatMessage.MessageColor;
import mage.view.ChatMessage.MessageType;
import mage.view.RoomUsersView;
import mage.view.UsersView;
import org.apache.log4j.Logger;
import org.mage.card.arcane.ManaSymbols;
/**
@ -59,6 +70,8 @@ import org.mage.card.arcane.ManaSymbols;
*/
public class ChatPanel extends javax.swing.JPanel {
private static final Logger logger = Logger.getLogger(ChatPanel.class);
private UUID chatId;
private Session session;
private final List<String> players = new ArrayList<>();
@ -117,6 +130,8 @@ 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
@ -144,6 +159,9 @@ public class ChatPanel extends javax.swing.JPanel {
jTablePlayers.setBackground(new Color(0, 0, 0, ALPHA));
jTablePlayers.setForeground(Color.white);
jTablePlayers.setRowSorter(new MageTableRowSorter(tableModel));
TableUtil.setColumnWidthAndOrder(jTablePlayers, defaultColumnsWidth, KEY_USERS_COLUMNS_WIDTH, KEY_USERS_COLUMNS_ORDER);
if (jScrollPaneTxt != null) {
jScrollPaneTxt.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() {
return chatType;
}
@ -311,8 +333,11 @@ public class ChatPanel extends javax.swing.JPanel {
class TableModel extends AbstractTableModel {
private final String[] columnNames = new String[]{" ","Players", "Info", "Games", "Connection"};
private UsersView[] players = new UsersView[0];
private Map<String, ImageIcon> flagIconCache = new HashMap<>();
public void loadData(Collection<RoomUsersView> roomUserInfoList) throws MageRemoteException {
RoomUsersView roomUserInfo = roomUserInfoList.iterator().next();
@ -343,7 +368,7 @@ public class ChatPanel extends javax.swing.JPanel {
public Object getValueAt(int arg0, int arg1) {
switch (arg1) {
case 0:
return players[arg0].getFlagName();
return getCountryFlagIcon(players[arg0].getFlagName());
case 1:
return players[arg0].getUserName();
case 2:
@ -369,13 +394,32 @@ public class ChatPanel extends javax.swing.JPanel {
@Override
public Class getColumnClass(int columnIndex) {
return String.class;
switch (columnIndex) {
case 0:
return Icon.class;
default:
return String.class;
}
}
@Override
public boolean isCellEditable(int rowIndex, int columnIndex) {
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() {

View file

@ -65,6 +65,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_AUTO_CONNECT;
import static mage.client.dialog.PreferencesDialog.KEY_CONNECT_FLAG;
import mage.client.util.gui.countryBox.CountryItemEditor;
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.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
for (int i = 0; i < cbFlag.getItemCount(); 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
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()) {
task.cancel(true);
} else {
@ -328,7 +329,7 @@ public class ConnectDialog extends MageDialog {
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
connection.setUsername(this.txtUserName.getText().trim());
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"));

View file

@ -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_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_1 = "gamepanelDividerLocation1";
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2";

View file

@ -64,12 +64,10 @@ import javax.swing.JInternalFrame;
import javax.swing.JLayeredPane;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JTable;
import javax.swing.JToggleButton;
import javax.swing.RowFilter;
import javax.swing.SwingWorker;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumn;
import mage.cards.decks.importer.DeckImporterUtil;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
@ -78,10 +76,13 @@ import mage.client.dialog.JoinTableDialog;
import mage.client.dialog.NewTableDialog;
import mage.client.dialog.NewTournamentDialog;
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.util.ButtonColumn;
import mage.client.util.MageTableRowSorter;
import mage.client.util.gui.GuiDisplayUtil;
import mage.client.util.gui.TableUtil;
import mage.constants.MatchTimeLimit;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
@ -93,7 +94,6 @@ import mage.view.MatchView;
import mage.view.RoomUsersView;
import mage.view.TableView;
import org.apache.log4j.Logger;
import org.mage.card.arcane.Util;
/**
*
@ -120,6 +120,8 @@ public class TablesPanel extends javax.swing.JPanel {
JToggleButton[] filterButtons;
private static final int[] defaultColumnsWidth = {35, 150, 120, 180, 80, 120, 80, 60, 60};
/** Creates new form TablesPanel */
public TablesPanel() {
@ -135,7 +137,8 @@ public class TablesPanel extends javax.swing.JPanel {
activeTablesSorter = new MageTableRowSorter(tableModel);
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));
@ -276,6 +279,7 @@ public class TablesPanel extends javax.swing.JPanel {
public void cleanUp() {
saveSettings();
chatPanel.cleanUp();
}
private void saveDividerLocations() {
@ -311,23 +315,7 @@ public class TablesPanel extends javax.swing.JPanel {
}
PreferencesDialog.saveValue(PreferencesDialog.KEY_TABLES_FILTER_SETTINGS, formatSettings.toString());
// Column width
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());
TableUtil.saveColumnWidthAndOrderToPrefs(tableTables, KEY_TABLES_COLUMNS_WIDTH, KEY_TABLES_COLUMNS_ORDER);
}
private void restoreDividerLocations() {
@ -1157,6 +1145,7 @@ public class TablesPanel extends javax.swing.JPanel {
options.setWinsNeeded(1);
options.setMatchTimeLimit(MatchTimeLimit.NONE);
options.setFreeMulligans(2);
options.setSkillLevel(SkillLevel.CASUAL);
table = session.createTable(roomId, options);
session.joinTable(roomId, table.getTableId(), "Human", "Human", 1, DeckImporterUtil.importDeck("test.dck"),"");
@ -1262,7 +1251,6 @@ class TableTableModel extends AbstractTableModel {
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 static final int[] defaultColumnsWidth = {35, 150, 120, 180, 80, 120, 80, 60, 60};
private TableView[] tables = new TableView[0];
private static final DateFormat timeFormatter = new SimpleDateFormat("HH:mm:ss");;
@ -1274,31 +1262,6 @@ class TableTableModel extends AbstractTableModel {
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
public int getRowCount() {
return tables.length;

View file

@ -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;
}
}

View file

@ -40,252 +40,252 @@ public class CountryComboBox extends JComboBox {
private final DefaultComboBoxModel model;
public static String[][] countryList = {
{"Afghanistan", "af.png"},
{"Åland Islands", "ax.png"},
{"Albania", "al.png"},
{"Algeria", "dz.png"},
{"American Samoa", "as.png"},
{"Andorra", "ad.png"},
{"Angola", "an.png"},
{"Anguilla", "ai.png"},
{"Antarctica", "ao.png"},
{"Antigua and Barbuda", "ag.png"},
{"Argentina", "ar.png"},
{"Armenia", "am.png"},
{"Aruba", "aw.png"},
{"Australia", "au.png"},
{"Austria", "at.png"},
{"Azerbaijan", "az.png"},
{"Bahamas", "bs.png"},
{"Bahrain", "bh.png"},
{"Bangladesh", "bd.png"},
{"Barbados", "bb.png"},
{"Belarus", "by.png"},
{"Belgium", "be.png"},
{"Belize", "bz.png"},
{"Benin", "bj.png"},
{"Bermuda", "bm.png"},
{"Bhutan", "bt.png"},
{"Bolivia, Plurinational State of", "bo.png"},
{"Bosnia and Herzegovina", "ba.png"},
{"Botswana", "bw.png"},
{"Bouvet Island", "bv.png"},
{"Brazil", "br.png"},
{"British Indian Ocean Territory", "io.png"},
{"Brunei Darussalam", "bn.png"},
{"Bulgaria", "bg.png"},
{"Burkina Faso", "bf.png"},
{"Burundi", "bi.png"},
{"Cabo Verde", "cv.png"},
{"Cambodia", "kh.png"},
{"Cameroon", "cm.png"},
{"Canada", "ca.png"},
{"Catalonia", "catalonia.png"},
{"Cayman Islands", "ky.png"},
{"Central African Republic", "cf.png"},
{"Chad", "td.png"},
{"Chile", "cl.png"},
{"China", "cn.png"},
{"Christmas Island", "cx.png"},
{"Cocos (Keeling) Islands", "cc.png"},
{"Colombia", "co.png"},
{"Comoros", "km.png"},
{"Congo", "cg.png"},
{"Congo, the Democratic Republic of the", "cd.png"},
{"Cook Islands", "ck.png"},
{"Costa Rica", "cr.png"},
{"Côte d'Ivoire", "ci.png"},
{"Croatia", "hr.png"},
{"Cuba", "cu.png"},
{"Cyprus", "cy.png"},
{"Czech Republic", "cz.png"},
{"Denmark", "dk.png"},
{"Djibouti", "dj.png"},
{"Dominica", "dm.png"},
{"Dominican Republic", "do.png"},
{"Ecuador", "ec.png"},
{"Egypt", "eg.png"},
{"El Salvador", "sv.png"},
{"England", "england.png"},
{"Equatorial Guinea", "gq.png"},
{"Eritrea", "er.png"},
{"Estonia", "ee.png"},
{"Ethiopia", "et.png"},
{"European Union", "europeanunion.png"},
{"Falkland Islands (Malvinas)", "fk.png"},
{"Faroe Islands", "fo.png"},
{"Fiji", "fj.png"},
{"Finland", "fi.png"},
{"France", "fr.png"},
{"French Guiana", "gf.png"},
{"French Polynesia", "pf.png"},
{"French Southern Territories", "tf.png"},
{"Gabon", "ga.png"},
{"Gambia", "gm.png"},
{"Georgia", "ge.png"},
{"Germany", "de.png"},
{"Ghana", "gh.png"},
{"Gibraltar", "gi.png"},
{"Greece", "gr.png"},
{"Greenland", "gl.png"},
{"Grenada", "gd.png"},
{"Guadeloupe", "gp.png"},
{"Guam", "gu.png"},
{"Guatemala", "gt.png"},
{"Guinea", "gn.png"},
{"Guinea-Bissau", "gw.png"},
{"Guyana", "gy.png"},
{"Haiti", "ht.png"},
{"Heard Island and McDonald Islands", "hm.png"},
{"Holy See", "va.png"},
{"Honduras", "hn.png"},
{"Hong Kong", "hk.png"},
{"Hungary", "hu.png"},
{"Iceland", "is.png"},
{"India", "in.png"},
{"Indonesia", "id.png"},
{"Iran, Islamic Republic of", "ir.png"},
{"Iraq", "iq.png"},
{"Ireland", "ie.png"},
{"Israel", "il.png"},
{"Italy", "it.png"},
{"Jamaica", "jm.png"},
{"Japan", "jp.png"},
{"Jordan", "jo.png"},
{"Kazakhstan", "kz.png"},
{"Kenya", "ke.png"},
{"Kiribati", "ki.png"},
{"Korea, Democratic People's Republic of", "kp.png"},
{"Korea, Republic of", "kr.png"},
{"Kuwait", "kw.png"},
{"Kyrgyzstan", "kg.png"},
{"Lao People's Democratic Republic", "la.png"},
{"Latvia", "lv.png"},
{"Lebanon", "lb.png"},
{"Lesotho", "ls.png"},
{"Liberia", "lr.png"},
{"Libya", "ly.png"},
{"Liechtenstein", "li.png"},
{"Lithuania", "lt.png"},
{"Luxembourg", "lu.png"},
{"Macao", "mo.png"},
{"Macedonia, the former Yugoslav Republic of", "mk.png"},
{"Madagascar", "mg.png"},
{"Malawi", "mw.png"},
{"Malaysia", "my.png"},
{"Maldives", "mv.png"},
{"Mali", "ml.png"},
{"Malta", "mt.png"},
{"Marshall Islands", "mh.png"},
{"Martinique", "mq.png"},
{"Mauritania", "mr.png"},
{"Mauritius", "mu.png"},
{"Mayotte", "yt.png"},
{"Mexico", "mx.png"},
{"Micronesia, Federated States of", "fm.png"},
{"Moldova, Republic of", "md.png"},
{"Monaco", "mc.png"},
{"Mongolia", "mn.png"},
{"Montenegro", "me.png"},
{"Montserrat", "ms.png"},
{"Morocco", "ma.png"},
{"Mozambique", "mz.png"},
{"Myanmar", "mm.png"},
{"Namibia", "na.png"},
{"Nauru", "nr.png"},
{"Nepal", "np.png"},
{"Netherlands", "nl.png"},
{"New Caledonia", "nc.png"},
{"New Zealand", "nz.png"},
{"Nicaragua", "ni.png"},
{"Niger", "ne.png"},
{"Nigeria", "ng.png"},
{"Niue", "nu.png"},
{"Norfolk Island", "nf.png"},
{"Northern Mariana Islands", "mp.png"},
{"Norway", "no.png"},
{"Oman", "om.png"},
{"Pakistan", "pk.png"},
{"Palau", "pw.png"},
{"Palestine, State of", "ps.png"},
{"Panama", "pa.png"},
{"Papua New Guinea", "pg.png"},
{"Paraguay", "py.png"},
{"Peru", "pe.png"},
{"Philippines", "ph.png"},
{"Pitcairn", "pn.png"},
{"Poland", "pl.png"},
{"Portugal", "pt.png"},
{"Puerto Rico", "pr.png"},
{"Qatar", "qa.png"},
{"Réunion", "re.png"},
{"Romania", "ro.png"},
{"Russian Federation", "ru.png"},
{"Rwanda", "rw.png"},
{"Saint Helena, Ascension and Tristan da Cunha", "sh.png"},
{"Saint Kitts and Nevis", "kn.png"},
{"Saint Lucia", "lc.png"},
{"Saint Pierre and Miquelon", "pm.png"},
{"Saint Vincent and the Grenadines", "vc.png"},
{"Samoa", "ws.png"},
{"San Marino", "sm.png"},
{"Sao Tome and Principe", "st.png"},
{"Saudi Arabia", "sa.png"},
{"Scotland", "scotland.png"},
{"Senegal", "sn.png"},
{"Serbia", "rs.png"},
{"Seychelles", "sc.png"},
{"Sierra Leone", "sl.png"},
{"Singapore", "sg.png"},
{"Slovakia", "sk.png"},
{"Slovenia", "si.png"},
{"Solomon Islands", "sb.png"},
{"Somalia", "so.png"},
{"South Africa", "za.png"},
{"South Georgia and the South Sandwich Islands", "gs.png"},
{"Spain", "es.png"},
{"Sri Lanka", "lk.png"},
{"Sudan", "sd.png"},
{"Suriname", "sr.png"},
{"Svalbard and Jan Mayen", "sj.png"},
{"Swaziland", "sz.png"},
{"Sweden", "se.png"},
{"Switzerland", "ch.png"},
{"Syrian Arab Republic", "sy.png"},
{"Taiwan, Province of China", "tw.png"},
{"Tajikistan", "tj.png"},
{"Tanzania, United Republic of", "tz.png"},
{"Thailand", "th.png"},
{"Timor-Leste", "tl.png"},
{"Togo", "tg.png"},
{"Tokelau", "tk.png"},
{"Tonga", "to.png"},
{"Trinidad and Tobago", "tt.png"},
{"Tunisia", "tn.png"},
{"Turkey", "tr.png"},
{"Turkmenistan", "tm.png"},
{"Turks and Caicos Islands", "tc.png"},
{"Tuvalu", "tv.png"},
{"Uganda", "ug.png"},
{"Ukraine", "ua.png"},
{"United Arab Emirates", "ae.png"},
{"United Kingdom of Great Britain and Northern Ireland", "gb.png"},
{"United States Minor Outlying Islands", "um.png"},
{"United States of America", "us.png"},
{"Uruguay", "uy.png"},
{"Uzbekistan", "uz.png"},
{"Vanuatu", "vu.png"},
{"Venezuela, Bolivarian Republic of", "ve.png"},
{"Viet Nam", "vn.png"},
{"Virgin Islands, British", "vg.png"},
{"Virgin Islands, U.S.", "vi.png"},
{"Wales", "wales.png"},
{"Wallis and Futuna", "wf.png"},
{"World", "world.png"},
{"Western Sahara", "eh.png"},
{"Yemen", "ye.png"},
{"Zambia", "zm.png"},
{"Zimbabwe", "zw.png"},
{"Afghanistan", "af"},
{"Åland Islands", "ax"},
{"Albania", "al"},
{"Algeria", "dz"},
{"American Samoa", "as"},
{"Andorra", "ad"},
{"Angola", "an"},
{"Anguilla", "ai"},
{"Antarctica", "ao"},
{"Antigua and Barbuda", "ag"},
{"Argentina", "ar"},
{"Armenia", "am"},
{"Aruba", "aw"},
{"Australia", "au"},
{"Austria", "at"},
{"Azerbaijan", "az"},
{"Bahamas", "bs"},
{"Bahrain", "bh"},
{"Bangladesh", "bd"},
{"Barbados", "bb"},
{"Belarus", "by"},
{"Belgium", "be"},
{"Belize", "bz"},
{"Benin", "bj"},
{"Bermuda", "bm"},
{"Bhutan", "bt"},
{"Bolivia, Plurinational State of", "bo"},
{"Bosnia and Herzegovina", "ba"},
{"Botswana", "bw"},
{"Bouvet Island", "bv"},
{"Brazil", "br"},
{"British Indian Ocean Territory", "io"},
{"Brunei Darussalam", "bn"},
{"Bulgaria", "bg"},
{"Burkina Faso", "bf"},
{"Burundi", "bi"},
{"Cabo Verde", "cv"},
{"Cambodia", "kh"},
{"Cameroon", "cm"},
{"Canada", "ca"},
{"Catalonia", "catalonia"},
{"Cayman Islands", "ky"},
{"Central African Republic", "cf"},
{"Chad", "td"},
{"Chile", "cl"},
{"China", "cn"},
{"Christmas Island", "cx"},
{"Cocos (Keeling) Islands", "cc"},
{"Colombia", "co"},
{"Comoros", "km"},
{"Congo", "cg"},
{"Congo, the Democratic Republic of the", "cd"},
{"Cook Islands", "ck"},
{"Costa Rica", "cr"},
{"Côte d'Ivoire", "ci"},
{"Croatia", "hr"},
{"Cuba", "cu"},
{"Cyprus", "cy"},
{"Czech Republic", "cz"},
{"Denmark", "dk"},
{"Djibouti", "dj"},
{"Dominica", "dm"},
{"Dominican Republic", "do"},
{"Ecuador", "ec"},
{"Egypt", "eg"},
{"El Salvador", "sv"},
{"England", "england"},
{"Equatorial Guinea", "gq"},
{"Eritrea", "er"},
{"Estonia", "ee"},
{"Ethiopia", "et"},
{"European Union", "europeanunion"},
{"Falkland Islands (Malvinas)", "fk"},
{"Faroe Islands", "fo"},
{"Fiji", "fj"},
{"Finland", "fi"},
{"France", "fr"},
{"French Guiana", "gf"},
{"French Polynesia", "pf"},
{"French Southern Territories", "tf"},
{"Gabon", "ga"},
{"Gambia", "gm"},
{"Georgia", "ge"},
{"Germany", "de"},
{"Ghana", "gh"},
{"Gibraltar", "gi"},
{"Greece", "gr"},
{"Greenland", "gl"},
{"Grenada", "gd"},
{"Guadeloupe", "gp"},
{"Guam", "gu"},
{"Guatemala", "gt"},
{"Guinea", "gn"},
{"Guinea-Bissau", "gw"},
{"Guyana", "gy"},
{"Haiti", "ht"},
{"Heard Island and McDonald Islands", "hm"},
{"Holy See", "va"},
{"Honduras", "hn"},
{"Hong Kong", "hk"},
{"Hungary", "hu"},
{"Iceland", "is"},
{"India", "in"},
{"Indonesia", "id"},
{"Iran, Islamic Republic of", "ir"},
{"Iraq", "iq"},
{"Ireland", "ie"},
{"Israel", "il"},
{"Italy", "it"},
{"Jamaica", "jm"},
{"Japan", "jp"},
{"Jordan", "jo"},
{"Kazakhstan", "kz"},
{"Kenya", "ke"},
{"Kiribati", "ki"},
{"Korea, Democratic People's Republic of", "kp"},
{"Korea, Republic of", "kr"},
{"Kuwait", "kw"},
{"Kyrgyzstan", "kg"},
{"Lao People's Democratic Republic", "la"},
{"Latvia", "lv"},
{"Lebanon", "lb"},
{"Lesotho", "ls"},
{"Liberia", "lr"},
{"Libya", "ly"},
{"Liechtenstein", "li"},
{"Lithuania", "lt"},
{"Luxembourg", "lu"},
{"Macao", "mo"},
{"Macedonia, the former Yugoslav Republic of", "mk"},
{"Madagascar", "mg"},
{"Malawi", "mw"},
{"Malaysia", "my"},
{"Maldives", "mv"},
{"Mali", "ml"},
{"Malta", "mt"},
{"Marshall Islands", "mh"},
{"Martinique", "mq"},
{"Mauritania", "mr"},
{"Mauritius", "mu"},
{"Mayotte", "yt"},
{"Mexico", "mx"},
{"Micronesia, Federated States of", "fm"},
{"Moldova, Republic of", "md"},
{"Monaco", "mc"},
{"Mongolia", "mn"},
{"Montenegro", "me"},
{"Montserrat", "ms"},
{"Morocco", "ma"},
{"Mozambique", "mz"},
{"Myanmar", "mm"},
{"Namibia", "na"},
{"Nauru", "nr"},
{"Nepal", "np"},
{"Netherlands", "nl"},
{"New Caledonia", "nc"},
{"New Zealand", "nz"},
{"Nicaragua", "ni"},
{"Niger", "ne"},
{"Nigeria", "ng"},
{"Niue", "nu"},
{"Norfolk Island", "nf"},
{"Northern Mariana Islands", "mp"},
{"Norway", "no"},
{"Oman", "om"},
{"Pakistan", "pk"},
{"Palau", "pw"},
{"Palestine, State of", "ps"},
{"Panama", "pa"},
{"Papua New Guinea", "pg"},
{"Paraguay", "py"},
{"Peru", "pe"},
{"Philippines", "ph"},
{"Pitcairn", "pn"},
{"Poland", "pl"},
{"Portugal", "pt"},
{"Puerto Rico", "pr"},
{"Qatar", "qa"},
{"Réunion", "re"},
{"Romania", "ro"},
{"Russian Federation", "ru"},
{"Rwanda", "rw"},
{"Saint Helena, Ascension and Tristan da Cunha", "sh"},
{"Saint Kitts and Nevis", "kn"},
{"Saint Lucia", "lc"},
{"Saint Pierre and Miquelon", "pm"},
{"Saint Vincent and the Grenadines", "vc"},
{"Samoa", "ws"},
{"San Marino", "sm"},
{"Sao Tome and Principe", "st"},
{"Saudi Arabia", "sa"},
{"Scotland", "scotland"},
{"Senegal", "sn"},
{"Serbia", "rs"},
{"Seychelles", "sc"},
{"Sierra Leone", "sl"},
{"Singapore", "sg"},
{"Slovakia", "sk"},
{"Slovenia", "si"},
{"Solomon Islands", "sb"},
{"Somalia", "so"},
{"South Africa", "za"},
{"South Georgia and the South Sandwich Islands", "gs"},
{"Spain", "es"},
{"Sri Lanka", "lk"},
{"Sudan", "sd"},
{"Suriname", "sr"},
{"Svalbard and Jan Mayen", "sj"},
{"Swaziland", "sz"},
{"Sweden", "se"},
{"Switzerland", "ch"},
{"Syrian Arab Republic", "sy"},
{"Taiwan, Province of China", "tw"},
{"Tajikistan", "tj"},
{"Tanzania, United Republic of", "tz"},
{"Thailand", "th"},
{"Timor-Leste", "tl"},
{"Togo", "tg"},
{"Tokelau", "tk"},
{"Tonga", "to"},
{"Trinidad and Tobago", "tt"},
{"Tunisia", "tn"},
{"Turkey", "tr"},
{"Turkmenistan", "tm"},
{"Turks and Caicos Islands", "tc"},
{"Tuvalu", "tv"},
{"Uganda", "ug"},
{"Ukraine", "ua"},
{"United Arab Emirates", "ae"},
{"United Kingdom of Great Britain and Northern Ireland", "gb"},
{"United States Minor Outlying Islands", "um"},
{"United States of America", "us"},
{"Uruguay", "uy"},
{"Uzbekistan", "uz"},
{"Vanuatu", "vu"},
{"Venezuela, Bolivarian Republic of", "ve"},
{"Viet Nam", "vn"},
{"Virgin Islands, British", "vg"},
{"Virgin Islands, U.S.", "vi"},
{"Wales", "wales"},
{"Wallis and Futuna", "wf"},
{"World", "world"},
{"Western Sahara", "eh"},
{"Yemen", "ye"},
{"Zambia", "zm"},
{"Zimbabwe", "zw"},
};
@SuppressWarnings("unchecked")
@ -311,5 +311,10 @@ public class CountryComboBox extends JComboBox {
}
}
@Override
public Object getSelectedItem() {
return super.getSelectedItem(); //To change body of generated methods, choose Tools | Templates.
}
}

View file

@ -35,6 +35,7 @@ import java.awt.Insets;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.LineBorder;
import javax.swing.plaf.basic.BasicComboBoxEditor;
@ -47,20 +48,23 @@ public class CountryItemEditor extends BasicComboBoxEditor {
private final JPanel panel = new JPanel();
private final JLabel labelItem = new JLabel();
private String selectedValue;
private String selectedImage;
public CountryItemEditor() {
panel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
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.setHorizontalAlignment(JLabel.LEFT);
labelItem.setForeground(Color.WHITE);
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;
}
@ -74,6 +78,9 @@ public class CountryItemEditor extends BasicComboBoxEditor {
return this.selectedValue;
}
public String getImageItem() {
return this.selectedImage;
}
@Override
public void setItem(Object item) {
if (item == null || !(item instanceof String[])) {
@ -81,7 +88,8 @@ public class CountryItemEditor extends BasicComboBoxEditor {
}
String[] countryItem = (String[]) item;
selectedValue = countryItem[0];
selectedImage = countryItem[1];
labelItem.setText(selectedValue);
labelItem.setIcon(new ImageIcon(getClass().getResource("/flags/"+ countryItem[1])));
labelItem.setIcon(new ImageIcon(getClass().getResource("/flags/"+ countryItem[1] + ".png")));
}
}

View file

@ -90,18 +90,4 @@ public class Util {
}
}
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;
}
}