Debian Codegraph @

src/dr/app/bss/JTableButtonCellRenderer.java

raw symbols SCIP
1 /*
2 * JTableButtonCellRenderer.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.Color;
29 import java.awt.Component;
30
31 import javax.swing.JButton;
32 import javax.swing.JTable;
33 import javax.swing.UIManager;
34 import javax.swing.border.LineBorder;
35 import javax.swing.table.TableCellRenderer;
36
37 /**
38 * @author Filip Bielejec
39 * @version $Id$
40 */
41 @SuppressWarnings("serial")
42 public class JTableButtonCellRenderer extends JButton implements
43 TableCellRenderer {
44
45 private PartitionDataList dataList = null;
46 private int columnIndex;
47 private String toolTipText = null;
48
49 public JTableButtonCellRenderer() {
50 super();
51 setOpaque(true);
52 }// END: Constructor
53
54 public JTableButtonCellRenderer(PartitionDataList dataList, int columnIndex) {
55 super();
56
57 setOpaque(true);
58 this.dataList = dataList;
59 this.columnIndex = columnIndex;
60
61 }// END: Constructor
62
63 @Override
64 public Component getTableCellRendererComponent(JTable table, Object value,
65 boolean isSelected, boolean hasFocus, int row, int column) {
66
67 JButton button = (JButton) value;
68
69 if (isSelected) {
70 button.setForeground(table.getSelectionForeground());
71 button.setBackground(table.getSelectionBackground());
72 } else {
73 button.setForeground(table.getForeground());
74 button.setBackground(UIManager.getColor("Button.background"));
75 }
76
77 if (hasFocus) {
78 button.setBorder(new LineBorder(Color.BLUE));
79 } else {
80 button.setBorder(button.getBorder());
81 }
82
83 // label on button
84 if (dataList != null) {
85
86 // switch between edit taxa and choose file labels
87 String label = null;
88 switch (columnIndex) {
89
90 case TreesTableModel.TREE_FILE_INDEX:
91
92 if (!dataList.recordsList.get(row).isTreeSet()) {
93 label = Utils.CHOOSE_FILE;
94 } else {
95 label = dataList.recordsList.get(row).getName();
96 }
97
98 break;
99
100 case TreesTableModel.TAXA_SET_INDEX:
101
102 if (!dataList.recordsList.get(row).isTaxaSet()) {
103 label = Utils.EDIT_TAXA_SET;
104 } else {
105 label = dataList.recordsList.get(row).getName();
106 }
107
108 break;
109
110 default:
111
112 break;
113 }// END: switch
114
115 button.setText(label);
116 }// END: null check
117
118 // tooltips
119 if (toolTipText != null) {
120 button.setToolTipText(toolTipText);
121 }
122
123 return button;
124 }// END: getTableCellRendererComponent
125
126 public void setColumnToolTipText(String toolTipText) {
127 this.toolTipText = toolTipText;
128 }// END: setColumnToolTipText
129
130 // public void setDataList(PartitionDataList dataList) {
131 // this.dataList = dataList;
132 // }//END: setDataList
133
134 }// END: class