use of beast.evolution.tree.TreeDistribution in project beast2 by CompEvol.
the class TreeDistributionInputEditor method init.
@Override
public void init(Input<?> input, BEASTInterface beastObject, int listItemNr, ExpandOption isExpandOption, boolean addButtons) {
m_bAddButtons = addButtons;
m_input = input;
m_beastObject = beastObject;
this.itemNr = listItemNr;
Box itemBox = Box.createHorizontalBox();
TreeDistribution distr = (TreeDistribution) beastObject;
String text = "";
if (distr.treeInput.get() != null) {
text += distr.treeInput.get().getID();
} else {
text += distr.treeIntervalsInput.get().treeInput.get().getID();
}
JLabel label = new JLabel(text);
Font font = label.getFont();
Dimension size = new Dimension(font.getSize() * 200 / 12, font.getSize() * 2);
label.setMinimumSize(size);
label.setPreferredSize(size);
itemBox.add(label);
// List<String> availableBEASTObjects =
// PluginPanel.getAvailablePlugins(m_input, m_beastObject, null);
List<BeautiSubTemplate> availableBEASTObjects = doc.getInputEditorFactory().getAvailableTemplates(m_input, m_beastObject, null, doc);
// make sure we are dealing with a TreeDistribution
for (int i = availableBEASTObjects.size() - 1; i >= 0; i--) {
BeautiSubTemplate t = availableBEASTObjects.get(i);
Class<?> c = t._class;
if (!(TreeDistribution.class.isAssignableFrom(c))) {
availableBEASTObjects.remove(i);
}
}
JComboBox<BeautiSubTemplate> comboBox = new JComboBox<>(availableBEASTObjects.toArray(new BeautiSubTemplate[] {}));
comboBox.setName("TreeDistribution");
for (int i = availableBEASTObjects.size() - 1; i >= 0; i--) {
if (!TreeDistribution.class.isAssignableFrom(availableBEASTObjects.get(i)._class)) {
availableBEASTObjects.remove(i);
}
}
String id = distr.getID();
try {
// id = BeautiDoc.parsePartition(id);
id = id.substring(0, id.indexOf('.'));
} catch (Exception e) {
throw new RuntimeException("Improperly formatted ID: " + distr.getID());
}
for (BeautiSubTemplate template : availableBEASTObjects) {
if (template.matchesName(id)) {
// getMainID().replaceAll(".\\$\\(n\\)",
// "").equals(id)) {
comboBox.setSelectedItem(template);
}
}
comboBox.addActionListener(e -> {
m_e = e;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
@SuppressWarnings("unchecked") JComboBox<BeautiSubTemplate> currentComboBox = (JComboBox<BeautiSubTemplate>) m_e.getSource();
@SuppressWarnings("unchecked") List<BEASTInterface> list = (List<BEASTInterface>) m_input.get();
BeautiSubTemplate template = (BeautiSubTemplate) currentComboBox.getSelectedItem();
PartitionContext partitionContext = doc.getContextFor(list.get(itemNr));
try {
template.createSubNet(partitionContext, list, itemNr, true);
} catch (Exception ex) {
ex.printStackTrace();
}
sync();
refreshPanel();
}
});
});
itemBox.add(comboBox);
itemBox.add(Box.createGlue());
m_validateLabel = new SmallLabel("x", new Color(200, 0, 0));
m_validateLabel.setVisible(false);
validateInput();
itemBox.add(m_validateLabel);
add(itemBox);
}
use of beast.evolution.tree.TreeDistribution 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.evolution.tree.TreeDistribution in project beast2 by CompEvol.
the class TreeDistributionInputEditor method validateInput.
@Override
public void validateInput() {
TreeDistribution distr = (TreeDistribution) m_beastObject;
// TODO: robustify for the case the tree is not a simple binary tree
Tree tree = (Tree) distr.treeInput.get();
if (tree == null) {
tree = distr.treeIntervalsInput.get().treeInput.get();
}
if (tree.hasDateTrait()) {
if (!distr.canHandleTipDates()) {
m_validateLabel.setToolTipText("This tree prior cannot handle dated tips. Choose another tree prior.");
m_validateLabel.m_circleColor = Color.red;
m_validateLabel.setVisible(true);
return;
}
}
super.validateInput();
}
Aggregations