Debian Codegraph @

src/dr/app/bss/JTableComboBoxCellRenderer.java

raw symbols SCIP
1 /*
2 * JTableComboBoxCellRenderer.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.bss;
27
28 import java.awt.Component;
29
30 import javax.swing.DefaultListCellRenderer;
31 import javax.swing.JComboBox;
32 import javax.swing.JList;
33 import javax.swing.JTable;
34 import javax.swing.table.TableCellRenderer;
35
36
37 @SuppressWarnings("serial")
38 public class JTableComboBoxCellRenderer extends JComboBox implements
39 TableCellRenderer {
40
41 private int columnIndex;
42
43 private DefaultListCellRenderer comboBoxRenderer = new DefaultListCellRenderer() {
44
45 @Override
46 public Component getListCellRendererComponent(JList list, Object value,
47 int index, boolean isSelected, boolean cellHasFocus) {
48
49 super.getListCellRendererComponent(list, value, index, isSelected,
50 cellHasFocus);
51
52 if (value != null) {
53
54 switch (columnIndex) {
55
56 case PartitionTableModel.DATA_INDEX:
57
58 TreesTableRecord record = (TreesTableRecord) value;
59 this.setText(record.getName());
60 break;
61
62 default:
63 break;
64
65 }// END: switch
66
67 }//END: null check
68
69 return this;
70 }
71
72 };
73
74 public JTableComboBoxCellRenderer(int columnIndex) {
75
76 super();
77 setOpaque(true);
78 this.setRenderer(comboBoxRenderer);
79 this.columnIndex = columnIndex;
80
81 }// END: Constructor
82
83 public Component getTableCellRendererComponent(JTable table, Object value,
84 boolean isSelected, boolean hasFocus, int row, int column) {
85
86 if (isSelected) {
87
88 this.setForeground(table.getSelectionForeground());
89 this.setBackground(table.getSelectionBackground());
90
91 } else {
92
93 this.setForeground(table.getForeground());
94 this.setBackground(table.getBackground());
95
96 }
97
98 // Select the current value
99 setSelectedItem(value);
100
101 if (value != null) {
102 removeAllItems();
103 addItem(value);
104 }
105
106 return this;
107 }
108 }// END: JTableComboBoxCellRenderer class