List of usage examples for javax.swing JCheckBoxMenuItem JCheckBoxMenuItem
public JCheckBoxMenuItem(Action a)
From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java
/** * Helper method to create the unit bar sub-menu. * //from w w w. j a va 2s . c om * @param pref The user preferences. * @return See above. */ private JMenu createScaleBarLengthSubMenu(ViewerPreferences pref) { scaleBarMenu = new JMenu(SCALE_BAR_TEXT + model.getUnits() + ")"); scaleBarGroup = new ButtonGroup(); if (pref != null && pref.getScaleBarIndex() > 0) defaultIndex = pref.getScaleBarIndex(); UnitBarSizeAction a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_ONE); JCheckBoxMenuItem item = new JCheckBoxMenuItem(a); item.setSelected(a.getIndex() == defaultIndex); scaleBarGroup.add(item); scaleBarMenu.add(item); a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_TWO); item = new JCheckBoxMenuItem(a); item.setSelected(a.getIndex() == defaultIndex); scaleBarGroup.add(item); scaleBarMenu.add(item); a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_FIVE); item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.UNIT_BAR_FIVE)); scaleBarGroup.add(item); item.setSelected(a.getIndex() == defaultIndex); scaleBarMenu.add(item); a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_TEN); item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.UNIT_BAR_TEN)); scaleBarGroup.add(item); item.setSelected(a.getIndex() == defaultIndex); scaleBarMenu.add(item); a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_TWENTY); item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.UNIT_BAR_TWENTY)); scaleBarGroup.add(item); item.setSelected(a.getIndex() == defaultIndex); scaleBarMenu.add(item); a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_FIFTY); item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.UNIT_BAR_FIFTY)); scaleBarGroup.add(item); item.setSelected(a.getIndex() == defaultIndex); scaleBarMenu.add(item); a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_HUNDRED); item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.UNIT_BAR_HUNDRED)); scaleBarGroup.add(item); item.setSelected(a.getIndex() == defaultIndex); scaleBarMenu.add(item); a = (UnitBarSizeAction) controller.getAction(ImViewerControl.UNIT_BAR_CUSTOM); item = new JCheckBoxMenuItem(controller.getAction(ImViewerControl.UNIT_BAR_CUSTOM)); scaleBarGroup.add(item); item.setSelected(a.getIndex() == defaultIndex); scaleBarMenu.add(item); return scaleBarMenu; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java
/** * Creates a menu item.//from ww w. j a v a 2 s . c o m * * @param index The index associated to the item. * @return See above. */ private JCheckBoxMenuItem createMenuItem(int index) { JCheckBoxMenuItem item = new JCheckBoxMenuItem(NAMES[index]); Font f = item.getFont(); item.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2)); item.setSelected(filter == index); item.addActionListener(this); item.setActionCommand("" + index); return item; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Creates the items for the menu./*from ww w .j a v a 2 s. c om*/ * * @param add Pass <code>true</code> to build items for the <code>Add</code> * menu, <code>false</code> otherwise. * @return See above */ private List<JMenuItem> createMenuItem(boolean add) { List<JMenuItem> items = new ArrayList<JMenuItem>(); List<GroupSelectionAction> l = controller.getUserGroupAction(add); Iterator<GroupSelectionAction> i = l.iterator(); GroupSelectionAction a; JMenuItem item; if (add) { //Check the groups that already in the view. Browser browser = model.getSelectedBrowser(); List<Long> ids = new ArrayList<Long>(); if (browser != null) { ExperimenterVisitor v = new ExperimenterVisitor(browser, -1); browser.accept(v, ExperimenterVisitor.TREEIMAGE_SET_ONLY); List<TreeImageDisplay> nodes = v.getNodes(); Iterator<TreeImageDisplay> j = nodes.iterator(); TreeImageDisplay node; while (j.hasNext()) { node = j.next(); ids.add(((GroupData) node.getUserObject()).getId()); } } while (i.hasNext()) { a = i.next(); item = new JMenuItem(a); if (ids.size() > 0) { item.setEnabled(!ids.contains(a.getGroupId())); } else item.setEnabled(true); initMenuItem(item); items.add(item); } } else { ButtonGroup buttonGroup = new ButtonGroup(); long id = model.getSelectedGroupId(); while (i.hasNext()) { a = i.next(); item = new JCheckBoxMenuItem(a); item.setEnabled(true); item.setSelected(a.isSameGroup(id)); initMenuItem(item); buttonGroup.add(item); items.add(item); } } return items; }
From source file:org.pmedv.core.provider.ApplicationMenuBarProviderImpl.java
@SuppressWarnings("unused") public ApplicationMenuBarProviderImpl() { populateKeyTable();//w w w . j a va2 s .c om menubar = new JMenuBar(); try { JAXBContext c = JAXBContext.newInstance(ApplicationMenubar.class); Unmarshaller u = c.createUnmarshaller(); ApplicationMenubar appMenuBar = (ApplicationMenubar) u .unmarshal(getClass().getClassLoader().getResourceAsStream("menus.xml")); for (ApplicationMenu currentMenu : appMenuBar.getMenus()) { JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(currentMenu.getName())); menu.setMnemonic(resources.getResourceByKey(currentMenu.getName()).charAt(0)); for (ApplicationMenuItem currentItem : currentMenu.getItems()) { try { if (currentItem.getActionClass() != null) { if (currentItem.getActionClass().equals("separator")) { menu.addSeparator(); continue; } log.info("Mapping action class : " + currentItem.getActionClass()); try { AbstractCommand command = null; Class<?> clazz = Class.forName(currentItem.getActionClass()); if (currentItem.isBean()) { command = (AbstractCommand) ctx.getBean(clazz); } else { command = (AbstractCommand) clazz.newInstance(); } ImageIcon icon = null; String mnemonic = null; String toolTipText = null; if (currentItem.getImageIcon() != null) { InputStream is = getClass().getClassLoader() .getResourceAsStream(currentItem.getImageIcon()); if (is == null) { is = getClass().getClassLoader() .getResourceAsStream("icons/noresource_16x16.png"); } icon = new ImageIcon(ImageIO.read(is)); } if (currentItem.getMnemonic() != null) { mnemonic = currentItem.getMnemonic(); } if (currentItem.getToolTipText() != null) { toolTipText = currentItem.getToolTipText(); } if (currentItem.getType() != null && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) { CmdJCheckBoxMenuItem cmdItem = new CmdJCheckBoxMenuItem(currentItem.getName(), icon, command, mnemonic, toolTipText, null); if (mnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); } else { JMenuItem cmdItem = new JMenuItem(command); if (mnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); } } catch (InstantiationException e) { log.info("could not instanciate menuitem, skipping."); } catch (IllegalAccessException e) { log.info("could not access menuitem, skipping."); } } } catch (ClassNotFoundException e) { log.info("could not find action class " + currentItem.getActionClass()); } } if (currentMenu.getType() != null && currentMenu.getType().equalsIgnoreCase("file")) { JMenu openRecentMenu = new JMenu(resources.getResourceByKey("menu.recentfiles")); RecentFileList fileList = null; try { String inputDir = System.getProperty("user.home") + "/." + AppContext.getName() + "/"; String inputFileName = "recentFiles.xml"; File inputFile = new File(inputDir + inputFileName); if (inputFile.exists()) { Unmarshaller u1 = JAXBContext.newInstance(RecentFileList.class).createUnmarshaller(); fileList = (RecentFileList) u1.unmarshal(inputFile); } if (fileList == null) fileList = new RecentFileList(); ArrayList<String> recent = fileList.getRecentFiles(); Collections.reverse(recent); for (String recentFile : fileList.getRecentFiles()) { File file = new File(recentFile); AbstractCommand openBoardAction = new OpenBoardCommand(file.getName(), file); JMenuItem item = new JMenuItem(openBoardAction); openRecentMenu.add(item); } } catch (JAXBException e) { e.printStackTrace(); } menu.addSeparator(); menu.add(openRecentMenu); JMenu openSamplesMenu = createSamplesMenu(); menu.add(openSamplesMenu); } menu.setId("common"); if (currentMenu.getType() != null && !currentMenu.getType().equalsIgnoreCase("help")) menubar.add(menu); else helpMenus.add(menu); menubar.setFont(new Font("SansSerif", Font.PLAIN, 12)); } ApplicationPerspectiveProvider perspectiveProvider = ctx.getBean(ApplicationPerspectiveProvider.class); ArrayList<ApplicationPerspective> perspectives = perspectiveProvider.getPerspectives(); JMenuWithId perspectivesMenu = new JMenuWithId("Perspectives"); perspectivesMenu.setId("common"); perspectivesMenu.setMnemonic('P'); for (ApplicationPerspective perspective : perspectives) { ImageIcon icon = null; String mnemonic = null; String toolTipText = null; if (perspective.getPerspectiveIcon() != null) { InputStream is = getClass().getClassLoader() .getResourceAsStream(perspective.getPerspectiveIcon()); if (is != null) { icon = new ImageIcon(ImageIO.read(is)); } else { is = getClass().getClassLoader().getResourceAsStream("icons/noresource_16x16.png"); if (is != null) icon = new ImageIcon(ImageIO.read(is)); } } if (perspective.getMnemonic() != null) { mnemonic = perspective.getMnemonic(); } if (perspective.getToolTipText() != null) { toolTipText = perspective.getToolTipText(); } log.info("mapping perspective class " + perspective.getPerspectiveClass()); OpenPerspectiveCommand command = new OpenPerspectiveCommand(perspective.getId()); JMenuItem item = new JMenuItem(command); if (mnemonic != null && perspective.getModifier() != null) { if (perspective.getModifier().equalsIgnoreCase("ctrl")) { item.setAccelerator( KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false)); } else if (perspective.getModifier().equalsIgnoreCase("alt")) { item.setAccelerator( KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false)); } else if (perspective.getModifier().equalsIgnoreCase("shift")) { item.setAccelerator( KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false)); } } perspectivesMenu.add(item); for (ApplicationMenu pMenu : perspective.getMenubarContributions()) { JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(pMenu.getName())); // if (pMenu.getMnemonic() != null && pMenu.getMnemonic().length() > 0) menu.setMnemonic(resources.getResourceByKey(pMenu.getName()).charAt(0)); for (ApplicationMenuItem currentItem : pMenu.getItems()) { try { if (currentItem.getActionClass() != null) { if (currentItem.getActionClass().equals("separator")) { menu.addSeparator(); continue; } log.info("Mapping action class : " + currentItem.getActionClass()); try { AbstractCommand pCommand = null; Class<?> clazz = Class.forName(currentItem.getActionClass()); if (currentItem.isBean()) { pCommand = (AbstractCommand) ctx.getBean(clazz); } else { pCommand = (AbstractCommand) clazz.newInstance(); } ImageIcon pIcon = null; String pMnemonic = null; String pToolTipText = null; if (currentItem.getImageIcon() != null) { InputStream is = getClass().getClassLoader() .getResourceAsStream(currentItem.getImageIcon()); pIcon = new ImageIcon(ImageIO.read(is)); } if (currentItem.getMnemonic() != null) { pMnemonic = currentItem.getMnemonic(); } if (currentItem.getToolTipText() != null) { pToolTipText = currentItem.getToolTipText(); } if (currentItem.getType() != null && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) { log.info( "Creating menu checkbox for class " + currentItem.getActionClass()); JCheckBoxMenuItem cmdItem = new JCheckBoxMenuItem(pCommand); if (pMnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); cmdItem.setSelected(true); } else { log.info("Creating menu entry for class " + currentItem.getActionClass()); JMenuItem cmdItem = new JMenuItem(pCommand); if (pMnemonic != null && currentItem.getModifier() != null) { if (currentItem.getModifier().equalsIgnoreCase("ctrl")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.CTRL_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("alt")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.ALT_MASK, false)); } else if (currentItem.getModifier().equalsIgnoreCase("shift")) { cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic), InputEvent.SHIFT_MASK, false)); } } menu.add(cmdItem); } } catch (InstantiationException e) { log.info("could not instanciate menuitem, skipping."); } catch (IllegalAccessException e) { log.info("could not access menuitem, skipping."); } } } catch (ClassNotFoundException e) { log.info("could not find action class " + currentItem.getActionClass()); } } menu.setId(perspective.getId()); menu.setVisible(false); menubar.add(menu); } } if (perspectiveProvider.getPerspectives().size() > 1) { menubar.add(perspectivesMenu); } for (JMenuWithId helpmenu : helpMenus) { menubar.add(helpmenu); } menubar.setFont(new Font("SansSerif", Font.PLAIN, 12)); } catch (JAXBException e) { log.info("could not deserialize menus."); throw new RuntimeException("could not deserialize menus."); } catch (IOException e) { log.info("could not load menus."); throw new RuntimeException("could not load menus."); } }
From source file:org.rdv.DockingDataPanelManager.java
/** * Creates the menu where individual window bars can be enabled and disabled. * * @return the window bar menu//from w ww .ja va2 s . c o m */ private JMenu createWindowBarsMenu() { JMenu barsMenu = new JMenu("Window Bars"); for (int i = 0; i < 4; i++) { final Direction d = Direction.getDirections()[i]; JCheckBoxMenuItem item = new JCheckBoxMenuItem("Toggle " + d); item.setSelected(rootWindow_.getWindowBar(d).isEnabled()); barsMenu.add(item).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Enable/disable the window bar rootWindow_.getWindowBar(d).setEnabled(!rootWindow_.getWindowBar(d).isEnabled()); } }); } return barsMenu; }
From source file:org.rdv.DockingDataPanelManager.java
/** * Creates the menu where the theme can be changed. * * @return the theme menu/* w w w.ja va2s .com*/ */ private JMenu createThemesMenu() { JMenu themesMenu = new JMenu("Themes"); // don't get the title bar window thing final JCheckBoxMenuItem titleBarStyleItem = new JCheckBoxMenuItem("Title Bar Style Theme"); titleBarStyleItem.setSelected(titleBarTheme_); titleBarStyleItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!titleBarTheme_) properties_.addSuperObject(titleBarStyleProperties); else { // TODO this does not work to remove title bars from windows properties_.removeSuperObject(titleBarStyleProperties); } titleBarTheme_ = !titleBarTheme_; } }); themesMenu.add(titleBarStyleItem); themesMenu.add(new JSeparator()); DockingWindowsTheme[] themes = { new DefaultDockingTheme(), new LookAndFeelDockingTheme(), new BlueHighlightDockingTheme(), new SlimFlatDockingTheme(), new GradientDockingTheme(), new ShapedGradientDockingTheme(), new SoftBlueIceDockingTheme(), new ClassicDockingTheme() }; ButtonGroup group = new ButtonGroup(); for (int i = 0; i < themes.length; i++) { final DockingWindowsTheme theme = themes[i]; JRadioButtonMenuItem item = new JRadioButtonMenuItem(theme.getName()); item.setSelected(themes[i].getClass() == currentTheme_.getClass()); group.add(item); themesMenu.add(item).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Clear the modified properties values properties_.getMap().clear(true); setTheme(theme); } }); } return themesMenu; }
From source file:org.rdv.ui.MainPanel.java
private void initMenuBar() { Application application = RDV.getInstance(); ApplicationContext context = application.getContext(); ResourceMap resourceMap = context.getResourceMap(); String platform = resourceMap.getString("platform"); boolean isMac = (platform != null && platform.equals("osx")); ActionFactory actionFactory = ActionFactory.getInstance(); Actions actions = Actions.getInstance(); ActionMap actionMap = context.getActionMap(actions); menuBar = new JMenuBar(); JMenuItem menuItem;// w w w . ja va 2 s .c o m JMenu fileMenu = new JMenu(fileAction); menuItem = new JMenuItem(connectAction); fileMenu.add(menuItem); menuItem = new JMenuItem(disconnectAction); fileMenu.add(menuItem); fileMenu.addSeparator(); menuItem = new JMenuItem(loginAction); fileMenu.add(menuItem); menuItem = new JMenuItem(logoutAction); fileMenu.add(menuItem); fileMenu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent arg0) { } public void menuDeselected(MenuEvent arg0) { } public void menuSelected(MenuEvent arg0) { if (AuthenticationManager.getInstance().getAuthentication() == null) { loginAction.setEnabled(true); logoutAction.setEnabled(false); } else { loginAction.setEnabled(false); logoutAction.setEnabled(true); } } }); fileMenu.addSeparator(); menuItem = new JMenuItem(loadAction); fileMenu.add(menuItem); menuItem = new JMenuItem(saveAction); fileMenu.add(menuItem); fileMenu.addSeparator(); fileMenu.add(new JMenuItem(actionMap.get("addLocalChannel"))); fileMenu.addSeparator(); JMenu importSubMenu = new JMenu(importAction); menuItem = new JMenuItem(actionFactory.getDataImportAction()); importSubMenu.add(menuItem); menuItem = new JMenuItem(actionFactory.getOpenSeesDataImportAction()); importSubMenu.add(menuItem); importSubMenu.add(new JMenuItem(actionMap.get("importJPEGs"))); fileMenu.add(importSubMenu); JMenu exportSubMenu = new JMenu(exportAction); menuItem = new JMenuItem(actionFactory.getDataExportAction()); exportSubMenu.add(menuItem); menuItem = new JMenuItem(exportVideoAction); exportSubMenu.add(menuItem); fileMenu.add(exportSubMenu); fileMenu.addSeparator(); menuItem = new DataViewerCheckBoxMenuItem(actionFactory.getOfflineAction()); fileMenu.add(menuItem); if (!isMac) { menuItem = new JMenuItem(exitAction); fileMenu.add(menuItem); } menuBar.add(fileMenu); JMenu controlMenu = new JMenu(controlAction); menuItem = new SelectableCheckBoxMenuItem(realTimeAction); controlMenu.add(menuItem); menuItem = new SelectableCheckBoxMenuItem(playAction); controlMenu.add(menuItem); menuItem = new SelectableCheckBoxMenuItem(pauseAction); controlMenu.add(menuItem); controlMenu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent arg0) { } public void menuDeselected(MenuEvent arg0) { } public void menuSelected(MenuEvent arg0) { int state = rbnb.getState(); realTimeAction.setSelected(state == Player.STATE_MONITORING); playAction.setSelected(state == Player.STATE_PLAYING); pauseAction.setSelected(state == Player.STATE_STOPPED); } }); controlMenu.addSeparator(); menuItem = new JMenuItem(beginningAction); controlMenu.add(menuItem); menuItem = new JMenuItem(endAction); controlMenu.add(menuItem); menuItem = new JMenuItem(gotoTimeAction); controlMenu.add(menuItem); menuBar.add(controlMenu); controlMenu.addSeparator(); menuItem = new JMenuItem(updateChannelListAction); controlMenu.add(menuItem); controlMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(dropDataAction); controlMenu.add(menuItem); JMenu viewMenu = new JMenu(viewAction); menuItem = new JCheckBoxMenuItem(showChannelListAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showMetadataPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showControlPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showAudioPlayerPanelAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showMarkerPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(showHiddenChannelsAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(hideEmptyTimeAction); menuItem.setSelected(false); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(fullScreenAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuBar.add(viewMenu); JMenu windowMenu = new JMenu(windowAction); List<Extension> extensions = dataPanelManager.getExtensions(); for (final Extension extension : extensions) { Action action = new DataViewerAction("Add " + extension.getName(), "", KeyEvent.VK_J) { /** serialization version identifier */ private static final long serialVersionUID = 36998228704476723L; public void actionPerformed(ActionEvent ae) { try { dataPanelManager.createDataPanel(extension); } catch (Exception e) { log.error("Unable to open data panel provided by extension " + extension.getName() + " (" + extension.getID() + ")."); e.printStackTrace(); } } }; menuItem = new JMenuItem(action); windowMenu.add(menuItem); } windowMenu.addSeparator(); menuItem = new JMenuItem(closeAllDataPanelsAction); windowMenu.add(menuItem); windowMenu.addSeparator(); JMenu dataPanelSubMenu = new JMenu(dataPanelAction); ButtonGroup dataPanelLayoutGroup = new ButtonGroup(); menuItem = new JRadioButtonMenuItem(dataPanelHorizontalLayoutAction); dataPanelSubMenu.add(menuItem); dataPanelLayoutGroup.add(menuItem); menuItem = new JRadioButtonMenuItem(dataPanelVerticalLayoutAction); menuItem.setSelected(true); dataPanelSubMenu.add(menuItem); dataPanelLayoutGroup.add(menuItem); windowMenu.add(dataPanelSubMenu); menuBar.add(windowMenu); JMenu helpMenu = new JMenu(helpAction); menuItem = new JMenuItem(usersGuideAction); helpMenu.add(menuItem); menuItem = new JMenuItem(supportAction); helpMenu.add(menuItem); menuItem = new JMenuItem(releaseNotesAction); helpMenu.add(menuItem); if (!isMac) { helpMenu.addSeparator(); menuItem = new JMenuItem(aboutAction); helpMenu.add(menuItem); } menuBar.add(helpMenu); menuBar.add(Box.createHorizontalGlue()); throbberStop = DataViewer.getIcon("icons/throbber.png"); throbberAnim = DataViewer.getIcon("icons/throbber_anim.gif"); throbber = new JLabel(throbberStop); throbber.setBorder(new EmptyBorder(0, 0, 0, 4)); menuBar.add(throbber, BorderLayout.EAST); if (isMac) { registerMacOSXEvents(); } frame.setJMenuBar(menuBar); }
From source file:org.rivalry.swingui.table.VisibleColumnsPopupMenu.java
/** * @param criterion Criterion.//w ww .j a v a2 s . c o m * * @return a new menu item. */ private JMenuItem createMenuItem(final Criterion criterion) { final String columnName = criterion.getName(); final JCheckBoxMenuItem answer = new JCheckBoxMenuItem(columnName); final boolean isVisible = _tableModel.isColumnVisible(columnName); answer.setSelected(isVisible); answer.addActionListener(createActionListener()); return answer; }
From source file:org.tros.logo.swing.LogoMenuBar.java
/** * Constructor.//from w w w . j a va2 s . c o m * * @param parent * @param controller * @param canvas */ @SuppressWarnings("OverridableMethodCallInConstructor") public LogoMenuBar(Component parent, Controller controller, LogoCanvas canvas) { super(parent, controller); this.canvas = canvas; add(setupExportMenu()); add(setupToolsMenu()); JMenu menu = new JMenu("Logo Options"); menu.add(setupMenu("Examples From Tortue", "logo/examples/tortue")); menu.add(setupMenu("Examples From ANTLR", "logo/examples/antlr")); final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(LogoMenuBar.class); final JCheckBoxMenuItem speedMenu = new JCheckBoxMenuItem("Wait for Repaint"); boolean checked = prefs.getBoolean(WAIT_FOR_REPAINT, true); speedMenu.setSelected(checked); speedMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.putBoolean(WAIT_FOR_REPAINT, speedMenu.isSelected()); } }); menu.add(speedMenu); add(menu); }
From source file:org.tros.torgo.ControllerBase.java
/** * Initialize the window. This is called here from run() and not the * constructor so that the Service Provider doesn't load up all of the * necessary resources when the application loads. *///from w w w .ja v a 2 s .co m private void initSwing() { this.torgoPanel = createConsole((Controller) this); this.torgoCanvas = createCanvas(torgoPanel); //init the GUI w/ the components... Container contentPane = window.getContentPane(); JToolBar tb = createToolBar(); if (tb != null) { contentPane.add(tb, BorderLayout.NORTH); } final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(NamedWindow.class); if (torgoCanvas != null) { final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, torgoCanvas.getComponent(), torgoPanel.getComponent()); int dividerLocation = prefs.getInt(this.getClass().getName() + "divider-location", window.getWidth() - 300); splitPane.setDividerLocation(dividerLocation); splitPane.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent pce) { prefs.putInt(this.getClass().getName() + "divider-location", splitPane.getDividerLocation()); } }); contentPane.add(splitPane); } else { contentPane.add(torgoPanel.getComponent()); } JMenuBar mb = createMenuBar(); if (mb == null) { mb = new TorgoMenuBar(window, this); } window.setJMenuBar(mb); JMenu helpMenu = new JMenu("Help"); JMenuItem aboutMenu = new JMenuItem("About Torgo"); try { java.util.Enumeration<URL> resources = ClassLoader.getSystemClassLoader() .getResources(ABOUT_MENU_TORGO_ICON); ImageIcon ico = new ImageIcon(resources.nextElement()); aboutMenu.setIcon(ico); } catch (IOException ex) { Logger.getLogger(ControllerBase.class.getName()).log(Level.SEVERE, null, ex); } aboutMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { AboutWindow aw = new AboutWindow(); aw.setVisible(true); } }); helpMenu.add(aboutMenu); JMenu vizMenu = new JMenu("Visualization"); for (String name : TorgoToolkit.getVisualizers()) { JCheckBoxMenuItem item = new JCheckBoxMenuItem(name); viz.add(item); vizMenu.add(item); } if (vizMenu.getItemCount() > 0) { mb.add(vizMenu); } mb.add(helpMenu); window.setJMenuBar(mb); window.addWindowListener(new WindowListener() { @Override public void windowOpened(WindowEvent e) { } /** * We only care if the window is closing so we can kill the * interpreter thread. * * @param e */ @Override public void windowClosing(WindowEvent e) { stopInterpreter(); } @Override public void windowClosed(WindowEvent e) { } @Override public void windowIconified(WindowEvent e) { } @Override public void windowDeiconified(WindowEvent e) { } @Override public void windowActivated(WindowEvent e) { } @Override public void windowDeactivated(WindowEvent e) { } }); }