Exemplo n.º 1
0
  private void modelsChanged() {
    TableColumn col = dataTable.getColumnModel().getColumn(5);
    col.setCellEditor(new ComboBoxCellEditor());

    col = dataTable.getColumnModel().getColumn(6);
    col.setCellEditor(new ComboBoxCellEditor());

    col = dataTable.getColumnModel().getColumn(7);
    col.setCellEditor(
        new DefaultCellEditor(new JComboBox(options.getNonTraitPartitionTreeModels().toArray())));
  }
Exemplo n.º 2
0
  public void unlinkTrees() { // reuse previous PartitionTreePrior
    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      PartitionTreeModel model = partition.getPartitionTreeModel();
      if (!model.getName().equals(partition.getName())
          && partition.getTraitType() == null) { // not a trait
        PartitionTreeModel newTree = new PartitionTreeModel(options, partition);

        // this prevents partition not broken, and used for unsharing tree prior only,
        // because sharing uses shareSameTreePrior, unsharing uses getPartitionTreePrior
        //                newTree.setPartitionTreePrior(newPrior); // important

        partition.setPartitionTreeModel(newTree);
      }
    }

    options.linkTreePriors(frame.getCurrentPartitionTreePrior());

    modelsChanged();

    fireDataChanged();
    options.taxonSets.clear();
    options.taxonSetsMono.clear();
    repaint();
  }
