List of usage examples for java.awt.event MouseEvent getX
public int getX()
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);/* w w w . ja va2 s. c om*/ 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.gumtree.vis.hist2d.Hist2DPanel.java
/** * Receives notification of mouse clicks on the panel. These are * translated and passed on to any registered {@link ChartMouseListener}s. * * @param event Information about the mouse event. *///from w ww . j a va2 s. c om public void mouseClicked(MouseEvent event) { Insets insets = getInsets(); int x = (int) ((event.getX() - insets.left) / getScaleX()); int y = (int) ((event.getY() - insets.top) / getScaleY()); double chartX = 0; double chartY = 0; double chartZ = 0; setAnchor(new Point2D.Double(x, y)); if (getChart() == null) { return; } // this.chart.setNotify(true); // force a redraw // new entity code... // Object[] listeners = this.chartMouseListeners.getListeners( // ChartMouseListener.class); ChartEntity entity = null; if (getChartRenderingInfo() != null) { EntityCollection entities = getChartRenderingInfo().getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } if (entity instanceof XYItemEntity) { IDataset dataset = (IDataset) ((XYItemEntity) entity).getDataset(); int item = ((XYItemEntity) entity).getItem(); chartX = dataset.getXValue(0, item); chartY = dataset.getYValue(0, item); chartZ = ((XYZDataset) dataset).getZValue(0, item); // System.out.println("px=" + x + ", py=" + y); // System.out.println("x=" + chartX + ", y=" + chartY + ", z=" + chartZ); // Point2D trsPoint = translateChartPoint(new Point2D.Double(chartX, chartY)); // System.out.println("tx=" + trsPoint.getX() + ", y=" + trsPoint.getY()); // if ((event.getModifiers() & maskingSelectionMask) != 0) { // selectMask(chartX, chartY); // repaint(); // } else { // if (getSelectedMask() != null && (event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0 // && !getSelectedMask().getShape().contains(chartX, chartY)) { // selectMask(null); // repaint(); // } // } if ((event.getModifiers() & MouseEvent.BUTTON1_MASK) != 0) { selectMask(chartX, chartY); repaint(); } } Object[] listeners = getListeners(ChartMouseListener.class); XYZChartMouseEvent chartEvent = new XYZChartMouseEvent(getChart(), event, entity); chartEvent.setXYZ(chartX, chartY, chartZ); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); } }
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 ww . j a v a 2s. 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:org.gumtree.vis.hist2d.Hist2DPanel.java
/** * Implementation of the MouseMotionListener's method. * * @param e the event./*from w w w.j a v a 2 s .c o m*/ */ public void mouseMoved(MouseEvent e) { if (getHorizontalAxisTrace()) { setHorizontalTraceLocation(e.getX()); } if (getVerticalAxisTrace()) { setVerticalTraceLocation(e.getY()); } Insets insets = getInsets(); int x = (int) ((e.getX() - insets.left) / getScaleX()); int y = (int) ((e.getY() - insets.top) / getScaleY()); ChartEntity entity = null; if (getChartRenderingInfo() != null) { EntityCollection entities = getChartRenderingInfo().getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } if (entity instanceof XYItemEntity) { IDataset dataset = (IDataset) ((XYItemEntity) entity).getDataset(); int item = ((XYItemEntity) entity).getItem(); setChartX(dataset.getXValue(0, item)); setChartY(dataset.getYValue(0, item)); setChartZ(((XYZDataset) dataset).getZValue(0, item)); } if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled()) { repaint(); } // if ((e.getModifiers() & maskingKeyMask) != 0) { // int cursorType = findSelectedMask(e.getX(), e.getY()); // setCursor(Cursor.getPredefinedCursor(cursorType)); // } else if (getCursor() != defaultCursor) { // setCursor(defaultCursor); // } // // we can only generate events if the panel's chart is not null // (see bug report 1556951) Object[] listeners = getListeners(ChartMouseListener.class); if (getChart() != null) { XYZChartMouseEvent event = new XYZChartMouseEvent(getChart(), e, entity); event.setXYZ(getChartX(), getChartY(), getChartZ()); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseMoved(event); } } super.mouseMoved(e); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Receives notification of mouse clicks on the panel. These are * translated and passed on to any registered chart mouse click listeners. * * @param event Information about the mouse event. *//*w ww . jav a 2s. co m*/ public void mouseClicked(MouseEvent event) { Insets insets = getInsets(); int x = event.getX() - insets.left; int y = event.getY() - insets.top; //"Custom" mouse click handling code. One may use it for interactive work with the plots //(or follow the original framework). //Manager should be set with setManager(), and handleMouseClicked(), which //is an empty function of AbstractManager, should be overriden in the AbstractManager subclass. if (manager != null) manager.handleMouseClicked(x, y); // old 'handle click' code... chart.handleClick(x, y, this.info); // new entity code... if (this.chartMouseListeners.isEmpty()) { return; } ChartEntity entity = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } ChartMouseEvent chartEvent = new ChartMouseEvent(getChart(), event, entity); Iterator iterator = chartMouseListeners.iterator(); while (iterator.hasNext()) { ChartMouseListener listener = (ChartMouseListener) iterator.next(); listener.chartMouseClicked(chartEvent); } }
From source file:oct.analysis.application.OCTAnalysisUI.java
private void octAnalysisPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_octAnalysisPanelMouseClicked octAnalysisPanel.requestFocus();// w w w .j a va 2 s .c o m //only perform actions when mouse click occurs over image area if (analysisMngr.getAnalysisMode() != null && octAnalysisPanel.coordinateOverlapsOCT(evt.getX(), evt.getY())) { switch (evt.getButton()) { case MouseEvent.BUTTON1: switch (analysisMngr.getAnalysisMode()) { case SINGLE: switch (toolMode) { case SELECT_SINGLE: //clear out any current analysis selection selectionLRPManager.removeSelections(false); octAnalysisPanel.repaint(); //add new selections and redraw panel selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection( octAnalysisPanel.translatePanelPointToOctPoint(evt.getPoint()).x, "Selection", SelectionType.NONFOVEAL, true)); octAnalysisPanel.repaint(); break; case SCREEN_SELECT: selectSelection(evt.getPoint()); break; } break; case MIRROR: switch (toolMode) { case SELECT_SINGLE: //clear out any current analysis selection selectionLRPManager.removeNonfovealSelections(false); octAnalysisPanel.repaint(); //add new selections and redraw panel int distFromFovea = Math.abs(analysisMngr.getFoveaCenterXPosition() - octAnalysisPanel.translatePanelPointToOctPoint(evt.getPoint()).x); selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection( analysisMngr.getFoveaCenterXPosition() - distFromFovea, "Left", SelectionType.NONFOVEAL, true)); selectionLRPManager.addOrUpdateSelection(selectionLRPManager.getSelection( analysisMngr.getFoveaCenterXPosition() + distFromFovea, "Right", SelectionType.NONFOVEAL, true)); octAnalysisPanel.repaint(); break; case SCREEN_SELECT: selectSelection(evt.getPoint()); break; } break; case EZ: //allow user to select and change position of the EZ edge selections after the fact switch (toolMode) { case SCREEN_SELECT: selectSelection(evt.getPoint()); default: break; } break; case EQUIDISTANT: //allow user to change placement of fovea after the fact if (toolMode == ToolMode.SELECT_FOVEA) { //clear out any current analysis information selectionLRPManager.removeSelections(true); octAnalysisPanel.repaint(); //add new selections and redraw panel selectionLRPManager.addOrUpdateEquidistantSelections(evt.getX(), analysisMngr.getMicronsBetweenSelections()); octAnalysisPanel.repaint(); } break; default: break; } break; case MouseEvent.BUTTON3: selectionLRPManager.removeSelections(true); octAnalysisPanel.repaint(); break; default: break; } } }
From source file:org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram.java
/** * Handles a 'mouse released' event. On Windows, we need to check if this * is a popup trigger, but only if we haven't already been tracking a zoom * rectangle./* ww w . j a v a2 s . co m*/ * * @param e information about the event. */ public void mouseReleased(MouseEvent e) { if (this.zoomRectangle != null) { boolean hZoom = false; boolean vZoom = false; if (this.orientation == PlotOrientation.HORIZONTAL) { hZoom = this.rangeZoomable; vZoom = this.domainZoomable; } else { hZoom = this.domainZoomable; vZoom = this.rangeZoomable; } boolean zoomTrigger1 = hZoom && Math.abs(e.getX() - this.zoomPoint.getX()) >= this.zoomTriggerDistance; boolean zoomTrigger2 = vZoom && Math.abs(e.getY() - this.zoomPoint.getY()) >= this.zoomTriggerDistance; if (zoomTrigger1 || zoomTrigger2) { if ((hZoom && (e.getX() < this.zoomPoint.getX())) || (vZoom && (e.getY() < this.zoomPoint.getY()))) { // restoreAutoBounds(); } else { double x, y, w, h; Rectangle2D screenDataArea = getScreenDataArea((int) this.zoomPoint.getX(), (int) this.zoomPoint.getY()); // for mouseReleased event, (horizontalZoom || verticalZoom) // will be true, so we can just test for either being false; // otherwise both are true if (!vZoom) { x = this.zoomPoint.getX(); y = screenDataArea.getMinY(); w = Math.min(this.zoomRectangle.getWidth(), screenDataArea.getMaxX() - this.zoomPoint.getX()); h = screenDataArea.getHeight(); } else if (!hZoom) { x = screenDataArea.getMinX(); y = this.zoomPoint.getY(); w = screenDataArea.getWidth(); h = Math.min(this.zoomRectangle.getHeight(), screenDataArea.getMaxY() - this.zoomPoint.getY()); } else { x = this.zoomPoint.getX(); y = this.zoomPoint.getY(); w = Math.min(this.zoomRectangle.getWidth(), screenDataArea.getMaxX() - this.zoomPoint.getX()); h = Math.min(this.zoomRectangle.getHeight(), screenDataArea.getMaxY() - this.zoomPoint.getY()); } if (activeROI != null) { Rectangle2D rectangleArea = new Rectangle2D.Double(x, y, w, h); g2 = (Graphics2D) getGraphics(); g2.setPaint(activeROI.getColor()); g2.draw(rectangleArea); activeROI.add(rectangleArea, getRange(rectangleArea)); RoiFromChartProcess process = new RoiFromChartProcess(); process.addParam("roi", activeROI); process.addParam("raster", (FLyrRasterSE) rasterSE); process.setActions(this); process.start(); if (gestorRois != null) { // Cargar la nueva ROI en el destor gestorRois.clearRoiGraphics(); } } } this.zoomPoint = null; this.zoomRectangle = null; updateUI(); } else { // Erase the zoom rectangle Graphics2D g2 = (Graphics2D) getGraphics(); drawRectangle(g2); g2.dispose(); this.zoomPoint = null; this.zoomRectangle = null; } } else if (e.isPopupTrigger()) { if (this.popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:base.BasePlayer.ClusterTable.java
@Override public void mouseDragged(MouseEvent event) { mouseDrag = true;//from w w w . j av a 2s.c o m if (resizeColumn > 0) { resizeTable(resizeColumn, event.getX() - this.dragX); this.dragX = event.getX(); } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse pressed' event./*from ww w . j av a2s . c o m*/ * <P> * This event is the popup trigger on Unix/Linux. For Windows, the popup * trigger is the 'mouse released' event. * * @param e The mouse event. */ public void mousePressed(MouseEvent e) { if (zoomRectangle == null) { this.zoomPoint = RefineryUtilities.getPointInRectangle(e.getX(), e.getY(), getScaledDataArea()); // check for popup trigger... if (e.isPopupTrigger()) { if (popup != null) { displayPopupMenu(e.getX(), e.getY()); } } } }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Get the tool tip text/* w w w.ja va 2 s . c o m*/ * * @param event The event * * @return tool tip */ public String chartPanelGetToolTipText(MouseEvent event) { ChartAnnotation annotation = findClosestAnnotation(getAllAnnotations(), event.getX(), event.getY(), false, false); if (annotation == null) { return null; } return annotation.getToolTipText(); }