Search in sources :

Example 1 with PaddingPanel

use of edu.cmu.tetradapp.ui.PaddingPanel in project tetrad by cmu-phil.

the class GeneralAlgorithmEditor method createAlgorithmFilterPanel.

private JPanel createAlgorithmFilterPanel() {
    // Filter based on algo types dropdown
    Box algoTypesBox = Box.createVerticalBox();
    // Algo types label box
    Box algTypesBoxLabelBox = Box.createHorizontalBox();
    algTypesBoxLabelBox.add(new JLabel("Show algorithms that: "));
    algTypesBoxLabelBox.setAlignmentX(LEFT_ALIGNMENT);
    // Add label to containing box
    algoTypesBox.add(algTypesBoxLabelBox);
    // All option
    Box algoTypeOptionAllBox = Box.createHorizontalBox();
    algoTypeOptionAllBox.setAlignmentX(LEFT_ALIGNMENT);
    // Add all option to containing box
    algoTypesBox.add(algoTypeOptionAllBox);
    // add radio buttons to panel
    if (!algoTypeOpts.isEmpty()) {
        Dimension indentSize = new Dimension(10, 20);
        algoTypeOpts.forEach(btn -> {
            Box box = Box.createHorizontalBox();
            box.setAlignmentX(LEFT_ALIGNMENT);
            box.add(Box.createRigidArea(indentSize));
            box.add(btn);
            algoTypesBox.add(box);
        });
    }
    // Is there a prior knowledge file?
    Box priorKnowledgeBox = Box.createVerticalBox();
    // Add label into this label box to size
    Box priorKnowledgeLabelBox = Box.createHorizontalBox();
    priorKnowledgeLabelBox.add(new JLabel("Show only: "));
    priorKnowledgeLabelBox.setAlignmentX(LEFT_ALIGNMENT);
    // Checkbox container
    Box priorKnowledgeOptionBox = Box.createHorizontalBox();
    priorKnowledgeOptionBox.setAlignmentX(LEFT_ALIGNMENT);
    // Add padding and option
    priorKnowledgeOptionBox.add(Box.createRigidArea(new Dimension(10, 20)));
    priorKnowledgeOptionBox.add(knowledgeChkBox);
    // Add to containg box
    priorKnowledgeBox.add(priorKnowledgeLabelBox);
    priorKnowledgeBox.add(priorKnowledgeOptionBox);
    Box algoFiltersBox = Box.createVerticalBox();
    algoFiltersBox.setAlignmentX(LEFT_ALIGNMENT);
    algoFiltersBox.add(algoTypesBox);
    algoFiltersBox.add(Box.createVerticalStrut(10));
    algoFiltersBox.add(priorKnowledgeBox);
    JPanel algoFilter = new JPanel(new BorderLayout());
    algoFilter.setBorder(BorderFactory.createTitledBorder("Algorithm Filters"));
    algoFilter.add(new PaddingPanel(algoFiltersBox), BorderLayout.CENTER);
    return algoFilter;
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) PaddingPanel(edu.cmu.tetradapp.ui.PaddingPanel)

Example 2 with PaddingPanel

use of edu.cmu.tetradapp.ui.PaddingPanel in project tetrad by cmu-phil.

the class GeneralAlgorithmEditor method createAlgorithmPanel.

private JPanel createAlgorithmPanel() {
    JButton resetSettingsBtn = new JButton("Reset All Settings");
    resetSettingsBtn.addActionListener((e) -> {
        resetAllSettings();
    });
    JPanel westMainSouthPanel = new JPanel(new BorderLayout(0, 10));
    westMainSouthPanel.add(new TestAndScorePanel(), BorderLayout.CENTER);
    westMainSouthPanel.add(resetSettingsBtn, BorderLayout.SOUTH);
    JPanel westMainWestPanel = new JPanel(new BorderLayout(0, 10));
    westMainWestPanel.add(createAlgorithmFilterPanel(), BorderLayout.CENTER);
    westMainWestPanel.add(westMainSouthPanel, BorderLayout.SOUTH);
    JPanel westMainPanel = new JPanel(new BorderLayout(5, 0));
    westMainPanel.add(westMainWestPanel, BorderLayout.WEST);
    westMainPanel.add(new AlgorithmListPanel(), BorderLayout.EAST);
    JPanel algoCard = new JPanel(new BorderLayout(10, 0));
    algoCard.add(westMainPanel, BorderLayout.WEST);
    algoCard.add(new AlgoDescPanel(), BorderLayout.CENTER);
    return new PaddingPanel(algoCard);
}
Also used : JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) JButton(javax.swing.JButton) PaddingPanel(edu.cmu.tetradapp.ui.PaddingPanel)

