Example usage for javax.swing JRadioButton addActionListener

List of usage examples for javax.swing JRadioButton addActionListener

Introduction

In this page you can find the example usage for javax.swing JRadioButton addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:tvbrowser.ui.settings.WebbrowserSettingsTab.java

/**
 * Creates the settings panel for this tab.
 *///from ww  w  .ja v  a 2  s  .  c  o m
public JPanel createSettingsPanel() {
    mSettingsPn = new JPanel(new FormLayout("5dlu, 10dlu, pref, 3dlu, pref, 3dlu, pref, fill:3dlu:grow, 3dlu",
            "pref, 5dlu, pref, 5dlu, pref, 5dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref, 3dlu, pref"));
    mSettingsPn.setBorder(Borders.DIALOG_BORDER);

    CellConstraints cc = new CellConstraints();

    mSettingsPn.add(
            DefaultComponentFactory.getInstance().createSeparator(mLocalizer.msg("browser", "Web browser")),
            cc.xyw(1, 1, 9));

    JButton testButton = new LinkButton(mLocalizer.msg("testBrowser", "Test Webbrowser"),
            "http://www.tvbrowser.org", SwingConstants.LEFT, false);
    testButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String buffer = Settings.propUserDefinedWebbrowser.getString();
            String bufferParams = Settings.propUserDefinedWebbrowserParams.getString();
            saveSettings();
            Launch.openURL("http://www.tvbrowser.org");
            Settings.propUserDefinedWebbrowser.setString(buffer);
            Settings.propUserDefinedWebbrowserParams.setString(bufferParams);
        }
    });

    mSettingsPn.add(UiUtilities.createHelpTextArea(mLocalizer.msg("help", "Help Text")), cc.xyw(2, 3, 7));

    mSettingsPn.add(testButton, cc.xyw(2, 5, 7));

    mSettingsPn.add(new JLabel(mLocalizer.msg("whichBrowser", "which browser")), cc.xyw(2, 7, 7));

    JRadioButton useDefault = new JRadioButton(mLocalizer.msg("defaultWebbrowser", "Default Webbrowser"));
    useDefault.setSelected(Settings.propUserDefinedWebbrowser.getString() == null);
    useDefault.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateInputFields();
        }
    });

    mSettingsPn.add(useDefault, cc.xyw(2, 9, 4));

    mUseWebbrowser = new JRadioButton(mLocalizer.msg("userDefinedWebbrowser", "user defined webbrowser"));
    mUseWebbrowser.setSelected(Settings.propUserDefinedWebbrowser.getString() != null);

    mUseWebbrowser.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateInputFields();
        }
    });

    ButtonGroup group = new ButtonGroup();
    group.add(useDefault);
    group.add(mUseWebbrowser);

    mSettingsPn.add(mUseWebbrowser, cc.xyw(2, 11, 7));

    mSettingsPn.add(new JLabel(mLocalizer.msg("browserExecutable", "Executable") + ":"), cc.xy(3, 13));

    mFileTextField = new JTextField(30);
    mFileTextField.setText(Settings.propUserDefinedWebbrowser.getString());
    mSettingsPn.add(mFileTextField, cc.xy(5, 13));

    mChooseButton = new JButton(Localizer.getLocalization(Localizer.I18N_SELECT));
    mChooseButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            if (mFileChooser == null) {
                mFileChooser = new JFileChooser();

                if (OperatingSystem.isMacOs()) {
                    mFileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                } else {
                    mFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
                }
            }

            int retVal = mFileChooser.showOpenDialog(mSettingsPn.getParent());
            if (retVal == JFileChooser.APPROVE_OPTION) {
                File f = mFileChooser.getSelectedFile();
                if (f != null) {
                    mFileTextField.setText(f.getAbsolutePath());
                }
            }
        }
    });
    mSettingsPn.add(mChooseButton, cc.xy(7, 13));

    mSettingsPn.add(new JLabel(mLocalizer.msg("browserParameter", "Parameter") + ":"), cc.xy(3, 15));

    mParams = new JTextField();
    mParams.setText(Settings.propUserDefinedWebbrowserParams.getString());
    mSettingsPn.add(mParams, cc.xy(5, 15));

    mSettingsPn.add(new JLabel(mLocalizer.msg("browserParameterHelp", "{0} will be replaced by the url.")),
            cc.xyw(5, 17, 4));

    updateInputFields();

    return mSettingsPn;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.simulator.viewcomponent.DataGenerationPanel.java

