source: src/main/java/genius/gui/renderer/RepItemListCellRenderer.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 1.5 KB
Line 
1package genius.gui.renderer;
2
3import java.awt.Component;
4
5import javax.swing.DefaultListCellRenderer;
6import javax.swing.JLabel;
7import javax.swing.JList;
8
9import genius.core.repository.PartyRepItem;
10import genius.core.repository.RepItem;
11import genius.core.repository.boa.BoaPartyRepItem;
12import genius.core.repository.boa.BoaRepItem;
13
14/**
15 * Renders RepItems, using {@link PartyRepItem#getName()} if possible, or
16 * toString otherwise.
17 */
18
19@SuppressWarnings("serial")
20public class RepItemListCellRenderer extends DefaultListCellRenderer {
21
22 @Override
23 public Component getListCellRendererComponent(JList<?> list, Object value,
24 int index, boolean isSelected, boolean cellHasFocus) {
25 JLabel comp = (JLabel) super.getListCellRendererComponent(list, value,
26 index, isSelected, cellHasFocus);
27 comp.setText(getText((RepItem) value));
28 return comp;
29 }
30
31 /**
32 *
33 * HACK static to at least be able to re-use this code in
34 * {@link RepItemTableCellRenderer}.
35 *
36 * @return label to show for a given RepItem.
37 */
38 protected static String getText(RepItem value) {
39 if (value == null) {
40 return "NULL";
41 }
42 if (value instanceof PartyRepItem) {
43 PartyRepItem participant = ((PartyRepItem) value);
44 return participant.getName() + " (" + participant.getDescription()
45 + ")";
46 }
47 if (value instanceof BoaPartyRepItem) {
48 return ((BoaPartyRepItem) value).getName();
49 }
50
51 if (value instanceof BoaRepItem) {
52 return ((BoaRepItem) value).getName();
53 }
54 return value.toString();
55 }
56}
Note: See TracBrowser for help on using the repository browser.