Example usage for javax.swing ButtonGroup getElements

List of usage examples for javax.swing ButtonGroup getElements

Introduction

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

Prototype

public Enumeration<AbstractButton> getElements() 

Source Link

Document

Returns all the buttons that are participating in this group.

Usage

From source file:Main.java

public static int getButtonGroupSelectIndex(ButtonGroup bg) {
    if (bg.getButtonCount() <= 0) {
        return -1;
    }/* w ww .ja  va 2 s  .co  m*/
    Enumeration<AbstractButton> bEnum = bg.getElements();
    for (int i = 0; bEnum.hasMoreElements(); i++) {
        AbstractButton temp = bEnum.nextElement();
        if (temp.isSelected()) {
            return i;
        }

    }
    return -1;
}

From source file:Main.java

public Main() {
    JRadioButton radMarriedYes = new JRadioButton("Yes?", true);
    JRadioButton radMarriedNo = new JRadioButton("No?", false);
    JRadioButton radGolfYes = new JRadioButton("Yes?", false);
    JRadioButton radGolfNo = new JRadioButton("No?", true);

    ButtonGroup radioGroup1 = new ButtonGroup();
    ButtonGroup radioGroup2 = new ButtonGroup();

    setLayout(null);//  w w  w  . j  a  va  2 s.  c o m

    add(radMarriedYes);
    add(radMarriedNo);
    add(radGolfYes);
    add(radGolfNo);

    radioGroup1.add(radMarriedYes);
    radioGroup1.add(radMarriedNo);

    Enumeration<AbstractButton> e = radioGroup1.getElements();

    radioGroup2.add(radGolfYes);
    radioGroup2.add(radGolfNo);

    radMarriedYes.setBounds(30, 50, 50, 20);
    radMarriedNo.setBounds(30, 80, 50, 20);

    radGolfYes.setBounds(150, 50, 50, 20);
    radGolfNo.setBounds(150, 80, 50, 20);
}

From source file:view.transacao.Relatorio.java

public JRadioButton getSelectedRadio(ButtonGroup group) {
    for (Enumeration eRadio = group.getElements(); eRadio.hasMoreElements();) {
        JRadioButton radioButton = (JRadioButton) eRadio.nextElement();

        if (radioButton.getModel() == group.getSelection()) {
            return radioButton;
        }/*from ww w.  j  a va2s .  co m*/
    }

    return null;
}

From source file:lab4.YouQuiz.java

public String getSelectedButtonText(ButtonGroup buttonGroup) {
    for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) {
        AbstractButton button = buttons.nextElement();

        if (button.isSelected()) {
            return button.getText();
        }/*ww w  .  ja  v  a 2 s  .  c  o  m*/
    }
    return null;
}

From source file:eu.apenet.dpt.standalone.gui.ead2edm.EdmOptionsPanel.java

private boolean isRadioBtnChecked(ButtonGroup buttonGroup) {
    Enumeration<AbstractButton> enumeration = buttonGroup.getElements();
    while (enumeration.hasMoreElements()) {
        AbstractButton btn = enumeration.nextElement();
        if (btn.isSelected()) {
            return true;
        }/*w  ww .  j a v  a 2 s  .  com*/
    }
    return false;
}

From source file:org.accretegb.modules.germplasm.stockannotation.StockAnnotationPanel.java

