Search in sources :

Example 41 with JRadioButton

use of javax.swing.JRadioButton in project JMRI by JMRI.

the class TrainsScheduleTableFrame method updateControlPanel.

/*
     * Update radio button names in the same order as the table
     */
private void updateControlPanel() {
    schedule.removeAll();
    // Name holds schedule id for the selected radio button
    noneButton.setName(TrainSchedule.NONE);
    noneButton.setSelected(true);
    // no text for the noneButton or anyButton
    commentTextArea.setText("");
    enableButtons(false);
    schedule.add(noneButton);
    schGroup.add(noneButton);
    for (int i = trainsScheduleModel.getFixedColumn(); i < trainsScheduleModel.getColumnCount(); i++) {
        log.debug("Column name: {}", trainsScheduleTable.getColumnName(i));
        TrainSchedule ts = trainScheduleManager.getScheduleByName(trainsScheduleTable.getColumnName(i));
        if (ts != null) {
            JRadioButton b = new JRadioButton();
            b.setText(ts.getName());
            b.setName(ts.getId());
            schedule.add(b);
            schGroup.add(b);
            addRadioButtonAction(b);
            if (b.getName().equals(trainManager.getTrainScheduleActiveId())) {
                b.setSelected(true);
                enableButtons(true);
                // update comment field
                commentTextArea.setText(ts.getComment());
            }
        }
    }
    // Name holds schedule id for the selected radio button
    anyButton.setName(TrainSchedule.ANY);
    schedule.add(anyButton);
    schGroup.add(anyButton);
    anyButton.setSelected(trainManager.getTrainScheduleActiveId().equals(TrainSchedule.ANY));
    schedule.revalidate();
}
Also used : JRadioButton(javax.swing.JRadioButton)

Example 42 with JRadioButton

use of javax.swing.JRadioButton in project JMRI by JMRI.

the class ProgOpsModePane method programmerSelected.

/**
     * Reload the interface with the new programmers.
     */
void programmerSelected() {
    log.debug("programmerSelected starts with {} buttons", buttonPool.size());
    // hide buttons
    for (JRadioButton button : buttonPool) {
        button.setVisible(false);
    }
    // clear map
    buttonMap.clear();
    // require new programmer if possible
    oldAddrValue = -1;
    // configure buttons
    int index = 0;
    List<ProgrammingMode> modes;
    if (getProgrammer() != null) {
        modes = programmer.getSupportedModes();
    } else {
        modes = ((AddressedProgrammerManager) progBox.getSelectedItem()).getDefaultModes();
    }
    // add OPSACCBYTEMODE if possible
    if (modes.contains(DefaultProgrammerManager.OPSBYTEMODE) && !modes.contains(DefaultProgrammerManager.OPSACCBYTEMODE)) {
        log.debug("   adding button for {} via AccessoryOpsModeProgrammerFacade", DefaultProgrammerManager.OPSACCBYTEMODE);
        modes.add(DefaultProgrammerManager.OPSACCBYTEMODE);
    }
    log.debug("   has {} modes", modes.size());
    for (ProgrammingMode mode : modes) {
        JRadioButton button;
        // need a new button?
        if (index >= buttonPool.size()) {
            log.debug("   add button");
            button = new JRadioButton();
            buttonPool.add(button);
            modeGroup.add(button);
            button.addActionListener(this);
            // add to GUI
            add(button);
        }
        // configure next button in pool
        log.debug("   set for {}", mode.toString());
        button = buttonPool.get(index++);
        button.setVisible(true);
        modeGroup.add(button);
        button.setText(mode.toString());
        buttonMap.put(mode, button);
    }
    setGuiFromProgrammer();
}
Also used : JRadioButton(javax.swing.JRadioButton) ProgrammingMode(jmri.ProgrammingMode)

Example 43 with JRadioButton

use of javax.swing.JRadioButton in project processdash by dtuma.

the class TaskScheduleChart method showSaveAsDialog.

