List of usage examples for javax.swing AbstractButton addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:Main.java
/** * select silently//w ww. j av a2s . c o m * @param aButton button * @param isSelected indicates if button should be selected * @param aListener listener to be removed when selecting index */ public final static void SelectSilently(AbstractButton aButton, boolean isSelected, ActionListener aListener) { aButton.removeActionListener(aListener); aButton.setSelected(isSelected); aButton.addActionListener(aListener); }
From source file:Main.java
public static void addActionListener(final AbstractButton abstractButton, final ActionListener actionListener) { if (abstractButton != null && actionListener != null) { runInEDT(() -> abstractButton.addActionListener(actionListener)); }// ww w .j a v a 2 s.c om }
From source file:com.moneydance.modules.features.importlist.table.AbstractEditor.java
@Override public final Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) { if (value != null) { this.label = value.toString(); }/*from w w w.j a va 2 s . c o m*/ AbstractButton button = this.buttonRenderer.getTableCellRendererButton(value, row); ActionListener actionListener = this.getActionListener(table.convertRowIndexToModel(row)); button.addActionListener(actionListener); return button; }
From source file:org.esa.snap.timeseries.ui.graph.TimeSeriesGraphForm.java
private JPanel createButtonPanel(final String helpID) { showTimeSeriesForSelectedPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/SelectedPinSpectra24.gif"), true); showTimeSeriesForSelectedPinsButton.addActionListener(e -> { if (graphModel.isShowingAllPins()) { showTimeSeriesForAllPinsButton.setSelected(false); graphModel.setIsShowingAllPins(false); }/*from w w w.j ava 2 s . com*/ graphModel.setIsShowingSelectedPins(showTimeSeriesForSelectedPinsButton.isSelected()); }); showTimeSeriesForSelectedPinsButton.setName("showTimeSeriesForSelectedPinsButton"); showTimeSeriesForSelectedPinsButton.setToolTipText("Show time series for selected pin"); ////////////////////////////////////////// showTimeSeriesForAllPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/PinSpectra24.gif"), true); showTimeSeriesForAllPinsButton.addActionListener(e -> { if (graphModel.isShowingSelectedPins()) { showTimeSeriesForSelectedPinsButton.setSelected(false); graphModel.setIsShowingSelectedPins(false); } graphModel.setIsShowingAllPins(showTimeSeriesForAllPinsButton.isSelected()); }); showTimeSeriesForAllPinsButton.setName("showTimeSeriesForAllPinsButton"); showTimeSeriesForAllPinsButton.setToolTipText("Show time series for all pins"); ////////////////////////////////////////// showCursorTimeSeriesButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/CursorSpectrum24.gif"), true); showCursorTimeSeriesButton.addActionListener( e -> graphModel.setIsShowingCursorTimeSeries(showCursorTimeSeriesButton.isSelected())); showCursorTimeSeriesButton.setToolTipText("Show time series for cursor"); showCursorTimeSeriesButton.setSelected(true); ////////////////////////////////////////// exportTimeSeriesButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false); exportTimeSeriesButton.addActionListener(e -> { final ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView(); JOptionPane.showMessageDialog(view, "Not available in the current version.", "Export data", JOptionPane.INFORMATION_MESSAGE); //@todo se remove message dialog and fix export that only the visible graph data will be exported // if (view != null // && view.getProduct() != null // && view.getProduct().getProductType().equals(AbstractTimeSeries.TIME_SERIES_PRODUCT_TYPE) // && TimeSeriesMapper.getInstance().getTimeSeries(view.getProduct()) != null) { // // AbstractTimeSeries timeSeries = TimeSeriesMapper.getInstance().getTimeSeries(view.getProduct()); // ExportTimeBasedText.export(mainPanel, timeSeries, helpID); // } }); exportTimeSeriesButton.setToolTipText("Export raster data time series of all pins"); exportTimeSeriesButton.setName("exportTimeSeriesButton"); final ProductSceneView sceneView = SnapApp.getDefault().getSelectedProductSceneView(); if (sceneView != null) { exportTimeSeriesButton.setEnabled(sceneView.getProduct().getPinGroup().getNodeCount() > 0); } else { exportTimeSeriesButton.setEnabled(false); } AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"), false); helpButton.addActionListener(e -> new HelpCtx(helpID).display()); helpButton.setToolTipText("Help"); final TableLayout tableLayout = new TableLayout(1); tableLayout.setTablePadding(4, 4); tableLayout.setTableAnchor(TableLayout.Anchor.NORTHWEST); tableLayout.setTableFill(TableLayout.Fill.HORIZONTAL); tableLayout.setTableWeightX(1.0); tableLayout.setTableWeightY(0.0); JPanel buttonPanel = new JPanel(tableLayout); buttonPanel.add(showTimeSeriesForSelectedPinsButton); buttonPanel.add(showTimeSeriesForAllPinsButton); buttonPanel.add(showCursorTimeSeriesButton); buttonPanel.add(exportTimeSeriesButton); buttonPanel.add(tableLayout.createVerticalSpacer()); buttonPanel.add(helpButton); return buttonPanel; }
From source file:org.esa.snap.rcp.statistics.ChartPagePanel.java
private JPanel createChartBottomPanel(final ChartPanel chartPanel) { final AbstractButton zoomAllButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/view-fullscreen.png"), false); zoomAllButton.setToolTipText("Zoom all."); zoomAllButton.setName("zoomAllButton."); zoomAllButton.addActionListener(e -> { chartPanel.restoreAutoBounds();/*from w w w . ja va 2 s .c o m*/ chartPanel.repaint(); }); final AbstractButton propertiesButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Edit24.gif"), false); propertiesButton.setToolTipText("Edit properties."); propertiesButton.setName("propertiesButton."); propertiesButton.addActionListener(e -> chartPanel.doEditChartProperties()); final AbstractButton saveButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false); saveButton.setToolTipText("Save chart as image."); saveButton.setName("saveButton."); saveButton.addActionListener(e -> { try { chartPanel.doSaveAs(); } catch (IOException e1) { JOptionPane.showMessageDialog(chartPanel, "Could not save chart:\n" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } }); final AbstractButton printButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Print24.gif"), false); printButton.setToolTipText("Print chart."); printButton.setName("printButton."); printButton.addActionListener(e -> chartPanel.createChartPrintJob()); final TableLayout tableLayout = new TableLayout(6); tableLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL); tableLayout.setColumnWeightX(4, 1.0); JPanel buttonPanel = new JPanel(tableLayout); tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0)); buttonPanel.add(zoomAllButton); tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0)); buttonPanel.add(propertiesButton); buttonPanel.add(saveButton); buttonPanel.add(printButton); buttonPanel.add(new JPanel()); buttonPanel.add(getHelpButton()); return buttonPanel; }
From source file:org.esa.snap.rcp.statistics.ChartPagePanel.java
private JPanel createTopPanel() { refreshButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/ViewRefresh22.png"), false); refreshButton.setToolTipText("Refresh View"); refreshButton.setName("refreshButton"); refreshButton.addActionListener(e -> { updateChartData();/*from w w w .ja v a 2s . c o m*/ refreshButton.setEnabled(false); }); AbstractButton switchToTableButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Table24.png"), false); switchToTableButton.setToolTipText("Switch to Table View"); switchToTableButton.setName("switchToTableButton"); switchToTableButton.setEnabled(hasAlternativeView()); switchToTableButton.addActionListener(e -> showAlternativeView()); final TableLayout tableLayout = new TableLayout(6); tableLayout.setColumnFill(2, TableLayout.Fill.HORIZONTAL); tableLayout.setColumnWeightX(2, 1.0); tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0)); JPanel buttonPanel = new JPanel(tableLayout); buttonPanel.add(refreshButton); tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0)); buttonPanel.add(switchToTableButton); buttonPanel.add(new JPanel()); return buttonPanel; }
From source file:org.esa.beam.visat.toolviews.stat.ChartPagePanel.java
private JPanel createChartBottomPanel(final ChartPanel chartPanel) { final AbstractButton zoomAllButton = ToolButtonFactory.createButton( UIUtils.loadImageIcon("/com/bc/ceres/swing/actions/icons_22x22/view-fullscreen.png"), false); zoomAllButton.setToolTipText("Zoom all."); zoomAllButton.setName("zoomAllButton."); zoomAllButton.addActionListener(new ActionListener() { @Override//from ww w . ja v a 2 s . co m public void actionPerformed(ActionEvent e) { chartPanel.restoreAutoBounds(); chartPanel.repaint(); } }); final AbstractButton propertiesButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Edit24.gif"), false); propertiesButton.setToolTipText("Edit properties."); propertiesButton.setName("propertiesButton."); propertiesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { chartPanel.doEditChartProperties(); } }); final AbstractButton saveButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false); saveButton.setToolTipText("Save chart as image."); saveButton.setName("saveButton."); saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { chartPanel.doSaveAs(); } catch (IOException e1) { JOptionPane.showMessageDialog(chartPanel, "Could not save chart:\n" + e1.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } }); final AbstractButton printButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Print24.gif"), false); printButton.setToolTipText("Print chart."); printButton.setName("printButton."); printButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { chartPanel.createChartPrintJob(); } }); final TableLayout tableLayout = new TableLayout(6); tableLayout.setColumnFill(4, TableLayout.Fill.HORIZONTAL); tableLayout.setColumnWeightX(4, 1.0); JPanel buttonPanel = new JPanel(tableLayout); tableLayout.setRowPadding(0, new Insets(0, 4, 0, 0)); buttonPanel.add(zoomAllButton); tableLayout.setRowPadding(0, new Insets(0, 0, 0, 0)); buttonPanel.add(propertiesButton); buttonPanel.add(saveButton); buttonPanel.add(printButton); buttonPanel.add(new JPanel()); buttonPanel.add(getHelpButton()); return buttonPanel; }
From source file:de.unibayreuth.bayeos.goat.panels.timeseries.JPanelChart.java
protected void prepareButton(AbstractButton button, String actionKey, String iconResource, String toolTipText) { button.setActionCommand(actionKey);/*from w ww. j a v a 2 s .com*/ button.setToolTipText(toolTipText); button.addActionListener(this); try { button.setIcon(ImageFactory.getIcon(iconResource)); } catch (ImageFactoryException i) { MsgBox.error(i.getMessage()); } }
From source file:net.pms.newgui.LooksFrame.java
public JComponent buildContent() { JPanel panel = new JPanel(new BorderLayout()); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false);//w w w . j a va 2 s. com toolBar.setRollover(true); toolBar.add(new JPanel()); if (PMS.getConfiguration().useWebInterface()) { webinterface = createToolBarButton(Messages.getString("LooksFrame.29"), "button-wif.png"); webinterface.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String error = null; if (PMS.get().getWebInterface() != null && isNotBlank(PMS.get().getWebInterface().getUrl())) { try { URI uri = new URI(PMS.get().getWebInterface().getUrl()); try { Desktop.getDesktop().browse(uri); } catch (RuntimeException | IOException be) { LOGGER.error("Cound not open the default web browser: {}", be.getMessage()); LOGGER.trace("", be); error = Messages.getString("LooksFrame.BrowserError") + "\n" + be.getMessage(); } } catch (URISyntaxException se) { LOGGER.error("Could not form a valid web interface URI from \"{}\": {}", PMS.get().getWebInterface().getUrl(), se.getMessage()); LOGGER.trace("", se); error = Messages.getString("LooksFrame.URIError"); } } else { error = Messages.getString("LooksFrame.URIError"); } if (error != null) { JOptionPane.showMessageDialog(null, error, Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE); } } }); webinterface.setToolTipText(Messages.getString("LooksFrame.30")); webinterface.setEnabled(configuration.useWebInterface()); toolBar.add(webinterface); toolBar.addSeparator(new Dimension(20, 1)); } restartIcon = (AnimatedIcon) reload.getIcon(); restartRequredIcon.start(); setReloadable(false); reload.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { reload.setEnabled(false); PMS.get().reset(); } }); reload.setToolTipText(Messages.getString("LooksFrame.28")); toolBar.add(reload); toolBar.addSeparator(new Dimension(20, 1)); AbstractButton quit = createToolBarButton(Messages.getString("LooksFrame.5"), "button-quit.png"); quit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { quit(); } }); toolBar.add(quit); if (System.getProperty(START_SERVICE) != null) { quit.setEnabled(false); } toolBar.add(new JPanel()); // Apply the orientation to the toolbar and all components in it ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale()); toolBar.applyComponentOrientation(orientation); toolBar.setBorder(new EmptyBorder(new Insets(8, 0, 0, 0))); panel.add(toolBar, BorderLayout.NORTH); panel.add(buildMain(), BorderLayout.CENTER); status = new JLabel(""); status.setBorder(BorderFactory.createEmptyBorder()); status.setComponentOrientation(orientation); // Calling applyComponentOrientation() here would be ideal. // Alas it horribly mutilates the layout of several tabs. //panel.applyComponentOrientation(orientation); panel.add(status, BorderLayout.SOUTH); return panel; }
From source file:apidemo.PanScrollZoomDemo.java
/** * Prepares a button./* w ww . j a v a2 s. com*/ * * @param button the button. * @param actionKey the action key. * @param buttonLabelText the button label. * @param toolTipText the tooltip text. */ private void prepareButton(final AbstractButton button, final String actionKey, final String buttonLabelText, final String toolTipText) { // todo // as this action is empty and the button text is // redefined later, it can be safely removed ... // Action action = new AbstractAction(actionKey) { // public void actionPerformed(ActionEvent evt) { // // ignored // } // }; // button.addActionListener(action); button.setActionCommand(actionKey); button.setText(buttonLabelText); button.setToolTipText(toolTipText); button.addActionListener(this); }