| 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.taxonsetspanel; |
| 27 |
|
| 28 |
import dr.app.beauti.BeautiApp; |
| 29 |
import dr.app.beauti.BeautiFrame; |
| 30 |
import dr.app.beauti.BeautiPanel; |
| 31 |
import dr.app.beauti.ComboBoxRenderer; |
| 32 |
import dr.app.beauti.options.BeautiOptions; |
| 33 |
import dr.app.beauti.options.PartitionTreeModel; |
| 34 |
import dr.app.beauti.util.PanelUtils; |
| 35 |
import dr.app.gui.table.DateCellEditor; |
| 36 |
import dr.evolution.util.Taxa; |
| 37 |
import dr.evolution.util.Taxon; |
| 38 |
import dr.evolution.util.TaxonList; |
| 39 |
import dr.util.DataTable; |
| 40 |
import jam.framework.Exportable; |
| 41 |
import jam.panels.ActionPanel; |
| 42 |
import jam.table.TableRenderer; |
| 43 |
import jam.util.IconUtils; |
| 44 |
|
| 45 |
import javax.swing.*; |
| 46 |
import javax.swing.border.TitledBorder; |
| 47 |
import javax.swing.event.DocumentEvent; |
| 48 |
import javax.swing.event.DocumentListener; |
| 49 |
import javax.swing.event.ListSelectionEvent; |
| 50 |
import javax.swing.event.ListSelectionListener; |
| 51 |
import javax.swing.filechooser.FileNameExtensionFilter; |
| 52 |
import javax.swing.plaf.BorderUIResource; |
| 53 |
import javax.swing.table.AbstractTableModel; |
| 54 |
import javax.swing.table.JTableHeader; |
| 55 |
import javax.swing.table.TableColumn; |
| 56 |
import javax.swing.table.TableColumnModel; |
| 57 |
import java.awt.*; |
| 58 |
import java.awt.event.*; |
| 59 |
import java.io.File; |
| 60 |
import java.io.FileNotFoundException; |
| 61 |
import java.io.FileReader; |
| 62 |
import java.io.IOException; |
| 63 |
import java.util.*; |
| 64 |
import java.util.List; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public class TaxonSetPanel extends BeautiPanel implements Exportable { |
| 72 |
|
| 73 |
private static final long serialVersionUID = -3138832889782090814L; |
| 74 |
|
| 75 |
private final String[] columnToolTips = {null, |
| 76 |
"Enforce the selected taxon set to be monophyletic on the specified tree", |
| 77 |
"The tmrcaStatistic will represent that age of the parent node of the MRCA, rather than the MRCA itself", |
| 78 |
"Select the tree from which to report the MRCA of the taxa"}; |
| 79 |
|
| 80 |
protected String TAXA; |
| 81 |
protected String TAXON; |
| 82 |
|
| 83 |
protected BeautiFrame frame = null; |
| 84 |
protected BeautiOptions options = null; |
| 85 |
|
| 86 |
ImportTaxonSetsAction importTaxonSetsAction = new ImportTaxonSetsAction(); |
| 87 |
|
| 88 |
|
| 89 |
protected JTable taxonSetsTable = null; |
| 90 |
private TableColumnModel tableColumnModel; |
| 91 |
protected TaxonSetsTableModel taxonSetsTableModel = new TaxonSetsTableModel(); |
| 92 |
ComboBoxRenderer comboBoxRenderer = new ComboBoxRenderer(); |
| 93 |
|
| 94 |
protected JPanel taxonSetEditingPanel = null; |
| 95 |
|
| 96 |
protected Taxa currentTaxonSet = null; |
| 97 |
|
| 98 |
protected final List<Taxon> includedTaxa = new ArrayList<Taxon>(); |
| 99 |
protected final List<Taxon> excludedTaxa = new ArrayList<Taxon>(); |
| 100 |
|
| 101 |
private JTextField excludedTaxaSearchField = new JTextField(); |
| 102 |
|
| 103 |
protected JTable excludedTaxaTable = null; |
| 104 |
protected TaxaTableModel excludedTaxaTableModel = null; |
| 105 |
private JLabel excludedTaxaLabel = new JLabel(); |
| 106 |
protected JComboBox excludedTaxonSetsComboBox = null; |
| 107 |
protected boolean excludedSelectionChanging = false; |
| 108 |
|
| 109 |
private JTextField includedTaxaSearchField = new JTextField(); |
| 110 |
|
| 111 |
protected JTable includedTaxaTable = null; |
| 112 |
protected TaxaTableModel includedTaxaTableModel = null; |
| 113 |
private JLabel includedTaxaLabel = new JLabel(); |
| 114 |
protected JComboBox includedTaxonSetsComboBox = null; |
| 115 |
protected boolean includedSelectionChanging = false; |
| 116 |
|
| 117 |
public TaxonSetPanel() { |
| 118 |
} |
| 119 |
|
| 120 |
public TaxonSetPanel(BeautiFrame parent) { |
| 121 |
|
| 122 |
this.frame = parent; |
| 123 |
|
| 124 |
setText(false); |
| 125 |
|
| 126 |
|
| 127 |
initTaxonSetsTable(taxonSetsTableModel, columnToolTips); |
| 128 |
|
| 129 |
initTableColumn(); |
| 130 |
|
| 131 |
initPanel(addTaxonSetAction, removeTaxonSetAction); |
| 132 |
} |
| 133 |
|
| 134 |
protected void setText(boolean useStarBEAST) { |
| 135 |
if (useStarBEAST) { |
| 136 |
TAXA = "Species"; |
| 137 |
TAXON = "Species set"; |
| 138 |
} else { |
| 139 |
TAXA = "Taxa"; |
| 140 |
TAXON = "Taxon set"; |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
protected void initPanel(Action addTaxonSetAction, Action removeTaxonSetAction) { |
| 145 |
JScrollPane scrollPane1 = new JScrollPane(taxonSetsTable, |
| 146 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, |
| 147 |
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 148 |
|
| 149 |
JToolBar toolBar1 = new JToolBar(); |
| 150 |
toolBar1.setFloatable(false); |
| 151 |
toolBar1.setOpaque(false); |
| 152 |
toolBar1.setBorder(BorderFactory.createEmptyBorder()); |
| 153 |
|
| 154 |
toolBar1.setLayout(new FlowLayout(java.awt.FlowLayout.LEFT, 0, 0)); |
| 155 |
JButton button = new JButton(importTaxonSetsAction); |
| 156 |
PanelUtils.setupComponent(button); |
| 157 |
toolBar1.add(button); |
| 158 |
|
| 159 |
ActionPanel actionPanel1 = new ActionPanel(false); |
| 160 |
actionPanel1.setAddAction(addTaxonSetAction); |
| 161 |
actionPanel1.setRemoveAction(removeTaxonSetAction); |
| 162 |
|
| 163 |
addTaxonSetAction.setEnabled(false); |
| 164 |
removeTaxonSetAction.setEnabled(false); |
| 165 |
|
| 166 |
JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
| 167 |
controlPanel1.add(actionPanel1); |
| 168 |
|
| 169 |
|
| 170 |
excludedTaxaTableModel = new TaxaTableModel(false); |
| 171 |
excludedTaxaTable = new JTable(excludedTaxaTableModel); |
| 172 |
|
| 173 |
excludedTaxaTable.getColumnModel().getColumn(0).setCellRenderer( |
| 174 |
new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4))); |
| 175 |
excludedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20); |
| 176 |
|
| 177 |
excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
| 178 |
public void valueChanged(ListSelectionEvent evt) { |
| 179 |
excludedTaxaTableSelectionChanged(); |
| 180 |
} |
| 181 |
}); |
| 182 |
|
| 183 |
JScrollPane scrollPane2 = new JScrollPane(excludedTaxaTable, |
| 184 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, |
| 185 |
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 186 |
|
| 187 |
includedTaxonSetsComboBox = new JComboBox(new String[]{TAXON.toLowerCase() + "..."}); |
| 188 |
excludedTaxonSetsComboBox = new JComboBox(new String[]{TAXON.toLowerCase() + "..."}); |
| 189 |
|
| 190 |
includedTaxaLabel.setText(""); |
| 191 |
excludedTaxaLabel.setText(""); |
| 192 |
|
| 193 |
Box panel1 = new Box(BoxLayout.X_AXIS); |
| 194 |
panel1.add(new JLabel("Select: ")); |
| 195 |
panel1.setOpaque(false); |
| 196 |
excludedTaxonSetsComboBox.setOpaque(false); |
| 197 |
panel1.add(excludedTaxonSetsComboBox); |
| 198 |
|
| 199 |
|
| 200 |
includedTaxaTableModel = new TaxaTableModel(true); |
| 201 |
includedTaxaTable = new JTable(includedTaxaTableModel); |
| 202 |
|
| 203 |
includedTaxaTable.getColumnModel().getColumn(0).setCellRenderer( |
| 204 |
new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4))); |
| 205 |
includedTaxaTable.getColumnModel().getColumn(0).setMinWidth(20); |
| 206 |
|
| 207 |
includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
| 208 |
public void valueChanged(ListSelectionEvent evt) { |
| 209 |
includedTaxaTableSelectionChanged(); |
| 210 |
} |
| 211 |
}); |
| 212 |
includedTaxaTable.doLayout(); |
| 213 |
|
| 214 |
JScrollPane scrollPane3 = new JScrollPane(includedTaxaTable, |
| 215 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, |
| 216 |
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
| 217 |
|
| 218 |
Box panel2 = new Box(BoxLayout.X_AXIS); |
| 219 |
panel2.add(new JLabel("Select: ")); |
| 220 |
panel2.setOpaque(false); |
| 221 |
includedTaxonSetsComboBox.setOpaque(false); |
| 222 |
panel2.add(includedTaxonSetsComboBox); |
| 223 |
|
| 224 |
Icon includeIcon = null, excludeIcon = null; |
| 225 |
try { |
| 226 |
includeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/include.png")); |
| 227 |
excludeIcon = new ImageIcon(IconUtils.getImage(BeautiApp.class, "images/exclude.png")); |
| 228 |
} catch (Exception e) { |
| 229 |
|
| 230 |
} |
| 231 |
|
| 232 |
JPanel buttonPanel = createAddRemoveButtonPanel(includeTaxonAction, includeIcon, "Include selected " |
| 233 |
+ TAXA.toLowerCase() + " in the " + TAXON.toLowerCase(), |
| 234 |
excludeTaxonAction, excludeIcon, "Exclude selected " + TAXA.toLowerCase() |
| 235 |
+ " from the " + TAXON.toLowerCase(), BoxLayout.Y_AXIS); |
| 236 |
|
| 237 |
taxonSetEditingPanel = new JPanel(); |
| 238 |
taxonSetEditingPanel.setBorder(BorderFactory.createTitledBorder("")); |
| 239 |
taxonSetEditingPanel.setOpaque(false); |
| 240 |
taxonSetEditingPanel.setLayout(new GridBagLayout()); |
| 241 |
|
| 242 |
excludedTaxaSearchField.setColumns(12); |
| 243 |
|
| 244 |
excludedTaxaSearchField.putClientProperty("Quaqua.TextField.style","search"); |
| 245 |
excludedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant","small"); |
| 246 |
includedTaxaSearchField.setColumns(12); |
| 247 |
|
| 248 |
includedTaxaSearchField.putClientProperty("Quaqua.TextField.style","search"); |
| 249 |
includedTaxaSearchField.putClientProperty("Quaqua.TextField.sizeVariant","small"); |
| 250 |
|
| 251 |
GridBagConstraints c = new GridBagConstraints(); |
| 252 |
|
| 253 |
c.gridx = 0; |
| 254 |
c.gridy = 0; |
| 255 |
c.weightx = 0.5; |
| 256 |
c.weighty = 0; |
| 257 |
c.fill = GridBagConstraints.HORIZONTAL; |
| 258 |
c.anchor = GridBagConstraints.CENTER; |
| 259 |
c.insets = new Insets(3, 6, 3, 0); |
| 260 |
taxonSetEditingPanel.add(excludedTaxaSearchField, c); |
| 261 |
|
| 262 |
c.gridx = 0; |
| 263 |
c.gridy = 1; |
| 264 |
c.weightx = 0.5; |
| 265 |
c.weighty = 1; |
| 266 |
c.fill = GridBagConstraints.BOTH; |
| 267 |
c.anchor = GridBagConstraints.CENTER; |
| 268 |
c.insets = new Insets(0, 6, 0, 0); |
| 269 |
taxonSetEditingPanel.add(scrollPane2, c); |
| 270 |
|
| 271 |
c.gridx = 0; |
| 272 |
c.gridy = 2; |
| 273 |
c.weightx = 0.5; |
| 274 |
c.weighty = 0; |
| 275 |
c.fill = GridBagConstraints.HORIZONTAL; |
| 276 |
c.anchor = GridBagConstraints.CENTER; |
| 277 |
c.insets = new Insets(0, 6, 3, 0); |
| 278 |
taxonSetEditingPanel.add(excludedTaxaLabel, c); |
| 279 |
|
| 280 |
c.gridx = 0; |
| 281 |
c.gridy = 3; |
| 282 |
c.weightx = 0.5; |
| 283 |
c.weighty = 0; |
| 284 |
c.fill = GridBagConstraints.HORIZONTAL; |
| 285 |
c.anchor = GridBagConstraints.CENTER; |
| 286 |
c.insets = new Insets(0, 6, 3, 0); |
| 287 |
taxonSetEditingPanel.add(panel1, c); |
| 288 |
|
| 289 |
c.gridx = 1; |
| 290 |
c.gridy = 0; |
| 291 |
c.weightx = 0; |
| 292 |
c.weighty = 1; |
| 293 |
c.gridheight = 4; |
| 294 |
c.fill = GridBagConstraints.NONE; |
| 295 |
c.anchor = GridBagConstraints.CENTER; |
| 296 |
c.insets = new Insets(12, 2, 12, 4); |
| 297 |
taxonSetEditingPanel.add(buttonPanel, c); |
| 298 |
|
| 299 |
c.gridx = 2; |
| 300 |
c.gridy = 0; |
| 301 |
c.weightx = 0.5; |
| 302 |
c.weighty = 0; |
| 303 |
c.gridheight = 1; |
| 304 |
c.fill = GridBagConstraints.HORIZONTAL; |
| 305 |
c.anchor = GridBagConstraints.CENTER; |
| 306 |
c.insets = new Insets(3, 0, 3, 6); |
| 307 |
taxonSetEditingPanel.add(includedTaxaSearchField, c); |
| 308 |
|
| 309 |
c.gridx = 2; |
| 310 |
c.gridy = 1; |
| 311 |
c.weightx = 0.5; |
| 312 |
c.weighty = 1; |
| 313 |
c.fill = GridBagConstraints.BOTH; |
| 314 |
c.anchor = GridBagConstraints.CENTER; |
| 315 |
c.insets = new Insets(0, 0, 0, 6); |
| 316 |
taxonSetEditingPanel.add(scrollPane3, c); |
| 317 |
|
| 318 |
c.gridx = 2; |
| 319 |
c.gridy = 2; |
| 320 |
c.weightx = 0.5; |
| 321 |
c.weighty = 0; |
| 322 |
c.fill = GridBagConstraints.HORIZONTAL; |
| 323 |
c.anchor = GridBagConstraints.CENTER; |
| 324 |
c.insets = new Insets(0, 0, 3, 6); |
| 325 |
taxonSetEditingPanel.add(includedTaxaLabel, c); |
| 326 |
|
| 327 |
c.gridx = 2; |
| 328 |
c.gridy = 3; |
| 329 |
c.weightx = 0.5; |
| 330 |
c.weighty = 0; |
| 331 |
c.fill = GridBagConstraints.HORIZONTAL; |
| 332 |
c.anchor = GridBagConstraints.CENTER; |
| 333 |
c.insets = new Insets(0, 0, 3, 6); |
| 334 |
taxonSetEditingPanel.add(panel2, c); |
| 335 |
|
| 336 |
JPanel panel3 = new JPanel(); |
| 337 |
panel3.setOpaque(false); |
| 338 |
panel3.setLayout(new GridBagLayout()); |
| 339 |
c = new GridBagConstraints(); |
| 340 |
|
| 341 |
c.gridx = 0; |
| 342 |
c.gridy = 0; |
| 343 |
c.weightx = 0.5; |
| 344 |
c.weighty = 1; |
| 345 |
c.fill = GridBagConstraints.BOTH; |
| 346 |
c.anchor = GridBagConstraints.CENTER; |
| 347 |
c.insets = new Insets(0, 0, 2, 12); |
| 348 |
panel3.add(scrollPane1, c); |
| 349 |
|
| 350 |
c.gridx = 0; |
| 351 |
c.gridy = 1; |
| 352 |
c.weightx = 0; |
| 353 |
c.weighty = 0; |
| 354 |
c.fill = GridBagConstraints.NONE; |
| 355 |
c.anchor = GridBagConstraints.WEST; |
| 356 |
c.insets = new Insets(2, 0, 0, 12); |
| 357 |
panel3.add(actionPanel1, c); |
| 358 |
|
| 359 |
c.gridx = 1; |
| 360 |
c.gridy = 0; |
| 361 |
c.weightx = 0.5; |
| 362 |
c.weighty = 1; |
| 363 |
c.fill = GridBagConstraints.BOTH; |
| 364 |
c.anchor = GridBagConstraints.CENTER; |
| 365 |
c.insets = new Insets(0, 0, 0, 0); |
| 366 |
panel3.add(taxonSetEditingPanel, c); |
| 367 |
|
| 368 |
setOpaque(false); |
| 369 |
setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12))); |
| 370 |
setLayout(new BorderLayout(0, 0)); |
| 371 |
add(toolBar1, BorderLayout.NORTH); |
| 372 |
add(panel3, BorderLayout.CENTER); |
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
includedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() { |
| 385 |
public void changedUpdate(DocumentEvent e) { |
| 386 |
selectIncludedTaxa(includedTaxaSearchField.getText()); |
| 387 |
} |
| 388 |
|
| 389 |
public void removeUpdate(DocumentEvent e) { |
| 390 |
selectIncludedTaxa(includedTaxaSearchField.getText()); |
| 391 |
} |
| 392 |
|
| 393 |
public void insertUpdate(DocumentEvent e) { |
| 394 |
selectIncludedTaxa(includedTaxaSearchField.getText()); |
| 395 |
} |
| 396 |
} |
| 397 |
); |
| 398 |
excludedTaxaSearchField.getDocument().addDocumentListener(new DocumentListener() { |
| 399 |
public void changedUpdate(DocumentEvent e) { |
| 400 |
selectExcludedTaxa(excludedTaxaSearchField.getText()); |
| 401 |
} |
| 402 |
|
| 403 |
public void removeUpdate(DocumentEvent e) { |
| 404 |
selectExcludedTaxa(excludedTaxaSearchField.getText()); |
| 405 |
} |
| 406 |
|
| 407 |
public void insertUpdate(DocumentEvent e) { |
| 408 |
selectExcludedTaxa(excludedTaxaSearchField.getText()); |
| 409 |
} |
| 410 |
} |
| 411 |
); |
| 412 |
|
| 413 |
|
| 414 |
includedTaxaTable.addMouseListener(new MouseAdapter() { |
| 415 |
public void mouseClicked(MouseEvent e) { |
| 416 |
if (e.getClickCount() == 2) { |
| 417 |
includeSelectedTaxa(); |
| 418 |
} |
| 419 |
} |
| 420 |
}); |
| 421 |
excludedTaxaTable.addMouseListener(new MouseAdapter() { |
| 422 |
public void mouseClicked(MouseEvent e) { |
| 423 |
if (e.getClickCount() == 2) { |
| 424 |
excludeSelectedTaxa(); |
| 425 |
} |
| 426 |
} |
| 427 |
}); |
| 428 |
|
| 429 |
includedTaxaTable.addFocusListener(new FocusAdapter() { |
| 430 |
public void focusGained(FocusEvent focusEvent) { |
| 431 |
excludedTaxaTable.clearSelection(); |
| 432 |
} |
| 433 |
}); |
| 434 |
excludedTaxaTable.addFocusListener(new FocusAdapter() { |
| 435 |
public void focusGained(FocusEvent focusEvent) { |
| 436 |
includedTaxaTable.clearSelection(); |
| 437 |
} |
| 438 |
}); |
| 439 |
|
| 440 |
includedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
| 441 |
public void valueChanged(ListSelectionEvent e) { |
| 442 |
if (!includedSelectionChanging) { |
| 443 |
if (includedTaxonSetsComboBox.getSelectedIndex() != 0) { |
| 444 |
includedTaxonSetsComboBox.setSelectedIndex(0); |
| 445 |
} |
| 446 |
includedTaxaSearchField.setText(""); |
| 447 |
} |
| 448 |
} |
| 449 |
}); |
| 450 |
includedTaxonSetsComboBox.addItemListener(new ItemListener() { |
| 451 |
public void itemStateChanged(ItemEvent e) { |
| 452 |
includedSelectionChanging = true; |
| 453 |
includedTaxaTable.clearSelection(); |
| 454 |
if (includedTaxonSetsComboBox.getSelectedIndex() > 0) { |
| 455 |
String taxaName = includedTaxonSetsComboBox.getSelectedItem().toString(); |
| 456 |
if (!taxaName.endsWith("...")) { |
| 457 |
Taxa taxa = options.getTaxa(taxaName); |
| 458 |
if (taxa != null) { |
| 459 |
for (int i = 0; i < taxa.getTaxonCount(); i++) { |
| 460 |
Taxon taxon = taxa.getTaxon(i); |
| 461 |
int index = includedTaxa.indexOf(taxon); |
| 462 |
includedTaxaTable.getSelectionModel().addSelectionInterval(index, index); |
| 463 |
|
| 464 |
} |
| 465 |
} |
| 466 |
} |
| 467 |
} |
| 468 |
includedSelectionChanging = false; |
| 469 |
} |
| 470 |
}); |
| 471 |
|
| 472 |
excludedTaxaTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
| 473 |
public void valueChanged(ListSelectionEvent e) { |
| 474 |
if (!excludedSelectionChanging) { |
| 475 |
if (excludedTaxonSetsComboBox.getSelectedIndex() != 0) { |
| 476 |
excludedTaxonSetsComboBox.setSelectedIndex(0); |
| 477 |
} |
| 478 |
excludedTaxaSearchField.setText(""); |
| 479 |
} |
| 480 |
|
| 481 |
} |
| 482 |
}); |
| 483 |
excludedTaxonSetsComboBox.addItemListener(new ItemListener() { |
| 484 |
public void itemStateChanged(ItemEvent e) { |
| 485 |
excludedSelectionChanging = true; |
| 486 |
excludedTaxaTable.clearSelection(); |
| 487 |
if (excludedTaxonSetsComboBox.getSelectedIndex() > 0) { |
| 488 |
String taxaName = excludedTaxonSetsComboBox.getSelectedItem().toString(); |
| 489 |
if (!taxaName.endsWith("...")) { |
| 490 |
Taxa taxa = options.getTaxa(taxaName); |
| 491 |
if (taxa != null) { |
| 492 |
for (int i = 0; i < taxa.getTaxonCount(); i++) { |
| 493 |
Taxon taxon = taxa.getTaxon(i); |
| 494 |
int index = excludedTaxa.indexOf(taxon); |
| 495 |
excludedTaxaTable.getSelectionModel().addSelectionInterval(index, index); |
| 496 |
|
| 497 |
} |
| 498 |
} |
| 499 |
} |
| 500 |
} |
| 501 |
excludedSelectionChanging = false; |
| 502 |
} |
| 503 |
}); |
| 504 |
|
| 505 |
includedTaxaTable.doLayout(); |
| 506 |
excludedTaxaTable.doLayout(); |
| 507 |
} |
| 508 |
|
| 509 |
private void selectIncludedTaxa(String text) { |
| 510 |
includedSelectionChanging = true; |
| 511 |
includedTaxaTable.clearSelection(); |
| 512 |
int index = 0; |
| 513 |
for (Taxon taxon : includedTaxa) { |
| 514 |
if (taxon.getId().contains(text)) { |
| 515 |
includedTaxaTable.getSelectionModel().addSelectionInterval(index, index); |
| 516 |
} |
| 517 |
index ++; |
| 518 |
|
| 519 |
} |
| 520 |
includedSelectionChanging = false; |
| 521 |
} |
| 522 |
|
| 523 |
private void selectExcludedTaxa(String text) { |
| 524 |
excludedSelectionChanging = true; |
| 525 |
excludedTaxaTable.clearSelection(); |
| 526 |
int index = 0; |
| 527 |
for (Taxon taxon : excludedTaxa) { |
| 528 |
if (taxon.getId().contains(text)) { |
| 529 |
excludedTaxaTable.getSelectionModel().addSelectionInterval(index, index); |
| 530 |
} |
| 531 |
index ++; |
| 532 |
|
| 533 |
} |
| 534 |
excludedSelectionChanging = false; |
| 535 |
|
| 536 |
} |
| 537 |
|
| 538 |
protected void initTableColumn() { |
| 539 |
tableColumnModel = taxonSetsTable.getColumnModel(); |
| 540 |
TableColumn tableColumn = tableColumnModel.getColumn(0); |
| 541 |
tableColumn.setCellRenderer(new TableRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4))); |
| 542 |
tableColumn.setMinWidth(20); |
| 543 |
|
| 544 |
tableColumn = tableColumnModel.getColumn(1); |
| 545 |
tableColumn.setPreferredWidth(20); |
| 546 |
tableColumn = tableColumnModel.getColumn(2); |
| 547 |
tableColumn.setPreferredWidth(20); |
| 548 |
|
| 549 |
tableColumn = tableColumnModel.getColumn(3); |
| 550 |
comboBoxRenderer.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); |
| 551 |
tableColumn.setCellRenderer(comboBoxRenderer); |
| 552 |
tableColumn.setPreferredWidth(30); |
| 553 |
|
| 554 |
tableColumn = tableColumnModel.getColumn(4); |
| 555 |
tableColumn.setCellEditor(new DateCellEditor(true)); |
| 556 |
tableColumn.setPreferredWidth(30); |
| 557 |
} |
| 558 |
|
| 559 |
protected void initTaxonSetsTable(AbstractTableModel tableModel, final String[] columnToolTips) { |
| 560 |
taxonSetsTable = new JTable(tableModel) { |
| 561 |
|
| 562 |
protected JTableHeader createDefaultTableHeader() { |
| 563 |
return new JTableHeader(columnModel) { |
| 564 |
public String getToolTipText(MouseEvent e) { |
| 565 |
Point p = e.getPoint(); |
| 566 |
int index = columnModel.getColumnIndexAtX(p.x); |
| 567 |
int realIndex = columnModel.getColumn(index).getModelIndex(); |
| 568 |
return columnToolTips[realIndex]; |
| 569 |
} |
| 570 |
}; |
| 571 |
} |
| 572 |
}; |
| 573 |
taxonSetsTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); |
| 574 |
|
| 575 |
taxonSetsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { |
| 576 |
public void valueChanged(ListSelectionEvent evt) { |
| 577 |
taxonSetsTableSelectionChanged(); |
| 578 |
} |
| 579 |
}); |
| 580 |
taxonSetsTable.doLayout(); |
| 581 |
} |
| 582 |
|
| 583 |
protected void taxonSetChanged() { |
| 584 |
currentTaxonSet.removeAllTaxa(); |
| 585 |
for (Taxon anIncludedTaxa : includedTaxa) { |
| 586 |
currentTaxonSet.addTaxon(anIncludedTaxa); |
| 587 |
} |
| 588 |
|
| 589 |
setupTaxonSetsComboBoxes(); |
| 590 |
|
| 591 |
includedTaxaLabel.setText("" + includedTaxa.size() + " taxa included"); |
| 592 |
excludedTaxaLabel.setText("" + excludedTaxa.size() + " taxa excluded"); |
| 593 |
|
| 594 |
if (options.taxonSetsMono.get(currentTaxonSet) != null && |
| 595 |
options.taxonSetsMono.get(currentTaxonSet) && |
| 596 |
!checkCompatibility(currentTaxonSet)) { |
| 597 |
options.taxonSetsMono.put(currentTaxonSet, Boolean.FALSE); |
| 598 |
} |
| 599 |
|
| 600 |
frame.setAllOptions(); |
| 601 |
frame.setDirty(); |
| 602 |
} |
| 603 |
|
| 604 |
protected void treeModelsChanged() { |
| 605 |
Object[] modelArray = options.getPartitionTreeModels().toArray(); |
| 606 |
TableColumn col = tableColumnModel.getColumn(3); |
| 607 |
col.setCellEditor(new DefaultCellEditor(new JComboBox(modelArray))); |
| 608 |
} |
| 609 |
|
| 610 |
protected void resetPanel() { |
| 611 |
if (!options.hasData() || options.taxonSets == null || options.taxonSets.size() < 1) { |
| 612 |
setCurrentTaxonSet(null); |
| 613 |
} |
| 614 |
} |
| 615 |
|
| 616 |
public void setOptions(BeautiOptions options) { |
| 617 |
|
| 618 |
this.options = options; |
| 619 |
|
| 620 |
resetPanel(); |
| 621 |
|
| 622 |
if (options.taxonSets == null) { |
| 623 |
addTaxonSetAction.setEnabled(false); |
| 624 |
removeTaxonSetAction.setEnabled(false); |
| 625 |
} else { |
| 626 |
addTaxonSetAction.setEnabled(options.hasData()); |
| 627 |
} |
| 628 |
|
| 629 |
taxonSetsTableModel.fireTableDataChanged(); |
| 630 |
} |
| 631 |
|
| 632 |
public void getOptions(BeautiOptions options) { |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
} |
| 637 |
|
| 638 |
public JComponent getExportableComponent() { |
| 639 |
return taxonSetsTable; |
| 640 |
} |
| 641 |
|
| 642 |
protected void taxonSetsTableSelectionChanged() { |
| 643 |
treeModelsChanged(); |
| 644 |
|
| 645 |
int[] rows = taxonSetsTable.getSelectedRows(); |
| 646 |
if (rows.length == 0) { |
| 647 |
removeTaxonSetAction.setEnabled(false); |
| 648 |
} else if (rows.length == 1) { |
| 649 |
currentTaxonSet = options.taxonSets.get(rows[0]); |
| 650 |
setCurrentTaxonSet(currentTaxonSet); |
| 651 |
removeTaxonSetAction.setEnabled(true); |
| 652 |
} else { |
| 653 |
setCurrentTaxonSet(null); |
| 654 |
removeTaxonSetAction.setEnabled(true); |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
Action addTaxonSetAction = new AbstractAction("+") { |
| 671 |
|
| 672 |
private static final long serialVersionUID = 20273987098143413L; |
| 673 |
|
| 674 |
public void actionPerformed(ActionEvent ae) { |
| 675 |
int taxonSetCount = options.taxonSets.size(); |
| 676 |
|
| 677 |
String newTaxonSetName = "untitled" + taxonSetCount; |
| 678 |
Taxa newTaxonSet = new Taxa(newTaxonSetName); |
| 679 |
|
| 680 |
options.taxonSets.add(newTaxonSet); |
| 681 |
Collections.sort(options.taxonSets); |
| 682 |
|
| 683 |
options.taxonSetsMono.put(newTaxonSet, Boolean.FALSE); |
| 684 |
options.taxonSetsIncludeStem.put(newTaxonSet, Boolean.FALSE); |
| 685 |
|
| 686 |
options.taxonSetsTreeModel.put(newTaxonSet, options.getPartitionTreeModels().get(0)); |
| 687 |
|
| 688 |
setCurrentTaxonSet(newTaxonSet); |
| 689 |
|
| 690 |
taxonSetChanged(); |
| 691 |
|
| 692 |
taxonSetsTableModel.fireTableDataChanged(); |
| 693 |
|
| 694 |
int sel = options.getTaxaIndex(newTaxonSetName); |
| 695 |
if (sel < 0) { |
| 696 |
taxonSetsTable.setRowSelectionInterval(0, 0); |
| 697 |
} else { |
| 698 |
taxonSetsTable.setRowSelectionInterval(sel, sel); |
| 699 |
} |
| 700 |
} |
| 701 |
}; |
| 702 |
|
| 703 |
Action removeTaxonSetAction = new AbstractAction("-") { |
| 704 |
|
| 705 |
private static final long serialVersionUID = 6077578872870122265L; |
| 706 |
|
| 707 |
public void actionPerformed(ActionEvent ae) { |
| 708 |
int row = taxonSetsTable.getSelectedRow(); |
| 709 |
if (row != -1) { |
| 710 |
Taxa taxa = options.taxonSets.remove(row); |
| 711 |
options.taxonSetsMono.remove(taxa); |
| 712 |
options.taxonSetsIncludeStem.remove(taxa); |
| 713 |
} |
| 714 |
taxonSetChanged(); |
| 715 |
|
| 716 |
taxonSetsTableModel.fireTableDataChanged(); |
| 717 |
|
| 718 |
if (row >= options.taxonSets.size()) { |
| 719 |
row = options.taxonSets.size() - 1; |
| 720 |
} |
| 721 |
if (row >= 0) { |
| 722 |
taxonSetsTable.setRowSelectionInterval(row, row); |
| 723 |
} else { |
| 724 |
setCurrentTaxonSet(null); |
| 725 |
} |
| 726 |
} |
| 727 |
}; |
| 728 |
|
| 729 |
protected void setCurrentTaxonSet(Taxa taxonSet) { |
| 730 |
|
| 731 |
this.currentTaxonSet = taxonSet; |
| 732 |
|
| 733 |
includedTaxa.clear(); |
| 734 |
excludedTaxa.clear(); |
| 735 |
|
| 736 |
if (currentTaxonSet != null) { |
| 737 |
for (int i = 0; i < taxonSet.getTaxonCount(); i++) { |
| 738 |
includedTaxa.add(taxonSet.getTaxon(i)); |
| 739 |
} |
| 740 |
Collections.sort(includedTaxa); |
| 741 |
|
| 742 |
|
| 743 |
PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(currentTaxonSet); |
| 744 |
TaxonList alignment = options.getDataPartitions(treeModel).get(0).getTaxonList(); |
| 745 |
Taxa taxa = new Taxa(alignment); |
| 746 |
for (int i = 0; i < taxa.getTaxonCount(); i++) { |
| 747 |
excludedTaxa.add(taxa.getTaxon(i)); |
| 748 |
} |
| 749 |
excludedTaxa.removeAll(includedTaxa); |
| 750 |
Collections.sort(excludedTaxa); |
| 751 |
} |
| 752 |
|
| 753 |
setTaxonSetTitle(); |
| 754 |
|
| 755 |
setupTaxonSetsComboBoxes(); |
| 756 |
|
| 757 |
includedTaxaTableModel.fireTableDataChanged(); |
| 758 |
excludedTaxaTableModel.fireTableDataChanged(); |
| 759 |
} |
| 760 |
|
| 761 |
protected void setTaxonSetTitle() { |
| 762 |
|
| 763 |
if (currentTaxonSet == null) { |
| 764 |
taxonSetEditingPanel.setBorder(BorderFactory.createTitledBorder("")); |
| 765 |
taxonSetEditingPanel.setEnabled(false); |
| 766 |
} else { |
| 767 |
taxonSetEditingPanel.setEnabled(true); |
| 768 |
taxonSetEditingPanel.setBorder(new TitledBorder(null, TAXON + ": " + currentTaxonSet.getId(), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.ABOVE_TOP)); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
protected void setupTaxonSetsComboBoxes() { |
| 774 |
setupTaxonSetsComboBox(excludedTaxonSetsComboBox, excludedTaxa); |
| 775 |
excludedTaxonSetsComboBox.setSelectedIndex(0); |
| 776 |
setupTaxonSetsComboBox(includedTaxonSetsComboBox, includedTaxa); |
| 777 |
includedTaxonSetsComboBox.setSelectedIndex(0); |
| 778 |
} |
| 779 |
|
| 780 |
protected void setupTaxonSetsComboBox(JComboBox comboBox, List<Taxon> availableTaxa) { |
| 781 |
comboBox.removeAllItems(); |
| 782 |
|
| 783 |
comboBox.addItem(TAXON.toLowerCase() + "..."); |
| 784 |
for (Taxa taxa : options.taxonSets) { |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
comboBox.addItem(taxa.getId()); |
| 790 |
|
| 791 |
|
| 792 |
} |
| 793 |
} |
| 794 |
|
| 795 |
public void importTaxonSets() { |
| 796 |
|
| 797 |
File[] files = frame.selectImportFiles("Import Taxon Set File...", false, new FileNameExtensionFilter[]{ |
| 798 |
new FileNameExtensionFilter("Tab-delimited text files", "txt", "tab", "dat")}); |
| 799 |
|
| 800 |
DataTable<String[]> dataTable; |
| 801 |
|
| 802 |
if (files != null && files.length != 0) { |
| 803 |
try { |
| 804 |
|
| 805 |
dataTable = DataTable.Text.parse(new FileReader(files[0]), false, true, false, false); |
| 806 |
|
| 807 |
} catch (FileNotFoundException fnfe) { |
| 808 |
JOptionPane.showMessageDialog(this, "Unable to open file: File not found", |
| 809 |
"Unable to open file", |
| 810 |
JOptionPane.ERROR_MESSAGE); |
| 811 |
return; |
| 812 |
} catch (IOException ioe) { |
| 813 |
JOptionPane.showMessageDialog(this, "Unable to read file: " + ioe.getMessage(), |
| 814 |
"Unable to read file", |
| 815 |
JOptionPane.ERROR_MESSAGE); |
| 816 |
return; |
| 817 |
} catch (Exception ex) { |
| 818 |
ex.printStackTrace(System.err); |
| 819 |
JOptionPane.showMessageDialog(this, "Fatal exception: " + ex, |
| 820 |
"Error reading file", |
| 821 |
JOptionPane.ERROR_MESSAGE); |
| 822 |
ex.printStackTrace(); |
| 823 |
return; |
| 824 |
} |
| 825 |
} else { |
| 826 |
return; |
| 827 |
} |
| 828 |
|
| 829 |
String[] taxonNames = dataTable.getRowLabels(); |
| 830 |
|
| 831 |
if (dataTable.getColumnCount() == 0) { |
| 832 |
String name = files[0].getName(); |
| 833 |
int lastDot = name.lastIndexOf('.'); |
| 834 |
if (lastDot >= 1) { |
| 835 |
name = name.substring(0, lastDot); |
| 836 |
} |
| 837 |
|
| 838 |
Taxa taxa = new Taxa(); |
| 839 |
|
| 840 |
|
| 841 |
for (String taxonName : taxonNames) { |
| 842 |
final int index = options.taxonList.getTaxonIndex(taxonName); |
| 843 |
if (index >= 0) { |
| 844 |
taxa.addTaxon(options.taxonList.getTaxon(index)); |
| 845 |
} |
| 846 |
} |
| 847 |
taxa.setId(name); |
| 848 |
options.taxonSets.add(taxa); |
| 849 |
options.taxonSetsTreeModel.put(taxa, options.getPartitionTreeModels().get(0)); |
| 850 |
} else { |
| 851 |
|
| 852 |
String[] taxonSetNames = dataTable.getColumn(0); |
| 853 |
|
| 854 |
Map<String, Taxa> taxonSets = new HashMap<String, Taxa>(); |
| 855 |
|
| 856 |
int i = 0; |
| 857 |
for (String taxonName : taxonNames) { |
| 858 |
final int index = options.taxonList.getTaxonIndex(taxonName); |
| 859 |
if (index >= 0) { |
| 860 |
Taxa taxa = taxonSets.get(taxonSetNames[i]); |
| 861 |
if (taxa == null) { |
| 862 |
taxa = new Taxa(); |
| 863 |
taxa.setId(taxonSetNames[i]); |
| 864 |
taxonSets.put(taxonSetNames[i], taxa); |
| 865 |
} |
| 866 |
taxa.addTaxon(options.taxonList.getTaxon(index)); |
| 867 |
} |
| 868 |
i++; |
| 869 |
} |
| 870 |
|
| 871 |
for (Taxa taxa : taxonSets.values()) { |
| 872 |
options.taxonSets.add(taxa); |
| 873 |
options.taxonSetsTreeModel.put(taxa, options.getPartitionTreeModels().get(0)); |
| 874 |
options.taxonSetsMono.put(taxa, false); |
| 875 |
options.taxonSetsIncludeStem.put(taxa, false); |
| 876 |
options.taxonSetsHeights.put(taxa, 0.0); |
| 877 |
} |
| 878 |
} |
| 879 |
|
| 880 |
taxonSetsTableModel.fireTableDataChanged(); |
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
protected boolean isCompatible(Taxa taxa, List<Taxon> availableTaxa) { |
| 892 |
|
| 893 |
for (int i = 0; i < taxa.getTaxonCount(); i++) { |
| 894 |
Taxon taxon = taxa.getTaxon(i); |
| 895 |
if (!availableTaxa.contains(taxon)) { |
| 896 |
return false; |
| 897 |
} |
| 898 |
} |
| 899 |
return true; |
| 900 |
} |
| 901 |
|
| 902 |
protected boolean checkCompatibility(Taxa taxa) { |
| 903 |
for (Taxa taxa2 : options.taxonSets) { |
| 904 |
if (taxa2 != taxa && options.taxonSetsMono.get(taxa2) |
| 905 |
&& options.taxonSetsTreeModel.get(taxa) == options.taxonSetsTreeModel.get(taxa2)) { |
| 906 |
if (taxa.containsAny(taxa2) && !taxa.containsAll(taxa2) && !taxa2.containsAll(taxa)) { |
| 907 |
JOptionPane.showMessageDialog(frame, |
| 908 |
"You cannot enforce monophyly on this " + TAXON.toLowerCase() + " \n" + |
| 909 |
"because it is not compatible with another " + TAXON.toLowerCase() + ",\n" + |
| 910 |
taxa2.getId() + ", for which monophyly is\n" + "enforced.", |
| 911 |
"Warning", |
| 912 |
JOptionPane.WARNING_MESSAGE); |
| 913 |
return false; |
| 914 |
} |
| 915 |
} |
| 916 |
} |
| 917 |
return true; |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
protected class TaxonSetsTableModel extends AbstractTableModel { |
| 924 |
private static final long serialVersionUID = 3318461381525023153L; |
| 925 |
|
| 926 |
String[] columnNames = {"Taxon Set", "Mono?", "Stem?", "Tree", "Age"}; |
| 927 |
|
| 928 |
public TaxonSetsTableModel() { |
| 929 |
} |
| 930 |
|
| 931 |
public int getColumnCount() { |
| 932 |
return columnNames.length; |
| 933 |
} |
| 934 |
|
| 935 |
public String getColumnName(int column) { |
| 936 |
return columnNames[column]; |
| 937 |
} |
| 938 |
|
| 939 |
public int getRowCount() { |
| 940 |
if (options == null) return 0; |
| 941 |
return options.taxonSets.size(); |
| 942 |
} |
| 943 |
|
| 944 |
public Object getValueAt(int rowIndex, int columnIndex) { |
| 945 |
Taxa taxonSet = options.taxonSets.get(rowIndex); |
| 946 |
switch (columnIndex) { |
| 947 |
case 0: |
| 948 |
return taxonSet.getId(); |
| 949 |
case 1: |
| 950 |
return options.taxonSetsMono.get(taxonSet); |
| 951 |
case 2: |
| 952 |
return options.taxonSetsIncludeStem.get(taxonSet); |
| 953 |
case 3: |
| 954 |
return options.taxonSetsTreeModel.get(taxonSet); |
| 955 |
case 4: |
| 956 |
return options.taxonSetsHeights.get(taxonSet); |
| 957 |
default: |
| 958 |
throw new IllegalArgumentException("unknown column, " + columnIndex); |
| 959 |
} |
| 960 |
} |
| 961 |
|
| 962 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
| 963 |
Taxa taxonSet = options.taxonSets.get(rowIndex); |
| 964 |
switch (columnIndex) { |
| 965 |
case 0: |
| 966 |
taxonSet.setId(aValue.toString()); |
| 967 |
options.renameTMRCAStatistic(taxonSet); |
| 968 |
setTaxonSetTitle(); |
| 969 |
break; |
| 970 |
|
| 971 |
case 1: |
| 972 |
if ((Boolean) aValue) { |
| 973 |
Taxa taxa = options.taxonSets.get(rowIndex); |
| 974 |
if (checkCompatibility(taxa)) { |
| 975 |
options.taxonSetsMono.put(taxonSet, (Boolean) aValue); |
| 976 |
} |
| 977 |
} else { |
| 978 |
options.taxonSetsMono.put(taxonSet, (Boolean) aValue); |
| 979 |
} |
| 980 |
break; |
| 981 |
|
| 982 |
case 2: |
| 983 |
options.taxonSetsIncludeStem.put(taxonSet, (Boolean) aValue); |
| 984 |
break; |
| 985 |
case 3: |
| 986 |
options.taxonSetsTreeModel.put(taxonSet, (PartitionTreeModel) aValue); |
| 987 |
this.fireTableDataChanged(); |
| 988 |
taxonSetsTable.getSelectionModel().setSelectionInterval(rowIndex, rowIndex); |
| 989 |
break; |
| 990 |
case 4: |
| 991 |
options.taxonSetsHeights.put(taxonSet, (Double) aValue); |
| 992 |
this.fireTableDataChanged(); |
| 993 |
taxonSetsTable.getSelectionModel().setSelectionInterval(rowIndex, rowIndex); |
| 994 |
break; |
| 995 |
default: |
| 996 |
throw new IllegalArgumentException("unknown column, " + columnIndex); |
| 997 |
} |
| 998 |
} |
| 999 |
|
| 1000 |
public boolean isCellEditable(int row, int col) { |
| 1001 |
return true; |
| 1002 |
} |
| 1003 |
|
| 1004 |
public Class getColumnClass(int columnIndex) { |
| 1005 |
switch (columnIndex) { |
| 1006 |
case 0: |
| 1007 |
return String.class; |
| 1008 |
case 1: |
| 1009 |
case 2: |
| 1010 |
return Boolean.class; |
| 1011 |
case 3: |
| 1012 |
return String.class; |
| 1013 |
case 4: |
| 1014 |
return Double.class; |
| 1015 |
default: |
| 1016 |
throw new IllegalArgumentException("unknown column, " + columnIndex); |
| 1017 |
} |
| 1018 |
} |
| 1019 |
} |
| 1020 |
|
| 1021 |
protected JPanel createAddRemoveButtonPanel(Action addAction, Icon addIcon, String addToolTip, |
| 1022 |
Action removeAction, Icon removeIcon, String removeToolTip, int axis) { |
| 1023 |
|
| 1024 |
JPanel buttonPanel = new JPanel(); |
| 1025 |
buttonPanel.setLayout(new BoxLayout(buttonPanel, axis)); |
| 1026 |
buttonPanel.setOpaque(false); |
| 1027 |
JButton addButton = new JButton(addAction); |
| 1028 |
if (addIcon != null) { |
| 1029 |
addButton.setIcon(addIcon); |
| 1030 |
addButton.setText(null); |
| 1031 |
} |
| 1032 |
addButton.setToolTipText(addToolTip); |
| 1033 |
addButton.putClientProperty("JButton.buttonType", "roundRect"); |
| 1034 |
|
| 1035 |
addButton.setOpaque(false); |
| 1036 |
addAction.setEnabled(false); |
| 1037 |
|
| 1038 |
JButton removeButton = new JButton(removeAction); |
| 1039 |
if (removeIcon != null) { |
| 1040 |
removeButton.setIcon(removeIcon); |
| 1041 |
removeButton.setText(null); |
| 1042 |
} |
| 1043 |
removeButton.setToolTipText(removeToolTip); |
| 1044 |
removeButton.putClientProperty("JButton.buttonType", "roundRect"); |
| 1045 |
|
| 1046 |
removeButton.setOpaque(false); |
| 1047 |
removeAction.setEnabled(false); |
| 1048 |
|
| 1049 |
buttonPanel.add(addButton); |
| 1050 |
buttonPanel.add(new JToolBar.Separator(new Dimension(6, 6))); |
| 1051 |
buttonPanel.add(removeButton); |
| 1052 |
|
| 1053 |
return buttonPanel; |
| 1054 |
} |
| 1055 |
|
| 1056 |
private void excludedTaxaTableSelectionChanged() { |
| 1057 |
if (excludedTaxaTable.getSelectedRowCount() == 0) { |
| 1058 |
includeTaxonAction.setEnabled(false); |
| 1059 |
} else { |
| 1060 |
includeTaxonAction.setEnabled(true); |
| 1061 |
} |
| 1062 |
} |
| 1063 |
|
| 1064 |
private void includedTaxaTableSelectionChanged() { |
| 1065 |
if (includedTaxaTable.getSelectedRowCount() == 0) { |
| 1066 |
excludeTaxonAction.setEnabled(false); |
| 1067 |
} else { |
| 1068 |
excludeTaxonAction.setEnabled(true); |
| 1069 |
} |
| 1070 |
} |
| 1071 |
|
| 1072 |
private void includeSelectedTaxa() { |
| 1073 |
int[] rows = excludedTaxaTable.getSelectedRows(); |
| 1074 |
|
| 1075 |
List<Taxon> transfer = new ArrayList<Taxon>(); |
| 1076 |
|
| 1077 |
for (int r : rows) { |
| 1078 |
transfer.add(excludedTaxa.get(r)); |
| 1079 |
} |
| 1080 |
|
| 1081 |
includedTaxa.addAll(transfer); |
| 1082 |
Collections.sort(includedTaxa); |
| 1083 |
|
| 1084 |
excludedTaxa.removeAll(includedTaxa); |
| 1085 |
|
| 1086 |
includedTaxaTableModel.fireTableDataChanged(); |
| 1087 |
excludedTaxaTableModel.fireTableDataChanged(); |
| 1088 |
|
| 1089 |
includedTaxaTable.getSelectionModel().clearSelection(); |
| 1090 |
for (Taxon taxon : transfer) { |
| 1091 |
int row = includedTaxa.indexOf(taxon); |
| 1092 |
includedTaxaTable.getSelectionModel().addSelectionInterval(row, row); |
| 1093 |
} |
| 1094 |
|
| 1095 |
taxonSetChanged(); |
| 1096 |
} |
| 1097 |
|
| 1098 |
private void excludeSelectedTaxa() { |
| 1099 |
int[] rows = includedTaxaTable.getSelectedRows(); |
| 1100 |
|
| 1101 |
List<Taxon> transfer = new ArrayList<Taxon>(); |
| 1102 |
|
| 1103 |
for (int r : rows) { |
| 1104 |
transfer.add(includedTaxa.get(r)); |
| 1105 |
} |
| 1106 |
|
| 1107 |
excludedTaxa.addAll(transfer); |
| 1108 |
Collections.sort(excludedTaxa); |
| 1109 |
|
| 1110 |
includedTaxa.removeAll(excludedTaxa); |
| 1111 |
|
| 1112 |
includedTaxaTableModel.fireTableDataChanged(); |
| 1113 |
excludedTaxaTableModel.fireTableDataChanged(); |
| 1114 |
|
| 1115 |
excludedTaxaTable.getSelectionModel().clearSelection(); |
| 1116 |
for (Taxon taxon : transfer) { |
| 1117 |
int row = excludedTaxa.indexOf(taxon); |
| 1118 |
excludedTaxaTable.getSelectionModel().addSelectionInterval(row, row); |
| 1119 |
} |
| 1120 |
|
| 1121 |
taxonSetChanged(); |
| 1122 |
} |
| 1123 |
|
| 1124 |
Action includeTaxonAction = new AbstractAction("->") { |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
private static final long serialVersionUID = 7510299673661594128L; |
| 1129 |
|
| 1130 |
public void actionPerformed(ActionEvent ae) { |
| 1131 |
includeSelectedTaxa(); |
| 1132 |
} |
| 1133 |
}; |
| 1134 |
|
| 1135 |
Action excludeTaxonAction = new AbstractAction("<-") { |
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
private static final long serialVersionUID = 449692708602410206L; |
| 1141 |
|
| 1142 |
public void actionPerformed(ActionEvent ae) { |
| 1143 |
excludeSelectedTaxa(); |
| 1144 |
} |
| 1145 |
}; |
| 1146 |
|
| 1147 |
public class ImportTaxonSetsAction extends AbstractAction { |
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
private static final long serialVersionUID = 8514706149822252033L; |
| 1152 |
|
| 1153 |
public ImportTaxonSetsAction() { |
| 1154 |
super("Import Taxon Sets"); |
| 1155 |
setToolTipText("Use this tool to import the taxon sets from a file"); |
| 1156 |
} |
| 1157 |
|
| 1158 |
public void actionPerformed(ActionEvent ae) { |
| 1159 |
importTaxonSets(); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
class TaxaTableModel extends AbstractTableModel { |
| 1164 |
|
| 1165 |
private static final long serialVersionUID = -8027482229525938010L; |
| 1166 |
boolean included; |
| 1167 |
|
| 1168 |
public TaxaTableModel(boolean included) { |
| 1169 |
this.included = included; |
| 1170 |
} |
| 1171 |
|
| 1172 |
public int getColumnCount() { |
| 1173 |
return 1; |
| 1174 |
} |
| 1175 |
|
| 1176 |
public int getRowCount() { |
| 1177 |
if (currentTaxonSet == null) return 0; |
| 1178 |
|
| 1179 |
if (included) { |
| 1180 |
return includedTaxa.size(); |
| 1181 |
} else { |
| 1182 |
return excludedTaxa.size(); |
| 1183 |
} |
| 1184 |
} |
| 1185 |
|
| 1186 |
public Object getValueAt(int row, int col) { |
| 1187 |
|
| 1188 |
if (included) { |
| 1189 |
return includedTaxa.get(row).getId(); |
| 1190 |
} else { |
| 1191 |
return excludedTaxa.get(row).getId(); |
| 1192 |
} |
| 1193 |
} |
| 1194 |
|
| 1195 |
public boolean isCellEditable(int row, int col) { |
| 1196 |
return false; |
| 1197 |
} |
| 1198 |
|
| 1199 |
public String getColumnName(int column) { |
| 1200 |
if (included) return "Included " + TAXA; |
| 1201 |
else return "Excluded " + TAXA; |
| 1202 |
} |
| 1203 |
|
| 1204 |
public Class getColumnClass(int c) { |
| 1205 |
return getValueAt(0, c).getClass(); |
| 1206 |
} |
| 1207 |
} |
| 1208 |
|
| 1209 |
} |