Java Code Examples for javax.swing.ButtonGroup#getElements()

The following examples show how to use javax.swing.ButtonGroup#getElements() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfilerPopup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getDefaultComponent(Container aContainer) {
    Component c = getFirstComponent(aContainer);
    
    if (c instanceof AbstractButton) {
        ButtonModel bm = ((AbstractButton)c).getModel();
        if (bm instanceof DefaultButtonModel) {
            ButtonGroup bg = ((DefaultButtonModel)bm).getGroup();
            Enumeration<AbstractButton> en = bg == null ? null : bg.getElements();
            while (en != null && en.hasMoreElements()) {
                AbstractButton ab = en.nextElement();
                if (ab.isSelected()) return ab;
            }
        }
    }
    
    return c;
}
 
Example 2
Source File: ProfilerPopup.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public Component getDefaultComponent(Container aContainer) {
    Component c = getFirstComponent(aContainer);
    
    if (c instanceof AbstractButton) {
        ButtonModel bm = ((AbstractButton)c).getModel();
        if (bm instanceof DefaultButtonModel) {
            ButtonGroup bg = ((DefaultButtonModel)bm).getGroup();
            Enumeration<AbstractButton> en = bg == null ? null : bg.getElements();
            while (en != null && en.hasMoreElements()) {
                AbstractButton ab = en.nextElement();
                if (ab.isSelected()) return ab;
            }
        }
    }
    
    return c;
}
 
Example 3
Source File: DriverSettings.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void setButtonGroup(String rdValue, ButtonGroup buttongroup) {
    Enumeration enumeration = buttongroup.getElements();
    while (enumeration.hasMoreElements()) {
        AbstractButton button = (AbstractButton) enumeration.nextElement();
        if (button.getActionCommand().equals(rdValue)) {
            buttongroup.setSelected(button.getModel(), true);
            break;
        }
    }
}
 
Example 4
Source File: CognizantITSSettings.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private void setButtonModelFromText(String text, ButtonGroup Bgroup) {
    for (Enumeration<AbstractButton> buttons = Bgroup.getElements(); buttons.hasMoreElements();) {
        AbstractButton button = buttons.nextElement();
        if (button.getText().equals(text)) {
            button.setSelected(true);
        }
    }
}
 
Example 5
Source File: CognizantITSSettings.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
private String getSelectedButton(ButtonGroup bGroup) {
    for (Enumeration<AbstractButton> buttons = bGroup.getElements(); buttons.hasMoreElements();) {
        AbstractButton button = buttons.nextElement();
        if (button.isSelected()) {
            return button.getText();
        }
    }
    return "None";
}
 
Example 6
Source File: OptionsPanel.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * @param group Button group.
 * @param value Value.
 */
private void setButtonGroupSelection(ButtonGroup group, int value) {
  if (group == null) {
    return;
  }
  Enumeration<AbstractButton> buttons = group.getElements();
  int count = 0;
  while (buttons.hasMoreElements()) {
    AbstractButton button = buttons.nextElement();
    group.setSelected(button.getModel(), (count == value));
    count++;
  }
}
 
Example 7
Source File: OptionsPanel.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Apply new values to the integer options.
 */
private void applyInteger() {
  Configuration config = Configuration.getConfiguration();

  for (Entry<ConfigurationValueInteger, Object> entry : integerValues.entrySet()) {
    if ((entry.getValue() != null) && (entry.getKey() != null)) {
      if (entry.getValue() instanceof JSpinner) {
        JSpinner spinner = (JSpinner) entry.getValue();
        Object value = spinner.getValue();
        if (value instanceof Integer) {
          Integer intValue = (Integer) value;
          config.setInt(null, entry.getKey(), intValue.intValue());
        }
      }
      if (entry.getValue() instanceof ButtonGroup) {
        ButtonGroup group = (ButtonGroup) entry.getValue();
        int count = 0;
        Enumeration<AbstractButton> buttons = group.getElements();
        while (buttons.hasMoreElements()) {
          AbstractButton button = buttons.nextElement();
          if (group.isSelected(button.getModel())) {
            config.setInt(null, entry.getKey(), count);
          }
          count++;
        }
      }
    }
  }
}
 
Example 8
Source File: TimeSeriesExportHelper.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static int parseLevel(ButtonGroup buttonGroup) {
    Enumeration<AbstractButton> buttonEnumeration = buttonGroup.getElements();
    while (buttonEnumeration.hasMoreElements()) {
        AbstractButton abstractButton = buttonEnumeration.nextElement();
        if (abstractButton.isSelected()) {
            String buttonText = abstractButton.getText();
            final int index = buttonText.indexOf(" (");
            if (index != -1) {
                buttonText = buttonText.substring(0, index);
            }
            return Integer.parseInt(buttonText);
        }
    }
    return-1;
}
 
