Search in sources :

Example 1 with PartitionContext

use of beast.app.beauti.PartitionContext in project beast2 by CompEvol.

the class ParameterInputEditor method addComboBox.

@Override
protected void addComboBox(JComponent box, Input<?> input, BEASTInterface beastObject) {
    Box paramBox = Box.createHorizontalBox();
    Parameter.Base<?> parameter = null;
    if (itemNr >= 0) {
        parameter = (Parameter.Base<?>) ((List<?>) input.get()).get(itemNr);
    } else {
        parameter = (Parameter.Base<?>) input.get();
    }
    if (parameter == null) {
        super.addComboBox(box, input, beastObject);
    } else {
        setUpEntry();
        paramBox.add(m_entry);
        if (doc.allowLinking) {
            boolean isLinked = doc.isLinked(m_input);
            if (isLinked || doc.suggestedLinks((BEASTInterface) m_input.get()).size() > 0) {
                JButton linkbutton = new JButton(Utils.getIcon(BeautiPanel.ICONPATH + (isLinked ? "link.png" : "unlink.png")));
                linkbutton.setBorder(BorderFactory.createEmptyBorder());
                linkbutton.setToolTipText("link/unlink this parameter with another compatible parameter");
                linkbutton.addActionListener(e -> {
                    if (doc.isLinked(m_input)) {
                        // unlink
                        try {
                            BEASTInterface candidate = doc.getUnlinkCandidate(m_input, m_beastObject);
                            m_input.setValue(candidate, m_beastObject);
                            doc.deLink(m_input);
                        } catch (RuntimeException e2) {
                            e2.printStackTrace();
                            JOptionPane.showMessageDialog(this, "Could not unlink: " + e2.getMessage());
                        }
                    } else {
                        // create a link
                        List<BEASTInterface> candidates = doc.suggestedLinks((BEASTInterface) m_input.get());
                        JComboBox<BEASTInterface> jcb = new JComboBox<>(candidates.toArray(new BEASTInterface[] {}));
                        JOptionPane.showMessageDialog(null, jcb, "select parameter to link with", JOptionPane.QUESTION_MESSAGE);
                        BEASTInterface candidate = (BEASTInterface) jcb.getSelectedItem();
                        if (candidate != null) {
                            try {
                                m_input.setValue(candidate, m_beastObject);
                                doc.addLink(m_input);
                            } catch (Exception e2) {
                                e2.printStackTrace();
                            }
                        }
                    }
                    refreshPanel();
                });
                paramBox.add(linkbutton);
            }
        }
        paramBox.add(Box.createHorizontalGlue());
        m_isEstimatedBox = new JCheckBox(doc.beautiConfig.getInputLabel(parameter, parameter.isEstimatedInput.getName()));
        m_isEstimatedBox.setName(input.getName() + ".isEstimated");
        if (input.get() != null) {
            m_isEstimatedBox.setSelected(parameter.isEstimatedInput.get());
        }
        m_isEstimatedBox.setToolTipText(parameter.isEstimatedInput.getHTMLTipText());
        boolean isClockRate = false;
        for (Object output : parameter.getOutputs()) {
            if (output instanceof BranchRateModel.Base) {
                isClockRate |= ((BranchRateModel.Base) output).meanRateInput.get() == parameter;
            }
        }
        m_isEstimatedBox.setEnabled(!isClockRate || !getDoc().autoSetClockRate);
        m_isEstimatedBox.addActionListener(e -> {
            try {
                Parameter.Base<?> parameter2 = (Parameter.Base<?>) m_input.get();
                parameter2.isEstimatedInput.setValue(m_isEstimatedBox.isSelected(), parameter2);
                if (isParametricDistributionParameter) {
                    String id = parameter2.getID();
                    if (id.startsWith("RealParameter")) {
                        ParametricDistribution parent = null;
                        for (Object beastObject2 : parameter2.getOutputs()) {
                            if (beastObject2 instanceof ParametricDistribution) {
                                parent = (ParametricDistribution) beastObject2;
                                break;
                            }
                        }
                        Distribution grandparent = null;
                        for (Object beastObject2 : parent.getOutputs()) {
                            if (beastObject2 instanceof Distribution) {
                                grandparent = (Distribution) beastObject2;
                                break;
                            }
                        }
                        id = "parameter.hyper" + parent.getClass().getSimpleName() + "-" + m_input.getName() + "-" + grandparent.getID();
                        doc.pluginmap.remove(parameter2.getID());
                        parameter2.setID(id);
                        doc.addPlugin(parameter2);
                    }
                    PartitionContext context = new PartitionContext(id.substring("parameter.".length()));
                    Log.warning.println(context + " " + id);
                    doc.beautiConfig.hyperPriorTemplate.createSubNet(context, true);
                }
                refreshPanel();
            } catch (Exception ex) {
                Log.err.println("ParameterInputEditor " + ex.getMessage());
            }
        });
        paramBox.add(m_isEstimatedBox);
        // only show the estimate flag if there is an operator that works on this parameter
        m_isEstimatedBox.setVisible(doc.isExpertMode());
        m_isEstimatedBox.setToolTipText("Estimate value of this parameter in the MCMC chain");
        // m_bAddButtons = false;
        if (itemNr < 0) {
            for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
                if (beastObject2 instanceof ParametricDistribution) {
                    m_isEstimatedBox.setVisible(true);
                    isParametricDistributionParameter = true;
                    break;
                }
            }
            for (Object beastObject2 : ((BEASTInterface) m_input.get()).getOutputs()) {
                if (beastObject2 instanceof Operator) {
                    m_isEstimatedBox.setVisible(true);
                    // m_editPluginButton.setVisible(true);
                    break;
                }
            }
        } else {
            for (Object beastObject2 : ((BEASTInterface) ((List<?>) m_input.get()).get(itemNr)).getOutputs()) {
                if (beastObject2 instanceof Operator) {
                    m_isEstimatedBox.setVisible(true);
                    // m_editPluginButton.setVisible(true);
                    break;
                }
            }
        }
        box.add(paramBox);
    }
}
Also used : Operator(beast.core.Operator) JComboBox(javax.swing.JComboBox) JButton(javax.swing.JButton) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) JComboBox(javax.swing.JComboBox) JCheckBox(javax.swing.JCheckBox) PartitionContext(beast.app.beauti.PartitionContext) ParametricDistribution(beast.math.distributions.ParametricDistribution) BranchRateModel(beast.evolution.branchratemodel.BranchRateModel) ParametricDistribution(beast.math.distributions.ParametricDistribution) Distribution(beast.core.Distribution) Parameter(beast.core.parameter.Parameter) List(java.util.List) BEASTInterface(beast.core.BEASTInterface)

Aggregations

PartitionContext (beast.app.beauti.PartitionContext)1 BEASTInterface (beast.core.BEASTInterface)1 Distribution (beast.core.Distribution)1 Operator (beast.core.Operator)1 Parameter (beast.core.parameter.Parameter)1 BranchRateModel (beast.evolution.branchratemodel.BranchRateModel)1 ParametricDistribution (beast.math.distributions.ParametricDistribution)1 List (java.util.List)1 Box (javax.swing.Box)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1