List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:edu.umich.robot.GuiApplication.java
/** * Entry point.//from w w w. j a v a 2 s. c om * * @param args Args from command line. */ public GuiApplication(Config config) { // Heavyweight is not desirable but it is the only thing that will // render in front of the Viewer on all platforms. Blame OpenGL JPopupMenu.setDefaultLightWeightPopupEnabled(false); ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false); // must have config //Config config = (args.length > 0) ? ConfigUtil.getDefaultConfig(args) : promptForConfig(frame); if (config == null) System.exit(1); // Add more stuff to the config file that doesn't change between runs. Application.setupSimulatorConfig(config); setupViewerConfig(config); Configs.toLog(logger, config); controller = new Controller(config, new Gamepad()); controller.initializeGamepad(); viewer = new Viewer(config, frame); // This puts us in full 3d mode by default. The Viewer GUI doesn't // reflect this in its right click drop-down, a bug. viewer.getVisCanvas().getViewManager().setInterfaceMode(3); controller.addListener(RobotAddedEvent.class, listener); controller.addListener(RobotRemovedEvent.class, listener); controller.addListener(AfterResetEvent.class, listener); controller.addListener(ControllerActivatedEvent.class, listener); controller.addListener(ControllerDeactivatedEvent.class, listener); actionManager = new ActionManager(this); initActions(); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { controller.shutdown(); System.exit(0); } }); frame.setLayout(new BorderLayout()); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); fileMenu.add(actionManager.getAction(CreateSplinterRobotAction.class)); fileMenu.add(actionManager.getAction(CreateSuperdroidRobotAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ConnectSuperdroidAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ResetPreferencesAction.class)); /* fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(TextMessageAction.class)); */ fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(SaveMapAction.class)); fileMenu.add(new JSeparator()); fileMenu.add(actionManager.getAction(ExitAction.class)); menuBar.add(fileMenu); JMenu cameraMenu = new JMenu("Camera"); cameraMenu.add(actionManager.getAction(DisableFollowAction.class)); cameraMenu.add(actionManager.getAction(FollowPositionAction.class)); cameraMenu.add(actionManager.getAction(FollowPositionAndThetaAction.class)); cameraMenu.add(new JSeparator()); cameraMenu.add(actionManager.getAction(MoveCameraBehindAction.class)); cameraMenu.add(actionManager.getAction(MoveCameraAboveAction.class)); menuBar.add(cameraMenu); JMenu objectMenu = new JMenu("Objects"); boolean added = false; for (String objectName : controller.getObjectNames()) { added = true; objectMenu.add(new AddObjectAction(this, objectName)); } if (!added) objectMenu.add(new JLabel("No objects available")); menuBar.add(objectMenu); menuBar.revalidate(); frame.setJMenuBar(menuBar); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true); toolBar.add(actionManager.getAction(SoarParametersAction.class)); toolBar.add(actionManager.getAction(SoarDataAction.class)); toolBar.add(actionManager.getAction(ResetAction.class)); toolBar.add(actionManager.getAction(SoarToggleAction.class)); toolBar.add(actionManager.getAction(SoarStepAction.class)); toolBar.add(actionManager.getAction(SimSpeedAction.class)); frame.add(toolBar, BorderLayout.PAGE_START); viewerView = new ViewerView(viewer.getVisCanvas()); robotsView = new RobotsView(this, actionManager); final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, viewerView, robotsView); splitPane.setDividerLocation(0.75); // TODO SoarApril /* viewer.addRobotSelectionChangedListener(robotsView); viewer.getVisCanvas().setDrawGround(true); */ viewer.getVisCanvas().addEventHandler(new VisCanvasEventAdapter() { public String getName() { return "Place Object"; } @Override public boolean mouseClicked(VisCanvas vc, GRay3D ray, MouseEvent e) { boolean ret = false; synchronized (GuiApplication.this) { if (objectToAdd != null && controller != null) { controller.addObject(objectToAdd, ray.intersectPlaneXY()); objectToAdd = null; ret = true; } else { double[] click = ray.intersectPlaneXY(); chatView.setClick(new Point2D.Double(click[0], click[1])); } } status.setMessage( String.format("%3.1f,%3.1f", ray.intersectPlaneXY()[0], ray.intersectPlaneXY()[1])); return ret; } }); consoleView = new ConsoleView(); chatView = new ChatView(this); controller.getRadio().addRadioHandler(chatView); final JSplitPane bottomPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, consoleView, chatView); bottomPane.setDividerLocation(200); final JSplitPane splitPane2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitPane, bottomPane); splitPane2.setDividerLocation(0.75); frame.add(splitPane2, BorderLayout.CENTER); status = new StatusBar(); frame.add(status, BorderLayout.SOUTH); /* frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { final Preferences windowPrefs = getWindowPreferences(); final Rectangle r = frame.getBounds(); if(frame.getExtendedState() == JFrame.NORMAL) { windowPrefs.putInt("x", r.x); windowPrefs.putInt("y", r.y); windowPrefs.putInt("width", r.width); windowPrefs.putInt("height", r.height); windowPrefs.putInt("divider", splitPane.getDividerLocation()); } exit(); }}); Preferences windowPrefs = getWindowPreferences(); if (windowPrefs.get("x", null) != null) { frame.setBounds( windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 1200), windowPrefs.getInt("height", 900)); splitPane.setDividerLocation(windowPrefs.getInt("divider", 500)); } else { frame.setBounds( windowPrefs.getInt("x", 0), windowPrefs.getInt("y", 0), windowPrefs.getInt("width", 1200), windowPrefs.getInt("height", 900)); splitPane.setDividerLocation(0.75); frame.setLocationRelativeTo(null); // center } */ frame.getRootPane().setBounds(0, 0, 1600, 1200); frame.getRootPane().registerKeyboardAction(new ActionListener() { public void actionPerformed(ActionEvent e) { frame.dispose(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); frame.pack(); frame.setVisible(true); for (String s : config.getStrings("splinters", new String[0])) { double[] pos = config.getDoubles(s + ".position"); if (pos == null) { logger.error("Splinter indexed in config file but no position defined: " + s); continue; } Pose pose = new Pose(pos); String prods = config.getString(s + ".productions"); boolean collisions = config.getBoolean(s + ".wallCollisions", true); controller.createSplinterRobot(s, pose, collisions); boolean simulated = config.getBoolean(s + ".simulated", true); if (simulated) controller.createSimSplinter(s); else controller.createRealSplinter(s); controller.createSimLaser(s); if (prods != null) { controller.createSoarController(s, s, prods, config.getChild(s + ".properties")); PREFERENCES.put("lastProductions", prods); } } for (String s : config.getStrings("superdroids", new String[0])) { double[] pos = config.getDoubles(s + ".position"); if (pos == null) { logger.error("Superdroid indexed in config file but no position defined: " + s); continue; } Pose pose = new Pose(pos); String prods = config.getString(s + ".productions"); boolean collisions = config.getBoolean(s + ".wallCollisions", true); controller.createSuperdroidRobot(s, pose, collisions); boolean simulated = config.getBoolean(s + ".simulated", true); if (simulated) controller.createSimSuperdroid(s); else { try { controller.createRealSuperdroid(s, "192.168.1.165", 3192); } catch (UnknownHostException e1) { e1.printStackTrace(); } catch (SocketException e1) { e1.printStackTrace(); } } controller.createSimLaser(s); if (prods != null) { // wait a sec try { Thread.sleep(1000); } catch (InterruptedException ex) { } controller.createSoarController(s, s, prods, config.getChild(s + ".properties")); PREFERENCES.put("lastProductions", prods); } } }
From source file:com.opendoorlogistics.studio.AppFrame.java
private void initWindowMenus(JMenu mnWindow) { mnWindow.add(new AbstractAction("Tile open windows") { @Override/* w ww . ja v a 2s. co m*/ public void actionPerformed(ActionEvent e) { tileWindows(); } }).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, Event.CTRL_MASK)); mnWindow.add(new AbstractAction("Cascade open windows") { @Override public void actionPerformed(ActionEvent e) { cascadeWindows(); } }).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK)); mnWindow.add(new AbstractAction("Close all open windows") { @Override public void actionPerformed(ActionEvent e) { closeWindows(); } }); mnWindow.add(new AbstractAction("Minimise all open windows") { @Override public void actionPerformed(ActionEvent e) { minimiseWindows(); } }).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK)); mnWindow.add(new AbstractAction("Show all tables") { @Override public void actionPerformed(ActionEvent e) { tileTables(); } }); JMenu mnResizeTo = new JMenu("Resize application to..."); for (final int[] size : new int[][] { new int[] { 1280, 720 }, new int[] { 1920, 1080 } }) { mnResizeTo.add(new AbstractAction("" + size[0] + " x " + size[1]) { @Override public void actionPerformed(ActionEvent e) { // set standard layout setSize(size[0], size[1]); splitterLeftPanelMain.setDividerLocation(0.175); splitterTablesScripts.setDividerLocation(0.3); } }); } mnWindow.add(mnResizeTo); }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
private JMenu getProviderMenu() { final JMenu providerMenu = new JMenu("Providers"); providerMenu.setMnemonic(KeyEvent.VK_P); providerMenu.getAccessibleContext().setAccessibleDescription("Managing cloud providers."); final JMenuItem manageProvidersItem = new JMenuItem("Manage Providers"); manageProvidersItem.setMnemonic(KeyEvent.VK_M); manageProvidersItem.addActionListener(new ActionListener() { @Override/*from w w w . ja v a2s . c o m*/ public void actionPerformed(final ActionEvent e) { new ManageProvidersWindow(GUI.this); } }); providerMenu.add(manageProvidersItem); final JMenuItem detectAllUnlinkedInstances = new JMenuItem("Link/Unlink Instances"); detectAllUnlinkedInstances.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { new LinkUnlinkWindow(GUI.this); // detectAllUnlinkedInstances(); } }); providerMenu.add(detectAllUnlinkedInstances); return providerMenu; }
From source file:com.opendoorlogistics.studio.AppFrame.java
private JMenu initHelpMenu() { JMenu mnHelp = new JMenu("Help"); mnHelp.setMnemonic('H'); mnHelp.add(initGotoWebsiteAction()); mnHelp.add(new AbstractAction("About ODL Studio") { @Override//w w w . j ava 2s . c om public void actionPerformed(ActionEvent e) { final AboutBoxDialog dlg = new AboutBoxDialog(AppFrame.this, false); dlg.setLocationRelativeTo(AppFrame.this); dlg.setVisible(true); } }); mnHelp.add(new AbstractAction("List of data adapter functions") { @Override public void actionPerformed(ActionEvent e) { addInternalFrame(FunctionsListPanel.createFrame(), FramePlacement.AUTOMATIC); } }); mnHelp.add(new AbstractAction("List of 3rd party data & libraries") { @Override public void actionPerformed(ActionEvent e) { final AboutBoxDialog dlg = new AboutBoxDialog(AppFrame.this, true); dlg.setTitle("3rd party data & libs used in ODL Studio"); dlg.setLocationRelativeTo(AppFrame.this); dlg.setVisible(true); } }); return mnHelp; }
From source file:com.declarativa.interprolog.gui.ListenerWindow.java
static void addItemToMenu(JMenu menu, String item, ActionListener handler) { JMenuItem menuItem = new JMenuItem(item); menu.add(menuItem); menuItem.addActionListener(handler); }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * @param menu//ww w . j av a 2 s .co m */ private void makeRecentSubMenu(JMenu menu) { menu.removeAll(); for (final Map.Entry<String, String> entry : RuntimeProperties.getRecentPackages().entrySet()) { JMenuItem menuItem = new JMenuItem(entry.getKey()); menuItem.setToolTipText(entry.getValue()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openNewCanvasWithPackage(new File(entry.getValue())); } }); menu.add(menuItem); } }
From source file:com.nbt.TreeFrame.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menuFile = new JMenu("File"); Action[] fileActions = { /* newAction, */browseAction, saveAction, /* saveAsAction, */refreshAction, exitAction };/*from www . jav a2 s .c o m*/ for (Action action : fileActions) menuFile.add(new JMenuItem(action)); menuBar.add(menuFile); JMenu menuEdit = new JMenu("Edit"); Action[] editActions = { cutAction, copyAction, pasteAction, null, deleteAction, null, addByteAction, addShortAction, addIntAction, addLongAction, addFloatAction, addDoubleAction, addByteArrayAction, addStringAction, addListAction, addCompoundAction }; for (Action action : editActions) { if (action == null) { menuEdit.addSeparator(); } else { menuEdit.add(new JMenuItem(action)); } } menuBar.add(menuEdit); JMenu menuView = new JMenu("View"); menuView.add(new JMenuItem(openAction)); menuBar.add(menuView); JMenu menuHelp = new JMenu("Help"); menuHelp.add(new JMenuItem(helpAction)); menuBar.add(menuHelp); return menuBar; }
From source file:be.ac.ua.comp.scarletnebula.gui.windows.GUI.java
private JMenu getHelpMenu() { final JMenu helpMenu = new JMenu("Help"); helpMenu.setMnemonic(KeyEvent.VK_H); // Pick a random message to display in the help menu final String messages[] = { "(You won't find any help here)", "(Nobody can help you)", "(Keep on lookin' if you need help)", "(Heeeeelp!)", "(You might want to try google for help)", "(Try yelling loudly if you need help)" }; final Random generator = new Random(System.currentTimeMillis()); final JMenuItem noHelpItem = new JMenuItem(messages[generator.nextInt(messages.length)]); noHelpItem.setEnabled(false);/* ww w.j a va2s. co m*/ helpMenu.add(noHelpItem); return helpMenu; }
From source file:com.isencia.passerelle.hmi.generic.GenericHMI.java
public void addPrefsMenu(final JMenuBar menuBar) { final JMenu prefsMenu = new JMenu(HMIMessages.getString(HMIMessages.MENU_PREFS)); prefsMenu.setMnemonic(HMIMessages.getString(HMIMessages.MENU_PREFS + HMIMessages.KEY).charAt(0)); final JMenuItem layoutMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_LAYOUT), HMIMessages.getString(HMIMessages.MENU_LAYOUT + HMIMessages.KEY).charAt(0)); layoutMenuItem.addActionListener(new ColumnCountDialogOpener()); prefsMenu.add(layoutMenuItem); final JMenuItem actorOrderMenuItem = new JMenuItem(HMIMessages.getString(HMIMessages.MENU_ACTOR_ORDER), HMIMessages.getString(HMIMessages.MENU_ACTOR_ORDER + HMIMessages.KEY).charAt(0)); actorOrderMenuItem.addActionListener(new ActorOrderOpener()); prefsMenu.add(actorOrderMenuItem);//from ww w. j av a 2 s. c om final JMenuItem paramFilterMenuItem = new JMenuItem( HMIMessages.getString(HMIMessages.MENU_PARAM_VISIBILITY), HMIMessages.getString(HMIMessages.MENU_PARAM_VISIBILITY + HMIMessages.KEY).charAt(0)); paramFilterMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_MASK)); paramFilterMenuItem.addActionListener(new ParameterFilterOpener()); prefsMenu.add(paramFilterMenuItem); menuBar.add(prefsMenu); StateMachine.getInstance().registerActionForState(StateMachine.MODEL_OPEN, HMIMessages.MENU_PREFS, prefsMenu); }