Example usage for javax.swing AbstractButton getActionCommand

List of usage examples for javax.swing AbstractButton getActionCommand

Introduction

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

Prototype

public String getActionCommand() 

Source Link

Document

Returns the action command for this button.

Usage

From source file:SimpleButtonGroupExample.java

public static void main(String[] args) {
    // Some choices
    JRadioButton choice1, choice2, choice3;
    choice1 = new JRadioButton("Bach: Well Tempered Clavier, Book I");
    choice1.setActionCommand("bach1");
    choice2 = new JRadioButton("Bach: Well Tempered Clavier, Book II");
    choice2.setActionCommand("bach2");
    choice3 = new JRadioButton("Shostakovich: 24 Preludes and Fugues");
    choice3.setActionCommand("shostakovich");

    // A group, to ensure that we only vote for one.
    final ButtonGroup group = new ButtonGroup();
    group.add(choice1);//  w  w  w .  j av a2  s .c  o m
    group.add(choice2);
    group.add(choice3);

    // A simple ActionListener, showing each selection using the ButtonModel
    class VoteActionListener implements ActionListener {
        public void actionPerformed(ActionEvent ev) {
            String choice = group.getSelection().getActionCommand();
            System.out.println("ACTION Choice Selected: " + choice);
        }
    }

    // A simple ItemListener, showing each selection and deselection
    class VoteItemListener implements ItemListener {
        public void itemStateChanged(ItemEvent ev) {
            boolean selected = (ev.getStateChange() == ItemEvent.SELECTED);
            AbstractButton button = (AbstractButton) ev.getItemSelectable();
            System.out
                    .println("ITEM Choice Selected: " + selected + ", Selection: " + button.getActionCommand());
        }
    }

    // Add listeners to each button
    ActionListener alisten = new VoteActionListener();
    choice1.addActionListener(alisten);
    choice2.addActionListener(alisten);
    choice3.addActionListener(alisten);

    ItemListener ilisten = new VoteItemListener();
    choice1.addItemListener(ilisten);
    choice2.addItemListener(ilisten);
    choice3.addItemListener(ilisten);

    // Throw everything together
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container c = frame.getContentPane();
    c.setLayout(new GridLayout(0, 1));
    c.add(new JLabel("Vote for your favorite prelude & fugue cycle"));
    c.add(choice1);
    c.add(choice2);
    c.add(choice3);
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    AbstractButton jb = new JButton("Press Me");
    jb.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            System.out.println(((JComponent) arg0.getSource()).getFont());
        }/*  w w  w .  j  a  v a 2s.c om*/
    });
    System.out.println(jb.getActionCommand());
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(jb);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

private static void inactivateOption(Container container, String text) {
    Component[] comps = container.getComponents();
    for (Component comp : comps) {
        if (comp instanceof AbstractButton) {
            AbstractButton btn = (AbstractButton) comp;
            if (btn.getActionCommand().equals(text)) {
                btn.setEnabled(false);//  w w  w.ja va  2 s. c o  m
                return;
            }
        } else if (comp instanceof Container) {
            inactivateOption((Container) comp, text);
        }
    }

}

From source file:com.codeasylum.liquibase.Liquidate.java

