List of usage examples for java.awt.event MouseEvent isPopupTrigger
public boolean isPopupTrigger()
From source file:it.unibas.spicygui.vista.listener.MyMouseEventListener.java
private void dispacciaEvento(Component com, MouseEvent e, Point point, boolean draggedEvent) { if (com == null) { com = SwingUtilities.getDeepestComponentAt(pannelloPrincipale, point.x, point.y); }/* ww w. j a v a 2 s . co m*/ Point componentPoint = SwingUtilities.convertPoint(component, e.getPoint(), com); if (com != null) { if (com instanceof JTree) { TreePath treePath = ((JTree) com).getPathForLocation(componentPoint.x, componentPoint.y); if (treePath == null || draggedEvent) { jLayeredPane.moveToFront(component); component.updateUI(); if (e.getButton() == MouseEvent.BUTTON3) { return; } } } com.dispatchEvent(new MouseEvent(com, e.getID(), e.getWhen(), e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(), e.isPopupTrigger())); jLayeredPane.moveToFront(component); component.updateUI(); } jLayeredPane.moveToFront(component); component.updateUI(); }
From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java
/** * /*from w w w. j a va 2s. c o m*/ */ protected void addContextMenu() { MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { super.mousePressed(e); if (e.isPopupTrigger()) { if (table.getSelectedColumnCount() > 0) { if (popupMenu != null && popupMenu.isVisible()) { popupMenu.setVisible(false); } if (popupMenu == null) { popupMenu = new JPopupMenu(); JMenuItem mi = popupMenu.add(new JMenuItem(UIRegistry.getResourceString("Remove"))); mi.addActionListener(createRemoveItemAL()); } Point p = table.getLocationOnScreen(); popupMenu.setLocation(p.x + e.getX() + 1, p.y + e.getY() + 1); popupMenu.setVisible(true); } } } }; table.addMouseListener(mouseAdapter); }
From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java
/** * Checks whether a mouse-click event should trigger a context-sensitive * popup menu and renders the menu if so. * //from ww w . jav a 2 s .c om * @param e */ private void maybeShowPopup(MouseEvent e) { if (!e.isPopupTrigger()) { return; } final int[] selectedRows = table.getSelectedRows(); if (ArrayUtils.isEmpty(selectedRows)) { final int row = table.rowAtPoint(e.getPoint()); if (row < 0) { if (log.isDebugEnabled()) { log.debug("maybeShowPopup(): Outside of table."); } return; } table.getSelectionModel().setSelectionInterval(row, row); } // translate row indices for (int i = 0; i < selectedRows.length; i++) { selectedRows[i] = table.getRowSorter().convertRowIndexToModel(selectedRows[i]); } if (populatePopupMenu(e, selectedRows)) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); } }
From source file:edu.ku.brc.af.ui.forms.ResultSetController.java
/** * Creates the UI for the controller.//from w ww .j a v a2 s .c om * @param addNewBtn indicates it should include the "Add" (New Object) button * @param addDelBtn indicates it should include Delete button * @param objTitle the title of a single object in the controller (used for building tooltips) */ protected void buildRecordNavBar(final boolean addNewBtn, final boolean addDelBtn, final boolean addSearchBtn, final String objTitle) { String colDef = "p,2dlu,p,2dlu,max(50dlu;p):grow,2dlu,p,2dlu,p" + (addNewBtn ? ",12px,p" : "") + (addDelBtn ? ",2dlu,p" : "") + (addSearchBtn ? ",2dlu,p" : ""); Insets insets = new Insets(1, 1, 1, 1); DefaultFormBuilder rowBuilder = new DefaultFormBuilder(new FormLayout(colDef, "p")); firstBtn = UIHelper.createIconBtn("FirstRec", null, null); prevBtn = UIHelper.createIconBtn("PrevRec", null, null); btnsHash.put(CommandType.Previous, prevBtn); btnsHash.put(CommandType.First, firstBtn); recDisp = createLabel(" "); recDisp.setHorizontalAlignment(SwingConstants.CENTER); recDisp.setOpaque(true); recDisp.setBackground(Color.WHITE); recDisp.setBorder(enabledBorder); recDisp.setFont(recDisp.getFont().deriveFont(recDisp.getFont().getSize2D() - 2)); MouseListener mouseListener = new MouseAdapter() { private boolean showIfPopupTrigger(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { JPopupMenu popupMenu = createPopupMenu(); if (popupMenu != null && popupMenu.getComponentCount() > 0) { popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); return true; } } return false; } @Override public void mousePressed(MouseEvent mouseEvent) { showIfPopupTrigger(mouseEvent); } @Override public void mouseReleased(MouseEvent mouseEvent) { showIfPopupTrigger(mouseEvent); } /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent) */ @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { if (numRecords == 1) { UIRegistry.writeTimedSimpleGlassPaneMsg(getResourceString("OnlyOneRrecordInCon")); } else { showGotoRecDlg(); } } } }; recDisp.addMouseListener(mouseListener); nextBtn = UIHelper.createIconBtn("NextRec", null, null); lastBtn = UIHelper.createIconBtn("LastRec", null, null); btnsHash.put(CommandType.Next, nextBtn); btnsHash.put(CommandType.Last, lastBtn); firstBtn.setToolTipText(createTooltip("GotoFirstRecordTT", objTitle)); prevBtn.setToolTipText(createTooltip("GotoPreviousRecordTT", objTitle)); nextBtn.setToolTipText(createTooltip("GotoNextRecordTT", objTitle)); lastBtn.setToolTipText(createTooltip("GotoLastRecordTT", objTitle)); firstBtn.setOpaque(false); prevBtn.setOpaque(false); nextBtn.setOpaque(false); lastBtn.setOpaque(false); CellConstraints cc = new CellConstraints(); rowBuilder.add(firstBtn, cc.xy(1, 1)); rowBuilder.add(prevBtn, cc.xy(3, 1)); rowBuilder.add(recDisp, cc.xy(5, 1)); rowBuilder.add(nextBtn, cc.xy(7, 1)); rowBuilder.add(lastBtn, cc.xy(9, 1)); int col = 11; if (addNewBtn) { if (false) { newRecBtn = new JButton("+") { public void setEnabled(boolean enable) { //log.debug("newRecBtn - RS: "+ formValidator.getName() + " " + newRecBtn.hashCode() + " "+enable+" isNewObj: "+isNewObj); if (formValidator != null && formValidator.getName() != null && formValidator.getName().equals("Collection Object")) { int x = 0; x++; if (enable) { int y = 0; y++; } } if (enable) { int x = 0; x++; } super.setEnabled(enable); } }; setControlSize(newRecBtn); ActionListener l = new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ResultSetControllerListener rscl : listeners) { rscl.newRecordAdded(); } } }; newRecBtn.addActionListener(l); } else { newRecBtn = UIHelper.createIconBtn("NewRecord", null, new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ResultSetControllerListener rscl : listeners) { rscl.newRecordAdded(); } } }); } newRecBtn.setToolTipText(createTooltip("NewRecordTT", objTitle)); newRecBtn.setEnabled(true); newRecBtn.setMargin(insets); btnsHash.put(CommandType.NewItem, newRecBtn); if (doLayoutBtns) { rowBuilder.add(newRecBtn, cc.xy(col, 1)); col += 2; } } if (addDelBtn) { if (false) { delRecBtn = new JButton("-") { public void setEnabled(boolean enable) { //log.debug("delRecBtn - RS: "+formValidator.getName() + " " + hashCode() + " "+enable); if (formValidator != null && formValidator.getName() != null && formValidator.getName().equals("Permit")) { int x = 0; x++; } if (!enable) { int x = 0; x++; } super.setEnabled(enable); } }; } else { delRecBtn = UIHelper.createIconBtn("DeleteRecord", null, null); } delRecBtn.setToolTipText(createTooltip("DeleteRecordTT", objTitle)); delRecBtn.setMargin(insets); btnsHash.put(CommandType.DelItem, delRecBtn); if (doLayoutBtns) { rowBuilder.add(delRecBtn, cc.xy(col, 1)); col += 2; } } if (addSearchBtn) { searchRecBtn = UIHelper.createIconBtn("Search", IconManager.IconSize.Std16, null, null); searchRecBtn.setToolTipText(createTooltip("SearchForRecordTT", objTitle)); searchRecBtn.setMargin(insets); if (doLayoutBtns) { rowBuilder.add(searchRecBtn, cc.xy(col, 1)); col += 2; } } firstBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { firstRecord(); } }); prevBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { prevRecord(); } }); nextBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { nextRecord(); } }); lastBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { lastRecord(); } }); // Make sure it gets centered rowBuilder.getPanel().setOpaque(false); DefaultFormBuilder outerCenteredPanel = new DefaultFormBuilder(new FormLayout("c:p:g", "p")); outerCenteredPanel.add(rowBuilder.getPanel(), cc.xy(1, 1)); panel = outerCenteredPanel.getPanel(); panel.setOpaque(false); }
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 a va 2 s .co m * 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:com.igormaznitsa.sciareto.ui.tree.ExplorerTree.java
public ExplorerTree(@Nonnull final Context context) { super();// www . ja va 2 s . c o m this.projectTree = new DnDTree(); this.context = context; this.projectTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); this.projectTree.setDropMode(DropMode.ON); this.projectTree.setEditable(true); ToolTipManager.sharedInstance().registerComponent(this.projectTree); this.projectTree.setCellRenderer(new TreeCellRenderer()); this.projectTree.setModel(new NodeProjectGroup(context, ".")); this.projectTree.setRootVisible(false); this.setViewportView(this.projectTree); this.projectTree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(@Nonnull final MouseEvent e) { if (e.getClickCount() > 1) { final int selRow = projectTree.getRowForLocation(e.getX(), e.getY()); final TreePath selPath = projectTree.getPathForLocation(e.getX(), e.getY()); if (selRow >= 0) { final NodeFileOrFolder node = (NodeFileOrFolder) selPath.getLastPathComponent(); if (node != null && node.isLeaf()) { final File file = node.makeFileForNode(); if (file != null && !context.openFileAsTab(file)) { UiUtils.openInSystemViewer(file); } } } } } @Override public void mouseReleased(@Nonnull final MouseEvent e) { if (e.isPopupTrigger()) { processPopup(e); } } @Override public void mousePressed(@Nonnull final MouseEvent e) { if (e.isPopupTrigger()) { processPopup(e); } } private void processPopup(@Nonnull final MouseEvent e) { final TreePath selPath = projectTree.getPathForLocation(e.getX(), e.getY()); if (selPath != null) { projectTree.setSelectionPath(selPath); final Object last = selPath.getLastPathComponent(); if (last instanceof NodeFileOrFolder) { makePopupMenu((NodeFileOrFolder) last).show(e.getComponent(), e.getX(), e.getY()); } } } }); }
From source file:edu.ku.brc.specify.tasks.subpane.images.ImagesPane.java
/** * Shows the Reset menu.//from w w w .ja v a 2s . c o m * @param e the mouse event */ private void showContextMenu(final MouseEvent e) { if (e.isPopupTrigger()) { JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("ES_TEXT_RESET")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ex) { searchText.setEnabled(true); searchText.setBackground(textBGColor); searchText.setText(""); } }); popup.add(menuItem); popup.show(e.getComponent(), e.getX(), e.getY()); } }
From source file:net.sf.jabref.gui.groups.GroupSelector.java
private void definePopup() { // These key bindings are just to have the shortcuts displayed // in the popup menu. The actual keystroke processing is in // BasePanel (entryTable.addKeyListener(...)). groupsContextMenu.add(editGroupPopupAction); groupsContextMenu.add(addGroupPopupAction); groupsContextMenu.add(addSubgroupPopupAction); groupsContextMenu.addSeparator();/*from ww w . ja va 2s. c om*/ groupsContextMenu.add(removeGroupAndSubgroupsPopupAction); groupsContextMenu.add(removeGroupKeepSubgroupsPopupAction); groupsContextMenu.add(removeSubgroupsPopupAction); groupsContextMenu.addSeparator(); groupsContextMenu.add(expandSubtreePopupAction); groupsContextMenu.add(collapseSubtreePopupAction); groupsContextMenu.addSeparator(); groupsContextMenu.add(moveSubmenu); sortSubmenu.add(sortDirectSubgroupsPopupAction); sortSubmenu.add(sortAllSubgroupsPopupAction); groupsContextMenu.add(sortSubmenu); moveSubmenu.add(moveNodeUpPopupAction); moveSubmenu.add(moveNodeDownPopupAction); moveSubmenu.add(moveNodeLeftPopupAction); moveSubmenu.add(moveNodeRightPopupAction); groupsContextMenu.addSeparator(); groupsContextMenu.add(addToGroup); groupsContextMenu.add(moveToGroup); groupsContextMenu.add(removeFromGroup); groupsTree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showPopup(e); } } @Override public void mouseClicked(MouseEvent e) { TreePath path = groupsTree.getPathForLocation(e.getPoint().x, e.getPoint().y); if (path == null) { return; } GroupTreeNodeViewModel node = (GroupTreeNodeViewModel) path.getLastPathComponent(); // the root node is "AllEntries" and cannot be edited if (node.getNode().isRoot()) { return; } if ((e.getClickCount() == 2) && (e.getButton() == MouseEvent.BUTTON1)) { // edit editGroupAction.actionPerformed(null); // dummy event } else if ((e.getClickCount() == 1) && (e.getButton() == MouseEvent.BUTTON1)) { annotationEvent(node); } } }); // be sure to remove a possible border highlight when the popup menu // disappears groupsContextMenu.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { // nothing to do } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { groupsTree.setHighlightBorderCell(null); } @Override public void popupMenuCanceled(PopupMenuEvent e) { groupsTree.setHighlightBorderCell(null); } }); }
From source file:edu.ku.brc.specify.tasks.ExpressSearchTask.java
/** * Shows the Reset menu.//from w w w . ja v a 2 s. c o m * @param e the mouse event */ protected void showContextMenu(MouseEvent e) { if (e.isPopupTrigger()) { JPopupMenu popup = new JPopupMenu(); JMenuItem menuItem = new JMenuItem(UIRegistry.getResourceString("ES_TEXT_RESET")); menuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ex) { searchText.setEnabled(true); searchText.setBackground(textBGColor); searchText.setText(""); if (statusBar != null) { statusBar.setProgressDone(EXPRESSSEARCH); } } }); popup.add(menuItem); popup.show(e.getComponent(), e.getX(), e.getY()); } }
From source file:edu.ku.brc.specify.tasks.RecordSetTask.java
/** * Adds the Context PopupMenu for the RecordSet. * @param roc the RolloverCommand btn to add the pop to *///from w ww.j ava 2 s.c o m public void addPopMenu(final RolloverCommand roc, final boolean isOKDelete, final boolean isOKModify) { if (roc.getLabelText() != null) { final JPopupMenu popupMenu = new JPopupMenu(); if (isOKModify) { JMenuItem renameMenuItem = new JMenuItem(UIRegistry.getResourceString("Rename")); renameMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { roc.startEditting(RecordSetTask.this); } }); popupMenu.add(renameMenuItem); } if (isOKDelete) { JMenuItem delMenuItem = new JMenuItem(UIRegistry.getResourceString("Delete")); delMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { CommandDispatcher.dispatch(new CommandAction(RECORD_SET, DELETE_CMD_ACT, roc)); } }); popupMenu.add(delMenuItem); } JMenuItem viewMenuItem = new JMenuItem(UIRegistry.getResourceString("View")); viewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { CommandAction cmdAction = new CommandAction("Express_Search", "ViewRecordSet", roc); cmdAction.setProperty("canModify", isOKDelete); CommandDispatcher.dispatch(cmdAction); } }); popupMenu.add(viewMenuItem); MouseListener mouseListener = new MouseAdapter() { private boolean showIfPopupTrigger(MouseEvent mouseEvent) { if (roc.isEnabled() && mouseEvent.isPopupTrigger() && popupMenu.getComponentCount() > 0) { popupMenu.show(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY()); return true; } return false; } @Override public void mousePressed(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } @Override public void mouseReleased(MouseEvent mouseEvent) { if (roc.isEnabled()) { showIfPopupTrigger(mouseEvent); } } }; roc.addMouseListener(mouseListener); } }