Search in sources :

Example 1 with SmallLabel

use of beast.app.draw.SmallLabel 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);
}
Also used : SmallLabel(beast.app.draw.SmallLabel) JComboBox(javax.swing.JComboBox) Color(java.awt.Color) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JComboBox(javax.swing.JComboBox) Dimension(java.awt.Dimension) Font(java.awt.Font) TreeDistribution(beast.evolution.tree.TreeDistribution) List(java.util.List) BEASTInterface(beast.core.BEASTInterface)

Example 2 with SmallLabel

use of beast.app.draw.SmallLabel in project beast2 by CompEvol.

the class ClockModelListInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
    fixMeanRatesCheckBox = new JCheckBox("Fix mean rate of clock models");
    m_buttonStatus = ButtonStatus.NONE;
    super.init(input, beastObject, itemNr, isExpandOption, addButtons);
    List<Operator> operators = ((MCMC) doc.mcmc.get()).operatorsInput.get();
    fixMeanRatesCheckBox.addActionListener(e -> {
        JCheckBox averageRatesBox = (JCheckBox) e.getSource();
        boolean averageRates = averageRatesBox.isSelected();
        List<Operator> operators2 = ((MCMC) doc.mcmc.get()).operatorsInput.get();
        if (averageRates) {
            // connect DeltaExchangeOperator
            if (!operators2.contains(operator)) {
                operators2.add(operator);
            }
            // set up relative weights
            setUpOperator();
        } else {
            operators2.remove(operator);
            fixMeanRatesValidateLabel.setVisible(false);
            repaint();
        }
    });
    operator = (DeltaExchangeOperator) doc.pluginmap.get("FixMeanRatesOperator");
    if (operator == null) {
        operator = new DeltaExchangeOperator();
        try {
            operator.setID("FixMeanRatesOperator");
            operator.initByName("weight", 2.0, "delta", 0.75);
        } catch (Exception e1) {
        // ignore initAndValidate exception
        }
        doc.addPlugin(operator);
    }
    fixMeanRatesCheckBox.setSelected(operators.contains(operator));
    Box box = Box.createHorizontalBox();
    box.add(fixMeanRatesCheckBox);
    box.add(Box.createHorizontalGlue());
    fixMeanRatesValidateLabel = new SmallLabel("x", Color.GREEN);
    fixMeanRatesValidateLabel.setVisible(false);
    box.add(fixMeanRatesValidateLabel);
    if (((List<?>) input.get()).size() > 1 && operator != null) {
        add(box);
    }
    setUpOperator();
}
Also used : JCheckBox(javax.swing.JCheckBox) Operator(beast.core.Operator) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator) SmallLabel(beast.app.draw.SmallLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) ArrayList(java.util.ArrayList) List(java.util.List) DeltaExchangeOperator(beast.evolution.operators.DeltaExchangeOperator)

Aggregations

SmallLabel (beast.app.draw.SmallLabel)2 List (java.util.List)2 Box (javax.swing.Box)2 BEASTInterface (beast.core.BEASTInterface)1 Operator (beast.core.Operator)1 DeltaExchangeOperator (beast.evolution.operators.DeltaExchangeOperator)1 TreeDistribution (beast.evolution.tree.TreeDistribution)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Font (java.awt.Font)1 ArrayList (java.util.ArrayList)1 JCheckBox (javax.swing.JCheckBox)1 JComboBox (javax.swing.JComboBox)1 JLabel (javax.swing.JLabel)1