List of usage examples for javax.swing JMenu validate
public void validate()
From source file:com.opendoorlogistics.studio.appframe.AppFrame.java
private void initFileMenu(JMenu mnFile, List<? extends Action> fileActions, ActionFactory actionFactory, MenuFactory menuBuilder) {//from w w w .j a v a2s .c o m mnFile.removeAll(); // non-dynamic for (Action action : fileActions) { if (action == null) { mnFile.addSeparator(); } else { 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 = menuBuilder.createImportMenu(this); mnFile.add(mnImport); // dynamic mnFile.addSeparator(); for (AppFrameAction action : actionFactory.createLoadRecentFilesActions(this)) { mnFile.add(action); } // clear recent mnFile.addSeparator(); mnFile.add(new AppFrameAction("Clear recent files", "Clear recent files", null, null, false, null, this) { @Override public void actionPerformed(ActionEvent e) { PreferencesManager.getSingleton().clearRecentFiles(); } }); // finally exit mnFile.addSeparator(); JMenuItem item = mnFile.add(new AppFrameAction("Exit", "Exit", null, null, false, KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.Event.CTRL_MASK), this) { @Override public void actionPerformed(ActionEvent e) { dispose(); System.exit(0); } }); // item.setAccelerator(((AppFrameAction) item.getAction()).accelerator); mnFile.validate(); }
From source file:com.opendoorlogistics.studio.AppFrame.java
private void initFileMenu(JMenu mnFile) { mnFile.removeAll();//from ww w . j a va 2s.c o m // 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(); }