private TaskScheduleChartSettings showSaveAsDialog(TaskScheduleChartSettings currentSettings, String chartID) {
    String title = resources.getString("Configure.Save_As.Window_Title");
    String namePrompt = resources.getString("Configure.Save_As.Name_Prompt");
    JTextField chartNameField = new JTextField();
    if (currentSettings != null)
        chartNameField.setText(currentSettings.getCustomName());
    new JOptionPaneActionHandler().install(chartNameField);
    String scopePrompt = resources.getString("Configure.Save_As.Scope_Prompt");
    ButtonGroup group = new ButtonGroup();
    JRadioButton localScopeButton = new JRadioButton(resources.getString("Configure.Save_As.Scope_Local"));
    group.add(localScopeButton);
    JRadioButton globalScopeButton = new JRadioButton(resources.getString("Configure.Save_As.Scope_Global"));
    group.add(globalScopeButton);
    boolean global = (currentSettings != null && currentSettings.isGlobal());
    (global ? globalScopeButton : localScopeButton).setSelected(true);
    String errorKey = null;
    while (true) {
        BoxUtils errorBox;
        if (errorKey != null) {
            JLabel errorLabel = new JLabel(resources.getString(errorKey));
            errorLabel.setForeground(Color.RED);
            errorBox = BoxUtils.hbox(20, errorLabel);
        } else {
            errorBox = BoxUtils.hbox();
        }
        Object[] message = { namePrompt, BoxUtils.hbox(20, chartNameField), new JOptionPaneTweaker.GrabFocus(chartNameField), errorBox, scopePrompt, BoxUtils.hbox(20, localScopeButton), BoxUtils.hbox(20, globalScopeButton) };
        int userChoice = JOptionPane.showConfirmDialog(configurationDialog, message, title, JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (userChoice != JOptionPane.OK_OPTION)
            return null;
        String chartName = chartNameField.getText();
        chartName = (chartName == null ? "" : chartName.trim());
        if (chartName.length() == 0) {
            errorKey = "Configure.Save_As.Name_Missing";
            continue;
        }
        TaskScheduleChartSettings result = new TaskScheduleChartSettings();
        if (localScopeButton.isSelected())
            result.setTaskListID(taskList.getID());
        result.setChartID(chartID);
        result.setCustomName(chartName);
        if (result.hasSameNameAs(currentSettings) == false && chartNameIsTaken(chartName)) {
            errorKey = "Configure.Save_As.Duplicate_Name";
            continue;
        }
        return result;
    }
}
Also used : JOptionPaneTweaker(net.sourceforge.processdash.ui.lib.JOptionPaneTweaker) JOptionPaneActionHandler(net.sourceforge.processdash.ui.lib.JOptionPaneActionHandler) JRadioButton(javax.swing.JRadioButton) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) BoxUtils(net.sourceforge.processdash.ui.lib.BoxUtils) Point(java.awt.Point) ButtonGroup(javax.swing.ButtonGroup) EventObject(java.util.EventObject)

Example 44 with JRadioButton

use of javax.swing.JRadioButton in project processdash by dtuma.

the class TranslationSharer method promptForAuthorInfo.

private void promptForAuthorInfo() {
    JLabel authorLabel = new JLabel(resources.getString("Translation.Sharing.Author.Name_Prompt"));
    JTextField author = new JTextField(20);
    JLabel emailLabel = new JLabel(resources.getString("Translation.Sharing.Author.Email_Prompt"));
    JTextField email = new JTextField(30);
    JRadioButton yesOption = new JRadioButton(resources.getString("Translation.Sharing.Author.Yes_Option"), true);
    JRadioButton noOption = new JRadioButton(resources.getString("Translation.Sharing.Author.No_Option"));
    ButtonGroup group = new ButtonGroup();
    group.add(yesOption);
    group.add(noOption);
    ContactOptionListener l = new ContactOptionListener(yesOption, new JComponent[] { authorLabel, author, emailLabel, email });
    yesOption.addActionListener(l);
    noOption.addActionListener(l);
    Box buttonBox = Box.createHorizontalBox();
    buttonBox.add(yesOption);
    buttonBox.add(Box.createHorizontalStrut(10));
    buttonBox.add(noOption);
    buttonBox.add(Box.createHorizontalGlue());
    Object[] message = new Object[] { resources.getString("Translation.Sharing.Author.Prompt"), buttonBox, inputBox(authorLabel, author), inputBox(emailLabel, email) };
    JOptionPane.showMessageDialog(null, message, resources.getString("Translation.Sharing.Author.Title"), JOptionPane.OK_OPTION);
    if (yesOption.isSelected()) {
        prefs.put(AUTHOR_SETTING, author.getText());
        prefs.put(EMAIL_SETTING, email.getText());
        try {
            prefs.flush();
        } catch (BackingStoreException e) {
            System.out.println(resources.getString("Translation.Errors.Cant_Save_Preferences"));
            e.printStackTrace();
        }
    }
}
Also used : JRadioButton(javax.swing.JRadioButton) ButtonGroup(javax.swing.ButtonGroup) BackingStoreException(java.util.prefs.BackingStoreException) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JTextField(javax.swing.JTextField)

Example 45 with JRadioButton

use of javax.swing.JRadioButton in project processdash by dtuma.

the class EditImportDirectoryPanel method createAutomaticButton.

private JRadioButton createAutomaticButton(String key) {
    JRadioButton result = new JRadioButton(getString(key));
    result.setActionCommand(key);
    makeAutomatic.add(result);
    if (makeAutomatic.getButtonCount() == 1)
        result.setSelected(true);
    return result;
}
Also used : JRadioButton(javax.swing.JRadioButton)

Aggregations

JRadioButton (javax.swing.JRadioButton)182 ButtonGroup (javax.swing.ButtonGroup)116 JPanel (javax.swing.JPanel)87 JLabel (javax.swing.JLabel)77 ActionEvent (java.awt.event.ActionEvent)44 ActionListener (java.awt.event.ActionListener)41 JTextField (javax.swing.JTextField)39 BoxLayout (javax.swing.BoxLayout)38 GridBagLayout (java.awt.GridBagLayout)36 GridBagConstraints (java.awt.GridBagConstraints)35 JButton (javax.swing.JButton)35 JCheckBox (javax.swing.JCheckBox)33 Insets (java.awt.Insets)31 BorderLayout (java.awt.BorderLayout)25 JScrollPane (javax.swing.JScrollPane)25 FlowLayout (java.awt.FlowLayout)22 JSpinner (javax.swing.JSpinner)20 Dimension (java.awt.Dimension)19 SpinnerNumberModel (javax.swing.SpinnerNumberModel)15 GridLayout (java.awt.GridLayout)13