List of usage examples for javax.swing SwingUtilities isLeftMouseButton
public static boolean isLeftMouseButton(MouseEvent anEvent)
From source file:krasa.cpu.CpuUsagePanel.java
public CpuUsagePanel(Project project) { refreshColors();/*from w ww.j a va 2 s .com*/ this.myProject = project; this.projectName = project.getName(); setOpaque(false); setFocusable(false); setToolTipText("IDE CPU usage / System CPU usage"); setBorder(StatusBarWidget.WidgetBorder.INSTANCE); updateUI(); new UiNotifyConnector(this, new Activatable() { @Override public void showNotify() { CpuUsageManager.register(CpuUsagePanel.this); } @Override public void hideNotify() { CpuUsageManager.unregister(CpuUsagePanel.this); } }); MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { CpuUsageManager.update(); final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ActionManager.getInstance().getAction("TakeThreadDump").actionPerformed(new AnActionEvent(e, context, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0)); } else if (SwingUtilities.isRightMouseButton(e)) { final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, getActionGroup(), context, JBPopupFactory.ActionSelectionAid.MNEMONICS, false); Dimension dimension = popup.getContent().getPreferredSize(); Point at = new Point(0, -dimension.height); popup.show(new RelativePoint(e.getComponent(), at)); } } }; addMouseListener(mouseAdapter); }
From source file:model.SignatureValidation.java
public SignatureValidation(String filename, String name, PdfPKCS7 pdfPkcs7, boolean changed, boolean coversEntireDocument, int revision, int numRevisions, int documentCertificationLevel, CertificateStatus ocspCertificateStatus, CertificateStatus crlCertificateStatus, boolean validTimeStamp, List<AcroFields.FieldPosition> posList, SignaturePermissions signaturePermissions, boolean valid) { this.filename = filename; this.name = name; this.pdfPkcs7 = pdfPkcs7; this.changed = changed; this.coversEntireDocument = coversEntireDocument; this.revision = revision; this.numRevisions = numRevisions; this.signaturePermissions = signaturePermissions; this.valid = valid; this.ocspCertificateStatus = ocspCertificateStatus; this.crlCertificateStatus = crlCertificateStatus; this.validTimeStamp = validTimeStamp; this.posList = posList; this.panel = new JPanel(); this.panel.setBackground(new Color(0, 0, 0, 0)); this.panel.setToolTipText(name); this.panel.addMouseListener(new MouseAdapter() { @Override/*from w w w.j a v a 2 s . c o m*/ public void mouseClicked(java.awt.event.MouseEvent evt) { if (SwingUtilities.isLeftMouseButton(evt)) { if (listener != null) { listener.onSignatureClick(SignatureValidation.this); } } } }); }
From source file:unikn.dbis.univis.visualization.graph.plaf.VGraphUI.java
/** * Creates the listener responsible for calling the correct handlers based * on mouse events, and to select invidual cells. *//*ww w . j av a 2 s .c o m*/ protected MouseListener createMouseListener() { return new MouseHandler() { /** * Invoked when a mouse button has been pressed on a component. * //@Override public void mousePressed(MouseEvent e) { Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; JPopupMenu menu = new JPopupMenu(); VChartPanel chartPanel = (VChartPanel) cell.getUserObject(); if (chartPanel.isShowPopUp()) { LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems(); JMenu first = new JMenu("1-39"); int checker = 0; for (Iterator iter = collect.iterator(); iter.hasNext();) { LegendItem item = (LegendItem) iter.next(); checker++; first.add(new JMenuItem(item.getLabel())); if ((checker % 40) == 0) { menu.add(first); first = new JMenu("" + checker + "-" + (checker + 39)); } if (!iter.hasNext()) { menu.add(first); } } menu.show(graph, e.getX(), e.getY()); } } super.mousePressed(e); } */ /** * Invoked when a mouse button has been pressed on a component. */ @Override public void mousePressed(MouseEvent e) { Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e) && e.isAltDown()) { if (o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; JPopupMenu menu = new JPopupMenu(); VChartPanel chartPanel = (VChartPanel) cell.getUserObject(); LegendItemCollection collect = chartPanel.getChart().getPlot().getLegendItems(); JMenu first = new JMenu("1-39"); int checker = 0; for (Iterator iter = collect.iterator(); iter.hasNext();) { LegendItem item = (LegendItem) iter.next(); checker++; first.add(new JMenuItem(item.getLabel())); if ((checker % 40) == 0) { menu.add(first); first = new JMenu("" + checker + "-" + (checker + 39)); } if (!iter.hasNext()) { menu.add(first); } } menu.show(graph, e.getX(), e.getY()); } } super.mousePressed(e); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; for (MouseListener l : chart.getMouseListeners()) { l.mousePressed(e); } } } } // Event may be null when called to cancel the current operation. @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; for (MouseListener l : chart.getMouseListeners()) { l.mouseReleased(e); } } } } /** * Invoked when the mouse has been clicked on a component. */ @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { VGraphCell cell = (VGraphCell) o; o = cell.getUserObject(); if (o != null && o instanceof VChartPanel) { VChartPanel chart = (VChartPanel) o; if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu menu = chart.createPopupMenu(true, true, true, true); menu.show(graph, e.getX(), e.getY()); } /* for (MouseListener l : chart.getMouseListeners()) { System.out.println("LISTENS CLI"); l.mouseClicked(e); } */ } } } /* // Event may be null when called to cancel the current operation. @Override public void mouseReleased(MouseEvent e) { super.mouseReleased(e); Object[] cells = graphSelectionModel.getSelectionCells(); Rectangle2D bounds = graph.getCellBounds(cells); if (bounds != null) { Rectangle2D b2 = graph.toScreen((Rectangle2D) bounds.clone()); graph.scrollRectToVisible(new Rectangle((int) b2.getX(), (int) b2.getY(), (int) b2.getWidth(), (int) b2.getHeight())); } } */ /** * Invoked when the mouse pointer has been moved on a component (with no * buttons down). */ @Override public void mouseMoved(MouseEvent e) { if (graph.isMoveable()) { super.mouseMoved(e); } Object o = graph.getFirstCellForLocation(e.getX(), e.getY()); if (o != null && o instanceof VGraphCell) { selectedCell = (VGraphCell) o; Rectangle2D bounds = graph.getCellBounds(selectedCell); menu.show(graph, (int) (bounds.getX() + bounds.getWidth()), (int) bounds.getY() + (int) (bounds.getHeight() - menu.getHeight())); } } }; }
From source file:com.diversityarrays.kdxplore.editing.EntityPropertiesTable.java
@Override public boolean editCellAt(int row, int column, EventObject e) { if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; if (SwingUtilities.isLeftMouseButton(me) && 2 != me.getClickCount()) { return false; }/* w w w . jav a 2 s .c o m*/ me.consume(); } @SuppressWarnings("unchecked") EntityPropertiesTableModel<T> eptm = (EntityPropertiesTableModel<T>) getModel(); if (!eptm.isCellEditable(row, column)) { return false; } if (handleEditCellAt(eptm, row, column)) { return false; } PropertyDescriptor pd = eptm.getPropertyDescriptor(row); if (pd == null) { return super.editCellAt(row, column); } Class<?> propertyClass = pd.getPropertyType(); if (propertyChangeConfirmer != null && !propertyChangeConfirmer.isChangeAllowed(pd)) { return false; } if (java.util.Date.class.isAssignableFrom(propertyClass)) { try { java.util.Date dateValue = (Date) pd.getReadMethod().invoke(eptm.getEntity()); if (propertyChangeConfirmer != null) { propertyChangeConfirmer.setValueBeforeChange(dateValue); } Closure<Date> onComplete = new Closure<Date>() { @Override public void execute(Date result) { if (result != null) { if (propertyChangeConfirmer == null || propertyChangeConfirmer.valueChangeCanCommit(pd, result)) { getModel().setValueAt(result, row, column); } } } }; String title = pd.getDisplayName(); DatePickerDialog datePicker = new DatePickerDialog(GuiUtil.getOwnerWindow(this), title, onComplete); datePicker.setDate(dateValue); datePicker.setVisible(true); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) { e1.printStackTrace(); } return false; } // else if (Enum.class.isAssignableFrom(propertyClass)) { // } Log.d(TAG, "editCellAt(" + row + "," + column + ") No Editor override provided for " + propertyClass.getName()); return super.editCellAt(row, column, e); }
From source file:FillViewportHeightDemo.java
public FillViewportHeightDemo() { super("Empty Table DnD Demo"); tableModel = getDefaultTableModel(); table = new JTable(tableModel); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDropMode(DropMode.INSERT_ROWS); table.setTransferHandler(new TransferHandler() { public boolean canImport(TransferSupport support) { // for the demo, we'll only support drops (not clipboard paste) if (!support.isDrop()) { return false; }// w ww . j a v a 2 s. co m // we only import Strings if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } return true; } public boolean importData(TransferSupport support) { // if we can't handle the import, say so if (!canImport(support)) { return false; } // fetch the drop location JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); int row = dl.getRow(); // fetch the data and bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (IOException e) { return false; } String[] rowData = data.split(","); tableModel.insertRow(row, rowData); Rectangle rect = table.getCellRect(row, 0, false); if (rect != null) { table.scrollRectToVisible(rect); } // demo stuff - remove for blog model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); // end demo stuff return true; } }); JList dragFrom = new JList(model); dragFrom.setFocusable(false); dragFrom.setPrototypeCellValue(getNextString(100)); model.insertElementAt(getNextString(count++), 0); dragFrom.setDragEnabled(true); dragFrom.setBorder(BorderFactory.createLoweredBevelBorder()); dragFrom.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) { String text = (String) model.getElementAt(0); String[] rowData = text.split(","); tableModel.insertRow(table.getRowCount(), rowData); model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); } } }); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); JPanel wrap = new JPanel(); wrap.add(new JLabel("Drag from here:")); wrap.add(dragFrom); p.add(Box.createHorizontalStrut(4)); p.add(Box.createGlue()); p.add(wrap); p.add(Box.createGlue()); p.add(Box.createHorizontalStrut(4)); getContentPane().add(p, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(table); getContentPane().add(sp, BorderLayout.CENTER); fillBox = new JCheckBoxMenuItem("Fill Viewport Height"); fillBox.addActionListener(this); JMenuBar mb = new JMenuBar(); JMenu options = new JMenu("Options"); mb.add(options); setJMenuBar(mb); JMenuItem clear = new JMenuItem("Reset"); clear.addActionListener(this); options.add(clear); options.add(fillBox); getContentPane().setPreferredSize(new Dimension(260, 180)); }
From source file:ja.lingo.application.gui.main.describer.DescriberGui.java
public void mouseClickedOnEditorPane(MouseEvent e) { if (!articlePanel.hasArticle()) { return;/*from w w w . ja v a2s. c om*/ } if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) { if (getSelectedTextTrimmed().length() > 0) { Rectangle rectangle; try { rectangle = articlePanel.getEditorPane() .modelToView(articlePanel.getEditorPane().getSelectionStart()); } catch (BadLocationException e1) { throw new RuntimeException(e1); } showMenuOnSelect(e.getX(), (int) (rectangle.getY() + rectangle.getHeight())); } return; } if (SwingUtilities.isRightMouseButton(e)) { if (getSelectedTextTrimmed().length() > 0) { showMenuOnSelect(e.getX(), e.getY()); } else { menu.show(articlePanel, e.getX(), e.getY()); } } }
From source file:com.intel.stl.ui.common.view.JumpChartPanel.java
@Override public void chartMouseClicked(ChartMouseEvent cme) { if (!SwingUtilities.isLeftMouseButton(cme.getTrigger())) { return;//from ww w. j a v a 2 s.c o m } ChartEntity xyItem = cme.getEntity(); if (xyItem instanceof CategoryLabelEntity) { jumpToEntity = (CategoryLabelEntity) xyItem; fireJumpEvent(jumpToEntity.getKey(), JumpDestination.DEFAULT); } }
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
@Override public void setSortable(boolean enable) { super.setSortable(enable); JTableHeader header = getTableHeader(); if (enable) { if (treeTableSortAdapter == null) { treeTableSortAdapter = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { JTableHeader h = (JTableHeader) e.getSource(); TableColumnModel columnModel = getColumnModel(); int viewColumn = h.columnAtPoint(e.getPoint()); int column = columnModel.getColumn(viewColumn).getModelIndex(); if (column != -1) { beforeSort(); // Toggle sort order (ascending <-> descending) SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel(); model.setColumnAndToggleSortOrder(column); // Set sorting icon and current column index ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer()) .setSortingIcon(model.getSortOrder()); ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer()) .setColumnIndex(column); saveSortPreferences(column); afterSort(); }/*ww w. j a va 2 s. co m*/ } } }; header.addMouseListener(treeTableSortAdapter); } } else { if (treeTableSortAdapter != null) { header.removeMouseListener(treeTableSortAdapter); treeTableSortAdapter = null; } } }
From source file:net.sf.xmm.moviemanager.gui.DialogIMDB.java
JPanel createMoviehitsList() { /* Movies List panel...*/ JPanel panelMoviesList = new JPanel(); panelMoviesList.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), Localizer.get("DialogIMDB.panel-movie-list.title")), //$NON-NLS-1$ BorderFactory.createEmptyBorder(5, 5, 5, 5))); listMovies = new JList() { public String getToolTipText(MouseEvent e) { if (getCellBounds(0, 0) == null) return null; String retVal = null; int row = (int) e.getPoint().getY() / (int) getCellBounds(0, 0).getHeight(); if (row >= 0 && row < getModel().getSize() && getMoviesList().getModel().getElementAt(row) instanceof ModelIMDbSearchHit) { retVal = ((ModelIMDbSearchHit) getMoviesList().getModel().getElementAt(row)).getAka(); if (retVal != null && retVal.trim().equals("")) //$NON-NLS-1$ retVal = null;/* w w w. j a v a2 s . co m*/ } return retVal; } public JToolTip createToolTip() { JMultiLineToolTip tooltip = new JMultiLineToolTip(); tooltip.setComponent(this); return tooltip; } }; // Unfortunately setting tooltip timeout affects ALL tooltips ToolTipManager ttm = ToolTipManager.sharedInstance(); ttm.registerComponent(listMovies); ttm.setInitialDelay(0); ttm.setReshowDelay(0); listMovies.setFixedCellHeight(18); listMovies.setFont(new Font(listMovies.getFont().getName(), Font.PLAIN, listMovies.getFont().getSize())); listMovies.setLayoutOrientation(JList.VERTICAL); listMovies.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); listMovies.setCellRenderer(new MovieHitListCellRenderer()); listMovies.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent event) { // Open we page if (SwingUtilities.isRightMouseButton(event)) { int index = listMovies.locationToIndex(event.getPoint()); if (index >= 0) { ModelIMDbSearchHit hit = (ModelIMDbSearchHit) listMovies.getModel().getElementAt(index); if (hit.getUrlID() != null && !hit.getUrlID().equals("")) { BrowserOpener opener = new BrowserOpener(hit.getCompleteUrl()); opener.executeOpenBrowser(MovieManager.getConfig().getSystemWebBrowser(), MovieManager.getConfig().getBrowserPath()); } } } else if (SwingUtilities.isLeftMouseButton(event) && event.getClickCount() >= 2) { buttonSelect.doClick(); } } }); KeyStroke enterKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, true); ActionListener listKeyBoardActionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { log.debug("ActionPerformed: " + "Movielist - ENTER pressed."); //$NON-NLS-1$ buttonSelect.doClick(); } }; listMovies.registerKeyboardAction(listKeyBoardActionListener, enterKeyStroke, JComponent.WHEN_FOCUSED); JScrollPane scrollPaneMovies = new JScrollPane(listMovies); scrollPaneMovies.setAutoscrolls(true); //scrollPaneMovies.registerKeyboardAction(listKeyBoardActionListener,enterKeyStroke, JComponent.WHEN_FOCUSED); panelMoviesList.setLayout(new BorderLayout()); panelMoviesList.add(scrollPaneMovies, BorderLayout.CENTER); return panelMoviesList; }
From source file:au.org.ala.delta.editor.ui.CharacterTree.java
public CharacterTree() { setToggleClickCount(0);// w w w. jav a 2 s.co m _characterListBehaviour = new CharacterListBehaviour(); _stateListBehaviour = new StateListBehaviour(); ToolTipManager.sharedInstance().registerComponent(this); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (_doubleProcessingMouseEvent) { return; } if (!isEditing()) { int selectedRow = getClosestRowForLocation(e.getX(), e.getY()); if ((selectedRow >= 0) && (e.getClickCount() == 2) && SwingUtilities.isLeftMouseButton(e)) { Action action = getActionMap().get(SELECTION_ACTION_KEY); if (action != null) { action.actionPerformed(new ActionEvent(this, -1, "")); } } } } }); addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath selection = e.getNewLeadSelectionPath(); if (selection != null) { Object lastComponent = selection.getLastPathComponent(); if (lastComponent instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) lastComponent; if (node.isLeaf()) { CharacterTree.super.setTransferHandler(_stateTransferHandler); } else { CharacterTree.super.setTransferHandler(_characterTransferHandler); } } } } }); ActionMap actionMap = Application.getInstance().getContext().getActionMap(this); javax.swing.Action find = actionMap.get("find"); if (find != null) { getActionMap().put("find", find); } javax.swing.Action findNext = actionMap.get("findNext"); if (findNext != null) { getActionMap().put("findNext", findNext); } getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_MASK), SELECTION_ACTION_KEY); }