public synchronized void setConfig(LiquidateConfig config) {

    this.config = config;

    changeSensitive = false;/*w w  w .j  a v a2s .c  o  m*/
    try {
        databaseCombo.setSelectedItem((config.getDatabase() == null) ? Database.MYSQL : config.getDatabase());
        hostTextField.setText((config.getHost() == null) ? "" : config.getHost());
        portTextField.setText((config.getPort() == 0) ? "" : String.valueOf(config.getPort()));
        schemaTextField.setText((config.getSchema() == null) ? "" : config.getSchema());
        userTextField.setText((config.getUser() == null) ? "" : config.getUser());
        passwordField.setText((config.getPassword() == null) ? "" : config.getPassword());

        for (AbstractButton button : new EnumerationIterator<AbstractButton>(sourceButtonGroup.getElements())) {
            if (button.getActionCommand()
                    .equals((config.getSource() == null) ? Source.FILE.name() : config.getSource().name())) {
                sourceButtonGroup.setSelected(button.getModel(), true);
                break;
            }
        }

        changeLogTextField.setText((config.getChangeLog() == null) ? "" : config.getChangeLog());

        for (AbstractButton button : new EnumerationIterator<AbstractButton>(goalButtonGroup.getElements())) {
            if (button.getActionCommand()
                    .equals((config.getGoal() == null) ? Goal.PREVIEW.name() : config.getGoal().name())) {
                goalButtonGroup.setSelected(button.getModel(), true);
                break;
            }
        }

        outputTextField.setText(config.getOutput());
        outputTextField
                .setEnabled(config.getGoal().equals(Goal.GENERATE) || config.getGoal().equals(Goal.DOCUMENT));
        browseButton
                .setEnabled(config.getGoal().equals(Goal.GENERATE) || config.getGoal().equals(Goal.DOCUMENT));
    } finally {
        changeSensitive = true;
    }
}

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

private String getCorrectRights(String type) {
    if (type.equals(CREATIVE_COMMONS)) {
        CreativeCommonsType creativeCommonsType = new CreativeCommonsType();
        Enumeration<AbstractButton> enumeration = creativeCommonsBtnGrp.getElements();
        while (enumeration.hasMoreElements()) {
            AbstractButton btn = enumeration.nextElement();
            if (btn.isSelected()) {
                creativeCommonsType.setBtnChecked(btn.getActionCommand());
            }//from  w  w w . j av a  2  s.  c  om
        }
        String urlType = creativeCommonsType.getUrlType();
        CreativeCommons creativeCommons = CreativeCommons
                .getCreativeCommonsByCountryName(creativeCommonsComboBox.getSelectedItem().toString());
        String url = CreativeCommons.constructUrl(creativeCommons);
        return MessageFormat.format(url, urlType);
    } else if (type.equals(EUROPEANA_RIGHTS_STATEMENTS)) {
        String europeanaRights = europeanaRightsComboBox.getSelectedItem().toString();
        if (europeanaRights.equals(this.labels.getString("edm.panel.license.europeana.free"))) {
            return "http://www.europeana.eu/rights/rr-f/";
        } else if (europeanaRights.equals(this.labels.getString("edm.panel.license.europeana.paid"))) {
            return "http://www.europeana.eu/rights/rr-p/";
        } else if (europeanaRights.equals(this.labels.getString("edm.panel.license.europeana.orphan"))) {
            return "http://www.europeana.eu/rights/orphan-work-eu/";
        } else {
            return "http://www.europeana.eu/rights/unknown/";
        }
    } else if (type.equalsIgnoreCase(EdmOptionsPanel.OUT_OF_COPYRIGHT)) {
        return "http://www.europeana.eu/rights/out-of-copyright-non-commercial/";
    } else if (type.equals(CREATIVE_COMMONS_CC0)) {
        return "http://creativecommons.org/publicdomain/zero/1.0/";
    } else {
        return "http://creativecommons.org/publicdomain/mark/1.0/";
    }
}

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

