List of usage examples for javax.swing JCheckBoxMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java
protected JPopupMenu createPopupMenuEntity(final mxCell cell, boolean newCell) { final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate(); JPopupMenu pop = new JPopupMenu(); JMenuItem i1 = new JMenuItem( localeDelegate.getMessage("nuclos.entityrelation.editor.14", "Symbol l\u00f6schen")); i1.addActionListener(new ActionListener() { @Override/*from ww w.j ava 2s .co m*/ public void actionPerformed(ActionEvent e) { mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); int iEdge = cell.getEdgeCount(); for (int i = 0; i < iEdge; i++) { mxCell cellRelation = (mxCell) cell.getEdgeAt(0); model.remove(cellRelation); } model.remove(cell); fireChangeListenEvent(); } }); if (!newCell) pop.add(i1); if (cell.getStyle() == null || !(cell.getStyle().indexOf(ENTITYSTYLE) >= 0)) { return pop; } JMenuItem iWizard = new JMenuItem( localeDelegate.getMessage("nuclos.entityrelation.editor.15", "Wizard \u00f6ffnen")); iWizard.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) { String sValue = ((EntityMetaDataVO) cell.getValue()).getEntity(); if (sValue.length() > 0) { try { final EntityMetaDataVO vo = MetaDataClientProvider.getInstance().getEntity(sValue); new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run(); } catch (Exception e1) { // neue Entity LOG.info("actionPerformed: " + e1 + " (new entity?)"); } } } } }); if (!newCell) { //pop.addSeparator(); pop.add(iWizard); } else { JMenuItem iNew = new JMenuItem( localeDelegate.getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t")); iNew.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) { final EntityMetaDataVO voTMP = (EntityMetaDataVO) cell.getValue(); final EntityMetaDataVO vo = MetaDataClientProvider.getInstance() .getEntity(voTMP.getEntity()); new ShowNuclosWizard.NuclosWizardEditRunnable(false, mf.getHomePane(), vo).run(); } else { cell.setValue( localeDelegate.getMessage("nuclos.entityrelation.editor.16", "neue Entit\u00e4t")); mxGraph graph = graphComponent.getGraph(); graph.refresh(); } } }); pop.add(iNew); } //pop.addSeparator(); Collection<EntityMetaDataVO> colMetaVO = MetaDataClientProvider.getInstance().getAllEntities(); List<EntityMetaDataVO> lst = new ArrayList<EntityMetaDataVO>(colMetaVO); Collections.sort(lst, new Comparator<EntityMetaDataVO>() { @Override public int compare(EntityMetaDataVO o1, EntityMetaDataVO o2) { return o1.getEntity().toLowerCase().compareTo(o2.getEntity().toLowerCase()); } }); for (final EntityMetaDataVO vo : lst) { if (vo.getEntity().startsWith("nuclos_")) continue; JCheckBoxMenuItem menu = new JCheckBoxMenuItem(vo.getEntity()); menu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JMenuItem item = (JMenuItem) e.getSource(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { cell.setValue(vo); graphComponent.repaint(); fireChangeListenEvent(); } }); } }); if (cell.getValue() != null && cell.getValue() instanceof EntityMetaDataVO) { EntityMetaDataVO sValue = (EntityMetaDataVO) cell.getValue(); if (vo.getEntity().equals(sValue.getEntity())) { menu.setSelected(true); } } //pop.add(menu); } return pop; }
From source file:org.omegat.gui.issues.IssuesPanelController.java
JMenuBar generateMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu = menuBar.add(new JMenu(OStrings.getString("ISSUES_WINDOW_MENU_OPTIONS"))); {//from w w w . jav a 2 s . c o m // Tags item is hard-coded because it is not disableable and is implemented differently from all // others. JCheckBoxMenuItem tagsItem = new JCheckBoxMenuItem(OStrings.getString( "ISSUES_WINDOW_MENU_OPTIONS_TOGGLE_PROVIDER", OStrings.getString("ISSUES_TAGS_PROVIDER_NAME"))); tagsItem.setSelected(true); tagsItem.setEnabled(false); menu.add(tagsItem); } Set<String> disabledProviders = IssueProviders.getDisabledProviderIds(); IssueProviders.getIssueProviders().stream().sorted(Comparator.comparing(IIssueProvider::getId)) .forEach(provider -> { String label = StringUtil.format( OStrings.getString("ISSUES_WINDOW_MENU_OPTIONS_TOGGLE_PROVIDER"), provider.getName()); JCheckBoxMenuItem item = new JCheckBoxMenuItem(label); item.addActionListener(e -> { IssueProviders.setProviderEnabled(provider.getId(), item.isSelected()); refreshData(selectedEntry, selectedType); }); item.setSelected(!disabledProviders.contains(provider.getId())); menu.add(item); }); menu.addSeparator(); { JCheckBoxMenuItem askItem = new JCheckBoxMenuItem(OStrings.getString("ISSUES_WINDOW_MENU_DONT_ASK")); askItem.setSelected(Preferences.isPreference(Preferences.ISSUE_PROVIDERS_DONT_ASK)); askItem.addActionListener( e -> Preferences.setPreference(Preferences.ISSUE_PROVIDERS_DONT_ASK, askItem.isSelected())); menu.add(askItem); } return menuBar; }
From source file:org.openconcerto.task.TodoListPanel.java
private void initViewableUsers(final User currentUser) { final SwingWorker2<List<Tuple3<String, Integer, String>>, Object> worker = new SwingWorker2<List<Tuple3<String, Integer, String>>, Object>() { @Override/* w w w .ja v a 2 s. c o m*/ protected List<Tuple3<String, Integer, String>> doInBackground() throws Exception { final List<Integer> canViewUsers = new ArrayList<Integer>(); for (final UserTaskRight right : UserTaskRight.getUserTaskRight(currentUser)) { if (right.canRead()) canViewUsers.add(right.getIdToUser()); } // final Vector users = new Vector(); final SQLTable userT = UserManager.getInstance().getTable(); final DBSystemRoot systemRoot = Configuration.getInstance().getSystemRoot(); final SQLSelect select1 = new SQLSelect(systemRoot, false); select1.addSelect(userT.getKey()); select1.addSelect(userT.getField("NOM")); select1.addSelect(userT.getField("PRENOM")); select1.addSelect(userT.getField("SURNOM")); final Where meWhere = new Where(userT.getKey(), "=", currentUser.getId()); final Where canViewWhere = new Where(userT.getKey(), canViewUsers); select1.setWhere(meWhere.or(canViewWhere)); final List<Tuple3<String, Integer, String>> result = new ArrayList<Tuple3<String, Integer, String>>(); userT.getDBSystemRoot().getDataSource().execute(select1.asString(), new ResultSetHandler() { public Object handle(ResultSet rs) throws SQLException { while (rs.next()) { String displayName = rs.getString(4).trim(); if (displayName.length() == 0) { displayName = rs.getString(3).trim() + " " + rs.getString(2).trim().toUpperCase(); } final int uId = rs.getInt(1); final String name = rs.getString(2); result.add(new Tuple3<String, Integer, String>(displayName, uId, name)); } return null; } }); return result; } @Override protected void done() { try { final List<Tuple3<String, Integer, String>> tuples = get(); for (Tuple3<String, Integer, String> tuple3 : tuples) { final JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem(tuple3.get0()); TodoListPanel.this.comboUser.add(checkBoxMenuItem); final int uId = tuple3.get1(); final String name = tuple3.get2(); TodoListPanel.this.users.add(new User(uId, name)); checkBoxMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (checkBoxMenuItem.isSelected()) addUserListenerId(uId); else removeUserListenerId(uId); } }); } } catch (Exception e) { ExceptionHandler.handle("Unable to get tasks users", e); } } }; worker.execute(); }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.AnnotationDataUI.java
/** * Creates a menu item.// w w w. j a v a 2 s . co 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.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public JPopupMenu getPopup() { JPopupMenu popup = new JPopupMenu(); JComponent[] menus = menuTree.getJMenus(); for (JComponent menu : menus) { popup.add(menu);//w w w . j a v a2 s .com } if (!tagSources.isEmpty() && lstSources.getSelectedIndices().length > 0) { JMenu menu = new JMenu(I18N.getString("orbisgis.org.orbisgis.core.ui.plugins.views.geocatalog.tag")); Iterator<String> tagsIterator = tagSources.keySet().iterator(); while (tagsIterator.hasNext()) { String tag = tagsIterator.next(); JCheckBoxMenuItem item; if (isSelectionTagged(tag)) { item = new JCheckBoxMenuItem(tag, true); RemoveTagActionListener removeTagAL = new RemoveTagActionListener(tag); item.addActionListener(removeTagAL); } else { item = new JCheckBoxMenuItem(tag, false); AddTagActionListener addTagAL = new AddTagActionListener(tag); item.addActionListener(addTagAL); } menu.add(item); } popup.addSeparator(); popup.add(menu); } return popup; }
From source file:org.rdv.datapanel.AbstractDataPanel.java
/** * Get a component for displaying the title in top bar. This implementation * includes a button to remove a specific channel. * /*from w w w. j a v a 2s. c om*/ * Subclasses should overide this method if they don't want the default * implementation. * * @return A component for the top bar * @since 1.3 */ JComponent getTitleComponent() { JPanel titleBar = new JPanel(); titleBar.setOpaque(false); titleBar.setLayout(new BorderLayout()); JPopupMenu popupMenu = new ScrollablePopupMenu(); final String title; if (description != null) { title = "Edit description"; } else { title = "Add description"; } JMenuItem addDescriptionMenuItem = new JMenuItem(title); addDescriptionMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String response = (String) JOptionPane.showInputDialog(null, "Enter a description", title, JOptionPane.QUESTION_MESSAGE, null, null, description); if (response == null) { return; } else if (response.length() == 0) { setDescription(null); } else { setDescription(response); } } }); popupMenu.add(addDescriptionMenuItem); if (description != null) { JMenuItem removeDescriptionMenuItem = new JMenuItem("Remove description"); removeDescriptionMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setDescription(null); } }); popupMenu.add(removeDescriptionMenuItem); } popupMenu.addSeparator(); final JCheckBoxMenuItem showChannelsInTitleMenuItem = new JCheckBoxMenuItem("Show channels in title", showChannelsInTitle); showChannelsInTitleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setShowChannelsInTitle(showChannelsInTitleMenuItem.isSelected()); } }); popupMenu.add(showChannelsInTitleMenuItem); if (channels.size() > 0) { popupMenu.addSeparator(); Iterator<String> i = channels.iterator(); while (i.hasNext()) { final String channelName = i.next(); JMenuItem unsubscribeChannelMenuItem = new JMenuItem("Unsubscribe from " + channelName); unsubscribeChannelMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { removeChannel(channelName); } }); popupMenu.add(unsubscribeChannelMenuItem); } } // set component popup and mouselistener to trigger it titleBar.setComponentPopupMenu(popupMenu); titleBar.addMouseListener(new MouseInputAdapter() { }); if (description != null) { titleBar.add(getDescriptionComponent(), BorderLayout.WEST); } JComponent titleComponent = getChannelComponent(); if (titleComponent != null) { titleBar.add(titleComponent, BorderLayout.CENTER); } return titleBar; }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;//from ww w .j a va 2s. com } if (columnGroupCount != 0) { panelBox.add(Box.createHorizontalStrut(7)); } final int tableIndex = columnGroupCount; final DataTableModel tableModel = new DataTableModel(); final JTable table = new JTable(tableModel); table.setDragEnabled(true); table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount)); if (showThresholdCheckBoxGroup.isSelected()) { tableModel.setThresholdVisible(true); } if (showMinMaxCheckBoxGroup.isSelected()) { tableModel.setMaxMinVisible(true); table.getColumn("Min").setCellRenderer(doubleCellRenderer); table.getColumn("Max").setCellRenderer(doubleCellRenderer); } table.getColumn("Value").setCellRenderer(dataCellRenderer); tables.add(table); tableModels.add(tableModel); JScrollPane tableScrollPane = new JScrollPane(table); panelBox.add(tableScrollPane); // popup menu for panel JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem copyMenuItem = new JMenuItem("Copy"); copyMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { TransferHandler.getCopyAction().actionPerformed( new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers())); } }); popupMenu.add(copyMenuItem); popupMenu.addSeparator(); JMenuItem printMenuItem = new JMenuItem("Print..."); printMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { table.print(JTable.PrintMode.FIT_WIDTH); } catch (PrinterException pe) { } } }); popupMenu.add(printMenuItem); popupMenu.addSeparator(); final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false); showMaxMinMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setMaxMinVisible(showMaxMinMenuItem.isSelected()); } }); showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem); popupMenu.add(showMaxMinMenuItem); final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false); showThresholdMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setThresholdVisible(showThresholdMenuItem.isSelected()); } }); showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem); popupMenu.add(showThresholdMenuItem); popupMenu.addSeparator(); JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row"); blankRowMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tableModel.addBlankRow(); } }); popupMenu.add(blankRowMenuItem); final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows"); removeSelectedRowsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removeSelectedRows(tableIndex); } }); popupMenu.add(removeSelectedRowsMenuItem); popupMenu.addSeparator(); JMenu numberOfColumnsMenu = new JMenu("Number of columns"); numberOfColumnsMenu.addMenuListener(new MenuListener() { public void menuSelected(MenuEvent me) { JMenu menu = (JMenu) me.getSource(); for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) { JMenuItem menuItem = menu.getItem(j); boolean selected = (j == (columnGroupCount - 1)); menuItem.setSelected(selected); } } public void menuDeselected(MenuEvent me) { } public void menuCanceled(MenuEvent me) { } }); for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) { final int number = i + 1; JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setNumberOfColumns(number); } }); numberOfColumnsMenu.add(item); } popupMenu.add(numberOfColumnsMenu); popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean anyRowsSelected = table.getSelectedRowCount() > 0; copyMenuItem.setEnabled(anyRowsSelected); removeSelectedRowsMenuItem.setEnabled(anyRowsSelected); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it table.setComponentPopupMenu(popupMenu); tableScrollPane.setComponentPopupMenu(popupMenu); panelBox.revalidate(); columnGroupCount++; properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount)); }
From source file:org.rdv.DockingDataPanelManager.java
/** * Creates the menu where the theme can be changed. * * @return the theme menu/*from w w w . ja v a 2s . c o m*/ */ 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.viz.image.HighResImageViz.java
public void buildPopupMenu(JPopupMenu menu, MouseEvent e) { super.buildPopupMenu(menu, e); ActionListener setTimerangeAction = new ActionListener() { public void actionPerformed(ActionEvent ae) { double newScale = Double.parseDouble(ae.getActionCommand()); setLocalTimescale(newScale); }/*www .j av a 2 s . co m*/ }; // regenerate new menu JMenu timeRangeMenu = new JMenu("Set Timerange"); ButtonGroup timeRangeGroup = new ButtonGroup(); JRadioButtonMenuItem range = new JRadioButtonMenuItem(TimeScale.TIME_SCALE_UNDEFINED_DESC); range.setActionCommand(String.valueOf(TimeScale.TIME_SCALE_UNDEFINED)); range.addActionListener(setTimerangeAction); timeRangeGroup.add(range); timeRangeMenu.add(range); if (localTimeScale_ == TimeScale.TIME_SCALE_UNDEFINED) range.setSelected(true); Double timeScales[] = TimeScale.getGlobalTimeScales(); for (int i = 0; i < timeScales.length; i++) { range = new JRadioButtonMenuItem(DataViewer.formatSeconds(timeScales[i])); range.setActionCommand(String.valueOf(timeScales[i])); range.addActionListener(setTimerangeAction); timeRangeGroup.add(range); timeRangeMenu.add(range); if (localTimeScale_ == timeScales[i]) range.setSelected(true); } menu.add(timeRangeMenu); menu.addSeparator(); // create a popup to copy an image to the clipboard final JMenuItem copyImageMenuItem = new JMenuItem("Copy"); copyImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { copyImage(); } }); menu.add(copyImageMenuItem); menu.addSeparator(); // create a popup to save an image final JMenuItem saveImageMenuItem = new JMenuItem("Save as..."); saveImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { saveImage(); } }); menu.add(saveImageMenuItem); menu.addSeparator(); // create a popup to copy an image to the clipboard final JMenuItem printImageMenuItem = new JMenuItem("Print..."); printImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { printImage(); } }); menu.add(printImageMenuItem); menu.addSeparator(); final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in"); zoomInMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { imagePanel.zoomIn(); } }); menu.add(zoomInMenuItem); final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out"); zoomOutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { imagePanel.zoomOut(); } }); menu.add(zoomOutMenuItem); final JSeparator zoomMenuSeparator = new JPopupMenu.Separator(); menu.add(zoomMenuSeparator); final JCheckBoxMenuItem autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", imagePanel.isAutoScaling()); autoScaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setAutoScale(autoScaleMenuItem.isSelected()); } }); menu.add(autoScaleMenuItem); final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale"); resetScaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { imagePanel.setScale(1); } }); menu.add(resetScaleMenuItem); final JCheckBoxMenuItem showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image", imagePanel.isNavigationImageEnabled()); showNavigationImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setShowNavigationImage(showNavigationImageMenuItem.isSelected()); } }); menu.add(showNavigationImageMenuItem); //menu.addSeparator(); final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image", useThumbnailImage); useThumbnailImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setUseThumbnailImage(useThumbnailImageMenuItem.isSelected()); } }); menu.add(useThumbnailImageMenuItem); boolean hasImage = displayedImageData != null; saveImageMenuItem.setEnabled(hasImage); copyImageMenuItem.setEnabled(hasImage); printImageMenuItem.setEnabled(hasImage); boolean enableZoom = hasImage; zoomInMenuItem.setEnabled(enableZoom); zoomInMenuItem.setVisible(true); zoomOutMenuItem.setEnabled(enableZoom); zoomOutMenuItem.setVisible(true); zoomMenuSeparator.setVisible(true); autoScaleMenuItem.setVisible(true); resetScaleMenuItem.setVisible(true); showNavigationImageMenuItem.setVisible(true); useThumbnailImageMenuItem.setSelected(useThumbnailImage); useThumbnailImageMenuItem.setVisible(imageHasThumbnail()); }
From source file:org.rdv.viz.image.ImageViz.java
private void initPopupMenu() { final JPopupMenu popupMenu = new JPopupMenu(); // create a popup to copy an image to the clipboard final JMenuItem copyImageMenuItem = new JMenuItem("Copy"); copyImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { copyImage();// www.j av a 2 s.c o m } }); popupMenu.add(copyImageMenuItem); popupMenu.addSeparator(); // create a popup to save an image final JMenuItem saveImageMenuItem = new JMenuItem("Save as..."); saveImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { saveImage(); } }); popupMenu.add(saveImageMenuItem); popupMenu.addSeparator(); // create a popup to copy an image to the clipboard final JMenuItem printImageMenuItem = new JMenuItem("Print..."); printImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { printImage(); } }); popupMenu.add(printImageMenuItem); popupMenu.addSeparator(); final JMenuItem zoomInMenuItem = new JMenuItem("Zoom in"); zoomInMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { imagePanel.zoomIn(); } }); popupMenu.add(zoomInMenuItem); final JMenuItem zoomOutMenuItem = new JMenuItem("Zoom out"); zoomOutMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { imagePanel.zoomOut(); } }); popupMenu.add(zoomOutMenuItem); final JSeparator zoomMenuSeparator = new JPopupMenu.Separator(); popupMenu.add(zoomMenuSeparator); autoScaleMenuItem = new JCheckBoxMenuItem("Auto scale", true); autoScaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setAutoScale(autoScaleMenuItem.isSelected()); } }); popupMenu.add(autoScaleMenuItem); final JMenuItem resetScaleMenuItem = new JMenuItem("Reset scale"); resetScaleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { imagePanel.setScale(1); } }); popupMenu.add(resetScaleMenuItem); showNavigationImageMenuItem = new JCheckBoxMenuItem("Show navigation image", imagePanel.isNavigationImageEnabled()); showNavigationImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { setShowNavigationImage(showNavigationImageMenuItem.isSelected()); } }); popupMenu.add(showNavigationImageMenuItem); final JMenu maximumFilmstripImagesMenu = new JMenu("Maximum number of images"); maximumFilmstripImagesButtonGroup = new ButtonGroup(); for (final int maximumFilmstripImagesValue : MAXIMUM_FILMSTRIP_IMAGES_VALUES) { boolean selected = filmstripPanel.getMaximumImages() == maximumFilmstripImagesValue; JMenuItem maximumFilmStripImagesMenuItem = new JRadioButtonMenuItem( Integer.toString(maximumFilmstripImagesValue), selected); maximumFilmStripImagesMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { filmstripPanel.setMaximumImages(maximumFilmstripImagesValue); } }); maximumFilmstripImagesButtonGroup.add(maximumFilmStripImagesMenuItem); maximumFilmstripImagesMenu.add(maximumFilmStripImagesMenuItem); } popupMenu.add(maximumFilmstripImagesMenu); popupMenu.addSeparator(); final JCheckBoxMenuItem showAsFilmstripMenuItem = new JCheckBoxMenuItem("Show as filmstrip", filmstripMode); showAsFilmstripMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { boolean filmstripMode = showAsFilmstripMenuItem.isSelected(); setFilmstripMode(filmstripMode); } }); popupMenu.add(showAsFilmstripMenuItem); final JCheckBoxMenuItem useThumbnailImageMenuItem = new JCheckBoxMenuItem("Use thumbnail image", useThumbnailImage); useThumbnailImageMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setUseThumbnailImage(useThumbnailImageMenuItem.isSelected()); } }); popupMenu.add(useThumbnailImageMenuItem); hideRoboticControlsMenuItem = new JCheckBoxMenuItem("Disable robotic controls", false); hideRoboticControlsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { setRoboticControls(); } }); popupMenu.add(hideRoboticControlsMenuItem); // enable the save image popup if an image is being displayed popupMenu.addPopupMenuListener(new PopupMenuListener() { public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) { boolean hasImage = displayedImageData != null; saveImageMenuItem.setEnabled(hasImage); copyImageMenuItem.setEnabled(hasImage); printImageMenuItem.setEnabled(hasImage); boolean enableZoom = hasImage && !filmstripMode; zoomInMenuItem.setEnabled(enableZoom); zoomInMenuItem.setVisible(!filmstripMode); zoomOutMenuItem.setEnabled(enableZoom); zoomOutMenuItem.setVisible(!filmstripMode); zoomMenuSeparator.setVisible(!filmstripMode); autoScaleMenuItem.setVisible(!filmstripMode); resetScaleMenuItem.setVisible(!filmstripMode); showNavigationImageMenuItem.setVisible(!filmstripMode); maximumFilmstripImagesMenu.setVisible(filmstripMode); showAsFilmstripMenuItem.setSelected(filmstripMode); useThumbnailImageMenuItem.setSelected(useThumbnailImage); useThumbnailImageMenuItem.setVisible(imageHasThumbnail()); hideRoboticControlsMenuItem.setVisible(flexTPSStream != null); } public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) { } public void popupMenuCanceled(PopupMenuEvent arg0) { } }); // set component popup and mouselistener to trigger it panel.setComponentPopupMenu(popupMenu); imagePanel.setComponentPopupMenu(popupMenu); filmstripPanel.setComponentPopupMenu(popupMenu); panel.addMouseListener(new MouseInputAdapter() { }); }