Search in sources :

Example 1 with InputEditor

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

the class GeneTreeForSpeciesTreeDistributionInputEditor method createPloidyEditor.

public InputEditor createPloidyEditor() {
    InputEditor editor = new InputEditor.Base(doc) {

        private static final long serialVersionUID = 1L;

        @Override
        public Class<?> type() {
            return null;
        }

        @Override
        public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
            m_beastObject = beastObject;
            m_input = input;
            m_bAddButtons = addButtons;
            this.itemNr = itemNr;
            addInputLabel();
            m_selectBeastObjectBox = new JComboBox<>(valuesString);
            setSelection();
            String selectString = input.get().toString();
            m_selectBeastObjectBox.setSelectedItem(selectString);
            m_selectBeastObjectBox.addActionListener(e -> {
                int i = m_selectBeastObjectBox.getSelectedIndex();
                if (i == OTHER) {
                    setSelection();
                    return;
                }
                try {
                    setValue(_values[i]);
                // lm_input.setValue(selected, m_beastObject);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            });
            m_selectBeastObjectBox.setToolTipText(input.getHTMLTipText());
            add(m_selectBeastObjectBox);
            add(Box.createGlue());
        }

        private void setSelection() {
            Double value = (Double) m_input.get();
            m_selectBeastObjectBox.setSelectedIndex(OTHER);
            for (int i = 0; i < _values.length; i++) {
                if (value.equals(_values[i])) {
                    m_selectBeastObjectBox.setSelectedIndex(i);
                }
            }
        }
    };
    editor.init(((GeneTreeForSpeciesTreeDistribution) m_beastObject).ploidyInput, m_beastObject, -1, ExpandOption.FALSE, true);
    return editor;
}
Also used : Input(beast.core.Input) InputEditor(beast.app.draw.InputEditor) BEASTInterface(beast.core.BEASTInterface)

Example 2 with InputEditor

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

the class ConstantPopulationInputEditor method init.

@Override
public void init(Input<?> input, BEASTInterface beastObject, int itemNr, ExpandOption isExpandOption, boolean addButtons) {
    ConstantPopulation population = (ConstantPopulation) input.get();
    try {
        InputEditor editor = doc.inputEditorFactory.createInputEditor(population.popSizeParameter, population, doc);
        add(editor.getComponent());
    } catch (NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
// TODO Auto-generated method stub
// super.init(input, beastObject, itemNr, isExpandOption, addButtons);
}
Also used : ConstantPopulation(beast.evolution.tree.coalescent.ConstantPopulation) InputEditor(beast.app.draw.InputEditor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with InputEditor

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

the class PriorListInputEditor method addPluginItem.

/**
 * add components to box that are specific for the beastObject.
 * By default, this just inserts a label with the beastObject ID
 *
 * @param itemBox box to add components to
 * @param beastObject  beastObject to add
 */
@Override
protected InputEditor addPluginItem(Box itemBox, BEASTInterface beastObject) {
    try {
        int listItemNr = ((List<?>) m_input.get()).indexOf(beastObject);
        InputEditor editor = doc.getInputEditorFactory().createInputEditor(m_input, listItemNr, beastObject, false, ExpandOption.FALSE, ButtonStatus.NONE, null, doc);
        itemBox.add((Component) editor);
        return editor;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return this;
}
Also used : InputEditor(beast.app.draw.InputEditor) ListInputEditor(beast.app.draw.ListInputEditor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with InputEditor

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

the class BeautiPanel method refreshInputPanel.

void refreshInputPanel(BEASTInterface beastObject, Input<?> input, boolean addButtons, InputEditor.ExpandOption forceExpansion) throws NoSuchMethodException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    if (centralComponent != null) {
        remove(centralComponent);
    }
    if (input != null && input.get() != null && input.getType() != null) {
        InputEditor.ButtonStatus bs = config.buttonStatusInput.get();
        InputEditor inputEditor = doc.getInputEditorFactory().createInputEditor(input, beastObject, addButtons, forceExpansion, bs, null, doc);
        JPanel p = new JPanel();
        p.setLayout(new BorderLayout());
        if (isToClone()) {
            ClonePartitionPanel clonePartitionPanel = new ClonePartitionPanel(this);
            p.add(clonePartitionPanel, BorderLayout.NORTH);
        } else {
            p.add(inputEditor.getComponent(), BorderLayout.CENTER);
        }
        Rectangle bounds = new Rectangle(0, 0);
        if (scroller != null) {
            // get lastPaintPosition from viewport
            // HACK access it through its string representation
            JViewport v = scroller.getViewport();
            String vs = v.toString();
            int i = vs.indexOf("lastPaintPosition=java.awt.Point[x=");
            if (i > -1) {
                i = vs.indexOf("y=", i);
                vs = vs.substring(i + 2, vs.indexOf("]", i));
                i = Integer.parseInt(vs);
            } else {
                i = 0;
            }
            bounds.y = -i;
        }
        scroller = new JScrollPane(p);
        scroller.getViewport().scrollRectToVisible(bounds);
        centralComponent = scroller;
    } else {
        centralComponent = new JLabel("No input editors.");
    }
    if (splitPane != null) {
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.add(centralComponent, BorderLayout.NORTH);
        splitPane.add(panel, JSplitPane.RIGHT);
    } else {
        add(centralComponent);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) InputEditor(beast.app.draw.InputEditor) BorderLayout(java.awt.BorderLayout) JViewport(javax.swing.JViewport) Rectangle(java.awt.Rectangle) JLabel(javax.swing.JLabel)

Aggregations

InputEditor (beast.app.draw.InputEditor)4 ListInputEditor (beast.app.draw.ListInputEditor)1 BEASTInterface (beast.core.BEASTInterface)1 Input (beast.core.Input)1 ConstantPopulation (beast.evolution.tree.coalescent.ConstantPopulation)1 BorderLayout (java.awt.BorderLayout)1 Rectangle (java.awt.Rectangle)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JViewport (javax.swing.JViewport)1