List of usage examples for javax.swing JRadioButtonMenuItem JRadioButtonMenuItem
public JRadioButtonMenuItem(Action a)
Action
supplied. From source file:org.languagetool.gui.Main.java
private void addLookAndFeelMenuItem(JMenu lafMenu, UIManager.LookAndFeelInfo laf, ButtonGroup buttonGroup) { JRadioButtonMenuItem lfItem = new JRadioButtonMenuItem(new SelectLFAction(laf)); lafMenu.add(lfItem);// w w w. j av a 2 s .com buttonGroup.add(lfItem); if (laf.getClassName().equals(UIManager.getLookAndFeel().getClass().getName())) { buttonGroup.setSelected(lfItem.getModel(), true); } }
From source file:org.notebook.gui.widget.LookAndFeelSelector.java
protected JMenu createMenu() { JMenu toolMenu = new JMenu(MenuToolbar.i18n("Views")); ButtonGroup group = new ButtonGroup(); JRadioButtonMenuItem item = null; for (String n : getListOfSkins()) { item = new JRadioButtonMenuItem(new LafMenuAction(n)); if (n.equals(DEFAULT_SKIN)) { item.setSelected(true);//from w w w . j av a 2s. c o m } group.add(item); toolMenu.add(item); } return toolMenu; }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
/** * @return//from w ww. ja v a 2s . c om * @precondition hasComparisonOperator() */ public JPopupMenu newComparisonOperatorPopupMenu() { if (!hasComparisonOperator()) { throw new IllegalStateException(); } final JPopupMenu result = new JPopupMenu( getSpringLocaleDelegate().getMessage("AbstractCollectableComponent.16", "Vergleichsoperator")); // 1. comparison operators: final ButtonGroup btngrpComparisonOperators = new ButtonGroup(); final ItemListener itemlistener = new ItemListener() { @Override public void itemStateChanged(ItemEvent ev) { if (ev.getStateChange() == ItemEvent.SELECTED) { final String sOperatorName = ((AbstractButton) ev.getItem()).getActionCommand(); setComparisonOperator(ComparisonOperator.getInstance(sOperatorName)); runLocked(new Runnable() { @Override public void run() { updateSearchConditionInModel(); } }); } } }; ComparisonOperator[] supportedComparisonOperators = getSupportedComparisonOperators(); if (supportedComparisonOperators == null) return null; for (ComparisonOperator compop : supportedComparisonOperators) { JMenuItem mi = new JRadioButtonMenuItem( getSpringLocaleDelegate().getMessage(compop.getResourceIdForLabel(), null)); mi.setActionCommand(compop.name()); mi.setToolTipText(getSpringLocaleDelegate().getMessage(compop.getResourceIdForDescription(), null)); result.add(mi); btngrpComparisonOperators.add(mi); mi.addItemListener(itemlistener); } result.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent ev) { for (int i = 0, n = result.getComponentCount(); i < n; i++) { Component c = result.getComponent(i); if (c instanceof JMenuItem && StringUtils.emptyIfNull(((JMenuItem) c).getActionCommand()) .equals(getComparisonOperator().name())) ((JMenuItem) c).setSelected(true); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) { } @Override public void popupMenuCanceled(PopupMenuEvent ev) { } }); // 2. right operand (value or other field): if (canDisplayComparisonWithOtherField()) { addRightOperandToPopupMenu(result, this); } return result; }
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
/** * @param result//from w w w . j a v a2s. c om * @param clctcomp */ private static void addRightOperandToPopupMenu(JPopupMenu result, final AbstractCollectableComponent clctcomp) { result.addSeparator(); final ButtonGroup btngrpCompareWith = new ButtonGroup(); final SpringLocaleDelegate localeDelegate = SpringLocaleDelegate.getInstance(); final JRadioButtonMenuItem miValue = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.17", "Wertvergleich")); miValue.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.10", "Dieses Feld mit einem festen Wert vergleichen")); result.add(miValue); btngrpCompareWith.add(miValue); miValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { clctcomp.resetWithComparison(); clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } }); final JRadioButtonMenuItem miOtherField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.12", "Feldvergleich...")); miOtherField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.9", "Dieses Feld mit dem Inhalt eines anderen Felds vergleichen")); result.add(miOtherField); btngrpCompareWith.add(miOtherField); miOtherField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { assert clctcomp.clcte != null; // select entity field with the same data type: final List<CollectableEntityField> lstclctefFiltered = CollectionUtils.select( CollectableUtils.getCollectableEntityFields(clctcomp.clcte), new Predicate<CollectableEntityField>() { @Override public boolean evaluate(CollectableEntityField clctef) { return clctef.getJavaClass() == clctcomp.clctef.getJavaClass(); } }); // and sort by label: final List<CollectableEntityField> lstclctefSorted = CollectionUtils.sorted(lstclctefFiltered, new CollectableEntityField.LabelComparator()); final JComboBox cmbbx = new JComboBox(lstclctefSorted.toArray()); cmbbx.setSelectedItem(clctcomp.getComparisonOtherField()); final int iBtn = JOptionPane .showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.6", "Anderes Feld: "), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.15", "Vergleich mit anderem Feld"), JOptionPane.OK_CANCEL_OPTION); if (iBtn == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((CollectableEntityField) cmbbx.getSelectedItem()); if (clctcomp.getComparisonOtherField() != null) { // clear the view: clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { // If the user selects "other field" and forgot to set the operator, we assume "EQUAL": clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); final List<ComparisonParameter> compatibleParameters = ComparisonParameter .getCompatibleParameters(clctcomp.getEntityField()); final JRadioButtonMenuItem miParameterField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.18", null)); miParameterField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.19", null)); btngrpCompareWith.add(miParameterField); if (compatibleParameters.size() > 0) { result.add(miParameterField); miParameterField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { ResourceIdMapper<ComparisonParameter> mapper = new ResourceIdMapper<ComparisonParameter>( compatibleParameters); JComboBox cmbbx = new JComboBox(CollectionUtils.sorted(compatibleParameters, mapper).toArray()); cmbbx.setRenderer(new DefaultListRenderer(mapper)); cmbbx.setSelectedItem(clctcomp.getComparisonParameter()); final int opt = JOptionPane.showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.20", null), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.19", null), JOptionPane.OK_CANCEL_OPTION); if (opt == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((ComparisonParameter) cmbbx.getSelectedItem()); if (clctcomp.getComparisonParameter() != null) { clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); } result.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent ev) { if (clctcomp.getComparisonParameter() != null) { miParameterField.setSelected(true); } else if (clctcomp.getComparisonOtherField() == null || clctcomp.getComparisonOperator().getOperandCount() < 2) { miValue.setSelected(true); } else { miOtherField.setSelected(true); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) { } @Override public void popupMenuCanceled(PopupMenuEvent ev) { } }); }
From source file:org.pentaho.reporting.designer.core.ReportDesignerFrame.java
private void initSetBarcodeTypeElements(final String id) { final JMenu menu = context.getView().getComponent(id, JMenu.class); if (menu == null) { return;/*from www.ja v a 2s.c o m*/ } final BarcodeTypePropertyEditor editor = new BarcodeTypePropertyEditor(); final String[] tags = editor.getTags(); for (int i = 0; i < tags.length; i++) { final String tag = tags[i]; final BarcodeTypeAction action = new BarcodeTypeAction(tag); action.setReportDesignerContext(context); menu.add(new JRadioButtonMenuItem(action)); } }
From source file:org.rdv.datapanel.DigitalTabularDataPanel.java
private void addColumn() { if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) { return;//from w w w . j a va 2 s . c o m } 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 ww. jav a 2 s .c om*/ */ private JMenu createThemesMenu() { JMenu themesMenu = new JMenu("Themes"); // don't get the title bar window thing final JCheckBoxMenuItem titleBarStyleItem = new JCheckBoxMenuItem("Title Bar Style Theme"); titleBarStyleItem.setSelected(titleBarTheme_); titleBarStyleItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (!titleBarTheme_) properties_.addSuperObject(titleBarStyleProperties); else { // TODO this does not work to remove title bars from windows properties_.removeSuperObject(titleBarStyleProperties); } titleBarTheme_ = !titleBarTheme_; } }); themesMenu.add(titleBarStyleItem); themesMenu.add(new JSeparator()); DockingWindowsTheme[] themes = { new DefaultDockingTheme(), new LookAndFeelDockingTheme(), new BlueHighlightDockingTheme(), new SlimFlatDockingTheme(), new GradientDockingTheme(), new ShapedGradientDockingTheme(), new SoftBlueIceDockingTheme(), new ClassicDockingTheme() }; ButtonGroup group = new ButtonGroup(); for (int i = 0; i < themes.length; i++) { final DockingWindowsTheme theme = themes[i]; JRadioButtonMenuItem item = new JRadioButtonMenuItem(theme.getName()); item.setSelected(themes[i].getClass() == currentTheme_.getClass()); group.add(item); themesMenu.add(item).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // Clear the modified properties values properties_.getMap().clear(true); setTheme(theme); } }); } return themesMenu; }
From source file:org.rdv.ui.MainPanel.java
private void initMenuBar() { Application application = RDV.getInstance(); ApplicationContext context = application.getContext(); ResourceMap resourceMap = context.getResourceMap(); String platform = resourceMap.getString("platform"); boolean isMac = (platform != null && platform.equals("osx")); ActionFactory actionFactory = ActionFactory.getInstance(); Actions actions = Actions.getInstance(); ActionMap actionMap = context.getActionMap(actions); menuBar = new JMenuBar(); JMenuItem menuItem;//from w w w . j a v a 2s . co m JMenu fileMenu = new JMenu(fileAction); menuItem = new JMenuItem(connectAction); fileMenu.add(menuItem); menuItem = new JMenuItem(disconnectAction); fileMenu.add(menuItem); fileMenu.addSeparator(); menuItem = new JMenuItem(loginAction); fileMenu.add(menuItem); menuItem = new JMenuItem(logoutAction); fileMenu.add(menuItem); fileMenu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent arg0) { } public void menuDeselected(MenuEvent arg0) { } public void menuSelected(MenuEvent arg0) { if (AuthenticationManager.getInstance().getAuthentication() == null) { loginAction.setEnabled(true); logoutAction.setEnabled(false); } else { loginAction.setEnabled(false); logoutAction.setEnabled(true); } } }); fileMenu.addSeparator(); menuItem = new JMenuItem(loadAction); fileMenu.add(menuItem); menuItem = new JMenuItem(saveAction); fileMenu.add(menuItem); fileMenu.addSeparator(); fileMenu.add(new JMenuItem(actionMap.get("addLocalChannel"))); fileMenu.addSeparator(); JMenu importSubMenu = new JMenu(importAction); menuItem = new JMenuItem(actionFactory.getDataImportAction()); importSubMenu.add(menuItem); menuItem = new JMenuItem(actionFactory.getOpenSeesDataImportAction()); importSubMenu.add(menuItem); importSubMenu.add(new JMenuItem(actionMap.get("importJPEGs"))); fileMenu.add(importSubMenu); JMenu exportSubMenu = new JMenu(exportAction); menuItem = new JMenuItem(actionFactory.getDataExportAction()); exportSubMenu.add(menuItem); menuItem = new JMenuItem(exportVideoAction); exportSubMenu.add(menuItem); fileMenu.add(exportSubMenu); fileMenu.addSeparator(); menuItem = new DataViewerCheckBoxMenuItem(actionFactory.getOfflineAction()); fileMenu.add(menuItem); if (!isMac) { menuItem = new JMenuItem(exitAction); fileMenu.add(menuItem); } menuBar.add(fileMenu); JMenu controlMenu = new JMenu(controlAction); menuItem = new SelectableCheckBoxMenuItem(realTimeAction); controlMenu.add(menuItem); menuItem = new SelectableCheckBoxMenuItem(playAction); controlMenu.add(menuItem); menuItem = new SelectableCheckBoxMenuItem(pauseAction); controlMenu.add(menuItem); controlMenu.addMenuListener(new MenuListener() { public void menuCanceled(MenuEvent arg0) { } public void menuDeselected(MenuEvent arg0) { } public void menuSelected(MenuEvent arg0) { int state = rbnb.getState(); realTimeAction.setSelected(state == Player.STATE_MONITORING); playAction.setSelected(state == Player.STATE_PLAYING); pauseAction.setSelected(state == Player.STATE_STOPPED); } }); controlMenu.addSeparator(); menuItem = new JMenuItem(beginningAction); controlMenu.add(menuItem); menuItem = new JMenuItem(endAction); controlMenu.add(menuItem); menuItem = new JMenuItem(gotoTimeAction); controlMenu.add(menuItem); menuBar.add(controlMenu); controlMenu.addSeparator(); menuItem = new JMenuItem(updateChannelListAction); controlMenu.add(menuItem); controlMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(dropDataAction); controlMenu.add(menuItem); JMenu viewMenu = new JMenu(viewAction); menuItem = new JCheckBoxMenuItem(showChannelListAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showMetadataPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showControlPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showAudioPlayerPanelAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(showMarkerPanelAction); menuItem.setSelected(true); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(showHiddenChannelsAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuItem = new JCheckBoxMenuItem(hideEmptyTimeAction); menuItem.setSelected(false); viewMenu.add(menuItem); viewMenu.addSeparator(); menuItem = new JCheckBoxMenuItem(fullScreenAction); menuItem.setSelected(false); viewMenu.add(menuItem); menuBar.add(viewMenu); JMenu windowMenu = new JMenu(windowAction); List<Extension> extensions = dataPanelManager.getExtensions(); for (final Extension extension : extensions) { Action action = new DataViewerAction("Add " + extension.getName(), "", KeyEvent.VK_J) { /** serialization version identifier */ private static final long serialVersionUID = 36998228704476723L; public void actionPerformed(ActionEvent ae) { try { dataPanelManager.createDataPanel(extension); } catch (Exception e) { log.error("Unable to open data panel provided by extension " + extension.getName() + " (" + extension.getID() + ")."); e.printStackTrace(); } } }; menuItem = new JMenuItem(action); windowMenu.add(menuItem); } windowMenu.addSeparator(); menuItem = new JMenuItem(closeAllDataPanelsAction); windowMenu.add(menuItem); windowMenu.addSeparator(); JMenu dataPanelSubMenu = new JMenu(dataPanelAction); ButtonGroup dataPanelLayoutGroup = new ButtonGroup(); menuItem = new JRadioButtonMenuItem(dataPanelHorizontalLayoutAction); dataPanelSubMenu.add(menuItem); dataPanelLayoutGroup.add(menuItem); menuItem = new JRadioButtonMenuItem(dataPanelVerticalLayoutAction); menuItem.setSelected(true); dataPanelSubMenu.add(menuItem); dataPanelLayoutGroup.add(menuItem); windowMenu.add(dataPanelSubMenu); menuBar.add(windowMenu); JMenu helpMenu = new JMenu(helpAction); menuItem = new JMenuItem(usersGuideAction); helpMenu.add(menuItem); menuItem = new JMenuItem(supportAction); helpMenu.add(menuItem); menuItem = new JMenuItem(releaseNotesAction); helpMenu.add(menuItem); if (!isMac) { helpMenu.addSeparator(); menuItem = new JMenuItem(aboutAction); helpMenu.add(menuItem); } menuBar.add(helpMenu); menuBar.add(Box.createHorizontalGlue()); throbberStop = DataViewer.getIcon("icons/throbber.png"); throbberAnim = DataViewer.getIcon("icons/throbber_anim.gif"); throbber = new JLabel(throbberStop); throbber.setBorder(new EmptyBorder(0, 0, 0, 4)); menuBar.add(throbber, BorderLayout.EAST); if (isMac) { registerMacOSXEvents(); } frame.setJMenuBar(menuBar); }
From source file:org.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); }/*from www. j a va 2s .c o 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.squidy.designer.Designer.java
/** * Initializes menu bar./* w ww. ja va 2 s . c o m*/ */ private void initMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu workspace = new JMenu("Workspace"); workspace.add(new AbstractAction("Open from...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); int option = fileChooser.showOpenDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { // Stop replacing workspace if currently running. if (data != null) { data.getWorkspace().stop(); } File workspaceFile = fileChooser.getSelectedFile(); if (storage instanceof LocalJAXBStorage) { ((LocalJAXBStorage) storage).setWorkspaceFile(workspaceFile); load(); } else { try { data = ModelViewHandler.getModelViewHandler().load(new FileInputStream(workspaceFile)); WorkspaceShape workspace = data.getWorkspaceShape(); workspace.setModel(data); workspace.setStorageHandler(Designer.this); workspace.initialize(); LayoutConstraint lc = workspace.getLayoutConstraint(); workspace.setScale(lc.getScale()); workspace.setOffset(lc.getX(), lc.getY()); getCanvas().getLayer().addChild(workspace); zoomToZoomedShape(data); } catch (SquidyException e1) { e1.printStackTrace(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } } } } }); workspace.add(new AbstractAction("Export as...") { /* * (non-Javadoc) * * @see * java.awt.event.ActionListener#actionPerformed(java.awt.event. * ActionEvent) */ public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileHidingEnabled(true); fileChooser.setFileFilter(new FileFilter() { /* * (non-Javadoc) * * @see * javax.swing.filechooser.FileFilter#accept(java.io.File) */ @Override public boolean accept(File f) { return f.isDirectory() || f.getName().endsWith(".sdy"); } /* * (non-Javadoc) * * @see javax.swing.filechooser.FileFilter#getDescription() */ @Override public String getDescription() { return "Squidy Workspace"; } }); if (storage instanceof LocalJAXBStorage) { fileChooser.setSelectedFile(((LocalJAXBStorage) storage).getWorkspaceFile()); } int option = fileChooser.showSaveDialog(Designer.this); if (option == JFileChooser.APPROVE_OPTION) { File workspaceFile = fileChooser.getSelectedFile(); try { ModelViewHandler.getModelViewHandler().save(new FileOutputStream(workspaceFile), data); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); JMenu options = new JMenu("Options"); rendering.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { VisualShape.setRenderPrimitiveRect(rendering.isSelected()); data.setRenderPrimitiveRect(rendering.isSelected()); storage.store(data); repaint(); } }); options.add(rendering); JMenu storage = new JMenu("Storage"); ButtonGroup group = new ButtonGroup(); final JRadioButtonMenuItem storageLocalJAXB = new JRadioButtonMenuItem("Local JAXB"); storageLocalJAXB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageLocalJAXB.isSelected()) { setStorageMode(StorageMode.FILE); } } }); storage.add(storageLocalJAXB); group.add(storageLocalJAXB); final JRadioButtonMenuItem storageBaseX = new JRadioButtonMenuItem("BaseX"); storageBaseX.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (storageBaseX.isSelected()) { setStorageMode(StorageMode.BASEX); } } }); storageBaseX.setSelected(storageType.equals(BaseXStorage.class)); storage.add(storageBaseX); group.add(storageBaseX); options.add(storage); menuBar.add(workspace); menuBar.add(options); setJMenuBar(menuBar); }