Example 3 with PaddingPanel

use of edu.cmu.tetradapp.ui.PaddingPanel in project tetrad by cmu-phil.

the class SimulationEditor method resetPanel.

private void resetPanel(Simulation simulation, String[] graphItems, String[] simulationItems, JTabbedPane tabbedPane) {
    RandomGraph randomGraph = (simulation.getSourceGraph() == null) ? new SingleGraph(new EdgeListGraph()) : new SingleGraph(simulation.getSourceGraph());
    if (!simulation.isFixedGraph()) {
        String graphItem = (String) graphsDropdown.getSelectedItem();
        simulation.getParams().set("graphsDropdownPreference", graphItem);
        if (graphItem.equals(graphItems[0])) {
            randomGraph = new RandomForward();
        } else if (graphItem.equals(graphItems[1])) {
            randomGraph = new ScaleFree();
        } else if (graphItem.equals(graphItems[2])) {
            randomGraph = new Cyclic();
        } else if (graphItem.equals(graphItems[3])) {
            randomGraph = new RandomSingleFactorMim();
        } else if (graphItem.equals(graphItems[4])) {
            randomGraph = new RandomTwoFactorMim();
        } else {
            throw new IllegalArgumentException("Unrecognized simulation type: " + graphItem);
        }
    }
    if (!simulation.isFixedSimulation()) {
        if (simulation.getSourceGraph() == null) {
            String simulationItem = (String) simulationsDropdown.getSelectedItem();
            simulation.getParams().set("simulationsDropdownPreference", simulationItem);
            simulation.setFixedGraph(false);
            if (randomGraph instanceof SingleGraph) {
                simulation.setFixedGraph(true);
            }
            if (simulationItem.equals(simulationItems[0])) {
                simulation.setSimulation(new BayesNetSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[1])) {
                simulation.setSimulation(new SemSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[2])) {
                simulation.setSimulation(new LinearFisherModel(randomGraph, simulation.getInputDataModelList()), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[3])) {
                simulation.setSimulation(new LeeHastieSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[4])) {
                simulation.setSimulation(new ConditionalGaussianSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[5])) {
                simulation.setSimulation(new TimeSeriesSemSimulation(randomGraph), simulation.getParams());
            } else {
                throw new IllegalArgumentException("Unrecognized simulation type: " + simulationItem);
            }
        } else {
            String simulationItem = (String) simulationsDropdown.getSelectedItem();
            simulation.getParams().set("simulationsDropdownPreference", simulationItem);
            simulation.setFixedGraph(false);
            if (randomGraph instanceof SingleGraph) {
                simulation.setFixedGraph(true);
            }
            if (simulationItem.equals(simulationItems[0])) {
                simulation.setSimulation(new BayesNetSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[1])) {
                simulation.setSimulation(new SemSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[2])) {
                simulation.setSimulation(new LinearFisherModel(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[3])) {
                simulation.setSimulation(new LeeHastieSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[4])) {
                simulation.setSimulation(new ConditionalGaussianSimulation(randomGraph), simulation.getParams());
            } else if (simulationItem.equals(simulationItems[5])) {
                simulation.setSimulation(new TimeSeriesSemSimulation(randomGraph), simulation.getParams());
            } else {
                throw new IllegalArgumentException("Unrecognized simulation type: " + simulationItem);
            }
        }
    }
    tabbedPane.setComponentAt(0, new PaddingPanel(getParameterPanel(simulation, simulation.getSimulation(), simulation.getParams())));
}
Also used : LinearFisherModel(edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel) RandomSingleFactorMim(edu.cmu.tetrad.algcomparison.graph.RandomSingleFactorMim) TimeSeriesSemSimulation(edu.cmu.tetrad.algcomparison.simulation.TimeSeriesSemSimulation) GeneralSemSimulation(edu.cmu.tetrad.algcomparison.simulation.GeneralSemSimulation) SemSimulation(edu.cmu.tetrad.algcomparison.simulation.SemSimulation) StandardizedSemSimulation(edu.cmu.tetrad.algcomparison.simulation.StandardizedSemSimulation) RandomForward(edu.cmu.tetrad.algcomparison.graph.RandomForward) EdgeListGraph(edu.cmu.tetrad.graph.EdgeListGraph) BayesNetSimulation(edu.cmu.tetrad.algcomparison.simulation.BayesNetSimulation) ScaleFree(edu.cmu.tetrad.algcomparison.graph.ScaleFree) TimeSeriesSemSimulation(edu.cmu.tetrad.algcomparison.simulation.TimeSeriesSemSimulation) PaddingPanel(edu.cmu.tetradapp.ui.PaddingPanel) RandomTwoFactorMim(edu.cmu.tetrad.algcomparison.graph.RandomTwoFactorMim) RandomGraph(edu.cmu.tetrad.algcomparison.graph.RandomGraph) Cyclic(edu.cmu.tetrad.algcomparison.graph.Cyclic) LeeHastieSimulation(edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation) ConditionalGaussianSimulation(edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation) SingleGraph(edu.cmu.tetrad.algcomparison.graph.SingleGraph)

Example 4 with PaddingPanel

use of edu.cmu.tetradapp.ui.PaddingPanel in project tetrad by cmu-phil.

the class SimulationEditor method getParameterPanel.

private JPanel getParameterPanel(Simulation simulationModel, edu.cmu.tetrad.algcomparison.simulation.Simulation simulation, Parameters parameters) {
    boolean fixedGraph = simulationModel.isFixedGraph();
    graphsDropdown.setEnabled(!fixedGraph);
    simulationsDropdown.setEnabled(!simulationModel.isFixedSimulation());
    Font labelFont = new Font("Dialog", Font.BOLD, 13);
    Box northBox = Box.createVerticalBox();
    // type of graph options
    if (!fixedGraph) {
        Box box = Box.createHorizontalBox();
        JLabel label = new JLabel("Type of Graph: ");
        label.setFont(labelFont);
        box.add(label);
        box.add(Box.createGlue());
        graphsDropdown.setMaximumSize(graphsDropdown.getPreferredSize());
        box.add(graphsDropdown);
        northBox.add(box);
    }
    // type of simulation model options
    Box box = Box.createHorizontalBox();
    JLabel label = new JLabel("Type of Simulation Model: ");
    label.setFont(labelFont);
    box.add(label);
    box.add(Box.createGlue());
    simulationsDropdown.setMaximumSize(simulationsDropdown.getPreferredSize());
    box.add(simulationsDropdown);
    northBox.add(Box.createVerticalStrut(10));
    northBox.add(box);
    label = new JLabel("Parameters for your simulation are listed below. Please adjust the parameter values.");
    label.setFont(labelFont);
    JPanel paramLblPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    paramLblPanel.add(label);
    JPanel paramPanel = (simulation == null) ? new JPanel() : new PaddingPanel(new ParameterPanel(simulation.getParameters(), parameters));
    JPanel centerPanel = new JPanel(new BorderLayout());
    centerPanel.add(paramLblPanel, BorderLayout.NORTH);
    centerPanel.add(paramPanel, BorderLayout.CENTER);
    JPanel southPanel = new JPanel();
    southPanel.add(simulateButton);
    JPanel northMainPanel = new JPanel(new BorderLayout(0, 10));
    northMainPanel.add(northBox, BorderLayout.NORTH);
    northMainPanel.add(centerPanel, BorderLayout.CENTER);
    JPanel mainPanel = new JPanel(new BorderLayout(0, 10));
    mainPanel.add(new JScrollPane(northMainPanel), BorderLayout.CENTER);
    mainPanel.add(southPanel, BorderLayout.SOUTH);
    return mainPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) PaddingPanel(edu.cmu.tetradapp.ui.PaddingPanel) Font(java.awt.Font)

Example 5 with PaddingPanel

use of edu.cmu.tetradapp.ui.PaddingPanel in project tetrad by cmu-phil.

the class AlgorithmParameterPanel method addToPanel.

public void addToPanel(GeneralAlgorithmRunner runner) {
    List<String> parametersToEdit = runner.getAlgorithm().getParameters();
    Parameters parameters = runner.getParameters();
    Algorithm algoAnno = runner.getAlgorithm().getClass().getAnnotation(Algorithm.class);
    String title = (algoAnno == null) ? DEFAULT_TITLE_BORDER : String.format("%s Parameters", algoAnno.name());
    setBorder(BorderFactory.createTitledBorder(title));
    removeAll();
    Box paramsBox = Box.createVerticalBox();
    // But we added bootstrap parameters anyway  - Zhou
    if (parametersToEdit.isEmpty()) {
        Box row = Box.createHorizontalBox();
        row.add(new JLabel("No parameters to edit"));
        paramsBox.add(row);
    } else {
        List<String> uniqueParams = parametersToEdit.stream().distinct().collect(Collectors.toList());
        uniqueParams.forEach(parameter -> {
            Object defaultValue = ParamDescriptions.getInstance().get(parameter).getDefaultValue();
            JComponent parameterSelection;
            if (defaultValue instanceof Double) {
                double lowerBoundDouble = ParamDescriptions.getInstance().get(parameter).getLowerBoundDouble();
                double upperBoundDouble = ParamDescriptions.getInstance().get(parameter).getUpperBoundDouble();
                parameterSelection = getDoubleField(parameter, parameters, (Double) defaultValue, lowerBoundDouble, upperBoundDouble);
            } else if (defaultValue instanceof Integer) {
                int lowerBoundInt = ParamDescriptions.getInstance().get(parameter).getLowerBoundInt();
                int upperBoundInt = ParamDescriptions.getInstance().get(parameter).getUpperBoundInt();
                parameterSelection = getIntTextField(parameter, parameters, (Integer) defaultValue, lowerBoundInt, upperBoundInt);
            } else if (defaultValue instanceof Boolean) {
                // Joe's old implementation with dropdown yes or no
                // parameterSelection = getBooleanBox(parameter, parameters, (Boolean) defaultValue);
                // Zhou's new implementation with yes/no radio buttons
                parameterSelection = getBooleanSelectionBox(parameter, parameters, (Boolean) defaultValue);
            } else if (defaultValue instanceof String) {
                parameterSelection = getStringField(parameter, parameters, (String) defaultValue);
            } else {
                throw new IllegalArgumentException("Unexpected type: " + defaultValue.getClass());
            }
            // Each parameter row contains parameter label and selection/input field
            Box paramRow = Box.createHorizontalBox();
            JLabel paramLabel = new JLabel(ParamDescriptions.getInstance().get(parameter).getDescription());
            paramRow.add(paramLabel);
            paramRow.add(Box.createHorizontalGlue());
            paramRow.add(parameterSelection);
            // Add each paramRow to paramsBox
            paramsBox.add(paramRow);
            // Also add some gap between rows
            paramsBox.add(Box.createVerticalStrut(10));
        });
    }
    add(new PaddingPanel(paramsBox), BorderLayout.CENTER);
}
Also used : Parameters(edu.cmu.tetrad.util.Parameters) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JComboBox(javax.swing.JComboBox) PaddingPanel(edu.cmu.tetradapp.ui.PaddingPanel) Algorithm(edu.cmu.tetrad.annotation.Algorithm)

Aggregations

PaddingPanel (edu.cmu.tetradapp.ui.PaddingPanel)5 BorderLayout (java.awt.BorderLayout)3 Box (javax.swing.Box)3 JComboBox (javax.swing.JComboBox)3 JLabel (javax.swing.JLabel)3 JPanel (javax.swing.JPanel)3 Cyclic (edu.cmu.tetrad.algcomparison.graph.Cyclic)1 RandomForward (edu.cmu.tetrad.algcomparison.graph.RandomForward)1 RandomGraph (edu.cmu.tetrad.algcomparison.graph.RandomGraph)1 RandomSingleFactorMim (edu.cmu.tetrad.algcomparison.graph.RandomSingleFactorMim)1 RandomTwoFactorMim (edu.cmu.tetrad.algcomparison.graph.RandomTwoFactorMim)1 ScaleFree (edu.cmu.tetrad.algcomparison.graph.ScaleFree)1 SingleGraph (edu.cmu.tetrad.algcomparison.graph.SingleGraph)1 BayesNetSimulation (edu.cmu.tetrad.algcomparison.simulation.BayesNetSimulation)1 ConditionalGaussianSimulation (edu.cmu.tetrad.algcomparison.simulation.ConditionalGaussianSimulation)1 GeneralSemSimulation (edu.cmu.tetrad.algcomparison.simulation.GeneralSemSimulation)1 LeeHastieSimulation (edu.cmu.tetrad.algcomparison.simulation.LeeHastieSimulation)1 LinearFisherModel (edu.cmu.tetrad.algcomparison.simulation.LinearFisherModel)1 SemSimulation (edu.cmu.tetrad.algcomparison.simulation.SemSimulation)1 StandardizedSemSimulation (edu.cmu.tetrad.algcomparison.simulation.StandardizedSemSimulation)1