Example usage for javax.swing ButtonGroup ButtonGroup

List of usage examples for javax.swing ButtonGroup ButtonGroup

Introduction

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

Prototype

public ButtonGroup() 

Source Link

Document

Creates a new ButtonGroup.

Usage

From source file:projects.upc.exec.HrDiagram.java

/**
 * Main constructor./*w w w. jav a  2s.  co  m*/
 */
public HrDiagram() {

    List<UpcStar> upcStars = UpcUtils.loadUpcCatalogue();
    List<UpcStar> hipStars = UpcUtils.getHipparcosSubset(upcStars);
    List<UpcStar> unmatchedStars = UpcUtils.getUnmatchedSubset(upcStars);

    upcStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(upcStars);
    hipStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(hipStars);
    unmatchedStarCrossMatches = XmUtil.getUpcStarCrossMatchMap(unmatchedStars);

    logger.info("Loaded " + upcStarCrossMatches.size() + " UpcStars with SSA cross matches");
    logger.info("Loaded " + hipStarCrossMatches.size() + " UpcStars with Hipparcos and SSA cross matches");
    logger.info("Loaded " + unmatchedStarCrossMatches.size()
            + " UpcStars with no parallax cross-match, and with SSA cross matches");

    starsToPlot = upcStarCrossMatches;

    useHip = false;
    method = METHOD.NAIVE;
    fMax = 1.0;

    final JCheckBox plotAllCheckBox = new JCheckBox("Plot all UPC stars: ", true);
    plotAllCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (plotAllCheckBox.isSelected()) {
                starsToPlot = upcStarCrossMatches;
                updateChart();
            }
        }
    });

    final JCheckBox plotHipCheckBox = new JCheckBox("Plot Hipparcos stars only: ", false);
    plotHipCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (plotHipCheckBox.isSelected()) {
                starsToPlot = hipStarCrossMatches;
                updateChart();
            }
        }
    });

    final JCheckBox plotUnmatchedCheckBox = new JCheckBox("Plot all stars with no external match: ", false);
    plotUnmatchedCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (plotUnmatchedCheckBox.isSelected()) {
                starsToPlot = unmatchedStarCrossMatches;
                updateChart();
            }
        }
    });

    final ButtonGroup bg = new ButtonGroup();
    bg.add(plotHipCheckBox);
    bg.add(plotAllCheckBox);
    bg.add(plotUnmatchedCheckBox);

    JCheckBox useHipCheckBox = new JCheckBox("Use Hipparcos parallaxes when available", useHip);
    useHipCheckBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            useHip = !useHip;
            updateChart();
        }
    });

    final JComboBox<METHOD> methodComboBox = new JComboBox<METHOD>(METHOD.values());
    methodComboBox.setSelectedItem(method);
    methodComboBox.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent evt) {
            method = (METHOD) methodComboBox.getSelectedItem();
            updateChart();
        }
    });

    final JSlider fSlider = GuiUtil.buildSlider(0.0, 2.0, 5, "%3.3f");
    fSlider.setValue((int) Math.rint(100.0 * fMax));
    final JLabel fLabel = new JLabel(getFLabel());
    // Create a change listener fot these
    ChangeListener cl = new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();

            if (source == fSlider) {
                // Compute fractional parallax error from slider position
                double newF = (2.0 * source.getValue() / 100.0);
                fMax = newF;
                fLabel.setText(getFLabel());
            }
            updateChart();
        }
    };
    fSlider.addChangeListener(cl);
    // Add a bit of padding to space things out
    fSlider.setBorder(new EmptyBorder(5, 5, 5, 5));

    // Present controls below the HR diagram
    JPanel controls = new JPanel(new GridLayout(3, 3));
    controls.add(plotAllCheckBox);
    controls.add(plotHipCheckBox);
    controls.add(plotUnmatchedCheckBox);
    controls.add(new JLabel("Distance estimation method:"));
    controls.add(methodComboBox);
    controls.add(useHipCheckBox);
    controls.add(fLabel);
    controls.add(fSlider);

    // Initialise the ChartPanel
    updateChart();

    // Build the panel contents
    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
    add(controls, BorderLayout.SOUTH);
}

From source file:com.eviware.soapui.support.editor.inspectors.auth.ExpirationTimeChooser.java