Example 9
Source File: DataPanel.java    From DiskBrowser with GNU General Public License v3.0 4 votes vote down vote up
public DataPanel (MenuHandler mh)
// ---------------------------------------------------------------------------------//
{
  this.menuHandler = mh;
  setTabPlacement (SwingConstants.BOTTOM);

  formattedText = new JTextArea (10, TEXT_WIDTH);
  formattedPane = setPanel (formattedText, "Formatted");
  //    formattedText.setLineWrap (prefs.getBoolean (MenuHandler.PREFS_LINE_WRAP, true));
  formattedText.setText ("Please use the 'File->Set HOME folder...' command to "
      + "\ntell DiskBrowser where your Apple disks are located."
      + "\n\nTo see the contents of a disk in more detail, double-click"
      + "\nthe disk. You will then be able to select individual files to "
      + "view completely.");

  hexText = new JTextArea (10, TEXT_WIDTH);
  setPanel (hexText, "Hex dump");

  disassemblyText = new JTextArea (10, TEXT_WIDTH);
  setPanel (disassemblyText, "Disassembly");

  imagePanel = new ImagePanel ();
  imagePane =
      new JScrollPane (imagePanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
          ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

  imagePane.setBorder (null);

  imagePane.getVerticalScrollBar ().setUnitIncrement (50);
  imagePane.getHorizontalScrollBar ().setUnitIncrement (25);

  addChangeListener (new ChangeListener ()
  {
    @Override
    public void stateChanged (ChangeEvent e)
    {
      switch (getSelectedIndex ())
      {
        case 0:
          if (!formattedTextValid)
          {
            if (currentDataSource == null)
              formattedText.setText ("");
            else
              setText (formattedText, currentDataSource.getText ());
            formattedTextValid = true;
          }
          break;
        case 1:
          if (!hexTextValid)
          {
            if (currentDataSource == null)
              hexText.setText ("");
            else
              setText (hexText, currentDataSource.getHexDump ());
            hexTextValid = true;
          }
          break;
        case 2:
          if (!assemblerTextValid)
          {
            if (currentDataSource == null)
              disassemblyText.setText ("");
            else
              setText (disassemblyText, currentDataSource.getAssembler ());
            assemblerTextValid = true;
          }
          break;
        default:
          System.out.println ("Invalid index selected in DataPanel");
      }
    }
  });

  LineWrapAction lineWrapAction = new LineWrapAction ();
  menuHandler.lineWrapItem.setAction (lineWrapAction);
  lineWrapAction.addListener (formattedText);

  menuHandler.colourQuirksItem.setAction (new ColourQuirksAction (this));
  menuHandler.monochromeItem.setAction (new MonochromeAction (this));
  menuHandler.debuggingItem.setAction (new DebuggingAction (this));

  // fill in the placeholders created by the MenuHandler
  List<Palette> palettes = HiResImage.getPalettes ();
  ButtonGroup buttonGroup = menuHandler.paletteGroup;
  Enumeration<AbstractButton> enumeration = buttonGroup.getElements ();
  int ndx = 0;
  while (enumeration.hasMoreElements ())
  {
    JCheckBoxMenuItem item = (JCheckBoxMenuItem) enumeration.nextElement ();
    item.setAction (new PaletteAction (this, palettes.get (ndx++)));
  }
  menuHandler.nextPaletteItem.setAction (new NextPaletteAction (this, buttonGroup));
  menuHandler.prevPaletteItem.setAction (new PreviousPaletteAction (this, buttonGroup));
}
 
Example 10
Source File: KwikiPDFToolBar.java    From ET_Redux with Apache License 2.0 4 votes vote down vote up
private void SetupDateChooserButtons() {
    dateChooserButtonGroup = new ButtonGroup();

    date206_238_radioButton = new JRadioButton("206/238");
    dateChooserButtonGroup.add(date206_238_radioButton);
    date206_238_radioButton.setFont(new java.awt.Font("Arial", 1, 10));
    date206_238_radioButton.setText("206/238");
    date206_238_radioButton.setName("age206_238r");
    date206_238_radioButton.setBounds(40, 1, 70, 17);
    date206_238_radioButton.setSelected(true);
    date206_238_radioButton.setOpaque(true);
    date206_238_radioButton.setBackground(Color.white);
    add(date206_238_radioButton);

    date207_206_radioButton = new JRadioButton("207/206");
    dateChooserButtonGroup.add(date207_206_radioButton);
    date207_206_radioButton.setFont(new java.awt.Font("Arial", 1, 10));
    date207_206_radioButton.setText("207/206");
    date207_206_radioButton.setName("age207_206r");
    date207_206_radioButton.setBounds(40, 19, 70, 17);
    date207_206_radioButton.setOpaque(true);
    date207_206_radioButton.setBackground(Color.white);
    add(date207_206_radioButton);

    dateBest_radioButton = new JRadioButton("best");
    dateChooserButtonGroup.add(dateBest_radioButton);
    dateBest_radioButton.setFont(new java.awt.Font("Arial", 1, 10));
    dateBest_radioButton.setText("best");
    dateBest_radioButton.setName("bestAge");
    dateBest_radioButton.setOpaque(true);
    dateBest_radioButton.setBackground(Color.white);
    dateBest_radioButton.setBounds(40, 37, 70, 17);

    add(dateBest_radioButton);

    // choose date
    for (Enumeration e = dateChooserButtonGroup.getElements(); e.hasMoreElements();) {
        final JRadioButton jrb = (JRadioButton) e.nextElement();
        jrb.addActionListener((ActionEvent arg0) -> {
            // oct 2014 handle new Pbc corrections
            String chosenDateName = jrb.getName();

            ((DateProbabilityDensityPanel) probabilityPanel).setChosenDateName(chosenDateName);
            ((DateProbabilityDensityPanel) probabilityPanel).//
                    setSelectedFractions(sample.getUpbFractionsUnknown());
            ((DateProbabilityDensityPanel) probabilityPanel).prepareAndPaintPanel();
        });
    }

}