Example usage for javax.swing JButton getActionListeners

List of usage examples for javax.swing JButton getActionListeners

Introduction

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

Prototype

@BeanProperty(bound = false)
public ActionListener[] getActionListeners() 

Source Link

Document

Returns an array of all the ActionListeners added to this AbstractButton with addActionListener().

Usage

From source file:Main.java

public static List<JButton> getListenedButtonsFor(Container c) {
    List<JButton> filter = null;
    List<JButton> result = new ArrayList<JButton>();
    searchFor(c, JButton.class, filter = new ArrayList<JButton>(), null);
    for (JButton button : filter) {
        if (button.getActionListeners().length > 0) {
            result.add(button);/*from w w  w .  j ava2s  . co  m*/
        }
    }
    return result;
}

From source file:com.github.benchdoos.weblocopener.updater.gui.UpdateDialog.java

private void removeAllListeners(JButton button) {
    for (ActionListener al : button.getActionListeners()) {
        button.removeActionListener(al);
    }/*from  w  w w.j  a  va2s.  c o m*/
}

From source file:edu.ku.brc.specify.config.FixAttachments.java

/**
 * @param btn/*from ww w  .  j  a  v a 2s . co  m*/
 * @param url
 */
private void hookupAction(final JButton btn, final URI uri) {
    for (ActionListener al : btn.getActionListeners()) {
        btn.removeActionListener(al);
    }

    if (uri != null) {
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                try {
                    AttachmentUtils.openURI(uri);
                } catch (Exception e) {
                }
            }
        });
    }
}

From source file:edu.ku.brc.af.ui.forms.validation.ValComboBoxFromQuery.java

/**
 * @param button/*from  ww  w .jav a2s  .  c  o m*/
 */
protected void removeAllActionListeners(final JButton button) {
    for (ActionListener al : button.getActionListeners()) {
        button.removeActionListener(al);
    }
}

From source file:edu.ku.brc.specify.datamodel.busrules.CollectionBusRules.java

@Override
public void initialize(Viewable viewableArg) {
    super.initialize(viewableArg);

    JButton newBtn = null;

    if (formViewObj != null) {
        ResultSetController rsc = formViewObj.getRsController();
        if (rsc != null) {
            if (formViewObj.getMVParent().isTopLevel()) {
                if (rsc.getNewRecBtn() != null)
                    rsc.getNewRecBtn().setVisible(false);
                if (rsc.getDelRecBtn() != null)
                    rsc.getDelRecBtn().setVisible(false);
            } else {
                newBtn = rsc.getNewRecBtn();
            }//from  ww  w.ja  va  2s.co  m
        }

        ValCheckBox chkBox = formViewObj.getCompById("6");
        boolean showColEventChkbx = AppPreferences.getLocalPrefs().getBoolean("show.cecheckbox", false);
        chkBox.setVisible(showColEventChkbx);
    }

    if (newBtn != null) {
        // Remove all ActionListeners, there should only be one
        for (ActionListener al : newBtn.getActionListeners()) {
            newBtn.removeActionListener(al);
        }

        newBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                addNewCollection();
            }
        });
    }
}

From source file:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java

