Search in sources :

Example 51 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class MRCAPriorInputEditor method createTipsonlyEditor.

public InputEditor createTipsonlyEditor() throws NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    BooleanInputEditor e = new BooleanInputEditor(doc) {

        private static final long serialVersionUID = 1L;

        @Override
        public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
            super.init(input, beastObject, itemNr, isExpandOption, addButtons);
            // hack to get to JCheckBox
            Component[] components = getComponents();
            ((JCheckBox) components[0]).addActionListener(e -> {
                JCheckBox src = (JCheckBox) e.getSource();
                if (src.isSelected()) {
                    enableTipSampling();
                } else {
                    disableTipSampling(m_beastObject, doc);
                }
            });
        }
    };
    MRCAPrior prior = (MRCAPrior) m_beastObject;
    Input<?> input = prior.onlyUseTipsInput;
    e.init(input, prior, -1, ExpandOption.FALSE, false);
    return e;
}
Also used : JCheckBox(javax.swing.JCheckBox) Input(beast.core.Input) MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface) Component(java.awt.Component) BooleanInputEditor(beast.app.draw.BooleanInputEditor)

Example 52 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class MRCAPriorInputEditor method enableTipSampling.

// add TipDatesRandomWalker (if not present) and add to list of operators
private void enableTipSampling() {
    // First, create/find the operator
    TipDatesRandomWalker operator = null;
    MRCAPrior prior = (MRCAPrior) m_beastObject;
    TaxonSet taxonset = prior.taxonsetInput.get();
    taxonset.initAndValidate();
    // see if an old operator still hangs around -- happens when toggling the TipsOnly checkbox a few times
    for (BEASTInterface o : taxonset.getOutputs()) {
        if (o instanceof TipDatesRandomWalker) {
            operator = (TipDatesRandomWalker) o;
        }
    }
    if (operator == null) {
        operator = new TipDatesRandomWalker();
        operator.initByName("tree", prior.treeInput.get(), "taxonset", taxonset, "windowSize", 1.0, "weight", 1.0);
    }
    operator.setID("tipDatesSampler." + taxonset.getID());
    doc.mcmc.get().setInputValue("operator", operator);
}
Also used : MRCAPrior(beast.math.distributions.MRCAPrior) BEASTInterface(beast.core.BEASTInterface) TaxonSet(beast.evolution.alignment.TaxonSet) TipDatesRandomWalker(beast.evolution.operators.TipDatesRandomWalker)

Example 53 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class PriorInputEditor 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();
    Prior prior = (Prior) beastObject;
    String text = prior.getParameterName();
    JLabel label = new JLabel(text);
    Font font = label.getFont();
    Dimension size = new Dimension(font.getSize() * 200 / 13, font.getSize() * 25 / 13);
    label.setMinimumSize(size);
    label.setPreferredSize(size);
    itemBox.add(label);
    List<BeautiSubTemplate> availableBEASTObjects = doc.getInputEditorFactory().getAvailableTemplates(prior.distInput, prior, null, doc);
    JComboBox<BeautiSubTemplate> comboBox = new JComboBox<BeautiSubTemplate>(availableBEASTObjects.toArray(new BeautiSubTemplate[] {}));
    comboBox.setName(text + ".distr");
    String id = prior.distInput.get().getID();
    // Log.warning.println("id=" + id);
    id = id.substring(0, id.indexOf('.'));
    for (BeautiSubTemplate template : availableBEASTObjects) {
        if (template.classInput.get() != null && template.shortClassName.equals(id)) {
            comboBox.setSelectedItem(template);
        }
    }
    comboBox.addActionListener(e -> {
        @SuppressWarnings("unchecked") JComboBox<BeautiSubTemplate> comboBox1 = (JComboBox<BeautiSubTemplate>) e.getSource();
        List<?> list = (List<?>) m_input.get();
        BeautiSubTemplate template = (BeautiSubTemplate) comboBox1.getSelectedItem();
        // String id = ((BEASTObject) list.get(item)).getID();
        // String partition = BeautiDoc.parsePartition(id);
        PartitionContext context = doc.getContextFor((BEASTInterface) list.get(itemNr));
        Prior prior1 = (Prior) list.get(itemNr);
        try {
            template.createSubNet(context, prior1, prior1.distInput, true);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        sync();
        refreshPanel();
    });
    JPanel panel = new JPanel();
    panel.add(comboBox);
    panel.setMaximumSize(size);
    itemBox.add(panel);
    if (prior.m_x.get() instanceof RealParameter) {
        // add range button for real parameters
        RealParameter p = (RealParameter) prior.m_x.get();
        JButton rangeButton = new JButton(paramToString(p));
        rangeButton.addActionListener(e -> {
            JButton rangeButton1 = (JButton) e.getSource();
            List<?> list = (List<?>) m_input.get();
            Prior prior1 = (Prior) list.get(itemNr);
            RealParameter p1 = (RealParameter) prior1.m_x.get();
            BEASTObjectDialog dlg = new BEASTObjectDialog(p1, RealParameter.class, doc);
            if (dlg.showDialog()) {
                dlg.accept(p1, doc);
                rangeButton1.setText(paramToString(p1));
                refreshPanel();
            }
        });
        itemBox.add(Box.createHorizontalStrut(10));
        itemBox.add(rangeButton);
    } else if (prior.m_x.get() instanceof IntegerParameter) {
        // add range button for real parameters
        IntegerParameter p = (IntegerParameter) prior.m_x.get();
        JButton rangeButton = new JButton(paramToString(p));
        rangeButton.addActionListener(e -> {
            JButton rangeButton1 = (JButton) e.getSource();
            List<?> list = (List<?>) m_input.get();
            Prior prior1 = (Prior) list.get(itemNr);
            IntegerParameter p1 = (IntegerParameter) prior1.m_x.get();
            BEASTObjectDialog dlg = new BEASTObjectDialog(p1, IntegerParameter.class, doc);
            if (dlg.showDialog()) {
                dlg.accept(p1, doc);
                rangeButton1.setText(paramToString(p1));
                refreshPanel();
            }
        });
        itemBox.add(Box.createHorizontalStrut(10));
        itemBox.add(rangeButton);
    }
    int fontsize = comboBox.getFont().getSize();
    comboBox.setMaximumSize(new Dimension(1024 * fontsize / 13, 24 * fontsize / 13));
    String tipText = getDoc().tipTextMap.get(beastObject.getID());
    // System.out.println(beastObject.getID());
    if (tipText != null) {
        JLabel tipTextLabel = new JLabel(" " + tipText);
        itemBox.add(tipTextLabel);
    }
    itemBox.add(Box.createGlue());
    add(itemBox);
}
Also used : Arrays(java.util.Arrays) JButton(javax.swing.JButton) Input(beast.core.Input) Prior(beast.math.distributions.Prior) Font(java.awt.Font) FontSizeAction(javax.swing.text.StyledEditorKit.FontSizeAction) BEASTObjectDialog(beast.app.draw.BEASTObjectDialog) Box(javax.swing.Box) IntegerParameter(beast.core.parameter.IntegerParameter) Dimension(java.awt.Dimension) List(java.util.List) InputEditor(beast.app.draw.InputEditor) JLabel(javax.swing.JLabel) RealParameter(beast.core.parameter.RealParameter) BEASTInterface(beast.core.BEASTInterface) JComboBox(javax.swing.JComboBox) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) IntegerParameter(beast.core.parameter.IntegerParameter) BEASTObjectDialog(beast.app.draw.BEASTObjectDialog) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) RealParameter(beast.core.parameter.RealParameter) Box(javax.swing.Box) JComboBox(javax.swing.JComboBox) Dimension(java.awt.Dimension) Font(java.awt.Font) Prior(beast.math.distributions.Prior) List(java.util.List)

