List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:net.pandoragames.far.ui.swing.menu.FileMenu.java
private void init(final Localizer localizer, final ComponentRepository componentRepository) { // Import//from ww w . java 2s . c o m JMenuItem importMenu = new JMenuItem(localizer.localize("label.import")); importMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileChooser = new JFileChooser(config.getFileListExportDirectory()); fileChooser.setDialogTitle(localizer.localize("label.select-import-file")); fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY); int returnVal = fileChooser.showOpenDialog(FileMenu.this); if (returnVal == JFileChooser.APPROVE_OPTION) { Runnable fileImporter = new ImportAction(fileChooser.getSelectedFile(), localizer, componentRepository.getOperationCallBackListener(), config.isWindows()); Thread thread = new Thread(fileImporter); thread.setDaemon(true); thread.start(); } } }); this.add(importMenu); // Export export = new JMenuItem(localizer.localize("label.export")); export.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ExportFileListDialog dialog = new ExportFileListDialog(mainFrame, tableModel, config); dialog.pack(); dialog.setVisible(true); } }); this.add(export); // seperator this.addSeparator(); // Edit edit = new JMenuItem(localizer.localize("label.edit")); edit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileEditor editor = new FileEditor(mainFrame, tableModel.getSelectedRows().get(0), config); editor.pack(); editor.setVisible(true); } }); this.add(edit); // View JMenuItem view = new JMenuItem(viewAction); this.add(view); // Preview JMenuItem preview = new JMenuItem(previewAction); this.add(preview); // Info info = new JMenuItem(localizer.localize("label.info")); info.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { InfoView infoView = new InfoView(mainFrame, tableModel.getSelectedRows().get(0), config, repository); infoView.pack(); infoView.setVisible(true); } }); this.add(info); // seperator this.addSeparator(); // copy copy = new JMenuItem(localizer.localize("menu.copy")); copy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.copyDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(copy); // tree copy treeCopy = new JMenuItem(localizer.localize("menu.treeCopy")); treeCopy.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.treeCopyDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(treeCopy); // move move = new JMenuItem(localizer.localize("menu.move")); move.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.moveDialog(tableModel, findForm, errorSink, config, mainFrame); } }); this.add(move); // delete delete = new JMenuItem(localizer.localize("menu.delete")); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { FileOperationDialog.deleteDialog(tableModel, findForm.getBaseDirectory(), errorSink, config, mainFrame); } }); this.add(delete); // rename rename = new JMenuItem(localizer.localize("menu.rename-dialog")); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int rowIndex = tableModel.getRowIndex(tableModel.getSelectedRows().get(0)); FileOperationDialog.renameDialog(rowIndex, tableModel, findForm, errorSink, config, mainFrame); } }); this.add(rename); }
From source file:edu.ku.brc.specify.tasks.SecurityAdminTask.java
public List<MenuItemDesc> getMenuItems() { menuItems = new Vector<MenuItemDesc>(); // show security summary menu item // no need to check security as everyone can see their own summary... besides it's read only String menuTitle = getKey("SHOW_SECURITY_SUMMARY_MENU"); //$NON-NLS-1$ String mneu = getKey("SHOW_SECURITY_SUMMARY_MNEU"); //$NON-NLS-1$ String desc = getKey("SHOW_SECURITY_SUMMARY_DESC"); //$NON-NLS-1$ JMenuItem mi = UIHelper.createLocalizedMenuItem(menuTitle, mneu, desc, true, null); // I18N mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { SecuritySummaryDlg dlg = new SecuritySummaryDlg(null); dlg.setVisible(true);//from www.j a va2 s. c om } }); String menuDesc = "Specify.SYSTEM_MENU/Specify.COLSETUP_MENU"; MenuItemDesc showSummaryMenuDesc = new MenuItemDesc(mi, menuDesc); showSummaryMenuDesc.setPosition(MenuItemDesc.Position.After, getResourceString(getKey("SECURITY_TOOLS_MENU"))); // check whether user can see the security admin panel // other permissions will be checked when the panel is created // XXX RELEASE String securityName = buildTaskPermissionName(SECURITY_ADMIN); if (!AppContextMgr.isSecurityOn() || SecurityMgr.getInstance().checkPermission(securityName, BasicSpPermission.view)) //$NON-NLS-1$ { // security tools menu item menuTitle = getKey("SECURITY_TOOLS_MENU"); //$NON-NLS-1$ mneu = getKey("SECURITY_TOOLS_MNEU"); //$NON-NLS-1$ desc = getKey("SECURITY_TOOLS_DESC"); //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menuTitle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (SubPaneMgr.getInstance().aboutToShutdown()) { SecurityAdminTask.this.requestContext(); } } }); MenuItemDesc mid = new MenuItemDesc(mi, menuDesc); mid.setPosition(MenuItemDesc.Position.After, getResourceString("SystemSetupTask.COLL_CONFIG")); //mid.setSepPosition(MenuItemDesc.Position.After); menuItems.add(mid); menuItems.add(showSummaryMenuDesc); } menuTitle = getKey("MASTER_PWD_MENU"); //$NON-NLS-1$ mneu = getKey("MASTER_PWD_MNEU"); //$NON-NLS-1$ desc = getKey("MASTER_PWD_DESC"); //$NON-NLS-1$ mi = UIHelper.createLocalizedMenuItem(menuTitle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { SpecifyUser spUser = AppContextMgr.getInstance().getClassObject(SpecifyUser.class); UserAndMasterPasswordMgr.getInstance().editMasterInfo(spUser.getName(), DBConnection.getInstance().getDatabaseName(), true); } }); MenuItemDesc mid = new MenuItemDesc(mi, UIHelper.isMacOS() ? "HELP" : "HELP/ABOUT", //$NON-NLS-1$ UIHelper.isMacOS() ? MenuItemDesc.Position.Bottom : MenuItemDesc.Position.Before); //$NON-NLS-2$ menuItems.add(mid); return menuItems; }
From source file:io.github.dsheirer.gui.SDRTrunk.java
/** * Initialize the contents of the frame. *///w w w . jav a 2s . c o m private void initGUI() { mMainGui.setLayout(new MigLayout("insets 0 0 0 0 ", "[grow,fill]", "[grow,fill]")); /** * Setup main JFrame window */ mTitle = SystemProperties.getInstance().getApplicationName(); mMainGui.setTitle(mTitle); mMainGui.setBounds(100, 100, 1280, 800); mMainGui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Set preferred sizes to influence the split mSpectralPanel.setPreferredSize(new Dimension(1280, 300)); mControllerPanel.setPreferredSize(new Dimension(1280, 500)); mSplitPane = new JideSplitPane(JideSplitPane.VERTICAL_SPLIT); mSplitPane.setDividerSize(5); mSplitPane.add(mSpectralPanel); mSplitPane.add(mControllerPanel); mBroadcastStatusVisible = SystemProperties.getInstance().get(PROPERTY_BROADCAST_STATUS_VISIBLE, false); //Show broadcast status panel when user requests - disabled by default if (mBroadcastStatusVisible) { mSplitPane.add(getBroadcastStatusPanel()); } mMainGui.add(mSplitPane, "cell 0 0,span,grow"); /** * Menu items */ JMenuBar menuBar = new JMenuBar(); mMainGui.setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem logFilesMenu = new JMenuItem("Logs & Recordings"); logFilesMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { Desktop.getDesktop().open(getHomePath().toFile()); } catch (Exception e) { mLog.error("Couldn't open file explorer"); JOptionPane.showMessageDialog(mMainGui, "Can't launch file explorer - files are located at: " + getHomePath().toString(), "Can't launch file explorer", JOptionPane.ERROR_MESSAGE); } } }); fileMenu.add(logFilesMenu); JMenuItem settingsMenu = new JMenuItem("Icon Manager"); settingsMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { mIconManager.showEditor(mMainGui); } }); fileMenu.add(settingsMenu); fileMenu.add(new JSeparator()); JMenuItem exitMenu = new JMenuItem("Exit"); exitMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitMenu); JMenu viewMenu = new JMenu("View"); viewMenu.add(new BroadcastStatusVisibleMenuItem(mControllerPanel)); menuBar.add(viewMenu); JMenuItem screenCaptureItem = new JMenuItem("Screen Capture"); screenCaptureItem.setMnemonic(KeyEvent.VK_C); screenCaptureItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.ALT_MASK)); screenCaptureItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { try { Robot robot = new Robot(); final BufferedImage image = robot.createScreenCapture(mMainGui.getBounds()); SystemProperties props = SystemProperties.getInstance(); Path capturePath = props.getApplicationFolder("screen_captures"); if (!Files.exists(capturePath)) { try { Files.createDirectory(capturePath); } catch (IOException e) { mLog.error("Couldn't create 'screen_captures' " + "subdirectory in the " + "SDRTrunk application directory", e); } } String filename = TimeStamp.getTimeStamp("_") + "_screen_capture.png"; final Path captureFile = capturePath.resolve(filename); EventQueue.invokeLater(new Runnable() { @Override public void run() { try { ImageIO.write(image, "png", captureFile.toFile()); } catch (IOException e) { mLog.error("Couldn't write screen capture to " + "file [" + captureFile.toString() + "]", e); } } }); } catch (AWTException e) { mLog.error("Exception while taking screen capture", e); } } }); menuBar.add(screenCaptureItem); }
From source file:gdt.jgui.entity.bonddetail.JBondDetailPanel.java
/** * Get the context menu.//from w w w. ja v a 2s . c o m * @return the context menu. */ @Override public JMenu getContextMenu() { menu1 = new JMenu("Context"); menu1.addMenuListener(new MenuListener() { @Override public void menuSelected(MenuEvent e) { // System.out.println("JBondDetailPanel:getConextMenu:BEGIN"); menu1.removeAll(); JMenuItem selectItem = new JMenuItem("Select all"); selectItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = getItems(); if (ipa != null) { for (JItemPanel ip : ipa) ip.setChecked(true); } } }); menu1.add(selectItem); JMenuItem unselectItem = new JMenuItem("Unselect all"); unselectItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JItemPanel[] ipa = getItems(); if (ipa != null) { for (JItemPanel ip : ipa) ip.setChecked(false); } } }); menu1.addSeparator(); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } else console.back(); } }); menu1.add(doneItem); menu1.addSeparator(); addItem = new JMenuItem("Add"); addItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Entigrator entigrator = console.getEntigrator(entihome$); JContext adp = (JContext) ExtensionHandler.loadHandlerInstance(entigrator, BondDetailHandler.EXTENSION_KEY, "gdt.jgui.entity.bonddetail.JAddDetailPanel"); String adpLocator$ = adp.getLocator(); adpLocator$ = Locator.append(adpLocator$, Entigrator.ENTIHOME, entihome$); adpLocator$ = Locator.append(adpLocator$, EntityHandler.ENTITY_KEY, entityKey$); JConsoleHandler.execute(console, adpLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } }); menu1.add(addItem); if (hasToPaste()) { JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { paste(); } }); menu1.add(pasteItem); } if (hasSelectedItems()) { JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { delete(); JBondDetailPanel bdp = new JBondDetailPanel(); String bdpLocator$ = bdp.getLocator(); bdpLocator$ = Locator.append(bdpLocator$, Entigrator.ENTIHOME, entihome$); bdpLocator$ = Locator.append(bdpLocator$, EntityHandler.ENTITY_KEY, entityKey$); bdpLocator$ = Locator.append(bdpLocator$, JBondsPanel.BOND_KEY, bondKey$); JConsoleHandler.execute(console, bdpLocator$); } } }); menu1.add(deleteItem); } } @Override public void menuDeselected(MenuEvent e) { } @Override public void menuCanceled(MenuEvent e) { } }); return menu1; }
From source file:DOMTreeTest.java
public DOMTreeFrame() { setTitle("DOMTreeTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile();//from w w w .j av a 2 s. c o m } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); }
From source file:medsavant.enrichment.app.RegionListAggregatePanel.java
private JPopupMenu createPopup() { JPopupMenu menu = new JPopupMenu(); TableModel model = tablePanel.getTable().getModel(); final int[] selRows = tablePanel.getTable().getSelectedRows(); if (selRows.length == 1) { JMenuItem browseItem = new JMenuItem(String.format("<html>Look at %s in genome browser</html>", "<i>" + model.getValueAt(selRows[0], 0) + "</i>")); browseItem.addActionListener(new ActionListener() { @Override//from w w w . j a v a2 s . c o m public void actionPerformed(ActionEvent ae) { TableModel model = tablePanel.getTable().getModel(); int r = selRows[0]; LocationController.getInstance().setLocation((String) model.getValueAt(r, 1), new Range((Integer) model.getValueAt(r, 2), (Integer) model.getValueAt(r, 3))); ViewController.getInstance().getMenu().switchToSubSection(BrowserPage.getInstance()); } }); menu.add(browseItem); } JMenuItem posItem = new JMenuItem(String.format("<html>Filter by %s</html>", selRows.length == 1 ? "Region <i>" + model.getValueAt(selRows[0], 0) + "</i>" : "Selected Regions")); posItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { ThreadController.getInstance().cancelWorkers(pageName); List<GenomicRegion> regions = new ArrayList<GenomicRegion>(); TableModel model = tablePanel.getTable().getModel(); for (int r : selRows) { String geneName = (String) model.getValueAt(r, 0); String chrom = (String) model.getValueAt(r, 1); Integer start = (Integer) model.getValueAt(r, 2); Integer end = (Integer) model.getValueAt(r, 3); regions.add(new GenomicRegion(geneName, chrom, start, end)); } QueryUtils.addQueryOnRegions(regions, Arrays.asList(new RegionSet[] { (RegionSet) regionSetCombo.getSelectedItem() })); } }); menu.add(posItem); return menu; }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
@Override protected JMenu buildResultsMenu() { JMenu resultsMenu = new JMenu("Results"); resultsMenu.setMnemonic('r'); JMenuItem cwItem = new JMenuItem("Central weight vectors", ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_CENTRALWEIGHTS)); cwItem.setMnemonic('c'); JMenuItem racsItem = new JMenuItem("Rank acceptability indices", ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_RANKACCEPTABILITIES)); racsItem.setMnemonic('r'); cwItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getCentralWeightsNode()); }/*from w ww . ja va 2s. c o m*/ }); racsItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getRankAcceptabilitiesNode()); } }); resultsMenu.add(cwItem); resultsMenu.add(racsItem); return resultsMenu; }
From source file:edu.clemson.cs.nestbed.client.gui.MoteDetailFrame.java
private JMenu buildFileMenu() { JMenu menu = new JMenu("File"); JMenuItem close = new JMenuItem("Close"); close.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { MoteDetailFrame.this.setVisible(false); }/*from w w w .j a v a 2 s . co m*/ }); menu.add(close); return menu; }
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingKnowledgeDBExplorerFrame.java
/** * Constructor./* w w w . j av a 2 s .co m*/ */ GapFillingKnowledgeDBExplorerFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp) throws Exception { LogoHelper.setLogo(this); this.setTitle("KnowledgeDB: explorer"); this.gcp = gcp; this.tablePanel = new JXPanel(); this.tablePanel.setBorder(new TitledBorder("Cases")); final JXPanel highPanel = new JXPanel(); highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS)); highPanel.add(this.tablePanel); this.geomapPanel = new JXPanel(); this.geomapPanel.add(buildGeoMapChart(new ArrayList<String>(), new ArrayList<String>())); highPanel.add(this.geomapPanel); this.caseChartPanel = new JXPanel(); this.caseChartPanel.setBorder(new TitledBorder("Inspected fake gap")); this.mostSimilarChartPanel = new JXPanel(); this.mostSimilarChartPanel.setBorder(new TitledBorder("Most similar")); this.nearestChartPanel = new JXPanel(); this.nearestChartPanel.setBorder(new TitledBorder("Nearest")); this.downstreamChartPanel = new JXPanel(); this.downstreamChartPanel.setBorder(new TitledBorder("Downstream")); this.upstreamChartPanel = new JXPanel(); this.upstreamChartPanel.setBorder(new TitledBorder("Upstream")); getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS)); //getContentPane().add(new JCheckBox("Use incomplete series")); getContentPane().add(highPanel); //getContentPane().add(new JXButton("Export")); getContentPane().add(caseChartPanel); getContentPane().add(mostSimilarChartPanel); getContentPane().add(nearestChartPanel); getContentPane().add(downstreamChartPanel); getContentPane().add(upstreamChartPanel); //final Instances kdbDS=GapFillingKnowledgeDB.getKnowledgeDBWithBestCasesOnly(); final Instances kdbDS = GapFillingKnowledgeDB.getKnowledgeDB(); final JXTable gapsTable = buidJXTable(kdbDS); final JScrollPane tableScrollPane = new JScrollPane(gapsTable); tableScrollPane.setPreferredSize( new Dimension(COMPONENT_WIDTH - 100, 40 + (int) (tableScrollPane.getPreferredSize().getHeight()))); this.tablePanel.add(tableScrollPane); gapsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final int modelRow = gapsTable.getSelectedRow(); final String attrname = gapsTable.getModel().getValueAt(modelRow, 1).toString(); final int gapsize = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue(); final String mostSimilarFlag = gapsTable.getModel().getValueAt(modelRow, 14).toString(); final String nearestFlag = gapsTable.getModel().getValueAt(modelRow, 15).toString(); final String downstreamFlag = gapsTable.getModel().getValueAt(modelRow, 16).toString(); final String upstreamFlag = gapsTable.getModel().getValueAt(modelRow, 17).toString(); final String algoname = gapsTable.getModel().getValueAt(modelRow, 12).toString(); final boolean useDiscretizedTime = Boolean .valueOf(gapsTable.getModel().getValueAt(modelRow, 13).toString()); try { geomapPanel.removeAll(); caseChartPanel.removeAll(); mostSimilarChartPanel.removeAll(); nearestChartPanel.removeAll(); downstreamChartPanel.removeAll(); upstreamChartPanel.removeAll(); final Set<String> selected = new HashSet<String>(); final Instances tmpds = WekaDataProcessingUtil.buildFilteredDataSet(ds, 0, ds.numAttributes() - 1, Math.max(0, position - GapsUtil.getCountOfValuesBeforeAndAfter(gapsize)), Math.min(position + gapsize + GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), ds.numInstances() - 1)); final List<String> attributeNames = WekaTimeSeriesUtil .getNamesOfAttributesWithoutGap(tmpds); //final List<String> attributeNames=WekaDataStatsUtil.getAttributeNames(ds); attributeNames.remove(attrname); attributeNames.remove("timestamp"); if (Boolean.valueOf(mostSimilarFlag)) { final String mostSimilarStationName = WekaTimeSeriesSimilarityUtil .findMostSimilarTimeSerie(tmpds, tmpds.attribute(attrname), attributeNames, false); selected.add(mostSimilarStationName); final Attribute mostSimilarStationAttr = tmpds.attribute(mostSimilarStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, mostSimilarStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); mostSimilarChartPanel.add(cp0); } if (Boolean.valueOf(nearestFlag)) { final String nearestStationName = gcp.findNearestStation(attrname, attributeNames); selected.add(nearestStationName); final Attribute nearestStationAttr = ds.attribute(nearestStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, nearestStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); nearestChartPanel.add(cp0); } if (Boolean.valueOf(downstreamFlag)) { final String downstreamStationName = gcp.findDownstreamStation(attrname, attributeNames); selected.add(downstreamStationName); final Attribute downstreamStationAttr = ds.attribute(downstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, downstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); downstreamChartPanel.add(cp0); } if (Boolean.valueOf(upstreamFlag)) { final String upstreamStationName = gcp.findUpstreamStation(attrname, attributeNames); selected.add(upstreamStationName); final Attribute upstreamStationAttr = ds.attribute(upstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, upstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); upstreamChartPanel.add(cp0); } final GapFiller gapFiller = GapFillerFactory.getGapFiller(algoname, useDiscretizedTime); final ChartPanel cp = GapsUIUtil.buildGapChartPanelWithCorrection(ds, dateIdx, ds.attribute(attrname), gapsize, position, gapFiller, selected); cp.getChart().removeLegend(); cp.setPreferredSize(new Dimension((int) CHART_DIMENSION.getWidth(), (int) (CHART_DIMENSION.getHeight() * 1.5))); caseChartPanel.add(cp); geomapPanel.add(buildGeoMapChart(Arrays.asList(attrname), selected)); getContentPane().repaint(); pack(); } catch (Exception e1) { e1.printStackTrace(); } } } }); gapsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); 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(gapsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(kdbDS, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsTable, e.getX(), e.getY()); } } }); setPreferredSize(new Dimension(FRAME_WIDTH, 1000)); pack(); setVisible(true); /* select the first row */ gapsTable.setRowSelectionInterval(0, 0); }
From source file:de.hshannover.f4.trust.visitmeta.gui.GraphConnection.java
private JPopupMenu createContextMenu(final GraphicWrapper node) { JPopupMenu result = new JPopupMenu(); for (final ContextMenuItem item : mContextMenuItems) { JMenuItem menuItem = new JMenuItem(item.getItemTitle()); menuItem.addActionListener(new ActionListener() { @Override/*from w w w. j a va 2 s. co m*/ public void actionPerformed(ActionEvent e) { item.actionPerformed(node); } }); if (!item.canHandle(node.getData())) { menuItem.setEnabled(false); } result.add(menuItem); } return result; }