private JPanel addStockPanelToolButtons() {
    JPanel panel = new JPanel();
    panel.setLayout(new MigLayout("insets 0 0 0 0, gapx 0"));
    List<Integer> editableColumns = new ArrayList<Integer>();
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION));
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE));
    editableColumns.add(stockTablePanel.getTable().getIndexOf(ColumnConstants.GENERATION));
    stockTablePanel.getTable().setEditableColumns(editableColumns);
    ;/*w w w.j a v a  2 s. c  o m*/
    JButton importStockList = new JButton("Import Stocks By Search");
    JButton importHarvestGroup = new JButton("Import Stocks From Harvest Group");
    JPanel subPanel1 = new JPanel();
    subPanel1.setLayout(new MigLayout("insets 0 0 0 0, gapx 0"));
    subPanel1.add(importStockList, "gapRight 10");
    subPanel1.add(importHarvestGroup, "gapRight 10, wrap");
    panel.add(subPanel1, "gapLeft 10, spanx,wrap");
    importStockList.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            StocksInfoPanel stockInfoPanel = CreateStocksInfoPanel
                    .createStockInfoPanel("stock annotation popup");
            stockInfoPanel.setSize(new Dimension(500, 400));
            int option = JOptionPane.showConfirmDialog(null, stockInfoPanel, "Search Stock Packets",
                    JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
            ArrayList<Integer> stockIds = new ArrayList<Integer>();

            if (option == JOptionPane.OK_OPTION) {
                DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel();
                CheckBoxIndexColumnTable stocksOutputTable = stockInfoPanel.getSaveTablePanel().getTable();
                for (int row = 0; row < stocksOutputTable.getRowCount(); ++row) {
                    int stockId = (Integer) stocksOutputTable.getValueAt(row,
                            stocksOutputTable.getIndexOf(ColumnConstants.STOCK_ID));
                    stockIds.add(stockId);
                }
                List<Stock> stocks = StockDAO.getInstance().getStocksByIds(stockIds);
                for (Stock stock : stocks) {
                    Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()];
                    rowData[0] = new Boolean(false);
                    Passport passport = stock.getPassport();
                    StockGeneration generation = stock.getStockGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock
                            .getStockName();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock
                            .getStockId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null
                                    : generation.getGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null
                            ? null
                            : passport.getAccession_name();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null
                            ? null
                            : passport.getPedigree();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationCode();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getPopulation();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getTaxonomyId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean(
                            false);
                    model.addRow(rowData);
                }

            }

        }

    });

    importHarvestGroup.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ArrayList<PMProject> projects = TokenRelationDAO.getInstance()
                    .findProjectObjects(LoginScreen.loginUserId);
            HashMap<String, Harvesting> name_tap = new HashMap<String, Harvesting>();
            for (PMProject project : projects) {
                List<HarvestingGroup> HarvestingGroups = HarvestingGroupDAO.getInstance()
                        .findByProjectid(project.getProjectId());
                for (HarvestingGroup hg : HarvestingGroups) {
                    Harvesting harvestingPanel = (Harvesting) getContext()
                            .getBean("Harvesting - " + project.getProjectId() + hg.getHarvestingGroupName());
                    name_tap.put(project.getProjectName() + "-" + hg.getHarvestingGroupName(), harvestingPanel);
                }

            }
            JPanel popup = new JPanel(new MigLayout("insets 0, gap 5"));
            JScrollPane jsp = new JScrollPane(popup) {
                @Override
                public Dimension getPreferredSize() {
                    return new Dimension(250, 320);
                }
            };
            ButtonGroup group = new ButtonGroup();
            for (String name : name_tap.keySet()) {
                JRadioButton button = new JRadioButton(name);
                group.add(button);
                popup.add(button, "wrap");

                button.setSelected(true);
            }
            String selected_group = null;
            int option = JOptionPane.showConfirmDialog(null, jsp, "Select Harvesting Group Name: ",
                    JOptionPane.OK_CANCEL_OPTION);
            if (option == JOptionPane.OK_OPTION) {
                for (Enumeration<AbstractButton> buttons = group.getElements(); buttons.hasMoreElements();) {
                    AbstractButton button = buttons.nextElement();
                    if (button.isSelected()) {
                        selected_group = button.getText();

                    }
                }
            }
            if (selected_group != null) {
                Harvesting harvestingPanel = name_tap.get(selected_group);
                DefaultTableModel model = (DefaultTableModel) stockTablePanel.getTable().getModel();
                ArrayList<String> stocknames = harvestingPanel.getStickerGenerator().getCreatedStocks();
                List<Stock> stocks = StockDAO.getInstance().getStocksByNames(stocknames);
                for (Stock stock : stocks) {
                    Object[] rowData = new Object[stockTablePanel.getTable().getColumnCount()];
                    rowData[0] = new Boolean(false);
                    Passport passport = stock.getPassport();
                    StockGeneration generation = stock.getStockGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_NAME)] = stock
                            .getStockName();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.STOCK_ID)] = stock
                            .getStockId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.GENERATION)] = generation == null ? null
                                    : generation.getGeneration();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.PASSPORT_ID)] = passport == null ? null : passport.getPassportId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.ACCESSION)] = passport == null
                            ? null
                            : passport.getAccession_name();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.PEDIGREE)] = passport == null
                            ? null
                            : passport.getPedigree();

                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_CODE)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationCode();
                    rowData[stockTablePanel.getTable().getIndexOf(
                            ColumnConstants.CLASSIFICATION_ID)] = passport.getClassification() == null ? null
                                    : passport.getClassification().getClassificationId();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.POPULATION)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getPopulation();
                    rowData[stockTablePanel.getTable()
                            .getIndexOf(ColumnConstants.TAXONOMY_ID)] = passport.getTaxonomy() == null ? null
                                    : passport.getTaxonomy().getTaxonomyId();
                    rowData[stockTablePanel.getTable().getIndexOf(ColumnConstants.MODIFIED)] = new Boolean(
                            false);
                    model.addRow(rowData);
                }
            }

        }

    });
    getstockTablePanel().getTable().addFocusListener(new FocusAdapter() {
        public void focusLost(FocusEvent e) {
            int row = getstockTablePanel().getTable().getSelectionModel().getAnchorSelectionIndex();
            getstockTablePanel().getTable().setValueAt(true, row,
                    getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
        }
    });
    JPanel subPanel2 = new JPanel();
    subPanel2.setLayout(new MigLayout("insets 0 0 0 0 , gapx 0"));
    subPanel2.add(new JLabel("Pedigree: "));
    this.pedigreeField = new JTextField(10);
    subPanel2.add(pedigreeField);
    JButton setPedigree = new JButton("set");
    setPedigree.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(pedigreeField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.PEDIGREE));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
            }
        }
    });
    subPanel2.add(setPedigree, "gapRight 15");

    subPanel2.add(new JLabel("Accession: "));
    this.accessionField = new JTextField(10);
    subPanel2.add(accessionField);
    JButton setAccession = new JButton("set");
    setAccession.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(accessionField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.ACCESSION));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));

            }
        }
    });
    subPanel2.add(setAccession, "gapRight 15");

    subPanel2.add(new JLabel("Generarion: "));
    this.generarionField = new JTextField(10);
    subPanel2.add(generarionField);
    JButton setGeneration = new JButton("set");
    setGeneration.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            for (int row : getstockTablePanel().getTable().getSelectedRows()) {
                getstockTablePanel().getTable().setValueAt(generarionField.getText(), row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.GENERATION));
                getstockTablePanel().getTable().setValueAt(true, row,
                        getstockTablePanel().getTable().getIndexOf(ColumnConstants.MODIFIED));
            }
        }
    });
    subPanel2.add(setGeneration);

    panel.add(subPanel2, "gapLeft 10,spanx");
    return panel;

}

