| 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 javax.swing.table.AbstractTableModel; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
@SuppressWarnings("serial") |
| 35 |
public class TaxaTableModel extends AbstractTableModel { |
| 36 |
|
| 37 |
private PartitionDataList dataList; |
| 38 |
|
| 39 |
private String[] COLUMN_NAMES = { "Name", "Height", "Data-set" }; |
| 40 |
private double[] heights = null; |
| 41 |
private String[] trees = null; |
| 42 |
|
| 43 |
public final static int NAME_INDEX = 0; |
| 44 |
public final static int HEIGHT_INDEX = 1; |
| 45 |
public final static int TAXA_SET_INDEX = 2; |
| 46 |
|
| 47 |
public TaxaTableModel(PartitionDataList dataList) { |
| 48 |
this.dataList = dataList; |
| 49 |
} |
| 50 |
|
| 51 |
public int getColumnCount() { |
| 52 |
return COLUMN_NAMES.length; |
| 53 |
} |
| 54 |
|
| 55 |
public int getRowCount() { |
| 56 |
return this.dataList.allTaxa.getTaxonCount(); |
| 57 |
} |
| 58 |
|
| 59 |
public Class<? extends Object> getColumnClass(int c) { |
| 60 |
return getValueAt(0, c).getClass(); |
| 61 |
} |
| 62 |
|
| 63 |
public boolean isCellEditable(int row, int col) { |
| 64 |
return false; |
| 65 |
} |
| 66 |
|
| 67 |
public String getColumnName(int column) { |
| 68 |
return COLUMN_NAMES[column]; |
| 69 |
} |
| 70 |
|
| 71 |
public Object getValueAt(int row, int col) { |
| 72 |
switch (col) { |
| 73 |
|
| 74 |
case NAME_INDEX: |
| 75 |
return this.dataList.allTaxa.getTaxonId(row); |
| 76 |
|
| 77 |
case HEIGHT_INDEX: |
| 78 |
|
| 79 |
if (heights != null) { |
| 80 |
return heights[row]; |
| 81 |
} else { |
| 82 |
return 0.0; |
| 83 |
} |
| 84 |
|
| 85 |
case TAXA_SET_INDEX: |
| 86 |
|
| 87 |
if (trees != null) { |
| 88 |
return trees[row]; |
| 89 |
} else { |
| 90 |
return ""; |
| 91 |
} |
| 92 |
|
| 93 |
default: |
| 94 |
return null; |
| 95 |
|
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
private void getHeights() { |
| 100 |
|
| 101 |
heights = new double[dataList.allTaxa.getTaxonCount()]; |
| 102 |
for (int i = 0; i < dataList.allTaxa.getTaxonCount(); i++) { |
| 103 |
|
| 104 |
heights[i] = (Double) dataList.allTaxa.getTaxon(i).getAttribute( |
| 105 |
Utils.ABSOLUTE_HEIGHT); |
| 106 |
|
| 107 |
} |
| 108 |
|
| 109 |
} |
| 110 |
|
| 111 |
private void getTrees() { |
| 112 |
|
| 113 |
trees = new String[dataList.allTaxa.getTaxonCount()]; |
| 114 |
for (int i = 0; i < dataList.allTaxa.getTaxonCount(); i++) { |
| 115 |
|
| 116 |
trees[i] = (String) dataList.allTaxa.getTaxon(i).getAttribute( |
| 117 |
Utils.TREE_FILENAME); |
| 118 |
|
| 119 |
} |
| 120 |
|
| 121 |
} |
| 122 |
|
| 123 |
public String toString() { |
| 124 |
StringBuffer buffer = new StringBuffer(); |
| 125 |
|
| 126 |
buffer.append(getColumnName(0)); |
| 127 |
for (int j = 1; j < getColumnCount(); j++) { |
| 128 |
buffer.append("\t"); |
| 129 |
buffer.append(getColumnName(j)); |
| 130 |
} |
| 131 |
buffer.append("\n"); |
| 132 |
|
| 133 |
for (int i = 0; i < getRowCount(); i++) { |
| 134 |
buffer.append(getValueAt(i, 0)); |
| 135 |
for (int j = 1; j < getColumnCount(); j++) { |
| 136 |
buffer.append("\t"); |
| 137 |
buffer.append(getValueAt(i, j)); |
| 138 |
} |
| 139 |
buffer.append("\n"); |
| 140 |
} |
| 141 |
|
| 142 |
return buffer.toString(); |
| 143 |
} |
| 144 |
|
| 145 |
public void fireTaxaChanged() { |
| 146 |
getHeights(); |
| 147 |
getTrees(); |
| 148 |
fireTableDataChanged(); |
| 149 |
} |
| 150 |
|
| 151 |
public void setDataList(PartitionDataList dataList) { |
| 152 |
this.dataList = dataList; |
| 153 |
} |
| 154 |
|
| 155 |
} |