Java Code Examples for java.awt.event.MouseEvent#getX()
The following examples show how to use
java.awt.event.MouseEvent#getX() .
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 File: DrawTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
@Override public void mouseDragged(MouseEvent e) { e.consume(); switch (mode) { case LINES: x2 = e.getX(); y2 = e.getY(); break; case POINTS: default: colors.add(getForeground()); lines.add(new Rectangle(x1, y1, e.getX(), e.getY())); x1 = e.getX(); y1 = e.getY(); break; } repaint(); }
Example 2
Source File: DrawTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void mouseDragged(MouseEvent e) { e.consume(); switch (mode) { case LINES: x2 = e.getX(); y2 = e.getY(); break; case POINTS: default: colors.add(getForeground()); lines.add(new Rectangle(x1, y1, e.getX(), e.getY())); x1 = e.getX(); y1 = e.getY(); break; } repaint(); }
Example 3
Source File: DrawingPanel.java From osp with GNU General Public License v3.0 | 6 votes |
/** * Handles the mouse released event. * * @param e */ public void mouseReleased(MouseEvent e) { if(isZoomEvent(e)&&(popupmenu!=null)&&popupmenu.isEnabled()) { if(isZoom()&&!zoomBox.isDragged()&& zoomBox.showUndraggedBox) { Dimension dim = viewRect==null? getSize(): viewRect.getSize(); dim.width -= getLeftGutter()+getRightGutter(); dim.height -= getTopGutter()+getBottomGutter(); zoomBox.xstart = e.getX()-dim.width/4; zoomBox.xstop = e.getX()+dim.width/4; zoomBox.ystart = e.getY()-dim.height/4; zoomBox.ystop = e.getY()+dim.height/4; zoomBox.visible = true; repaint(); } JPopupMenu popup = getPopupMenu(); if (popup!=null) popup.show(e.getComponent(), e.getX(), e.getY()); return; } else if(OSPRuntime.isPopupTrigger(e)&&(popupmenu==null)&&(customInspector!=null)) { customInspector.setVisible(true); return; } }
Example 4
Source File: HandToolSupport.java From Pixelitor with GNU General Public License v3.0 | 6 votes |
public void mouseDragged(MouseEvent e, JViewport viewport) { int dx = e.getX() - startX; int dy = e.getY() - startY; Point scrollPos = viewport.getViewPosition(); scrollPos.x -= dx; scrollPos.y -= dy; if (scrollPos.x < 0) { scrollPos.x = 0; } if (scrollPos.y < 0) { scrollPos.y = 0; } if (scrollPos.x > maxScrollPositionX) { scrollPos.x = maxScrollPositionX; } if (scrollPos.y > maxScrollPositionY) { scrollPos.y = maxScrollPositionY; } viewport.setViewPosition(scrollPos); }
Example 5
Source File: DirectoryChooserUI.java From netbeans with Apache License 2.0 | 6 votes |
private void handlePopupMenu (MouseEvent e) { if (!e.isPopupTrigger()) { return; } final 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 != null) { DirectoryNode node = (DirectoryNode) path.getLastPathComponent(); ((DirectoryTreeModel) tree.getModel()).nodeChanged(node); if(!fileChooser.getFileSystemView().isFileSystem(node.getFile())) { return; } tree.setSelectionPath(path); popupMenu.show(tree, x, y); } }
Example 6
Source File: HorizontalLinealComponent.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected int getActiveGuideIndex( final MouseEvent e ) { if ( pageDefinition == null ) { setToolTipText( null ); return -1; } final GuideLine[] lines = linealModel.getGuideLines(); final Unit unit = WorkspaceSettings.getInstance().getUnit(); for ( int i = 0; i < lines.length; i++ ) { final GuideLine guideLine = lines[ i ]; double start = 0; if ( showLeftBorder ) { start = getLeftBorder(); } final int x = (int) ( ( guideLine.getPosition() + start ) * getZoomAsMicropoints() ); if ( x <= e.getX() + 2 && x >= e.getX() - 2 ) { final double unitValue = unit.convertFromPoints( guideLine.getPosition() ); setToolTipText( DECIMAL_FORMAT.format( unitValue ) ); return i; } } setToolTipText( null ); return -1; }
Example 7
Source File: WeightedMeanGraphPanel.java From ET_Redux with Apache License 2.0 | 6 votes |
/** * * @param evt */ @Override public void mouseDragged(MouseEvent evt) { zoomMaxX = evt.getX(); zoomMaxY = evt.getY(); if (imageMode.equalsIgnoreCase("PAN")) { setDisplayOffsetX(getDisplayOffsetX() // + (convertMouseXToValue(zoomMinX) - convertMouseXToValue(zoomMaxX))); setDisplayOffsetY(getDisplayOffsetY() // + (convertMouseYToValue(zoomMinY) - convertMouseYToValue(zoomMaxY))); // System.out.println("move from " + zoomMinX + ", " + zoomMinY + " to " + zoomMaxX + ", " + zoomMaxY); zoomMinX = zoomMaxX; zoomMinY = zoomMaxY; } repaint(); }
Example 8
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override protected TrackListener createTrackListener(JSlider slider) { return new TrackListener() { @Override public void mouseDragged(MouseEvent e) { // case HORIZONTAL: int halfThumbWidth = thumbRect.width / 2; int thumbLeft = e.getX() - offset; int maxPos = xPositionForValue(MAXI) - halfThumbWidth; int minPos = xPositionForValue(MINI) - halfThumbWidth; if (thumbLeft > maxPos) { e.translatePoint(maxPos + offset - e.getX(), 0); } else if (thumbLeft < minPos) { e.translatePoint(minPos + offset - e.getX(), 0); } super.mouseDragged(e); } }; }
Example 9
Source File: ColorPicker.java From 3Dscript with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void mouseMoved(MouseEvent e) { int x = e.getX(); int y = e.getY(); int p = ip.getPixel(x, y); int r = (p&0xff0000)>>16; int g = (p&0xff00)>>8; int b = p&0xff; String hex = Colors.colorToString(new Color(r,g,b)); IJ.showStatus("red="+pad(r)+", green="+pad(g)+", blue="+pad(b)+" ("+hex+")"); }
Example 10
Source File: RenderGrid.java From orbit-image-analysis with GNU General Public License v3.0 | 5 votes |
public void processMouseEvent(MouseEvent e) { switch (e.getID()) { case MouseEvent.MOUSE_PRESSED: setCursor(new Cursor(Cursor.MOVE_CURSOR)); int x = e.getX(); int y = e.getY(); dragx = 0; dragy = 0; if (currentShape != null && currentShape.contains(x, y)) { dragOn = true; } else { // set vpPos to mouse position and update view (simulate drag) int vpWid, vpHt; if (vpSize == null) { vpWid = thumbWidth; vpHt = thumbHeight; } else { vpWid = (int) (vpSize.width * ((double) thumbWidth / imageSize.width)); vpHt = (int) (vpSize.height * ((double) thumbHeight / imageSize.height)); } vpPos.setLocation(e.getX() - (vpWid / 2) - iOffsX, e.getY() - (vpHt / 2) - iOffsY); // clicking outside the vp: iOffs has to be considered dragOn = true; // update view (copied from processMouseMotionEvent) if (dragx == 0) { dragx = (int) Math.abs(vpPos.getX() - e.getX()); dragy = (int) Math.abs(vpPos.getY() - e.getY()); } scroll(e.getX() - dragx, e.getY() - dragy); } break; case MouseEvent.MOUSE_CLICKED: break; case MouseEvent.MOUSE_RELEASED: setCursor(Cursor.getDefaultCursor()); dragOn = false; break; } }
Example 11
Source File: ConstructionWizard.java From mars-sim with GNU General Public License v3.0 | 5 votes |
@Override public synchronized void mouseDragged(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1) { moveSite(site, e.getX(), e.getY()); } else site.setMousePicked(false); xLast = e.getX(); yLast = e.getY(); }
Example 12
Source File: WidgetAction.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates a mouse event. * @param id the event id * @param event the Swing event */ public WidgetMouseEvent(long id, MouseEvent event) { this.id = id; this.event = event; x = event.getX(); y = event.getY(); }
Example 13
Source File: TransformBox.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
/** * Used when there can be more than one transform boxes. * Returns true if this particular transform box handles * the given mouse moved event. */ public boolean processMouseMoved(MouseEvent e) { int x = e.getX(); int y = e.getY(); DraggablePoint hit = handleWasHit(x, y); if (hit != null) { hit.setActive(true); view.repaint(); view.setCursor(hit.getCursor()); return true; } return false; }
Example 14
Source File: ChartPanel.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Implementation of the MouseMotionListener's method. * * @param e the event. */ @Override public void mouseMoved(MouseEvent e) { Graphics2D g2 = (Graphics2D) getGraphics(); if (this.horizontalAxisTrace) { drawHorizontalAxisTrace(g2, e.getX()); } if (this.verticalAxisTrace) { drawVerticalAxisTrace(g2, e.getY()); } g2.dispose(); Object[] listeners = this.chartMouseListeners.getListeners( ChartMouseListener.class); if (listeners.length == 0) { return; } Insets insets = getInsets(); int x = (int) ((e.getX() - insets.left) / this.scaleX); int y = (int) ((e.getY() - insets.top) / this.scaleY); ChartEntity entity = null; if (this.info != null) { EntityCollection entities = this.info.getEntityCollection(); if (entities != null) { entity = entities.getEntity(x, y); } } // we can only generate events if the panel's chart is not null // (see bug report 1556951) if (this.chart != null) { ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity); for (int i = listeners.length - 1; i >= 0; i -= 1) { ((ChartMouseListener) listeners[i]).chartMouseMoved(event); } } }
Example 15
Source File: MarkerBarListener.java From microba with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void mouseDragged(MouseEvent e) { if (!bar.isEnabled()) return; BoundedTableModel dataModel = bar.getDataModel(); if (holdingIndex >= 0 && dataModel != null) { int componentOffset; if (bar.getOrientation() == SwingConstants.HORIZONTAL) componentOffset = e.getX() - holdingShift; else componentOffset = e.getY() - holdingShift; int logicalOffset = this.barUI.componentOffsetToLogicalOffset( componentOffset, dataModel); int logicalPos = dataModel.getLowerBound() + logicalOffset; if (logicalPos < dataModel.getLowerBound()) logicalPos = dataModel.getLowerBound(); if (logicalPos > dataModel.getUpperBound()) logicalPos = dataModel.getUpperBound(); dataModel.setValueAt(new Integer(logicalPos), holdingIndex, bar .getPositionColumn()); } }
Example 16
Source File: ChartSelectionManager.java From visualvm with GNU General Public License v2.0 | 5 votes |
public void mouseMoved(MouseEvent e) { mouseX = e.getX(); mouseY = e.getY(); if (selectionMode == SELECTION_NONE) setSelectionBounds(null); else setSelectionBounds(mouseX, mouseY, 0, 0); updateHighlightedItems(); }
Example 17
Source File: BeltMetaDataStatisticsViewer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public void mousePressed(final MouseEvent e) { if (!SwingUtilities.isLeftMouseButton(e)) { return; } // we somehow missed the drag end event, so finish resize now if (startingX > -1) { int diff = e.getX() - startingX; resizeNameColumn(diff, true); } // start new resize in any case startingX = e.getX(); }
Example 18
Source File: Mouse.java From Cherno with GNU General Public License v3.0 | 4 votes |
public void mouseMoved(MouseEvent e) { x = (int) (e.getX() / scale / scale); y = (int) (e.getY() / scale / scale); }
Example 19
Source File: MultipleSelectionTool.java From openAGV with Apache License 2.0 | 4 votes |
@Override // DelegationSelectionTool protected void handleDoubleClick(MouseEvent evt) { DrawingView v = getView(); Point pos = new Point(evt.getX(), evt.getY()); Handle handle = v.findHandle(pos); // Special case PathConnection: Ignore double click if (handle != null && !(handle instanceof BezierOutlineHandle)) { handle.trackDoubleClick(pos, evt.getModifiersEx()); } else { Point2D.Double p = viewToDrawing(pos); // Note: The search sequence used here, must be // consistent with the search sequence used by the // HandleTracker, the SelectAreaTracker and SelectionTool. // If possible, continue to work with the current selection Figure figure = null; if (isSelectBehindEnabled()) { for (Figure f : v.getSelectedFigures()) { if (f.contains(p)) { figure = f; break; } } } // If the point is not contained in the current selection, // search for a figure in the drawing. if (figure == null) { figure = v.findFigure(pos); } Figure outerFigure = figure; if (figure != null && figure.isSelectable()) { Tool figureTool = figure.getTool(p); if (figureTool == null) { figure = getDrawing().findFigureInside(p); if (figure != null) { figureTool = figure.getTool(p); } } if (figureTool != null) { setTracker(figureTool); figureTool.mousePressed(evt); } else { if (outerFigure.handleMouseClick(p, evt, getView())) { v.clearSelection(); v.addToSelection(outerFigure); } else { v.clearSelection(); v.addToSelection(outerFigure); } } } } evt.consume(); }
Example 20
Source File: XYZApp.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public void mousePressed(MouseEvent e) { prevx = e.getX(); prevy = e.getY(); e.consume(); }