List of usage examples for java.awt.event MouseEvent getY
public int getY()
From source file:org.adempiere.apps.graph.PerformanceIndicator.java
/************************************************************************** * Mouse Clicked// www . j ava 2s .c o m * @param e mouse event */ public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) fireActionPerformed(e); if (SwingUtilities.isRightMouseButton(e)) popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:net.sf.jabref.gui.openoffice.StyleSelectDialog.java
private void tablePopup(MouseEvent e) { popup.show(e.getComponent(), e.getX(), e.getY()); }
From source file:net.bioclipse.model.ScatterPlotMouseHandler.java
public void mouseClicked(MouseEvent me) { Point2D p = null;//from ww w.j ava2 s . c o m ChartDescriptor cd = null; int[] indices = null; JFreeChart selectedChart = null; ChartPanel chartPanel = getChartPanel(me); p = chartPanel.translateScreenToJava2D(new Point(me.getX(), me.getY())); selectedChart = chartPanel.getChart(); cd = ChartUtils.getChartDescriptor(selectedChart); indices = cd.getSourceIndices(); XYPlot plot = (XYPlot) chartPanel.getChart().getPlot(); XYItemRenderer plotRenderer = plot.getRenderer(); if (!(plotRenderer instanceof ScatterPlotRenderer)) { throw new IllegalStateException( "Charts using ScatterPlotMouseHandler must use ScatterPlotRenderer as their renderer"); } renderer = (ScatterPlotRenderer) plot.getRenderer(); // now convert the Java2D coordinate to axis coordinates... Number xx = getDomainX(chartPanel, plot, p); Number yy = getRangeY(chartPanel, plot, p); //Find the selected point in the dataset //If shift is down, save old selections if (!me.isShiftDown() || currentSelection == null) { currentSelection = new ChartSelection(); } for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) { for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) { Number xK = plot.getDataset().getX(i, j); Number yK = plot.getDataset().getY(i, j); Number xKCheck = xK.doubleValue() - xx.doubleValue(); Number yKCheck = yK.doubleValue() - yy.doubleValue(); Number xxCheck = xKCheck.doubleValue() * xKCheck.doubleValue(); Number yyCheck = yKCheck.doubleValue() * yKCheck.doubleValue(); //Check distance from click and point, don't want to mark points that are too far from the click if (Math.sqrt(xxCheck.doubleValue()) <= 0.1 && Math.sqrt(yyCheck.doubleValue()) <= 0.1) { //Create a new selection PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel()); cp.setDataPoint(j, i); currentSelection.addPoint(cp); if (!me.isShiftDown()) renderer.clearMarkedPoints(); renderer.addMarkedPoint(j, i); selectedChart.plotChanged(new PlotChangeEvent(plot)); } } } currentSelection.setDescriptor(cd); ChartUtils.updateSelection(currentSelection); }
From source file:com.rapidminer.gui.plotter.charts.ChartPanelShiftController.java
@Override public void mouseDragged(MouseEvent mouseEvent) { if (!mouseEvent.isControlDown()) { return;/* www . jav a 2 s . c o m*/ } if (oldx > -1 && oldy > -1) { int xdif = mouseEvent.getX() - oldx; int ydif = mouseEvent.getY() - oldy; final Rectangle2D scaledDataArea = chartPanel.getScreenDataArea(); ValueAxis[] domAxes = getPlotAxis(chartPanel.getChart(), !axesSwaped); if (domAxes != null) { double[] xDelta = new double[domAxes.length]; for (int i = 0; i < domAxes.length; i++) { xDelta[i] = xdif * domAxes[i].getRange().getLength() / (scaledDataArea.getWidth()); } for (int i = 0; i < domAxes.length; i++) { domAxes[i].setRange(domAxes[i].getLowerBound() - xDelta[i], domAxes[i].getUpperBound() - xDelta[i]); } } ValueAxis[] rngAxes = getPlotAxis(chartPanel.getChart(), axesSwaped); if (rngAxes != null) { double[] yDelta = new double[rngAxes.length]; for (int i = 0; i < rngAxes.length; i++) { yDelta[i] = ydif * rngAxes[i].getRange().getLength() / (scaledDataArea.getHeight()); } if (!onlyXShift) { for (int i = 0; i < rngAxes.length; i++) { rngAxes[i].setRange(rngAxes[i].getLowerBound() + yDelta[i], rngAxes[i].getUpperBound() + yDelta[i]); } } } } oldx = mouseEvent.getX(); oldy = mouseEvent.getY(); }
From source file:mobac.gui.components.JMapSourceTree.java
@Override public String getToolTipText(MouseEvent event) { if (getRowForLocation(event.getX(), event.getY()) == -1) return ""; TreePath curPath = getPathForLocation(event.getX(), event.getY()); Object lastPathComponent = curPath.getLastPathComponent(); if (lastPathComponent == null) return null; Object userObject = ((ComparableTreeNode) lastPathComponent).getUserObject(); if (userObject.getClass().equals(folderClass)) { return null; }//from w w w . java 2s . com return generateMapSourceTooltip((MapSource) userObject); }
From source file:com.ctsim.simemua_instructor.ACarControlPanelFrame.java
private void viewPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_viewPanelMouseClicked doClickDevice(evt.getX(), evt.getY()); }
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. *///from ww w . j a v a 2 s. co 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:edu.harvard.mcz.imagecapture.DeterminationFrame.java
/** * This method initializes jTable //w w w . jav a2s . co m * * @return javax.swing.JTable */ private JTable getJTable() { if (jTableDeterminations == null) { jTableDeterminations = new JTable(); DeterminationTableModel model = new DeterminationTableModel(); jTableDeterminations.setModel(model); if (determinations != null) { jTableDeterminations.setModel(determinations); } FilteringAgentJComboBox field = new FilteringAgentJComboBox(); jTableDeterminations.getColumnModel().getColumn(DeterminationTableModel.ROW_IDENTIFIEDBY) .setCellEditor(new ComboBoxCellEditor(field)); setTableColumnEditors(); jTableDeterminations.setRowHeight(jTableDeterminations.getRowHeight() + 4); jTableDeterminations.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupDets.show(e.getComponent(), e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { clickedOnDetsRow = ((JTable) e.getComponent()).getSelectedRow(); jPopupDets.show(e.getComponent(), e.getX(), e.getY()); } } }); jPopupDets = new JPopupMenu(); JMenuItem mntmDeleteRow = new JMenuItem("Delete Row"); mntmDeleteRow.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { log.debug(clickedOnDetsRow); if (clickedOnDetsRow >= 0) { int ok = JOptionPane.showConfirmDialog(thisFrame, "Delete the selected determination?", "Delete Determination", JOptionPane.OK_CANCEL_OPTION); if (ok == JOptionPane.OK_OPTION) { log.debug("deleting determination row " + clickedOnDetsRow); ((DeterminationTableModel) jTableDeterminations.getModel()) .deleteRow(clickedOnDetsRow); } else { log.debug("determination row delete canceled by user."); } } else { JOptionPane.showMessageDialog(thisFrame, "Unable to select row to delete."); } } catch (Exception ex) { log.error(ex.getMessage()); JOptionPane.showMessageDialog(thisFrame, "Failed to delete a determination row. " + ex.getMessage()); } } }); jPopupDets.add(mntmDeleteRow); } return jTableDeterminations; }
From source file:ucar.unidata.idv.control.chart.RangeFilter.java
/** * Make the attached, but opposite, range filter * * @param event The event/*from w ww . ja v a2 s . c o m*/ * * @return The attached range filter positioned near me. */ public RangeFilter doMakeAttached(MouseEvent event) { if (attached != null) { return attached; } TimeSeriesChartWrapper tscw = (TimeSeriesChartWrapper) getPlotWrapper(); if (type == TYPE_GREATERTHAN) { attached = new RangeFilter(tscw.getRangeValue(event.getY() - 30), tscw); attached.setType(TYPE_LESSTHAN); } else { attached = new RangeFilter(tscw.getRangeValue(event.getY() + 30), tscw); attached.setType(TYPE_GREATERTHAN); } attached.setAttached(this); return attached; }
From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java
/** * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions. *///from w w w. j a v a 2 s . c o m protected void addCopyMenu(final JTextComponent component) { Preconditions.checkNotNull(component); if (!component.isEditable()) { component.setCursor(new Cursor(Cursor.TEXT_CURSOR)); } final JPopupMenu contextMenu = new JPopupMenu(); JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction)); copy.setText(i18n.getString(I18n.TEXT_COPY_ID)); contextMenu.add(copy); contextMenu.addSeparator(); JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction)); selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID)); contextMenu.add(selectAll); component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { contextMenu.show(component, e.getX(), e.getY()); } } }); }