List of usage examples for java.awt.event MouseEvent getY
public int getY()
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override public void mouseMoved(MouseEvent e) { Insets insets = getInsets();// w w w .j ava2 s .co m 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); // boolean isDirty = false; int seriesIndex = -1; if (selectedSeriesIndex >= 0) { // double xInChart = ChartMaskingUtilities.translateScreenX(x, // getScreenDataArea(), getChart()); // XYDataset dataset = getChart().getXYPlot().getDataset(); // PatternDataset patternDataset = (PatternDataset) dataset; // int itemIndex = patternDataset.getItemFromX(selectedSeriesIndex, xInChart); // if (itemIndex < patternDataset.getItemCount(selectedSeriesIndex)) { // chartX = patternDataset.getXValue(selectedSeriesIndex, itemIndex); // chartY = patternDataset.getYValue(selectedSeriesIndex, itemIndex); // Point2D axisTrace = ChartMaskingUtilities.translateChartPoint( // new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart()); // horizontalTraceLocation = (int) axisTrace.getX(); // verticalTraceLocation = (int) axisTrace.getY(); // if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) { // repaint(); // } // seriesIndex = selectedSeriesIndex; // isDirty = true; // } seriesIndex = followDomainTrace(selectedSeriesIndex, x); if (seriesIndex >= 0 && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) { repaint(); } } else if (getChart().getXYPlot().getSeriesCount() == 1) { // int seriesIndex0 = 0; // double xInChart = ChartMaskingUtilities.translateScreenX(x, // getScreenDataArea(), getChart()); // XYDataset dataset = getChart().getXYPlot().getDataset(); // PatternDataset patternDataset = (PatternDataset) dataset; // int itemIndex = patternDataset.getItemFromX(seriesIndex0, xInChart); // if (itemIndex < patternDataset.getItemCount(seriesIndex0)) { // chartX = patternDataset.getXValue(seriesIndex0, itemIndex); // chartY = patternDataset.getYValue(seriesIndex0, itemIndex); // Point2D axisTrace = ChartMaskingUtilities.translateChartPoint( // new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart()); //// if (getScreenDataArea().contains(axisTrace)) { // horizontalTraceLocation = (int) axisTrace.getX(); // verticalTraceLocation = (int) axisTrace.getY(); // if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled) { // repaint(); // } // seriesIndex = seriesIndex0; // isDirty = true; //// } // } seriesIndex = followDomainTrace(0, x); if (seriesIndex >= 0 && (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled())) { repaint(); } } else if (entity instanceof XYItemEntity) { XYItemEntity xyEntity = (XYItemEntity) entity; XYDataset dataset = xyEntity.getDataset(); int item = ((XYItemEntity) entity).getItem(); seriesIndex = xyEntity.getSeriesIndex(); double chartX = dataset.getXValue(seriesIndex, item); double chartY = dataset.getYValue(seriesIndex, item); Point2D screenPoint = ChartMaskingUtilities.translateChartPoint( new Point2D.Double(chartX, chartY), getScreenDataArea(), getChart()); setChartX(chartX); setChartY(chartY); setSeriesIndex(seriesIndex); setItemIndex(item); if (dataset instanceof IXYErrorDataset) { setChartError(((IXYErrorDataset) dataset).getYError(seriesIndex, item)); } if (getHorizontalAxisTrace()) { setHorizontalTraceLocation((int) screenPoint.getX()); } if (getVerticalAxisTrace()) { setVerticalTraceLocation((int) screenPoint.getY()); } if (getHorizontalAxisTrace() || getVerticalAxisTrace() || isToolTipFollowerEnabled()) { repaint(); } // isDirty = true; } if (seriesIndex >= 0) { Object[] listeners = getListeners(ChartMouseListener.class); if (getChart() != null) { XYChartMouseEvent event = new XYChartMouseEvent(getChart(), e, entity); event.setXY(getChartX(), getChartY()); event.setSeriesIndex(seriesIndex); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseMoved(event); } } } } // getChart().handleClick(x, y, getChartRenderingInfo()); } if (isInternalLegendEnabled && isInternalLegendSelected) { int cursorType = findCursorOnSelectedItem(e.getX(), e.getY()); setCursor(Cursor.getPredefinedCursor(cursorType)); } else if (getCursor() != defaultCursor) { setCursor(defaultCursor); } super.mouseMoved(e); // we can only generate events if the panel's chart is not null // (see bug report 1556951) }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Handles a 'mouse released' event.//from w w w . ja v a2 s. co m * <P> * On Windows, we need to check if this is a popup trigger, but only if we * haven't already been tracking a zoom rectangle. * * @param e Information about the event. */ public void mouseReleased(MouseEvent e) { if (zoomRectangle != null) { // if (Math.abs(e.getX() - zoomPoint.getX()) >= MINIMUM_DRAG_ZOOM_SIZE) { if (Math.abs(e.getX() - zoomPoint.getX()) >= 7) { if (e.getX() < zoomPoint.getX() || e.getY() < zoomPoint.getY()) { autoRangeBoth(); } else { double x, y, w, h; Rectangle2D scaledDataArea = getScaledDataArea(); //for a mouseReleased event, (horizontalZoom || verticalZoom) //will be true, so we can just test for either being false; //otherwise both are true if (!verticalZoom) { x = zoomPoint.getX(); y = scaledDataArea.getMinY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = scaledDataArea.getHeight(); } else if (!horizontalZoom) { x = scaledDataArea.getMinX(); y = zoomPoint.getY(); w = scaledDataArea.getWidth(); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } else { x = zoomPoint.getX(); y = zoomPoint.getY(); w = Math.min(zoomRectangle.getWidth(), scaledDataArea.getMaxX() - zoomPoint.getX()); h = Math.min(zoomRectangle.getHeight(), scaledDataArea.getMaxY() - zoomPoint.getY()); } Rectangle2D zoomArea = new Rectangle2D.Double(x, y, w, h); zoom(zoomArea); } this.zoomPoint = null; this.zoomRectangle = null; } else { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); if (fillZoomRectangle) { g2.fill(zoomRectangle); } else { g2.draw(zoomRectangle); } g2.dispose(); this.zoomRectangle = null; } // notify a redraw event CoreStatusEvent ev = new CoreStatusEvent(this); ev.setType(CoreStatusEvent.REDRAW); ((AbstractDmcPlot) chart.getPlot()).notifyCoreStatusListeners(ev); } else if (e.isPopupTrigger()) { if (popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
From source file:com.jcraft.weirdx.DDXWindowImpSwing.java
@SuppressWarnings("unused") public void mouseDragged(MouseEvent e) { if (threeButton) { if (threeBstate != s) { if (threeBstate == sp) { procPressed(threeBPressed); threeBPressed = null;/*from w w w. j a va 2 s.c o m*/ threeBstate = s; } else if (threeBstate == spp) { e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK))) | InputEvent.BUTTON2_MASK, e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()); } else if (threeBstate == sppr) { return; } } } int x = e.getX() + window.x; int y = e.getY() + window.y; XWindow.sprite.hot.x = x; XWindow.sprite.hot.y = y; int mod = e.getModifiers(); // button 1 -> 16 // button 2 -> 8 // button 3 -> 4 // shift -> 1 // control -> 2 // alt -> 12 ?? int state = 0; int detail = 0; if ((mod & InputEvent.BUTTON1_MASK) != 0) { state |= (1 << 8); detail = 1; } if ((mod & InputEvent.BUTTON2_MASK) != 0) { state |= (1 << 9); detail = 2; } if ((mod & InputEvent.BUTTON3_MASK) != 0) { state |= (1 << 10); detail = 3; } if ((mod & InputEvent.SHIFT_MASK) != 0) state |= 1; if ((mod & InputEvent.CTRL_MASK) != 0) state |= 4; // alt -> state|=8; XWindow.sprite.hot.state = state; px = x; py = y; event.mkMotionNotify(1, window.screen.rootId, /*window.id,*/ XWindow.sprite.win.id, 0, px, py, e.getX(), e.getY(), state, 1); try { if (!XWindow.checkMotion(event, window)) { return; } event.mkMotionNotify(1, window.screen.rootId, /*window.id,*/ XWindow.sprite.win.id, 0, px, py, px - XWindow.sprite.win.x, py - XWindow.sprite.win.y, //e.getX(), //e.getY(), state, 1); if (XWindow.grab != null) XWindow.sendGrabbedEvent(event, false, 1); else XWindow.sendDeviceEvent(XWindow.sprite.win, event, XWindow.grab, null, 1); } catch (Exception ee) { } }
From source file:com.jcraft.weirdx.DDXWindowImp.java
public void mousePressed(MouseEvent e) { if (threeButton) { if (threeBstate == s) { threeBPressed = e;//from w w w. j av a2 s.c o m threeBstate = sp; return; } if (threeBstate == sp // || threeBstate==sppr ) { threeBPressed = null; threeBstate = spp; e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK))) | InputEvent.BUTTON2_MASK, e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()); } } procPressed(e); }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Implementation of the MouseMotionListener's method * * @param e the event.//from w w w .java 2 s. c o m */ public void mouseMoved(MouseEvent e) { //crosshair if (this.horizontalAxisTrace && this.verticalAxisTrace && this.crosshairNotBlocked) { Rectangle2D rect = this.getScaledDataArea(); double ux = userX(e); double uy = userY(e); if (!(rect.contains(e.getX(), e.getY()) && disableCrosshairTillLeavesDisplay)) { if (disableCrosshairTillLeavesDisplay) { disableCrosshairTillLeavesDisplay = false; drawHorizontalAxisTrace(e.getX()); drawVerticalAxisTrace(e.getY()); } else { drawHorizontalAxisTrace(e.getX()); drawVerticalAxisTrace(e.getY()); if (rect.contains(e.getX(), e.getY())) { float uxf = (float) ux; float uyf = (float) uy; this.writeToStatusBar("( " + uxf + " , " + uyf + " )"); } else { this.writeToStatusBar(""); } } } } if (this.chartMouseListeners.isEmpty()) { return; } Insets insets = getInsets(); int x = e.getX() - insets.left; int y = e.getY() - insets.top; ChartEntity entity = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity); Iterator iterator = chartMouseListeners.iterator(); while (iterator.hasNext()) { ChartMouseListener listener = (ChartMouseListener) iterator.next(); listener.chartMouseMoved(event); } }
From source file:com.jcraft.weirdx.DDXWindowImp.java
@SuppressWarnings("unused") public void mouseDragged(MouseEvent e) { if (threeButton) { if (threeBstate != s) { if (threeBstate == sp) { procPressed(threeBPressed); threeBPressed = null;//from www . j a v a 2 s . c om threeBstate = s; } else if (threeBstate == spp) { e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK))) | InputEvent.BUTTON2_MASK, e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()); } else if (threeBstate == sppr) { return; } } } if (window == null) return; // calc abs cursor position use old window position for calculation // as mouseDragged (if you use Panel) delivers its coordinates relative to the position after mousepressed // UPDATE: this was a bug of the IBM JDK // int x=e.getX()+oldwindowx; // int y=e.getY()+oldwindowy; int x = e.getX() + window.x; int y = e.getY() + window.y; // set new drag position (absolute) XWindow.sprite.hot.x = x; XWindow.sprite.hot.y = y; int mod = e.getModifiers(); // button 1 -> 16 // button 2 -> 8 // button 3 -> 4 // shift -> 1 // control -> 2 // alt -> 12 ?? int state = 0; int detail = 0; if ((mod & InputEvent.BUTTON1_MASK) != 0) { state |= (1 << 8); detail = 1; } if ((mod & InputEvent.BUTTON2_MASK) != 0) { state |= (1 << 9); detail = 2; } if ((mod & InputEvent.BUTTON3_MASK) != 0) { state |= (1 << 10); detail = 3; } if ((mod & InputEvent.SHIFT_MASK) != 0) state |= 1; if ((mod & InputEvent.CTRL_MASK) != 0) state |= 4; // alt -> state|=8; XWindow.sprite.hot.state = state; px = x; py = y; event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py, e.getX(), e.getY(), state, 1); try { if (!XWindow.checkMotion(event, window)) { return; } event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py, px - XWindow.sprite.win.x, py - XWindow.sprite.win.y, state, 1); if (XWindow.grab != null) { XWindow.sendGrabbedEvent(event, false, 1); } else { XWindow.sendDeviceEvent(XWindow.sprite.win, event, XWindow.grab, null, 1); } } catch (Exception ee) { } }
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. * // w w w . j ava2 s . co m * @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:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override public void mousePressed(MouseEvent e) { int mods = e.getModifiers(); // if (isMaskingEnabled() && (mods & maskingKeyMask) != 0) { if (isInternalLegendEnabled && isInternalLegendSelected) { int cursorType = findCursorOnSelectedItem(e.getX(), e.getY()); if (cursorType == Cursor.DEFAULT_CURSOR) { Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY()); if (screenDataArea != null) { legendPoint = e.getPoint(); } else { legendPoint = null;//from ww w . j a v a2 s . c o m } } else { if (cursorType == Cursor.MOVE_CURSOR) { legendPoint = e.getPoint(); } } } if (isMaskingEnabled()) { // Prepare masking service. int cursorType = findCursorOnSelectedItem(e.getX(), e.getY()); if (cursorType == Cursor.DEFAULT_CURSOR && (mods & maskingKeyMask) != 0) { Rectangle2D screenDataArea = getScreenDataArea(e.getX(), e.getY()); if (screenDataArea != null) { this.maskPoint = getPointInRectangle(e.getX(), e.getY(), screenDataArea).getX(); } else { this.maskPoint = Double.NaN; } } else { if (cursorType == Cursor.MOVE_CURSOR) { // this.maskMovePoint = translateScreenToChart( // translateScreenToJava2D(e.getPoint())).getX(); Insets insets = getInsets(); this.maskMovePoint = ChartMaskingUtilities.translateScreenX( (e.getX() - insets.left) / getScaleX(), getScreenDataArea(), getChart()); } setMaskDragIndicator(cursorType); } } if (getMaskDragIndicator() == Cursor.DEFAULT_CURSOR) { super.mousePressed(e); } }
From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Returns a string for the tooltip./*from w w w . ja v a 2s.c o m*/ * * @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), (int) (e.getY() - insets.top)); if (entity != null) { result = entity.getToolTipText(); } } } return result; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Is mouse on top axis/* ww w .ja va 2s. c o m*/ * * @param mouseEvent the event * * @return On top axis */ private boolean isOnTopDomainAxis(MouseEvent mouseEvent) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); if (mouseEvent.getX() < dataArea.getX()) { return false; } if (mouseEvent.getX() > dataArea.getX() + dataArea.getWidth()) { return false; } double top = dataArea.getY(); return mouseEvent.getY() <= top + 20; }