Java Code Examples for java.awt.event.MouseEvent.getX()
The following are Jave code examples for showing how to use
getX() of the
java.awt.event.MouseEvent
class.
You can vote up the examples you like. Your votes will be used in our system to get
more good examples.
+ Save this method
Example 1
Project: incubator-netbeans File: DirectoryChooserUI.java View Source Code | 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 2
Project: Logisim File: SubcircuitPoker.java View Source Code | 6 votes |
private boolean isWithin(InstanceState state, MouseEvent e) { Bounds bds = state.getInstance().getBounds(); int cx = bds.getX() + bds.getWidth() / 2; int cy = bds.getY() + bds.getHeight() / 2; int dx = e.getX() - cx; int dy = e.getY() - cy; return dx * dx + dy * dy <= 60; }
Example 3
Project: incubator-netbeans File: PopupHandler.java View Source Code | 6 votes |
public void mousePressed(MouseEvent ev) { if (ev.isPopupTrigger()) { int x = ev.getX(); int y = ev.getY(); TreePath path = view.getClosestPathForLocation(x, y); if (path != null) { LookTreeNode n = (LookTreeNode)path.getLastPathComponent(); clicked = new WeakReference<LookTreeNode>(n); @SuppressWarnings("unchecked") Action[] actions = n.getLook().getActions(n.getData(), n.getLookup() ); // XXX handle multiselects... Node selection = makeNode( n ); Lookup context = Lookups.fixed(new Object[] {selection, actionMap}); JPopupMenu menu = Utilities.actionsToPopup(actions, context); menu.show(view, x, y); // XXX selection does not appear to be collected... do we need to // also destroy the popup menu? } } }
Example 4
Project: ZXSprite File: SpriteToggler.java View Source Code | 6 votes |
@Override public void mouseDragged(MouseEvent e) { int mx = e.getX() - xInset; int my = e.getY() - yInset; int gridX = mx / cellSize; int gridY = my / cellSize; if (gridX < sprite.getWidth() && gridY < sprite.getHeight() && gridX >= 0 && gridY >= 0) { if (SwingUtilities.isLeftMouseButton(e)) { sprite.setBit(gridX, gridY); } else { sprite.resetBit(gridX, gridY); } } repaint(); parent.dispatchEvent(e); }
Example 5
Project: Logisim File: EditTool.java View Source Code | 5 votes |
@Override public void mousePressed(Canvas canvas, Graphics g, MouseEvent e) { boolean wire = updateLocation(canvas, e); Location oldWireLoc = wireLoc; wireLoc = NULL_LOCATION; lastX = Integer.MIN_VALUE; if (wire) { current = wiring; Selection sel = canvas.getSelection(); Circuit circ = canvas.getCircuit(); Collection<Component> selected = sel.getAnchoredComponents(); ArrayList<Component> suppress = null; for (Wire w : circ.getWires()) { if (selected.contains(w)) { if (w.contains(oldWireLoc)) { if (suppress == null) suppress = new ArrayList<Component>(); suppress.add(w); } } } sel.setSuppressHandles(suppress); } else { current = select; } pressX = e.getX(); pressY = e.getY(); current.mousePressed(canvas, g, e); }
Example 6
Project: BrainControl File: LevelEditView.java View Source Code | 5 votes |
public void mouseDragged(MouseEvent e) { xTile = e.getX() / 16; yTile = e.getY() / 16; cursorPosition.setText("Cursor position: ("+xTile+", "+yTile+")"); level.setBlock(xTile, yTile, tilePicker.pickedTile); levelRenderer.repaint(xTile - 1, yTile - 1, 3, 3); repaint(); }
Example 7
Project: JavaGraph File: JGraphUI.java View Source Code | 5 votes |
@Override public void mousePressed(MouseEvent e) { if (isAllowed(e)) { this.pressX = e.getX(); this.pressY = e.getY(); this.bounds.setBounds(this.pressX, this.pressY, 0, 0); this.active = true; } }
Example 8
Project: incubator-netbeans File: WidgetAction.java View Source Code | 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 9
Project: parabuild-ci File: ChartPanel.java View Source Code | 5 votes |
/** * Implementation of the MouseMotionListener's method * * @param e the event. */ public void mouseMoved(MouseEvent e) { if (this.horizontalAxisTrace) { drawHorizontalAxisTrace(e.getX()); } if (this.verticalAxisTrace) { drawVerticalAxisTrace(e.getY()); } if (this.chartMouseListeners.isEmpty()) { 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); } } ChartMouseEvent event = new ChartMouseEvent(getChart(), e, entity); Iterator iterator = this.chartMouseListeners.iterator(); while (iterator.hasNext()) { ChartMouseListener listener = (ChartMouseListener) iterator.next(); listener.chartMouseMoved(event); } }
Example 10
Project: incubator-netbeans File: ChartSelectionManager.java View Source Code | 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 11
Project: Neukoelln_SER316 File: TaskTable.java View Source Code | 4 votes |
/** * Overridden to return false, and if the event is a mouse event it is * forwarded to the tree. * <p> * The behavior for this is debatable, and should really be offered as a * property. By returning false, all keyboard actions are implemented in * terms of the table. By returning true, the tree would get a chance to * do something with the keyboard events. For the most part this is ok. * But for certain keys, such as left/right, the tree will * expand/collapse where as the table focus should really move to a * different column. Page up/down should also be implemented in terms of * the table. By returning false this also has the added benefit that * clicking outside of the bounds of the tree node, but still in the * tree column will select the row, whereas if this returned true that * wouldn't be the case. * <p> * By returning false we are also enforcing the policy that the tree * will never be editable (at least by a key sequence). */ public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent) { for (int counter = getColumnCount() - 1; counter >= 0; counter--) { if (getColumnClass(counter) == TreeTableModel.class) { MouseEvent me = (MouseEvent) e; MouseEvent newME = new MouseEvent(tree, me.getID(), me .getWhen(), me.getModifiers(), me.getX() - getCellRect(0, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger()); tree.dispatchEvent(newME); break; } } } return false; }
Example 12
Project: SER316-Aachen File: JTreeTable.java View Source Code | 4 votes |
/** * Overridden to return false, and if the event is a mouse event it is * forwarded to the tree. * <p> * The behavior for this is debatable, and should really be offered as a * property. By returning false, all keyboard actions are implemented in * terms of the table. By returning true, the tree would get a chance to * do something with the keyboard events. For the most part this is ok. * But for certain keys, such as left/right, the tree will * expand/collapse where as the table focus should really move to a * different column. Page up/down should also be implemented in terms of * the table. By returning false this also has the added benefit that * clicking outside of the bounds of the tree node, but still in the * tree column will select the row, whereas if this returned true that * wouldn't be the case. * <p> * By returning false we are also enforcing the policy that the tree * will never be editable (at least by a key sequence). */ public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent) { for (int counter = getColumnCount() - 1; counter >= 0; counter--) { if (getColumnClass(counter) == TreeTableModel.class) { MouseEvent me = (MouseEvent) e; MouseEvent newME = new MouseEvent(tree, me.getID(), me .getWhen(), me.getModifiers(), me.getX() - getCellRect(0, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger()); tree.dispatchEvent(newME); break; } } } return false; }
Example 13
Project: openjdk-jdk10 File: XYZApp.java View Source Code | 4 votes |
@Override public void mousePressed(MouseEvent e) { prevx = e.getX(); prevy = e.getY(); e.consume(); }
Example 14
Project: jdk8u-jdk File: XYZApp.java View Source Code | 4 votes |
@Override public void mousePressed(MouseEvent e) { prevx = e.getX(); prevy = e.getY(); e.consume(); }
Example 15
Project: openjdk-jdk10 File: AquaSliderUI.java View Source Code | 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 16
Project: Reinickendorf_SER316 File: TaskTable.java View Source Code | 4 votes |
/** * Overridden to return false, and if the event is a mouse event it is * forwarded to the tree. * <p> * The behavior for this is debatable, and should really be offered as a * property. By returning false, all keyboard actions are implemented in * terms of the table. By returning true, the tree would get a chance to * do something with the keyboard events. For the most part this is ok. * But for certain keys, such as left/right, the tree will * expand/collapse where as the table focus should really move to a * different column. Page up/down should also be implemented in terms of * the table. By returning false this also has the added benefit that * clicking outside of the bounds of the tree node, but still in the * tree column will select the row, whereas if this returned true that * wouldn't be the case. * <p> * By returning false we are also enforcing the policy that the tree * will never be editable (at least by a key sequence). */ public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent) { for (int counter = getColumnCount() - 1; counter >= 0; counter--) { if (getColumnClass(counter) == TreeTableModel.class) { MouseEvent me = (MouseEvent) e; MouseEvent newME = new MouseEvent(tree, me.getID(), me .getWhen(), me.getModifiers(), me.getX() - getCellRect(0, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger()); tree.dispatchEvent(newME); break; } } } return false; }
Example 17
Project: Wilmersdorf_SER316 File: TimeLogTable.java View Source Code | 4 votes |
/** * Overridden to return false, and if the event is a mouse event it is * forwarded to the tree. * <p> * The behavior for this is debatable, and should really be offered as a * property. By returning false, all keyboard actions are implemented in * terms of the table. By returning true, the tree would get a chance to * do something with the keyboard events. For the most part this is ok. * But for certain keys, such as left/right, the tree will * expand/collapse where as the table focus should really move to a * different column. Page up/down should also be implemented in terms of * the table. By returning false this also has the added benefit that * clicking outside of the bounds of the tree node, but still in the * tree column will select the row, whereas if this returned true that * wouldn't be the case. * <p> * By returning false we are also enforcing the policy that the tree * will never be editable (at least by a key sequence). */ public boolean isCellEditable(EventObject e) { if (e instanceof MouseEvent) { for (int counter = getColumnCount() - 1; counter >= 0; counter--) { if (getColumnClass(counter) == TreeTableModel.class) { MouseEvent me = (MouseEvent) e; MouseEvent newME = new MouseEvent(tree, me.getID(), me .getWhen(), me.getModifiers(), me.getX() - getCellRect(0, counter, true).x, me.getY(), me.getClickCount(), me.isPopupTrigger()); tree.dispatchEvent(newME); break; } } } return false; }
Example 18
Project: jdk8u-jdk File: AquaSliderUI.java View Source Code | 4 votes |
public void mousePressed(final MouseEvent e) { if (!slider.isEnabled()) return; // We should recalculate geometry just before // calculation of the thumb movement direction. // It is important for the case, when JSlider // is a cell editor in JTable. See 6348946. calculateGeometry(); final boolean firstClick = (currentMouseX == -1) && (currentMouseY == -1); currentMouseX = e.getX(); currentMouseY = e.getY(); if (slider.isRequestFocusEnabled()) { slider.requestFocus(); } boolean isMouseEventInThumb = thumbRect.contains(currentMouseX, currentMouseY); // we don't want to move the thumb if we just clicked on the edge of the thumb if (!firstClick || !isMouseEventInThumb) { slider.setValueIsAdjusting(true); switch (slider.getOrientation()) { case SwingConstants.VERTICAL: slider.setValue(valueForYPosition(currentMouseY)); break; case SwingConstants.HORIZONTAL: slider.setValue(valueForXPosition(currentMouseX)); break; } slider.setValueIsAdjusting(false); isMouseEventInThumb = true; // since we just moved it in there } // Clicked in the Thumb area? if (isMouseEventInThumb) { switch (slider.getOrientation()) { case SwingConstants.VERTICAL: offset = currentMouseY - thumbRect.y; break; case SwingConstants.HORIZONTAL: offset = currentMouseX - thumbRect.x; break; } fIsDragging = true; return; } fIsDragging = false; }
Example 19
Project: featurea File: MouseAndKeyInputAdapter.java View Source Code | 4 votes |
@Override public final void mousePressed(MouseEvent e) { x = e.getX(); y = e.getY(); down(e, x, y); }
Example 20
Project: Logisim File: PlaRom.java View Source Code | 4 votes |
private boolean isInside(InstanceState state, MouseEvent e) { Location loc = state.getInstance().getLocation(); int dx = e.getX() - loc.getX(); int dy = e.getY() - loc.getY(); return (dx >= 4 && dx <= 76 && dy >= 7 && dy <= 24); }