private void initializeRadioButtons() {
    long serverIssuedExpirationTime = profile.getAccessTokenExpirationTime();
    String serverIssuedExpirationTimeLabel;
    if (serverIssuedExpirationTime > 0) {
        serverIssuedExpirationTimeLabel = getMostLegibleTimeString(serverIssuedExpirationTime);
    } else {//  www . j  a va 2s.c o m
        serverIssuedExpirationTimeLabel = "No expiration";
    }

    serverExpirationTimeOption = new JRadioButton(
            "Use expiration time from authorization server: " + serverIssuedExpirationTimeLabel);
    serverExpirationTimeOption.setName(SERVER_EXPIRATION_RADIO_NAME);
    ActionListener checkBoxMonitor = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            timeTextField.setEnabled(manualExpirationTimeOption.isSelected());
            timeUnitCombo.setEnabled(manualExpirationTimeOption.isSelected());
        }
    };
    serverExpirationTimeOption.addActionListener(checkBoxMonitor);

    manualExpirationTimeOption = new JRadioButton("Custom");
    manualExpirationTimeOption.setName(MANUAL_EXPIRATION_RADIO_NAME);
    manualExpirationTimeOption.addActionListener(checkBoxMonitor);

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(serverExpirationTimeOption);
    buttonGroup.add(manualExpirationTimeOption);

    if (profile.useManualAccessTokenExpirationTime()) {
        manualExpirationTimeOption.setSelected(true);
    } else {
        serverExpirationTimeOption.setSelected(true);
    }
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java

/**
 * Initialize main view./*from   w w w  .ja v a 2  s  . com*/
 */
private void initAnalysisPanel() {
    // make a new panel
    analysisPanel = new AnalysisPanel();
    //create a ButtonGroup for the radioButtons used for analysis
    ButtonGroup radioButtonGroup = new ButtonGroup();
    radioButtonGroup.add(analysisPanel.getCellTracksRadioButton());
    radioButtonGroup.add(analysisPanel.getCellSpeedRadioButton());
    radioButtonGroup.add(analysisPanel.getStatisticsRadioButton());

    /**
     * Add action listeners
     */
    // plot the cell tracks
    analysisPanel.getCellTracksRadioButton().addActionListener((ActionEvent e) -> {
        // get the layout from the bottom panel and show the appropriate one
        CardLayout layout = (CardLayout) analysisPanel.getBottomPanel().getLayout();
        layout.show(analysisPanel.getBottomPanel(), analysisPanel.getCellTracksPanel().getName());
        plotCellTracks();
    });

    // 
    analysisPanel.getCellSpeedRadioButton().addActionListener((ActionEvent e) -> {
        // get the layout from the bottom panel and show the appropriate one
        CardLayout layout = (CardLayout) analysisPanel.getBottomPanel().getLayout();
        layout.show(analysisPanel.getBottomPanel(), analysisPanel.getCellSpeedsPanel().getName());
        // take care of data and plots here
        plotData();
    });

    // go to the statistics
    analysisPanel.getStatisticsRadioButton().addActionListener((ActionEvent e) -> {
        // get the layout from the bottom panel and show the appropriate one
        CardLayout layout = (CardLayout) analysisPanel.getBottomPanel().getLayout();
        layout.show(analysisPanel.getBottomPanel(), analysisPanel.getStatisticsParentPanel().getName());
        singleCellStatisticsController.updateConditionList();
    });

    analysisPanel.getCellTracksRadioButton().setSelected(true);
    AlignedTableRenderer alignedTableRenderer = new AlignedTableRenderer(SwingConstants.LEFT);
    for (int i = 0; i < analysisPanel.getDataTable().getColumnModel().getColumnCount(); i++) {
        analysisPanel.getDataTable().getColumnModel().getColumn(i).setCellRenderer(alignedTableRenderer);
    }
    analysisPanel.getDataTable().getTableHeader()
            .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT));

    // add view to parent panel
    singleCellMainController.getSingleCellAnalysisPanel().getAnalysisParentPanel().add(analysisPanel,
            gridBagConstraints);
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.filtering.MultipleCutOffFilteringController.java

/**
 * Private methods and classes//ww  w.  j  a v a2  s  . c o  m
 */
