Java Code Examples for java.awt.event.MouseEvent#getY()
The following examples show how to use
java.awt.event.MouseEvent#getY() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Crucible4IDEA File: CommentsTree.java License: MIT License | 6 votes |
@Nullable @Override protected Object getTagAt(MouseEvent e) { JTree tree = (JTree) e.getSource(); final TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return null; } Rectangle bounds = tree.getPathBounds(path); if (bounds == null) { return null; } int dx = e.getX() - bounds.x; int dy = e.getY() - bounds.y; CommentAction.Type linkType = myRenderer.getActionLink(dx, dy); if (linkType == null) { return null; } DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)path.getLastPathComponent(); Comment comment = (Comment)treeNode.getUserObject(); return linkType.createAction(myProject, myReview, comment); }
Example 2
Source Project: netbeans File: InteractiveCanvasComponent.java License: Apache License 2.0 | 6 votes |
public void mouseDragged(MouseEvent e) { if (!dragging) return; int mouseDragX = e.getX(); int mouseDragY = e.getY(); long oldOffsetX = getOffsetX(); long oldOffsetY = getOffsetY(); if (lastMouseDragX != 0 && lastMouseDragY != 0) { int mouseDragDx = isRightBased() ? mouseDragX - lastMouseDragX : lastMouseDragX - mouseDragX; int mouseDragDy = isBottomBased() ? mouseDragY - lastMouseDragY : lastMouseDragY - mouseDragY; setOffset(oldOffsetX + mouseDragDx, oldOffsetY + mouseDragDy); repaintDirtyAccel(); // repaintDirty(); } if (getOffsetX() != oldOffsetX) lastMouseDragX = mouseDragX; if (getOffsetY() != oldOffsetY) lastMouseDragY = mouseDragY; }
Example 3
Source Project: keystore-explorer File: DViewCrl.java License: GNU General Public License v3.0 | 6 votes |
private void maybeDisplayCrlEntryExtensions(MouseEvent evt) { if (evt.getClickCount() > 1) { Point point = new Point(evt.getX(), evt.getY()); int row = jtRevokedCerts.rowAtPoint(point); if (row != -1) { try { CursorUtil.setCursorBusy(DViewCrl.this); jtRevokedCerts.setRowSelectionInterval(row, row); displayCrlEntryExtensions(); } finally { CursorUtil.setCursorFree(DViewCrl.this); } } } }
Example 4
Source Project: radiance File: SubstanceTreeUI.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void mousePressed(MouseEvent e) { if (!tree.isEnabled()) return; TreePath closestPath = tree.getClosestPathForLocation(e.getX(), e.getY()); if (closestPath == null) return; Rectangle bounds = tree.getPathBounds(closestPath); // Process events outside the immediate bounds - fix for defect // 19 on substance-netbeans. This properly handles Ctrl and Shift // selections on trees. if ((e.getY() >= bounds.y) && (e.getY() < (bounds.y + bounds.height)) && ((e.getX() < bounds.x) || (e.getX() > (bounds.x + bounds.width)))) { // tree.setSelectionPath(closestPath); // fix - don't select a node if the click was on the // expand control if (isLocationInExpandControl(closestPath, e.getX(), e.getY())) return; selectPathForEvent(closestPath, e); } }
Example 5
Source Project: JAVA-MVC-Swing-Monopoly File: GameShop.java License: Apache License 2.0 | 6 votes |
@Override public void mouseDragged(MouseEvent e) { int w = this.mainFrame.getX() + this.mainFrame.getWidth(); int h = this.mainFrame.getY() + this.mainFrame.getHeight(); int x = e.getX() - this.frame.getWidth() / 2; int y = e.getY() - this.frame.getHeight() / 2; if (x + this.frame.getWidth() > w) x = w - this.frame.getWidth(); if (y + this.frame.getHeight() > h) y = h - this.frame.getHeight(); if (x < 0) x = 0; if (y < 0) y = 0; frame.setLocation(x, y); }
Example 6
Source Project: FancyBing File: GameTreePanel.java License: GNU General Public License v3.0 | 5 votes |
public void mouseDragged(MouseEvent event) { int x = event.getX(); int y = event.getY(); JPanel panel = (JPanel)event.getSource(); Rectangle rectangle = new Rectangle(x, y, 1, 1); panel.scrollRectToVisible(rectangle); }
Example 7
Source Project: mzmine3 File: TICPlot.java License: GNU General Public License v2.0 | 5 votes |
public void mouseClicked(final MouseEvent event) { // Let the parent handle the event (selection etc.) // super.mouseClicked(event); // Request focus to receive key events. requestFocus(); // Handle mouse click events if (event.getButton() == MouseEvent.BUTTON1) { System.out.println("mouse " + event); if (event.getX() < 70) { // User clicked on Y-axis if (event.getClickCount() == 2) { // Reset zoom on Y-axis XYDataset data = ((XYPlot) getChart().getPlot()).getDataset(); Number maximum = DatasetUtils.findMaximumRangeValue(data); getXYPlot().getRangeAxis().setRange(0, 1.05 * maximum.floatValue()); } else if (event.getClickCount() == 1) { // Auto range on Y-axis getXYPlot().getRangeAxis().setAutoTickUnitSelection(true); getXYPlot().getRangeAxis().setAutoRange(true); } } else if (event.getY() > this.getRenderingInfo().getPlotInfo().getPlotArea().getMaxY() - 41 && event.getClickCount() == 2) { // Reset zoom on X-axis getXYPlot().getDomainAxis().setAutoTickUnitSelection(true); // restoreAutoDomainBounds(); } else if (event.getClickCount() == 2) { // If user double-clicked // left button, place a // request to open a // spectrum. showSpectrumRequest = true; } } }
Example 8
Source Project: radiance File: ColorSliderUI.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * If the mouse is pressed above the "thumb" component then reduce the * scrollbars value by one page ("page up"), otherwise increase it by * one page. If there is no thumb then page up if the mouse is in the * upper half of the track. */ @Override public void mousePressed(MouseEvent e) { if (!slider.isEnabled()) return; currentMouseX = e.getX(); currentMouseY = e.getY(); if (slider.isRequestFocusEnabled()) { slider.requestFocus(); } // Clicked inside the Thumb area? if (thumbRect.contains(currentMouseX, currentMouseY)) { super.mousePressed(e); } else { switch (slider.getOrientation()) { case JSlider.VERTICAL: slider.setValue(valueForYPosition(currentMouseY)); break; case JSlider.HORIZONTAL: slider.setValue(valueForXPosition(currentMouseX)); break; } // FIXME: // We should set isDragging to false here. Unfortunately, // we can not access this variable in class BasicSliderUI. } }
Example 9
Source Project: ET_Redux File: MaskingShade.java License: Apache License 2.0 | 5 votes |
/** * * @param e */ @Override public void mouseMoved(MouseEvent e) { currentMouseX = e.getX(); currentMouseY = e.getY(); if (mouseInPullTab()) { setCursor(new Cursor(Cursor.HAND_CURSOR)); } else { setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); } }
Example 10
Source Project: ccu-historian File: ChartPanel.java License: GNU General Public License v3.0 | 5 votes |
/** * 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. */ @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); } }
Example 11
Source Project: javagame File: MainPanel.java License: MIT License | 5 votes |
/** * �}�b�v��Ń}�E�X���h���b�O�����Ƃ� */ public void mouseDragged(MouseEvent e) { // �}�E�X�|�C���^�̍��W������W�i�}�X�j�����߂� int x = e.getX() / CHIP_SIZE; int y = e.getY() / CHIP_SIZE; // �p���b�g����擾�����ԍ����Z�b�g if (x >= 0 && x < col && y >= 0 && y < row) { map[y][x] = paletteDialog.getSelectedMapChipNo(); } repaint(); }
Example 12
Source Project: visualvm File: HTMLTextArea.java License: GNU General Public License v2.0 | 5 votes |
private void showPopupMenu(MouseEvent e) { if (isEnabled() && isFocusable() && showPopup) { JPopupMenu popup = new JPopupMenu(); populatePopup(popup); if (popup.getComponentCount() > 0) { if (!hasFocus()) requestFocus(); // required for Select All functionality int x, y; if (e != null) { x = e.getX(); y = e.getY(); } else { Rectangle vis = getVisibleRect(); x = vis.x + vis.width / 2; y = vis.y + vis.height / 2; try { Rectangle pos = modelToView(getCaretPosition()); if (pos != null) { pos.width = Math.max(pos.width, 1); // must have nonzero width for the intersects() to work if (vis.intersects(pos)) { x = pos.x + pos.width; y = pos.y + pos.height; } } } catch (BadLocationException ex) {} } popup.show(this, x, y); } } }
Example 13
Source Project: visualvm File: InteractiveCanvasComponent.java License: GNU General Public License v2.0 | 5 votes |
public void mousePressed(MouseEvent e) { dragging = panningPossible() && e.getButton() == mousePanningButton; if (!dragging) return; lastMouseDragX = e.getX(); lastMouseDragY = e.getY(); if (mousePanningCursor != null && isMousePanningEnabled()) setCursor(mousePanningCursor); if (!isOffsetAdjusting()) offsetAdjustingStarted(); }
Example 14
Source Project: ET_Redux File: ConcordiaGraphPanel.java License: Apache License 2.0 | 5 votes |
/** * * @param evt * @return */ public boolean mouseEnteredDateBox(MouseEvent evt) { // this is not very sensitive, so have forced cursor at mode selection below if (preferredDatePanel == null) { return false; } else if ((evt.getX() >= preferredDatePanel.getX()) && (evt.getX() <= (preferredDatePanel.getX() + preferredDatePanel.getWidth())) && (evt.getY() >= preferredDatePanel.getY()) && (evt.getY() <= (preferredDatePanel.getY() + preferredDatePanel.getHeight()))) { return true; } else { return false; } }
Example 15
Source Project: netbeans File: CheckListener.java License: Apache License 2.0 | 5 votes |
@Override public void mouseClicked(MouseEvent e) { // todo (#pf): we need to solve problem between click and double // click - click should be possible only on the check box area // and double click should be bordered by title text. // we need a test how to detect where the mouse pointer is JTree tree = (JTree) e.getSource(); Point p = e.getPoint(); int x = e.getX(); int y = e.getY(); int row = tree.getRowForLocation(x, y); TreePath path = tree.getPathForRow(row); // if path exists and mouse is clicked exactly once if (path == null) { return; } Node node = Visualizer.findNode(path.getLastPathComponent()); if (node == null) { return; } Rectangle chRect = CheckRenderer.getCheckBoxRectangle(); Rectangle rowRect = tree.getPathBounds(path); chRect.setLocation(chRect.x + rowRect.x, chRect.y + rowRect.y); if (e.getClickCount() == 1 && chRect.contains(p)) { boolean isSelected = model.isNodeSelected(node); model.setNodeSelected(node, !isSelected); tree.repaint(); } }
Example 16
Source Project: openjdk-jdk9 File: AquaSliderUI.java License: GNU General Public License v2.0 | 4 votes |
/** * Set the models value to the position of the top/left * of the thumb relative to the origin of the track. */ public void mouseDragged(final MouseEvent e) { int thumbMiddle = 0; if (!slider.isEnabled()) return; currentMouseX = e.getX(); currentMouseY = e.getY(); if (!fIsDragging) return; slider.setValueIsAdjusting(true); switch (slider.getOrientation()) { case SwingConstants.VERTICAL: final int halfThumbHeight = thumbRect.height / 2; int thumbTop = e.getY() - offset; int trackTop = trackRect.y; int trackBottom = trackRect.y + (trackRect.height - 1); final int vMax = yPositionForValue(slider.getMaximum() - slider.getExtent()); if (drawInverted()) { trackBottom = vMax; } else { trackTop = vMax; } thumbTop = Math.max(thumbTop, trackTop - halfThumbHeight); thumbTop = Math.min(thumbTop, trackBottom - halfThumbHeight); setThumbLocation(thumbRect.x, thumbTop); thumbMiddle = thumbTop + halfThumbHeight; slider.setValue(valueForYPosition(thumbMiddle)); break; case SwingConstants.HORIZONTAL: final int halfThumbWidth = thumbRect.width / 2; int thumbLeft = e.getX() - offset; int trackLeft = trackRect.x; int trackRight = trackRect.x + (trackRect.width - 1); final int hMax = xPositionForValue(slider.getMaximum() - slider.getExtent()); if (drawInverted()) { trackLeft = hMax; } else { trackRight = hMax; } thumbLeft = Math.max(thumbLeft, trackLeft - halfThumbWidth); thumbLeft = Math.min(thumbLeft, trackRight - halfThumbWidth); setThumbLocation(thumbLeft, thumbRect.y); thumbMiddle = thumbLeft + halfThumbWidth; slider.setValue(valueForXPosition(thumbMiddle)); break; default: return; } // enable live snap-to-ticks <rdar://problem/3165310> if (slider.getSnapToTicks()) { calculateThumbLocation(); setThumbLocation(thumbRect.x, thumbRect.y); // need to call to refresh the repaint region } }
Example 17
Source Project: opensim-gui File: ChartPanel.java License: Apache License 2.0 | 4 votes |
/** * 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. * * @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 { Graphics2D g2 = (Graphics2D) getGraphics(); g2.setXORMode(java.awt.Color.gray); if (this.fillZoomRectangle) { g2.fill(this.zoomRectangle); } else { g2.draw(this.zoomRectangle); } g2.dispose(); this.zoomPoint = null; this.zoomRectangle = null; } } else if (e.isPopupTrigger()) { if (this.popup != null) { displayPopupMenu(e.getX(), e.getY()); } } }
Example 18
Source Project: Juicebox File: RangeSliderUI.java License: MIT License | 4 votes |
@Override public void mousePressed(MouseEvent e) { if (!slider.isEnabled()) { return; } currentMouseX = e.getX(); currentMouseY = e.getY(); if (slider.isRequestFocusEnabled()) { slider.requestFocus(); } // Determine which thumb is pressed. If the upper thumb is // selected (last one dragged), then check its position first; // otherwise check the position of the lower thumb first. boolean lowerPressed = false; boolean upperPressed = false; if (upperThumbSelected) { if (upperThumbRect.contains(currentMouseX, currentMouseY)) { upperPressed = true; } else if (thumbRect.contains(currentMouseX, currentMouseY)) { lowerPressed = true; } } else { if (thumbRect.contains(currentMouseX, currentMouseY)) { lowerPressed = true; } else if (upperThumbRect.contains(currentMouseX, currentMouseY)) { upperPressed = true; } } // Handle lower thumb pressed. if (lowerPressed && !colorIsOE) { switch (slider.getOrientation()) { case JSlider.VERTICAL: offset = currentMouseY - thumbRect.y; break; case JSlider.HORIZONTAL: offset = currentMouseX - thumbRect.x; break; } upperThumbSelected = false; lowerDragging = true; return; } lowerDragging = false; // Handle upper thumb pressed. if (upperPressed) { switch (slider.getOrientation()) { case JSlider.VERTICAL: offset = currentMouseY - upperThumbRect.y; break; case JSlider.HORIZONTAL: offset = currentMouseX - upperThumbRect.x; break; } upperThumbSelected = true; upperDragging = true; return; } upperDragging = false; }
Example 19
Source Project: marathonv5 File: ImagePanel.java License: Apache License 2.0 | 4 votes |
private void updateCurrentRect(MouseEvent e) { int x = e.getX(); int y = e.getY(); selectedAnnotation.setSize(x - selectedAnnotation.x, y - selectedAnnotation.y); ImagePanel.this.scrollRectToVisible(selectedAnnotation); }
Example 20
Source Project: niftyeditor File: GuiSelectionListener.java License: Apache License 2.0 | 4 votes |
@Override public void mouseMoved(MouseEvent e) { if(this.selecting){ this.disable(); if(e.getX()>selected.getMaxX()-5 && e.getX()<selected.getMaxX()+5 && e.getY()>selected.getMaxY()-5 && e.getY()<selected.getMaxY()+5 ){ e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.SE_RESIZE_CURSOR)); curDir=DIR_SE; }else if(e.getX()==selected.getMinX() && (e.getY()<selected.getMaxY() && e.getY()>selected.getMinY() )){ e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.W_RESIZE_CURSOR)); curDir=DIR_W; }else if(e.getX()==selected.getMaxX() && (e.getY()<selected.getMaxY() && e.getY()>selected.getMinY() )){ e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.E_RESIZE_CURSOR)); curDir=DIR_E; } else if(e.getY()<selected.getMaxY()+5 && e.getY()>selected.getMaxY()-5 && (e.getX()<selected.getMaxX() && e.getX()>selected.getMinX() )){ e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.S_RESIZE_CURSOR)); curDir=DIR_S; } else if(e.getY()==selected.getMinY() && (e.getX()<selected.getMaxX() && e.getX()>selected.getMinX() )){ curDir=DIR_N; e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.N_RESIZE_CURSOR)); }else if(e.getY()<selected.getCenterY()+10 && e.getY()>selected.getCenterY()-10 && (e.getX()<(selected.getCenterX()+10) && e.getX()>selected.getCenterX()-10 )){ e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR)); this.enable(); curDir = NOP; } else{ e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); curDir=NOP; } }else{ e.getComponent().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); curDir=NOP; } }