private EdmConfig fillEdmConfig() {
    EdmConfig config = new EdmConfig();

    Enumeration<AbstractButton> enumeration = cLevelIdSourceButtonGroup.getElements();
    boolean found = false;
    while (!found && enumeration.hasMoreElements()) {
        AbstractButton btn = enumeration.nextElement();
        if (btn.isSelected()) {
            if (EdmOptionsPanel.UNITID.equals(btn.getActionCommand())) {
                config.setIdSource(EdmOptionsPanel.UNITID);
            } else if (EdmOptionsPanel.CID.equals(btn.getActionCommand())) {
                config.setIdSource(EdmOptionsPanel.CID);
            }/*from  ww w. j  a va 2  s  . co m*/
            found = true;
        }
    }

    enumeration = landingPageButtonGroup.getElements();
    found = false;
    while (!found && enumeration.hasMoreElements()) {
        AbstractButton btn = enumeration.nextElement();
        if (btn.isSelected()) {
            if (EdmOptionsPanel.APE.equals(btn.getActionCommand())) {
                config.setLandingPage(EdmOptionsPanel.APE);
            } else if (EdmOptionsPanel.OTHER.equals(btn.getActionCommand())) {
                config.setLandingPage(landingPageTextArea.getText());
            }
            found = true;
        }
    }

    config.setUseExistingRepository(false);
    if (useExistingRepoCheckbox.isSelected()) {
        config.setUseExistingRepository(true);
    }

    config.setDataProvider(dataProviderTextArea.getText());
    config.setProvider("Archives Portal Europe");

    enumeration = typeGroup.getElements();
    found = false;
    while (!found && enumeration.hasMoreElements()) {
        AbstractButton btn = enumeration.nextElement();
        if (btn.isSelected()) {
            if (EdmOptionsPanel.TEXT.equals(btn.getActionCommand())) {
                config.setType(EdmOptionsPanel.TEXT);
            } else if (EdmOptionsPanel.IMAGE.equals(btn.getActionCommand())) {
                config.setType(EdmOptionsPanel.IMAGE);
            } else if (EdmOptionsPanel.VIDEO.equals(btn.getActionCommand())) {
                config.setType(EdmOptionsPanel.VIDEO);
            } else if (EdmOptionsPanel.SOUND.equals(btn.getActionCommand())) {
                config.setType(EdmOptionsPanel.SOUND);
            } else {
                config.setType(EdmOptionsPanel.THREE_D);
            }
            found = true;
        }
    }

    config.setUseExistingDaoRole(false);
    if (useExistingDaoRoleCheckbox.isSelected()) {
        config.setUseExistingDaoRole(true);
    }

    config.setInheritElementsFromFileLevel(false);
    enumeration = inheritParentGroup.getElements();
    while (enumeration.hasMoreElements()) {
        AbstractButton btn = enumeration.nextElement();
        if (FULL.equals(conversionMode) && inheritParentCheckbox.isSelected() && btn.isSelected()
                && btn.getActionCommand().equals(YES)) {
            config.setInheritElementsFromFileLevel(true);
        }
    }

    config.setInheritOrigination(false);
    enumeration = inheritOriginationGroup.getElements();
    while (enumeration.hasMoreElements()) {
        AbstractButton btn = enumeration.nextElement();
        if (FULL.equals(conversionMode) && inheritOriginationCheckbox.isSelected() && btn.isSelected()
                && btn.getActionCommand().equals(YES)) {
            config.setInheritOrigination(true);
        }
    }

    config.setInheritLanguage(true);
    if (this.batch) {
        if (!useExistingLanguageCheckbox.isSelected()) {
            config.setInheritLanguage(false);
        }
        StringBuilder result = new StringBuilder();
        Object[] languageValues = languageList.getSelectedValues();
        for (int i = 0; i < languageValues.length; i++) {
            result.append(languages.get(languageValues[i].toString()));
            if (languageValues.length > 0 && i < (languageValues.length - 1)) {
                result.append(" ");
            }
        }
        config.setLanguage(result.toString());
    } else {
        enumeration = inheritLanguageGroup.getElements();
        while (enumeration.hasMoreElements()) {
            AbstractButton btn = enumeration.nextElement();
            if (/*inheritLanguageCheckbox.isSelected() &&*/btn.isSelected()) {
                if (btn.getActionCommand().equals(NO)) {
                    config.setInheritLanguage(false);
                } else if (btn.getActionCommand().equals(PROVIDE)) {
                    if (!useExistingLanguageCheckbox.isSelected()) {
                        config.setInheritLanguage(false);
                    }
                    StringBuilder result = new StringBuilder();
                    Object[] languageValues = languageList.getSelectedValues();
                    for (int i = 0; i < languageValues.length; i++) {
                        result.append(languages.get(languageValues[i].toString()));
                        if (languageValues.length > 0 && i < (languageValues.length - 1)) {
                            result.append(" ");
                        }
                    }
                    config.setLanguage(result.toString());
                }
            }
        }
    }
    if (useExistingLanguageCheckbox.isSelected()) {
        config.setUseExistingLanguage(true);
    }

    //        config.setInheritRightsInfo(false);
    //        if (this.batch) {
    config.setInheritRightsInfo(true);
    Enumeration<AbstractButton> licenseEnumeration = licenseGroup.getElements();
    while (licenseEnumeration.hasMoreElements()) {
        AbstractButton btn = licenseEnumeration.nextElement();
        if (btn.isSelected()) {
            config.setRights(getCorrectRights(btn.getActionCommand()));
        }
    }
    //        } else {
    //            enumeration = inheritLicenseGroup.getElements();
    //            while (enumeration.hasMoreElements()) {
    //                AbstractButton btn = enumeration.nextElement();
    //                if (/*inheritLanguageCheckbox.isSelected() &&*/btn.isSelected()) {
    //                    if (btn.getActionCommand().equals(YES)) {
    //                        config.setInheritRightsInfo(true);
    //                    } else {
    //                        Enumeration<AbstractButton> licenseEnumeration = licenseGroup.getElements();
    //                        while (licenseEnumeration.hasMoreElements()) {
    //                            AbstractButton licenseBtn = licenseEnumeration.nextElement();
    //                            if (licenseBtn.isSelected()) {
    //                                config.setRights(getCorrectRights(licenseBtn.getActionCommand()));
    //                            }
    //                        }
    //                    }
    //                }
    //            }
    //        }
    if (useExistingRightsInfoCheckbox.isSelected()) {
        config.setUseExistingRightsInfo(true);
    } else {
        config.setUseExistingRightsInfo(false);
    }

    if (additionalRightsTextArea != null && StringUtils.isNotEmpty(additionalRightsTextArea.getText())) {
        config.setRightsAdditionalInformation(additionalRightsTextArea.getText());
    }

    if (MINIMAL.equals(conversionMode)) {
        config.setMinimalConversion(true);
    } else {
        config.setMinimalConversion(false);
    }

    if (ARCHDESC_UNITTITLE.equals(sourceOfFondsTitle)) {
        config.setUseArchUnittitle(true);
    } else {
        config.setUseArchUnittitle(false);
    }

    //EDM identifier used for OAI-PMH; not needed for DPT purposes, so set to empty string
    config.setEdmIdentifier("");

    //prefixUrl, repositoryCode and xmlTypeName used for EDM element id generation;
    //repositoryCode is taken from the tool while the other two have fixed values.
    config.setHost("www.archivesportaleurope.net");
    config.setRepositoryCode(dataPreparationToolGUI.getRepositoryCodeIdentifier());
    config.setXmlTypeName("fa");

    return config;
}