// initialize the main view
private void initMainView() {
    // make a new view
    multipleCutOffPanel = new MultipleCutOffPanel();
    // make a new radio button group for the radio buttons
    ButtonGroup radioButtonGroup = new ButtonGroup();
    radioButtonGroup.add(multipleCutOffPanel.getPixelRadioButton());
    radioButtonGroup.add(multipleCutOffPanel.getMicroMeterRadioButton());

    // pixels or m?
    multipleCutOffPanel.getPixelRadioButton().addActionListener((ActionEvent e) -> {
        multipleCutOffPanel.getConversionFactorTextField().setEnabled(true);
    });

    multipleCutOffPanel.getMicroMeterRadioButton().addActionListener((ActionEvent e) -> {
        // m: we do not need a conversion factor
        multipleCutOffPanel.getConversionFactorTextField().setEnabled(false);
    });

    // set default to micrometer
    multipleCutOffPanel.getMicroMeterRadioButton().setSelected(true);
    // and therefore no need for the conversion factor
    multipleCutOffPanel.getConversionFactorTextField().setEnabled(false);
    // set some default values for the top and bottom translocaton limits
    multipleCutOffPanel.getBottomLimTextField().setText("0.4");
    multipleCutOffPanel.getTopLimTextField().setText("2.8");
    multipleCutOffPanel.getTranslocationStepTextField().setText("0.8");
    multipleCutOffPanel.getPercentageMotileStepsTextField().setText("30");
    percentageMotile = 33;

    // actually do the filtering
    multipleCutOffPanel.getFilterButton().addActionListener((ActionEvent e) -> {

        // try to read the user-inserted values for up and down limit
        // check for number format exception
        try {
            if (multipleCutOffPanel.getPixelRadioButton().isSelected()) {
                double conversionFactor = Double
                        .parseDouble(multipleCutOffPanel.getConversionFactorTextField().getText());
                multipleCutOffPanel.getBottomLimTextField()
                        .setText("" + AnalysisUtils.roundTwoDecimals(
                                Double.parseDouble(multipleCutOffPanel.getBottomLimTextField().getText())
                                        / conversionFactor));
                multipleCutOffPanel.getTopLimTextField()
                        .setText("" + AnalysisUtils.roundTwoDecimals(
                                Double.parseDouble(multipleCutOffPanel.getTopLimTextField().getText())
                                        / conversionFactor));
            }

            int topLimit = (int) (Double.parseDouble(multipleCutOffPanel.getTopLimTextField().getText()) * 10);
            int bottomLimit = (int) (Double.parseDouble(multipleCutOffPanel.getBottomLimTextField().getText())
                    * 10);
            double step = Double.parseDouble(multipleCutOffPanel.getTranslocationStepTextField().getText());
            percentageMotile = Double
                    .parseDouble(multipleCutOffPanel.getPercentageMotileStepsTextField().getText());

            int numberSteps = (int) ((topLimit - bottomLimit) / (10 * step)) + 1;
            motileSteps = new ArrayList<>();

            for (int i = 0; i < numberSteps; i++) {
                motileSteps.add(((double) bottomLimit / 10) + (step * i));
            }
            FilterSwingWorker filterSwingWorker = new FilterSwingWorker();
            filterSwingWorker.execute();

        } catch (NumberFormatException ex) {
            // warn the user and log the error for info
            filteringController.showMessage("Please insert valid numbers!" + "\n " + ex.getMessage(),
                    "number format exception", JOptionPane.ERROR_MESSAGE);
            LOG.error(ex.getMessage());
        }

    });

    // apply a specific cut-off value to all the conditions at once
    multipleCutOffPanel.getApplyCutOffToConditionsButton().addActionListener((ActionEvent e) -> {
        // get the cut-off from the list (sure this is a Double)
        Double value = (Double) multipleCutOffPanel.getCutOffValuesComboBox().getSelectedItem();
        FilterConditionSwingWorker filterConditionSwingWorker = new FilterConditionSwingWorker(value);
        filterConditionSwingWorker.execute();
    });

    // select cut-off for a condition
    multipleCutOffPanel.getSelectCutOffForConditionButton().addActionListener((ActionEvent e) -> {
        if (multipleCutOffPanel.getCutOffValuesComboBox().getSelectedItem() != null) {
            SelectCutOffConditionSwingWorker selectCutOffConditionSwingWorker = new SelectCutOffConditionSwingWorker();
            selectCutOffConditionSwingWorker.execute();
        } else {
            filteringController.showMessage("Please select a cut-off!", "info", JOptionPane.WARNING_MESSAGE);
        }

    });

    AlignedTableRenderer alignedTableRenderer = new AlignedTableRenderer(SwingConstants.LEFT);
    for (int i = 0; i < multipleCutOffPanel.getFilterTrackTable().getColumnModel().getColumnCount(); i++) {
        multipleCutOffPanel.getFilterTrackTable().getColumnModel().getColumn(i)
                .setCellRenderer(alignedTableRenderer);
        multipleCutOffPanel.getSummaryTable().getColumnModel().getColumn(i)
                .setCellRenderer(alignedTableRenderer);
    }
    multipleCutOffPanel.getFilterTrackTable().getTableHeader()
            .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT));
    multipleCutOffPanel.getSummaryTable().getTableHeader()
            .setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT));

    // add view to parent component
    filteringController.getFilteringPanel().getMultipleCutOffParentPanel().add(multipleCutOffPanel,
            gridBagConstraints);
}