/**
 * Inits the components.//w  ww  . j  av a 2s  .  c  om
 */
public synchronized void initComponents() {

    while (activeFrame == null) {
        if (applicationService != null && applicationService.getFrameView() != null) {
            activeFrame = applicationService.getFrameView().getActiveFrame();
        }
    }

    JPanel runPanel = new JPanel();
    runPanel.setLayout(new BoxLayout(runPanel, BoxLayout.LINE_AXIS));
    runPanel.setBorder(BorderFactory.createEmptyBorder(paddingSize, paddingSize, paddingSize, paddingSize));
    JXLabel label = new JXLabel();
    label.setLineWrap(true);
    label.setText(
            "<html>This panel allows the creation of clinically plausible data based on a query specification. "
                    + "Please note that you <b>must</b> always specify a data generation source. "
                    + "The rest of the parameters can be left in their default state. When you've configured the parameters "
                    + "click the 'Generate data' button.</html>");
    runPanel.add(label);
    runPanel.add(new JSeparator(SwingConstants.VERTICAL));
    runPanel.add(Box.createHorizontalStrut(paddingSize));
    JideButton runButton = new JideButton(new GenerateDataAction(applicationService, queryService,
            dataGenerationEngine, propertyChangeTrackerService));
    runButton.setButtonStyle(ButtonStyle.HYPERLINK_STYLE);
    runPanel.add(runButton);
    runButton.setIcon(new ImageIcon(DataGenerationPanel.class.getResource("resources/linuxconf.png")));
    runPanel.add(Box.createHorizontalStrut(paddingSize));

    // create radio buttons for choosing source
    JRadioButton queryButton = new JRadioButton("Active Query");
    queryButton.setSelected(true);
    queryButton.addActionListener(this);
    queryButton.setActionCommand("activeQuery");
    JRadioButton fileButton = new JRadioButton("File");
    fileButton.addActionListener(this);
    fileButton.setActionCommand("file");

    JRadioButton folderButton = new JRadioButton("Folder");
    folderButton.addActionListener(this);
    folderButton.setActionCommand("folder");
    ButtonGroup bg = new ButtonGroup();
    bg.add(queryButton);
    bg.add(fileButton);
    bg.add(folderButton);
    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
    //      buttonsPanel.add(new JLabel("Select data generation source"));
    buttonsPanel.setBorder(BorderFactory.createTitledBorder("Select data generation source"));
    buttonsPanel.add(Box.createHorizontalStrut(paddingSize));
    buttonsPanel.add(queryButton);
    buttonsPanel.add(Box.createHorizontalStrut(paddingSize));
    buttonsPanel.add(fileButton);
    buttonsPanel.add(Box.createHorizontalStrut(paddingSize));
    buttonsPanel.add(folderButton);

    locationField = new JTextField(100);
    JButton loadQueryButton = new JButton("Browse");
    loadQueryButton.addActionListener(this);
    loadQueryButton.setActionCommand("load");
    locationPanel = new JPanel();
    locationPanel.setLayout(new BoxLayout(locationPanel, BoxLayout.LINE_AXIS));
    locationPanel.add(new JLabel("Load file from"));
    locationPanel.add(Box.createHorizontalStrut(paddingSize));
    locationPanel.add(locationField);
    locationPanel.add(Box.createHorizontalStrut(paddingSize));
    locationPanel.add(loadQueryButton);

    JPanel lhsPanel = new JPanel(new GridLayout(0, 2));
    JPanel rhsPanel = new JPanel(new GridLayout(0, 2));

    lhsPanel.add(new JLabel("Max number of patients to generate"));

    SpinnerNumberModel model = new SpinnerNumberModel(initialPatientsNumber, 1, 1000000, 1);
    ptNumberSpinner = new JSpinner(model);
    ptNumberSpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent event) {
            // get value currently selected in spinner and set in engine
            dataGenerationEngine.setMaxPatientNumber(Long.parseLong(ptNumberSpinner.getValue().toString()));
            //                Object value = ptNumberSpinner.getValue();
            //                if(value instanceof Double)
            //                {
            //                    Double d = (Double) ptNumberSpinner.getValue();
            //                    dataGenerationEngine.setMaxPatientNumber(d.longValue());
            //                }
            //                else
            //                {
            //                    dataGenerationEngine.setMaxPatientNumber(Long.parseLong(ptNumberSpinner.getValue().toString()));
            //                }
            logger.debug("ptNumberSpinner.getValue().getClass() = " + ptNumberSpinner.getValue().getClass());
            logger.debug("Max pt number in engine set to : " + dataGenerationEngine.getMaxPatientNumber());
        }
    });
    lhsPanel.add(ptNumberSpinner);

    lhsPanel.add(new JLabel("Min age of patients to generate"));
    SpinnerNumberModel ageModel = new SpinnerNumberModel(initialMinimumAge, 1, 120, 1);
    minAgeSpinner = new JSpinner(ageModel);
    minAgeSpinner.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            // set min pt age to current value
            dataGenerationEngine.setMinPatientAgeInYears(Integer.parseInt(minAgeSpinner.getValue().toString()));
            logger.debug("Value of engine.getMinPatientAgeInYears() : "
                    + dataGenerationEngine.getMinPatientAgeInYears());
        }
    });
    lhsPanel.add(minAgeSpinner);

    lhsPanel.add(new JLabel("Data generation strategy"));
    generationStrategyBox = new JComboBox(DataGenerationEngine.DataGenerationStrategy.values());
    generationStrategyBox.setSelectedItem(DataGenerationEngine.DataGenerationStrategy.ADD_IF_NOT_EXISTS);
    generationStrategyBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dataGenerationEngine.setDataGenerationStrategy(
                    (DataGenerationEngine.DataGenerationStrategy) generationStrategyBox.getSelectedItem());
        }
    });
    lhsPanel.add(generationStrategyBox);

    includeExcludedTermsBox = new JCheckBox(new AbstractAction("Include Excluded terms in data") {

        public void actionPerformed(ActionEvent arg0) {
            dataGenerationEngine.setIncludeExcludedTerms(includeExcludedTermsBox.isSelected());
            logger.debug("dataGenerationEngine.isIncludeExcludedTerms() = "
                    + dataGenerationEngine.isIncludeExcludedTerms());
        }
    });
    rhsPanel.add(includeExcludedTermsBox);

    randomiseNumericalValuesBox = new JCheckBox(new AbstractAction("Randomise Numerical values in data") {

        public void actionPerformed(ActionEvent arg0) {
            dataGenerationEngine.setRandomiseNumericalValues(randomiseNumericalValuesBox.isSelected());
            logger.debug("dataGenerationEngine.isRandomiseNumericalValues() = "
                    + dataGenerationEngine.isRandomiseNumericalValues());
        }
    });
    rhsPanel.add(randomiseNumericalValuesBox);

    refineQualifiersCheckBox = new JCheckBox(new AbstractAction("Refine Qualifiers in expression") {
        public void actionPerformed(ActionEvent e) {
            dataGenerationEngine.setRefineQualifiers(refineQualifiersCheckBox.isSelected());
            logger.debug(
                    "dataGenerationEngine.isRefineQualifiers() = " + dataGenerationEngine.isRefineQualifiers());
        }
    });
    rhsPanel.add(refineQualifiersCheckBox);

    includePreCoordinatedDataCheckBox = new JCheckBox(
            new AbstractAction("Include pre-coordinated expressions") {
                public void actionPerformed(ActionEvent e) {
                    dataGenerationEngine
                            .setIncludePrecoordinatedData(includePreCoordinatedDataCheckBox.isSelected());
                    logger.debug("dataGenerationEngine.isIncludePrecoordinatedData() = "
                            + dataGenerationEngine.isIncludePrecoordinatedData());
                }
            });
    rhsPanel.add(includePreCoordinatedDataCheckBox);
    rhsPanel.add(new JLabel("  "));

    /*
    * create panel for parametrising engine
    */
    JPanel parametrisationPanel = new JPanel();
    parametrisationPanel.setLayout(new GridLayout(0, 2));
    parametrisationPanel.setBorder(BorderFactory.createTitledBorder("Engine Parameters"));

    // add panels to parametrisation panel
    parametrisationPanel.add(lhsPanel);
    parametrisationPanel.add(rhsPanel);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS));
    topPanel.add(runPanel);
    topPanel.add(new JSeparator(SwingConstants.VERTICAL));
    topPanel.add(buttonsPanel);
    // add all panels to this component
    setLayout(new BorderLayout());
    add(topPanel, BorderLayout.NORTH);
    add(parametrisationPanel, BorderLayout.CENTER);

    // initialise values
    populateFields(dataGenerationEngine);
}