List of usage examples for java.awt.event MouseEvent getX
public int getX()
From source file:org.rdv.viz.chart.ChartPanel.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. */// w ww . j av a 2s . c om public void mouseClicked(MouseEvent event) { Insets insets = getInsets(); int x = (int) ((event.getX() - insets.left) / this.scaleX); int y = (int) ((event.getY() - insets.top) / this.scaleY); this.anchor = new Point2D.Double(x, y); if (this.chart == null) { return; } this.chart.setNotify(true); // force a redraw // new entity code... Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class); if (listeners.length == 0) { 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); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); } }
From source file:com.isti.traceview.common.TraceViewChartPanel.java
/** * Returns a string for the tooltip./*w ww . java 2s .c om*/ * * @param e * the mouse event. * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Insets insets = getInsets(); ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX), (int) ((e.getY() - insets.top) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
public void showTabPopup(MouseEvent e) { JComponent tabHeaderComponent = (JComponent) e.getComponent(); int tabIndex = getTabIndex(tabHeaderComponent); JComponent tabContent = (JComponent) tabsPane.getComponentAt(tabIndex); WindowBreadCrumbs windowBreadCrumbs = tabs.get(tabContent); Window window = windowBreadCrumbs.getCurrentWindow(); JPopupMenu popupMenu = createWindowPopupMenu(window); if (popupMenu.getComponentCount() > 0) { popupMenu.show(tabHeaderComponent, e.getX(), e.getY()); }/*from ww w . j a v a 2s . c o m*/ }
From source file:org.gumtree.vis.awt.JChartPanel.java
@Override public void mousePressed(MouseEvent e) { if (selectedTextWrapper != null && getCursor() == Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)) { Point2D screenXY = ChartMaskingUtilities.translateChartPoint( new Point2D.Double(selectedTextWrapper.getMinX(), selectedTextWrapper.getMinY()), getScreenDataArea(), getChart()); Rectangle2D screenRect = new Rectangle2D.Double(screenXY.getX(), screenXY.getY() - 15, selectedTextWrapper.getWidth(), selectedTextWrapper.getHeight()); if (screenRect.contains(e.getX(), e.getY())) { double screenX = ChartMaskingUtilities.translateScreenX(e.getX() / getScaleX(), getScreenDataArea(), getChart());// ww w . j a v a2s . c om double screenY = ChartMaskingUtilities.translateScreenY(e.getY(), getScreenDataArea(), getChart(), 0); // Point2D point = translateScreenToChart(translateScreenToJava2D(e.getPoint())); Point2D point = new Point2D.Double(screenX, screenY); if (point != null) { this.textMovePoint = point; } } else { this.textMovePoint = null; } } else { super.mousePressed(e); } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void mouseDragged(MouseEvent e) { if (mouse_start_point != null && theDocument.size() > 0) { if (is_moving) { // moving double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX()); if (mz_delta > 0.) { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getMaxMZ()); double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getMinMZ()); double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); }//from w w w. jav a2 s.co m mouse_start_point = e.getPoint(); } else { // zooming Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics(); g2.setXORMode(java.awt.Color.gray); // delete old rectangle if (zoom_rectangle != null) g2.draw(zoom_rectangle); // create new rectangle double start_x = Math.min(e.getX(), mouse_start_point.getX()); double end_x = Math.max(e.getX(), mouse_start_point.getX()); Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x, (int) mouse_start_point.getY()); double xmax = Math.min(end_x, data_area.getMaxX()); zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x, data_area.getHeight()); // draw new rectangle g2.draw(zoom_rectangle); g2.dispose(); } } }
From source file:org.rdv.viz.chart.ChartPanel.java
/** * Returns a string for the tooltip.// w w w .j av a 2s. c om * * @param e the mouse event. * * @return A tool tip or <code>null</code> if no tooltip is available. */ public String getToolTipText(MouseEvent e) { String result = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { Insets insets = getInsets(); ChartEntity entity = entities.getEntity((int) ((e.getX() - insets.left) / this.scaleX), (int) ((e.getY() - insets.top) / this.scaleY)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:com.isti.traceview.common.TraceViewChartPanel.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. * /*w w w. j a va 2 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()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { // Erase the zoom rectangle Graphics2D g2 = (Graphics2D) getGraphics(); drawZoomRectangle(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:com.SE.myPlayer.MusicPlayerGUI.java
private void songData_TableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_songData_TableMouseClicked try {//from w ww . j a va 2 s . c om if (evt.getClickCount() == 2 | next == 1 | previous == 1 && SwingUtilities.isLeftMouseButton(evt)) { currentSongRow = songData_Table.getSelectedRow(); songLocation = songData[currentSongRow]; sd.addToRecent(songLocation); for (ObjectBean list1 : list) { list1.getMpg().addJmenuItemsToRecentSongs(); } songPlay(); } else if (SwingUtilities.isRightMouseButton(evt)) { Point point = evt.getPoint(); int alreadySelectedRow = songData_Table.getSelectedRow(); int currentRow = songData_Table.rowAtPoint(point); songData_Table.setRowSelectionInterval(alreadySelectedRow, currentRow); if (songData_Table.isRowSelected(currentRow)) { songTable_PopUp.show(songData_Table, evt.getX(), evt.getY()); } else { songTable_PopUp.show(songTable_PopUp, evt.getX(), evt.getY()); } } } catch (Exception e) { currentSongRow = songData_Table.getSelectedRow(); songLocation = songData[currentSongRow]; sd.addToRecent(songLocation); for (ObjectBean list1 : list) { list1.getMpg().addJmenuItemsToRecentSongs(); } songPlay(); } ; }
From source file:com.peterbochs.instrument.InstrumentPanel.java
public void updateCallGraph() { graph = new mxGraph() { public void drawState(mxICanvas canvas, mxCellState state, String label) { if (getModel().isVertex(state.getCell()) && canvas instanceof PeterSwingCanvas) { PeterSwingCanvas c = (PeterSwingCanvas) canvas; c.drawVertex(state, label); } else { // draw edge, at least // super.drawState(canvas, state, label); super.drawState(canvas, state, true); }/*from w w w . j a v a 2s.com*/ } // Ports are not used as terminals for edges, they are // only used to compute the graphical connection point public boolean isPort(Object cell) { mxGeometry geo = getCellGeometry(cell); return (geo != null) ? geo.isRelative() : false; } // Implements a tooltip that shows the actual // source and target of an edge public String getToolTipForCell(Object cell) { if (model.isEdge(cell)) { return convertValueToString(model.getTerminal(cell, true)) + " -> " + convertValueToString(model.getTerminal(cell, false)); } return super.getToolTipForCell(cell); } public boolean isCellFoldable(Object cell, boolean collapse) { return false; } }; graphComponent = new CallGraphComponent(graph); Object parent = graph.getDefaultParent(); addCells(parent); graph.setCellsDisconnectable(false); graphComponent.setGridVisible(true); graphComponent.setGridColor(Color.lightGray); graphComponent.setBackground(Color.white); graphComponent.getViewport().setOpaque(false); graphComponent.setBackground(Color.WHITE); graphComponent.setConnectable(false); graphComponent.getGraphControl().addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { Object cell = graphComponent.getCellAt(e.getX(), e.getY()); if (cell != null) { String label = graph.getLabel(cell); if (label.contains("->")) { cellClientEvent(label); } } } }); graph.setCellsResizable(false); graph.setCellsMovable(false); graph.setCellsEditable(false); graph.foldCells(false); graph.setGridSize(10); jPanel3.removeAll(); jPanel3.add(graphComponent, BorderLayout.CENTER); graphOutline = new mxGraphOutline(graphComponent); graphOutline.setBackground(Color.white); graphOutline.setBorder(new LineBorder(Color.LIGHT_GRAY)); jCallGraphPreviewPanel.removeAll(); jCallGraphPreviewPanel.add(graphOutline, BorderLayout.CENTER); jCallGraphPreviewPanel.setPreferredSize(new Dimension(100, 100)); }
From source file:com.rapidminer.gui.plotter.charts.AbstractChartPanel.java
/** * Receives notification of mouse clicks on the panel. These are translated and passed on to any * registered {@link ChartMouseListener}s. * /* w w w . j a va 2s . co m*/ * @param event * Information about the mouse event. */ @Override public void mouseClicked(MouseEvent event) { Insets insets = getInsets(); int x = (int) ((event.getX() - insets.left) / this.scaleX); int y = (int) ((event.getY() - insets.top) / this.scaleY); this.anchor = new Point2D.Double(x, y); if (this.chart == null) { return; } this.chart.setNotify(true); // force a redraw // new entity code... Object[] listeners = this.chartMouseListeners.getListeners(ChartMouseListener.class); if (listeners.length == 0) { 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); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseClicked(chartEvent); } }