From source file:ext.scrollablepopupmenu.TestXCheckedButton.java

/**
 * Test model./*from  w  w w . j  av a 2s.  c  o m*/
 * 
 */
public void testModel() {
    XCheckedButton button = new XCheckedButton("testtext", new DummyIcon());
    assertNotNull(button.getModel());
    button.setSelected(true);
    button.setSelected(false);
    ((DefaultButtonModel) button.getModel()).setGroup(new ButtonGroup());
    button.setSelected(true);
    button.setSelected(false);
}

From source file:net.sf.jabref.openoffice.StyleSelectDialog.java

private void init(String inSelection) {
    this.initSelection = inSelection;

    ButtonGroup bg = new ButtonGroup();
    bg.add(useDefaultAuthoryear);// w  w  w.  j  ava2 s .  co m
    bg.add(useDefaultNumerical);
    bg.add(chooseDirectly);
    bg.add(setDirectory);
    if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_AUTHORYEAR_STYLE)) {
        useDefaultAuthoryear.setSelected(true);
    } else if (Globals.prefs.getBoolean(JabRefPreferences.OO_USE_DEFAULT_NUMERICAL_STYLE)) {
        useDefaultNumerical.setSelected(true);
    } else {
        if (Globals.prefs.getBoolean(JabRefPreferences.OO_CHOOSE_STYLE_DIRECTLY)) {
            chooseDirectly.setSelected(true);
        } else {
            setDirectory.setSelected(true);
        }
    }

    directFile.setText(Globals.prefs.get(JabRefPreferences.OO_DIRECT_FILE));
    styleDir.setText(Globals.prefs.get(JabRefPreferences.OO_STYLE_DIRECTORY));
    directFile.setEditable(false);
    styleDir.setEditable(false);

    popup.add(edit);

    BrowseAction dfBrowse = BrowseAction.buildForFile(directFile, directFile);
    browseDirectFile.addActionListener(dfBrowse);

    BrowseAction sdBrowse = BrowseAction.buildForDir(styleDir, setDirectory);
    browseStyleDir.addActionListener(sdBrowse);

    showDefaultAuthoryearStyle.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            displayDefaultStyle(true);
        }
    });
    showDefaultNumericalStyle.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            displayDefaultStyle(false);
        }
    });
    // Add action listener to "Edit" menu item, which is supposed to open the style file in an external editor:
    edit.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            int i = table.getSelectedRow();
            if (i == -1) {
                return;
            }
            ExternalFileType type = ExternalFileTypes.getInstance().getExternalFileTypeByExt("jstyle");
            String link = tableModel.getElementAt(i).getFile().getPath();
            try {
                if (type == null) {
                    JabRefDesktop.openExternalFileUnknown(frame, new BibEntry(), new MetaData(), link,
                            new UnknownExternalFileType("jstyle"));
                } else {
                    JabRefDesktop.openExternalFileAnyFormat(new MetaData(), link, type);
                }
            } catch (IOException e) {
                LOGGER.warn("Problem open style file editor", e);
            }
        }
    });

    diag = new JDialog(frame, Localization.lang("Styles"), true);

    styles = new BasicEventList<>();
    EventList<OOBibStyle> sortedStyles = new SortedList<>(styles);

    // Create a preview panel for previewing styles:
    preview = new PreviewPanel(null, new MetaData(), "");
    // Use the test entry from the Preview settings tab in Preferences:
    preview.setEntry(prevEntry);

    tableModel = (DefaultEventTableModel<OOBibStyle>) GlazedListsSwing
            .eventTableModelWithThreadProxyList(sortedStyles, new StyleTableFormat());
    table = new JTable(tableModel);
    TableColumnModel cm = table.getColumnModel();
    cm.getColumn(0).setPreferredWidth(100);
    cm.getColumn(1).setPreferredWidth(200);
    cm.getColumn(2).setPreferredWidth(80);
    selectionModel = (DefaultEventSelectionModel<OOBibStyle>) GlazedListsSwing
            .eventSelectionModelWithThreadProxyList(sortedStyles);
    table.setSelectionModel(selectionModel);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            if (mouseEvent.isPopupTrigger()) {
                tablePopup(mouseEvent);
            }
        }

        @Override
        public void mouseReleased(MouseEvent mouseEvent) {
            if (mouseEvent.isPopupTrigger()) {
                tablePopup(mouseEvent);
            }
        }
    });

    selectionModel.getSelected().addListEventListener(new EntrySelectionListener());

    styleDir.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            readStyles();
            setDirectory.setSelected(true);
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            readStyles();
            setDirectory.setSelected(true);
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            readStyles();
            setDirectory.setSelected(true);
        }
    });
    directFile.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent documentEvent) {
            chooseDirectly.setSelected(true);
        }

        @Override
        public void removeUpdate(DocumentEvent documentEvent) {
            chooseDirectly.setSelected(true);
        }

        @Override
        public void changedUpdate(DocumentEvent documentEvent) {
            chooseDirectly.setSelected(true);
        }
    });

    contentPane.setTopComponent(new JScrollPane(table));
    contentPane.setBottomComponent(preview);

    readStyles();

    DefaultFormBuilder b = new DefaultFormBuilder(
            new FormLayout("fill:pref,4dlu,fill:150dlu,4dlu,fill:pref", ""));
    b.append(useDefaultAuthoryear, 3);
    b.append(showDefaultAuthoryearStyle);
    b.nextLine();
    b.append(useDefaultNumerical, 3);
    b.append(showDefaultNumericalStyle);
    b.nextLine();
    b.append(chooseDirectly);
    b.append(directFile);
    b.append(browseDirectFile);
    b.nextLine();
    b.append(setDirectory);
    b.append(styleDir);
    b.append(browseStyleDir);
    b.nextLine();
    DefaultFormBuilder b2 = new DefaultFormBuilder(
            new FormLayout("fill:1dlu:grow", "fill:pref, fill:pref, fill:270dlu:grow"));

    b2.nextLine();
    b2.append(new JLabel("<html>"
            + Localization.lang("This is the list of available styles. Select the one you want to use.")
            + "</html>"));
    b2.nextLine();
    b2.append(contentPane);
    b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    b2.getPanel().setBorder(BorderFactory.createEmptyBorder(15, 5, 5, 5));
    diag.add(b.getPanel(), BorderLayout.NORTH);
    diag.add(b2.getPanel(), BorderLayout.CENTER);

    AbstractAction okListener = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            if (!useDefaultAuthoryear.isSelected() && !useDefaultNumerical.isSelected()) {
                if (chooseDirectly.isSelected()) {
                    File f = new File(directFile.getText());
                    if (!f.exists()) {
                        JOptionPane.showMessageDialog(diag,
                                Localization.lang(
                                        "You must select either a valid style file, or use a default style."),
                                Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                } else {
                    if ((table.getRowCount() == 0) || (table.getSelectedRowCount() == 0)) {
                        JOptionPane.showMessageDialog(diag,
                                Localization.lang(
                                        "You must select either a valid style file, or use a default style."),
                                Localization.lang("Style selection"), JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                }
            }
            okPressed = true;
            storeSettings();
            diag.dispose();
        }
    };
    ok.addActionListener(okListener);

    Action cancelListener = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent event) {
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelListener);

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.add(bb.getPanel(), BorderLayout.SOUTH);

    ActionMap am = bb.getPanel().getActionMap();
    InputMap im = bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", cancelListener);
    im.put(KeyStroke.getKeyStroke("ENTER"), "enterOk");
    am.put("enterOk", okListener);

    diag.pack();
    diag.setLocationRelativeTo(frame);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            contentPane.setDividerLocation(contentPane.getSize().height - 150);
        }
    });

}

