| 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.event.ActionEvent; |
| 29 |
import java.awt.event.ActionListener; |
| 30 |
|
| 31 |
import javax.swing.JButton; |
| 32 |
import javax.swing.JComboBox; |
| 33 |
import javax.swing.table.AbstractTableModel; |
| 34 |
import javax.swing.text.BadLocationException; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
@SuppressWarnings("serial") |
| 41 |
public class PartitionTableModel extends AbstractTableModel { |
| 42 |
|
| 43 |
private PartitionDataList dataList; |
| 44 |
|
| 45 |
public final static int DATA_INDEX = 0; |
| 46 |
public final static int FROM_INDEX = 1; |
| 47 |
public final static int TO_INDEX = 2; |
| 48 |
public final static int EVERY_INDEX = 3; |
| 49 |
public final static int DATA_TYPE_INDEX = 4; |
| 50 |
|
| 51 |
public final static int DEMOGRAPHIC_MODEL_INDEX = 5; |
| 52 |
public final static int BRANCH_SUBSTITUTION_MODEL_INDEX = 6; |
| 53 |
public final static int FREQUENCY_MODEL_INDEX = 7; |
| 54 |
|
| 55 |
public final static int SITE_RATE_MODEL_INDEX = 8; |
| 56 |
public final static int CLOCK_RATE_MODEL_INDEX = 9; |
| 57 |
public final static int ROOT_SEQUENCE_INDEX = 10; |
| 58 |
|
| 59 |
public static String[] COLUMN_NAMES = { "Input", |
| 60 |
"From", |
| 61 |
"To", |
| 62 |
"Every", |
| 63 |
"Data Type", |
| 64 |
"Tree model", |
| 65 |
"Substitution Model", |
| 66 |
"Frequencies", |
| 67 |
"Site Rate Model", |
| 68 |
"Clock Rate Model", |
| 69 |
"Root Sequence" |
| 70 |
}; |
| 71 |
|
| 72 |
private static final Class<?>[] COLUMN_TYPES = new Class<?>[] { |
| 73 |
JComboBox.class, |
| 74 |
Integer.class, |
| 75 |
Integer.class, |
| 76 |
Integer.class, |
| 77 |
JComboBox.class, |
| 78 |
JButton.class, |
| 79 |
JButton.class, |
| 80 |
JButton.class, |
| 81 |
JButton.class, |
| 82 |
JButton.class, |
| 83 |
JButton.class |
| 84 |
}; |
| 85 |
|
| 86 |
private DemographicModelEditor demographicModelEditor; |
| 87 |
private BranchSubstitutionModelEditor branchSubstitutionModelEditor; |
| 88 |
private SiteRateModelEditor siteRateModelEditor; |
| 89 |
private ClockRateModelEditor clockRateModelEditor; |
| 90 |
private FrequencyModelEditor frequencyModelEditor; |
| 91 |
private RootSequenceEditor rootSequenceEditor; |
| 92 |
|
| 93 |
public PartitionTableModel(PartitionDataList dataList) { |
| 94 |
this.dataList = dataList; |
| 95 |
} |
| 96 |
|
| 97 |
public void addRow(PartitionData row) { |
| 98 |
dataList.add(row); |
| 99 |
fireTableRowsInserted(dataList.size() - 1, dataList.size() - 1); |
| 100 |
} |
| 101 |
|
| 102 |
public void addDefaultRow() { |
| 103 |
dataList.add(new PartitionData()); |
| 104 |
fireTableRowsInserted(dataList.size() - 1, dataList.size() - 1); |
| 105 |
} |
| 106 |
|
| 107 |
public void deleteRow(int row) { |
| 108 |
dataList.remove(row); |
| 109 |
fireTableDataChanged(); |
| 110 |
} |
| 111 |
|
| 112 |
@Override |
| 113 |
public int getColumnCount() { |
| 114 |
return COLUMN_NAMES.length; |
| 115 |
} |
| 116 |
|
| 117 |
@Override |
| 118 |
public int getRowCount() { |
| 119 |
return dataList.size(); |
| 120 |
} |
| 121 |
|
| 122 |
@Override |
| 123 |
public Class<?> getColumnClass(int columnIndex) { |
| 124 |
return COLUMN_TYPES[columnIndex]; |
| 125 |
} |
| 126 |
|
| 127 |
public boolean isCellEditable(int row, int column) { |
| 128 |
switch (column) { |
| 129 |
case DATA_INDEX: |
| 130 |
return true; |
| 131 |
case DEMOGRAPHIC_MODEL_INDEX: |
| 132 |
return false; |
| 133 |
case DATA_TYPE_INDEX: |
| 134 |
return true; |
| 135 |
case FROM_INDEX: |
| 136 |
return true; |
| 137 |
case TO_INDEX: |
| 138 |
return true; |
| 139 |
case EVERY_INDEX: |
| 140 |
return true; |
| 141 |
case BRANCH_SUBSTITUTION_MODEL_INDEX: |
| 142 |
return false; |
| 143 |
case SITE_RATE_MODEL_INDEX: |
| 144 |
return false; |
| 145 |
case CLOCK_RATE_MODEL_INDEX: |
| 146 |
return false; |
| 147 |
case FREQUENCY_MODEL_INDEX: |
| 148 |
return false; |
| 149 |
case ROOT_SEQUENCE_INDEX: |
| 150 |
return false; |
| 151 |
default: |
| 152 |
return false; |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
public String getColumnName(int column) { |
| 157 |
return COLUMN_NAMES[column]; |
| 158 |
} |
| 159 |
|
| 160 |
@Override |
| 161 |
public Object getValueAt(final int row, final int column) { |
| 162 |
switch (column) { |
| 163 |
|
| 164 |
case DATA_INDEX: |
| 165 |
|
| 166 |
return dataList.get(row).record == null ? new TreesTableRecord() : dataList |
| 167 |
.get(row).record; |
| 168 |
|
| 169 |
case DEMOGRAPHIC_MODEL_INDEX: |
| 170 |
|
| 171 |
final JButton topologyButton = new JButton(COLUMN_NAMES[column]); |
| 172 |
topologyButton |
| 173 |
.addActionListener(new ListenOpenDemographicModelEditor(row)); |
| 174 |
return topologyButton; |
| 175 |
|
| 176 |
case DATA_TYPE_INDEX: |
| 177 |
return PartitionData.dataTypes[dataList.get(row).dataTypeIndex]; |
| 178 |
|
| 179 |
case FROM_INDEX: |
| 180 |
return dataList.get(row).from; |
| 181 |
|
| 182 |
case TO_INDEX: |
| 183 |
return dataList.get(row).to; |
| 184 |
|
| 185 |
case EVERY_INDEX: |
| 186 |
return dataList.get(row).every; |
| 187 |
|
| 188 |
case BRANCH_SUBSTITUTION_MODEL_INDEX: |
| 189 |
|
| 190 |
final JButton branchSubstModelButton = new JButton( |
| 191 |
COLUMN_NAMES[column]); |
| 192 |
branchSubstModelButton |
| 193 |
.addActionListener(new ListenOpenBranchSubstitutionModelEditor( |
| 194 |
row)); |
| 195 |
return branchSubstModelButton; |
| 196 |
|
| 197 |
case SITE_RATE_MODEL_INDEX: |
| 198 |
|
| 199 |
final JButton siteRateModelButton = new JButton( |
| 200 |
COLUMN_NAMES[column]); |
| 201 |
siteRateModelButton |
| 202 |
.addActionListener(new ListenOpenSiteRateModelEditor(row)); |
| 203 |
|
| 204 |
return siteRateModelButton; |
| 205 |
|
| 206 |
case CLOCK_RATE_MODEL_INDEX: |
| 207 |
|
| 208 |
final JButton clockRateModelButton = new JButton( |
| 209 |
COLUMN_NAMES[column]); |
| 210 |
clockRateModelButton |
| 211 |
.addActionListener(new ListenOpenClockRateModelEditor(row)); |
| 212 |
return clockRateModelButton; |
| 213 |
|
| 214 |
case FREQUENCY_MODEL_INDEX: |
| 215 |
|
| 216 |
final JButton frequencyModelButton = new JButton( |
| 217 |
COLUMN_NAMES[column]); |
| 218 |
frequencyModelButton |
| 219 |
.addActionListener(new ListenOpenFrequencyModelEditor(row)); |
| 220 |
return frequencyModelButton; |
| 221 |
|
| 222 |
case ROOT_SEQUENCE_INDEX: |
| 223 |
|
| 224 |
final JButton ancestralSequenceButton = new JButton(COLUMN_NAMES[column]); |
| 225 |
ancestralSequenceButton.addActionListener(new ListenOpenRootSequenceEditor(row)); |
| 226 |
return ancestralSequenceButton; |
| 227 |
|
| 228 |
default: |
| 229 |
return "Error"; |
| 230 |
} |
| 231 |
|
| 232 |
} |
| 233 |
|
| 234 |
public void setValueAt(Object value, int row, int column) { |
| 235 |
|
| 236 |
switch (column) { |
| 237 |
|
| 238 |
case DATA_INDEX: |
| 239 |
dataList.get(row).record = (TreesTableRecord) value; |
| 240 |
break; |
| 241 |
|
| 242 |
case DATA_TYPE_INDEX: |
| 243 |
dataList.get(row).dataTypeIndex = (Integer) Utils.arrayIndex( |
| 244 |
PartitionData.dataTypes, (String) value); |
| 245 |
break; |
| 246 |
|
| 247 |
case FROM_INDEX: |
| 248 |
dataList.get(row).from = (Integer) value; |
| 249 |
break; |
| 250 |
|
| 251 |
case TO_INDEX: |
| 252 |
dataList.get(row).to = (Integer) value; |
| 253 |
break; |
| 254 |
|
| 255 |
case EVERY_INDEX: |
| 256 |
dataList.get(row).every = (Integer) value; |
| 257 |
break; |
| 258 |
|
| 259 |
case BRANCH_SUBSTITUTION_MODEL_INDEX: |
| 260 |
dataList.get(row).substitutionModelIndex = (Integer) value; |
| 261 |
break; |
| 262 |
|
| 263 |
case SITE_RATE_MODEL_INDEX: |
| 264 |
dataList.get(row).siteRateModelIndex = (Integer) value; |
| 265 |
break; |
| 266 |
|
| 267 |
case CLOCK_RATE_MODEL_INDEX: |
| 268 |
dataList.get(row).clockModelIndex = (Integer) value; |
| 269 |
break; |
| 270 |
|
| 271 |
case FREQUENCY_MODEL_INDEX: |
| 272 |
dataList.get(row).frequencyModelIndex = (Integer) value; |
| 273 |
break; |
| 274 |
|
| 275 |
default: |
| 276 |
throw new RuntimeException("Invalid index."); |
| 277 |
} |
| 278 |
|
| 279 |
fireTableCellUpdated(row, column); |
| 280 |
|
| 281 |
} |
| 282 |
|
| 283 |
private class ListenOpenDemographicModelEditor implements ActionListener { |
| 284 |
|
| 285 |
private int row; |
| 286 |
|
| 287 |
public ListenOpenDemographicModelEditor(int row) { |
| 288 |
this.row = row; |
| 289 |
} |
| 290 |
|
| 291 |
public void actionPerformed(ActionEvent ev) { |
| 292 |
|
| 293 |
demographicModelEditor = new DemographicModelEditor(dataList, row); |
| 294 |
demographicModelEditor.launch(); |
| 295 |
|
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
private class ListenOpenBranchSubstitutionModelEditor implements |
| 300 |
ActionListener { |
| 301 |
|
| 302 |
private int row; |
| 303 |
|
| 304 |
public ListenOpenBranchSubstitutionModelEditor(int row) { |
| 305 |
this.row = row; |
| 306 |
} |
| 307 |
|
| 308 |
public void actionPerformed(ActionEvent ev) { |
| 309 |
|
| 310 |
branchSubstitutionModelEditor = new BranchSubstitutionModelEditor( |
| 311 |
dataList, row); |
| 312 |
branchSubstitutionModelEditor.launch(); |
| 313 |
|
| 314 |
} |
| 315 |
} |
| 316 |
|
| 317 |
private class ListenOpenSiteRateModelEditor implements ActionListener { |
| 318 |
private int row; |
| 319 |
|
| 320 |
public ListenOpenSiteRateModelEditor(int row) { |
| 321 |
this.row = row; |
| 322 |
} |
| 323 |
|
| 324 |
public void actionPerformed(ActionEvent ev) { |
| 325 |
|
| 326 |
try { |
| 327 |
siteRateModelEditor = new SiteRateModelEditor(dataList, row); |
| 328 |
siteRateModelEditor.launch(); |
| 329 |
} catch (NumberFormatException e) { |
| 330 |
Utils.handleException(e); |
| 331 |
} catch (BadLocationException e) { |
| 332 |
Utils.handleException(e); |
| 333 |
} |
| 334 |
|
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
private class ListenOpenClockRateModelEditor implements ActionListener { |
| 339 |
private int row; |
| 340 |
|
| 341 |
public ListenOpenClockRateModelEditor(int row) { |
| 342 |
this.row = row; |
| 343 |
} |
| 344 |
|
| 345 |
public void actionPerformed(ActionEvent ev) { |
| 346 |
|
| 347 |
clockRateModelEditor = new ClockRateModelEditor(dataList, row); |
| 348 |
clockRateModelEditor.launch(); |
| 349 |
|
| 350 |
} |
| 351 |
} |
| 352 |
|
| 353 |
private class ListenOpenFrequencyModelEditor implements ActionListener { |
| 354 |
private int row; |
| 355 |
|
| 356 |
public ListenOpenFrequencyModelEditor(int row) { |
| 357 |
this.row = row; |
| 358 |
} |
| 359 |
|
| 360 |
public void actionPerformed(ActionEvent ev) { |
| 361 |
|
| 362 |
frequencyModelEditor = new FrequencyModelEditor(dataList, row); |
| 363 |
frequencyModelEditor.launch(); |
| 364 |
|
| 365 |
} |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
private class ListenOpenRootSequenceEditor implements ActionListener { |
| 370 |
private int row; |
| 371 |
|
| 372 |
public ListenOpenRootSequenceEditor(int row) { |
| 373 |
this.row = row; |
| 374 |
} |
| 375 |
|
| 376 |
public void actionPerformed(ActionEvent ev) { |
| 377 |
|
| 378 |
rootSequenceEditor = new RootSequenceEditor(dataList, row); |
| 379 |
rootSequenceEditor.launch(); |
| 380 |
|
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
public void setDataList(PartitionDataList dataList) { |
| 385 |
this.dataList = dataList; |
| 386 |
} |
| 387 |
|
| 388 |
} |