Example usage for javax.swing JRadioButton setForeground

List of usage examples for javax.swing JRadioButton setForeground

Introduction

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

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The foreground color of the component.")
public void setForeground(Color fg) 

Source Link

Document

Sets the foreground color of this component.

Usage

From source file:com.diversityarrays.kdxplore.trials.SampleGroupExportDialog.java

public SampleGroupExportDialog(Window owner, String title, Trial trial, KdxploreDatabase kdxploreDatabase,
        DeviceType deviceType, DeviceIdentifier devid, SampleGroup sampleGroup,
        Set<Integer> excludeTheseTraitIds, Map<Integer, Trait> allTraitIds, Set<Integer> excludeThesePlotIds) {
    super(owner, title, ModalityType.APPLICATION_MODAL);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setGlassPane(backgroundRunner.getBlockingPane());

    this.allTraits = allTraitIds;
    this.trial = trial;
    this.kdxploreDatabase = kdxploreDatabase;
    this.sampleGroup = sampleGroup;
    this.excludeTheseTraitIds = excludeTheseTraitIds;
    this.excludeThesePlotIds = excludeThesePlotIds;

    String deviceName = devid == null ? "Unknown_" + deviceType.name() : devid.getDeviceName();

    if (DeviceType.FOR_SCORING.equals(deviceType)) {
        if (!Check.isEmpty(sampleGroup.getOperatorName())) {
            deviceName = sampleGroup.getOperatorName();
        }/*from   w w  w  .  j  a  va  2  s . c o m*/
    }

    File directory = KdxplorePreferences.getInstance().getOutputDirectory();
    if (directory == null) {
        directory = new File(System.getProperty("user.home"));
    }
    String filename = Util.getTimestampedOutputFileName(trial.getTrialName(), deviceName);

    File outfile = new File(directory, filename);

    filepathText.setText(outfile.getPath());

    filepathText.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateButtons();
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateButtons();
        }
    });
    updateButtons();

    boolean developer = RunMode.getRunMode().isDeveloper();
    oldKdsmartOption.setForeground(Color.BLUE);
    oldKdsmartOption.setToolTipText("For ElapsedDays value compatiblity with older versions of KDSmart");

    Box exportForOptionsBox = Box.createHorizontalBox();
    for (JComponent comp : exportForOptions) {
        if (developer || comp != oldKdsmartOption) {
            exportForOptionsBox.add(comp);
        }
    }

    Map<JRadioButton, OutputOption> optionByRb = new HashMap<>();
    ActionListener rbListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectedOutputOption = optionByRb.get(e.getSource());
            boolean enb = selectedOutputOption.exportFor != null;
            for (JComponent comp : exportForOptions) {
                if (comp == wantMediaFilesOption) {
                    comp.setEnabled(enb && selectedOutputOption.supportsMediaFiles());
                } else if (comp == kdsmartVersion3option) {
                    comp.setEnabled(enb && selectedOutputOption.usesWorkPackage());
                } else {
                    comp.setEnabled(enb);
                }
            }
        }
    };

    boolean anySamplesForIndividuals = true;
    try {
        anySamplesForIndividuals = kdxploreDatabase.getAnySamplesForIndividuals(sampleGroup);
    } catch (IOException e) {
        Shared.Log.w("SampleGroupExportDialog", "getAnySamplesForIndividuals", e);
    }

    ButtonGroup bg = new ButtonGroup();
    Box radioButtons = Box.createHorizontalBox();

    List<OutputOption> options = new ArrayList<>();
    Collections.addAll(options, OutputOption.values());

    if (!anySamplesForIndividuals) {
        // No relevant samples so don't bother offering the option.
        options.remove(OutputOption.CSV_FULL);
    }

    for (OutputOption oo : options) {
        if (!developer && OutputOption.JSON == oo) {
            continue;
        }

        JRadioButton rb = new JRadioButton(oo.displayName);
        if (OutputOption.KDX == oo) {
            kdxExportButton = rb;
        }

        if (OutputOption.ZIP == oo) {
            zipExportButton = rb;
        }

        rb.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                exportExclusionBox.selectAndDeactivateButtons(
                        kdxExportButton.isSelected() || zipExportButton.isSelected());
            }
        });

        if (OutputOption.JSON == oo) {
            rb.setForeground(Color.BLUE);
            rb.setToolTipText("Developer Only");
        }
        bg.add(rb);
        optionByRb.put(rb, oo);
        radioButtons.add(rb);
        rb.addActionListener(rbListener);
        if (bg.getButtonCount() == 1) {
            rb.doClick();
        }
    }

    Box additionalOptionsBox = Box.createHorizontalBox();
    additionalOptionsBox.add(this.wantMediaFilesOption);
    additionalOptionsBox.add(this.kdsmartVersion3option);

    dbVersionLabel.setToolTipText(TTT_DATABASE_VERSION_FOR_EXPORT);
    databaseVersionChoices.setToolTipText(TTT_DATABASE_VERSION_FOR_EXPORT);

    JPanel panel = new JPanel();
    GBH gbh = new GBH(panel);
    int y = 0;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Output File:");
    gbh.add(1, y, 1, 1, GBH.HORZ, 1, 1, GBH.CENTER, filepathText);
    gbh.add(2, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, new JButton(browseFileAction));
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, "Options:");
    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, radioButtons);
    ++y;

    gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, exportExclusionBox);
    ++y;

    gbh.add(0, y, 3, 1, GBH.HORZ, 1, 1, GBH.CENTER, additionalOptionsBox);
    ++y;

    gbh.add(0, y, 1, 1, GBH.NONE, 0, 1, GBH.EAST, dbVersionLabel);
    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, BoxBuilder.horizontal().add(databaseVersionChoices).get());

    gbh.add(1, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, exportForOptionsBox);
    ++y;

    Box buttons = Box.createHorizontalBox();
    buttons.add(Box.createHorizontalGlue());
    buttons.add(new JButton(cancelAction));
    buttons.add(new JButton(exportAction));
    buttons.add(new JButton(exportAndCloseAction));

    Container cp = getContentPane();

    cp.add(panel, BorderLayout.CENTER);
    cp.add(buttons, BorderLayout.SOUTH);

    pack();
}