From source file:net.pandoragames.far.ui.swing.RenameFilesPanel.java

private void init(SwingConfig config, ComponentRepository componentRepository) {

    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    this.setBorder(
            BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING));

    this.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));
    JLabel patternLabel = new JLabel(localizer.localize("label.find-pattern"));
    this.add(patternLabel);
    filenamePattern = new JTextField();
    filenamePattern.setPreferredSize(//from   ww w .j av  a 2 s.c om
            new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, config.getStandardComponentHight()));
    filenamePattern
            .setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, config.getStandardComponentHight()));
    filenamePattern.setAlignmentX(Component.LEFT_ALIGNMENT);
    UndoHistory findUndoManager = new UndoHistory();
    findUndoManager.registerUndoHistory(filenamePattern);
    findUndoManager.registerSnapshotHistory(filenamePattern);
    componentRepository.getReplaceCommand().addResetable(findUndoManager);
    filenamePattern.getDocument().addDocumentListener(new DocumentChangeListener() {
        public void documentUpdated(DocumentEvent e, String text) {
            dataModel.setPatternString(text);
            updateFileTable();
        }
    });
    componentRepository.getResetDispatcher().addToBeCleared(filenamePattern);
    this.add(filenamePattern);
    JCheckBox caseBox = new JCheckBox(localizer.localize("label.ignore-case"));
    caseBox.setSelected(true);
    caseBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            dataModel.setIgnoreCase((ItemEvent.SELECTED == event.getStateChange()));
            updateFileTable();
        }
    });
    this.add(caseBox);
    JCheckBox regexBox = new JCheckBox(localizer.localize("label.regular-expression"));
    regexBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            dataModel.setRegexPattern((ItemEvent.SELECTED == event.getStateChange()));
            updateFileTable();
        }
    });
    this.add(regexBox);
    JPanel extensionPanel = new JPanel();
    extensionPanel.setBorder(BorderFactory.createTitledBorder(localizer.localize("label.modify-extension")));
    extensionPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    extensionPanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    extensionPanel.setPreferredSize(new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, 60));
    extensionPanel.setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, 100));
    ButtonGroup extensionGroup = new ButtonGroup();
    JRadioButton protectButton = new JRadioButton(localizer.localize("label.protect-extension"));
    protectButton.setSelected(true);
    protectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dataModel.setProtectExtension(true);
            updateFileTable();
        }
    });
    extensionGroup.add(protectButton);
    extensionPanel.add(protectButton);
    JRadioButton includeButton = new JRadioButton(localizer.localize("label.include-extension"));
    includeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dataModel.setExtensionOnly(false);
            dataModel.setProtectExtension(false);
            updateFileTable();
        }
    });
    extensionGroup.add(includeButton);
    extensionPanel.add(includeButton);
    JRadioButton onlyButton = new JRadioButton(localizer.localize("label.only-extension"));
    onlyButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            dataModel.setExtensionOnly(true);
            updateFileTable();
        }
    });
    extensionGroup.add(onlyButton);
    extensionPanel.add(onlyButton);
    this.add(extensionPanel);

    this.add(Box.createVerticalGlue());
    this.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING)));

    // replace
    JLabel replaceLabel = new JLabel(localizer.localize("label.replacement-pattern"));
    this.add(replaceLabel);
    replacePattern = new JTextField();
    replacePattern.setPreferredSize(
            new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, config.getStandardComponentHight()));
    replacePattern
            .setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, config.getStandardComponentHight()));
    replacePattern.setAlignmentX(Component.LEFT_ALIGNMENT);
    UndoHistory undoManager = new UndoHistory();
    undoManager.registerUndoHistory(replacePattern);
    undoManager.registerSnapshotHistory(replacePattern);
    componentRepository.getReplaceCommand().addResetable(undoManager);
    replacePattern.getDocument().addDocumentListener(new DocumentChangeListener() {
        public void documentUpdated(DocumentEvent e, String text) {
            dataModel.setReplacementString(text);
            updateFileTable();
        }
    });
    componentRepository.getResetDispatcher().addToBeCleared(replacePattern);
    this.add(replacePattern);

    // treat case
    JPanel modifyCasePanel = new JPanel();
    modifyCasePanel.setBorder(BorderFactory.createTitledBorder(localizer.localize("label.modify-case")));
    modifyCasePanel.setLayout(new BoxLayout(modifyCasePanel, BoxLayout.Y_AXIS));
    modifyCasePanel.setAlignmentX(Component.LEFT_ALIGNMENT);
    modifyCasePanel.setPreferredSize(new Dimension(SwingConfig.COMPONENT_WIDTH_LARGE, 100));
    modifyCasePanel.setMaximumSize(new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, 200));
    ButtonGroup modifyCaseGroup = new ButtonGroup();
    ActionListener radioButtonListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String cmd = e.getActionCommand();
            dataModel.setTreatCase(RenameForm.CASEHANDLING.valueOf(cmd));
            updateFileTable();
        }
    };
    JRadioButton lowerButton = new JRadioButton(localizer.localize("label.to-lower-case"));
    lowerButton.setActionCommand(RenameForm.CASEHANDLING.LOWER.name());
    lowerButton.addActionListener(radioButtonListener);
    modifyCaseGroup.add(lowerButton);
    modifyCasePanel.add(lowerButton);
    JRadioButton upperButton = new JRadioButton(localizer.localize("label.to-upper-case"));
    upperButton.setActionCommand(RenameForm.CASEHANDLING.UPPER.name());
    upperButton.addActionListener(radioButtonListener);
    modifyCaseGroup.add(upperButton);
    modifyCasePanel.add(upperButton);
    JRadioButton keepButton = new JRadioButton(localizer.localize("label.preserve-case"));
    keepButton.setActionCommand(RenameForm.CASEHANDLING.PRESERVE.name());
    keepButton.setSelected(true);
    keepButton.addActionListener(radioButtonListener);
    modifyCaseGroup.add(keepButton);
    modifyCasePanel.add(keepButton);
    this.add(modifyCasePanel);

    // prevent case conflict
    JCheckBox caseConflictBox = new JCheckBox(localizer.localize("label.prevent-case-conflict"));
    caseConflictBox.setAlignmentX(Component.LEFT_ALIGNMENT);
    caseConflictBox.setSelected(true);
    caseConflictBox.setEnabled(!SwingConfig.isWindows()); // disabled on windows
    caseConflictBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            dataModel.setPreventCaseConflict((ItemEvent.SELECTED == event.getStateChange()));
            updateFileTable();
        }
    });
    this.add(caseConflictBox);

    this.add(Box.createVerticalGlue());

}

