| 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.beauti.datapanel; |
| 27 |
|
| 28 |
import dr.app.beauti.BeautiFrame; |
| 29 |
import dr.app.beauti.BeautiPanel; |
| 30 |
import dr.app.beauti.ComboBoxRenderer; |
| 31 |
import dr.app.beauti.alignmentviewer.AlignmentViewer; |
| 32 |
import dr.app.beauti.alignmentviewer.AminoAcidDecorator; |
| 33 |
import dr.app.beauti.alignmentviewer.NucleotideDecorator; |
| 34 |
import dr.app.beauti.alignmentviewer.StateCellDecorator; |
| 35 |
import dr.app.beauti.options.*; |
| 36 |
import dr.app.beauti.util.PanelUtils; |
| 37 |
import dr.app.gui.table.TableEditorStopper; |
| 38 |
import dr.evolution.alignment.Alignment; |
| 39 |
import dr.evolution.datatype.DataType; |
| 40 |
import dr.evolution.datatype.Microsatellite; |
| 41 |
import dr.evolution.util.Taxa; |
| 42 |
import jam.framework.Exportable; |
| 43 |
import jam.panels.ActionPanel; |
| 44 |
|
| 45 |
import javax.swing.*; |
| 46 |
import javax.swing.event.ListSelectionEvent; |
| 47 |
import javax.swing.event.ListSelectionListener; |
| 48 |
import javax.swing.plaf.BorderUIResource; |
| 49 |
import javax.swing.table.AbstractTableModel; |
| 50 |
import javax.swing.table.TableColumn; |
| 51 |
import java.awt.*; |
| 52 |
import java.awt.event.ActionEvent; |
| 53 |
import java.awt.event.MouseAdapter; |
| 54 |
import java.awt.event.MouseEvent; |
| 55 |
import java.util.ArrayList; |
| 56 |
import java.util.HashSet; |
| 57 |
import java.util.List; |
| 58 |
import java.util.Set; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public class DataPanel extends BeautiPanel implements Exportable { |
| 66 |
|
| 67 |
JScrollPane scrollPane = new JScrollPane(); |
| 68 |
JTable dataTable = null; |
| 69 |
DataTableModel dataTableModel = null; |
| 70 |
|
| 71 |
UnlinkModelsAction unlinkModelsAction = new UnlinkModelsAction(); |
| 72 |
LinkModelsAction linkModelsAction = new LinkModelsAction(); |
| 73 |
|
| 74 |
UnlinkClocksAction unlinkClocksAction = new UnlinkClocksAction(); |
| 75 |
LinkClocksAction linkClocksAction = new LinkClocksAction(); |
| 76 |
|
| 77 |
UnlinkTreesAction unlinkTreesAction = new UnlinkTreesAction(); |
| 78 |
LinkTreesAction linkTreesAction = new LinkTreesAction(); |
| 79 |
|
| 80 |
CreateTraitPartitionAction createTraitPartitionAction = new CreateTraitPartitionAction(); |
| 81 |
|
| 82 |
ViewPartitionAction viewPartitionAction = new ViewPartitionAction(); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
SelectModelDialog selectModelDialog = null; |
| 87 |
SelectClockDialog selectClockDialog = null; |
| 88 |
SelectTreeDialog selectTreeDialog = null; |
| 89 |
|
| 90 |
SelectTraitDialog selectTraitDialog = null; |
| 91 |
|
| 92 |
BeautiFrame frame = null; |
| 93 |
|
| 94 |
BeautiOptions options = null; |
| 95 |
|
| 96 |
public DataPanel(BeautiFrame parent, Action importDataAction, Action removeDataAction) { |
| 97 |
|
| 98 |
this.frame = parent; |
| 99 |
|
| 100 |
dataTableModel = new DataTableModel(); |
| 101 |
dataTable = new JTable(dataTableModel); |
| 102 |
|
| 103 |
dataTable.getTableHeader().setReorderingAllowed(false); |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
TableColumn col = dataTable.getColumnModel().getColumn(5); |
| 108 |
ComboBoxRenderer comboBoxRenderer = new ComboBoxRenderer(); |
| 109 |
col.setCellRenderer(comboBoxRenderer); |
| 110 |
|
| 111 |
col = dataTable.getColumnModel().getColumn(6); |
| 112 |
comboBoxRenderer = new ComboBoxRenderer(); |
| 113 |
col.setCellRenderer(comboBoxRenderer); |
| 114 |
|
| 115 |
col = dataTable.getColumnModel().getColumn(7); |
| 116 |
comboBoxRenderer = new ComboBoxRenderer(); |
| 117 |
col.setCellRenderer(comboBoxRenderer); |
| 118 |
|
| 119 |
TableEditorStopper.ensureEditingStopWhenTableLosesFocus(dataTable); |
| 120 |
|
| 121 |
dataTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
| 122 |
public void valueChanged(ListSelectionEvent evt) { |
| 123 |
selectionChanged(); |
| 124 |
} |
| 125 |
}); |
| 126 |
|
| 127 |
dataTable.addMouseListener(new MouseAdapter() { |
| 128 |
public void mouseClicked(MouseEvent e) { |
| 129 |
if (e.getClickCount() == 2) { |
| 130 |
showAlignment(); |
| 131 |
} |
| 132 |
} |
| 133 |
}); |
| 134 |
|
| 135 |
|
| 136 |
scrollPane = new JScrollPane(dataTable, |
| 137 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, |
| 138 |
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
| 139 |
scrollPane.setOpaque(false); |
| 140 |
|
| 141 |
JToolBar toolBar1 = new JToolBar(); |
| 142 |
toolBar1.setFloatable(false); |
| 143 |
toolBar1.setOpaque(false); |
| 144 |
toolBar1.setLayout(new BoxLayout(toolBar1, BoxLayout.X_AXIS)); |
| 145 |
toolBar1.setBorder(BorderFactory.createEmptyBorder()); |
| 146 |
|
| 147 |
JButton button = new JButton(unlinkModelsAction); |
| 148 |
unlinkModelsAction.setEnabled(false); |
| 149 |
PanelUtils.setupComponent(button); |
| 150 |
toolBar1.add(button); |
| 151 |
|
| 152 |
button = new JButton(linkModelsAction); |
| 153 |
linkModelsAction.setEnabled(false); |
| 154 |
PanelUtils.setupComponent(button); |
| 155 |
toolBar1.add(button); |
| 156 |
|
| 157 |
toolBar1.addSeparator(); |
| 158 |
|
| 159 |
button = new JButton(unlinkClocksAction); |
| 160 |
unlinkClocksAction.setEnabled(false); |
| 161 |
PanelUtils.setupComponent(button); |
| 162 |
toolBar1.add(button); |
| 163 |
|
| 164 |
button = new JButton(linkClocksAction); |
| 165 |
linkClocksAction.setEnabled(false); |
| 166 |
PanelUtils.setupComponent(button); |
| 167 |
toolBar1.add(button); |
| 168 |
|
| 169 |
toolBar1.addSeparator(); |
| 170 |
|
| 171 |
button = new JButton(unlinkTreesAction); |
| 172 |
unlinkTreesAction.setEnabled(false); |
| 173 |
PanelUtils.setupComponent(button); |
| 174 |
toolBar1.add(button); |
| 175 |
|
| 176 |
button = new JButton(linkTreesAction); |
| 177 |
linkTreesAction.setEnabled(false); |
| 178 |
PanelUtils.setupComponent(button); |
| 179 |
toolBar1.add(button); |
| 180 |
|
| 181 |
ActionPanel actionPanel1 = new ActionPanel(false); |
| 182 |
actionPanel1.setAddAction(importDataAction); |
| 183 |
actionPanel1.setRemoveAction(removeDataAction); |
| 184 |
removeDataAction.setEnabled(false); |
| 185 |
|
| 186 |
JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| 187 |
controlPanel1.setOpaque(false); |
| 188 |
controlPanel1.add(actionPanel1); |
| 189 |
|
| 190 |
button = new JButton(viewPartitionAction); |
| 191 |
controlPanel1.add(new JLabel(" ")); |
| 192 |
viewPartitionAction.setEnabled(false); |
| 193 |
PanelUtils.setupComponent(button); |
| 194 |
controlPanel1.add(button); |
| 195 |
|
| 196 |
button = new JButton(createTraitPartitionAction); |
| 197 |
controlPanel1.add(new JLabel(" ")); |
| 198 |
PanelUtils.setupComponent(button); |
| 199 |
controlPanel1.add(button); |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
setOpaque(false); |
| 207 |
setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12))); |
| 208 |
setLayout(new BorderLayout(0, 0)); |
| 209 |
add(toolBar1, BorderLayout.NORTH); |
| 210 |
add(scrollPane, BorderLayout.CENTER); |
| 211 |
add(controlPanel1, BorderLayout.SOUTH); |
| 212 |
|
| 213 |
} |
| 214 |
|
| 215 |
private void showAlignment() { |
| 216 |
|
| 217 |
int[] selRows = dataTable.getSelectedRows(); |
| 218 |
for (int row : selRows) { |
| 219 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 220 |
Alignment alignment = null; |
| 221 |
|
| 222 |
if (partition instanceof PartitionData) alignment = ((PartitionData) partition).getAlignment(); |
| 223 |
|
| 224 |
|
| 225 |
if (alignment == null) { |
| 226 |
JOptionPane.showMessageDialog(this, "Cannot display traits or microsatellite data currently.\nUse the traits panel to view and edit traits.", |
| 227 |
"Illegal Argument Exception", |
| 228 |
JOptionPane.ERROR_MESSAGE); |
| 229 |
return; |
| 230 |
} |
| 231 |
|
| 232 |
JFrame frame = new JFrame(); |
| 233 |
frame.setSize(800, 600); |
| 234 |
|
| 235 |
AlignmentViewer viewer = new AlignmentViewer(); |
| 236 |
if (alignment.getDataType().getType() == DataType.NUCLEOTIDES) { |
| 237 |
viewer.setCellDecorator(new StateCellDecorator(new NucleotideDecorator(), false)); |
| 238 |
} else if (alignment.getDataType().getType() == DataType.AMINO_ACIDS) { |
| 239 |
viewer.setCellDecorator(new StateCellDecorator(new AminoAcidDecorator(), false)); |
| 240 |
} else { |
| 241 |
|
| 242 |
} |
| 243 |
viewer.setAlignmentBuffer(new BeautiAlignmentBuffer(alignment)); |
| 244 |
|
| 245 |
JPanel panel = new JPanel(new BorderLayout()); |
| 246 |
panel.setOpaque(false); |
| 247 |
panel.add(viewer, BorderLayout.CENTER); |
| 248 |
|
| 249 |
JPanel infoPanel = new JPanel(new BorderLayout()); |
| 250 |
infoPanel.setOpaque(false); |
| 251 |
panel.add(infoPanel, BorderLayout.SOUTH); |
| 252 |
|
| 253 |
frame.setContentPane(panel); |
| 254 |
frame.setVisible(true); |
| 255 |
} |
| 256 |
|
| 257 |
} |
| 258 |
|
| 259 |
private void fireDataChanged() { |
| 260 |
|
| 261 |
frame.setDirty(); |
| 262 |
} |
| 263 |
|
| 264 |
private void modelsChanged() { |
| 265 |
TableColumn col = dataTable.getColumnModel().getColumn(5); |
| 266 |
col.setCellEditor(new ComboBoxCellEditor()); |
| 267 |
|
| 268 |
col = dataTable.getColumnModel().getColumn(6); |
| 269 |
col.setCellEditor(new ComboBoxCellEditor()); |
| 270 |
|
| 271 |
col = dataTable.getColumnModel().getColumn(7); |
| 272 |
col.setCellEditor(new DefaultCellEditor(new JComboBox(options.getPartitionTreeModels().toArray()))); |
| 273 |
} |
| 274 |
|
| 275 |
public class ComboBoxCellEditor extends DefaultCellEditor { |
| 276 |
public ComboBoxCellEditor() { |
| 277 |
super(new JComboBox()); |
| 278 |
} |
| 279 |
|
| 280 |
public Component getTableCellEditorComponent(JTable table, Object value, |
| 281 |
boolean isSelected, |
| 282 |
int row, int column) { |
| 283 |
|
| 284 |
((JComboBox) editorComponent).removeAllItems(); |
| 285 |
|
| 286 |
if (column == 5) { |
| 287 |
for (Object ob : options.getPartitionSubstitutionModels()) { |
| 288 |
((JComboBox) editorComponent).addItem(ob); |
| 289 |
} |
| 290 |
} else if (column == 6) { |
| 291 |
for (Object ob : options.getPartitionClockModels()) { |
| 292 |
((JComboBox) editorComponent).addItem(ob); |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
((JComboBox) editorComponent).setSelectedItem(value); |
| 299 |
delegate.setValue(value); |
| 300 |
|
| 301 |
return editorComponent; |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
public void selectionChanged() { |
| 306 |
int[] selRows = dataTable.getSelectedRows(); |
| 307 |
boolean hasSelection = (selRows != null && selRows.length != 0); |
| 308 |
frame.dataSelectionChanged(hasSelection); |
| 309 |
|
| 310 |
boolean canUnlink = options.dataPartitions.size() > 1 && hasSelection; |
| 311 |
boolean canLink = options.dataPartitions.size() > 1 && hasSelection && selRows.length > 1; |
| 312 |
|
| 313 |
unlinkModelsAction.setEnabled(canUnlink); |
| 314 |
linkModelsAction.setEnabled(canLink); |
| 315 |
|
| 316 |
unlinkClocksAction.setEnabled(canUnlink); |
| 317 |
linkClocksAction.setEnabled(canLink); |
| 318 |
|
| 319 |
unlinkTreesAction.setEnabled(canUnlink); |
| 320 |
linkTreesAction.setEnabled(canLink); |
| 321 |
|
| 322 |
viewPartitionAction.setEnabled(options.dataPartitions.size() > 0 && hasSelection); |
| 323 |
} |
| 324 |
|
| 325 |
public void setOptions(BeautiOptions options) { |
| 326 |
|
| 327 |
this.options = options; |
| 328 |
|
| 329 |
modelsChanged(); |
| 330 |
|
| 331 |
boolean taxaAvailable = options.taxonList != null && options.taxonList.getTaxonCount() > 0; |
| 332 |
boolean traitAvailable = options.traits != null && options.traits.size() > 0; |
| 333 |
|
| 334 |
createTraitPartitionAction.setEnabled(traitAvailable); |
| 335 |
|
| 336 |
dataTableModel.fireTableDataChanged(); |
| 337 |
} |
| 338 |
|
| 339 |
public void getOptions(BeautiOptions options) { |
| 340 |
} |
| 341 |
|
| 342 |
public JComponent getExportableComponent() { |
| 343 |
return dataTable; |
| 344 |
} |
| 345 |
|
| 346 |
public void removeSelection() { |
| 347 |
int[] selRows = dataTable.getSelectedRows(); |
| 348 |
Set<AbstractPartitionData> partitionsToRemove = new HashSet<AbstractPartitionData>(); |
| 349 |
for (int row : selRows) { |
| 350 |
partitionsToRemove.add(options.dataPartitions.get(row)); |
| 351 |
} |
| 352 |
|
| 353 |
boolean hasIdenticalTaxa = options.hasIdenticalTaxa(); |
| 354 |
|
| 355 |
|
| 356 |
options.dataPartitions.removeAll(partitionsToRemove); |
| 357 |
|
| 358 |
if (options.dataPartitions.size() == 0) { |
| 359 |
|
| 360 |
options.reset(); |
| 361 |
frame.statusLabel.setText(""); |
| 362 |
frame.setAllOptions(); |
| 363 |
frame.getExportAction().setEnabled(false); |
| 364 |
} else if (!hasIdenticalTaxa) { |
| 365 |
options.updateTaxonList(); |
| 366 |
} |
| 367 |
|
| 368 |
dataTableModel.fireTableDataChanged(); |
| 369 |
|
| 370 |
fireDataChanged(); |
| 371 |
} |
| 372 |
|
| 373 |
public void selectAll() { |
| 374 |
dataTable.selectAll(); |
| 375 |
} |
| 376 |
|
| 377 |
public boolean createFromTraits(List<TraitData> traits) { |
| 378 |
int selRow = -1; |
| 379 |
|
| 380 |
if (selectTraitDialog == null) { |
| 381 |
selectTraitDialog = new SelectTraitDialog(frame); |
| 382 |
} |
| 383 |
|
| 384 |
if (traits==null || traits.size() == 0) { |
| 385 |
int result = selectTraitDialog.showDialog(options.traits, null); |
| 386 |
if (result != JOptionPane.CANCEL_OPTION) { |
| 387 |
TraitData trait = selectTraitDialog.getTrait(); |
| 388 |
String name = trait.getName(); |
| 389 |
if (selectTraitDialog.getMakeCopy()) { |
| 390 |
name = selectTraitDialog.getName(); |
| 391 |
} |
| 392 |
|
| 393 |
selRow = options.createPartitionForTraits(name, trait); |
| 394 |
} else { |
| 395 |
return false; |
| 396 |
} |
| 397 |
} else { |
| 398 |
if (traits.size() > 1) { |
| 399 |
|
| 400 |
int result = selectTraitDialog.showDialog(null, null); |
| 401 |
if (result != JOptionPane.CANCEL_OPTION) { |
| 402 |
String name = selectTraitDialog.getName(); |
| 403 |
selRow = options.createPartitionForTraits(name, traits); |
| 404 |
} else { |
| 405 |
return false; |
| 406 |
} |
| 407 |
} else { |
| 408 |
selRow = options.createPartitionForTraits(traits.get(0).getName(), traits); |
| 409 |
} |
| 410 |
} |
| 411 |
|
| 412 |
modelsChanged(); |
| 413 |
dataTableModel.fireTableDataChanged(); |
| 414 |
|
| 415 |
if (selRow != -1) { |
| 416 |
dataTable.getSelectionModel().setSelectionInterval(selRow, selRow); |
| 417 |
} |
| 418 |
fireDataChanged(); |
| 419 |
repaint(); |
| 420 |
|
| 421 |
return true; |
| 422 |
} |
| 423 |
|
| 424 |
public void unlinkSubstitutionModels() { |
| 425 |
int[] selRows = dataTable.getSelectedRows(); |
| 426 |
for (int row : selRows) { |
| 427 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 428 |
|
| 429 |
PartitionSubstitutionModel model = partition.getPartitionSubstitutionModel(); |
| 430 |
if (!model.getName().equals(partition.getName())) { |
| 431 |
PartitionSubstitutionModel newModel = new PartitionSubstitutionModel(options, partition.getName(), model); |
| 432 |
partition.setPartitionSubstitutionModel(newModel); |
| 433 |
} |
| 434 |
} |
| 435 |
|
| 436 |
modelsChanged(); |
| 437 |
|
| 438 |
fireDataChanged(); |
| 439 |
repaint(); |
| 440 |
} |
| 441 |
|
| 442 |
public void linkSubstitutionModels() { |
| 443 |
int[] selRows = dataTable.getSelectedRows(); |
| 444 |
List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>(); |
| 445 |
DataType dateType = null; |
| 446 |
for (int row : selRows) { |
| 447 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 448 |
if (dateType == null) { |
| 449 |
dateType = partition.getDataType(); |
| 450 |
} else { |
| 451 |
if (partition.getDataType() != dateType) { |
| 452 |
JOptionPane.showMessageDialog(this, "Can only link the models for data partitions \n" + |
| 453 |
"of the same data type (e.g., nucleotides)", |
| 454 |
"Unable to link models", |
| 455 |
JOptionPane.ERROR_MESSAGE); |
| 456 |
return; |
| 457 |
} |
| 458 |
} |
| 459 |
|
| 460 |
if (!selectedPartitionData.contains(partition)) |
| 461 |
selectedPartitionData.add(partition); |
| 462 |
} |
| 463 |
|
| 464 |
Object[] modelArray = options.getPartitionSubstitutionModels(selectedPartitionData).toArray(); |
| 465 |
|
| 466 |
if (selectModelDialog == null) { |
| 467 |
selectModelDialog = new SelectModelDialog(frame); |
| 468 |
} |
| 469 |
|
| 470 |
int result = selectModelDialog.showDialog(modelArray); |
| 471 |
if (result != JOptionPane.CANCEL_OPTION) { |
| 472 |
PartitionSubstitutionModel model = selectModelDialog.getModel(); |
| 473 |
if (selectModelDialog.getMakeCopy()) { |
| 474 |
model.setName(selectModelDialog.getName()); |
| 475 |
} |
| 476 |
|
| 477 |
for (AbstractPartitionData partition : selectedPartitionData) { |
| 478 |
partition.setPartitionSubstitutionModel(model); |
| 479 |
} |
| 480 |
} |
| 481 |
|
| 482 |
if (options.getPartitionSubstitutionModels(Microsatellite.INSTANCE).size() <= 1) { |
| 483 |
options.shareMicroSat = true; |
| 484 |
} |
| 485 |
|
| 486 |
modelsChanged(); |
| 487 |
|
| 488 |
fireDataChanged(); |
| 489 |
repaint(); |
| 490 |
} |
| 491 |
|
| 492 |
public void unlinkClockModels() { |
| 493 |
int[] selRows = dataTable.getSelectedRows(); |
| 494 |
for (int row : selRows) { |
| 495 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 496 |
|
| 497 |
PartitionClockModel clockModel = partition.getPartitionClockModel(); |
| 498 |
if (!clockModel.getName().equals(partition.getName())) { |
| 499 |
clockModel = new PartitionClockModel(options, partition.getName(), clockModel); |
| 500 |
partition.setPartitionClockModel(clockModel); |
| 501 |
} |
| 502 |
|
| 503 |
|
| 504 |
clockModel.setPartitionTreeModel(partition.getPartitionTreeModel()); |
| 505 |
} |
| 506 |
|
| 507 |
modelsChanged(); |
| 508 |
|
| 509 |
fireDataChanged(); |
| 510 |
repaint(); |
| 511 |
} |
| 512 |
|
| 513 |
public void linkClockModels() { |
| 514 |
int[] selRows = dataTable.getSelectedRows(); |
| 515 |
|
| 516 |
List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>(); |
| 517 |
for (int row : selRows) { |
| 518 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 519 |
|
| 520 |
if (!selectedPartitionData.contains(partition)) { |
| 521 |
selectedPartitionData.add(partition); |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
if (selectedPartitionData.size() > 1) { |
| 526 |
if (!options.hasIdenticalTaxa(selectedPartitionData)) { |
| 527 |
String errMsg = "To share a clock model, partitions need to have identical taxa."; |
| 528 |
JOptionPane.showMessageDialog(this, errMsg, "Unsuppoted Configuration", JOptionPane.ERROR_MESSAGE); |
| 529 |
return; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
|
| 534 |
Object[] modelArray = options.getPartitionClockModels(selectedPartitionData).toArray(); |
| 535 |
|
| 536 |
if (selectClockDialog == null) { |
| 537 |
selectClockDialog = new SelectClockDialog(frame); |
| 538 |
} |
| 539 |
|
| 540 |
int result = selectClockDialog.showDialog(modelArray); |
| 541 |
if (result != JOptionPane.CANCEL_OPTION) { |
| 542 |
PartitionClockModel clockModel = selectClockDialog.getModel(); |
| 543 |
if (selectClockDialog.getMakeCopy()) { |
| 544 |
clockModel.setName(selectClockDialog.getName()); |
| 545 |
} |
| 546 |
|
| 547 |
for (AbstractPartitionData partition : selectedPartitionData) { |
| 548 |
partition.setPartitionClockModel(clockModel); |
| 549 |
|
| 550 |
|
| 551 |
partition.setPartitionTreeModel(clockModel.getPartitionTreeModel()); |
| 552 |
} |
| 553 |
} |
| 554 |
|
| 555 |
modelsChanged(); |
| 556 |
|
| 557 |
fireDataChanged(); |
| 558 |
repaint(); |
| 559 |
} |
| 560 |
|
| 561 |
public void unlinkTreeModels() { |
| 562 |
int[] selRows = dataTable.getSelectedRows(); |
| 563 |
for (int row : selRows) { |
| 564 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 565 |
|
| 566 |
PartitionTreeModel treeModel = partition.getPartitionTreeModel(); |
| 567 |
if (!treeModel.getName().equals(partition.getName()) && partition.getTraits() == null) { |
| 568 |
treeModel = new PartitionTreeModel(options, partition.getName(), treeModel); |
| 569 |
partition.setPartitionTreeModel(treeModel); |
| 570 |
} |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
PartitionClockModel clockModel = partition.getPartitionClockModel(); |
| 576 |
if (!clockModel.getName().equals(partition.getName())) { |
| 577 |
clockModel = new PartitionClockModel(options, partition.getName(), clockModel); |
| 578 |
partition.setPartitionClockModel(clockModel); |
| 579 |
} |
| 580 |
|
| 581 |
clockModel.setPartitionTreeModel(treeModel); |
| 582 |
} |
| 583 |
|
| 584 |
|
| 585 |
options.linkTreePriors(frame.getCurrentPartitionTreePrior()); |
| 586 |
|
| 587 |
modelsChanged(); |
| 588 |
|
| 589 |
fireDataChanged(); |
| 590 |
repaint(); |
| 591 |
} |
| 592 |
|
| 593 |
public void linkTreeModels() { |
| 594 |
int[] selRows = dataTable.getSelectedRows(); |
| 595 |
|
| 596 |
List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>(); |
| 597 |
for (int row : selRows) { |
| 598 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 599 |
|
| 600 |
if (!selectedPartitionData.contains(partition)) |
| 601 |
selectedPartitionData.add(partition); |
| 602 |
} |
| 603 |
|
| 604 |
if (selectedPartitionData.size() > 1) { |
| 605 |
if (!options.hasIdenticalTaxa(selectedPartitionData)) { |
| 606 |
String errMsg = "To share a tree, partitions need to have identical taxa."; |
| 607 |
if (selectedPartitionData.get(0).getDataType().getType() == DataType.MICRO_SAT) |
| 608 |
errMsg += "\nThe data must be all diploid or all haploid when you want to link the tree."; |
| 609 |
JOptionPane.showMessageDialog(this, errMsg, "Unsuppoted Configuration", JOptionPane.ERROR_MESSAGE); |
| 610 |
return; |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
Object[] treeArray = options.getPartitionTreeModels(selectedPartitionData).toArray(); |
| 615 |
|
| 616 |
if (selectTreeDialog == null) { |
| 617 |
selectTreeDialog = new SelectTreeDialog(frame); |
| 618 |
} |
| 619 |
|
| 620 |
int result = selectTreeDialog.showDialog(treeArray); |
| 621 |
if (result != JOptionPane.CANCEL_OPTION) { |
| 622 |
PartitionTreeModel treeModel = selectTreeDialog.getTree(); |
| 623 |
if (selectTreeDialog.getMakeCopy()) { |
| 624 |
treeModel.setName(selectTreeDialog.getName()); |
| 625 |
} |
| 626 |
PartitionTreePrior prior = treeModel.getPartitionTreePrior(); |
| 627 |
options.linkTreePriors(prior); |
| 628 |
|
| 629 |
for (AbstractPartitionData partition : selectedPartitionData) { |
| 630 |
partition.setPartitionTreeModel(treeModel); |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
PartitionClockModel clockModel = partition.getPartitionClockModel(); |
| 635 |
clockModel.setPartitionTreeModel(treeModel); |
| 636 |
|
| 637 |
} |
| 638 |
|
| 639 |
for (Taxa taxa : options.taxonSets) { |
| 640 |
PartitionTreeModel prevModel = options.taxonSetsTreeModel.get(taxa); |
| 641 |
if (prevModel != treeModel) options.taxonSetsTreeModel.put(taxa, treeModel); |
| 642 |
} |
| 643 |
} |
| 644 |
|
| 645 |
modelsChanged(); |
| 646 |
|
| 647 |
fireDataChanged(); |
| 648 |
repaint(); |
| 649 |
} |
| 650 |
|
| 651 |
public void unlinkAll() { |
| 652 |
unlinkSubstitutionModels(); |
| 653 |
unlinkClockModels(); |
| 654 |
unlinkTreeModels(); |
| 655 |
} |
| 656 |
|
| 657 |
class DataTableModel extends AbstractTableModel { |
| 658 |
|
| 659 |
private static final long serialVersionUID = -6707994233020715574L; |
| 660 |
String[] columnNames = {"Partition Name", "File Name", "Taxa", "Sites", "Data Type", "Site Model", "Clock Model", "Partition Tree"}; |
| 661 |
|
| 662 |
public DataTableModel() { |
| 663 |
} |
| 664 |
|
| 665 |
public int getColumnCount() { |
| 666 |
return columnNames.length; |
| 667 |
} |
| 668 |
|
| 669 |
public int getRowCount() { |
| 670 |
if (options == null) return 0; |
| 671 |
|
| 672 |
return options.dataPartitions.size(); |
| 673 |
} |
| 674 |
|
| 675 |
public Object getValueAt(int row, int col) { |
| 676 |
|
| 677 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 678 |
switch (col) { |
| 679 |
case 0: |
| 680 |
return partition.getName(); |
| 681 |
case 1: |
| 682 |
return partition.getFileName(); |
| 683 |
case 2: |
| 684 |
return "" + (partition.getTaxonCount() >= 0 ? partition.getTaxonCount() : "-"); |
| 685 |
case 3: |
| 686 |
return "" + (partition.getSiteCount() >= 0 ? partition.getSiteCount() : "-"); |
| 687 |
case 4: |
| 688 |
return partition.getDataDescription(); |
| 689 |
case 5: |
| 690 |
|
| 691 |
|
| 692 |
return partition.getPartitionSubstitutionModel().getName(); |
| 693 |
case 6: |
| 694 |
return "" + (partition.getPartitionClockModel() != null ? partition.getPartitionClockModel().getName() : "-"); |
| 695 |
case 7: |
| 696 |
return partition.getPartitionTreeModel().getName(); |
| 697 |
default: |
| 698 |
throw new IllegalArgumentException("unknown column, " + col); |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
public void setValueAt(Object aValue, int row, int col) { |
| 703 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 704 |
switch (col) { |
| 705 |
case 0: |
| 706 |
String name = ((String) aValue).trim(); |
| 707 |
if (options.hasPartitionData(name)) { |
| 708 |
JOptionPane.showMessageDialog(frame, "Duplicate partition name.", |
| 709 |
"Illegal Argument Exception", JOptionPane.ERROR_MESSAGE); |
| 710 |
return; |
| 711 |
} |
| 712 |
if (name.length() > 0) { |
| 713 |
options.renamePartition(partition, name); |
| 714 |
} |
| 715 |
break; |
| 716 |
case 5: |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
if (((PartitionSubstitutionModel) aValue).getDataType().equals(partition.getDataType())) { |
| 721 |
partition.setPartitionSubstitutionModel((PartitionSubstitutionModel) aValue); |
| 722 |
} |
| 723 |
break; |
| 724 |
case 6: |
| 725 |
partition.setPartitionClockModel((PartitionClockModel) aValue); |
| 726 |
break; |
| 727 |
case 7: |
| 728 |
partition.setPartitionTreeModel((PartitionTreeModel) aValue); |
| 729 |
break; |
| 730 |
} |
| 731 |
fireDataChanged(); |
| 732 |
} |
| 733 |
|
| 734 |
public boolean isCellEditable(int row, int col) { |
| 735 |
boolean editable; |
| 736 |
|
| 737 |
AbstractPartitionData partition = options.dataPartitions.get(row); |
| 738 |
|
| 739 |
switch (col) { |
| 740 |
case 0: |
| 741 |
editable = true; |
| 742 |
break; |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
case 5: |
| 747 |
editable = partition.getDataType().getType() != DataType.CONTINUOUS; |
| 748 |
break; |
| 749 |
case 6: |
| 750 |
editable = partition.getDataType().getType() != DataType.CONTINUOUS; |
| 751 |
break; |
| 752 |
case 7: |
| 753 |
editable = true; |
| 754 |
break; |
| 755 |
default: |
| 756 |
editable = false; |
| 757 |
} |
| 758 |
|
| 759 |
return editable; |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
public String getColumnName(int column) { |
| 764 |
return columnNames[column]; |
| 765 |
} |
| 766 |
|
| 767 |
public Class getColumnClass(int c) { |
| 768 |
if (getRowCount() == 0) { |
| 769 |
return Object.class; |
| 770 |
} |
| 771 |
return getValueAt(0, c).getClass(); |
| 772 |
} |
| 773 |
|
| 774 |
public String toString() { |
| 775 |
StringBuffer buffer = new StringBuffer(); |
| 776 |
|
| 777 |
buffer.append(getColumnName(0)); |
| 778 |
for (int j = 1; j < getColumnCount(); j++) { |
| 779 |
buffer.append("\t"); |
| 780 |
buffer.append(getColumnName(j)); |
| 781 |
} |
| 782 |
buffer.append("\n"); |
| 783 |
|
| 784 |
for (int i = 0; i < getRowCount(); i++) { |
| 785 |
buffer.append(getValueAt(i, 0)); |
| 786 |
for (int j = 1; j < getColumnCount(); j++) { |
| 787 |
buffer.append("\t"); |
| 788 |
buffer.append(getValueAt(i, j)); |
| 789 |
} |
| 790 |
buffer.append("\n"); |
| 791 |
} |
| 792 |
|
| 793 |
return buffer.toString(); |
| 794 |
} |
| 795 |
} |
| 796 |
|
| 797 |
public class UnlinkModelsAction extends AbstractAction { |
| 798 |
public UnlinkModelsAction() { |
| 799 |
super("Unlink Subst. Models"); |
| 800 |
setToolTipText("Use this tool to use a different substitution model for each selected data partition"); |
| 801 |
} |
| 802 |
|
| 803 |
public void actionPerformed(ActionEvent ae) { |
| 804 |
unlinkSubstitutionModels(); |
| 805 |
} |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
public class LinkModelsAction extends AbstractAction { |
| 810 |
public LinkModelsAction() { |
| 811 |
super("Link Subst. Models"); |
| 812 |
setToolTipText("Use this tool to set all the selected partitions to the same substitution model"); |
| 813 |
} |
| 814 |
|
| 815 |
public void actionPerformed(ActionEvent ae) { |
| 816 |
linkSubstitutionModels(); |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
public class UnlinkClocksAction extends AbstractAction { |
| 821 |
public UnlinkClocksAction() { |
| 822 |
super("Unlink Clock Models"); |
| 823 |
setToolTipText("Use this tool to use a different clock model for each selected data partition"); |
| 824 |
} |
| 825 |
|
| 826 |
public void actionPerformed(ActionEvent ae) { |
| 827 |
unlinkClockModels(); |
| 828 |
} |
| 829 |
} |
| 830 |
|
| 831 |
|
| 832 |
public class LinkClocksAction extends AbstractAction { |
| 833 |
public LinkClocksAction() { |
| 834 |
super("Link Clock Models"); |
| 835 |
setToolTipText("Use this tool to set all the selected partitions to the same clock model"); |
| 836 |
} |
| 837 |
|
| 838 |
public void actionPerformed(ActionEvent ae) { |
| 839 |
linkClockModels(); |
| 840 |
} |
| 841 |
} |
| 842 |
|
| 843 |
public class UnlinkTreesAction extends AbstractAction { |
| 844 |
public UnlinkTreesAction() { |
| 845 |
super("Unlink Trees"); |
| 846 |
setToolTipText("Use this tool to use a different tree for each selected data partition"); |
| 847 |
} |
| 848 |
|
| 849 |
public void actionPerformed(ActionEvent ae) { |
| 850 |
unlinkTreeModels(); |
| 851 |
} |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
public class LinkTreesAction extends AbstractAction { |
| 856 |
public LinkTreesAction() { |
| 857 |
super("Link Trees"); |
| 858 |
setToolTipText("Use this tool to set all the selected partitions to the same tree"); |
| 859 |
} |
| 860 |
|
| 861 |
public void actionPerformed(ActionEvent ae) { |
| 862 |
linkTreeModels(); |
| 863 |
} |
| 864 |
} |
| 865 |
|
| 866 |
public class ViewPartitionAction extends AbstractAction { |
| 867 |
public ViewPartitionAction() { |
| 868 |
super("View Partition ..."); |
| 869 |
setToolTipText("View alignment in a window."); |
| 870 |
} |
| 871 |
|
| 872 |
public void actionPerformed(ActionEvent ae) { |
| 873 |
showAlignment(); |
| 874 |
} |
| 875 |
} |
| 876 |
|
| 877 |
public class CreateTraitPartitionAction extends AbstractAction { |
| 878 |
public CreateTraitPartitionAction() { |
| 879 |
super("Create partition from trait ..."); |
| 880 |
setToolTipText("Create a data partition from a trait. Traits can be defined in the Traits panel."); |
| 881 |
} |
| 882 |
|
| 883 |
public void actionPerformed(ActionEvent ae) { |
| 884 |
createFromTraits(null); |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
} |