public static JComponent getWebsiteDownloadButton(final String title, final String optUrlManualDownloadWebsite,
        final String target_dir_null_ask_user, final String optIntroText, final String[] downloadURLs,
        final String optIntroDialogTitle, final FileDownloadStatusInformationProvider statusProvider,
        final Runnable optFinishSwingTask) {

    final JButton res = new JMButton("Download/Update");
    res.setToolTipText(//from w w  w.j a v  a  2 s. co  m
            "<html>Click button to start automatic download<br><code><b>Check License/Disclaimers first!");
    res.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            final String opt_local_folder;
            if (target_dir_null_ask_user == null) {
                File file = OpenFileDialogService.getDirectoryFromUser("Select folder");
                if (file == null)
                    return;
                else
                    opt_local_folder = file.getAbsolutePath();
            } else {
                opt_local_folder = target_dir_null_ask_user;
            }

            res.setEnabled(false);
            res.setText("Downloading");
            final BackgroundTaskStatusProviderSupportingExternalCallImpl status = new BackgroundTaskStatusProviderSupportingExternalCallImpl(
                    "Please wait...", "Downloading files...");
            BackgroundTaskHelper.issueSimpleTask(title, "Please wait...", new Runnable() {
                public void run() {
                    boolean allOK = true;
                    for (String downloadURL : downloadURLs) {
                        allOK = performDownload(downloadURL, opt_local_folder, status);
                        if (status.wantsToStop()) {
                            break;
                        }
                    }
                    if (status.wantsToStop()) {
                        allOK = true;
                        try {
                            status.setCurrentStatusText1("Cancel...");
                            for (String downloadURL : downloadURLs) {
                                String fileName = downloadURL.substring(downloadURL.lastIndexOf("/") + 1);
                                if (downloadURL.contains("|"))
                                    fileName = downloadURL.substring(downloadURL.lastIndexOf("|") + 1);
                                String targetFileName = ReleaseInfo.getAppFolderWithFinalSep() + fileName;
                                if (new File(targetFileName).exists()) {
                                    new File(targetFileName).delete();
                                    status.setCurrentStatusText2("Delete " + targetFileName);
                                }
                            }
                        } catch (Exception e) {
                            //
                        }
                    }

                    if (!allOK) {
                        res.setEnabled(true);
                        res.setText(
                                "<html><small>Automatic download failure<br>Click here for manual download");
                        res.removeActionListener(res.getActionListeners()[0]);
                        res.addActionListener(getDialogAction(optUrlManualDownloadWebsite, opt_local_folder,
                                optIntroText, optIntroDialogTitle));
                        res.requestFocus();
                        final JDialog jd = (JDialog) ErrorMsg.findParentComponent(res, JDialog.class);
                        if (jd != null) {
                            SwingUtilities.invokeLater(new Runnable() {
                                public void run() {
                                    jd.pack();
                                }
                            });
                        }
                    } else {
                        if (status.wantsToStop()) {
                            res.setText("Canceled");
                            status.pleaseContinueRun();
                            status.setCurrentStatusText2("Canceled!");
                        } else {
                            res.setText("Downloaded");
                        }
                        res.setEnabled(false);
                        if (statusProvider != null)
                            statusProvider.finishedNewDownload();
                        if (optFinishSwingTask != null)
                            SwingUtilities.invokeLater(optFinishSwingTask);
                    }
                }
            }, null, status);
        }
    });
    return res;
}

From source file:org.ut.biolab.medsavant.client.variant.VariantWorker.java

/**
 * Initialise functionality shared by all UpdateWorkers and PublicationWorkers.
 *
 * @param activity "Importing", "Publishing", or "Removing"
 * @param wizard the wizard which is providing the user interface
 * @param progressLabel label which indicates progress activity
 * @param progressBar provides quantitative display of progress
 * @param workButton starts the process and cancels it
 *///from  w  ww.j a v a 2s  .  c  o  m
VariantWorker(String activity, WizardDialog wizard, JLabel progressLabel, JProgressBar progressBar,
        JButton workButton) {
    super(activity + "Variants");
    this.activity = activity;
    this.wizard = wizard;
    this.progressLabel = progressLabel;
    this.progressBar = progressBar;
    this.workButton = workButton;

    progressLabel.setText(String.format("%s ...", activity));

    // Convert our start button into a cancel button.
    workButton.setText("Cancel");
    if (workButton.getActionListeners().length > 0) {
        workButton.removeActionListener(workButton.getActionListeners()[0]);
    }
    workButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            VariantWorker.this.progressBar.setIndeterminate(true);
            VariantWorker.this.workButton.setText("Cancelling...");
            VariantWorker.this.workButton.setEnabled(false);
            cancel(true);
        }
    });

    workButton.setEnabled(true);
    wizard.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
}