List of usage examples for java.awt.event MouseEvent getComponent
public Component getComponent()
From source file:com.intuit.tank.proxy.ProxyApp.java
private JPanel getTransactionTable() { JPanel frame = new JPanel(new BorderLayout()); model = new TransactionTableModel(); final JTable table = new TransactionTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);/*ww w. j a va2 s . c o m*/ final JPopupMenu pm = new JPopupMenu(); JMenuItem item = new JMenuItem("Delete Selected"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { int response = JOptionPane.showConfirmDialog(ProxyApp.this, "Are you sure you want to delete " + selectedRows.length + " Transactions?", "Confirm Delete", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { int[] correctedRows = new int[selectedRows.length]; for (int i = selectedRows.length; --i >= 0;) { int row = selectedRows[i]; int index = (Integer) table.getValueAt(row, 0) - 1; correctedRows[i] = index; } Arrays.sort(correctedRows); for (int i = correctedRows.length; --i >= 0;) { int row = correctedRows[i]; Transaction transaction = model.getTransactionForIndex(row); if (transaction != null) { model.removeTransaction(transaction, row); isDirty = true; saveAction.setEnabled(isDirty && !stopAction.isEnabled()); } } } } } }); pm.add(item); table.add(pm); table.addMouseListener(new MouseAdapter() { boolean pressed = false; public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int index = (Integer) table.getValueAt(row, 0) - 1; Transaction transaction = model.getTransactionForIndex(index); if (transaction != null) { detailsTF.setText(transaction.toString()); detailsTF.setCaretPosition(0); detailsDialog.setVisible(true); } } } /** * @{inheritDoc */ @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { pressed = true; int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } /** * @{inheritDoc */ @Override public void mouseReleased(MouseEvent e) { if (!pressed && e.isPopupTrigger()) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } }); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter: "); panel.add(label, BorderLayout.WEST); final JLabel countLabel = new JLabel(" Count: 0 "); panel.add(countLabel, BorderLayout.EAST); final JTextField filterText = new JTextField(""); filterText.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { String text = filterText.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { try { sorter.setRowFilter(RowFilter.regexFilter(text)); countLabel.setText(" Count: " + sorter.getViewRowCount() + " "); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } } }); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); return frame; }
From source file:org.openconcerto.erp.panel.ITreeSelection.java
public void mousePressed(MouseEvent e) { TreePath path = this.getSelectionPath(); if (path != null) { Object o = path.getLastPathComponent(); int id = 1; if (e.getButton() == MouseEvent.BUTTON3) { final int idSelect = getSelectedID(); // Ajouter, supprimer, modifier un lment dans l'arbre JPopupMenu menu = new JPopupMenu(); menu.add(new AbstractAction("Ajouter un lment") { public void actionPerformed(ActionEvent e) { addElement(idSelect); }// w ww . j ava 2 s.c o m }); if (idSelect > 1) { menu.add(new AbstractAction("Modifier") { public void actionPerformed(ActionEvent e) { modifyElement(idSelect); } }); menu.add(new AbstractAction("Supprimer") { public void actionPerformed(ActionEvent e) { removeElement(idSelect); } }); } menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y); } } }
From source file:tufts.vue.RichTextBox.java
private void displayContextMenu(MouseEvent e) { getPopup(e).show(e.getComponent(), e.getX(), e.getY()); }
From source file:desmoj.extensions.visualization2d.engine.modelGrafic.StatisticGrafic.java
/** * Build the popup menu to switch between typeAnimation. * works only when statistic has observations * Called by MouseListener // w w w . j av a 2s . c om * Event wird nur bearbeitet, wenn die Simulation angehalten ist * Im anderen Fall kann der Viewer (inbes. Applet) ueberlastet sein * @param event MouseEvent */ private void checkPopupMenu(MouseEvent event) { //System.out.println("StatisticGrafic.checkPopupMenu"); ViewerPanel viewer = this.statistic.getModel().getViewer(); if (viewer != null && viewer.getSimulationThread() != null && !viewer.getSimulationThread().isWorking()) { // Event wird nur bearbeitet, wenn die Simulation angehalten ist // Im anderen Fall kann der Viewer (inbes. Applet) ueberlastet sein if (event.isPopupTrigger() && this.statistic.hasValue()) { JPopupMenu popup = new JPopupMenu(); JMenuItem mi = new JMenuItem(StatisticGrafic.TEXT_POPUP_MENU[0]); mi.addActionListener(this); popup.add(mi); mi = new JMenuItem(StatisticGrafic.TEXT_POPUP_MENU[1]); mi.addActionListener(this); popup.add(mi); popup.show(event.getComponent(), event.getX(), event.getY()); } } }
From source file:pl.otros.logview.gui.LogViewPanel.java
private void showMessageFormatterOrColorizerPopupMenu(MouseEvent e, String menuTitle, PluginableElementsContainer<? extends PluginableElement> selectedPluginableElementsContainer, PluginableElementsContainer<? extends PluginableElement> pluginableElementsContainer) { final JPopupMenu popupMenu = new JPopupMenu(menuTitle); popupMenu.add(new JLabel(menuTitle)); ArrayList<PluginableElement> elements = new ArrayList<PluginableElement>( pluginableElementsContainer.getElements()); Collections.sort(elements, new PluginableElementNameComparator()); for (final PluginableElement pluginableElement : elements) { addMessageFormatterOrColorizerToMenu(popupMenu, pluginableElement, selectedPluginableElementsContainer); }// w w w .j a v a 2 s . c o m popupMenu.show(e.getComponent(), e.getX(), e.getY()); }
From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java
/** * Shows the popup menu when the trigger button (right-click) has been pushed. Deselects the * rows if no row was selected.//from www . ja va 2 s.c o m */ private void checkSelectionAndPopupMenu(java.awt.event.MouseEvent evt) { int row = eventTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row == -1) { deselectRows(); } if (evt.isPopupTrigger()) { if (row != -1) { eventTable.setRowSelectionInterval(row, row); } parent.eventPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } }
From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java
/** * Opens the <tt>WritePanelRightButtonMenu</tt> when user clicks with the * right mouse button on the editor area. * * @param e the <tt>MouseEvent</tt> that notified us *//*from w w w .j a v a 2 s.com*/ public void mouseClicked(MouseEvent e) { if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) { Point p = e.getPoint(); SwingUtilities.convertPointToScreen(p, e.getComponent()); //SPELLCHECK ArrayList<JMenuItem> contributedMenuEntries = new ArrayList<JMenuItem>(); for (ChatMenuListener listener : this.menuListeners) { contributedMenuEntries.addAll(listener.getMenuElements(this.chatPanel, e)); } for (JMenuItem item : contributedMenuEntries) { rightButtonMenu.add(item); } JPopupMenu rightMenu = rightButtonMenu.makeMenu(contributedMenuEntries); rightMenu.setInvoker(editorPane); rightMenu.setLocation(p.x, p.y); rightMenu.setVisible(true); } }
From source file:com.mirth.connect.client.ui.editors.transformer.TransformerPane.java
/** * Shows the popup menu when the trigger button (right-click) has been pushed. *///from ww w .j a v a 2 s . c o m private void checkSelectionAndPopupMenu(java.awt.event.MouseEvent evt) { int row = transformerTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (evt.isPopupTrigger()) { if (row != -1) { transformerTable.setRowSelectionInterval(row, row); } transformerPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } }
From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryAuthoringTreePanel.java
/** * Creates the tree interface./*from w ww . j a v a 2s . c o m*/ */ private void createTreeInterface() { reportingQueryTreeModel = new ReportingQueryStatementTreeModel(activeQuery); queryInterfaceTree = new JXTree(reportingQueryTreeModel); // queryInterfaceTree.setCellRenderer(new ReportingQueryStatementTreeCellRenderer(humanReadableRender)); queryInterfaceTree.setCellRenderer(new StyledQueryStatementTreeCellRenderer(humanReadableRender)); queryInterfaceTree.addHighlighter(HighlighterFactory.createAlternateStriping()); // add listener for mouse events queryInterfaceTree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { evaluatePopupAction(e); } @Override public void mouseReleased(MouseEvent e) { evaluatePopupAction(e); } private void evaluatePopupAction(MouseEvent e) { // get node selected int row = queryInterfaceTree.getRowForLocation(e.getX(), e.getY()); if (row > -1) { TreePath selectedPath = queryInterfaceTree.getPathForLocation(e.getX(), e.getY()); Object node = selectedPath.getLastPathComponent(); if (node != null && node instanceof QueryExpression) { QueryExpression expression = (QueryExpression) node; // set selected expression selectedExpression = expression; // check if right click if (expression instanceof QueryIntersectionExpression || expression instanceof QueryUnionExpression || expression instanceof QueryStatement) { if (e.isPopupTrigger()) { queryActionsMenu.show(e.getComponent(), e.getX(), e.getY()); } } else if (expression instanceof QueryComponentExpression) { if (e.getClickCount() == 2) { QueryComponentExpression componentExpression = (QueryComponentExpression) expression; // get selected sub query and display it in a dialog queryComponentExpressionPanel.setComponentExpression(componentExpression); // queryComponentExpressionDialog.setTitle("Author Component Query"); queryComponentExpressionDialog.setVisible(true); } else if (e.isPopupTrigger()) { toggleStatusMenu.show(e.getComponent(), e.getX(), e.getY()); } } } } else { if (queryActionsMenu.isVisible()) { queryActionsMenu.setVisible(false); } if (toggleStatusMenu.isVisible()) { toggleStatusMenu.setVisible(false); } } } }); }
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//w w w . java2 s.com // 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() }