From source file:com.rapidminer.gui.new_plotter.gui.dialog.AddParallelLineDialog.java

/**
 * Setup the GUI.//  ww w.  j  a v  a  2s.  c  o  m
 */
private void setupGUI() {
    JPanel mainPanel = new JPanel();
    this.setContentPane(mainPanel);

    // start layout
    mainPanel.setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 2, 5);
    horizontalLineRadiobutton = new JRadioButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.horizontal.label"));
    horizontalLineRadiobutton.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.horizontal.tip"));
    horizontalLineRadiobutton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setHorizontalLineSelected();
        }
    });
    horizontalLineRadiobutton.setSelected(true);
    this.add(horizontalLineRadiobutton, gbc);

    gbc.gridx = 1;
    gbc.gridy = 0;
    gbc.anchor = GridBagConstraints.EAST;
    verticalLineRadiobutton = new JRadioButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.vertical.label"));
    verticalLineRadiobutton
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.vertical.tip"));
    verticalLineRadiobutton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            setVerticalLineSelected();
        }
    });
    this.add(verticalLineRadiobutton, gbc);

    ButtonGroup group = new ButtonGroup();
    group.add(horizontalLineRadiobutton);
    group.add(verticalLineRadiobutton);

    gbc.gridx = 0;
    gbc.gridy = 1;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1;
    gbc.gridwidth = 2;
    gbc.anchor = GridBagConstraints.CENTER;
    rangeAxisSelectionCombobox = new JComboBox();
    rangeAxisSelectionCombobox.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.range_axis_combobox.tip"));
    rangeAxisSelectionCombobox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            updateYFieldValue();
        }
    });
    this.add(rangeAxisSelectionCombobox, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 2, 5);
    JLabel xLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.width.label"));
    this.add(xLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 2;
    gbc.insets = new Insets(2, 5, 2, 5);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    xField = new JTextField();
    xField.setText(String.valueOf(x));
    xField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyYInput(input);
        }
    });
    xField.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.width.tip"));
    xField.setEnabled(false);
    this.add(xField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.NONE;
    JLabel yLabel = new JLabel(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.height.label"));
    this.add(yLabel, gbc);

    gbc.gridx = 1;
    gbc.gridy = 3;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    yField = new JTextField();
    yField.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.height.tip"));
    yField.setText(String.valueOf(y));
    yField.setInputVerifier(new InputVerifier() {

        @Override
        public boolean verify(JComponent input) {
            return verifyXInput(input);
        }
    });
    this.add(yField, gbc);

    gbc.gridx = 0;
    gbc.gridy = 4;
    gbc.fill = GridBagConstraints.NONE;
    gbc.insets = new Insets(10, 5, 0, 5);
    modifyLineButton = new JButton();
    modifyLineButton.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.modify_line.tip"));
    modifyLineButton.setIcon(SwingTools.createIcon(
            "16/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.modify_line.icon")));
    modifyLineButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            modifyLine();
        }
    });
    this.add(modifyLineButton, gbc);

    gbc.gridx = 0;
    gbc.gridy = 5;
    gbc.gridwidth = 2;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(15, 5, 5, 5);
    this.add(new JSeparator(), gbc);

    gbc.gridx = 0;
    gbc.gridy = 6;
    gbc.gridwidth = 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(5, 5, 5, 5);
    okButton = new JButton(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.ok.label"));
    okButton.setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.ok.tip"));
    okButton.setIcon(SwingTools
            .createIcon("24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.ok.icon")));
    okButton.setMnemonic(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.ok.mne").toCharArray()[0]);
    okButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            boolean successful = addSpecifiedLine();
            // don't dispose dialog if not successful
            if (!successful) {
                return;
            }

            AddParallelLineDialog.this.dispose();
        }
    });
    okButton.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                okButton.doClick();
            }
        }
    });
    this.add(okButton, gbc);

    gbc.gridx = 1;
    gbc.gridy = 6;
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.EAST;
    cancelButton = new JButton(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.label"));
    cancelButton
            .setToolTipText(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.tip"));
    cancelButton.setIcon(SwingTools.createIcon(
            "24/" + I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.icon")));
    cancelButton.setMnemonic(
            I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.cancel.mne").toCharArray()[0]);
    cancelButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // cancel requested, close dialog
            AddParallelLineDialog.this.dispose();
        }
    });
    this.add(cancelButton, gbc);

    // misc settings
    this.setMinimumSize(new Dimension(300, 250));
    // center dialog
    this.setLocationRelativeTo(null);
    this.setTitle(I18N.getMessage(I18N.getGUIBundle(), "gui.action.add_parallel_line.title.label"));
    this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    this.setModal(true);

    this.addWindowListener(new WindowAdapter() {

        @Override
        public void windowActivated(WindowEvent e) {
            okButton.requestFocusInWindow();
        }
    });
}

From source file:com.nvinayshetty.DTOnator.Ui.InputWindow.java

private void initButtons() {
    buttonOk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onOK();//from  www.  ja va  2  s .c  o m
        }
    });
    buttonCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    });
    classTypeButtonGroup = new ButtonGroup();
    classTypeButtonGroup.add(createSeparateFile);
    classTypeButtonGroup.add(creteSingleFile);
    feedTypeButtonGroup = new ButtonGroup();
    feedTypeButtonGroup.add(pojoRadioButton);
    feedTypeButtonGroup.add(gsonRadioButton);
}

From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java

private JMenu getjTrommelSortMenu() {
    JMenu trommelSortMenu = new JMenu("Trommel Sortierung");

    JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren");
    inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder());
    inOrder.addActionListener(new ActionListener() {
        @Override/*  ww w . j av a  2 s  .c  om*/
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                ConfigReader.getInstance().setTrommelInOrder(inOrder.isSelected());
                //                    if (kabelTypAuswahlAAS != null) {
                //                        kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected());
                //                    }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
    trommelSortMenu.add(inOrder);

    trommelSortMenu.addSeparator();

    ButtonGroup group = new ButtonGroup();
    for (AbstractTrommelSort aTS : ConfigReader.getInstance().getAllTrommelSort()) {

        JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName());
        sw.setSelected(aTS.equals(ConfigReader.getInstance().getTrommelSort()));
        group.add(sw);
        trommelSortMenu.add(sw);

        sw.addActionListener(aTS);
    }
    return trommelSortMenu;
}