List of usage examples for javax.swing JMenu JMenu
public JMenu(Action a)
Action
supplied. From source file:uk.co.petertribble.jkstat.gui.KstatBaseChartFrame.java
/** * Create the Statistics Menu, showing all available statistics for the * chosen ChartableKstat./*from w ww .ja v a 2 s. co m*/ * * @param cks the Kstat to show the statistics of in the menu * @param statistic the initial statistic, which will be checked * * @return the Statistics Menu */ protected JMenu statisticsMenu(ChartableKstat cks, String statistic) { JMenu jmstat = new JMenu(KstatResources.getString("CHART.SHOW")); jmstat.setMnemonic(KeyEvent.VK_S); for (String stat : cks.getStatistics()) { JCheckBoxMenuItem jmi = new JCheckBoxMenuItem(stat, stat.equals(statistic)); jmi.addActionListener(this); jmstat.add(jmi); } return jmstat; }
From source file:org.peerfact.impl.service.aggregation.skyeye.visualization.SkyNetVisualization.java
private SkyNetVisualization() { super("Metric-Visualization"); createLookAndFeel();/*from w w w . ja va2s. com*/ displayedMetrics = new LinkedHashMap<String, MetricsPlot>(); setLayout(new GridLayout(1, 1)); addWindowListener(this); graphix = new JPanel(new GridBagLayout()); graphix.setLayout(new BoxLayout(graphix, BoxLayout.PAGE_AXIS)); mb = new JMenuBar(); JScrollPane scroller = new JScrollPane(graphix, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // calculating the size of the application-window as well as of all // components, that depend on the size of the window Toolkit kit = Toolkit.getDefaultToolkit(); int appWidth = kit.getScreenSize().width * 3 / 4; int appHeight = kit.getScreenSize().height * 3 / 4; scroller.setPreferredSize(new Dimension(appWidth, appHeight)); getContentPane().add(scroller); maxPlotsPerRow = 1; while ((maxPlotsPerRow + 1) * PLOT_WIDTH < appWidth) { maxPlotsPerRow++; } log.warn("Creating the visualization..."); mb.add(new JMenu("File")); JMenu met = new JMenu("Available Metrics"); met.setEnabled(false); mb.add(met); setJMenuBar(mb); }
From source file:JDAC.JDAC.java
public JDAC() { setTitle("JDAC"); ImageIcon img = new ImageIcon("logo.png"); setIconImage(img.getImage());/*w ww .jav a 2 s. c o m*/ //setLayout(new FlowLayout()); mDataset = createDataset("A"); mChart = ChartFactory.createXYLineChart("Preview", "Time (ms)", "Value", mDataset, PlotOrientation.VERTICAL, false, true, false); mLastChart = ChartFactory.createXYLineChart("Last n values", "Time (ms)", "Value", createLastDataset("B"), PlotOrientation.VERTICAL, false, true, false); mChart.getXYPlot().getDomainAxis().setLowerMargin(0); mChart.getXYPlot().getDomainAxis().setUpperMargin(0); mLastChart.getXYPlot().getDomainAxis().setLowerMargin(0); mLastChart.getXYPlot().getDomainAxis().setUpperMargin(0); ChartPanel chartPanel = new ChartPanel(mChart); ChartPanel chartLastPanel = new ChartPanel(mLastChart); //chartPanel.setPreferredSize( new java.awt.Dimension( 560 , 367 ) ); XYPlot plot = mChart.getXYPlot(); XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(); renderer.setSeriesPaint(0, Color.GREEN); renderer.setSeriesStroke(0, new BasicStroke(1.0f)); plot.setRenderer(renderer); XYPlot lastPlot = mLastChart.getXYPlot(); XYLineAndShapeRenderer lastRenderer = new XYLineAndShapeRenderer(); lastRenderer.setSeriesPaint(0, Color.RED); lastRenderer.setSeriesStroke(0, new BasicStroke(1.0f)); lastPlot.setRenderer(lastRenderer); resetChartButton = new JButton("Reset"); resetChartButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { resetChart(); } }); mMenuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenu sensorMenu = new JMenu("Sensor"); JMenu deviceMenu = new JMenu("Device"); portSubMenu = new JMenu("Port"); JMenu helpMenu = new JMenu("Help"); serialStatusLabel = new JLabel("Disconnected"); statusLabel = new JLabel("Ready"); clearStatus = new LabelClear(statusLabel); clearStatus.resetTime(); connectButton = new JMenuItem("Connect"); disconnectButton = new JMenuItem("Disconnect"); startButton = new JButton("Start"); stopButton = new JButton("Stop"); scanButton = new JMenuItem("Refresh port list"); exportCSVButton = new JMenuItem("Export data to CSV"); exportCSVButton.setAccelerator(KeyStroke.getKeyStroke("control S")); exportCSVButton.setMnemonic(KeyEvent.VK_S); exportPNGButton = new JMenuItem("Export chart to PNG"); JPanel optionsPanel = new JPanel(new BorderLayout()); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.setAccelerator(KeyStroke.getKeyStroke("control X")); exitItem.setMnemonic(KeyEvent.VK_X); JMenuItem aboutItem = new JMenuItem("About"); JMenuItem helpItem = new JMenuItem("Help"); JMenuItem quickStartItem = new JMenuItem("Quick start"); lastSpinner = new JSpinner(new SpinnerNumberModel(10, 0, 1000, 1)); ActionListener mSensorListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setSensor(e.getActionCommand()); } }; ButtonGroup sensorGroup = new ButtonGroup(); JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem("Temperature"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Distance"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Voltage"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); tmpRadioButton = new JRadioButtonMenuItem("Generic"); tmpRadioButton.setSelected(true); setSensor("Generic"); sensorGroup.add(tmpRadioButton); sensorMenu.add(tmpRadioButton); tmpRadioButton.addActionListener(mSensorListener); connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (selectedPortName == null) { setStatus("No port selected"); return; } connect(selectedPortName); } }); disconnectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { serialStatusLabel.setText("Disconnecting..."); if (serialPort == null) { serialStatusLabel.setText("Disconnected"); serialConnected = false; return; } stopCollect(); disconnect(); } }); scanButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { searchForPorts(); } }); exportCSVButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveData(); } }); exportPNGButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { exportPNG(); } }); startButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { startCollect(); } }); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { stopCollect(); } }); lastSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { numLastValues = (Integer) lastSpinner.getValue(); updateLastTitle(); } }); updateLastTitle(); exitItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); helpItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new HelpFrame(); } }); aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new AboutFrame(); } }); quickStartItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new StartFrame(); } }); fileMenu.add(exportCSVButton); fileMenu.add(exportPNGButton); fileMenu.addSeparator(); fileMenu.add(exitItem); deviceMenu.add(connectButton); deviceMenu.add(disconnectButton); deviceMenu.addSeparator(); deviceMenu.add(portSubMenu); deviceMenu.add(scanButton); helpMenu.add(quickStartItem); helpMenu.add(helpItem); helpMenu.add(aboutItem); mMenuBar.add(fileMenu); mMenuBar.add(sensorMenu); mMenuBar.add(deviceMenu); mMenuBar.add(helpMenu); JPanel controlsPanel = new JPanel(); controlsPanel.add(startButton); controlsPanel.add(stopButton); controlsPanel.add(resetChartButton); optionsPanel.add(controlsPanel, BorderLayout.LINE_START); JPanel lastPanel = new JPanel(new FlowLayout()); lastPanel.add(new JLabel("Shown values: ")); lastPanel.add(lastSpinner); optionsPanel.add(lastPanel); JPanel serialPanel = new JPanel(new FlowLayout()); serialPanel.add(serialStatusLabel); optionsPanel.add(serialPanel, BorderLayout.LINE_END); add(optionsPanel, BorderLayout.PAGE_START); JPanel mainPanel = new JPanel(new GridLayout(0, 2)); mainPanel.add(chartPanel); mainPanel.add(chartLastPanel); add(mainPanel); add(statusLabel, BorderLayout.PAGE_END); setJMenuBar(mMenuBar); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { dispose(); } }); setSize(800, 800); pack(); new StartFrame(); //center on screen Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); int x = (int) ((dimension.getWidth() - getWidth()) / 2); int y = (int) ((dimension.getHeight() - getHeight()) / 2); setLocation(x, y); setVisible(true); }
From source file:org.simbrain.plot.barchart.BarChartGui.java
/** * Creates the menu bar.//from w w w . j av a 2 s . c o m */ private void createAttachMenuBar() { JMenuBar bar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); for (Action action : actionManager.getOpenSavePlotActions()) { fileMenu.add(action); } fileMenu.addSeparator(); fileMenu.add(new CloseAction(this.getWorkspaceComponent())); JMenu editMenu = new JMenu("Edit"); JMenuItem preferences = new JMenuItem("Preferences..."); preferences.addActionListener(this); preferences.setActionCommand("dialog"); editMenu.add(preferences); JMenu helpMenu = new JMenu("Help"); ShowHelpAction helpAction = new ShowHelpAction("Pages/Plot/bar_chart.html"); JMenuItem helpItem = new JMenuItem(helpAction); helpMenu.add(helpItem); bar.add(fileMenu); bar.add(editMenu); bar.add(helpMenu); getParentFrame().setJMenuBar(bar); }
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 w w . ja v a 2 s. com 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:com.documentgenerator.view.MainWindow.java
private void addMenu(JSONObject jsonMenu) { menu = new JMenu((String) jsonMenu.get("menuTitle")); menu.setMnemonic(((String) jsonMenu.get("mnemonic")).charAt(0)); List<JMenuItem> menuItems = getMenuItem((JSONArray) jsonMenu.get("menuItem")); for (JMenuItem menuItem : menuItems) { menu.add(menuItem);/*from w ww. j av a 2s . co m*/ } menuBar.add(menu); }
From source file:TreeUtil.java
/** * Makes menus from the root node//from w w w . j a v a2 s . com */ public JMenuItem getMenus() { JMenu rootMenu = new JMenu(itsRootNode.getUserObject().toString()); rootMenu.setActionCommand("TreeMenu"); rootMenu.addActionListener(this); return getMenus(itsRootNode, rootMenu); }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
@Override protected JMenuItem buildAddCriterionItem() { JMenu menu = new JMenu("Add new"); menu.setIcon(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ADDCRITERION)); addUtilityAddItemsToMenu(menu);//from w w w. j av a 2 s.co m return menu; }
From source file:misc.ActionDemo.java
protected JMenu createAbleMenu() { JMenu ableMenu = new JMenu("Action State"); cbmi = new JCheckBoxMenuItem[3]; cbmi[0] = new JCheckBoxMenuItem("First action enabled"); cbmi[1] = new JCheckBoxMenuItem("Second action enabled"); cbmi[2] = new JCheckBoxMenuItem("Third action enabled"); for (int i = 0; i < cbmi.length; i++) { cbmi[i].setSelected(true);//from www .j a v a2 s .c o m cbmi[i].addItemListener(this); ableMenu.add(cbmi[i]); } return ableMenu; }
From source file:de.burrotinto.jKabel.dispalyAS.DisplayAAS.java
private JMenu getjTrommelSortMenu() { JMenu trommelSortMenu = new JMenu("Trommel Sortierung"); JRadioButtonMenuItem inOrder = new JRadioButtonMenuItem("Aufsteigend Sortieren"); inOrder.setSelected(ConfigReader.getInstance().isTypeInOrder()); inOrder.addActionListener(new ActionListener() { @Override/*from w w w .java2 s . c o m*/ public void actionPerformed(ActionEvent actionEvent) { try { ConfigReader.getInstance().setTrommelInOrder(inOrder.isSelected()); // if (kabelTypAuswahlAAS != null) { // kabelTypAuswahlAAS.typSelected(kabelTypAuswahlAAS.getSelected()); // } } catch (IOException e) { e.printStackTrace(); } } }); trommelSortMenu.add(inOrder); trommelSortMenu.addSeparator(); ButtonGroup group = new ButtonGroup(); for (AbstractTrommelSort aTS : ConfigReader.getInstance().getAllTrommelSort()) { JRadioButtonMenuItem sw = new JRadioButtonMenuItem(aTS.getName()); sw.setSelected(aTS.equals(ConfigReader.getInstance().getTrommelSort())); group.add(sw); trommelSortMenu.add(sw); sw.addActionListener(aTS); } return trommelSortMenu; }