List of usage examples for javax.swing JCheckBoxMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:com.mirth.connect.client.ui.components.MirthTable.java
private JPopupMenu getColumnMenu() { JPopupMenu columnMenu = new JPopupMenu(); DefaultTableModel model = (DefaultTableModel) getModel(); for (int i = 0; i < model.getColumnCount(); i++) { final String columnName = model.getColumnName(i); // Get the column object by name. Using an index may not return the column object if the column is hidden TableColumnExt column = getColumnExt(columnName); // Create the menu item final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName); // Show or hide the checkbox menuItem.setSelected(column.isVisible()); menuItem.addActionListener(new ActionListener() { @Override//from www . j a v a 2 s . com public void actionPerformed(ActionEvent evt) { TableColumnExt column = getColumnExt(menuItem.getText()); // Determine whether to show or hide the selected column boolean enable = !column.isVisible(); // Do not hide a column if it is the last remaining visible column if (enable || getColumnCount() > 1) { column.setVisible(enable); saveColumnOrder(); } } }); columnMenu.add(menuItem); } columnMenu.addSeparator(); JMenuItem menuItem = new JMenuItem("Restore Default"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { restoreDefaultColumnPreferences(); } }); columnMenu.add(menuItem); return columnMenu; }
From source file:SciTK.PlotXYZBlock.java
private void init(String x_label, String y_label, String window_title) { chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true, false);/* ww w .ja v a2 s. c om*/ // turn off borders of the plot: XYPlot p = chart.getXYPlot(); p.getDomainAxis().setLowerMargin(0.0); p.getDomainAxis().setUpperMargin(0.0); p.getRangeAxis().setLowerMargin(0.0); p.getRangeAxis().setUpperMargin(0.0); // -------------------------------------------- // set up a lookup table // -------------------------------------------- // this is how we render the block plots: XYBlockRenderer renderer = new XYBlockRenderer(); // need to find max and min z of the data set: double min = 0; double max = 0; for (int i = 0; i < data.getSeriesCount(); i++) // iterate over data sets { for (int j = 0; j < data.getItemCount(i); j++) // iterate over points in dataset { if (data.getZValue(i, j) < min) min = data.getZValue(i, j); else if (data.getZValue(i, j) > max) max = data.getZValue(i, j); } } // create paint scale using min and max values, default color black: LookupPaintScale paintScale = new LookupPaintScale(min, max, Color.black); // set up the LUT: double step_size = (max - min) / 255.; // step size for LUT for (int i = 0; i < 256; i++) { paintScale.add(min + i * step_size, new Color(i, i, i, 255)); } renderer.setPaintScale(paintScale); // set this renderer to the plot: p.setRenderer(renderer); // -------------------------------------------- // set up a color bar // -------------------------------------------- // create an array of display labels: num_labels = 10; // default to 10 labels on color bar double display_step_size = (max - min) / ((double) num_labels); String[] scale_bar_labels = new String[num_labels + 1]; // to format numbers in scientific notation: DecimalFormat formater = new DecimalFormat("0.#E0"); // create list of labesl: for (int i = 0; i <= num_labels; i++) { scale_bar_labels[i] = formater.format(min + i * display_step_size); } // create axis: SymbolAxis scaleAxis = new SymbolAxis(null, scale_bar_labels); scaleAxis.setRange(min, max); scaleAxis.setPlot(new PiePlot()); scaleAxis.setGridBandsVisible(false); // set up the paint scale: psl = new PaintScaleLegend(paintScale, scaleAxis); psl.setBackgroundPaint(new Color(255, 255, 255, 0)); // clear background // set up frame with buffer region to allow text display psl.setFrame(new LineBorder((Paint) Color.BLACK, new BasicStroke((float) 1.0), new RectangleInsets(15, 10, 15, 10))); psl.setAxisOffset(5.0); // display on right side: psl.setPosition(RectangleEdge.RIGHT); // margin around color scale: psl.setMargin(new RectangleInsets(20, 15, 20, 15)); // add to the chart so it will be displayed by default: chart.addSubtitle(psl); // -------------------------------------------- // WINDOW-RELATED UI // -------------------------------------------- // set up the generic plot UI: super.window_title = window_title; super.initUI(); // add another menu item JMenuBar mb = super.getJMenuBar(); // get the menu bar // find menu named "Plot" JMenu menu_plot = null; for (int i = 0; i < mb.getMenuCount(); i++) { if (mb.getMenu(i).getText() == "Plot") menu_plot = mb.getMenu(i); } // Add a new checkbox for the color scale bar JCheckBoxMenuItem menu_plot_scalebar = new JCheckBoxMenuItem("Color Scale"); menu_plot_scalebar.setToolTipText("Show color scale bar?"); menu_plot_scalebar.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); setScaleBar(selected); } }); // set appropirate checkbox state: menu_plot_scalebar.setState(true); if (menu_plot != null) // sanity check menu_plot.add(menu_plot_scalebar); }
From source file:de.tud.kom.p2psim.impl.skynet.visualization.SkyNetVisualization.java
public void setAvailableMetrics(Vector<String> names) { Vector<String> temp = new Vector<String>(); temp.addAll(names);//from w ww . j a v a2s . c o m temp.add("Online Peers"); temp.add("Available Attributes"); temp.add("Memory Usage"); Collections.sort(temp); JMenu met = mb.getMenu(1); met.setEnabled(true); JMenu avgMet = new JMenu("Average Metrics"); JMenu genMet = new JMenu("General Metrics"); JMenu recMet = new JMenu("Metrics for Receiving"); JMenu sentMet = new JMenu("Metrics for Sending"); JCheckBoxMenuItem item = null; for (String name : temp) { if (name.startsWith("Aver")) { item = new JCheckBoxMenuItem(name, false); item.addActionListener(this); avgMet.add(item); } else if (name.startsWith("Rec")) { item = new JCheckBoxMenuItem(name, false); item.addActionListener(this); recMet.add(item); } else if (name.startsWith("Sent")) { item = new JCheckBoxMenuItem(name, false); item.addActionListener(this); sentMet.add(item); } else { item = new JCheckBoxMenuItem(name, false); item.addActionListener(this); genMet.add(item); } } avgMet.add(new JSeparator(SwingConstants.HORIZONTAL)); avgMet.add(createMenuItem("Display all Average Metrics")); avgMet.add(createMenuItem("Remove all Average Metrics")); genMet.add(new JSeparator(SwingConstants.HORIZONTAL)); genMet.add(createMenuItem("Display all General Metrics")); genMet.add(createMenuItem("Remove all General Metrics")); recMet.add(new JSeparator(SwingConstants.HORIZONTAL)); recMet.add(createMenuItem("Display all Metrics for Receiving")); recMet.add(createMenuItem("Remove all Metrics for Receiving")); sentMet.add(new JSeparator(SwingConstants.HORIZONTAL)); sentMet.add(createMenuItem("Display all Metrics for Sending")); sentMet.add(createMenuItem("Remove all Metrics for Sending")); met.add(avgMet); met.add(genMet); met.add(recMet); met.add(sentMet); met.add(new JSeparator(SwingConstants.HORIZONTAL)); met.add(createMenuItem("Display all Metrics")); met.add(createMenuItem("Remove all Metrics")); mb.add(met); repaint(); log.warn("Created Menu 'Available Metrics'"); }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initOHLCSeries(int datasetNumber, XYDataset dataset, SeriesDefinitionVO seriesDefinition) { BarDefinitionVO barDefinition = (BarDefinitionVO) seriesDefinition; OHLCSeriesCollection ohlcSeriesCollection = (OHLCSeriesCollection) dataset; ohlcSeriesCollection.setXPosition(TimePeriodAnchor.START); // create the TimeSeries OHLCSeries series = new OHLCSeries(barDefinition.getLabel()); ohlcSeriesCollection.addSeries(series); this.bars.put(barDefinition.getSecurityId(), series); // get the seriesNumber & color final int seriesNumber = ohlcSeriesCollection.getSeriesCount() - 1; // configure the renderer final CandlestickRenderer renderer = (CandlestickRenderer) getPlot().getRenderer(datasetNumber); renderer.setSeriesPaint(seriesNumber, getColor(barDefinition.getColor())); renderer.setSeriesVisible(seriesNumber, seriesDefinition.isSelected()); renderer.setAutoWidthMethod(HideableCandlestickRenderer.WIDTHMETHOD_SMALLEST); // add the menu item JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel()); menuItem.setSelected(seriesDefinition.isSelected()); menuItem.addActionListener(new ActionListener() { @Override/*from w w w .j a v a 2s .c o m*/ public void actionPerformed(ActionEvent e) { resetAxis(); renderer.setSeriesVisible(seriesNumber, ((JCheckBoxMenuItem) e.getSource()).isSelected(), true); initAxis(); } }); this.getPopupMenu().add(menuItem); }
From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderJoinCondition.java
private void createPopupMenu() { bindingGroup = new BindingGroup(); menu = new JPopupMenu("Popup menu"); JMenuItem item1;//from ww w . j a v a2 s .c o m JCheckBoxMenuItem item2; JCheckBoxMenuItem item3; JCheckBoxMenuItem item4; item1 = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.GENERIC_DELETE)); item1.setActionCommand(DELETE); item1.addActionListener(this); item2 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MANDATORY)); Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${mandatory}"), item2, BeanProperty.create("selected")); bindingGroup.addBinding(binding); item2.setActionCommand(TOGGLE_MANDATORY); item2.addActionListener(this); item3 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_FOREIGN)); Binding binding2 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${monodirectional}"), item3, BeanProperty.create("selected")); bindingGroup.addBinding(binding2); item3.setActionCommand(TOGGLE_FOREIGN); item3.addActionListener(this); item4 = new JCheckBoxMenuItem(NbBundle.getMessage(Costanti.class, Costanti.TOGGLE_MATCH_STRING)); Binding binding3 = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ, joinCondition, ELProperty.create("${matchString}"), item4, BeanProperty.create("selected")); bindingGroup.addBinding(binding3); item4.setActionCommand(TOGGLE_MATCH_STRING); item4.addActionListener(this); menu.add(item1); menu.add(item2); menu.add(item3); menu.add(item4); bindingGroup.bind(); }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initTimeSeries(int datasetNumber, XYDataset dataset, SeriesDefinitionVO seriesDefinition) { IndicatorDefinitionVO indicatorDefinition = (IndicatorDefinitionVO) seriesDefinition; TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) dataset; // create the TimeSeries TimeSeries series = new TimeSeries(indicatorDefinition.getLabel()); timeSeriesCollection.addSeries(series); this.indicators.put(indicatorDefinition.getName(), series); // get the seriesNumber & color final int seriesNumber = timeSeriesCollection.getSeriesCount() - 1; // configure the renderer final XYItemRenderer renderer = getPlot().getRenderer(datasetNumber); renderer.setSeriesPaint(seriesNumber, getColor(indicatorDefinition.getColor())); renderer.setSeriesVisible(seriesNumber, seriesDefinition.isSelected()); renderer.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); if (seriesDefinition.isDashed()) { renderer.setSeriesStroke(seriesNumber, new BasicStroke(0.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f)); } else {/*from w ww .j ava 2s. c o m*/ renderer.setSeriesStroke(seriesNumber, new BasicStroke(0.5f)); } // add the menu item JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel()); menuItem.setSelected(seriesDefinition.isSelected()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetAxis(); renderer.setSeriesVisible(seriesNumber, ((JCheckBoxMenuItem) e.getSource()).isSelected()); initAxis(); } }); this.getPopupMenu().add(menuItem); }
From source file:ch.algotrader.client.chart.ChartTab.java
private void initMarker(SeriesDefinitionVO seriesDefinition) { final MarkerDefinitionVO markerDefinition = (MarkerDefinitionVO) seriesDefinition; final Marker marker; if (markerDefinition.isInterval()) { marker = new IntervalMarker(0, 0); marker.setLabelAnchor(RectangleAnchor.BOTTOM_RIGHT); // position of the label marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); // position of the text within the label } else {// ww w. jav a 2 s. c o m marker = new ValueMarker(0); marker.setLabelAnchor(RectangleAnchor.TOP_RIGHT); marker.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT); } marker.setPaint(getColor(markerDefinition.getColor())); marker.setLabel(markerDefinition.getLabel()); marker.setLabelFont(new Font("SansSerif", 0, 9)); if (seriesDefinition.isDashed()) { marker.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 5.0f }, 0.0f)); } else { marker.setStroke(new BasicStroke(1.0f)); } getPlot().addRangeMarker(marker, markerDefinition.isInterval() ? Layer.BACKGROUND : Layer.FOREGROUND); this.markers.put(markerDefinition.getName(), marker); this.markersSelectionStatus.put(markerDefinition.getName(), seriesDefinition.isSelected()); // add the menu item JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(seriesDefinition.getLabel()); menuItem.setSelected(seriesDefinition.isSelected()); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetAxis(); boolean selected = ((JCheckBoxMenuItem) e.getSource()).isSelected(); ChartTab.this.markersSelectionStatus.put(markerDefinition.getName(), selected); if (selected) { if (marker instanceof ValueMarker) { marker.setAlpha(1.0f); } else { marker.setAlpha(0.5f); } } else { marker.setAlpha(0); } initAxis(); } }); this.getPopupMenu().add(menuItem); }
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
private JPopupMenu getColumnMenu() { SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel(); JPopupMenu columnMenu = new JPopupMenu(); for (int i = 0; i < model.getColumnCount(); i++) { final String columnName = model.getColumnName(i); // Get the column object by name. Using an index may not return the column object if the column is hidden TableColumnExt column = getColumnExt(columnName); // Create the menu item final JCheckBoxMenuItem menuItem = new JCheckBoxMenuItem(columnName); // Show or hide the checkbox menuItem.setSelected(column.isVisible()); menuItem.addActionListener(new ActionListener() { @Override// w ww. j a v a2 s . c o m public void actionPerformed(ActionEvent arg0) { TableColumnExt column = getColumnExt(menuItem.getText()); // Determine whether to show or hide the selected column boolean enable = !column.isVisible(); // Do not hide a column if it is the last remaining visible column if (enable || getColumnCount() > 1) { column.setVisible(enable); Set<String> customHiddenColumns = customHiddenColumnMap.get(channelId); if (customHiddenColumns != null) { if (enable) { customHiddenColumns.remove(columnName); } else { customHiddenColumns.add(columnName); } } } saveColumnOrder(); } }); columnMenu.add(menuItem); } columnMenu.addSeparator(); JMenuItem menuItem = new JMenuItem("Collapse All"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { collapseAll(); } }); columnMenu.add(menuItem); menuItem = new JMenuItem("Expand All"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { expandAll(); } }); columnMenu.add(menuItem); columnMenu.addSeparator(); menuItem = new JMenuItem("Restore Default"); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (metaDataColumns != null) { defaultVisibleColumns.addAll(metaDataColumns); } restoreDefaultColumnPreferences(); } }); columnMenu.add(menuItem); return columnMenu; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * Build menu.//from w w w . j ava2s. co m */ public void makeMenu() { JMenuItem menuItem; JMenu menu; JMenu submenu; menuBar = new JMenuBar(); setJMenuBar(menuBar); menu = new JMenu(Menu.MENU_FILE); menu.setMnemonic(KeyEvent.VK_F); menuItem = new JMenuItem(Menu.NEW_SCHEME, KeyEvent.VK_N); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.LOAD_SCHEME, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD_SCHEME, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.SAVE_SCHEME, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SCHEME_AS); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.DELETE_SCHEME, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.EXPORT_MENU); menu.add(submenu); //submenu.setMnemonic( KeyEvent.VK_E ); SchemeExporter.makeSchemeExportMenu(submenu, getActionListener()); // Export window graphics submenu.add(GraphicsExporter.getExportMenu()); menu.addSeparator(); menuItem = new JMenuItem(Menu.PRINT, KeyEvent.VK_P); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK)); menu.add(menuItem); menu.addSeparator(); menuItem = new JMenuItem(Menu.EXIT, KeyEvent.VK_X); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu = new JMenu(Menu.MENU_EDIT); menu.setMnemonic(KeyEvent.VK_E); menu.add(undoAction); menu.add(redoAction); menu.add(cloneAction); menuItem = new JMenuItem(Menu.SCHEME_FIND, KeyEvent.VK_F); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.SELECT_ALL, KeyEvent.VK_A); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLEAR_ALL, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); final JCheckBoxMenuItem painterEnabled = new JCheckBoxMenuItem(Menu.CLASSPAINTER, true); painterEnabled.addActionListener(getActionListener()); menu.add(painterEnabled); menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas = Editor.getInstance().getCurrentCanvas(); if (canvas == null || !canvas.getPackage().hasPainters()) { painterEnabled.setVisible(false); } else { painterEnabled.setVisible(true); painterEnabled.setSelected(canvas.isEnableClassPainter()); } } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_VIEW); menu.setMnemonic(KeyEvent.VK_V); gridCheckBox = new JCheckBoxMenuItem(Menu.GRID, RuntimeProperties.isShowGrid()); gridCheckBox.setMnemonic('G'); gridCheckBox.addActionListener(getActionListener()); menu.add(gridCheckBox); ctrlCheckBox = new JCheckBoxMenuItem(Menu.CONTROL_PANEL, RuntimeProperties.isShowControls()); ctrlCheckBox.setMnemonic('C'); ctrlCheckBox.addActionListener(getActionListener()); menu.add(ctrlCheckBox); showPortCheckBox = new JCheckBoxMenuItem(Menu.SHOW_PORTS, true); showPortCheckBox.addActionListener(getActionListener()); menu.add(showPortCheckBox); showObjectNamesCheckBox = new JCheckBoxMenuItem(Menu.SHOW_NAMES, false); showObjectNamesCheckBox.addActionListener(getActionListener()); menu.add(showObjectNamesCheckBox); //sync View with current canvas menu.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { Canvas canvas; if ((canvas = getCurrentCanvas()) == null) return; gridCheckBox.setSelected(canvas.isGridVisible()); ctrlCheckBox.setSelected(canvas.isCtrlPanelVisible()); showPortCheckBox.setSelected(canvas.isDrawPorts()); showObjectNamesCheckBox.setSelected(canvas.isShowObjectNames()); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menuBar.add(menu); menu = new JMenu(Menu.MENU_PACKAGE); menu.setMnemonic(KeyEvent.VK_P); menuItem = new JMenuItem(Menu.LOAD, KeyEvent.VK_L); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.RELOAD, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.INFO, KeyEvent.VK_I); menuItem.addActionListener(getActionListener()); menu.add(menuItem); if (Desktop.isDesktopSupported()) { menuItem = new JMenuItem(Menu.BROWSE_PACKAGE, KeyEvent.VK_B); menuItem.addActionListener(getActionListener()); menu.add(menuItem); } menuItem = new JMenuItem(Menu.CLOSE, KeyEvent.VK_C); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.CLOSE_ALL); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuBar.add(menu); menu.add(new JSeparator()); final JMenu submenuRecent = new JMenu(Menu.RECENT); submenuRecent.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { final JMenuItem empty = new JMenuItem("Empty"); @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeRecentSubMenu(submenuRecent); if (submenuRecent.getMenuComponentCount() == 0) { submenuRecent.add(empty); empty.setEnabled(false); } else { if (!((submenuRecent.getMenuComponentCount() == 1) && (submenuRecent.getPopupMenu().getComponentIndex(empty) >= -1))) { submenuRecent.remove(empty); } } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); menu.add(submenuRecent); final JMenu menuScheme = new JMenu(Menu.MENU_SCHEME); menuScheme.setMnemonic(KeyEvent.VK_S); makeSchemeMenu(menuScheme); menuScheme.getPopupMenu().addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { makeSchemeMenu(menuScheme); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // ignore } @Override public void popupMenuCanceled(PopupMenuEvent e) { // ignore } }); /* * menuItem = new JMenuItem("Planner"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); * menuItem = new JMenuItem("Plan, compile, run"); * menuItem.setActionCommand("Run"); * menuItem.addActionListener(aListener); menuScheme.add(menuItem); */ // menuScheme.setMnemonic(KeyEvent.VK_A); menuBar.add(menuScheme); menu = new JMenu(Menu.MENU_OPTIONS); menu.setMnemonic(KeyEvent.VK_O); menuItem = new JMenuItem(Menu.SETTINGS, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_J, ActionEvent.CTRL_MASK)); menu.add(menuItem); menuItem = new JMenuItem(Menu.FONTS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.SAVE_SETTINGS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); submenu = new JMenu(Menu.MENU_LAF); submenu.setMnemonic(KeyEvent.VK_L); Look.getInstance().createMenuItems(submenu); menu.add(submenu); menuBar.add(menu); makeToolsMenu(menuBar); menu = new JMenu(Menu.MENU_HELP); menu.setMnemonic(KeyEvent.VK_H); menuBar.add(menu); menuItem = new JMenuItem(Menu.DOCS, KeyEvent.VK_D); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:SciTK.Plot.java
/** * Load the initial UI//from ww w . j av a 2s . c o m */ protected final void initUI() { setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); // create a ChartPanel, and make it default to 1/4 of screen size: chart_panel = new ChartPanel(chart); chart_panel.setPreferredSize(new Dimension(def_width, def_height)); //add the chart to the window: getContentPane().add(chart_panel); // create a menu bar: menubar = new JMenuBar(); // --------------------------------------------------------- // First dropdown menu: "File" // --------------------------------------------------------- file = new JMenu("File"); file.setMnemonic(KeyEvent.VK_F); // Set up a save dialog option under the file menu: JMenuItem menu_file_save; ImageIcon menu_file_save_icon = null; try { menu_file_save_icon = new ImageIcon(getClass().getResource("/SciTK/resources/document-save-5.png")); menu_file_save = new JMenuItem("Save", menu_file_save_icon); } catch (Exception e) { menu_file_save = new JMenuItem("Save"); } menu_file_save.setMnemonic(KeyEvent.VK_S); menu_file_save.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menu_file_save.setToolTipText("Save an image"); menu_file_save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { saveImage(); } }); file.add(menu_file_save); // Set up a save SVG dialog option under the file menu: JMenuItem menu_file_save_svg; try { menu_file_save_svg = new JMenuItem("Save VG", menu_file_save_icon); } catch (Exception e) { menu_file_save_svg = new JMenuItem("Save VG"); } menu_file_save_svg.setToolTipText("Save as vector graphics (SVG,PS,EPS)"); menu_file_save_svg.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { saveVectorGraphics(); } }); file.add(menu_file_save_svg); // Set up a save data dialog option under the file menu: JMenuItem menu_file_save_data; try { menu_file_save_data = new JMenuItem("Save data", menu_file_save_icon); } catch (Exception e) { menu_file_save_data = new JMenuItem("Save data"); } menu_file_save_data.setToolTipText("Save raw data to file"); menu_file_save_data.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { saveData(); } }); file.add(menu_file_save_data); // Set up a save data dialog option under the file menu: JMenuItem menu_file_print; try { ImageIcon menu_file_print_icon = new ImageIcon( getClass().getResource("/SciTK/resources/document-print-5.png")); menu_file_print = new JMenuItem("Print", menu_file_print_icon); } catch (Exception e) { menu_file_print = new JMenuItem("Print"); } menu_file_print.setToolTipText("Print image of chart"); menu_file_print.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { printPlot(); } }); file.add(menu_file_print); // menu item for exiting JMenuItem menu_file_exit; try { ImageIcon menu_file_exit_icon = new ImageIcon( getClass().getResource("/SciTK/resources/application-exit.png")); menu_file_exit = new JMenuItem("Exit", menu_file_exit_icon); } catch (Exception e) { menu_file_exit = new JMenuItem("Exit"); } menu_file_exit.setMnemonic(KeyEvent.VK_X); menu_file_exit.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menu_file_exit.setToolTipText("Exit application"); menu_file_exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { dispose(); } }); file.add(menu_file_exit); // --------------------------------------------------------- // Second dropdown menu: "Edit" // --------------------------------------------------------- edit = new JMenu("Edit"); edit.setMnemonic(KeyEvent.VK_E); // copy to clipboard JMenuItem menu_edit_copy_image; ImageIcon menu_edit_copy_icon = null; try { menu_edit_copy_icon = new ImageIcon(getClass().getResource("/SciTK/resources/edit-copy-7.png")); menu_edit_copy_image = new JMenuItem("Copy", menu_edit_copy_icon); } catch (Exception e) { menu_edit_copy_image = new JMenuItem("Copy"); } menu_edit_copy_image.setMnemonic(KeyEvent.VK_C); menu_edit_copy_image.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menu_edit_copy_image.setToolTipText("Copy image to clipboard"); menu_edit_copy_image.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { copyImage(); } }); edit.add(menu_edit_copy_image); // copy data to clipboard JMenuItem menu_edit_copy_data; try { menu_edit_copy_data = new JMenuItem("Copy data", menu_edit_copy_icon); } catch (Exception e) { menu_edit_copy_data = new JMenuItem("Copy data"); } menu_edit_copy_data.setToolTipText("Copy data to clipboard"); menu_edit_copy_data.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { copyData(); } }); edit.add(menu_edit_copy_data); // set background color JMenuItem menu_edit_BackgroundColor; ImageIcon menu_edit_Color_icon = null; try { menu_edit_Color_icon = new ImageIcon(getClass().getResource("/SciTK/resources/color-wheel.png")); menu_edit_BackgroundColor = new JMenuItem("Background Color", menu_edit_Color_icon); } catch (Exception e) { menu_edit_BackgroundColor = new JMenuItem("Background Color"); } menu_edit_BackgroundColor.setToolTipText("Select background color"); menu_edit_BackgroundColor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Color bgColor = plotColorChooser("Choose background color", (Color) chart.getBackgroundPaint()); setBackgroundColor(bgColor); } }); edit.add(menu_edit_BackgroundColor); // set plot color JMenuItem menu_edit_PlotColor; try { menu_edit_PlotColor = new JMenuItem("Window Color", menu_edit_Color_icon); } catch (Exception e) { menu_edit_PlotColor = new JMenuItem("Window Color"); } menu_edit_PlotColor.setToolTipText("Select plot window color"); menu_edit_PlotColor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Color plotColor = plotColorChooser("Choose plot color", (Color) chart.getPlot().getBackgroundPaint()); setWindowBackground(plotColor); } }); edit.add(menu_edit_PlotColor); // set gridline color JMenuItem menu_edit_GridlineColor; try { menu_edit_GridlineColor = new JMenuItem("Gridline Color", menu_edit_Color_icon); } catch (Exception e) { menu_edit_GridlineColor = new JMenuItem("Gridline Color"); } menu_edit_GridlineColor.setToolTipText("Select grid color"); menu_edit_GridlineColor.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { Color gridColor = plotColorChooser("Choose grid color", (Color) chart.getPlot().getBackgroundPaint()); setGridlineColor(gridColor); } }); edit.add(menu_edit_GridlineColor); // edit chart preferences JMenuItem menu_edit_preferences; try { ImageIcon menu_edit_preferences_icon = new ImageIcon( getClass().getResource("/SciTK/resources/preferences-desktop-3.png")); menu_edit_preferences = new JMenuItem("Preferences", menu_edit_preferences_icon); } catch (Exception e) { menu_edit_preferences = new JMenuItem("Preferences"); } menu_edit_preferences.setToolTipText("Edit chart preferences"); menu_edit_preferences.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { chart_panel.doEditChartProperties(); } }); edit.add(menu_edit_preferences); // --------------------------------------------------------- // Third dropdown menu: "Plot" // --------------------------------------------------------- plot = new JMenu("Plot"); plot.setMnemonic(KeyEvent.VK_P); // Options to set log axes JCheckBoxMenuItem menu_plot_ylog = new JCheckBoxMenuItem("Log y axis"); menu_plot_ylog.setToolTipText("Set y axis to logarithmic"); menu_plot_ylog.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); setRangeAxisLog(selected); } }); plot.add(menu_plot_ylog); JCheckBoxMenuItem menu_plot_xlog = new JCheckBoxMenuItem("Log x axis"); menu_plot_xlog.setToolTipText("Set x axis to logarithmic"); menu_plot_xlog.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); setDomainAxisLog(selected); } }); plot.add(menu_plot_xlog); // grid line display JCheckBoxMenuItem menu_plot_grid = new JCheckBoxMenuItem("Grid lines"); menu_plot_grid.setToolTipText("Show plot grid lines?"); menu_plot_grid.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); setGridlineVisible(selected); } }); // set appropirate checkbox state: menu_plot_grid.setState(chart.getXYPlot().isDomainGridlinesVisible()); plot.add(menu_plot_grid); // control for displaying plot legend JCheckBoxMenuItem menu_plot_legend = new JCheckBoxMenuItem("Legend"); menu_plot_legend.setToolTipText("Show plot legend?"); menu_plot_legend.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); setLegend(selected); } }); // set appropirate checkbox state: menu_plot_legend.setState((chart.getLegend() instanceof LegendTitle)); plot.add(menu_plot_legend); // --------------------------------------------------------- // General UI // --------------------------------------------------------- // Add menus to the menu bar: menubar.add(file); menubar.add(edit); menubar.add(plot); // Set menubar as this JFrame's menu setJMenuBar(menubar); // set default plot colors: chart.setBackgroundPaint(new Color(255, 255, 255, 0)); chart.getPlot().setBackgroundPaint(new Color(255, 255, 255, 255)); setBackgroundAlpha(0.0f); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); pack(); setTitle(window_title); setLocationRelativeTo(null); setVisible(true); }