List of usage examples for javax.swing JMenuItem JMenuItem
public JMenuItem(Action a)
Action
. From source file:lu.lippmann.cdb.ext.hydviga.ui.GapsOverviewPanel.java
public void refresh(final Instances dataSet, final int dateIdx) { final Instances gapsDescriptionsDataset = GapsUtil.buildGapsDescription(gcp, dataSet, dateIdx); final JXTable gapsDescriptionsTable = new JXTable(); final InstanceTableModel gapsDescriptionsTableModel = new InstanceTableModel(false); gapsDescriptionsTableModel.setDataset(gapsDescriptionsDataset); gapsDescriptionsTable.setModel(gapsDescriptionsTableModel); gapsDescriptionsTable.setEditable(true); gapsDescriptionsTable.setShowHorizontalLines(false); gapsDescriptionsTable.setShowVerticalLines(false); gapsDescriptionsTable.setVisibleRowCount(5); gapsDescriptionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); gapsDescriptionsTable.setSortable(false); gapsDescriptionsTable.packAll();/*from ww w.j a va 2 s . co m*/ gapsDescriptionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsDescriptionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int modelRow = gapsDescriptionsTable.getSelectedRow(); if (modelRow < 0) modelRow = 0; final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()).doubleValue(); try { final ChartPanel cp = GapsUIUtil.buildGapChartPanel(dataSet, dateIdx, attr, gapsize, position); visualOverviewPanel.removeAll(); visualOverviewPanel.add(cp, BorderLayout.CENTER); geomapPanel.removeAll(); geomapPanel.add(gcp.getMapPanel(Arrays.asList(attrname), new ArrayList<String>(), false)); jxp.updateUI(); } catch (Exception ee) { ee.printStackTrace(); } } } }); gapsDescriptionsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { final InstanceTableModel instanceTableModel = (InstanceTableModel) gapsDescriptionsTable.getModel(); final int row = gapsDescriptionsTable.rowAtPoint(e.getPoint()); //final int row=gapsDescriptionsTable.getSelectedRow(); final int modelRow = gapsDescriptionsTable.convertRowIndexToModel(row); //final int modelRow=(int)Double.valueOf(instanceTableModel.getValueAt(row,0).toString()).doubleValue(); //System.out.println(row+" "+modelRow); final String attrname = instanceTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double.valueOf(instanceTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem interactiveFillMenuItem = new JMenuItem("Fill this gap (interactively)"); interactiveFillMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final GapFillingFrame jxf = new GapFillingFrame(atv, dataSet, attr, dateIdx, GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), position, gapsize, gcp, false); jxf.setSize(new Dimension(900, 700)); //jxf.setExtendedState(Frame.MAXIMIZED_BOTH); jxf.setLocationRelativeTo(jPopupMenu); jxf.setVisible(true); //jxf.setResizable(false); } }); jPopupMenu.add(interactiveFillMenuItem); final JMenuItem lookupInKnowledgeDBMenuItem = new JMenuItem( "Show the most similar cases from KnowledgeDB"); lookupInKnowledgeDBMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final double x = gcp.getCoordinates(attrname)[0]; final double y = gcp.getCoordinates(attrname)[1]; final String season = instanceTableModel.getValueAt(modelRow, 3).toString() .split("/")[0]; final boolean isDuringRising = instanceTableModel.getValueAt(modelRow, 11).toString() .equals("true"); try { final Calendar cal = Calendar.getInstance(); final String dateAsString = instanceTableModel.getValueAt(modelRow, 2).toString() .replaceAll("'", ""); cal.setTime(FormatterUtil.DATE_FORMAT.parse(dateAsString)); final int year = cal.get(Calendar.YEAR); new SimilarCasesFrame(dataSet, dateIdx, gcp, attrname, gapsize, position, x, y, year, season, isDuringRising); } catch (Exception e1) { e1.printStackTrace(); } } }); jPopupMenu.add(lookupInKnowledgeDBMenuItem); final JMenuItem mExport = new JMenuItem("Export this table as CSV"); mExport.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); final int returnVal = fc.showSaveDialog(gapsDescriptionsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(gapsDescriptionsDataset, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsDescriptionsTable, e.getX(), e.getY()); } } }); final int tableWidth = (int) gapsDescriptionsTable.getPreferredSize().getWidth() + 30; final JScrollPane scrollPane = new JScrollPane(gapsDescriptionsTable); scrollPane.setPreferredSize(new Dimension(Math.min(tableWidth, 500), 500)); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.tablePanel.removeAll(); this.tablePanel.add(scrollPane, BorderLayout.CENTER); this.visualOverviewPanel.removeAll(); /* automatically compute the most similar series and the 'rising' flag */ new AbstractSimpleAsync<Void>(false) { @Override public Void execute() throws Exception { final int rc = gapsDescriptionsTableModel.getRowCount(); for (int i = 0; i < rc; i++) { final int modelRow = i; try { final String attrname = gapsDescriptionsTableModel.getValueAt(modelRow, 1).toString(); final Attribute attr = dataSet.attribute(attrname); final int gapsize = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 5).toString()) .doubleValue(); final int position = (int) Double .valueOf(gapsDescriptionsTableModel.getValueAt(modelRow, 6).toString()) .doubleValue(); /* most similar */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 7); final int cvba = GapsUtil.getCountOfValuesBeforeAndAfter(gapsize); Instances gapds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0, dataSet.numAttributes() - 1, Math.max(0, position - cvba), Math.min(position + gapsize + cvba, dataSet.numInstances() - 1)); final String mostsimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(gapds, attr, WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(gapds), false); gapsDescriptionsTableModel.setValueAt(mostsimilar, modelRow, 7); /* 'rising' flag */ gapsDescriptionsTableModel.setValueAt("...", modelRow, 11); final List<String> attributeNames = WekaDataStatsUtil.getAttributeNames(dataSet); attributeNames.remove("timestamp"); final String nearestStationName = gcp.findNearestStation(attr.name(), attributeNames); final Attribute nearestStationAttr = dataSet.attribute(nearestStationName); //System.out.println(nearestStationName+" "+nearestStationAttr); final boolean isDuringRising = GapsUtil.isDuringRising(dataSet, position, gapsize, new int[] { dateIdx, attr.index(), nearestStationAttr.index() }); gapsDescriptionsTableModel.setValueAt(isDuringRising, modelRow, 11); gapsDescriptionsTableModel.fireTableDataChanged(); } catch (Exception e) { gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 7); gapsDescriptionsTableModel.setValueAt("n/a", modelRow, 11); e.printStackTrace(); } } return null; } @Override public void onSuccess(Void result) { } @Override public void onFailure(Throwable caught) { caught.printStackTrace(); } }.start(); /* select the first row */ gapsDescriptionsTable.setRowSelectionInterval(0, 0); }
From source file:org.simbrain.plot.scatterplot.ScatterPlotGui.java
/** * Creates the menu bar./*from ww w . ja va 2 s . com*/ */ 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/scatter_plot.html"); JMenuItem helpItem = new JMenuItem(helpAction); helpMenu.add(helpItem); bar.add(fileMenu); bar.add(editMenu); bar.add(helpMenu); getParentFrame().setJMenuBar(bar); }
From source file:javazoom.jlgui.player.amp.equalizer.ui.EqualizerUI.java
public void loadUI() { log.info("Load EqualizerUI (EDT=" + SwingUtilities.isEventDispatchThread() + ")"); removeAll();//from w w w . j a v a 2 s . c om // Background ImageBorder border = new ImageBorder(); border.setImage(ui.getEqualizerImage()); setBorder(border); // On/Off add(ui.getAcEqOnOff(), ui.getAcEqOnOff().getConstraints()); ui.getAcEqOnOff().removeActionListener(this); ui.getAcEqOnOff().addActionListener(this); // Auto add(ui.getAcEqAuto(), ui.getAcEqAuto().getConstraints()); ui.getAcEqAuto().removeActionListener(this); ui.getAcEqAuto().addActionListener(this); // Sliders add(ui.getAcEqPresets(), ui.getAcEqPresets().getConstraints()); for (int i = 0; i < ui.getAcEqSliders().length; i++) { add(ui.getAcEqSliders()[i], ui.getAcEqSliders()[i].getConstraints()); ui.getAcEqSliders()[i].setValue(maxGain - gainValue[i]); ui.getAcEqSliders()[i].removeChangeListener(this); ui.getAcEqSliders()[i].addChangeListener(this); } if (ui.getSpline() != null) { ui.getSpline().setValues(gainValue); add(ui.getSpline(), ui.getSpline().getConstraints()); } // Popup menu on TitleBar mainpopup = new JPopupMenu(); String[] presets = { "Normal", "Classical", "Club", "Dance", "Full Bass", "Full Bass & Treble", "Full Treble", "Laptop", "Live", "Party", "Pop", "Reggae", "Rock", "Techno" }; JMenuItem mi; for (int p = 0; p < presets.length; p++) { mi = new JMenuItem(presets[p]); mi.removeActionListener(this); mi.addActionListener(this); mainpopup.add(mi); } ui.getAcEqPresets().removeActionListener(this); ui.getAcEqPresets().addActionListener(this); validate(); }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
private JMenuItem createAddScaleCriterionItem() { JMenuItem cardCrit = new JMenuItem("Cardinal"); cardCrit.setIcon(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_CARDINALCRITERION)); cardCrit.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { addCriterionAndStartRename(new ScaleCriterion(generateNextCriterionName())); }/*from www. ja v a 2 s . c om*/ }); return cardCrit; }
From source file:be.nbb.demetra.dfm.output.simulation.RMSEGraphView.java
private JMenu buildMenu() { JMenu menu = new JMenu(); JMenuItem item;//from w ww. java2 s . c om item = new JMenuItem(new CopyAction()); item.setText("Copy data"); menu.add(item); return menu; }
From source file:DragPictureDemo2.java
public JMenuBar createMenuBar() { JMenuItem menuItem = null;/*from w w w .j a v a 2 s . c o m*/ JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); TransferActionListener actionListener = new TransferActionListener(); menuItem = new JMenuItem("Cut"); menuItem.setActionCommand((String) TransferHandler.getCutAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem("Copy"); menuItem.setActionCommand((String) TransferHandler.getCopyAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem("Paste"); menuItem.setActionCommand((String) TransferHandler.getPasteAction().getValue(Action.NAME)); menuItem.addActionListener(actionListener); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, ActionEvent.CTRL_MASK)); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:common.AbstractGUI.java
private void createToolMenu() { toolMenu = new JMenu("Tools"); menuBar.add(toolMenu);/*from ww w .jav a 2 s . c om*/ takeSnapshotMenuItem = new JMenuItem("Take snapshot"); takeSnapshotMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.ALT_MASK)); takeSnapshotMenuItem.addActionListener(snapshotActionListener); toolMenu.add(takeSnapshotMenuItem); }
From source file:edu.clemson.cs.nestbed.client.gui.NetworkMonitorFrame.java
private final JMenu buildFileMenu() { JMenu menu = new JMenu("File"); JMenuItem video = new JMenuItem("Video"); JMenuItem close = new JMenuItem("Close"); video.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { WebCam cam = new WebCam("nestbed.cs.clemson.edu", 9192); }//from w w w . j a v a 2s . c o m }); menu.add(video); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { NetworkMonitorFrame.this.setVisible(false); } }); menu.add(new JSeparator()); menu.add(close); return menu; }
From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java
protected JPopupMenu createPopupMenu() { if (TABLE.getSelectionModel().isSelectionEmpty()) return null; JPopupMenu menu = new JPopupMenu(); menu.add(new JMenuItem(LAUNCH_ACTION)); menu.add(new JMenuItem(ENQUEUE_ACTION)); menu.addSeparator();/*from www . j a v a2 s .c o m*/ menu.add(new JMenuItem(RESUME_ACTION)); menu.addSeparator(); menu.add(new JMenuItem(DELETE_ACTION)); menu.add(new JMenuItem(RENAME_ACTION)); menu.addSeparator(); DataLine[] dls = TABLE.getSelectedDataLines(); boolean dirSelected = false; boolean fileSelected = false; for (int i = 0; i < dls.length; i++) { if (((LibraryTableDataLine) dls[i]).getFile().isDirectory()) dirSelected = true; else fileSelected = true; if (dirSelected && fileSelected) break; } if (dirSelected) { if (GUIMediator.isPlaylistVisible()) ENQUEUE_ACTION.setEnabled(false); DELETE_ACTION.setEnabled(false); RENAME_ACTION.setEnabled(false); if (fileSelected) { JMenu sharingMenu = new JMenu(GUIMediator.getStringResource("LIBRARY_TABLE_SHARING_SUB_MENU")); sharingMenu.add(new JMenuItem(SHARE_ACTION)); sharingMenu.add(new JMenuItem(UNSHARE_ACTION)); sharingMenu.add(new JMenuItem(ANNOTATE_ACTION)); sharingMenu.add(new JMenuItem(PUBLISH_ACTION)); sharingMenu.addSeparator(); sharingMenu.add(new JMenuItem(SHARE_FOLDER_ACTION)); sharingMenu.add(new JMenuItem(UNSHARE_FOLDER_ACTION)); menu.add(sharingMenu); } else { menu.add(new JMenuItem(SHARE_FOLDER_ACTION)); menu.add(new JMenuItem(UNSHARE_FOLDER_ACTION)); } } else { if (GUIMediator.isPlaylistVisible()) ENQUEUE_ACTION.setEnabled(true); DELETE_ACTION.setEnabled(true); RENAME_ACTION.setEnabled(!_isIncomplete); menu.add(new JMenuItem(SHARE_ACTION)); menu.add(new JMenuItem(UNSHARE_ACTION)); menu.add(new JMenuItem(ANNOTATE_ACTION)); menu.add(new JMenuItem(PUBLISH_ACTION)); } menu.addSeparator(); menu.add(createSearchSubMenu((LibraryTableDataLine) dls[0])); menu.add(createAdvancedMenu((LibraryTableDataLine) dls[0])); LICENSE_ACTION.setEnabled(dls != null && dls[0] != null && ((LibraryTableDataLine) dls[0]).isLicensed()); return menu; }
From source file:edu.clemson.cs.nestbed.client.gui.TestbedManagerFrame.java
private final JMenu buildFileMenu() { JMenu file = new JMenu("File"); JMenuItem exit = new JMenuItem("Exit"); exit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doExit();/*from w w w.j av a 2 s. co m*/ } }); file.add(exit); return file; }