From source file:net.sourceforge.pmd.util.designer.Designer.java

private void loadSettings() {
    File file = new File(SETTINGS_FILE_NAME);
    if (file.exists()) {
        try (InputStream stream = Files.newInputStream(file.toPath())) {
            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document document = builder.parse(stream);
            Element settingsElement = document.getDocumentElement();
            Element codeElement = (Element) settingsElement.getElementsByTagName("code").item(0);
            Element xpathElement = (Element) settingsElement.getElementsByTagName("xpath").item(0);

            String code = getTextContext(codeElement);
            String languageVersion = codeElement.getAttribute("language-version");
            String xpath = getTextContext(xpathElement);
            String xpathVersion = xpathElement.getAttribute("version");

            codeEditorPane.setText(code);
            setLanguageVersion(LanguageRegistry.findLanguageVersionByTerseName(languageVersion));
            xpathQueryArea.setText(xpath);
            for (Enumeration<AbstractButton> e = xpathVersionButtonGroup.getElements(); e.hasMoreElements();) {
                AbstractButton button = e.nextElement();
                if (xpathVersion.equals(button.getActionCommand())) {
                    button.setSelected(true);
                    break;
                }//ww w.j  a  v a  2  s.  c o m
            }
        } catch (ParserConfigurationException | IOException | SAXException e) {
            e.printStackTrace();
        }
    }
}