Java Code Examples for java.awt.event.MouseEvent#getComponent()
The following examples show how to use
java.awt.event.MouseEvent#getComponent() .
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: ChartGestureMouseAdapter.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
@Override public void mousePressed(MouseEvent e) { if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.PRESSED)) return; if (e.getComponent() instanceof ChartPanel) { ChartPanel chartPanel = (ChartPanel) e.getComponent(); ChartEntity entity = findChartEntity(chartPanel, e); ChartGesture.Entity gestureEntity = ChartGesture.getGestureEntity(entity); Button button = Button.getButton(e.getButton()); // handle event lastDragEvent = new ChartGestureEvent(chartPanel, e, entity, new ChartGesture(gestureEntity, Event.PRESSED, button)); handleEvent(lastDragEvent); } }
Example 2
Source File: SortableTableHeaderListener.java From ccu-historian with GNU General Public License v3.0 | 6 votes |
/** * Handle a mouse press event - if the user is NOT resizing a column and NOT dragging a column * then give visual feedback that the column header has been pressed. * * @param e the mouse event. */ public void mousePressed(final MouseEvent e) { final JTableHeader header = (JTableHeader) e.getComponent(); if (header.getResizingColumn() == null) { // resizing takes precedence over sorting if (header.getDraggedDistance() < 1) { // dragging also takes precedence over sorting final int columnIndex = header.columnAtPoint(e.getPoint()); final int modelColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex); if (this.model.isSortable(modelColumnIndex)) { this.sortColumnIndex = header.getTable().convertColumnIndexToModel(columnIndex); this.renderer.setPressedColumn(this.sortColumnIndex); header.repaint(); if (header.getTable().isEditing()) { header.getTable().getCellEditor().stopCellEditing(); } } else { this.sortColumnIndex = -1; } } } }
Example 3
Source File: ChartGestureMouseAdapter.java From mzmine2 with GNU General Public License v2.0 | 6 votes |
@Override public void mouseDragged(MouseEvent e) { if (gestureHandlers == null || gestureHandlers.isEmpty() || !listensFor(Event.DRAGGED)) return; if (e.getComponent() instanceof ChartPanel) { ChartPanel chartPanel = (ChartPanel) e.getComponent(); // keep the same chartEntity ChartEntity entity = lastDragEvent.getEntity(); ChartGesture.Entity gestureEntity = lastDragEvent.getGesture().getEntity(); Button button = lastDragEvent.getGesture().getButton(); // handle event lastDragEvent = new ChartGestureEvent(chartPanel, e, entity, new ChartGesture(gestureEntity, Event.DRAGGED, button)); handleEvent(lastDragEvent); } }
Example 4
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override public void mouseDragged(MouseEvent e) { JList<?> l = (JList<?>) e.getComponent(); if (l.getDragEnabled()) { return; } Point destPoint = e.getPoint(); Path2D rb = getRubberBand(); rb.reset(); rb.moveTo(srcPoint.x, srcPoint.y); rb.lineTo(destPoint.x, srcPoint.y); rb.lineTo(destPoint.x, destPoint.y); rb.lineTo(srcPoint.x, destPoint.y); rb.closePath(); // JDK 1.7.0: l.setSelectedIndices(getIntersectsIcons(l, rubberBand)); int[] indices = IntStream.range(0, l.getModel().getSize()) .filter(i -> rb.intersects(l.getCellBounds(i, i))).toArray(); l.setSelectedIndices(indices); l.repaint(); }
Example 5
Source File: SplayedLayout.java From pumpernickel with MIT License | 6 votes |
private void process(MouseEvent e) { Component c = e.getComponent(); JComponent splayedAncestor = (JComponent) getSplayedAncestor(c); if (splayedAncestor == null) { c.removeMouseListener(this); } else if (prioritizeRollover) { if (e.getID() == MouseEvent.MOUSE_ENTERED && splayedAncestor .getClientProperty(PROPERTY_ROLLOVER_CHILD) != c) { splayedAncestor.putClientProperty(PROPERTY_ROLLOVER_CHILD, c); splayedAncestor.revalidate(); } else if (e.getID() == MouseEvent.MOUSE_EXITED && splayedAncestor .getClientProperty(PROPERTY_ROLLOVER_CHILD) == c) { splayedAncestor.putClientProperty(PROPERTY_ROLLOVER_CHILD, null); splayedAncestor.revalidate(); } } }
Example 6
Source File: ButtonTabComponent.java From JCEditor with GNU General Public License v2.0 | 5 votes |
public void mouseEntered(MouseEvent e) { Component component = e.getComponent(); if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; button.setBorderPainted(false); } }
Example 7
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
protected void updateToolTip(MouseEvent e) { JSlider slider = (JSlider) e.getComponent(); int intValue = slider.getValue(); if (prevValue != intValue) { label.setText(String.format("%03d", slider.getValue())); Point pt = e.getPoint(); pt.y = -size.height; SwingUtilities.convertPointToScreen(pt, e.getComponent()); pt.translate(-size.width / 2, 0); toolTip.setLocation(pt); } prevValue = intValue; }
Example 8
Source File: TableColumnManager.java From mars-sim with GNU General Public License v3.0 | 5 votes |
private void checkForPopup(MouseEvent e) { if (e.isPopupTrigger()) { JTableHeader header = (JTableHeader)e.getComponent(); int column = header.columnAtPoint( e.getPoint() ); showPopup(column); } }
Example 9
Source File: EditorActionUtil.java From consulo with Apache License 2.0 | 5 votes |
private static void showEditorPopup(final EditorMouseEvent event, @Nonnull final ActionGroup group) { if (!event.isConsumed() && event.getArea() == EditorMouseEventArea.EDITING_AREA) { ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.EDITOR_POPUP, group); MouseEvent e = event.getMouseEvent(); final Component c = e.getComponent(); if (c != null && c.isShowing()) { popupMenu.getComponent().show(c, e.getX(), e.getY()); } e.consume(); } }
Example 10
Source File: DefaultSelectedPanel.java From opt4j with MIT License | 5 votes |
@Override public void mouseExited(MouseEvent e) { Component component = e.getComponent(); if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; button.setBorderPainted(false); } }
Example 11
Source File: InnerPanelSupport.java From netbeans with Apache License 2.0 | 5 votes |
public void redispatchMouseEvent(MouseEvent e) { if (!(e.getComponent() instanceof RenderedImage)) { return; } MouseEvent delegate = SwingUtilities.convertMouseEvent(e.getComponent(), e, listClasses); listClasses.dispatchEvent(delegate); // if the table started editing, remove the popup: if (listClasses.isEditing()) { hidePopup(); } }
Example 12
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void mousePressed(MouseEvent e) { Component c = e.getComponent(); c.setCursor(hndCursor); Container p = SwingUtilities.getUnwrappedParent(c); if (p instanceof JViewport) { JViewport vport = (JViewport) p; Point cp = SwingUtilities.convertPoint(c, e.getPoint(), vport); pp.setLocation(cp); } }
Example 13
Source File: ComponentMover.java From mars-sim with GNU General Public License v3.0 | 5 votes |
/** * Setup the variables used to control the moving of the component: * * source - the source component of the mouse event * destination - the component that will ultimately be moved * pressed - the Point where the mouse was pressed in the destination * component coordinates. */ @Override public void mousePressed(MouseEvent e) { isMousePressed = true; source = e.getComponent(); int width = source.getSize().width - dragInsets.left - dragInsets.right; int height = source.getSize().height - dragInsets.top - dragInsets.bottom; Rectangle r = new Rectangle(dragInsets.left, dragInsets.top, width, height); if (r.contains(e.getPoint())) setupForDragging(e); }
Example 14
Source File: ButtonTabComponent.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
@Override public void mouseEntered (MouseEvent e) { Component component = e.getComponent(); if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton) component; button.setBorderPainted(true); } }
Example 15
Source File: CurvedPolylineCreationUI.java From pumpernickel with MIT License | 5 votes |
@Override public void mouseDragged(MouseEvent evt) { ShapeCreationPanel scp = (ShapeCreationPanel) evt.getComponent(); try { AffineTransform tx = scp.getTransform().createInverse(); Point2D mouseLoc = new Point2D.Float(evt.getX(), evt.getY()); Point2D abstractLoc = tx.transform(mouseLoc, null); boolean isCreating = ShapeCreationPanel.MODE_CREATE.equals(scp .getMode()); if (!isCreating) { Selection selection = scp.getSelectionModel() .getSelection(); if (selection.getShapeIndex() != -1) { if (selection.getNodeIndex() != -1) { CurvedPolyline shape = getMirror(scp)[selection .getShapeIndex()]; shape.setPoint(selection.getNodeIndex(), abstractLoc.getX(), abstractLoc.getY()); scp.getDataModel().setShape( selection.getShapeIndex(), shape); } else { float dx = evt.getX() - lastUntransformedX; float dy = evt.getY() - lastUntransformedY; nudge(scp, dx, dy); } return; } } mouseMoved(evt); } catch (Exception e) { e.printStackTrace(); } finally { lastUntransformedX = evt.getX(); lastUntransformedY = evt.getY(); } }
Example 16
Source File: ReorderbleList.java From java-swing-tips with MIT License | 5 votes |
@Override public void mouseReleased(MouseEvent e) { JList<?> l = (JList<?>) e.getComponent(); l.setFocusable(true); // if (Objects.isNull(srcPoint) || !getDragEnabled()) { // Component glassPane = l.getRootPane().getGlassPane(); // glassPane.setVisible(false); // } getRubberBand().reset(); l.setDragEnabled(l.getSelectedIndices().length > 0); l.repaint(); }
Example 17
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void mouseReleased(MouseEvent e) { if (!window.isVisible() || Objects.isNull(draggingComponent)) { return; } Point pt = e.getPoint(); Container parent = (Container) e.getComponent(); Component cmp = draggingComponent; draggingComponent = null; window.setVisible(false); for (int i = 0; i < parent.getComponentCount(); i++) { Component c = parent.getComponent(i); Rectangle r = c.getBounds(); int wd2 = r.width / 2; PREV_AREA.setBounds(r.x, r.y, wd2, r.height); NEXT_AREA.setBounds(r.x + wd2, r.y, wd2, r.height); if (PREV_AREA.contains(pt)) { swapComponentLocation(parent, gap, cmp, i > 1 ? i : 0); return; } else if (NEXT_AREA.contains(pt)) { swapComponentLocation(parent, gap, cmp, i); return; } } if (parent.getBounds().contains(pt)) { swapComponentLocation(parent, gap, cmp, parent.getComponentCount()); } else { swapComponentLocation(parent, gap, cmp, index); } }
Example 18
Source File: MouseEventUI.java From darklaf with MIT License | 4 votes |
private void dispatchMouseEvent(final MouseEvent mouseEvent) { if (mouseEvent != null) { Component target = mouseEvent.getComponent(); target.dispatchEvent(mouseEvent); } }
Example 19
Source File: MainPanel.java From java-swing-tips with MIT License | 4 votes |
@Override public void mousePressed(MouseEvent e) { JComponent panel = (JComponent) e.getComponent(); origin.setLocation(e.getPoint()); // 選択された部品を上へ parent.moveToFront(panel); }
Example 20
Source File: RelativePoint.java From consulo with Apache License 2.0 | 4 votes |
public RelativePoint(@Nonnull MouseEvent event) { this(event.getComponent(), event.getPoint()); }