| 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 |
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 |
|
| 39 |
|
| 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 |
} |
| 53 |
|
| 54 |
public JTableButtonCellRenderer(PartitionDataList dataList, int columnIndex) { |
| 55 |
super(); |
| 56 |
|
| 57 |
setOpaque(true); |
| 58 |
this.dataList = dataList; |
| 59 |
this.columnIndex = columnIndex; |
| 60 |
|
| 61 |
} |
| 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 |
|
| 84 |
if (dataList != null) { |
| 85 |
|
| 86 |
|
| 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 |
} |
| 114 |
|
| 115 |
button.setText(label); |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
if (toolTipText != null) { |
| 120 |
button.setToolTipText(toolTipText); |
| 121 |
} |
| 122 |
|
| 123 |
return button; |
| 124 |
} |
| 125 |
|
| 126 |
public void setColumnToolTipText(String toolTipText) { |
| 127 |
this.toolTipText = toolTipText; |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
} |