List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name, Icon icon)
From source file:feedsplugin.FeedsPlugin.java
private ActionMenu getContextMenuAction(final ArrayList<SyndEntryWithParent> matches) { if (matches.isEmpty()) { return null; }/*from w w w . j a v a2 s .c o m*/ final ArrayList<SyndEntry> entries = new ArrayList<SyndEntry>(matches.size()); for (SyndEntryWithParent match : matches) { entries.add(match.getEntry()); } AbstractAction action = new AbstractAction(mLocalizer.msg("contextMenu", "Feeds {0}", matches.size()), getPluginIcon()) { public void actionPerformed(final ActionEvent e) { showFeedsDialog(new FeedsDialog(getParentFrame(), entries)); } }; return new ActionMenu(action); }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * Returns the 'Add child' action./*w w w . j a v a 2 s . c o m*/ * * @return the action */ @SuppressWarnings("serial") private Action getAddChildAction() { if (addChildAction == null) { String actionCommand = bundle.getString(ADD_CHILD_NODE_KEY); String actionKey = bundle.getString(ADD_CHILD_NODE_KEY + ".action"); addChildAction = new AbstractAction(actionCommand, Icons.ADD) { @Override public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed(): action = " + e.getActionCommand()); if (checkAction()) { model.addNode(StringUtils.removeEnd(nodes[0].getPath(), "/") + "/" + childName, childText.getBytes()); } childName = childText = ""; } private boolean checkAction() { JDialog dlg = createAddChildDialog(); dlg.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); dlg.setSize(800, 600); dlg.setLocationRelativeTo(null); dlg.setVisible(true); boolean nameIsEmpty = childName == null || childName.isEmpty(); boolean dataIsEmpty = childText == null; return !nameIsEmpty && !dataIsEmpty; } }; addChildAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); } return this.addChildAction; }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * //www .j a v a2 s . c o m * @return */ public Action getClearLogOutputAction() { Action ret = actionMap.get(ACTION_CLEAR_LOG); if (ret == null) { ret = new AbstractAction(ACTION_CLEAR_LOG, getIcon("bin_closed.png", IconSize.SMALL)) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent event) { try { debuggerFrame.getLoggerTA().setText(""); debuggerFrame.getLoggerTA().setCaretPosition(0); } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; actionMap.put(ACTION_CLEAR_LOG, ret); } return ret; }
From source file:org.geopublishing.atlasViewer.swing.AtlasChartJDialog.java
/** * Adds a Button to the ToolBar of the {@link AtlasChartJPanel}, that zoom * the chart to full extends. has to be done in the * {@link AtlasChartJDialog}, because {@link AtlasChartJPanel} doesn't know * about the {@link ChartStyle}.// w w w . j a va 2 s. c om * * @return */ public static JButton createZoomToFullChartExtentButton(final AtlasChartJPanel chartPanel, final ChartStyle chartStyle) { /** * Add an Action to SET the selection. */ JButton resetZoomTool = new SmallButton(new AbstractAction("", AtlasChartJPanel.ICON_FULL_EXTEND) { @Override public void actionPerformed(ActionEvent e) { if (chartStyle.getPlotStyle() != null) { JFreeChartUtil.zoomPlotToFullExtend(chartPanel.getChart().getPlot(), null, chartStyle.getPlotStyle().isCenterOriginSymetrically()); } else { JFreeChartUtil.zoomPlotToFullExtend(chartPanel.getChart().getPlot(), null, false); } } }, GpCoreUtil.R("AtlasChartJPanel.zoomFullExtent.tt")); return resetZoomTool; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * Returns the 'Update' action.//from w w w . j ava 2s . c o m * * @return the action */ @SuppressWarnings("serial") private Action getUpdateAction() { if (updateAction == null) { String actionCommand = bundle.getString(UPDATE_NODE_KEY); String actionKey = bundle.getString(UPDATE_NODE_KEY + ".action"); updateAction = new AbstractAction(actionCommand, Icons.UPDATE) { @Override public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed(): action = " + e.getActionCommand()); if (checkAction()) { model.updateData(nodes[0].getPath(), taUpdate.getText().getBytes(getCharset())); } } private boolean checkAction() { // No node or several nodes selected if (nodes == null || nodes.length > 1) { return false; } // No parent if (nodes == null || nodes.length != 1) { JOptionPane.showMessageDialog(JZVNodePanel.this, bundle.getString("dlg.error.updateWithoutParent"), bundle.getString("dlg.error.title"), JOptionPane.ERROR_MESSAGE); return false; } return (JOptionPane.showConfirmDialog(JZVNodePanel.this, bundle.getString("dlg.confirm.update")) == JOptionPane.YES_OPTION); } }; updateAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); } return updateAction; }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java
private Component createImportButton() { JButton b = new JButton(new AbstractAction(null, UIAgent.getInstance().getIcon(UIAgent.ICON_IMPORT_24)) { private static final long serialVersionUID = 985413615438877711L; @Override/* ww w .ja v a 2 s. c o m*/ public void actionPerformed(ActionEvent e) { JFileChooser ch = new JFileChooser(); ch.setFileFilter(new ExtensionFilter("xls", "Excel File")); int i = ch.showOpenDialog(null); if (i == JFileChooser.APPROVE_OPTION) { DiveProfileExcelParser p = new DiveProfileExcelParser(); try { File f = ch.getSelectedFile(); DiveProfile dp = p.read(f); I18nResourceManager i18n = I18nResourceManager.sharedInstance(); int yes = JOptionPane.showConfirmDialog(DiveProfileGraphicDetailPanel.this, i18n.getString("overwritte.diveprofile.confirm"), i18n.getString("confirmation"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (yes == JOptionPane.YES_OPTION) { currentDive.setDiveProfile(dp); setDiveProfile(dp, currentDive); logBookManagerFacade.setDiveChanged(currentDive); } } catch (IOException e1) { ExceptionDialog.showDialog(e1, DiveProfileGraphicDetailPanel.this); LOGGER.error(e1.getMessage()); } } } }); b.setToolTipText("Import"); return b; }
From source file:com.intuit.tank.tools.debugger.ActionProducer.java
/** * //from w w w . j a v a 2s .c o m * @return */ public Action getFindAction() { Action ret = actionMap.get(ACTION_FIND); if (ret == null) { ret = new AbstractAction(ACTION_FIND, getIcon("find.png", IconSize.SMALL)) { private static final long serialVersionUID = 1L; private FindReplaceDialog dialog; @Override public void actionPerformed(ActionEvent event) { try { if (dialog == null) { dialog = new FindReplaceDialog(debuggerFrame, DialogType.SEARCH); } dialog.setVisible(true); } catch (HeadlessException e) { showError("Error opening file: " + e); } } }; ret.putValue(Action.SHORT_DESCRIPTION, "Find in script."); ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('F', menuActionMods)); ret.putValue(Action.MNEMONIC_KEY, new Integer('F')); ret.setEnabled(false); actionMap.put(ACTION_FIND, ret); } return ret; }
From source file:org.photovault.swingui.BrowserWindow.java
protected void createUI(PhotoCollection collection) { window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); tabPane = new JTabbedPane(); queryPane = new QueryPane(); PhotoFolderTreeController treeCtrl = new PhotoFolderTreeController(window, this); viewCtrl = new PhotoViewController(window, this); treePane = treeCtrl.folderTree;/*from ww w . ja v a 2s .c om*/ viewPane = viewCtrl.getThumbPane(); previewPane = viewCtrl.getPreviewPane(); tabPane.addTab("Query", queryPane); tabPane.addTab("Folders", treePane); VolumeTreeController volTreeCtrl = new VolumeTreeController(this); JTree volumeTree = volTreeCtrl.getView(); JScrollPane voltreeScrollPane = new JScrollPane(volumeTree); voltreeScrollPane.setPreferredSize(new Dimension(200, 500)); tabPane.add("Volumes", voltreeScrollPane); // TODO: get rid of this!!!! EditSelectionColorsAction colorAction = (EditSelectionColorsAction) viewPane.getEditSelectionColorsAction(); colorAction.setPreviewCtrl(previewPane); // Set listeners to both query and folder tree panes /* If an actionEvent comes from query pane, swich to query results. */ queryPane.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { viewCtrl.setCollection(queryPane.getResultCollection()); } }); /* If the selected folder is changed in treePane, switch to that immediately */ treeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() { public void handleEvent(DefaultEvent<PhotoCollection> event) { PhotoCollection c = event.getPayload(); if (c != null) { viewCtrl.setCollection(c); if (c instanceof PhotoFolder) { PhotoFolder f = (PhotoFolder) c; if (f.getExternalDir() != null) { ExternalDir ed = f.getExternalDir(); folderIndexer.updateDir(ed.getVolume(), ed.getPath()); viewCtrl.setIndexingOngoing(true); } } } } }); volTreeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() { public void handleEvent(DefaultEvent<PhotoCollection> event) { PhotoCollection c = event.getPayload(); if (c != null) { viewCtrl.setCollection(c); if (c instanceof ExtDirPhotos) { ExtDirPhotos photos = (ExtDirPhotos) c; ExternalVolume vol = (ExternalVolume) viewCtrl.getDAOFactory().getVolumeDAO() .getVolume(photos.getVolId()); folderIndexer.updateDir(vol, photos.getDirPath()); viewCtrl.setIndexingOngoing(true); } } } }); collectionPane = viewCtrl.getCollectionPane(); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tabPane, collectionPane); split.putClientProperty(JSplitPane.ONE_TOUCH_EXPANDABLE_PROPERTY, new Boolean(true)); Container cp = window.getContentPane(); cp.setLayout(new BorderLayout()); cp.add(split, BorderLayout.CENTER); statusBar = new StatusBar(); cp.add(statusBar, BorderLayout.SOUTH); // Create actions for BrowserWindow UI ImageIcon indexDirIcon = getIcon("index_dir.png"); DefaultAction indexDirAction = new DefaultAction("Index directory...", indexDirIcon) { public void actionPerformed(ActionEvent e) { indexDir(); } }; indexDirAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_D); indexDirAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Index all images in a directory"); this.registerAction("new_ext_vol", indexDirAction); ImageIcon importIcon = getIcon("import.png"); importAction = new AbstractAction("Import image...", importIcon) { public void actionPerformed(ActionEvent e) { importFile(); } }; importAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O); importAction.putValue(AbstractAction.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); importAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Import new image into database"); ImageIcon updateIcon = getIcon("update_indexed_dirs.png"); UpdateIndexAction updateIndexAction = new UpdateIndexAction(viewCtrl, "Update indexed dirs", updateIcon, "Check for changes in previously indexed directories", KeyEvent.VK_U); this.registerAction("update_indexed_dirs", updateIndexAction); updateIndexAction.addStatusChangeListener(statusBar); ImageIcon previewTopIcon = getIcon("view_preview_top.png"); DefaultAction previewTopAction = new DefaultAction("Preview on top", previewTopIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_HORIZONTAL_THUMBS); } }; previewTopAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on top of thumbnails"); previewTopAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_T); this.registerAction("view_preview_top", previewTopAction); ImageIcon previewRightIcon = getIcon("view_preview_right.png"); DefaultAction previewRightAction = new DefaultAction("Preview on right", previewRightIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_VERTICAL_THUMBS); } }; previewRightAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on right of thumbnails"); previewRightAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_R); this.registerAction("view_preview_right", previewRightAction); ImageIcon previewNoneIcon = getIcon("view_no_preview.png"); DefaultAction previewNoneAction = new DefaultAction("No preview", previewNoneIcon) { public void actionPerformed(ActionEvent e) { viewCtrl.setLayout(PhotoViewController.Layout.ONLY_THUMBS); } }; previewNoneAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show no preview image"); previewNoneAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O); this.registerAction("view_no_preview", previewNoneAction); DefaultAction previewLargeAction = new DefaultAction("Large", null) { public void actionPerformed(ActionEvent e) { viewCtrl.setPreviewSize(200); } }; DefaultAction previewSmallAction = new DefaultAction("Small", null) { public void actionPerformed(ActionEvent e) { viewCtrl.setPreviewSize(100); } }; JToolBar tb = createToolbar(); cp.add(tb, BorderLayout.NORTH); // Create the menu bar & menus JMenuBar menuBar = new JMenuBar(); window.setJMenuBar(menuBar); // File menu JMenu fileMenu = new JMenu("File"); fileMenu.setMnemonic(KeyEvent.VK_F); menuBar.add(fileMenu); JMenuItem newWindowItem = new JMenuItem("New window", KeyEvent.VK_N); newWindowItem.setIcon(getIcon("window_new.png")); newWindowItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { BrowserWindow br = new BrowserWindow(getParentController(), null); // br.setVisible( true ); } }); fileMenu.add(newWindowItem); JMenuItem importItem = new JMenuItem(importAction); fileMenu.add(importItem); JMenuItem indexDirItem = new JMenuItem(indexDirAction); fileMenu.add(indexDirItem); fileMenu.add(new JMenuItem(viewCtrl.getActionAdapter("update_indexed_dirs"))); ExportSelectedAction exportAction = (ExportSelectedAction) viewPane.getExportSelectedAction(); JMenuItem exportItem = new JMenuItem(exportAction); exportAction.addStatusChangeListener(statusBar); fileMenu.add(exportItem); JMenu dbMenu = new JMenu("Database"); dbMenu.setMnemonic(KeyEvent.VK_B); dbMenu.setIcon(getIcon("empty_icon.png")); ExportMetadataAction exportMetadata = new ExportMetadataAction("Export as XML...", null, "Export whole database as XML file", KeyEvent.VK_E); dbMenu.add(new JMenuItem(exportMetadata)); ImportXMLAction importMetadata = new ImportXMLAction("Import XML data...", null, "Import data from other Photovault database as XML", KeyEvent.VK_I); importMetadata.addStatusChangeListener(statusBar); dbMenu.add(new JMenuItem(importMetadata)); fileMenu.add(dbMenu); JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_X); exitItem.setIcon(getIcon("exit.png")); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); fileMenu.add(exitItem); JMenu viewMenu = new JMenu("View"); viewMenu.setMnemonic(KeyEvent.VK_V); menuBar.add(viewMenu); JMenuItem vertIconsItem = new JMenuItem(previewRightAction); viewMenu.add(vertIconsItem); JMenuItem horzIconsItem = new JMenuItem(previewTopAction); viewMenu.add(horzIconsItem); JMenuItem noPreviewItem = new JMenuItem(previewNoneAction); viewMenu.add(noPreviewItem); JMenuItem nextPhotoItem = new JMenuItem(viewPane.getSelectNextAction()); viewMenu.add(nextPhotoItem); JMenuItem prevPhotoItem = new JMenuItem(viewPane.getSelectPreviousAction()); viewMenu.add(prevPhotoItem); viewMenu.add(new JMenuItem(previewSmallAction)); viewMenu.add(new JMenuItem(previewLargeAction)); JMenu sortMenu = new JMenu("Sort by"); sortMenu.setMnemonic(KeyEvent.VK_S); sortMenu.setIcon(getIcon("empty_icon.png")); JMenuItem byDateItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingDateComparator(), "Date", null, "Order photos by date", KeyEvent.VK_D)); sortMenu.add(byDateItem); JMenuItem byPlaceItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingPlaceComparator(), "Place", null, "Order photos by shooting place", KeyEvent.VK_P)); sortMenu.add(byPlaceItem); JMenuItem byQualityItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new QualityComparator(), "Quality", null, "Order photos by quality", KeyEvent.VK_Q)); sortMenu.add(byQualityItem); viewMenu.add(sortMenu); // Set default ordering by date byDateItem.getAction().actionPerformed(new ActionEvent(this, 0, "Setting default")); JMenu imageMenu = new JMenu("Image"); imageMenu.setMnemonic(KeyEvent.VK_I); menuBar.add(imageMenu); imageMenu.add(new JMenuItem(viewPane.getEditSelectionPropsAction())); imageMenu.add(new JMenuItem(viewPane.getShowSelectedPhotoAction())); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_cw"))); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_ccw"))); imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_180"))); imageMenu.add(new JMenuItem(previewPane.getCropAction())); imageMenu.add(new JMenuItem(viewPane.getEditSelectionColorsAction())); imageMenu.add(new JMenuItem(viewPane.getDeleteSelectedAction())); // Create the Quality submenu JMenu qualityMenu = new JMenu("Quality"); qualityMenu.setIcon(getIcon("empty_icon.png")); for (int n = 0; n < 6; n++) { Action qualityAction = viewCtrl.getActionAdapter("quality_" + n); JMenuItem qualityMenuItem = new JMenuItem(qualityAction); qualityMenu.add(qualityMenuItem); } imageMenu.add(qualityMenu); JMenu aboutMenu = new JMenu("About"); aboutMenu.setMnemonic(KeyEvent.VK_A); aboutMenu.add(new JMenuItem(new ShowAboutDlgAction("About Photovault...", null, "", null))); menuBar.add(Box.createHorizontalGlue()); menuBar.add(aboutMenu); window.pack(); window.setVisible(true); }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java
private Component createExportButton() { exportButton = new JButton(new AbstractAction(null, UIAgent.getInstance().getIcon(UIAgent.ICON_EXPORT_24)) { private static final long serialVersionUID = 9021437098555924654L; @Override//w w w .ja v a 2 s.c o m public void actionPerformed(ActionEvent e) { JFileChooser ch = new JFileChooser(); ch.setFileFilter(new ExtensionFilter("xls", "Excel File")); int i = ch.showSaveDialog(null); if (i == JFileChooser.APPROVE_OPTION) { DiveProfileExcelParser p = new DiveProfileExcelParser(); try { File f = ch.getSelectedFile(); if (FileUtilities.getExtension(f) == null || !("xls".equals(FileUtilities.getExtension(f)))) { f = new File(f.getAbsoluteFile() + ".xls"); } p.export(currentDive.getDate(), diveProfile, f); } catch (IOException e1) { ExceptionDialog.showDialog(e1, DiveProfileGraphicDetailPanel.this); LOGGER.error(e1.getMessage()); } } } }); exportButton.setToolTipText("Export"); return exportButton; }
From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java
/** * Returns the 'Delete node(s)' action./*from w w w. j a v a 2 s .co m*/ * <p> * The action is created and mapped to the [Delete] key stroke * </p> * * @return the action */ @SuppressWarnings("serial") private Action getDeleteAction() { if (this.deleteAction == null) { String actionCommand = bundle.getString(DELETE_NODE_KEY); String actionKey = bundle.getString(DELETE_NODE_KEY + ".action"); this.deleteAction = new AbstractAction(actionCommand, Icons.DELETE) { @Override public void actionPerformed(ActionEvent e) { System.out.println("actionPerformed(): action = " + e.getActionCommand()); if (checkAction()) { // Checks if several nodes will be deleted if (nodes.length > 1) { model.deleteNodes(nodes); } else { model.deleteNode(nodes[0]); } } } private boolean checkAction() { // No node selected if (nodes == null) { JOptionPane.showMessageDialog(JZVNodePanel.this, bundle.getString("dlg.error.deleteWithoutSelection"), bundle.getString("dlg.error.title"), JOptionPane.ERROR_MESSAGE); return false; } return (JOptionPane.showConfirmDialog(JZVNodePanel.this, bundle.getString("dlg.confirm.update")) == JOptionPane.YES_OPTION); } }; this.deleteAction.putValue(Action.ACTION_COMMAND_KEY, actionKey); this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), actionKey); this.getActionMap().put(actionKey, this.deleteAction); } return this.deleteAction; }