Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
PlayerNameRenderer |
|
| 3.5;3.5 |
1 | /****************************************************************************** | |
2 | * PlayerNameRenderer.java - Draw the player name and any icons in the player table | |
3 | * $Id$ | |
4 | * | |
5 | * BuckoFIBS - Backgammon by BuckoSoft | |
6 | * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp. | |
7 | * | |
8 | * $Log$ | |
9 | * Revision 1.2 2010/03/03 12:19:49 inim | |
10 | * Moved source to UTF8 encoding from CP1252 encoding. To this end all source files' (c) message was updated to "Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.". This replaces the (c) sign to UTF8, and adds the new year 2010. | |
11 | * | |
12 | * Revision 1.1 2010/02/04 05:57:53 inim | |
13 | * Mavenized project folder layout | |
14 | * | |
15 | * Revision 1.5 2010/01/23 06:26:29 dick | |
16 | * Add the YouInvited icon. | |
17 | * | |
18 | * Revision 1.4 2009/03/04 19:03:38 dick | |
19 | * With the new Java 1.6 row filtering, sometimes we get requests for bad rows, don't react to them. | |
20 | * | |
21 | * Revision 1.3 2009/02/14 15:46:36 dick | |
22 | * BuckoFIBS is released under the GNU license. | |
23 | * | |
24 | * Revision 1.2 2009/02/01 21:29:48 dick | |
25 | * Draw MissManners and SavedGames tooltips. | |
26 | * | |
27 | * Revision 1.1 2009/02/01 09:01:01 dick | |
28 | * Draw the player name and any icons in the player table. | |
29 | */ | |
30 | ||
31 | /* | |
32 | * This program is free software: you can redistribute it and/or modify | |
33 | * it under the terms of the GNU General Public License as published by | |
34 | * the Free Software Foundation, either version 3 of the License, or | |
35 | * (at your option) any later version. | |
36 | * | |
37 | * This program is distributed in the hope that it will be useful, | |
38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
40 | * GNU General Public License for more details. | |
41 | * | |
42 | * You should have received a copy of the GNU General Public License | |
43 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
44 | * | |
45 | * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>. | |
46 | * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp. | |
47 | * | |
48 | */ | |
49 | package com.buckosoft.fibs.BuckoFIBS.gui.playerList; | |
50 | ||
51 | import java.awt.Color; | |
52 | import java.awt.Component; | |
53 | import java.awt.Dimension; | |
54 | import java.awt.GridBagConstraints; | |
55 | import java.awt.GridBagLayout; | |
56 | import java.awt.Insets; | |
57 | ||
58 | import javax.swing.ImageIcon; | |
59 | import javax.swing.JLabel; | |
60 | import javax.swing.JPanel; | |
61 | import javax.swing.JTable; | |
62 | import javax.swing.table.TableCellRenderer; | |
63 | ||
64 | import com.buckosoft.fibs.domain.Player; | |
65 | import java.awt.Font; | |
66 | ||
67 | /** Draw the player name and any icons in the player table | |
68 | * @author Dick Balaska | |
69 | * @since 2009/02/01 | |
70 | * @version $Revision$ <br> $Date$ | |
71 | * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/inviterList/PlayerNameRenderer.java">cvs PlayerNameRenderer.java</a> | |
72 | */ | |
73 | public class PlayerNameRenderer extends JPanel implements TableCellRenderer { | |
74 | private static final long serialVersionUID = 1L; | |
75 | private Color selectedBackgroundColor; // @jve:decl-index=0: | |
76 | 0 | private JLabel jLabel = null; |
77 | 0 | private JLabel jLabelIcon0 = null; |
78 | 0 | private JLabel jLabelIcon1 = null; |
79 | 0 | private ImageIcon warningIcon = new ImageIcon(getClass().getResource("/g/caution.png")); |
80 | 0 | private ImageIcon docWarnIcon = new ImageIcon(getClass().getResource("/g/docwarn.png")); |
81 | 0 | private JLabel jLabelIconInvite = null; |
82 | ||
83 | /** | |
84 | * This method initializes | |
85 | * | |
86 | */ | |
87 | public PlayerNameRenderer() { | |
88 | 0 | super(); |
89 | 0 | initialize(); |
90 | 0 | } |
91 | ||
92 | /** | |
93 | * This method initializes this | |
94 | * | |
95 | */ | |
96 | private void initialize() { | |
97 | 0 | GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
98 | 0 | gridBagConstraints11.gridx = 3; |
99 | 0 | gridBagConstraints11.gridy = 0; |
100 | 0 | jLabelIconInvite = new JLabel(); |
101 | 0 | jLabelIconInvite.setIcon(new ImageIcon(getClass().getResource("/g/left.png"))); |
102 | 0 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
103 | 0 | gridBagConstraints2.insets = new Insets(0, 0, 0, 0); |
104 | 0 | gridBagConstraints2.gridx = 1; |
105 | 0 | gridBagConstraints2.gridy = 0; |
106 | 0 | gridBagConstraints2.anchor = GridBagConstraints.EAST; |
107 | 0 | gridBagConstraints2.weightx = 0.2; |
108 | 0 | gridBagConstraints2.gridheight = 1; |
109 | 0 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
110 | 0 | gridBagConstraints1.insets = new Insets(0, 0, 0, 0); |
111 | 0 | gridBagConstraints1.gridx = 2; |
112 | 0 | gridBagConstraints1.gridy = 0; |
113 | 0 | gridBagConstraints1.anchor = GridBagConstraints.EAST; |
114 | 0 | gridBagConstraints1.weightx = 0.2; |
115 | 0 | gridBagConstraints1.gridheight = 1; |
116 | 0 | GridBagConstraints gridBagConstraints = new GridBagConstraints(); |
117 | 0 | gridBagConstraints.insets = new Insets(0, 0, 0, 0); |
118 | 0 | gridBagConstraints.gridx = 0; |
119 | 0 | gridBagConstraints.gridy = 0; |
120 | 0 | gridBagConstraints.anchor = GridBagConstraints.WEST; |
121 | 0 | gridBagConstraints.weightx = 0.2; |
122 | 0 | gridBagConstraints.gridheight = 1; |
123 | 0 | jLabelIcon0 = new JLabel(); |
124 | 0 | jLabelIcon0.setIcon(warningIcon); |
125 | 0 | jLabelIcon1 = new JLabel(); |
126 | 0 | jLabelIcon1.setIcon(docWarnIcon); |
127 | // jLabelIcon.setText(""); | |
128 | 0 | jLabel = new JLabel(); |
129 | 0 | jLabel.setText("JLabel"); |
130 | 0 | jLabel.setFont(new Font("Dialog", Font.PLAIN, 12)); |
131 | 0 | this.setLayout(new GridBagLayout()); |
132 | 0 | this.setSize(new Dimension(79, 22)); |
133 | 0 | this.add(jLabel, gridBagConstraints); |
134 | 0 | this.add(jLabelIcon0, gridBagConstraints1); |
135 | 0 | this.add(jLabelIcon1, gridBagConstraints2); |
136 | 0 | this.add(jLabelIconInvite, gridBagConstraints11); |
137 | ||
138 | 0 | } |
139 | ||
140 | public void setSelectedBackground(Color color) { | |
141 | 0 | selectedBackgroundColor = color; |
142 | 0 | } |
143 | ||
144 | /* (non-Javadoc) | |
145 | * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int) | |
146 | */ | |
147 | @Override | |
148 | public Component getTableCellRendererComponent(JTable table, Object value, | |
149 | boolean isSelected, boolean hasFocus, int row, int column) { | |
150 | 0 | Player p = (Player)value; |
151 | 0 | this.setOpaque(true); |
152 | 0 | this.jLabel.setOpaque(true); |
153 | 0 | if (isSelected) { |
154 | 0 | this.setBackground(selectedBackgroundColor); |
155 | 0 | this.jLabel.setBackground(selectedBackgroundColor); |
156 | } else { | |
157 | 0 | this.setBackground(Color.white); |
158 | 0 | this.jLabel.setBackground(Color.white); |
159 | } | |
160 | 0 | if (p == null) { |
161 | 0 | System.out.println("getTableCellRendererComponent player = null"); |
162 | 0 | return(this); |
163 | } | |
164 | 0 | this.jLabel.setText(p.getName()); |
165 | 0 | this.jLabel.setOpaque(true); |
166 | 0 | String tt = ""; |
167 | 0 | if (p.getBfStatus() != null && p.getBfStatus().length() > 0) { |
168 | 0 | this.jLabelIcon0.setVisible(true); |
169 | 0 | tt += p.getBfStatus(); |
170 | } else { | |
171 | 0 | this.jLabelIcon0.setVisible(false); |
172 | //this.setToolTipText(null); | |
173 | } | |
174 | 0 | if (p.getMissManners() != null) { |
175 | 0 | this.jLabelIcon0.setVisible(true); |
176 | //this.setToolTipText(p.getMissManners()); | |
177 | 0 | if (tt.length() > 0) |
178 | 0 | tt += "\r\n"; |
179 | 0 | tt += p.getMissManners(); |
180 | } else { | |
181 | 0 | this.jLabelIcon0.setVisible(false); |
182 | //this.setToolTipText(null); | |
183 | } | |
184 | 0 | if (p.getSavedMatch() != null) { |
185 | 0 | this.jLabelIcon1.setVisible(true); |
186 | //this.setToolTipText(p.getSavedMatch()); | |
187 | 0 | if (tt.length() > 0) |
188 | 0 | tt += "\r\n"; |
189 | 0 | tt += p.getSavedMatch(); |
190 | } else { | |
191 | 0 | this.jLabelIcon1.setVisible(false); |
192 | //this.setToolTipText(null); | |
193 | } | |
194 | 0 | this.jLabelIconInvite.setVisible(p.isInvited()); |
195 | 0 | this.setToolTipText(tt.length() > 1 ? tt : null); |
196 | 0 | return this; |
197 | } | |
198 | ||
199 | } // @jve:decl-index=0:visual-constraint="10,10" |