View Javadoc
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  	private JLabel jLabel = null;
77  	private JLabel jLabelIcon0 = null;
78  	private JLabel jLabelIcon1 = null;
79  	private	ImageIcon	warningIcon = new ImageIcon(getClass().getResource("/g/caution.png"));
80  	private	ImageIcon	docWarnIcon = new ImageIcon(getClass().getResource("/g/docwarn.png"));
81  	private JLabel jLabelIconInvite = null;
82  
83  	/**
84  	 * This method initializes 
85  	 * 
86  	 */
87  	public PlayerNameRenderer() {
88  		super();
89  		initialize();
90  	}
91  
92  	/**
93  	 * This method initializes this
94  	 * 
95  	 */
96  	private void initialize() {
97          GridBagConstraints gridBagConstraints11 = new GridBagConstraints();
98          gridBagConstraints11.gridx = 3;
99          gridBagConstraints11.gridy = 0;
100         jLabelIconInvite = new JLabel();
101         jLabelIconInvite.setIcon(new ImageIcon(getClass().getResource("/g/left.png")));
102         GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
103         gridBagConstraints2.insets = new Insets(0, 0, 0, 0);
104         gridBagConstraints2.gridx = 1;
105         gridBagConstraints2.gridy = 0;
106         gridBagConstraints2.anchor = GridBagConstraints.EAST;
107         gridBagConstraints2.weightx = 0.2;
108         gridBagConstraints2.gridheight = 1;
109         GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
110         gridBagConstraints1.insets = new Insets(0, 0, 0, 0);
111         gridBagConstraints1.gridx = 2;
112         gridBagConstraints1.gridy = 0;
113         gridBagConstraints1.anchor = GridBagConstraints.EAST;
114         gridBagConstraints1.weightx = 0.2;
115         gridBagConstraints1.gridheight = 1;
116         GridBagConstraints gridBagConstraints = new GridBagConstraints();
117         gridBagConstraints.insets = new Insets(0, 0, 0, 0);
118         gridBagConstraints.gridx = 0;
119         gridBagConstraints.gridy = 0;
120         gridBagConstraints.anchor = GridBagConstraints.WEST;
121         gridBagConstraints.weightx = 0.2;
122         gridBagConstraints.gridheight = 1;
123         jLabelIcon0 = new JLabel();
124 		jLabelIcon0.setIcon(warningIcon);
125         jLabelIcon1 = new JLabel();
126 		jLabelIcon1.setIcon(docWarnIcon);
127 //        jLabelIcon.setText("");
128         jLabel = new JLabel();
129         jLabel.setText("JLabel");
130         jLabel.setFont(new Font("Dialog", Font.PLAIN, 12));
131         this.setLayout(new GridBagLayout());
132         this.setSize(new Dimension(79, 22));
133         this.add(jLabel, gridBagConstraints);
134         this.add(jLabelIcon0, gridBagConstraints1);
135         this.add(jLabelIcon1, gridBagConstraints2);
136         this.add(jLabelIconInvite, gridBagConstraints11);
137 			
138 	}
139 
140 	public void setSelectedBackground(Color color) {
141 		selectedBackgroundColor = color;
142 	}
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 		Player p = (Player)value;
151 		this.setOpaque(true);
152 		this.jLabel.setOpaque(true);
153 		if (isSelected) {
154 			this.setBackground(selectedBackgroundColor);
155 			this.jLabel.setBackground(selectedBackgroundColor);
156 		} else {
157 			this.setBackground(Color.white);
158 			this.jLabel.setBackground(Color.white);
159 		}
160 		if (p == null) {
161 			System.out.println("getTableCellRendererComponent player = null");
162 			return(this);
163 		}
164 		this.jLabel.setText(p.getName());
165 		this.jLabel.setOpaque(true);
166 		String tt = "";
167 		if (p.getBfStatus() != null && p.getBfStatus().length() > 0) {
168 			this.jLabelIcon0.setVisible(true);
169 			tt += p.getBfStatus();
170 		} else {
171 			this.jLabelIcon0.setVisible(false);
172 			//this.setToolTipText(null);
173 		}
174 		if (p.getMissManners() != null) {
175 			this.jLabelIcon0.setVisible(true);
176 			//this.setToolTipText(p.getMissManners());
177 			if (tt.length() > 0)
178 				tt += "\r\n";
179 			tt += p.getMissManners();
180 		} else {
181 			this.jLabelIcon0.setVisible(false);
182 			//this.setToolTipText(null);
183 		}
184 		if (p.getSavedMatch() != null) {
185 			this.jLabelIcon1.setVisible(true);
186 			//this.setToolTipText(p.getSavedMatch());
187 			if (tt.length() > 0)
188 				tt += "\r\n";
189 			tt += p.getSavedMatch();
190 		} else {
191 			this.jLabelIcon1.setVisible(false);
192 			//this.setToolTipText(null);
193 		}
194 		this.jLabelIconInvite.setVisible(p.isInvited());
195 		this.setToolTipText(tt.length() > 1 ? tt : null);
196 		return this;
197 	}
198 
199 }  //  @jve:decl-index=0:visual-constraint="10,10"