List of usage examples for javax.swing AbstractAction AbstractAction
public AbstractAction(String name)
From source file:org.colombbus.tangara.EditorFrame.java
/** * Returns the paste action//from w w w . j ava 2 s.com * * @return */ public Action getPasteAction() { if (pasteAction == null) { pasteAction = new AbstractAction(Messages.getString("Banner.menu.paste")) { //$NON-NLS-1$ @Override public void actionPerformed(ActionEvent e) { paste(); } }; pasteAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control V")); } return pasteAction; }
From source file:org.colombbus.tangara.EditorFrame.java
/** * Returns the undo action/* www. j av a2 s . co m*/ * * @return */ public Action getUndoAction() { if (undoAction == null) { undoAction = new AbstractAction(Messages.getString("Banner.menu.undo")) { //$NON-NLS-1$ @Override public void actionPerformed(ActionEvent e) { programUndo(); } }; undoAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Z")); } return undoAction; }
From source file:org.colombbus.tangara.EditorFrame.java
/** * Returns the undo action/*from ww w. j a va 2s .c o m*/ * * @return */ public Action getRedoAction() { if (redoAction == null) { redoAction = new AbstractAction(Messages.getString("Banner.menu.redo")) { //$NON-NLS-1$ @Override public void actionPerformed(ActionEvent e) { programRedo(); } }; redoAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control Y")); } return redoAction; }
From source file:net.panthema.BispanningGame.GamePanel.java
AbstractAction getActionNewGraphType() { return new AbstractAction(generateOnlyAtomic ? "Generate Composite or Atomic" : "Generate Only Atomic") { private static final long serialVersionUID = 571719711573657790L; public void actionPerformed(ActionEvent e) { generateOnlyAtomic = !generateOnlyAtomic; }/* w w w . java 2 s . co m*/ }; }
From source file:net.panthema.BispanningGame.GamePanel.java
public void addPopupActions(JPopupMenu popup) { popup.add(new AbstractAction("Center Graph") { private static final long serialVersionUID = 571719411574657791L; public void actionPerformed(ActionEvent e) { centerAndScaleGraph();/*w w w . j a v a 2 s . c o m*/ } }); popup.add(new AbstractAction("Relayout Graph") { private static final long serialVersionUID = 571719411573657791L; public void actionPerformed(ActionEvent e) { relayoutGraph(); } }); popup.add(new AbstractAction("Reset Board Colors") { private static final long serialVersionUID = 571719411573657796L; public void actionPerformed(ActionEvent e) { mGraph.updateOriginalColor(); mTurnNum = 0; putLog("Resetting game graph's colors."); updateGraphMessage(); mVV.repaint(); } }); popup.add(new AbstractAction( allowFreeExchange ? "Restrict to Unique Exchanges" : "Allow Free Edge Exchanges") { private static final long serialVersionUID = 571719411573657798L; public void actionPerformed(ActionEvent e) { allowFreeExchange = !allowFreeExchange; mVV.repaint(); } }); popup.add(new AbstractAction((mAutoPlayBob ? "Disable" : "Enable") + " Autoplay of Bob's Moves") { private static final long serialVersionUID = 571719413573657798L; public void actionPerformed(ActionEvent e) { mAutoPlayBob = !mAutoPlayBob; } }); popup.addSeparator(); JMenu newGraph = new JMenu("New Random Graph"); for (int i = 0; i < actionRandomGraph.length; ++i) { if (actionRandomGraph[i] != null) newGraph.add(actionRandomGraph[i]); } newGraph.addSeparator(); newGraph.add(getActionNewGraphType()); popup.add(newGraph); JMenu newNamedGraph = new JMenu("New Named Graph"); for (int i = 0; i < actionNamedGraph.size(); ++i) { if (actionNamedGraph.get(i) != null) newNamedGraph.add(actionNamedGraph.get(i)); } popup.add(newNamedGraph); popup.add(new AbstractAction("Show GraphString") { private static final long serialVersionUID = 545719411573657792L; public void actionPerformed(ActionEvent e) { JEditorPane text = new JEditorPane("text/plain", GraphString.write_graph(mGraph, mVV.getModel().getGraphLayout())); text.setEditable(false); text.setPreferredSize(new Dimension(300, 125)); JOptionPane.showMessageDialog(null, text, "GraphString Serialization", JOptionPane.INFORMATION_MESSAGE); } }); popup.add(new AbstractAction("Load GraphString") { private static final long serialVersionUID = 8636579131902717983L; public void actionPerformed(ActionEvent e) { String input = JOptionPane.showInputDialog(null, "Enter GraphString:", ""); if (input == null) return; loadGraphString(input); } }); popup.add(new AbstractAction("Show graph6") { private static final long serialVersionUID = 571719411573657792L; public void actionPerformed(ActionEvent e) { JTextArea text = new JTextArea(Graph6.write_graph6(mGraph)); JOptionPane.showMessageDialog(null, text, "graph6 Serialization", JOptionPane.INFORMATION_MESSAGE); } }); popup.add(new AbstractAction("Load graph6/sparse6") { private static final long serialVersionUID = 571719411573657792L; public void actionPerformed(ActionEvent e) { String input = JOptionPane.showInputDialog(null, "Enter graph6/sparse6 string:", ""); if (input == null) return; MyGraph g = Graph6.read_graph6(input); setNewGraph(g); } }); popup.add(new AbstractAction("Read GraphML") { private static final long serialVersionUID = 571719411573657794L; public void actionPerformed(ActionEvent e) { try { readGraphML(); } catch (IOException e1) { showStackTrace(e1); } catch (GraphIOException e1) { showStackTrace(e1); } } }); popup.add(new AbstractAction("Write GraphML") { private static final long serialVersionUID = 571719411573657795L; public void actionPerformed(ActionEvent e) { try { writeGraphML(); } catch (IOException e1) { showStackTrace(e1); } } }); popup.add(new AbstractAction("Write PDF") { private static final long serialVersionUID = 571719411573657793L; public void actionPerformed(ActionEvent e) { try { writePdf(); } catch (FileNotFoundException e1) { showStackTrace(e1); } catch (DocumentException de) { System.err.println(de.getMessage()); } } }); }
From source file:com.opendoorlogistics.studio.AppFrame.java
void launchScriptWizard(final int tableIds[], final ODLComponent component) { // final ODLTableDefinition dfn = (tableId != -1 && loaded != null) ? loaded.getDs().getTableByImmutableId(tableId) : null; // create button to launch the wizard ArrayList<JButton> buttons = new ArrayList<>(); for (final ODLWizardTemplateConfig config : ScriptTemplatesImpl.getTemplates(getApi(), component)) { Action action = new AbstractAction( "Launch wizard \"" + config.getName() + "\" to configure new script") { @Override/*from w w w . ja v a 2 s. co m*/ public void actionPerformed(ActionEvent e) { Script script = ScriptWizardActions.createScriptFromMasterComponent(getApi(), AppFrame.this, component, config, loaded != null ? loaded.getDs() : null, tableIds); if (script != null) { // ScriptEditor dlg = new ScriptEditorWizardGenerated(script, null, getScriptUIManager()); // AppFrame.this.addInternalFrame(dlg); scriptManager.launchScriptEditor(script, null, null); } } }; JButton button = new JButton(action); button.setToolTipText(config.getDescription()); buttons.add(button); } // launch dialog to select the option if (buttons.size() > 1) { launchButtonsListDialog(component.getName(), "Choose \"" + component.getName() + "\" option:", component.getIcon(getApi(), ODLComponent.MODE_DEFAULT), buttons); } else { // pick the only option... buttons.get(0).doClick(); } }
From source file:org.gtdfree.GTDFree.java
private ActionMap getActionMap() { if (actionMap == null) { actionMap = new ActionMap(); AbstractAction a = new AbstractAction(Messages.getString("GTDFree.View.Closed")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override//from w w w .j a va 2 s . c o m public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_ALL_ACTIONS, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_ALL_ACTIONS)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Closed.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_ALL_ACTIONS, a); a = new AbstractAction(Messages.getString("GTDFree.View.Empty")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_EMPTY_FOLDERS, !getEngine() .getGlobalProperties().getBoolean(GlobalProperties.SHOW_EMPTY_FOLDERS, true)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Empty.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_EMPTY_FOLDERS, a); a = new AbstractAction(Messages.getString("GTDFree.View.ClosedLists")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_CLOSED_FOLDERS, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_CLOSED_FOLDERS)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.ClosedLists.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_CLOSED_FOLDERS, a); a = new AbstractAction(Messages.getString("GTDFree.View.Overview")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_OVERVIEW_TAB, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_OVERVIEW_TAB)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Overview.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_OVERVIEW_TAB, a); a = new AbstractAction(Messages.getString("GTDFree.View.Quick")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_QUICK_COLLECT, !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_QUICK_COLLECT)); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Quick.desc")); //$NON-NLS-1$ actionMap.put(GlobalProperties.SHOW_QUICK_COLLECT, a); a = new AbstractAction(Messages.getString("GTDFree.View.Tray")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { boolean b = !getEngine().getGlobalProperties().getBoolean(GlobalProperties.SHOW_TRAY_ICON); getEngine().getGlobalProperties().putProperty(GlobalProperties.SHOW_TRAY_ICON, b); if (b) { try { SystemTray.getSystemTray().add(getTrayIcon()); } catch (AWTException e1) { Logger.getLogger(this.getClass()).error("System tray icon initialization failed.", e1); //$NON-NLS-1$ } } else { SystemTray.getSystemTray().remove(getTrayIcon()); } } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.View.Tray.desc")); //$NON-NLS-1$ a.setEnabled(SystemTray.isSupported()); actionMap.put(GlobalProperties.SHOW_TRAY_ICON, a); a = new AbstractAction(Messages.getString("GTDFree.ImportExamples")) { //$NON-NLS-1$ private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { getImportDialog().getDialog(getJFrame()).setVisible(true); } }; a.putValue(Action.SHORT_DESCRIPTION, Messages.getString("GTDFree.ImportExamples.desc")); //$NON-NLS-1$ actionMap.put("importDialog", a); //$NON-NLS-1$ } return actionMap; }
From source file:edu.ku.brc.specify.Specify.java
/** * Create menus/*from w ww .j a v a 2 s .c om*/ */ public JMenuBar createMenus() { JMenuBar mb = new JMenuBar(); JMenuItem mi; //-------------------------------------------------------------------- //-- File Menu //-------------------------------------------------------------------- JMenu menu = null; if (!UIHelper.isMacOS() || !isWorkbenchOnly) { menu = UIHelper.createLocalizedMenu(mb, "Specify.FILE_MENU", "Specify.FILE_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ } if (!isWorkbenchOnly) { // Add Menu for switching Collection String title = "Specify.CHANGE_COLLECTION"; //$NON-NLS-1$ String mnu = "Specify.CHANGE_COLL_MNEU"; //$NON-NLS-1$ changeCollectionMenuItem = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null); changeCollectionMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (SubPaneMgr.getInstance().aboutToShutdown()) { // Actually we really need to start over // "true" means that it should NOT use any cached values it can find to automatically initialize itself // instead it should ask the user any questions as if it were starting over restartApp(null, databaseName, userName, true, false); } } }); menu.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent e) { } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuSelected(MenuEvent e) { boolean enable = Uploader.getCurrentUpload() == null && ((SpecifyAppContextMgr) AppContextMgr.getInstance()).getNumOfCollectionsForUser() > 1 && !TaskMgr.areTasksDisabled(); changeCollectionMenuItem.setEnabled(enable); } }); } if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { if (!UIRegistry.isMobile()) { menu.addSeparator(); } String title = "Specify.EXIT"; //$NON-NLS-1$ String mnu = "Specify.Exit_MNEU"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, true, null); if (!UIHelper.isMacOS()) { mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, InputEvent.CTRL_DOWN_MASK)); } mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doExit(true); } }); } menu = UIRegistry.getInstance().createEditMenu(); mb.add(menu); //menu = UIHelper.createMenu(mb, "EditMenu", "EditMneu"); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { menu.addSeparator(); String title = "Specify.PREFERENCES"; //$NON-NLS-1$ String mnu = "Specify.PREFERENCES_MNEU";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, title, mnu, title, false, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doPreferences(); } }); mi.setEnabled(true); } //-------------------------------------------------------------------- //-- Data Menu //-------------------------------------------------------------------- JMenu dataMenu = UIHelper.createLocalizedMenu(mb, "Specify.DATA_MENU", "Specify.DATA_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ ResultSetController.addMenuItems(dataMenu); dataMenu.addSeparator(); // Save And New Menu Item Action saveAndNewAction = new AbstractAction(getResourceString("Specify.SAVE_AND_NEW")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.setSaveAndNew(((JCheckBoxMenuItem) e.getSource()).isSelected()); } } }; saveAndNewAction.setEnabled(false); JCheckBoxMenuItem saveAndNewCBMI = new JCheckBoxMenuItem(saveAndNewAction); dataMenu.add(saveAndNewCBMI); UIRegistry.register("SaveAndNew", saveAndNewCBMI); //$NON-NLS-1$ UIRegistry.registerAction("SaveAndNew", saveAndNewAction); //$NON-NLS-1$ mb.add(dataMenu); // Configure Carry Forward Action configCarryForwardAction = new AbstractAction( getResourceString("Specify.CONFIG_CARRY_FORWARD_MENU")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.configureCarryForward(); } } }; configCarryForwardAction.setEnabled(false); JMenuItem configCFWMI = new JMenuItem(configCarryForwardAction); dataMenu.add(configCFWMI); UIRegistry.register("ConfigCarryForward", configCFWMI); //$NON-NLS-1$ UIRegistry.registerAction("ConfigCarryForward", configCarryForwardAction); //$NON-NLS-1$ mb.add(dataMenu); //--------------------------------------- // Carry Forward Menu Item (On / Off) Action carryForwardAction = new AbstractAction(getResourceString("Specify.CARRY_FORWARD_CHECKED_MENU")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.toggleCarryForward(); ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isDoCarryForward()); } } }; carryForwardAction.setEnabled(false); JCheckBoxMenuItem carryForwardCBMI = new JCheckBoxMenuItem(carryForwardAction); dataMenu.add(carryForwardCBMI); UIRegistry.register("CarryForward", carryForwardCBMI); //$NON-NLS-1$ UIRegistry.registerAction("CarryForward", carryForwardAction); //$NON-NLS-1$ mb.add(dataMenu); if (!isWorkbenchOnly) { final String AUTO_NUM = "AutoNumbering"; //--------------------------------------- // AutoNumber Menu Item (On / Off) Action autoNumberOnOffAction = new AbstractAction( getResourceString("FormViewObj.SET_AUTONUMBER_ONOFF")) { //$NON-NLS-1$ public void actionPerformed(ActionEvent e) { FormViewObj fvo = getCurrentFVO(); if (fvo != null) { fvo.toggleAutoNumberOnOffState(); ((JCheckBoxMenuItem) e.getSource()).setSelected(fvo.isAutoNumberOn()); } } }; autoNumberOnOffAction.setEnabled(false); JCheckBoxMenuItem autoNumCBMI = new JCheckBoxMenuItem(autoNumberOnOffAction); dataMenu.add(autoNumCBMI); UIRegistry.register(AUTO_NUM, autoNumCBMI); //$NON-NLS-1$ UIRegistry.registerAction(AUTO_NUM, autoNumberOnOffAction); //$NON-NLS-1$ } if (System.getProperty("user.name").equals("rods")) { dataMenu.addSeparator(); AbstractAction gpxAction = new AbstractAction("GPS Data") { @Override public void actionPerformed(ActionEvent e) { GPXPanel.getDlgInstance().setVisible(true); } }; JMenuItem gpxMI = new JMenuItem(gpxAction); dataMenu.add(gpxMI); UIRegistry.register("GPXDlg", gpxMI); //$NON-NLS-1$ UIRegistry.registerAction("GPXDlg", gpxAction); //$NON-NLS-1$ } mb.add(dataMenu); SubPaneMgr.getInstance(); // force creating of the Mgr so the menu Actions are created. //-------------------------------------------------------------------- //-- System Menu //-------------------------------------------------------------------- if (!isWorkbenchOnly) { // TODO This needs to be moved into the SystemTask, but right now there is no way // to ask a task for a menu. menu = UIHelper.createLocalizedMenu(mb, "Specify.SYSTEM_MENU", "Specify.SYSTEM_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ /*if (true) { menu = UIHelper.createMenu(mb, "Forms", "o"); Action genForms = new AbstractAction() { public void actionPerformed(ActionEvent ae) { FormGenerator fg = new FormGenerator(); fg.generateForms(); } }; mi = UIHelper.createMenuItemWithAction(menu, "Generate All Forms", "G", "", true, genForms); }*/ } //-------------------------------------------------------------------- //-- Tab Menu //-------------------------------------------------------------------- menu = UIHelper.createLocalizedMenu(mb, "Specify.TABS_MENU", "Specify.TABS_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ String ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MENU"); String mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_CUR_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseCurrent")); if (!UIHelper.isMacOS()) { mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK)); } ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MENU"); mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALL_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAll")); if (!UIHelper.isMacOS()) { mi.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK | InputEvent.SHIFT_DOWN_MASK)); } ttl = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MENU"); mnu = UIRegistry.getResourceString("Specify.SBP_CLOSE_ALLBUT_MNEU"); mi = UIHelper.createMenuItemWithAction(menu, ttl, mnu, ttl, true, getAction("CloseAllBut")); menu.addSeparator(); // Configure Task JMenuItem configTaskMI = new JMenuItem(getAction("ConfigureTask")); menu.add(configTaskMI); //UIRegistry.register("ConfigureTask", configTaskMI); //$NON-NLS-1$ //-------------------------------------------------------------------- //-- Debug Menu //-------------------------------------------------------------------- boolean doDebug = AppPreferences.getLocalPrefs().getBoolean("debug.menu", false); if (!UIRegistry.isRelease() || doDebug) { menu = UIHelper.createLocalizedMenu(mb, "Specify.DEBUG_MENU", "Specify.DEBUG_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ String ttle = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ String mneu = "Specify.SHOW_LOC_PREF_MNEU";//$NON-NLS-1$ String desc = "Specify.SHOW_LOC_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { openLocalPrefs(); } }); ttle = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ mneu = "Specify.SHOW_REM_PREFS_MNEU";//$NON-NLS-1$ desc = "Specify.SHOW_REM_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { openRemotePrefs(); } }); menu.addSeparator(); ttle = "Specify.CONFIG_LOGGERS";//$NON-NLS-1$ mneu = "Specify.CONFIG_LOGGERS_MNEU";//$NON-NLS-1$ desc = "Specify.CONFIG_LOGGER";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { final LoggerDialog dialog = new LoggerDialog(topFrame); UIHelper.centerAndShow(dialog); } }); ttle = "Specify.CONFIG_DEBUG_LOGGERS";//$NON-NLS-1$ mneu = "Specify.CONFIG_DEBUG_LOGGERS_MNEU";//$NON-NLS-1$ desc = "Specify.CONFIG_DEBUG_LOGGER";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { DebugLoggerDialog dialog = new DebugLoggerDialog(topFrame); UIHelper.centerAndShow(dialog); } }); menu.addSeparator(); ttle = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ mneu = "Specify.SHOW_MEM_STATS_MNEU";//$NON-NLS-1$ desc = "Specify.SHOW_MEM_STATS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { System.gc(); System.runFinalization(); // Get current size of heap in bytes double meg = 1024.0 * 1024.0; double heapSize = Runtime.getRuntime().totalMemory() / meg; // Get maximum size of heap in bytes. The heap cannot grow beyond this size. // Any attempt will result in an OutOfMemoryException. double heapMaxSize = Runtime.getRuntime().maxMemory() / meg; // Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created. double heapFreeSize = Runtime.getRuntime().freeMemory() / meg; UIRegistry.getStatusBar() .setText(String.format("Heap Size: %7.2f Max: %7.2f Free: %7.2f Used: %7.2f", //$NON-NLS-1$ heapSize, heapMaxSize, heapFreeSize, (heapSize - heapFreeSize))); } }); JMenu prefsMenu = new JMenu(UIRegistry.getResourceString("Specify.PREFS_IMPORT_EXPORT")); //$NON-NLS-1$ menu.add(prefsMenu); ttle = "Specify.IMPORT_MENU";//$NON-NLS-1$ mneu = "Specify.IMPORT_MNEU";//$NON-NLS-1$ desc = "Specify.IMPORT_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { importPrefs(); } }); ttle = "Specify.EXPORT_MENU";//$NON-NLS-1$ mneu = "Specify.EXPORT_MNEU";//$NON-NLS-1$ desc = "Specify.EXPORT_PREFS";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(prefsMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { exportPrefs(); } }); ttle = "Associate Storage Items";//$NON-NLS-1$ mneu = "A";//$NON-NLS-1$ desc = "";//$NON-NLS-1$ mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { associateStorageItems(); } }); ttle = "Load GPX Points";//$NON-NLS-1$ mneu = "a";//$NON-NLS-1$ desc = "";//$NON-NLS-1$ mi = UIHelper.createMenuItemWithAction(menu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @SuppressWarnings("synthetic-access") //$NON-NLS-1$ public void actionPerformed(ActionEvent ae) { CustomDialog dlg = GPXPanel.getDlgInstance(); if (dlg != null) { dlg.setVisible(true); } } }); JCheckBoxMenuItem cbMenuItem = new JCheckBoxMenuItem("Security Activated"); //$NON-NLS-1$ menu.add(cbMenuItem); cbMenuItem.setSelected(AppContextMgr.isSecurityOn()); cbMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { boolean isSecurityOn = !SpecifyAppContextMgr.isSecurityOn(); AppContextMgr.getInstance().setSecurity(isSecurityOn); ((JMenuItem) ae.getSource()).setSelected(isSecurityOn); JLabel secLbl = statusField.getSectionLabel(3); if (secLbl != null) { secLbl.setIcon(IconManager.getImage(isSecurityOn ? "SecurityOn" : "SecurityOff", IconManager.IconSize.Std16)); secLbl.setHorizontalAlignment(SwingConstants.CENTER); secLbl.setToolTipText(getResourceString("Specify.SEC_" + (isSecurityOn ? "ON" : "OFF"))); } } }); JMenuItem sizeMenuItem = new JMenuItem("Set to " + PREFERRED_WIDTH + "x" + PREFERRED_HEIGHT); //$NON-NLS-1$ menu.add(sizeMenuItem); sizeMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { topFrame.setSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } }); } //---------------------------------------------------- //-- Helper Menu //---------------------------------------------------- JMenu helpMenu = UIHelper.createLocalizedMenu(mb, "Specify.HELP_MENU", "Specify.HELP_MNEU"); //$NON-NLS-1$ //$NON-NLS-2$ HelpMgr.createHelpMenuItem(helpMenu, getResourceString("SPECIFY_HELP")); //$NON-NLS-1$ helpMenu.addSeparator(); String ttle = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$ String mneu = "Specify.LOG_SHOW_FILES_MNEU";//$NON-NLS-1$ String desc = "Specify.LOG_SHOW_FILES";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); helpMenu.addSeparator(); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { AppBase.displaySpecifyLogFiles(); } }); ttle = "SecurityAdminTask.CHANGE_PWD_MENU"; //$NON-NLS-1$ mneu = "SecurityAdminTask.CHANGE_PWD_MNEU"; //$NON-NLS-1$ desc = "SecurityAdminTask.CHANGE_PWD_DESC"; //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { SecurityAdminTask.changePassword(true); } }); ttle = "Specify.CHECK_UPDATE";//$NON-NLS-1$ mneu = "Specify.CHECK_UPDATE_MNEU";//$NON-NLS-1$ desc = "Specify.CHECK_UPDATE_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { checkForUpdates(); } }); ttle = "Specify.AUTO_REG";//$NON-NLS-1$ mneu = "Specify.AUTO_REG_MNEU";//$NON-NLS-1$ desc = "Specify.AUTO_REG_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { RegisterSpecify.register(true, 0); } }); ttle = "Specify.SA_REG";//$NON-NLS-1$ mneu = "Specify.SA_REG_MNEU";//$NON-NLS-1$ desc = "Specify.SA_REG_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { RegisterSpecify.registerISA(); } }); ttle = "Specify.FEEDBACK";//$NON-NLS-1$ mneu = "Specify.FB_MNEU";//$NON-NLS-1$ desc = "Specify.FB_DESC";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { FeedBackDlg feedBackDlg = new FeedBackDlg(); feedBackDlg.sendFeedback(); } }); if (UIHelper.getOSType() != UIHelper.OSTYPE.MacOSX) { helpMenu.addSeparator(); ttle = "Specify.ABOUT";//$NON-NLS-1$ mneu = "Specify.ABOUTMNEU";//$NON-NLS-1$ desc = "Specify.ABOUT";//$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(helpMenu, ttle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { doAbout(); } }); } return mb; }
From source file:com.opendoorlogistics.studio.AppFrame.java
private void initFileMenu(JMenu mnFile) { mnFile.removeAll();/*from w w w .j a va2 s.com*/ // non-dynamic for (MyAction action : fileActions) { if (action == null) { mnFile.addSeparator(); } else { JMenuItem item = mnFile.add(action); if (action.accelerator != null) { item.setAccelerator(action.accelerator); } } } // import (not in action list as doesn't appear on toolbar) mnFile.addSeparator(); JMenu mnImport = new JMenu("Import"); mnFile.add(mnImport); class ImportPair { String menuString; SupportedFileType type; public ImportPair(String menuString, SupportedFileType type) { super(); this.menuString = menuString; this.type = type; } } for (final ImportPair type : new ImportPair[] { new ImportPair("Comma separated (CSV) text", SupportedFileType.CSV), new ImportPair("Tab separated text", SupportedFileType.TABBED), new ImportPair("Excel", SupportedFileType.EXCEL), new ImportPair("Shapefile (link geometry to original file)", SupportedFileType.SHAPEFILE_LINKED_GEOM), new ImportPair("Shapefile (copy geometry into spreadsheet)", SupportedFileType.SHAPEFILE_COPIED_GEOM), }) { mnImport.add(new AbstractAction(type.menuString) { @Override public void actionPerformed(ActionEvent e) { importFile(type.type); } }); } // dynamic mnFile.addSeparator(); List<File> recent = PreferencesManager.getSingleton().getRecentFiles(); for (int i = 0; i < recent.size(); i++) { final File file = recent.get(i); String s = Integer.toString(i + 1) + ". " + file.getAbsolutePath(); int maxLen = 100; if (s.length() > maxLen) { s = s.substring(0, maxLen) + "..."; } mnFile.add(new MyAction(s, "Load file " + file.getAbsolutePath(), null, null, false, null) { @Override public void actionPerformed(ActionEvent e) { if (!canCloseDatastore()) { return; } openFile(file); updateAppearance(); } }); } // clear recent mnFile.addSeparator(); mnFile.add(new MyAction("Clear recent files", "Clear recent files", null, null, false, null) { @Override public void actionPerformed(ActionEvent e) { PreferencesManager.getSingleton().clearRecentFiles(); } }); // finally exit mnFile.addSeparator(); JMenuItem item = mnFile.add(new MyAction("Exit", "Exit", null, null, false, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.Event.CTRL_MASK)) { @Override public void actionPerformed(ActionEvent e) { dispose(); System.exit(0); } }); item.setAccelerator(((MyAction) item.getAction()).accelerator); mnFile.validate(); }
From source file:org.nuclos.client.main.MainController.java
private Map<String, Map<String, Action>> getCommandMap() { HashMap<String, Map<String, Action>> res = new HashMap<String, Map<String, Action>>(); HashMap<String, Action> mainController = new HashMap<String, Action>(); /* that's too cumbersome: mainController.put(/*from w w w . j a v a 2 s . c om*/ "cmdChangePassword", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cmdChangePassword(); } }); */ mainController.put("cmdDirectHelp", cmdDirectHelp); mainController.put("cmdShowPersonalTasks", cmdShowPersonalTasks); mainController.put("cmdShowTimelimitTasks", cmdShowTimelimitTasks); mainController.put("cmdShowPersonalSearchFilters", cmdShowPersonalSearchFilters); mainController.put("cmdChangePassword", cmdChangePassword); mainController.put("cmdOpenSettings", cmdOpenSettings); mainController.put("cmdOpenManagementConsole", cmdOpenManagementConsole); //mainController.put("cmdOpenEntityWizard", cmdOpenEntityWizard); mainController.put("cmdOpenRelationEditor", cmdOpenRelationEditor); mainController.put("cmdOpenCustomComponentWizard", cmdOpenCustomComponentWizard); //mainController.put("cmdRefreshClientCaches", cmdRefreshClientCaches); mainController.put("cmdSelectAll", cmdSelectAll); mainController.put("cmdHelpContents", cmdHelpContents); mainController.put("cmdShowAboutDialog", cmdShowAboutDialog); mainController.put("cmdShowProjectReleaseNotes", cmdShowProjectReleaseNotes); mainController.put("cmdShowNuclosReleaseNotes", cmdShowNuclosReleaseNotes); mainController.put("cmdLogoutExit", cmdLogoutExit); mainController.put("cmdWindowClosing", cmdWindowClosing); mainController.put("cmdExecuteRport", cmdExecuteRport); for (Method m : getClass().getDeclaredMethods()) { if (m.getName().startsWith("cmd")) { Class<?>[] pt = m.getParameterTypes(); if (pt.length == 0 || (pt.length == 1 && pt[0].isAssignableFrom(ActionEvent.class))) { final Method fm = m; Action a = new AbstractAction(m.getName()) { @Override public void actionPerformed(ActionEvent e) { miDelegator(e, fm); } }; mainController.put(m.getName(), a); } } } res.put("MainController", mainController); HashMap<String, Action> clipboardUtils = new HashMap<String, Action>(); clipboardUtils.put("cutAction", new ClipboardUtils.CutAction()); clipboardUtils.put("copyAction", new ClipboardUtils.CopyAction()); clipboardUtils.put("pasteAction", new ClipboardUtils.PasteAction()); res.put("ClipboardUtils", clipboardUtils); HashMap<String, Action> dev = new HashMap<String, Action>(); dev.put("jmsNotification", new AbstractAction("Test JMS notification") { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(getMainFrame(), "Topic: Message"); if (s == null) return; String[] a = s.split(": *"); if (a.length == 2) { // testFacadeRemote.testClientNotification(a[0], a[1]); throw new UnsupportedOperationException("TestFacade removed"); } else { JOptionPane.showMessageDialog(getMainFrame(), "Wrong input format"); } } }); dev.put("webPrefs", new AbstractAction("Test Web Prefs-Access") { @Override public void actionPerformed(ActionEvent e) { String s = JOptionPane.showInputDialog(getMainFrame(), "Access-Path"); if (s == null) return; try { Map<String, String> m = getWebAccessPrefs().getPrefsMap(s); StringBuilder sb = new StringBuilder(); for (String k : m.keySet()) sb.append(k).append(": ").append(m.get(k)).append("\n"); JOptionPane.showMessageDialog(getMainFrame(), sb.toString()); } catch (CommonBusinessException e1) { Errors.getInstance().showExceptionDialog(getMainFrame(), e1); } } }); dev.put("uiDefaults", new AbstractAction("UIDefaults") { @Override public void actionPerformed(ActionEvent e) { JFrame out = new JFrame("UIDefaults"); out.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); out.getContentPane().setLayout(new BorderLayout()); final UIDefTableModel mdl = new UIDefTableModel(); final JTable contentTable = new JTable(mdl); JScrollPane sp = new JScrollPane(contentTable); out.getContentPane().add(sp, BorderLayout.CENTER); UIDefaults defs = UIManager.getDefaults(); for (Object key : CollectionUtils.iterableEnum((defs.keys()))) mdl.add(key.toString(), defs.get(key)); mdl.sort(); contentTable.getColumnModel().getColumn(1).setCellRenderer(new UIDefaultsRenderer()); contentTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int row = contentTable.rowAtPoint(e.getPoint()); mdl.forceValue(contentTable.convertRowIndexToModel(row)); } }); out.pack(); out.setVisible(true); } }); dev.put("checkJawin", new AbstractAction("Check Jawin") { @Override public void actionPerformed(ActionEvent e) { try { SystemUtils.checkJawin(); JOptionPane.showMessageDialog(Main.getInstance().getMainFrame(), "Jawin ok"); } catch (Exception ex) { Errors.getInstance().showDetailedExceptionDialog(Main.getInstance().getMainFrame(), ex); } } }); res.put("Dev", dev); return res; }