List of usage examples for javax.swing JPopupMenu show
public void show(Component invoker, int x, int y)
From source file:ro.nextreports.designer.querybuilder.DBBrowserTree.java
private void selectionFolder(DBBrowserNode selectedNode, MouseEvent e) { if (e.getClickCount() == 2) { return;//w w w . j a v a 2 s . c o m } JPopupMenu popupMenu = new JPopupMenu(); boolean testSql = false; if (selectedNode.getDBObject().getType() == DBObject.FOLDER_QUERY) { testSql = true; JMenuItem menuItem = new JMenuItem(new ImportQueryAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem); } else if (selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT) { testSql = true; JMenuItem menuItem = new JMenuItem( new ImportReportAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem( new DownloadBulkReportAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem2); } else if (selectedNode.getDBObject().getType() == DBObject.FOLDER_CHART) { testSql = true; JMenuItem menuItem = new JMenuItem(new ImportChartAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem( new DownloadBulkChartAction(selectedNode.getDBObject().getAbsolutePath())); popupMenu.add(menuItem2); } JMenuItem menuItem = new JMenuItem( new AddFolderAction(this, selectedNode, selectedNode.getDBObject().getType())); popupMenu.add(menuItem); JMenuItem menuItem2 = new JMenuItem(new RenameFolderAction(this, selectedNode)); popupMenu.add(menuItem2); JMenuItem menuItem3 = new JMenuItem(new DeleteFolderAction(this, selectedNode)); popupMenu.add(menuItem3); if (testSql) { JMenuItem menuItem4 = new JMenuItem(new ValidateSqlsAction(selectedNode.getDBObject())); popupMenu.add(menuItem4); } popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:ro.nextreports.designer.querybuilder.SelectionColumnPanel.java
private void buildUI() { setLayout(new GridBagLayout()); final DBViewer viewer = Globals.getDBViewer(); schemaCombo = new JComboBox(); schemaCombo.setPreferredSize(comboDim); schemaCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { String schema = (String) e.getItem(); shownColumnModel.clear();//ww w. ja v a2 s. co m columnModel.clear(); tableModel.clear(); try { DBInfo dbInfo = viewer.getDBInfo(schema, DBInfo.TABLES | DBInfo.VIEWS); List<DBTable> tables = dbInfo.getTables(); Collections.sort(tables); for (DBTable table : tables) { tableModel.addElement(table); } } catch (NextSqlException ex) { LOG.error(ex.getMessage(), ex); ex.printStackTrace(); } } }); try { List<String> schemas = viewer.getSchemas(); String schemaName = viewer.getUserSchema(); Collections.sort(schemas); boolean added = false; for (String schema : schemas) { if (DefaultSchemaManager.getInstance().isVisible( DefaultDataSourceManager.getInstance().getConnectedDataSource().getName(), schema)) { added = true; schemaCombo.addItem(schema); } } if ((schema == null) || schema.equals(DefaultDBViewer.NO_SCHEMA_NAME)) { schema = DefaultDBViewer.NO_SCHEMA_NAME;//viewer.getUserSchema(); } if (!added) { schemaCombo.addItem(schema); } schemaCombo.setSelectedItem(schema); } catch (NextSqlException e) { LOG.error(e.getMessage(), e); e.printStackTrace(); } // create table list tableList = new JXList(tableModel); tableList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); tableList.setCellRenderer(new DBTableCellRenderer()); // create column list columnList = new JXList(columnModel); if (singleSelection) { columnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } columnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList = new JXList(shownColumnModel); if (singleSelection) { shownColumnList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else { columnList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } addDoubleClick(); shownColumnList.setCellRenderer(new DBColumnCellRenderer()); shownColumnList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent mouseEvent) { if ((mouseEvent.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK) { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(new DeselectListAction(shownColumnList)); popupMenu.add(menuItem); popupMenu.show((Component) mouseEvent.getSource(), mouseEvent.getX(), mouseEvent.getY()); } } }); tableList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { int index = tableList.getSelectedIndex(); if (index == -1) { return; } DBTable table = (DBTable) tableModel.getElementAt(index); try { List<DBColumn> columns = null; try { columns = viewer.getColumns(table.getSchema(), table.getName()); } catch (MalformedTableNameException e1) { Show.error("Malformed table name : " + table.getName()); return; } Collections.sort(columns); columnModel.clear(); shownColumnModel.clear(); for (DBColumn column : columns) { columnModel.addElement(column); shownColumnModel.addElement(column); } } catch (NextSqlException e1) { LOG.error(e1.getMessage(), e1); e1.printStackTrace(); Show.error(e1); } } } }); columnList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { shownColumnList.clearSelection(); } }); scrTable = new JScrollPane(tableList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrTable.setPreferredSize(scrDim); scrTable.setMinimumSize(scrDim); scrTable.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.tables"))); scrColumn = new JScrollPane(columnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrColumn.setPreferredSize(scrDim); scrColumn.setMinimumSize(scrDim); scrColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.columns"))); scrShownColumn = new JScrollPane(shownColumnList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrShownColumn.setPreferredSize(scrDim); scrShownColumn.setMinimumSize(scrDim); scrShownColumn.setBorder(new TitledBorder(I18NSupport.getString("parameter.source.shown.columns"))); JPanel schemaPanel = new JPanel(); schemaPanel.setLayout(new BoxLayout(schemaPanel, BoxLayout.X_AXIS)); schemaPanel.add(new JLabel("Schema")); schemaPanel.add(Box.createHorizontalStrut(5)); schemaPanel.add(schemaCombo); add(schemaPanel, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); add(scrTable, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); add(scrColumn, new GridBagConstraints(1, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0)); if (show) { add(scrShownColumn, new GridBagConstraints(2, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } }
From source file:ro.nextreports.designer.wizpublish.JcrBrowserTree.java
public JcrBrowserTree(final byte typeRoot, WebServiceClient client) { super();//from w ww. j av a 2s .c om this.client = client; populateTree(typeRoot); setCellRenderer(new JcrBrowserTreeRenderer()); getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); instance = this; addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { job(e, true); } public void mouseReleased(MouseEvent e) { job(e, false); } private void job(MouseEvent e, boolean pressed) { if (e.isPopupTrigger()) { final TreePath selPath = getPathForLocation(e.getX(), e.getY()); if (selPath == null) { return; } setSelectionPath(selPath); try { final DBBrowserNode selectedNode = (DBBrowserNode) selPath.getLastPathComponent(); if (selectedNode != null) { JPopupMenu popupMenu = new JPopupMenu(); boolean show = false; if ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT) || (selectedNode.getDBObject().getType() == DBObject.DATABASE) || (selectedNode.getDBObject().getType() == DBObject.REPORTS_GROUP) || (selectedNode.getDBObject().getType() == DBObject.CHARTS_GROUP)) { JMenuItem menuItem = new JMenuItem(new PublishFolderAction(selectedNode)); popupMenu.add(menuItem); show = true; } if ((typeRoot == DBObject.DATABASE) && ((selectedNode.getDBObject().getType() == DBObject.FOLDER_REPORT) || (selectedNode.getDBObject().getType() == DBObject.DATABASE))) { PublishDataSourceAction publishDSAction = new PublishDataSourceAction(selectedNode); JMenuItem menuItem2 = new JMenuItem(publishDSAction); popupMenu.add(menuItem2); show = true; } if (show) { popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); } } } catch (Exception ex) { Show.error(ex); } } } }); }
From source file:statechum.analysis.learning.Visualiser.java
private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { if ((e.getModifiers() & InputEvent.SHIFT_MASK) == 0) popupMenu.show(e.getComponent(), e.getX(), e.getY()); else/*from ww w.ja v a 2 s. c o m*/ // attempt the popup for the diff if (currentGraph >= 0) {// if there are any graphs in this frame JPopupMenu diffMenu = new JPopupMenu(); final LearnerGraphND ourGraph = graphsOrig.get(currentGraph); if (ourGraph != null) {// if this is a real graph for (Visualiser viz : framesVisible) { final Visualiser fViz = viz; if (fViz.currentGraph >= 0) { final LearnerGraphND otherGr = fViz.graphsOrig.get(fViz.currentGraph); if (ourGraph != otherGr && otherGr != null) {// only if this is a real graph JMenuItem menuitem = new JMenuItem(new AbstractAction() { /** * ID for serialization */ private static final long serialVersionUID = 6840129509410881970L; {// Constructor putValue(Action.NAME, otherGr.getNameNotNull()); putValue(SHORT_DESCRIPTION, otherGr.getNameNotNull()); } @Override public void actionPerformed(@SuppressWarnings("unused") ActionEvent ev) { GD<List<CmpVertex>, List<CmpVertex>, LearnerGraphNDCachedData, LearnerGraphNDCachedData> gd = new GD<List<CmpVertex>, List<CmpVertex>, LearnerGraphNDCachedData, LearnerGraphNDCachedData>(); DirectedSparseGraph gr = //gd.showGD(ourGraph,otherGr,ExperimentRunner.getCpuNumber()); ChangesToGraph.computeVisualisationParameters( Synapse.StatechumProcess.constructFSM(ourGraph), ChangesToGraph.computeGD(ourGraph, otherGr, ourGraph.config)); Visualiser.updateFrame(gr, null); } }); diffMenu.add(menuitem); } } // if otherGr != null } // if fViz.graphs.size() > 0 if (diffMenu.getComponentCount() > 0) diffMenu.show(e.getComponent(), e.getX(), e.getY()); } // if ourGraph != null } // if graphs.size() > 0 } // e.isPopupTrigger() }
From source file:view.MainWindow.java
private void setupTreePopups() { jtOpenedDocuments.addMouseListener(new MouseAdapter() { @Override//from w ww. j a v a2 s. c om public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu popup = new JPopupMenu(); if (null != jtOpenedDocuments.getSelectionRows()) { if (1 >= jtOpenedDocuments.getSelectionRows().length) { int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY()); jtOpenedDocuments.setSelectionRow(row); } else { int row = jtOpenedDocuments.getClosestRowForLocation(e.getX(), e.getY()); boolean selected = false; for (int i : jtOpenedDocuments.getSelectionRows()) { if (i == row) { selected = true; break; } } if (!selected) { jtOpenedDocuments.setSelectionRow(row); } } JMenuItem m = null; ActionListener open = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { loadPdf(getSelectedFile(jtOpenedDocuments), true); } }; ActionListener remove = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeDocument(true); } }; ActionListener removeOthers = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final ArrayList<File> alFilesToClose = new ArrayList<>(); boolean showDialog = false; for (File file : getOpenedFiles()) { if (!getSelectedOpenedFiles().contains(file)) { alFilesToClose.add(file); if (file.equals(openedFile)) { showDialog = true; } } } closeDocuments(alFilesToClose, showDialog); } }; ActionListener removeAll = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { closeDocuments(getOpenedFiles(), true); } }; ActionListener show = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().open(getSelectedFile(jtOpenedDocuments).getParentFile()); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }; if (!openedFile.equals(getSelectedFile(jtOpenedDocuments))) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.open")); m.addActionListener(open); popup.add(m); } m = new JMenuItem(getSelectedOpenedFiles().size() > 1 ? Bundle.getBundle().getString("menuItem.removeTheseLoadedDocuments") : Bundle.getBundle().getString("menuItem.removeThisLoadedDocument")); m.addActionListener(remove); popup.add(m); if (getOpenedFiles().size() > 1) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeOtherLoadedDocuments")); m.addActionListener(removeOthers); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.removeAllLoadedDocuments")); m.addActionListener(removeAll); popup.add(m); } if (getSelectedOpenedFiles().size() == 1) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer")); m.addActionListener(show); popup.add(m); } popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); jtExplorer.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu popup = new JPopupMenu(); if (null != jtExplorer.getSelectionRows()) { if (1 >= jtExplorer.getSelectionRows().length) { int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY()); jtExplorer.setSelectionRow(row); } else { int row = jtExplorer.getClosestRowForLocation(e.getX(), e.getY()); boolean selected = false; for (int i : jtExplorer.getSelectionRows()) { if (i == row) { selected = true; break; } } if (!selected) { jtExplorer.setSelectionRow(row); } } JMenuItem m = null; ActionListener loadFile = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jtExplorer.getSelectionRows().length == 1) { loadPdf(getSelectedFile(jtExplorer), true); } else { ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer); for (File f : sl) { loadPdf(f, false); } } } }; ActionListener loadFolder = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jtExplorer.getSelectionRows().length == 1) { File f = getSelectedFile(jtExplorer); loadFolder(f, false); } else { ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer); for (File f : sl) { loadFolder(f, false); } } } }; ActionListener loadFolderRecursively = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jtExplorer.getSelectionRows().length == 1) { File f = getSelectedFile(jtExplorer); loadFolder(f, true); } else { ArrayList<File> sl = getMultipleSelectedFiles(jtExplorer); for (File s : sl) { loadFolder(s, true); } } } }; ActionListener remove = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ArrayList<File> listaF = getMultipleSelectedFiles(jtExplorer); closeDocuments(listaF, true); } }; ActionListener show = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop() .open(getSelectedFile(jtExplorer).isFile() ? getSelectedFile(jtExplorer).getParentFile() : getSelectedFile(jtExplorer)); } catch (IOException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }; if (files.isEmpty()) { if (jtExplorer.getSelectionRows().length <= 1) { File f = getSelectedFile(jtExplorer); if (f.isDirectory()) { m = new JMenuItem( Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder")); m.addActionListener(loadFolder); popup.add(m); m = new JMenuItem(Bundle.getBundle() .getString("menuItem.openDocumentsThisFolderRecursive")); m.addActionListener(loadFolderRecursively); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer")); m.addActionListener(show); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocument")); m.addActionListener(loadFile); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.showInExplorer")); m.addActionListener(show); popup.add(m); } } else { ArrayList<File> l = getMultipleSelectedFiles(jtExplorer); boolean file = l.get(0).isFile(); boolean allSame = true; for (File f : l) { if (file != f.isFile()) { allSame = false; break; } } if (allSame) { if (file) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.openDocuments")); m.addActionListener(loadFile); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle() .getString("menuItem.openDocumentsInTheseFolders")); m.addActionListener(loadFolder); popup.add(m); } } } } else { File f = getSelectedFile(jtExplorer); if (f.isDirectory()) { m = new JMenuItem( Bundle.getBundle().getString("menuItem.openDocumentsInThisFolder")); m.addActionListener(loadFolder); popup.add(m); m = new JMenuItem( Bundle.getBundle().getString("menuItem.openDocumentsThisFolderRecursive")); m.addActionListener(loadFolderRecursively); popup.add(m); } else if (files.contains(getSelectedFile(jtExplorer))) { m = new JMenuItem( Bundle.getBundle().getString("menuItem.removeFromLoadedDocuments")); m.addActionListener(remove); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.addToLoadedDocuments")); m.addActionListener(loadFile); popup.add(m); } } popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); jtExplorer.setCellRenderer(new TooltipTreeCellRenderer()); ToolTipManager.sharedInstance().registerComponent(jtExplorer); FileListTreeCellRenderer renderer1 = new FileListTreeCellRenderer((MainWindow) this); jtOpenedDocuments.setCellRenderer(renderer1); ToolTipManager.sharedInstance().registerComponent(jtOpenedDocuments); }
From source file:view.WorkspacePanel.java
private void btnValidateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnValidateActionPerformed if (mainWindow.getOpenedFiles().size() > 1) { JPopupMenu popup = new JPopupMenu(); JMenuItem m = null;/*from w w w.j a v a 2 s . co m*/ ActionListener validateOne = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!rightPanel.isVisible()) { changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) { String msg = Bundle.getBundle().getString("yes"); Object[] options = { Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { status = Status.READY; changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } } } }; ActionListener validateAll = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { MultipleValidationDialog mvd = new MultipleValidationDialog(mainWindow, true, mainWindow.getOpenedFiles()); mvd.setLocationRelativeTo(null); mvd.setVisible(true); } }; int numSigs = CCInstance.getInstance().getNumberOfSignatures(document.getDocumentLocation()); if (numSigs == 0) { m = new JMenuItem(Bundle.getBundle().getString("notSigned")); m.addActionListener(validateOne); m.setEnabled(false); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateOnlyThis")); m.addActionListener(validateOne); popup.add(m); } if (mainWindow.getSelectedOpenedFiles().size() > 1 && mainWindow.getSelectedOpenedFiles().size() < mainWindow.getOpenedFiles().size()) { m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAllSelected")); m.addActionListener(validateAll); popup.add(m); m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll")); m.addActionListener(validateAll); popup.add(m); } else { m = new JMenuItem(Bundle.getBundle().getString("menuItem.validateAll")); m.addActionListener(validateAll); popup.add(m); } popup.setLightWeightPopupEnabled(true); popup.show(btnValidate, 0, btnValidate.getHeight()); } else if (!rightPanel.isVisible()) { changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } else if (WorkspacePanel.this.status == WorkspacePanel.Status.SIGNING) { String msg = Bundle.getBundle().getString("msg.signatureStillNotAppliedCancel1"); Object[] options = { Bundle.getBundle().getString("yes"), Bundle.getBundle().getString("no") }; int opt = JOptionPane.showOptionDialog(null, msg, "", JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (opt == JOptionPane.YES_OPTION) { status = Status.READY; changeCard(CardEnum.VALIDATE_PANEL, true); startValidationThread(); } else { return; } } removeTempSignature(); }