From source file:org.drugis.addis.gui.WelcomeDialog.java

private void initComps() {

    final ButtonGroup examples = new ButtonGroup();
    examples.add(new JRadioButton(Main.Examples.DEPRESSION.name, true));
    examples.add(new JRadioButton(Main.Examples.HYPERTENSION.name));

    final AbstractAction exampleAction = new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            d_main.loadExampleDomain(Main.Examples.findFileName(getSelection(examples).getText()));
            closeWelcome();/*from   www .  j ava  2  s. c o m*/
        }
    };

    final AbstractAction loadAction = new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            if (d_main.fileLoadActions() == JFileChooser.APPROVE_OPTION) {
                closeWelcome();
            }
        }
    };

    final AbstractAction newAction = new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            d_main.newFileActions();
            closeWelcome();
        }
    };

    FormLayout layout = new FormLayout("left:pref, " + SPACING + "px, left:pref",
            "p, 3dlu, p, " + SPACING + "px, p, " + SPACING + "px, p, 3dlu, p");
    PanelBuilder builder = new PanelBuilder(layout);
    final CellConstraints cc = new CellConstraints();

    builder.add(createImageLabel(FileNames.IMAGE_HEADER), cc.xyw(1, 1, 3));
    builder.add(createButton("Load example", FileNames.ICON_TIP, exampleAction), cc.xy(1, 3));

    final PanelBuilder radios = new PanelBuilder(new FormLayout("p, fill:pref:grow, right:pref", "p, 3dlu, p"));

    final ArrayList<AbstractButton> buttons = Collections.list(examples.getElements());
    forAllDo(buttons, new Closure<AbstractButton>() {
        public void execute(final AbstractButton exampleOption) {
            int row = buttons.indexOf(exampleOption) == 0 ? 1 : buttons.indexOf(exampleOption) + 2;
            exampleOption.setOpaque(false);
            radios.add(exampleOption, cc.xy(1, row));
            radios.add(createHelpButton(exampleOption), cc.xy(3, row));
        }

        private JButton createHelpButton(final AbstractButton exampleOption) {
            JButton help = GUIFactory.createIconButton(org.drugis.mtc.gui.FileNames.ICON_ABOUT,
                    "Information about this example");
            removeBackground(help);

            help.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Examples example = Examples.findByName(exampleOption.getText());
                    String helpText = s_help.getHelpText(example.name().toLowerCase());
                    showExampleInfo(helpText);
                }
            });
            return help;
        }
    });

    JPanel radiosPanel = radios.getPanel();
    setBorder(radiosPanel);
    builder.add(radiosPanel, cc.xy(3, 3));

    builder.add(createButton("Open file", FileNames.ICON_OPENFILE, loadAction), cc.xy(1, 5));
    JTextPane load = createLabel("Load an existing ADDIS data file stored on your computer.");
    builder.add(load, cc.xy(3, 5));

    builder.add(createButton("New dataset", FileNames.ICON_FILE_NEW, newAction), cc.xy(1, 7));
    builder.add(createLabel("Start with an empty file to build up your own data and analyses."), cc.xy(3, 7));

    builder.add(createImageLabel(FileNames.IMAGE_FOOTER), cc.xyw(1, 9, 3));

    setContentPane(builder.getPanel());
}

