1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
68
69
70
71
72
73 public class PlayerNameRenderer extends JPanel implements TableCellRenderer {
74 private static final long serialVersionUID = 1L;
75 private Color selectedBackgroundColor;
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
85
86
87 public PlayerNameRenderer() {
88 super();
89 initialize();
90 }
91
92
93
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
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
145
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
173 }
174 if (p.getMissManners() != null) {
175 this.jLabelIcon0.setVisible(true);
176
177 if (tt.length() > 0)
178 tt += "\r\n";
179 tt += p.getMissManners();
180 } else {
181 this.jLabelIcon0.setVisible(false);
182
183 }
184 if (p.getSavedMatch() != null) {
185 this.jLabelIcon1.setVisible(true);
186
187 if (tt.length() > 0)
188 tt += "\r\n";
189 tt += p.getSavedMatch();
190 } else {
191 this.jLabelIcon1.setVisible(false);
192
193 }
194 this.jLabelIconInvite.setVisible(p.isInvited());
195 this.setToolTipText(tt.length() > 1 ? tt : null);
196 return this;
197 }
198
199 }