use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class HierarchicalPriorDialog method setupComponents.
private void setupComponents() {
panel.removeAll();
JPanel mainPanel = new JPanel(new GridBagLayout());
panel.add(mainPanel);
OptionsPanel[] optionsPanel = new OptionsPanel[4];
JPanel[] panel = new JPanel[4];
for (int i = 0; i < 4; ++i) {
optionsPanel[i] = new OptionsPanel(12, (OSType.isMac() ? 6 : 24));
panel[i] = new JPanel(new FlowLayout(FlowLayout.CENTER));
if (i > 1) {
panel[i].setLayout(new BoxLayout(panel[i], BoxLayout.PAGE_AXIS));
}
panel[i].add(optionsPanel[i]);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = i % 2;
gbc.gridy = i / 2;
mainPanel.add(panel[i], gbc);
}
optionsPanel[0].addComponent(new JLabel("Select HPM for parameters: "));
OptionsPanel list = new OptionsPanel();
list.setBackground(Color.WHITE);
list.setOpaque(true);
for (Parameter p : parameterList) {
JLabel label = new JLabel("\t" + p.getName());
label.setForeground(Color.DARK_GRAY);
list.addSpanningComponent(label);
}
optionsPanel[0].addSpanningComponent(list);
PriorType modelType;
optionsPanel[1].addComponentWithLabel("Hierarchical Distribution: ", priorCombo);
modelType = (PriorType) priorCombo.getSelectedItem();
optionsPanel[1].addSeparator();
String modelName = "untitled";
nameField = new JTextField(modelName);
nameField.setColumns(10);
optionsPanel[1].addComponentWithLabel("Unique Name: ", nameField);
optionsPanel[2].addSeparator();
optionsPanel[3].addSeparator();
optionsPanel[2].addSpanningComponent(new JLabel("Population Mean Hyperprior: Normal"));
optionsPanel[3].addSpanningComponent(new JLabel("Population Precision Hyperprior: Gamma"));
optionsPanel[2].addSpanningComponent(optionsPanels.get(PriorType.NORMAL_PRIOR));
optionsPanel[3].addSpanningComponent(optionsPanels.get(PriorType.GAMMA_PRIOR));
optionsPanel[2].addSeparator();
optionsPanel[3].addSeparator();
setupChart();
for (int i = 0; i < 2; ++i) {
chart[i].setPreferredSize(new Dimension(300, 200));
chart[i].setFontSize(8);
panel[2 + i].add(chart[i]);
panel[2 + i].add(quantilePanel[i]);
}
setArguments(modelType);
mainPanel.repaint();
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class HierarchicalPriorDialog method setupComponents.
private void setupComponents() {
panel.removeAll();
JPanel mainPanel = new JPanel(new GridBagLayout());
panel.add(mainPanel);
OptionsPanel[] optionsPanel = new OptionsPanel[4];
JPanel[] panel = new JPanel[4];
for (int i = 0; i < 4; ++i) {
optionsPanel[i] = new OptionsPanel(12, (OSType.isMac() ? 6 : 24));
panel[i] = new JPanel(new FlowLayout(FlowLayout.CENTER));
if (i > 1) {
panel[i].setLayout(new BoxLayout(panel[i], BoxLayout.PAGE_AXIS));
}
panel[i].add(optionsPanel[i]);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = i % 2;
gbc.gridy = i / 2;
mainPanel.add(panel[i], gbc);
}
String modelName = "untitled";
nameField = new JTextField(modelName);
nameField.setColumns(10);
optionsPanel[0].addComponentWithLabel("Unique Name: ", nameField);
PriorType modelType;
optionsPanel[0].addComponentWithLabel("Hierarchical Distribution: ", priorCombo);
modelType = (PriorType) priorCombo.getSelectedItem();
// optionsPanel[0].addSeparator();
optionsPanel[1].addComponent(new JLabel("Selected parameters: "));
Object[] parameters = parameterList.toArray();
// data has type Object[]
JList list = new JList(parameters);
// list.setSelectionModel(null);
list.setLayoutOrientation(JList.VERTICAL);
list.setVisibleRowCount(-1);
list.setEnabled(false);
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setPreferredSize(new Dimension(250, 120));
optionsPanel[1].addSpanningComponent(scrollPane);
optionsPanel[2].addSeparator();
optionsPanel[3].addSeparator();
optionsPanel[2].addSpanningComponent(new JLabel("Population Mean Hyperprior: Normal"));
optionsPanel[3].addSpanningComponent(new JLabel("Population Precision Hyperprior: Gamma"));
optionsPanel[2].addSpanningComponent(optionsPanels.get(PriorType.NORMAL_PRIOR));
optionsPanel[3].addSpanningComponent(optionsPanels.get(PriorType.GAMMA_PRIOR));
optionsPanel[2].addSeparator();
optionsPanel[3].addSeparator();
setupChart();
for (int i = 0; i < 2; ++i) {
chart[i].setPreferredSize(new Dimension(300, 200));
chart[i].setFontSize(8);
panel[2 + i].add(chart[i]);
panel[2 + i].add(quantilePanel[i]);
}
setArguments(modelType);
mainPanel.repaint();
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class HierarchicalPriorDialog method showDialog.
public int showDialog(final java.util.List<Parameter> parameterList) {
this.parameterList = parameterList;
this.parameter = parameterList.get(0);
PriorType priorType = parameter.priorType;
// Set-up combo box depending on parameters
priorCombo.removeAllItems();
if (parameter.isNonNegative) {
priorCombo.addItem(PriorType.LOGNORMAL_HPM_PRIOR);
}
priorCombo.addItem(PriorType.NORMAL_HPM_PRIOR);
priorCombo.setSelectedItem(priorType);
double lower = Double.NEGATIVE_INFINITY;
double upper = Double.POSITIVE_INFINITY;
if (parameter.isZeroOne) {
lower = 0.0;
upper = 1.0;
} else if (parameter.isNonNegative) {
lower = 0.0;
}
initialField.setRange(lower, upper);
initialField.setValue(parameter.getInitial());
panel = new JPanel(new GridBagLayout());
setupComponents();
JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setBorder(null);
scrollPane.getViewport().setOpaque(false);
JOptionPane optionPane = new JOptionPane(scrollPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, null, null);
optionPane.setBorder(new EmptyBorder(12, 12, 12, 12));
final JDialog dialog = optionPane.createDialog(frame, "Phylogenetic Hierarchical Model Setup");
priorCombo.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
setupComponents();
dialog.validate();
dialog.repaint();
dialog.pack();
}
});
for (PriorOptionsPanel optionsPanel : optionsPanels.values()) {
optionsPanel.addListener(new PriorOptionsPanel.Listener() {
public void optionsPanelChanged() {
setupChart();
dialog.validate();
dialog.repaint();
}
});
}
dialog.pack();
if (OSType.isMac()) {
dialog.setMinimumSize(new Dimension(dialog.getBounds().width, 300));
} else {
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension d = tk.getScreenSize();
if (d.height < 700 && panel.getHeight() > 450) {
dialog.setSize(new Dimension(panel.getWidth() + 100, 550));
} else {
// setSize because optionsPanel is shrunk in dialog
dialog.setSize(new Dimension(panel.getWidth() + 100, panel.getHeight() + 100));
}
// System.out.println("panel width = " + panel.getWidth());
// System.out.println("panel height = " + panel.getHeight());
}
dialog.setResizable(true);
dialog.setVisible(true);
int result = JOptionPane.CANCEL_OPTION;
Integer value = (Integer) optionPane.getValue();
if (value != null && value != -1) {
result = value;
}
return result;
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class PriorSettingsPanel method setupComponents.
private void setupComponents() {
removeAll();
OptionsPanel optionsPanel = new OptionsPanel(12, (OSType.isMac() ? 6 : 24));
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
panel1.add(optionsPanel);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.weightx = 1.0;
gbc.weighty = 0.0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.PAGE_START;
gbc.gridwidth = GridBagConstraints.REMAINDER;
add(panel1, gbc);
PriorType priorType = (PriorType) priorCombo.getSelectedItem();
if (!parameter.isPriorFixed) {
optionsPanel.addComponentWithLabel("Prior Distribution: ", priorCombo);
} else {
optionsPanel.addComponentWithLabel("Prior Distribution: ", new JLabel(priorType.toString()));
}
PriorOptionsPanel panel3 = optionsPanels.get(priorType);
if (panel3 != null) {
// important to make init field appear during switch
panel3.setArguments(parameter, priorType);
optionsPanel.addSpanningComponent(panel3);
}
if (priorType == PriorType.CTMC_RATE_REFERENCE_PRIOR) {
optionsPanel.addSpanningComponent(citationText);
}
if (priorType == PriorType.ONE_OVER_X_PRIOR) {
optionsPanel.addSpanningComponent(oneOverXCaution);
}
if (priorType == PriorType.NONE_IMPROPER) {
optionsPanel.addSpanningComponent(improperCaution);
}
if (priorType.isPlottable()) {
optionsPanel.addSeparator();
setupChart();
chart.setMinimumSize(new Dimension(120, 120));
chart.setPreferredSize(new Dimension(300, 200));
chart.setFontSize(8);
gbc.gridy = 1;
gbc.weighty = 1.0;
gbc.fill = GridBagConstraints.BOTH;
add(chart, gbc);
gbc.gridy = 2;
gbc.weighty = 0.0;
gbc.anchor = GridBagConstraints.PAGE_END;
gbc.fill = GridBagConstraints.HORIZONTAL;
add(quantilePanel, gbc);
}
repaint();
}
use of dr.app.beauti.types.PriorType in project beast-mcmc by beast-dev.
the class PriorSettingsPanel method hasInvalidInput.
public boolean hasInvalidInput(boolean showError) {
PriorType priorType = (PriorType) priorCombo.getSelectedItem();
PriorOptionsPanel panel = optionsPanels.get(priorType);
if (panel != null) {
if (panel.hasInvalidInput(priorType)) {
if (showError)
JOptionPane.showMessageDialog(frame, panel.error, "Invalid input", JOptionPane.ERROR_MESSAGE);
return true;
} else {
return false;
}
}
// if there is no panel for this prior type then assume it is valid
return false;
// throw new IllegalComponentStateException("Cannot get PriorOptionsPanel");
}
Aggregations