List of usage examples for javax.swing AbstractButton getActionListeners
@BeanProperty(bound = false)
public ActionListener[] getActionListeners()
ActionListener
s added to this AbstractButton with addActionListener(). 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()); }/*from ww w. j a v a 2s . com*/ }); ActionListener[] lis = jb.getActionListeners(); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(jb); f.pack(); f.setVisible(true); }
From source file:Main.java
public static void associaTeclaAtalho(final AbstractButton button, String nomeAcao, String... atalhos) { Action action = new AbstractAction(nomeAcao) { @Override/*from ww w .ja va 2 s . c om*/ public void actionPerformed(ActionEvent e) { for (ActionListener listener : button.getActionListeners()) { listener.actionPerformed(e); } } }; associaTeclaAtalho(button, action, nomeAcao, atalhos); }
From source file:Main.java
public static void removeAllActionListeners(final AbstractButton abstractButton) { if (abstractButton != null) { runInEDT(() -> {// w ww .j av a2 s . com for (final ActionListener actionListener : abstractButton.getActionListeners()) { abstractButton.removeActionListener(actionListener); } }); } }
From source file:org.datacleaner.windows.ResultWindow.java
/** * * @param configuration//from ww w .java2s. c o m * @param job * either this or result must be available * @param result * either this or job must be available * @param jobFilename * @param windowContext * @param userPreferences * @param rendererFactory */ @Inject protected ResultWindow(DataCleanerConfiguration configuration, @Nullable AnalysisJob job, @Nullable AnalysisResult result, @Nullable @JobFile FileObject jobFilename, WindowContext windowContext, UserPreferences userPreferences, RendererFactory rendererFactory) { super(windowContext); final boolean running = (result == null); _resultPanels = new IdentityHashMap<>(); _configuration = configuration; _job = job; _jobFilename = jobFilename; _userPreferences = userPreferences; _rendererFactory = rendererFactory; final Ref<AnalysisResult> resultRef = new Ref<AnalysisResult>() { @Override public AnalysisResult get() { return getResult(); } }; Border buttonBorder = new CompoundBorder(WidgetUtils.BORDER_LIST_ITEM_SUBTLE, new EmptyBorder(10, 4, 10, 4)); _cancelButton = WidgetFactory.createDefaultButton("Cancel job", IconUtils.ACTION_STOP); _cancelButton.setHorizontalAlignment(SwingConstants.LEFT); _cancelButton.setBorder(buttonBorder); _saveResultsPopupButton = WidgetFactory.createDefaultPopupButton("Save results", IconUtils.ACTION_SAVE_DARK); _saveResultsPopupButton.setHorizontalAlignment(SwingConstants.LEFT); _saveResultsPopupButton.setBorder(buttonBorder); _saveResultsPopupButton.setMenuPosition(MenuPosition.TOP); _saveResultsPopupButton.getMenu().setBorder(new MatteBorder(1, 0, 0, 1, WidgetUtils.BG_COLOR_MEDIUM)); JMenuItem saveAsFileItem = WidgetFactory.createMenuItem("Save as result file", IconUtils.ACTION_SAVE_DARK); saveAsFileItem.addActionListener(new SaveAnalysisResultActionListener(resultRef, _userPreferences)); saveAsFileItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(saveAsFileItem); JMenuItem exportToHtmlItem = WidgetFactory.createMenuItem("Export to HTML", IconUtils.WEBSITE); exportToHtmlItem.addActionListener( new ExportResultToHtmlActionListener(resultRef, _configuration, _userPreferences)); exportToHtmlItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(exportToHtmlItem); JMenuItem publishToServerItem = WidgetFactory.createMenuItem("Publish to server", IconUtils.MENU_DQ_MONITOR); publishToServerItem.addActionListener(new PublishResultToMonitorActionListener(getWindowContext(), _userPreferences, resultRef, _jobFilename)); publishToServerItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(publishToServerItem); _tabbedPane = new VerticalTabbedPane() { private static final long serialVersionUID = 1L; @Override protected JComponent wrapInCollapsiblePane(final JComponent originalPanel) { DCPanel buttonPanel = new DCPanel(); buttonPanel.setLayout(new VerticalLayout()); buttonPanel.setBorder(new MatteBorder(1, 0, 0, 0, WidgetUtils.BG_COLOR_MEDIUM)); buttonPanel.add(_saveResultsPopupButton); buttonPanel.add(_cancelButton); DCPanel wrappedPanel = new DCPanel(); wrappedPanel.setLayout(new BorderLayout()); wrappedPanel.add(originalPanel, BorderLayout.CENTER); wrappedPanel.add(buttonPanel, BorderLayout.SOUTH); return super.wrapInCollapsiblePane(wrappedPanel); } }; final Dimension size = getDefaultWindowSize(); _windowSizePreference = new WindowSizePreferences(_userPreferences, getClass(), size.width, size.height); _progressInformationPanel = new ProgressInformationPanel(running); _tabbedPane.addTab("Progress information", imageManager.getImageIcon("images/model/progress_information.png", IconUtils.ICON_SIZE_TAB), _progressInformationPanel); for (Func<ResultWindow, JComponent> pluggableComponent : PLUGGABLE_BANNER_COMPONENTS) { JComponent component = pluggableComponent.eval(this); if (component != null) { if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; JMenuItem menuItem = WidgetFactory.createMenuItem(button.getText(), button.getIcon()); for (ActionListener listener : button.getActionListeners()) { menuItem.addActionListener(listener); } menuItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(menuItem); } else if (component instanceof JMenuItem) { // TODO: Not possible. JMenuItem is a subclass of AbstractButton. Reorder or remove? JMenuItem menuItem = (JMenuItem) component; menuItem.setBorder(buttonBorder); _saveResultsPopupButton.getMenu().add(menuItem); } } } if (running) { // run the job in a swing worker _result = null; _worker = new AnalysisRunnerSwingWorker(_configuration, _job, this); _cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { _worker.cancelIfRunning(); } }); } else { // don't add the progress information, simply render the job asap _result = result; _worker = null; final Map<ComponentJob, AnalyzerResult> map = result.getResultMap(); for (Entry<ComponentJob, AnalyzerResult> entry : map.entrySet()) { final ComponentJob componentJob = entry.getKey(); final AnalyzerResult analyzerResult = entry.getValue(); addResult(componentJob, analyzerResult); } _progressInformationPanel.onSuccess(); WidgetUtils.invokeSwingAction(new Runnable() { @Override public void run() { if (_tabbedPane.getTabCount() > 1) { // switch to the first available result panel _tabbedPane.setSelectedIndex(1); } } }); } updateButtonVisibility(running); }