From source file:org.drugis.addis.gui.WelcomeDialog.java

public static JRadioButton getSelection(ButtonGroup group) {
    for (Enumeration<AbstractButton> e = group.getElements(); e.hasMoreElements();) {
        JRadioButton b = (JRadioButton) e.nextElement();
        if (b.getModel() == group.getSelection()) {
            return b;
        }//www  .j  a v a2 s . com
    }
    return null;
}

From source file:org.jets3t.gui.UserInputFields.java

/**
 *
 *
 * @return//from   w  w  w .ja v  a  2  s  .  com
 * properties containing the user's answers to the input fields. Property names correspond to
 * the field's name, and the property values are the user's response.
 */
public Properties getUserInputsAsProperties(boolean hashPasswords) {
    Properties properties = new Properties();

    for (Iterator iter = userInputComponentsMap.keySet().iterator(); iter.hasNext();) {
        String fieldName = (String) iter.next();
        String fieldValue = null;

        Object component = userInputComponentsMap.get(fieldName);
        if (component instanceof ButtonGroup) {
            ButtonGroup bg = (ButtonGroup) component;
            Enumeration radioEnum = bg.getElements();
            while (radioEnum.hasMoreElements()) {
                JRadioButton button = (JRadioButton) radioEnum.nextElement();
                if (button.isSelected()) {
                    fieldValue = button.getText();
                    break;
                }
            }
        } else if (component instanceof JComboBox) {
            fieldValue = ((JComboBox) component).getSelectedItem().toString();
        } else if (component instanceof JPasswordField) {
            if (hashPasswords) {
                String password = new String(((JPasswordField) component).getPassword());
                try {
                    fieldValue = ServiceUtils
                            .toHex(ServiceUtils.computeMD5Hash(password.getBytes(Constants.DEFAULT_ENCODING)));
                } catch (Exception e) {
                    log.error("Unable to generate hash of password for field named '" + fieldName + "'", e);
                }
            } else {
                fieldValue = new String(((JPasswordField) component).getPassword());
            }
        } else if (component instanceof JTextField) {
            fieldValue = ((JTextField) component).getText();
        } else if (component instanceof JTextArea) {
            fieldValue = ((JTextArea) component).getText();
        } else {
            log.warn("Unrecognised component type for field named '" + fieldName + "': "
                    + component.getClass().getName());
        }

        properties.put(fieldName, fieldValue);
    }
    return properties;
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/**
 * Removes all the elements from the passed menu and button group.
 * // w  ww  .  j av  a 2 s  .  c  o  m
 * @param group The group to handle.
 * @param menu  The menu to handle.
 */
private void clearZoomMenu(ButtonGroup group, JMenu menu) {
    menu.removeAll();
    for (Enumeration<AbstractButton> e = group.getElements(); e.hasMoreElements();)
        group.remove(e.nextElement());
}