Exemplo n.º 3
0
  public void linkClocks() { // keep previous PartitionTreePrior for reuse
    int[] selRows = dataTable.getSelectedRows();

    List<PartitionData> selectedPartitionData = new ArrayList<PartitionData>();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }
    Object[] modelArray = options.getPartitionClockModels(selectedPartitionData).toArray();

    if (selectClockDialog == null) {
      selectClockDialog = new SelectClockDialog(frame);
    }

    int result = selectClockDialog.showDialog(modelArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionClockModel model = selectClockDialog.getModel();
      if (selectClockDialog.getMakeCopy()) {
        model.setName(selectClockDialog.getName());
      }

      for (PartitionData partition : selectedPartitionData) {
        partition.setPartitionClockModel(model);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
Exemplo n.º 4
0
  public void removeSelection() {
    int[] selRows = dataTable.getSelectedRows();
    Set<PartitionData> partitionsToRemove = new HashSet<PartitionData>();
    for (int row : selRows) {
      partitionsToRemove.add(options.dataPartitions.get(row));
    }

    // TODO: would probably be a good idea to check if the user wants to remove the last partition
    options.dataPartitions.removeAll(partitionsToRemove);

    //        if (options.allowDifferentTaxa && options.dataPartitions.size() < 2) {
    //            uncheckAllowDifferentTaxa();
    //        }

    if (options.getNonTraitsDataList().size() == 0) {
      // all data partitions removed so reset the taxa
      options.reset();
      useStarBEASTCheck.setSelected(false);
      frame.statusLabel.setText("");
      frame.setAllOptions();
      frame.getExportAction().setEnabled(false);
    }

    dataTableModel.fireTableDataChanged();

    fireDataChanged();
  }
Exemplo n.º 5
0
    public Component getTableCellEditorComponent(
        JTable table, Object value, boolean isSelected, int row, int column) {

      ((JComboBox) editorComponent).removeAllItems();
      if (options.containTrait(table.getValueAt(row, 0).toString())) {
        if (column == 5) {
          for (Object ob : options.getPartitionTraitsSubstitutionModels()) {
            ((JComboBox) editorComponent).addItem(ob);
          }
        } else if (column == 6) {
          for (Object ob : options.getPartitionTraitsClockModels()) {
            ((JComboBox) editorComponent).addItem(ob);
          }
        }
      } else {
        if (column == 5) {
          for (Object ob : options.getPartitionNonTraitsSubstitutionModels()) {
            ((JComboBox) editorComponent).addItem(ob);
          }
        } else if (column == 6) {
          for (Object ob : options.getPartitionNonTraitsClockModels()) {
            ((JComboBox) editorComponent).addItem(ob);
          }
        }
      }

      //            if (((JComboBox) editorComponent).contains(value)) // todo need validate whether
      // value in the editorComponent

      ((JComboBox) editorComponent).setSelectedItem(value);
      delegate.setValue(value);

      return editorComponent;
    }
Exemplo n.º 6
0
  public void removeSelection() {
    int[] selRows = dataTable.getSelectedRows();
    Set<AbstractPartitionData> partitionsToRemove = new HashSet<AbstractPartitionData>();
    for (int row : selRows) {
      partitionsToRemove.add(options.dataPartitions.get(row));
    }

    boolean hasIdenticalTaxa =
        options.hasIdenticalTaxa(); // need to check this before removing partitions

    // TODO: would probably be a good idea to check if the user wants to remove the last partition
    options.dataPartitions.removeAll(partitionsToRemove);

    if (options.dataPartitions.size() == 0) {
      // all data partitions removed so reset the taxa
      options.reset();
      useStarBEASTCheck.setSelected(false);
      frame.setupStarBEAST(false);
      frame.statusLabel.setText("");
      frame.setAllOptions();
      frame.getExportAction().setEnabled(false);
    } else if (!hasIdenticalTaxa) {
      options.updateTaxonList();
    }

    dataTableModel.fireTableDataChanged();

    fireDataChanged();
  }
Exemplo n.º 7
0
  public void linkTrees() { // keep previous PartitionTreePrior for reuse
    int[] selRows = dataTable.getSelectedRows();

    List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>();
    for (int row : selRows) {
      AbstractPartitionData partition = options.dataPartitions.get(row);

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }

    if (selectedPartitionData.size() > 1) {
      if (!options.hasIdenticalTaxa(selectedPartitionData)) {
        String errMsg = "To share a tree, partitions need to have identical taxa.";
        if (selectedPartitionData.get(0).getDataType().getType() == DataType.MICRO_SAT)
          errMsg += "\nThe data must be all diploid or all haploid when you want to link the tree.";
        JOptionPane.showMessageDialog(
            this, errMsg, "Illegal Configuration", JOptionPane.ERROR_MESSAGE);
        return;
      }
    }

    Object[] treeArray = options.getPartitionTreeModels(selectedPartitionData).toArray();

    if (selectTreeDialog == null) {
      selectTreeDialog = new SelectTreeDialog(frame);
    }

    int result = selectTreeDialog.showDialog(treeArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionTreeModel model = selectTreeDialog.getTree();
      if (selectTreeDialog.getMakeCopy()) {
        model.setName(selectTreeDialog.getName());
      }
      PartitionTreePrior prior = model.getPartitionTreePrior();
      options.linkTreePriors(prior);

      for (AbstractPartitionData partition : selectedPartitionData) {
        partition.setPartitionTreeModel(model);
      }

      for (Taxa taxa :
          options.taxonSets) { // Issue 454: all the taxon sets are deleted when link/unlink tree
        PartitionTreeModel prevModel = options.taxonSetsTreeModel.get(taxa);
        if (prevModel != model) options.taxonSetsTreeModel.put(taxa, model);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
Exemplo n.º 8
0
  public void linkTrees() { // keep previous PartitionTreePrior for reuse
    int[] selRows = dataTable.getSelectedRows();

    List<PartitionData> selectedPartitionData = new ArrayList<PartitionData>();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }

    if (options.allowDifferentTaxa) { // BEAST cannot handle multi <taxa> ref for 1 tree
      if (selectedPartitionData.size() > 1) {
        if (!options.validateDiffTaxa(selectedPartitionData)) {
          JOptionPane.showMessageDialog(
              this,
              "To accommodate different taxa for each partition trees cannot be linked.",
              "Illegal Configuration",
              JOptionPane.ERROR_MESSAGE);
          return;
        }
      }
    }

    Object[] treeArray = options.getPartitionTreeModels(selectedPartitionData).toArray();

    if (selectTreeDialog == null) {
      selectTreeDialog = new SelectTreeDialog(frame);
    }

    int result = selectTreeDialog.showDialog(treeArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionTreeModel model = selectTreeDialog.getTree();
      if (selectTreeDialog.getMakeCopy()) {
        model.setName(selectTreeDialog.getName());
      }
      PartitionTreePrior prior = model.getPartitionTreePrior();
      options.linkTreePriors(prior);

      for (PartitionData partition : selectedPartitionData) {
        partition.setPartitionTreeModel(model);
      }
    }

    modelsChanged();

    fireDataChanged();
    options.taxonSets.clear();
    options.taxonSetsMono.clear();
    repaint();
  }
Exemplo n.º 9
0
  public void linkModels() {
    int[] selRows = dataTable.getSelectedRows();
    List<AbstractPartitionData> selectedPartitionData = new ArrayList<AbstractPartitionData>();
    DataType dateType = null;
    for (int row : selRows) {
      AbstractPartitionData partition = options.dataPartitions.get(row);
      if (dateType == null) {
        dateType = partition.getDataType();
      } else {
        if (partition.getDataType() != dateType) {
          JOptionPane.showMessageDialog(
              this,
              "Can only link the models for data partitions \n"
                  + "of the same data type (e.g., nucleotides)",
              "Unable to link models",
              JOptionPane.ERROR_MESSAGE);
          return;
        }
      }

      if (!selectedPartitionData.contains(partition)) selectedPartitionData.add(partition);
    }

    Object[] modelArray = options.getPartitionSubstitutionModels(selectedPartitionData).toArray();

    if (selectModelDialog == null) {
      selectModelDialog = new SelectModelDialog(frame);
    }

    int result = selectModelDialog.showDialog(modelArray);
    if (result != JOptionPane.CANCEL_OPTION) {
      PartitionSubstitutionModel model = selectModelDialog.getModel();
      if (selectModelDialog.getMakeCopy()) {
        model.setName(selectModelDialog.getName());
      }

      for (AbstractPartitionData partition : selectedPartitionData) {
        partition.setPartitionSubstitutionModel(model);
      }
    }

    if (options.getPartitionSubstitutionModels(Microsatellite.INSTANCE).size() <= 1) {
      options.shareMicroSat = true;
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
Exemplo n.º 10
0
  public void unlinkClocks() { // reuse previous PartitionTreePrior
    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      PartitionClockModel model = partition.getPartitionClockModel();
      if (!model.getName().equals(partition.getName())) {
        PartitionClockModel newModel = new PartitionClockModel(options, partition);
        partition.setPartitionClockModel(newModel);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
Exemplo n.º 11
0
  public void unlinkModels() {
    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      PartitionData partition = options.dataPartitions.get(row);

      PartitionSubstitutionModel model = partition.getPartitionSubstitutionModel();
      if (!model.getName().equals(partition.getName())) {
        PartitionSubstitutionModel newModel = new PartitionSubstitutionModel(options, partition);
        partition.setPartitionSubstitutionModel(newModel);
      }
    }

    modelsChanged();

    fireDataChanged();
    repaint();
  }
Exemplo n.º 12
0
  public void selectionChanged() {
    int[] selRows = dataTable.getSelectedRows();
    boolean hasSelection = (selRows != null && selRows.length != 0);
    frame.dataSelectionChanged(hasSelection);

    boolean canUnlink = options.dataPartitions.size() > 1 && hasSelection;
    boolean canLink = options.dataPartitions.size() > 1 && hasSelection && selRows.length > 1;

    unlinkModelsAction.setEnabled(canUnlink);
    linkModelsAction.setEnabled(canLink);

    unlinkClocksAction.setEnabled(canUnlink);
    linkClocksAction.setEnabled(canLink);

    unlinkTreesAction.setEnabled(canUnlink);
    linkTreesAction.setEnabled(canLink);
  }
Exemplo n.º 13
0
  public boolean createFromTraits(List<TraitData> traits) {
    int selRow = -1;

    if (selectTraitDialog == null) {
      selectTraitDialog = new SelectTraitDialog(frame);
    }

    if (traits == null || traits.size() == 0) {
      int result = selectTraitDialog.showDialog(options.traits, null);
      if (result != JOptionPane.CANCEL_OPTION) {
        TraitData trait = selectTraitDialog.getTrait();
        String name = trait.getName();
        if (selectTraitDialog.getMakeCopy()) {
          name = selectTraitDialog.getName();
        }

        selRow = options.createPartitionForTraits(name, trait);
      } else {
        return false;
      }
    } else {
      if (traits.size() > 1) {
        // a set of traits have been passed to the function
        int result = selectTraitDialog.showDialog(null, null);
        if (result != JOptionPane.CANCEL_OPTION) {
          String name = selectTraitDialog.getName();
          selRow = options.createPartitionForTraits(name, traits);
        } else {
          return false;
        }
      } else {
        selRow = options.createPartitionForTraits(traits.get(0).getName(), traits);
      }
    }

    modelsChanged();
    dataTableModel.fireTableDataChanged();

    if (selRow != -1) {
      dataTable.getSelectionModel().setSelectionInterval(selRow, selRow);
    }
    fireDataChanged();
    repaint();

    return true;
  }
Exemplo n.º 14
0
  private void showAlignment() {

    int[] selRows = dataTable.getSelectedRows();
    for (int row : selRows) {
      AbstractPartitionData partition = options.dataPartitions.get(row);
      Alignment alignment = null;

      if (partition instanceof PartitionData)
        alignment = ((PartitionData) partition).getAlignment();

      // alignment == null if partition is trait or microsat
      // http://code.google.com/p/beast-mcmc/issues/detail?id=343
      if (alignment == null) {
        JOptionPane.showMessageDialog(
            this,
            "Cannot display traits or microsatellite data currently.\nUse the traits panel to view and edit traits.",
            "Illegal Argument Exception",
            JOptionPane.ERROR_MESSAGE);
        return;
      }

      JFrame frame = new JFrame();
      frame.setSize(800, 600);

      AlignmentViewer viewer = new AlignmentViewer();
      if (alignment.getDataType().getType() == DataType.NUCLEOTIDES) {
        viewer.setCellDecorator(new StateCellDecorator(new NucleotideDecorator(), false));
      } else if (alignment.getDataType().getType() == DataType.AMINO_ACIDS) {
        viewer.setCellDecorator(new StateCellDecorator(new AminoAcidDecorator(), false));
      } else {
        // no colouring
      }
      viewer.setAlignmentBuffer(new BeautiAlignmentBuffer(alignment));

      JPanel panel = new JPanel(new BorderLayout());
      panel.setOpaque(false);
      panel.add(viewer, BorderLayout.CENTER);

      JPanel infoPanel = new JPanel(new BorderLayout());
      infoPanel.setOpaque(false);
      panel.add(infoPanel, BorderLayout.SOUTH);

      frame.setContentPane(panel);
      frame.setVisible(true);
    }
  }
Exemplo n.º 15
0
  public DataPanel(
      BeautiFrame parent,
      Action importDataAction,
      Action removeDataAction /*, Action importTraitsAction*/) {

    this.frame = parent;

    dataTableModel = new DataTableModel();
    dataTable = new JTable(dataTableModel);

    dataTable.getTableHeader().setReorderingAllowed(false);
    dataTable
        .getTableHeader()
        .setDefaultRenderer(new HeaderRenderer(SwingConstants.LEFT, new Insets(0, 4, 0, 4)));

    TableColumn col = dataTable.getColumnModel().getColumn(5);
    ComboBoxRenderer comboBoxRenderer = new ComboBoxRenderer();
    comboBoxRenderer.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    col.setCellRenderer(comboBoxRenderer);

    //        col = dataTable.getColumnModel().getColumn(5);
    //        comboBoxRenderer = new ComboBoxRenderer();
    //        comboBoxRenderer.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    //        col.setCellRenderer(comboBoxRenderer);

    col = dataTable.getColumnModel().getColumn(6);
    comboBoxRenderer = new ComboBoxRenderer();
    comboBoxRenderer.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    col.setCellRenderer(comboBoxRenderer);

    col = dataTable.getColumnModel().getColumn(7);
    comboBoxRenderer = new ComboBoxRenderer();
    comboBoxRenderer.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
    col.setCellRenderer(comboBoxRenderer);

    TableEditorStopper.ensureEditingStopWhenTableLosesFocus(dataTable);

    dataTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent evt) {
                selectionChanged();
              }
            });

    dataTable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              showAlignment();
            }
          }
        });

    scrollPane =
        new JScrollPane(
            dataTable,
            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setOpaque(false);

    JToolBar toolBar1 = new JToolBar();
    toolBar1.setFloatable(false);
    toolBar1.setOpaque(false);
    toolBar1.setLayout(new BoxLayout(toolBar1, BoxLayout.X_AXIS));

    JButton button = new JButton(unlinkModelsAction);
    unlinkModelsAction.setEnabled(false);
    PanelUtils.setupComponent(button);
    toolBar1.add(button);

    button = new JButton(linkModelsAction);
    linkModelsAction.setEnabled(false);
    PanelUtils.setupComponent(button);
    toolBar1.add(button);

    toolBar1.addSeparator();

    button = new JButton(unlinkClocksAction);
    unlinkClocksAction.setEnabled(false);
    PanelUtils.setupComponent(button);
    toolBar1.add(button);

    button = new JButton(linkClocksAction);
    linkClocksAction.setEnabled(false);
    PanelUtils.setupComponent(button);
    toolBar1.add(button);

    toolBar1.addSeparator();

    button = new JButton(unlinkTreesAction);
    unlinkTreesAction.setEnabled(false);
    PanelUtils.setupComponent(button);
    toolBar1.add(button);

    button = new JButton(linkTreesAction);
    linkTreesAction.setEnabled(false);
    PanelUtils.setupComponent(button);
    toolBar1.add(button);

    // too crowded on the toolbar  - just double click to show
    //            button = new JButton(showAction);
    //            showAction.setEnabled(false);
    //            PanelUtils.setupComponent(button);
    //            toolBar1.add(button);

    ActionPanel actionPanel1 = new ActionPanel(false);
    actionPanel1.setAddAction(importDataAction);
    actionPanel1.setRemoveAction(removeDataAction);
    removeDataAction.setEnabled(false);

    JPanel controlPanel1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
    controlPanel1.setOpaque(false);
    controlPanel1.add(actionPanel1);

    controlPanel1.add(new JLabel("   "));
    PanelUtils.setupComponent(createImportTraitButton);
    controlPanel1.add(createImportTraitButton);

    //        controlPanel1.add(new JLabel(" or "));
    //
    //        button = new JButton(importTraitsAction);
    //        PanelUtils.setupComponent(button);
    //        controlPanel1.add(button);

    JPanel panel1 = new JPanel(new BorderLayout());
    panel1.setOpaque(false);
    panel1.add(useStarBEASTCheck, BorderLayout.NORTH);
    panel1.add(toolBar1, BorderLayout.SOUTH);

    setOpaque(false);
    setBorder(new BorderUIResource.EmptyBorderUIResource(new Insets(12, 12, 12, 12)));
    setLayout(new BorderLayout(0, 0));
    add(panel1, BorderLayout.NORTH);
    add(scrollPane, BorderLayout.CENTER);
    add(controlPanel1, BorderLayout.SOUTH);

    useStarBEASTCheck.setEnabled(false);
    useStarBEASTCheck.setToolTipText(STARBEASTOptions.CITATION);
    useStarBEASTCheck.addActionListener(
        new java.awt.event.ActionListener() {
          public void actionPerformed(
              ActionEvent e) { // wrong listener Issue 397: *BEAST in BEAUti is broken
            frame.setupStarBEAST(useStarBEASTCheck.isSelected());
            dataTableModel.fireTableDataChanged();
          }
        });
  }
Exemplo n.º 16
0
 public void selectAll() {
   dataTable.selectAll();
 }