Example 54 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class DoubleListInputEditor method setValue.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void setValue(Object o) {
    if (itemNr < 0) {
        m_input.setValue(o, m_beastObject);
    } else {
        // set value of an item in a list
        List list = (List) m_input.get();
        Object other = list.get(itemNr);
        if (other != o) {
            if (other instanceof BEASTInterface) {
                BEASTInterface.getOutputs(other).remove(m_beastObject);
            }
            list.set(itemNr, o);
            if (o instanceof BEASTInterface) {
                BEASTInterface.getOutputs(o).add(m_beastObject);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BEASTInterface(beast.core.BEASTInterface)

Example 55 with BEASTInterface

use of beast.core.BEASTInterface in project beast2 by CompEvol.

the class ListInputEditor method pluginSelector.

/**
 * Select existing plug-in, or create a new one.
 * Suppress existing plug-ins with IDs from the taboo list.
 * Return null if nothing is selected.
 */
protected List<BEASTInterface> pluginSelector(Input<?> input, BEASTInterface parent, List<String> tabooList) {
    List<BEASTInterface> selectedPlugins = new ArrayList<>();
    List<String> beastObjectNames = doc.getInputEditorFactory().getAvailablePlugins(input, parent, tabooList, doc);
    /* select a beastObject **/
    String className = null;
    if (beastObjectNames.size() == 1) {
        // if there is only one candidate, select that one
        className = beastObjectNames.get(0);
    } else if (beastObjectNames.size() == 0) {
        // no candidate => we cannot be in expert mode
        // create a new BEASTObject
        doc.setExpertMode(true);
        beastObjectNames = doc.getInputEditorFactory().getAvailablePlugins(input, parent, tabooList, doc);
        doc.setExpertMode(false);
        className = beastObjectNames.get(0);
    } else {
        // otherwise, pop up a list box
        className = (String) JOptionPane.showInputDialog(null, "Select a constant", "select", JOptionPane.PLAIN_MESSAGE, null, beastObjectNames.toArray(new String[0]), null);
        if (className == null) {
            return null;
        }
    }
    if (!className.startsWith("new ")) {
        /* return existing beastObject */
        selectedPlugins.add(doc.pluginmap.get(className));
        return selectedPlugins;
    }
    /* create new beastObject */
    try {
        BEASTInterface beastObject = (BEASTInterface) Class.forName(className.substring(4)).newInstance();
        BEASTObjectPanel.addPluginToMap(beastObject, doc);
        selectedPlugins.add(beastObject);
        return selectedPlugins;
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Could not select beastObject: " + ex.getClass().getName() + " " + ex.getMessage());
        return null;
    }
}
Also used : ArrayList(java.util.ArrayList) BEASTInterface(beast.core.BEASTInterface)

Aggregations

BEASTInterface (beast.core.BEASTInterface)111 ArrayList (java.util.ArrayList)43 List (java.util.List)27 IOException (java.io.IOException)22 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)18 SAXException (org.xml.sax.SAXException)18 NodeList (org.w3c.dom.NodeList)13 Input (beast.core.Input)12 MRCAPrior (beast.math.distributions.MRCAPrior)12 File (java.io.File)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)12 XMLParser (beast.util.XMLParser)11 TransformerException (javax.xml.transform.TransformerException)11 Alignment (beast.evolution.alignment.Alignment)10 XMLParserException (beast.util.XMLParserException)10 BEASTObject (beast.core.BEASTObject)9 Distribution (beast.core.Distribution)9 XMLProducer (beast.util.XMLProducer)9 CompoundDistribution (beast.core.util.CompoundDistribution)8 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)8