List of usage examples for javax.swing JMenuItem setSelected
public void setSelected(boolean b)
From source file:BeanContainer.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); //from ww w.ja va2 s . c o m JMenu mFile = new JMenu("File"); JMenuItem mItem = new JMenuItem("New..."); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { Thread newthread = new Thread() { public void run() { String result = (String)JOptionPane.showInputDialog( BeanContainer.this, "Please enter class name to create a new bean", "Input", JOptionPane.INFORMATION_MESSAGE, null, null, m_className); repaint(); if (result==null) return; try { m_className = result; Class cls = Class.forName(result); Object obj = cls.newInstance(); if (obj instanceof Component) { m_activeBean = (Component)obj; m_activeBean.addFocusListener( BeanContainer.this); m_activeBean.requestFocus(); getContentPane().add(m_activeBean); } validate(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog( BeanContainer.this, "Error: "+ex.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } } }; newthread.start(); } }; mItem.addActionListener(lst); mFile.add(mItem); mItem = new JMenuItem("Load..."); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { Thread newthread = new Thread() { public void run() { m_chooser.setCurrentDirectory(m_currentDir); m_chooser.setDialogTitle( "Please select file with serialized bean"); int result = m_chooser.showOpenDialog( BeanContainer.this); repaint(); if (result != JFileChooser.APPROVE_OPTION) return; m_currentDir = m_chooser.getCurrentDirectory(); File fChoosen = m_chooser.getSelectedFile(); try { FileInputStream fStream = new FileInputStream(fChoosen); ObjectInput stream = new ObjectInputStream(fStream); Object obj = stream.readObject(); if (obj instanceof Component) { m_activeBean = (Component)obj; m_activeBean.addFocusListener( BeanContainer.this); m_activeBean.requestFocus(); getContentPane().add(m_activeBean); } stream.close(); fStream.close(); validate(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog( BeanContainer.this, "Error: "+ex.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } repaint(); } }; newthread.start(); } }; mItem.addActionListener(lst); mFile.add(mItem); mItem = new JMenuItem("Save..."); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { Thread newthread = new Thread() { public void run() { if (m_activeBean == null) return; m_chooser.setDialogTitle( "Please choose file to serialize bean"); m_chooser.setCurrentDirectory(m_currentDir); int result = m_chooser.showSaveDialog( BeanContainer.this); repaint(); if (result != JFileChooser.APPROVE_OPTION) return; m_currentDir = m_chooser.getCurrentDirectory(); File fChoosen = m_chooser.getSelectedFile(); try { FileOutputStream fStream = new FileOutputStream(fChoosen); ObjectOutput stream = new ObjectOutputStream(fStream); stream.writeObject(m_activeBean); stream.close(); fStream.close(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog( BeanContainer.this, "Error: "+ex.toString(), "Warning", JOptionPane.WARNING_MESSAGE); } } }; newthread.start(); } }; mItem.addActionListener(lst); mFile.add(mItem); mFile.addSeparator(); mItem = new JMenuItem("Exit"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }; mItem.addActionListener(lst); mFile.add(mItem); menuBar.add(mFile); JMenu mEdit = new JMenu("Edit"); mItem = new JMenuItem("Delete"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_activeBean == null) return; Object obj = m_editors.get(m_activeBean); if (obj != null) { BeanEditor editor = (BeanEditor)obj; editor.dispose(); m_editors.remove(m_activeBean); } getContentPane().remove(m_activeBean); m_activeBean = null; validate(); repaint(); } }; mItem.addActionListener(lst); mEdit.add(mItem); mItem = new JMenuItem("Properties..."); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { if (m_activeBean == null) return; Object obj = m_editors.get(m_activeBean); if (obj != null) { BeanEditor editor = (BeanEditor)obj; editor.setVisible(true); editor.toFront(); } else { BeanEditor editor = new BeanEditor(m_activeBean); m_editors.put(m_activeBean, editor); } } }; mItem.addActionListener(lst); mEdit.add(mItem); menuBar.add(mEdit); JMenu mLayout = new JMenu("Layout"); ButtonGroup group = new ButtonGroup(); mItem = new JRadioButtonMenuItem("FlowLayout"); mItem.setSelected(true); lst = new ActionListener() { public void actionPerformed(ActionEvent e){ getContentPane().setLayout(new FlowLayout()); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("GridLayout"); lst = new ActionListener() { public void actionPerformed(ActionEvent e){ int col = 3; int row = (int)Math.ceil(getContentPane(). getComponentCount()/(double)col); getContentPane().setLayout(new GridLayout(row, col, 10, 10)); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("BoxLayout - X"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().setLayout(new BoxLayout( getContentPane(), BoxLayout.X_AXIS)); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("BoxLayout - Y"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().setLayout(new BoxLayout( getContentPane(), BoxLayout.Y_AXIS)); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); mItem = new JRadioButtonMenuItem("DialogLayout"); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { getContentPane().setLayout(new DialogLayout()); validate(); repaint(); } }; mItem.addActionListener(lst); group.add(mItem); mLayout.add(mItem); menuBar.add(mLayout); return menuBar; }
From source file:com.pironet.tda.TDA.java
/** * check menu and button events./*from w w w .j a va 2 s . com*/ */ public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JMenuItem) { JMenuItem source = (JMenuItem) (e.getSource()); if (source.getText().substring(1).startsWith(":\\") || source.getText().startsWith("/")) { if (source.getText().endsWith(".tsf")) { try { loadSession(new File(source.getText()), true); } catch (IOException ex) { ex.printStackTrace(); } } else { dumpFile = source.getText(); openFiles(new File[] { new File(dumpFile) }, true); } } else if ("Open...".equals(source.getText())) { chooseFile(); } else if ("Open loggc file...".equals(source.getText())) { openLoggcFile(); } else if ("Save Logfile...".equals(source.getText())) { saveLogFile(); } else if ("Save Session...".equals(source.getText())) { saveSession(); } else if ("Open Session...".equals(source.getText())) { openSession(); } else if ("Preferences".equals(source.getText())) { showPreferencesDialog(); } else if ("Filters".equals(source.getText())) { showFilterDialog(); } else if ("Categories".equals(source.getText())) { showCategoriesDialog(); } else if ("Get Logfile from clipboard".equals(source.getText())) { getLogfileFromClipboard(); } else if ("Exit TDA".equals(source.getText())) { saveState(); frame.dispose(); } else if (ResourceManager.translate("help.contents").equals(source.getText())) { showHelp(); } else if ("Help".equals(source.getText())) { showHelp(); } else if ("Release Notes".equals(source.getText())) { showInfoFile("Release Notes", "doc/README", Const.ICON_DOCUMENT); } else if ("License".equals(source.getText())) { showInfoFile("License Information", "doc/COPYING", Const.ICON_DOCUMENT); } else if ("Forum".equals(source.getText())) { try { Browser.open("https://tda.dev.java.net/servlets/ForumMessageList?forumID=1967"); } catch (Exception ex) { JOptionPane.showMessageDialog(this.getRootPane(), "Error opening TDA Online Forum\nPlease open https://tda.dev.java.net/servlets/ForumMessageList?forumID=1967 in your browser!", "Error", JOptionPane.ERROR_MESSAGE); } } else if ("About TDA".equals(source.getText())) { showInfo(); } else if ("Search...".equals(source.getText())) { showSearchDialog(); } else if ("Parse loggc-logfile...".equals(source.getText())) { parseLoggcLogfile(); } else if ("Find long running threads...".equals(source.getText())) { findLongRunningThreads(); } else if (("Close logfile...".equals(source.getText())) || ("Close...".equals(source.getText()))) { closeCurrentDump(); } else if ("Close all...".equals(source.getText())) { closeAllDumps(); } else if ("Diff Selection".equals(source.getText())) { final TreePath[] paths = tree.getSelectionPaths(); if (paths != null) { if ((paths.length < 2)) { JOptionPane.showMessageDialog(this.getRootPane(), "You must select at least two dumps for getting a diff!\n", "Error", JOptionPane.ERROR_MESSAGE); } else { DefaultMutableTreeNode mergeRoot = fetchTop(tree.getSelectionPath()); Map dumpMap = dumpStore.getFromDumpFiles(mergeRoot.getUserObject().toString()); ((Logfile) mergeRoot.getUserObject()).getUsedParser().mergeDumps(mergeRoot, dumpMap, paths, paths.length, null); createTree(); this.getRootPane().revalidate(); } } } else if ("Show selected Dump in logfile".equals(source.getText())) { navigateToDumpInLogfile(); } else if ("Show Toolbar".equals(source.getText())) { setShowToolbar(((JCheckBoxMenuItem) source).getState()); } else if ("Request Thread Dump...".equals(source.getText())) { addMXBeanDump(); } else if ("Expand all nodes".equals(source.getText())) { expandAllCatNodes(true); } else if ("Collapse all nodes".equals(source.getText())) { expandAllCatNodes(false); } else if ("Sort by thread count".equals(source.getText())) { sortCatByThreads(); } else if ("Expand all Dump nodes".equals(source.getText())) { expandAllDumpNodes(true); } else if ("Collapse all Dump nodes".equals(source.getText())) { expandAllDumpNodes(false); } } else if (e.getSource() instanceof JButton) { JButton source = (JButton) e.getSource(); if ("Open Logfile".equals(source.getToolTipText())) { chooseFile(); } else if ("Close selected Logfile".equals(source.getToolTipText())) { closeCurrentDump(); } else if ("Get Logfile from clipboard".equals(source.getToolTipText())) { getLogfileFromClipboard(); } else if ("Preferences".equals(source.getToolTipText())) { showPreferencesDialog(); } else if ("Find long running threads".equals(source.getToolTipText())) { findLongRunningThreads(); } else if ("Expand all nodes".equals(source.getToolTipText())) { expandAllDumpNodes(true); } else if ("Collapse all nodes".equals(source.getToolTipText())) { expandAllDumpNodes(false); } else if ("Find long running threads".equals(source.getToolTipText())) { findLongRunningThreads(); } else if ("Filters".equals(source.getToolTipText())) { showFilterDialog(); } else if ("Custom Categories".equals(source.getToolTipText())) { showCategoriesDialog(); } else if ("Request a Thread Dump".equals(source.getToolTipText())) { addMXBeanDump(); } else if ("Help".equals(source.getToolTipText())) { showHelp(); } source.setSelected(false); } }
From source file:org.nuclos.client.relation.EntityRelationshipModelEditPanel.java
protected JPopupMenu createRelationPopupMenu(final mxCell cell, boolean delete, boolean objectGeneration) { final SpringLocaleDelegate localeDelegate = getSpringLocaleDelegate(); JPopupMenu pop = new JPopupMenu(); JMenuItem i1 = new JMenuItem( localeDelegate.getMessage("nuclos.entityrelation.editor.10", "Bezug zu Stammdaten bearbeiten")); i1.addActionListener(new ActionListener() { @Override//from ww w .j a v a 2 s . c om public void actionPerformed(ActionEvent e) { editMasterdataRelation(cell); } }); JMenuItem i2 = new JMenuItem( localeDelegate.getMessage("nuclos.entityrelation.editor.11", "Unterfomularbezug bearbeiten")); i2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { editSubformRelation(cell); } }); JMenuItem i4 = new JMenuItem( localeDelegate.getMessage("nuclos.entityrelation.editor.12", "Verbindung l\u00f6sen")); i4.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int opt = JOptionPane.showConfirmDialog(mainPanel, localeDelegate.getMessage( "nuclos.entityrelation.editor.7", "M\u00f6chten Sie die Verbindung wirklich l\u00f6sen?")); if (opt != 0) { return; } mxCell cellSource = (mxCell) cell.getSource(); if (cellSource != null && cellSource.getValue() instanceof EntityMetaDataVO) { EntityMetaDataVO metaSource = (EntityMetaDataVO) cellSource.getValue(); if (cell.getValue() instanceof EntityFieldMetaDataVO) { EntityFieldMetaDataVO voField = (EntityFieldMetaDataVO) cell.getValue(); voField.flagRemove(); List<EntityFieldMetaDataTO> toList = new ArrayList<EntityFieldMetaDataTO>(); EntityFieldMetaDataTO toField = new EntityFieldMetaDataTO(); toField.setEntityFieldMeta(voField); toList.add(toField); MetaDataDelegate.getInstance().modifyEntityMetaData(metaSource, toList); if (mpRemoveRelation.containsKey(metaSource)) { mpRemoveRelation.get(metaSource).add(voField); } else { Set<EntityFieldMetaDataVO> s = new HashSet<EntityFieldMetaDataVO>(); s.add(voField); mpRemoveRelation.put(metaSource, s); } } else if (cell.getValue() != null && cell.getValue() instanceof String) { } } mxGraphModel model = (mxGraphModel) graphComponent.getGraph().getModel(); model.remove(cell); EntityRelationshipModelEditPanel.this.fireChangeListenEvent(); } }); JMenuItem i5 = new JMenuItem( localeDelegate.getMessage("nuclos.entityrelation.editor.13", "Arbeitsschritt bearbeiten")); i5.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { mxCell cellSource = (mxCell) cell.getSource(); mxCell cellTarget = (mxCell) cell.getTarget(); EntityMetaDataVO sourceModule = (EntityMetaDataVO) cellSource.getValue(); EntityMetaDataVO targetModule = (EntityMetaDataVO) cellTarget.getValue(); String sSourceModule = sourceModule.getEntity(); String sTargetModule = targetModule.getEntity(); boolean blnFound = false; for (MasterDataVO voGeneration : MasterDataCache.getInstance() .get(NuclosEntity.GENERATION.getEntityName())) { String sSource = (String) voGeneration.getField("sourceModule"); String sTarget = (String) voGeneration.getField("targetModule"); if (org.apache.commons.lang.StringUtils.equals(sSource, sSourceModule) && org.apache.commons.lang.StringUtils.equals(sTarget, sTargetModule)) { GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory .getInstance().newMasterDataCollectController( NuclosEntity.GENERATION.getEntityName(), null, null); gcc.runViewSingleCollectableWithId(voGeneration.getId()); blnFound = true; break; } } if (!blnFound) { GenerationCollectController gcc = (GenerationCollectController) NuclosCollectControllerFactory .getInstance().newMasterDataCollectController( NuclosEntity.GENERATION.getEntityName(), null, null); Map<String, Object> mp = new HashMap<String, Object>(); mp.put("sourceModule", sSourceModule); mp.put("sourceModuleId", new Integer( MetaDataClientProvider.getInstance().getEntity(sSourceModule).getId().intValue())); mp.put("targetModule", sTargetModule); mp.put("targetModuleId", new Integer( MetaDataClientProvider.getInstance().getEntity(sTargetModule).getId().intValue())); MasterDataVO vo = new MasterDataVO(NuclosEntity.GENERATION.getEntityName(), null, null, null, null, null, null, mp); gcc.runWithNewCollectableWithSomeFields(vo); } } catch (NuclosBusinessException e1) { LOG.warn("actionPerformed failed: " + e1, e1); } catch (CommonPermissionException e1) { LOG.warn("actionPerformed failed: " + e1, e1); } catch (CommonFatalException e1) { LOG.warn("actionPerformed failed: " + e1, e1); } catch (CommonBusinessException e1) { LOG.warn("actionPerformed failed: " + e1, e1); } } }); if (cell.getStyle() != null && cell.getStyle().indexOf(OPENARROW) >= 0) { i1.setSelected(true); pop.add(i1); } else if (cell.getStyle() != null && cell.getStyle().indexOf(DIAMONDARROW) >= 0) { i2.setSelected(true); pop.add(i2); } if (objectGeneration) { //pop.addSeparator(); pop.add(i5); } if (delete) { pop.addSeparator(); pop.add(i4); } return pop; }
From source file:org.omegat.gui.properties.SegmentPropertiesArea.java
private void populateLocalContextMenuOptions(JPopupMenu contextMenu, Point p) { final String key = viewImpl.getKeyAtPoint(p); if (key == null) { return;//from w w w . j a v a 2 s.c o m } String displayKey = key; if (!Preferences.isPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS)) { try { displayKey = OStrings .getString(ISegmentPropertiesView.PROPERTY_TRANSLATION_KEY + key.toUpperCase()); } catch (MissingResourceException ignore) { // If this is not a known key then we can't translate it, // so use the "raw" key instead. } } String label = StringUtil.format(OStrings.getString("SEGPROP_CONTEXTMENU_NOTIFY_ON_PROP"), displayKey); final JMenuItem notifyOnItem = new JCheckBoxMenuItem(label); notifyOnItem.setSelected(getKeysToNotify().contains(key)); notifyOnItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setKeyToNotify(key, notifyOnItem.isSelected()); } }); contextMenu.add(notifyOnItem); }
From source file:org.omegat.gui.properties.SegmentPropertiesArea.java
@Override public void populatePaneMenu(JPopupMenu contextMenu) { JMenuItem tableModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_TABLE_MODE")); tableModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesTableView.class)); tableModeItem.addActionListener(new ActionListener() { @Override// w w w . ja v a 2 s . co m public void actionPerformed(ActionEvent e) { toggleMode(SegmentPropertiesTableView.class); } }); JMenuItem listModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_LIST_MODE")); listModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesListView.class)); listModeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleMode(SegmentPropertiesListView.class); } }); ButtonGroup group = new ButtonGroup(); group.add(tableModeItem); group.add(listModeItem); contextMenu.add(tableModeItem); contextMenu.add(listModeItem); contextMenu.addSeparator(); final JMenuItem toggleKeyTranslationItem = new JCheckBoxMenuItem( OStrings.getString("SEGPROP_CONTEXTMENU_RAW_KEYS")); toggleKeyTranslationItem.setSelected(Preferences.isPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS)); toggleKeyTranslationItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Preferences.setPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS, toggleKeyTranslationItem.isSelected()); viewImpl.update(); } }); contextMenu.add(toggleKeyTranslationItem); }
From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java
/** * Helper method to create the controls menu. * /*from w w w .ja va 2 s . c om*/ * @param pref The user preferences. * @return The controls sub-menu. */ private JMenu createControlsMenu(ViewerPreferences pref) { JMenu menu = new JMenu("Controls"); menu.setMnemonic(KeyEvent.VK_C); ViewerAction action = controller.getAction(ImViewerControl.RENDERER); rndItem = new JCheckBoxMenuItem(); rndItem.setSelected(isRendererShown()); rndItem.setAction(action); rndItem.setText(action.getName()); if (pref != null) rndItem.setSelected(pref.isRenderer()); //menu.add(rndItem); action = controller.getAction(ImViewerControl.METADATA); metadataItem = new JCheckBoxMenuItem(); metadataItem.setSelected(isRendererShown()); metadataItem.setAction(action); metadataItem.setText(action.getName()); if (pref != null) metadataItem.setSelected(pref.isRenderer()); //menu.add(metadataItem); action = controller.getAction(ImViewerControl.HISTORY); historyItem = new JCheckBoxMenuItem(); historyItem.setSelected(isHistoryShown()); historyItem.setAction(action); historyItem.setText(action.getName()); if (pref != null) historyItem.setSelected(pref.isHistory()); //menu.add(historyItem); action = controller.getAction(ImViewerControl.MOVIE); JMenuItem item = new JMenuItem(action); item.setText(action.getName()); menu.add(item); action = controller.getAction(ImViewerControl.LENS); item = new JMenuItem(action); item.setText(action.getName()); menu.add(item); action = controller.getAction(ImViewerControl.MEASUREMENT_TOOL); item = new JMenuItem(action); item.setText(action.getName()); menu.add(item); menu.add(new JSeparator(JSeparator.HORIZONTAL)); //Color model colorModelGroup = new ButtonGroup(); action = controller.getAction(ImViewerControl.GREY_SCALE_MODEL); item = new JCheckBoxMenuItem(); String cm = model.getColorModel(); item.setSelected(cm.equals(ImViewer.GREY_SCALE_MODEL)); item.setAction(action); colorModelGroup.add(item); menu.add(item); action = controller.getAction(ImViewerControl.RGB_MODEL); item = new JCheckBoxMenuItem(); item.setAction(action); item.setSelected(cm.equals(ImViewer.RGB_MODEL)); colorModelGroup.add(item); menu.add(item); menu.add(new JSeparator()); action = controller.getAction(ImViewerControl.CHANNELS_ON); item = new JMenuItem(action); item.setText(action.getName()); menu.add(item); action = controller.getAction(ImViewerControl.CHANNELS_OFF); item = new JMenuItem(action); item.setText(action.getName()); menu.add(item); menu.add(new JSeparator()); action = controller.getAction(ImViewerControl.SAVE); item = new JMenuItem(action); item.setText(action.getName()); menu.add(item); action = controller.getAction(ImViewerControl.PREFERENCES); item = new JMenuItem(action); item.setText(action.getName()); //menu.add(item); return menu; }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Creates the items for the menu./*from w w w . ja va 2 s. com*/ * * @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.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;/*from w w w .j a v a 2 s . c om*/ } 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.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; JMenu fileMenu = new JMenu(fileAction); menuItem = new JMenuItem(connectAction); fileMenu.add(menuItem);//from www .j a v a 2 s . c om 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.yccheok.jstock.gui.JStock.java
private void jMenu8MenuSelected(javax.swing.event.MenuEvent evt) {//GEN-FIRST:event_jMenu8MenuSelected this.jMenu8.removeAll(); final java.util.List<String> portfolioNames = org.yccheok.jstock.portfolio.Utils.getPortfolioNames(); final String currentPortfolioName = this.getJStockOptions().getPortfolioName(); final javax.swing.ButtonGroup buttonGroup = new javax.swing.ButtonGroup(); for (String portfolioName : portfolioNames) { final JMenuItem mi = (JRadioButtonMenuItem) jMenu8.add(new JRadioButtonMenuItem(portfolioName)); buttonGroup.add(mi);/*from w w w . j a va2 s .c o m*/ mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String s = ((JRadioButtonMenuItem) e.getSource()).getText(); if (false == s.equals(currentPortfolioName)) { JStock.this.selectActivePortfolio(s); } } }); mi.setSelected(portfolioName.equals(currentPortfolioName)); } jMenu8.addSeparator(); final JMenuItem mi = new JMenuItem(GUIBundle.getString("MainFrame_MultiplePortolio..."), this.getImageIcon("/images/16x16/calc.png")); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { multiplePortfolios(); } }); jMenu8.add(mi); }