use of beast.app.draw.SmallButton in project beast2 by CompEvol.
the class AlignmentListInputEditor method createAddRemoveSplitButtons.
private JComponent createAddRemoveSplitButtons() {
Box buttonBox = Box.createHorizontalBox();
addButton = new SmallButton("+", true, SmallButton.ButtonType.square);
addButton.setName("+");
addButton.setToolTipText("Add item to the list");
addButton.addActionListener(e -> addItem());
buttonBox.add(Box.createHorizontalStrut(STRUT_SIZE));
buttonBox.add(addButton);
buttonBox.add(Box.createHorizontalStrut(STRUT_SIZE));
delButton = new SmallButton("-", true, SmallButton.ButtonType.square);
delButton.setName("-");
delButton.setToolTipText("Delete selected items from the list");
delButton.addActionListener(e -> {
if (doc.hasLinkedAtLeastOnce) {
JOptionPane.showMessageDialog(null, "Cannot delete partition while parameters are linked");
return;
}
delItem();
});
buttonBox.add(delButton);
buttonBox.add(Box.createHorizontalStrut(STRUT_SIZE));
replaceButton = new SmallButton("r", true, SmallButton.ButtonType.square);
replaceButton.setName("r");
replaceButton.setToolTipText("Replace alignment by one loaded from file");
replaceButton.addActionListener(e -> replaceItem());
buttonBox.add(Box.createHorizontalStrut(STRUT_SIZE));
buttonBox.add(replaceButton);
buttonBox.add(Box.createHorizontalStrut(STRUT_SIZE));
splitButton = new JButton("Split");
splitButton.setName("Split");
splitButton.setToolTipText("Split alignment into partitions, for example, codon positions");
splitButton.addActionListener(e -> splitItem());
buttonBox.add(splitButton);
buttonBox.add(Box.createHorizontalGlue());
return buttonBox;
}
use of beast.app.draw.SmallButton in project beast2 by CompEvol.
the class PriorListInputEditor method init.
@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
List<?> list = (List<?>) input.get();
Collections.sort(list, (Object o1, Object o2) -> {
if (o1 instanceof BEASTInterface && o2 instanceof BEASTInterface) {
String d1 = ((BEASTInterface) o1).getID();
String id2 = ((BEASTInterface) o2).getID();
// first the tree priors
if (o1 instanceof TreeDistribution) {
if (o2 instanceof TreeDistribution) {
TreeInterface tree1 = ((TreeDistribution) o1).treeInput.get();
if (tree1 == null) {
tree1 = ((TreeDistribution) o1).treeIntervalsInput.get().treeInput.get();
}
TreeInterface tree2 = ((TreeDistribution) o2).treeInput.get();
if (tree2 == null) {
tree2 = ((TreeDistribution) o2).treeIntervalsInput.get().treeInput.get();
}
return d1.compareTo(id2);
} else {
return -1;
}
} else if (o1 instanceof MRCAPrior) {
// last MRCA priors
if (o2 instanceof MRCAPrior) {
return d1.compareTo(id2);
} else {
return 1;
}
} else {
if (o2 instanceof TreeDistribution) {
return 1;
}
if (o2 instanceof MRCAPrior) {
return -1;
}
if (o1 instanceof Prior) {
d1 = ((Prior) o1).getParameterName();
}
if (o2 instanceof Prior) {
id2 = ((Prior) o2).getParameterName();
}
return d1.compareTo(id2);
}
}
return 0;
});
rangeButtons = new ArrayList<>();
taxonButtons = new ArrayList<>();
// m_buttonStatus = ButtonStatus.NONE;
super.init(input, beastObject, itemNr, isExpandOption, addButtons);
if (beastObject instanceof BeautiPanelConfig) {
BeautiPanelConfig config = (BeautiPanelConfig) beastObject;
if (config.parentBEASTObjects != null && config.parentBEASTObjects.size() > 0 && config.parentBEASTObjects.get(0).getID().equals("speciescoalescent")) {
m_buttonStatus = ButtonStatus.NONE;
}
}
if (m_buttonStatus == ButtonStatus.ALL || m_buttonStatus == ButtonStatus.ADD_ONLY) {
addButton = new SmallButton("+ Add Prior", true);
addButton.setName("addItem");
addButton.setToolTipText("Add new prior (like an MRCA-prior) to the list of priors");
addButton.addActionListener(e -> {
addItem();
});
buttonBox.add(addButton);
buttonBox.add(Box.createHorizontalGlue());
}
}
use of beast.app.draw.SmallButton in project beast2 by CompEvol.
the class MRCAPriorInputEditor method init.
@Override
public void init(Input<?> input, BEASTInterface beastObject, final int listItemNr, ExpandOption isExpandOption, boolean addButtons) {
m_bAddButtons = addButtons;
m_input = input;
m_beastObject = beastObject;
this.itemNr = listItemNr;
Box itemBox = Box.createHorizontalBox();
MRCAPrior prior = (MRCAPrior) beastObject;
String text = prior.getID();
JButton taxonButton = new JButton(text);
// taxonButton.setMinimumSize(Base.PREFERRED_SIZE);
// taxonButton.setPreferredSize(Base.PREFERRED_SIZE);
itemBox.add(taxonButton);
taxonButton.addActionListener(e -> {
List<?> list = (List<?>) m_input.get();
MRCAPrior prior2 = (MRCAPrior) list.get(itemNr);
try {
TaxonSet taxonset = prior2.taxonsetInput.get();
List<Taxon> originalTaxa = new ArrayList<>();
originalTaxa.addAll(taxonset.taxonsetInput.get());
Set<Taxon> candidates = getTaxonCandidates(prior2);
TaxonSetDialog dlg = new TaxonSetDialog(taxonset, candidates, doc);
if (dlg.showDialog()) {
if (dlg.taxonSet.taxonsetInput.get().size() == 0) {
JOptionPane.showMessageDialog(doc.beauti, "At least one taxon should be included in the taxon set", "Error specifying taxon set", JOptionPane.ERROR_MESSAGE);
taxonset.taxonsetInput.get().addAll(originalTaxa);
return;
}
prior2.taxonsetInput.setValue(dlg.taxonSet, prior2);
int i = 1;
String id = dlg.taxonSet.getID();
while (doc.pluginmap.containsKey(dlg.taxonSet.getID()) && doc.pluginmap.get(dlg.taxonSet.getID()) != dlg.taxonSet) {
dlg.taxonSet.setID(id + i);
i++;
}
BEASTObjectPanel.addPluginToMap(dlg.taxonSet, doc);
prior2.setID(dlg.taxonSet.getID() + ".prior");
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
refreshPanel();
});
if (prior.distInput.getType() == null) {
try {
prior.distInput.setValue(new OneOnX(), prior);
prior.distInput.setValue(null, prior);
} catch (Exception e) {
// TODO: handle exception
}
}
List<BeautiSubTemplate> availableBEASTObjects = doc.getInputEditorFactory().getAvailableTemplates(prior.distInput, prior, null, doc);
JComboBox<BeautiSubTemplate> comboBox = new JComboBox<>(availableBEASTObjects.toArray(new BeautiSubTemplate[] {}));
comboBox.setName(text + ".distr");
if (prior.distInput.get() != null) {
String id = prior.distInput.get().getID();
// id = BeautiDoc.parsePartition(id);
id = id.substring(0, id.indexOf('.'));
for (BeautiSubTemplate template : availableBEASTObjects) {
if (template.classInput.get() != null && template.shortClassName.equals(id)) {
comboBox.setSelectedItem(template);
}
}
} else {
comboBox.setSelectedItem(BeautiConfig.NULL_TEMPLATE);
}
comboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@SuppressWarnings("unchecked") JComboBox<BeautiSubTemplate> comboBox = (JComboBox<BeautiSubTemplate>) e.getSource();
BeautiSubTemplate template = (BeautiSubTemplate) comboBox.getSelectedItem();
List<?> list = (List<?>) m_input.get();
MRCAPrior prior = (MRCAPrior) list.get(itemNr);
// }
try {
// BEASTObject beastObject2 =
template.createSubNet(new PartitionContext(""), prior, prior.distInput, true);
} catch (Exception e1) {
e1.printStackTrace();
}
refreshPanel();
}
});
itemBox.add(comboBox);
JCheckBox isMonophyleticdBox = new JCheckBox(doc.beautiConfig.getInputLabel(prior, prior.isMonophyleticInput.getName()));
isMonophyleticdBox.setName(text + ".isMonophyletic");
isMonophyleticdBox.setSelected(prior.isMonophyleticInput.get());
isMonophyleticdBox.setToolTipText(prior.isMonophyleticInput.getHTMLTipText());
isMonophyleticdBox.addActionListener(new MRCAPriorActionListener(prior));
itemBox.add(isMonophyleticdBox);
JButton deleteButton = new SmallButton("-", true);
deleteButton.setToolTipText("Delete this calibration");
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Log.warning.println("Trying to delete a calibration");
List<?> list = (List<?>) m_input.get();
MRCAPrior prior = (MRCAPrior) list.get(itemNr);
doc.disconnect(prior, "prior", "distribution");
doc.disconnect(prior, "tracelog", "log");
if (prior.onlyUseTipsInput.get()) {
disableTipSampling(m_beastObject, doc);
}
doc.unregisterPlugin(prior);
refreshPanel();
}
});
itemBox.add(Box.createGlue());
itemBox.add(deleteButton);
add(itemBox);
}
Aggregations