java.awt.event.MouseEvent#getComponent()源码实例Demo

下面列出了java.awt.event.MouseEvent#getComponent() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * 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;
            }
        }
    }

}
 
源代码2 项目: java-swing-tips   文件: MainPanel.java
@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();
}
 
源代码3 项目: pumpernickel   文件: SplayedLayout.java
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();
		}
	}
}
 
源代码4 项目: mzmine2   文件: ChartGestureMouseAdapter.java
@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);
  }
}
 
源代码5 项目: mzmine2   文件: ChartGestureMouseAdapter.java
@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);
  }
}
 
源代码6 项目: java-swing-tips   文件: MainPanel.java
@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);
  }
}
 
源代码7 项目: JCEditor   文件: ButtonTabComponent.java
public void mouseEntered(MouseEvent e) {
    Component component = e.getComponent();
    if (component instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) component;
        button.setBorderPainted(false);
    }
}
 
源代码8 项目: java-swing-tips   文件: ReorderbleList.java
@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();
}
 
源代码9 项目: pumpernickel   文件: CurvedPolylineCreationUI.java
@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();
	}
}
 
源代码10 项目: audiveris   文件: ButtonTabComponent.java
@Override
public void mouseEntered (MouseEvent e)
{
    Component component = e.getComponent();

    if (component instanceof AbstractButton) {
        AbstractButton button = (AbstractButton) component;
        button.setBorderPainted(true);
    }
}
 
源代码11 项目: mars-sim   文件: ComponentMover.java
/**
 *  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);
}
 
源代码12 项目: java-swing-tips   文件: MainPanel.java
@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);
  }
}
 
源代码13 项目: netbeans   文件: InnerPanelSupport.java
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();
    }
}
 
源代码14 项目: opt4j   文件: DefaultSelectedPanel.java
@Override
public void mouseExited(MouseEvent e) {
	Component component = e.getComponent();
	if (component instanceof AbstractButton) {
		AbstractButton button = (AbstractButton) component;
		button.setBorderPainted(false);
	}
}
 
源代码15 项目: consulo   文件: EditorActionUtil.java
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();
  }
}
 
源代码16 项目: mars-sim   文件: TableColumnManager.java
private void checkForPopup(MouseEvent e)
{
	if (e.isPopupTrigger())
	{
		JTableHeader header = (JTableHeader)e.getComponent();
		int column = header.columnAtPoint( e.getPoint() );
		showPopup(column);
	}
}
 
源代码17 项目: java-swing-tips   文件: MainPanel.java
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;
}
 
源代码18 项目: java-swing-tips   文件: MainPanel.java
@Override public void mousePressed(MouseEvent e) {
  JComponent panel = (JComponent) e.getComponent();
  origin.setLocation(e.getPoint());
  // 選択された部品を上へ
  parent.moveToFront(panel);
}
 
源代码19 项目: darklaf   文件: MouseEventUI.java
private void dispatchMouseEvent(final MouseEvent mouseEvent) {
    if (mouseEvent != null) {
        Component target = mouseEvent.getComponent();
        target.dispatchEvent(mouseEvent);
    }
}
 
源代码20 项目: consulo   文件: RelativePoint.java
public RelativePoint(@Nonnull MouseEvent event) {
  this(event.getComponent(), event.getPoint());
}