mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 21:12:04 -08:00
Added country name to tooltip of country icon in user list.
This commit is contained in:
parent
b3fdc167a8
commit
0f37d0fcd0
3 changed files with 95 additions and 35 deletions
|
|
@ -96,7 +96,7 @@
|
|||
<Component class="javax.swing.JTable" name="jTablePlayers">
|
||||
<Properties>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||
<Connection code="this.tableModel" type="code"/>
|
||||
<Connection code="this.userTableModel" type="code"/>
|
||||
</Property>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Connected players"/>
|
||||
<Property name="autoscrolls" type="boolean" value="false"/>
|
||||
|
|
|
|||
|
|
@ -37,31 +37,25 @@ 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.client.util.gui.countryBox.CountryCellRenderer;
|
||||
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;
|
||||
|
||||
/**
|
||||
|
|
@ -69,13 +63,11 @@ import org.mage.card.arcane.ManaSymbols;
|
|||
* @author BetaSteward_at_googlemail.com, nantuko
|
||||
*/
|
||||
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<>();
|
||||
private final TableModel tableModel;
|
||||
private final UserTableModel userTableModel;
|
||||
/**
|
||||
* Chat message color for opponents.
|
||||
*/
|
||||
|
|
@ -153,14 +145,15 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
* @param addPlayersTab
|
||||
*/
|
||||
public ChatPanel(boolean addPlayersTab) {
|
||||
tableModel = new TableModel();
|
||||
userTableModel = new UserTableModel();
|
||||
initComponents();
|
||||
setBackground(new Color(0, 0, 0, ALPHA));
|
||||
jTablePlayers.setBackground(new Color(0, 0, 0, ALPHA));
|
||||
jTablePlayers.setForeground(Color.white);
|
||||
jTablePlayers.setRowSorter(new MageTableRowSorter(tableModel));
|
||||
|
||||
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));
|
||||
|
|
@ -331,13 +324,10 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
return this.jSplitPane1.getDividerLocation();
|
||||
}
|
||||
|
||||
class TableModel extends AbstractTableModel {
|
||||
|
||||
|
||||
|
||||
class UserTableModel 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();
|
||||
|
|
@ -368,7 +358,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
public Object getValueAt(int arg0, int arg1) {
|
||||
switch (arg1) {
|
||||
case 0:
|
||||
return getCountryFlagIcon(players[arg0].getFlagName());
|
||||
return players[arg0].getFlagName();
|
||||
case 1:
|
||||
return players[arg0].getUserName();
|
||||
case 2:
|
||||
|
|
@ -407,18 +397,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -460,7 +439,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
|
||||
jScrollPanePlayers.setBorder(null);
|
||||
|
||||
jTablePlayers.setModel(this.tableModel);
|
||||
jTablePlayers.setModel(this.userTableModel);
|
||||
jTablePlayers.setToolTipText("Connected players");
|
||||
jTablePlayers.setAutoscrolls(false);
|
||||
jTablePlayers.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
|
||||
|
|
@ -528,7 +507,7 @@ public class ChatPanel extends javax.swing.JPanel {
|
|||
|
||||
public void setRoomUserInfo(List<Collection<RoomUsersView>> view) {
|
||||
try {
|
||||
tableModel.loadData(view.get(0));
|
||||
userTableModel.loadData(view.get(0));
|
||||
} catch (Exception ex) {
|
||||
this.players.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
/*
|
||||
* 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.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 mage.client.chat.ChatPanel;
|
||||
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(column == 0) {
|
||||
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 +".png"));
|
||||
if (flagIcon.getImage() == null) {
|
||||
logger.warn("Country flag resource not found: " + countryCode);
|
||||
} else {
|
||||
flagIconCache.put(countryCode, flagIcon);
|
||||
}
|
||||
}
|
||||
return flagIcon;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue