List of usage examples for javax.swing JMenu setIcon
@BeanProperty(visualUpdate = true, description = "The button's default icon") public void setIcon(Icon defaultIcon)
From source file:org.openmicroscopy.shoola.agents.dataBrowser.view.PopupMenu.java
/** Builds and lays out the GUI. */ private void buildGUI() { setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED)); if (model.getType() == DataBrowserModel.GROUP) { add(resetPassword);/*ww w . j a va 2 s. c o m*/ add(activatedUser); add(buildEditMenu()); add(removeElement); } else { JMenu menu; String text = "View"; switch (DataBrowserAgent.runAsPlugin()) { case DataBrowser.IMAGE_J: menu = new JMenu(text); menu.setIcon(view.getIcon()); menu.add(view); menu.add(controller.getAction(DataBrowserControl.VIEW_IN_IJ)); add(menu); break; case DataBrowser.KNIME: menu = new JMenu(text); menu.setIcon(view.getIcon()); menu.add(view); menu.add(controller.getAction(DataBrowserControl.VIEW_IN_KNIME)); add(menu); break; default: add(view); } ; add(openWithMenu); add(new JSeparator(JSeparator.HORIZONTAL)); add(buildEditMenu()); add(removeElement); JMenu m = createMoveToMenu(); if (m != null) add(m); add(new JSeparator(JSeparator.HORIZONTAL)); add(tagElement); add(newExperimentElement); add(new JSeparator(JSeparator.HORIZONTAL)); add(buildRenderingSettingsMenu()); } }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.ToolBar.java
/** Creates or recycles the save as menu. */ private JPopupMenu createSaveAsMenu() { saveAsMenu = new JPopupMenu(); IconManager icons = IconManager.getInstance(); downloadItem = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD)); downloadItem.setToolTipText("Download the Archived File(s)."); downloadItem.setText("Download..."); downloadItem.addActionListener(controller); downloadItem.setActionCommand("" + EditorControl.DOWNLOAD); downloadItem.setBackground(UIUtilities.BACKGROUND_COLOR); List<DataObject> nodes = model.getSelectedObjects(); boolean b = false; if (!CollectionUtils.isEmpty(nodes)) { Iterator<DataObject> i = nodes.iterator(); while (i.hasNext()) { if (model.isArchived(i.next())) { b = true;/*from w ww .j ava 2s. c om*/ break; } } } downloadItem.setEnabled(b); saveAsMenu.add(downloadItem); downloadOriginalMetadataItem = new JMenuItem(icons.getIcon(IconManager.DOWNLOAD)); downloadOriginalMetadataItem.setToolTipText("Download the " + "metadata read from the image files."); downloadOriginalMetadataItem.setText("Download Original metadata..."); downloadOriginalMetadataItem.addActionListener(controller); downloadOriginalMetadataItem.setActionCommand("" + EditorControl.DOWNLOAD_METADATA); downloadOriginalMetadataItem.setBackground(UIUtilities.BACKGROUND_COLOR); downloadOriginalMetadataItem.setEnabled(model.hasOriginalMetadata()); saveAsMenu.add(downloadOriginalMetadataItem); exportAsOmeTiffItem = new JMenuItem(icons.getIcon(IconManager.EXPORT_AS_OMETIFF)); exportAsOmeTiffItem.setText("Export as OME-TIFF..."); exportAsOmeTiffItem.setToolTipText(EXPORT_AS_OME_TIFF_TOOLTIP); exportAsOmeTiffItem.addActionListener(controller); exportAsOmeTiffItem.setActionCommand("" + EditorControl.EXPORT_AS_OMETIFF); if (model.isMultiSelection()) b = false; else { b = model.getRefObject() instanceof ImageData && !model.isLargeImage(); } exportAsOmeTiffItem.setEnabled(b); saveAsMenu.add(exportAsOmeTiffItem); JMenu menu = new JMenu(); menu.setIcon(icons.getIcon(IconManager.SAVE_AS)); menu.setText("Save as..."); menu.setToolTipText("Save the images at full size as JPEG. PNG or" + "TIFF."); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent e) { int index = Integer.parseInt(e.getActionCommand()); controller.saveAs(index); } }; Map<Integer, String> formats = FigureParam.FORMATS; Entry<Integer, String> e; Iterator<Entry<Integer, String>> i = formats.entrySet().iterator(); JMenuItem item; Object ho = model.getRefObject(); boolean enabled = (ho instanceof ImageData || ho instanceof WellSampleData || ho instanceof DatasetData); while (i.hasNext()) { e = i.next(); item = new JMenuItem(); item.setText(e.getValue()); item.addActionListener(l); item.setActionCommand("" + e.getKey()); item.setEnabled(enabled); menu.add(item); } saveAsMenu.add(menu); setRootObject(); return saveAsMenu; }
From source file:org.openscience.jmol.app.Jmol.java
/** * Create a menu for the app. By default this pulls the * definition of the menu from the associated resource file. * @param key//from w w w . jav a 2 s . com * @return Menu created */ protected JMenu createMenu(String key) { // Get list of items from resource file: String[] itemKeys = tokenize(JmolResourceHandler.getStringX(key)); // Get label associated with this menu: JMenu menu = guimap.newJMenu(key); ImageIcon f = JmolResourceHandler.getIconX(key + "Image"); if (f != null) { menu.setHorizontalTextPosition(SwingConstants.RIGHT); menu.setIcon(f); } // Loop over the items in this menu: for (int i = 0; i < itemKeys.length; i++) { String item = itemKeys[i]; if (item.equals("-")) { menu.addSeparator(); continue; } if (item.endsWith("Menu")) { JMenu pm; if ("recentFilesMenu".equals(item)) { /*recentFilesMenu = */pm = createMenu(item); } else { pm = createMenu(item); } menu.add(pm); continue; } JMenuItem mi = createMenuItem(item); menu.add(mi); } menu.addMenuListener(display.getMenuListener()); return menu; }
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 w w w . j av a2 s . co m 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:org.pmedv.blackboard.components.BoardEditor.java
/** * Setup the context menu//www. ja v a2 s . co m * * TODO : Should be externalized into an XML based configuration file. */ private void hookContextMenu() { popupMenu = new JPopupMenu(); popupMenu.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.GRAY, 1), BorderFactory.createEmptyBorder(5, 5, 5, 5))); popupMenu.add(ctx.getBean(SetSelectModeCommand.class)); popupMenu.add(ctx.getBean(SetDrawModeCommand.class)); // popupMenu.add(ctx.getBean(SetMoveModeCommand.class)); popupMenu.add(ctx.getBean(SetColorCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(ToggleSnapToGridCommand.class)); popupMenu.add(ctx.getBean(ToggleGridCommand.class)); popupMenu.add(ctx.getBean(ToggleMirrorCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(BrowsePartsCommand.class)); popupMenu.add(ctx.getBean(AddResistorCommand.class)); popupMenu.add(ctx.getBean(ExportImageCommand.class)); popupMenu.add(ctx.getBean(AddTextCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(CopyCommand.class)); popupMenu.add(ctx.getBean(PasteCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(UndoCommand.class)); popupMenu.add(ctx.getBean(RedoCommand.class)); popupMenu.addSeparator(); popupMenu.add(deleteCommand); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(RotateCWCommand.class)); popupMenu.add(ctx.getBean(RotateCCWCommand.class)); popupMenu.add(ctx.getBean(FlipHorizontalCommand.class)); popupMenu.add(ctx.getBean(FlipVerticalCommand.class)); popupMenu.addSeparator(); popupMenu.add(ctx.getBean(MoveToLayerCommand.class)); popupMenu.add(ctx.getBean(ConvertToPartCommand.class)); popupMenu.add(ctx.getBean(ConvertToSymbolCommand.class)); popupMenu.add(ctx.getBean(BreakSymbolCommand.class)); popupMenu.add(ctx.getBean(AddSymbolToLibraryCommand.class)); popupMenu.addSeparator(); // popupMenu.add(ctx.getBean(EditPartCommand.class)); popupMenu.add(ctx.getBean(EditPropertiesCommand.class)); popupMenu.addSeparator(); final SimulateCircuitCommand simulateCommand = ctx.getBean(SimulateCircuitCommand.class); final JMenu simulatorMenu = new JMenu(resources.getResourceByKey("SimulateCircuitCommand.name")); simulatorMenu.setIcon(resources.getIcon("icon.simulate")); final SimulatorProvider provider = AppContext.getContext().getBean(SimulatorProvider.class); for (final SpiceSimulator simulator : provider.getElements()) { final JMenuItem item = new JMenuItem(simulator.getName()); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { simulateCommand.setSimulator(simulator); simulateCommand.execute(null); } }); simulatorMenu.add(item); } popupMenu.add(simulatorMenu); }
From source file:org.wmediumd.WmediumdGraphView.java
public WmediumdGraphView() { JMenuBar menuBar;//from www. j a v a2s .c om JMenu menu; JMenuItem menuItem; setup(); setupVisualization(); setupMouse(); // Let's add a menu for changing mouse modes menuBar = new JMenuBar(); menu = new JMenu(); menu.setText("File"); menu.setIcon(null); menuItem = new JMenuItem("New file"); menuItem.setIcon(UIManager.getIcon("FileView.fileIcon")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { // TODO Use the Factory MyNode.nodeCount = 0; MyLink.linkCount = 0; graph.clear(); frame.repaint(); } }); menu.add(menuItem); menuItem = new JMenuItem("Load file"); menuItem.setIcon(UIManager.getIcon("FileChooser.upFolderIcon")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { FileChooserLoad fl = new FileChooserLoad(); if (fl.getMatrixList().rates() == MyLink.rates) { MyNode.nodeCount = 0; MyLink.linkCount = 0; graph.clear(); graph.setDataFromMatrixList(fl.getMatrixList()); frame.repaint(); } } }); menu.add(menuItem); menuItem = new JMenuItem("Save as..."); menuItem.setIcon(UIManager.getIcon("FileView.floppyDriveIcon")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (MyNode.nodeCount > 1) { System.out.println(generateConfigString()); new FileChooserSave(generateConfigString()); } } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("Exit"); menuItem.setIcon(UIManager.getIcon("InternalFrame.closeIcon")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.exit(0); } }); menu.add(menuItem); menuBar.add(menu); menu = graphMouse.getModeMenu(); // Obtain mode menu from the mouse menu.setText("Edit"); menu.setIcon(null); // I'm using this in a main menu menu.setPreferredSize(new Dimension(40, 15)); // Change the size menuBar.add(menu); menu = new JMenu("Help"); menuItem = new JMenuItem("Help"); menuItem.setIcon(UIManager.getIcon("FileChooser.detailsViewIcon")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { openURL("http://o11s.org/trac/wiki/MeshTestingWmediumd#a4.1.Usingwconfig"); } }); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem("About"); menuItem.setIcon(UIManager.getIcon("FileChooser.homeFolderIcon")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JOptionPane.showMessageDialog( frame, "Wireless medium daemon\n" + "configuration tool <v0.2b>\n\n" + "(C) 2011 - Javier Lopez\n" + "<jlopex@gmail.com>\n", "About", JOptionPane.INFORMATION_MESSAGE); } }); menu.add(menuItem); menuBar.add(menu); graphMouse.setMode(ModalGraphMouse.Mode.EDITING); // Start off in editing mode vViewer.setGraphMouse(graphMouse); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setJMenuBar(menuBar); frame.getContentPane().add(vViewer); frame.pack(); frame.setVisible(true); }
From source file:phex.gui.actions.BanHostActionUtils.java
public static BanHostActionMenu createActionMenu(BanHostActionProvider addressProvider) { FWAction[] actions = new FWAction[4]; JMenu mainMenu = new JMenu(Localizer.getString("BanHostAction_BanHost")); mainMenu.setIcon(GUIRegistry.getInstance().getPlafIconPack().getIcon("Security.BanHost")); // 1 day/* www.j a v a 2 s. c om*/ BanHostAction action = new BanHostAction(Localizer.getString("BanHostAction_1Day"), addressProvider, ExpiryDate.getExpiryDate(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY)); actions[0] = action; mainMenu.add(action); // 7 days action = new BanHostAction(Localizer.getString("BanHostAction_7Days"), addressProvider, ExpiryDate.getExpiryDate(System.currentTimeMillis() + DateUtils.MILLIS_PER_DAY * 7)); actions[1] = action; mainMenu.add(action); // never action = new BanHostAction(Localizer.getString("BanHostAction_Unlimited"), addressProvider, ExpiryDate.getExpiryDate(ExpiryDate.EXPIRES_NEVER)); actions[2] = action; mainMenu.add(action); // custom action = new BanHostAction(Localizer.getString("BanHostAction_Custom"), addressProvider, null); actions[3] = action; mainMenu.add(action); // we return an extra wrapper class to have the option of two return // values. BanHostActionMenu actionMenu = new BanHostActionMenu(); actionMenu.menu = mainMenu; actionMenu.actions = actions; return actionMenu; }
From source file:pl.otros.logview.gui.LogViewPanel.java
private JPopupMenu initTableContextMenu() { JPopupMenu menu = new JPopupMenu("Menu"); JMenuItem mark = new JMenuItem("Mark selected rows"); mark.addActionListener(new MarkRowAction(otrosApplication)); JMenuItem unmark = new JMenuItem("Unmark selected rows"); unmark.addActionListener(new UnMarkRowAction(otrosApplication)); JMenuItem autoResizeMenu = new JMenu("Table auto resize mode"); autoResizeMenu.setIcon(Icons.TABLE_RESIZE); JMenuItem autoResizeSubsequent = new JMenuItem("Subsequent columns"); autoResizeSubsequent/*w ww . j a v a 2 s . c om*/ .addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS)); JMenuItem autoResizeLast = new JMenuItem("Last column"); autoResizeLast.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_LAST_COLUMN)); JMenuItem autoResizeNext = new JMenuItem("Next column"); autoResizeNext.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_NEXT_COLUMN)); JMenuItem autoResizeAll = new JMenuItem("All columns"); autoResizeAll.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_ALL_COLUMNS)); JMenuItem autoResizeOff = new JMenuItem("Auto resize off"); autoResizeOff.addActionListener(new TableResizeActionListener(table, JTable.AUTO_RESIZE_OFF)); autoResizeMenu.add(autoResizeSubsequent); autoResizeMenu.add(autoResizeOff); autoResizeMenu.add(autoResizeNext); autoResizeMenu.add(autoResizeLast); autoResizeMenu.add(autoResizeAll); JMenu removeMenu = new JMenu("Remove log events"); removeMenu.setFont(menuLabelFont); removeMenu.setIcon(Icons.BIN); JLabel removeLabel = new JLabel("Remove by:"); removeLabel.setFont(menuLabelFont); removeMenu.add(removeLabel); Map<String, Set<String>> propKeyValue = getPropertiesOfSelectedLogEvents(); for (AcceptCondition acceptCondition : acceptConditionList) { removeMenu.add(new JMenuItem(new RemoveByAcceptanceCriteria(acceptCondition, otrosApplication))); } for (String propertyKey : propKeyValue.keySet()) { for (String propertyValue : propKeyValue.get(propertyKey)) { PropertyAcceptCondition propAcceptCondition = new PropertyAcceptCondition(propertyKey, propertyValue); removeMenu .add(new JMenuItem(new RemoveByAcceptanceCriteria(propAcceptCondition, otrosApplication))); } } menu.add(new JSeparator()); JLabel labelMarkingRows = new JLabel("Marking/unmarking rows"); labelMarkingRows.setFont(menuLabelFont); menu.add(labelMarkingRows); menu.add(new JSeparator()); menu.add(mark); menu.add(unmark); JMenu[] markersMenu = getAutomaticMarkersMenu(); menu.add(markersMenu[0]); menu.add(markersMenu[1]); menu.add(new ClearMarkingsAction(otrosApplication)); menu.add(new JSeparator()); JLabel labelQuickFilters = new JLabel("Quick filters"); labelQuickFilters.setFont(menuLabelFont); menu.add(labelQuickFilters); menu.add(new JSeparator()); menu.add(focusOnThisThreadAction); menu.add(focusOnEventsAfter); menu.add(focusOnEventsBefore); menu.add(focusOnSelectedClassesAction); menu.add(ignoreSelectedEventsClasses); menu.add(focusOnSelectedLoggerNameAction); menu.add(showCallHierarchyAction); for (String propertyKey : propKeyValue.keySet()) { for (String propertyValue : propKeyValue.get(propertyKey)) { menu.add(new FocusOnSelectedPropertyAction(propertyFilter, propertyFilterPanel.getEnableCheckBox(), otrosApplication, propertyKey, propertyValue)); } } menu.add(new JSeparator()); menu.add(removeMenu); menu.add(new JSeparator()); JLabel labelTableOptions = new JLabel("Table options"); labelTableOptions.setFont(menuLabelFont); menu.add(labelTableOptions); menu.add(new JSeparator()); menu.add(autoResizeMenu); menu.add(new JSeparator()); List<MenuActionProvider> menuActionProviders = otrosApplication.getLogViewPanelMenuActionProvider(); for (MenuActionProvider menuActionProvider : menuActionProviders) { try { List<OtrosAction> actions = menuActionProvider.getActions(otrosApplication, this); if (actions == null) { continue; } for (OtrosAction action : actions) { menu.add(action); } } catch (Exception e) { LOGGER.log(Level.SEVERE, "Cant get action from from provider " + menuActionProvider, e); } } return menu; }
From source file:Samples.Advanced.GraphEditorDemo.java
/** * a driver for this demo// www . ja v a 2s. c o m */ @SuppressWarnings("serial") public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final GraphEditorDemo demo = new GraphEditorDemo(); JMenu menu = new JMenu("File"); menu.add(new AbstractAction("Make Image") { public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); int option = chooser.showSaveDialog(demo); if (option == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); demo.writeJPEGImage(file); } } }); menu.add(new AbstractAction("Print") { public void actionPerformed(ActionEvent e) { PrinterJob printJob = PrinterJob.getPrinterJob(); printJob.setPrintable(demo); if (printJob.printDialog()) { try { printJob.print(); } catch (Exception ex) { ex.printStackTrace(); } } } }); JPopupMenu.setDefaultLightWeightPopupEnabled(false); JMenuBar menuBar = new JMenuBar(); menuBar.add(menu); JMenu matrixMenu = new JMenu(); matrixMenu.setText("Matrix"); matrixMenu.setIcon(null); matrixMenu.setPreferredSize(new Dimension(80, 20)); menuBar.add(matrixMenu); JMenuItem copyMatrix = new JMenuItem("Copy Matrix to clipboard", KeyEvent.VK_C); copyMatrix.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); menuBar.add(copyMatrix); frame.setJMenuBar(menuBar); frame.getContentPane().add(demo); copyMatrix.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Vem textTransfer = new Vem(); //Set up Matrix List<Integer[]> graphMatrix = new ArrayList<Integer[]>(); int MatrixSize = graph.getVertexCount(); Integer[] activeV = new Integer[MatrixSize]; int count = 0; int activeVPos = 0; while (activeVPos < MatrixSize) { if (graph.containsVertex(count)) { activeV[activeVPos] = count; activeVPos++; } count++; } // sgv.g.getVertices().toArray() ((Integer[])(sgv.g.getVertices().toArray())) for (int i = 0; i < MatrixSize; i++) { Integer[] tempArray = new Integer[MatrixSize]; for (int j = 0; j < MatrixSize; j++) { if (graph.findEdge(activeV[i], activeV[j]) != null) { tempArray[j] = 1; } else { tempArray[j] = 0; } } graphMatrix.add(tempArray); } //graphMatrix.add(new Integer[]{1, 2, 3}); //graphMatrix.add(new Integer[]{4, 5 , 6, 7}); //System.out.println(matrixToString(graphMatrix)); //System.out.println(matrixToMathematica(graphMatrix)); textTransfer.setClipboardContents("" + matrixToMathematica(graphMatrix)); System.out.println("Clipboard contains:" + textTransfer.getClipboardContents()); } }); frame.pack(); frame.setVisible(true); }
From source file:utybo.branchingstorytree.swing.OpenBSTGUI.java
private JMenu createShortMenu() { JMenu shortMenu = new JMenu(); addDarkModeCallback(b -> {/*from ww w.ja v a2 s . c o m*/ shortMenu.setBackground(b ? OPENBST_BLUE.darker().darker() : OPENBST_BLUE.brighter()); shortMenu.setForeground(b ? Color.WHITE : OPENBST_BLUE); }); shortMenu.setBackground(OPENBST_BLUE.brighter()); shortMenu.setForeground(OPENBST_BLUE); shortMenu.setText(Lang.get("banner.title")); shortMenu.setIcon(new ImageIcon(Icons.getImage("Logo", 16))); JMenuItem label = new JMenuItem(Lang.get("menu.title")); label.setEnabled(false); shortMenu.add(label); shortMenu.addSeparator(); shortMenu.add( new JMenuItem(new AbstractAction(Lang.get("menu.open"), new ImageIcon(Icons.getImage("Open", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { openStory(VisualsUtils.askForFile(OpenBSTGUI.this, Lang.get("file.title"))); } })); shortMenu.addSeparator(); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.create"), new ImageIcon(Icons.getImage("Add Property", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { doNewEditor(); } })); JMenu additionalMenu = new JMenu(Lang.get("menu.advanced")); shortMenu.add(additionalMenu); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.package"), new ImageIcon(Icons.getImage("Open Archive", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new PackageDialog(instance).setVisible(true); } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("langcheck"), new ImageIcon(Icons.getImage("LangCheck", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { final Map<String, String> languages = new Gson() .fromJson(new InputStreamReader( OpenBST.class.getResourceAsStream( "/utybo/branchingstorytree/swing/lang/langs.json"), StandardCharsets.UTF_8), new TypeToken<Map<String, String>>() { }.getType()); languages.remove("en"); languages.remove("default"); JComboBox<String> jcb = new JComboBox<>(new Vector<>(languages.keySet())); JPanel panel = new JPanel(); panel.add(new JLabel(Lang.get("langcheck.choose"))); panel.add(jcb); int result = JOptionPane.showOptionDialog(OpenBSTGUI.this, panel, Lang.get("langcheck"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { Locale selected = new Locale((String) jcb.getSelectedItem()); if (!Lang.getMap().keySet().contains(selected)) { try { Lang.loadTranslationsFromFile(selected, OpenBST.class .getResourceAsStream("/utybo/branchingstorytree/swing/lang/" + languages.get(jcb.getSelectedItem().toString()))); } catch (UnrespectedModelException | IOException e1) { LOG.warn("Failed to load translation file", e1); } } ArrayList<String> list = new ArrayList<>(); Lang.getLocaleMap(Locale.ENGLISH).forEach((k, v) -> { if (!Lang.getLocaleMap(selected).containsKey(k)) { list.add(k + "\n"); } }); StringBuilder sb = new StringBuilder(); Collections.sort(list); list.forEach(s -> sb.append(s)); JDialog dialog = new JDialog(OpenBSTGUI.this, Lang.get("langcheck")); dialog.getContentPane().setLayout(new MigLayout()); dialog.getContentPane().add(new JLabel(Lang.get("langcheck.result")), "pushx, growx, wrap"); JTextArea area = new JTextArea(); area.setLineWrap(true); area.setWrapStyleWord(true); area.setText(sb.toString()); area.setEditable(false); area.setBorder(BorderFactory.createLoweredBevelBorder()); JScrollPane jsp = new JScrollPane(area); jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); dialog.getContentPane().add(jsp, "pushx, pushy, growx, growy"); dialog.setSize((int) (Icons.getScale() * 300), (int) (Icons.getScale() * 300)); dialog.setLocationRelativeTo(OpenBSTGUI.this); dialog.setModalityType(ModalityType.APPLICATION_MODAL); dialog.setVisible(true); } } })); additionalMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.debug"), new ImageIcon(Icons.getImage("Code", 16))) { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { DebugInfo.launch(OpenBSTGUI.this); } })); JMenu includedFiles = new JMenu("Included BST files"); for (Entry<String, String> entry : OpenBST.getInternalFiles().entrySet()) { JMenuItem jmi = new JMenuItem(entry.getKey()); jmi.addActionListener(ev -> { String path = "/bst/" + entry.getValue(); InputStream is = OpenBSTGUI.class.getResourceAsStream(path); ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(OpenBSTGUI.this, "Extracting...", is); new Thread(() -> { try { File f = File.createTempFile("openbstinternal", ".bsp"); FileOutputStream fos = new FileOutputStream(f); IOUtils.copy(pmis, fos); openStory(f); } catch (final IOException e) { LOG.error("IOException caught", e); showException(Lang.get("file.error").replace("$e", e.getClass().getSimpleName()) .replace("$m", e.getMessage()), e); } }).start(); }); includedFiles.add(jmi); } additionalMenu.add(includedFiles); shortMenu.addSeparator(); JMenu themesMenu = new JMenu(Lang.get("menu.themes")); shortMenu.add(themesMenu); themesMenu.setIcon(new ImageIcon(Icons.getImage("Color Wheel", 16))); ButtonGroup themesGroup = new ButtonGroup(); JRadioButtonMenuItem jrbmi; jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.dark")); if (0 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(0, DARK_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.light")); if (1 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(1, LIGHT_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); jrbmi = new JRadioButtonMenuItem(Lang.get("menu.themes.debug")); if (2 == selectedTheme) { jrbmi.setSelected(true); } jrbmi.addActionListener(e -> switchLaF(2, DEBUG_THEME)); themesMenu.add(jrbmi); themesGroup.add(jrbmi); JMenu additionalLightThemesMenu = new JMenu(Lang.get("menu.themes.morelight")); int j = 3; for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_LIGHT_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalLightThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalLightThemesMenu); JMenu additionalDarkThemesMenu = new JMenu(Lang.get("menu.themes.moredark")); for (Map.Entry<String, LookAndFeel> entry : ADDITIONAL_DARK_THEMES.entrySet()) { int jf = j; jrbmi = new JRadioButtonMenuItem(entry.getKey()); if (j == selectedTheme) jrbmi.setSelected(true); jrbmi.addActionListener(e -> switchLaF(jf, entry.getValue())); additionalDarkThemesMenu.add(jrbmi); themesGroup.add(jrbmi); j++; } themesMenu.add(additionalDarkThemesMenu); shortMenu.add(new JMenuItem( new AbstractAction(Lang.get("menu.about"), new ImageIcon(Icons.getImage("About", 16))) { /** * */ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { new AboutDialog(instance).setVisible(true); } })); return shortMenu; }