Java Code Examples for javax.swing.SwingUtilities#getDeepestComponentAt()

The following examples show how to use javax.swing.SwingUtilities#getDeepestComponentAt() . 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: Bytecoder   File: JLightweightFrame.java    License: Apache License 2.0 6 votes vote down vote up
private void updateClientCursor() {
    PointerInfo pointerInfo = MouseInfo.getPointerInfo();
    if (pointerInfo == null) {
        /*
         * This can happen when multiple graphics device cannot decide
         * which graphics device contains the current mouse position
         * or on systems without a mouse
         */
         return;
    }
    Point p = pointerInfo.getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 2
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 3
Source Project: pumpernickel   File: BoxTabbedPaneUI.java    License: MIT License 5 votes vote down vote up
public int getTabForCoordinate(int x, int y) {
	Component c = SwingUtilities.getDeepestComponentAt(tabs, x, y);
	while (c != tabs) {
		if (c instanceof JComponent) {
			JComponent jc = (JComponent) c;
			Integer i = (Integer) jc
					.getClientProperty(PROPERTY_TAB_INDEX);
			if (i != null)
				return i;
		}
		c = c.getParent();
	}
	return -1;
}
 
Example 4
Source Project: stendhal   File: DragLayer.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get the drop target capable of accepting the dragged entity at the
 * current location.
 *
 * @return drop target, or <code>null</code> if the component below is not a
 * 	DropTarget, or it is not capable of accepting the dragged entity
 */
private DropTarget getCurrentDropTarget() {
	if (underlyingComponent == null) {
		Container parent = getParent();
		Point containerPoint = SwingUtilities.convertPoint(this, point, parent);
		underlyingComponent = SwingUtilities.getDeepestComponentAt(parent, containerPoint.x, containerPoint.y);
	}
	if ((underlyingComponent instanceof DropTarget)
			&& (((DropTarget) underlyingComponent).canAccept(dragged.getEntity()))) {
		return (DropTarget) underlyingComponent;
	}
	return null;
}
 
Example 5
Source Project: marathonv5   File: Device.java    License: Apache License 2.0 5 votes vote down vote up
public static Component getActiveComponent(Component component, int x, int y) {
    Component componentx = SwingUtilities.getDeepestComponentAt(component, x, y);
    if (componentx == null) {
        return component;
    }
    return componentx;
}
 
Example 6
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 7
Source Project: marathonv5   File: ContextMenuHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void showPopup(MouseEvent mouseEvent) {
    if (isContextMenuOn()) {
        return;
    }
    Component component = SwingUtilities.getDeepestComponentAt(mouseEvent.getComponent(), mouseEvent.getX(), mouseEvent.getY());
    if (component == null) {
        return;
    }
    if (component instanceof JMenuItem && (!(component instanceof JMenu) || ((JMenu) component).isSelected())) {
        return;
    }
    Point point = SwingUtilities.convertPoint(mouseEvent.getComponent(), mouseEvent.getPoint(), component);
    showPopup(component, point);
}
 
Example 8
Source Project: netbeans   File: RendererPanel.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getToolTipText(MouseEvent event) {
    Component c = SwingUtilities.getDeepestComponentAt(this, event.getX(), event.getY());
    if (c instanceof JComponent) {
        JComponent jc = (JComponent) c;
        String tooltip = jc.getToolTipText();
        if (null != tooltip) {
            return tooltip;
        }
    }
    return super.getToolTipText(event);
}
 
Example 9
Source Project: chipster   File: EditableHeaderUI.java    License: MIT License 5 votes vote down vote up
private void setDispatchComponent(MouseEvent e) { 
	Component editorComponent = header.getEditorComponent();
	Point p = e.getPoint();
	Point p2 = SwingUtilities.convertPoint(header, p, editorComponent);
	dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, 
			p2.x, p2.y);
}
 
Example 10
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 11
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 12
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 13
Source Project: gcs   File: MouseCapture.java    License: Mozilla Public License 2.0 5 votes vote down vote up
private void redispatchMouseEvent(MouseEvent event) {
    Point     glassPanePoint = event.getPoint();
    Point     containerPoint = SwingUtilities.convertPoint(mGlassPane, glassPanePoint, mCaptureComponent);
    Component component      = SwingUtilities.getDeepestComponentAt(mCaptureComponent, containerPoint.x, containerPoint.y);
    if (component != null) {
        Point componentPoint = SwingUtilities.convertPoint(mGlassPane, glassPanePoint, component);
        component.dispatchEvent(new MouseEvent(component, event.getID(), event.getWhen(), event.getModifiersEx(), componentPoint.x, componentPoint.y, event.getClickCount(), event.isPopupTrigger()));
    }
}
 
Example 14
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 15
private void updateClientCursor() {
    Point p = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(p, this);
    Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
    if (target != null) {
        content.setCursor(target.getCursor());
    }
}
 
Example 16
private void setDispatchComponent(MouseEvent e) {
	Component editorComponent = header.getEditorComponent();
	Point p = e.getPoint();
	Point p2 = SwingUtilities.convertPoint(header, p, editorComponent);
	dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, p2.x, p2.y);
}
 
Example 17
Source Project: netbeans   File: AbstractListUI.java    License: Apache License 2.0 4 votes vote down vote up
private boolean redispatchComponent(MouseEvent e) {
    Point p = e.getPoint();
    int index = list.locationToIndex(p);
    if (index < 0 || index >= list.getModel().getSize()) {
        return false;
    }

    ListCellRenderer renderer = list.getCellRenderer();
    if (null == renderer) {
        return false;
    }
    Component renComponent = renderer.getListCellRendererComponent(list, list.getModel().getElementAt(index), index, false, false);
    if (null == renComponent) {
        return false;
    }
    Rectangle rect = list.getCellBounds(index, index);
    if (null == rect) {
        return false;
    }
    renComponent.setBounds(0, 0, rect.width, rect.height);
    renComponent.doLayout();
    Point p3 = rect.getLocation();

    Point p2 = new Point(p.x - p3.x, p.y - p3.y);
    Component dispatchComponent =
            SwingUtilities.getDeepestComponentAt(renComponent,
            p2.x, p2.y);
    if ( e.isPopupTrigger() &&
         dispatchComponent instanceof LinkButton && 
         !((LinkButton)dispatchComponent).isHandlingPopupEvents() ) 
    {
        return false;
    } 
    if (dispatchComponent instanceof AbstractButton) {
        if (!((AbstractButton) dispatchComponent).isEnabled()) {
            return false;
        }
        Point p4 = SwingUtilities.convertPoint(renComponent, p2, dispatchComponent);
        MouseEvent newEvent = new MouseEvent(dispatchComponent,
                e.getID(),
                e.getWhen(),
                e.getModifiers(),
                p4.x, p4.y,
                e.getClickCount(),
                e.isPopupTrigger(),
                MouseEvent.NOBUTTON);
        dispatchComponent.dispatchEvent(newEvent);
        list.repaint(rect);
        e.consume();
        return true;
    }
    return false;
}
 
Example 18
public static Component findComponentUnderMouse() {
    Window window = findWindow();
    Point location = MouseInfo.getPointerInfo().getLocation();
    SwingUtilities.convertPointFromScreen(location, window);
    return SwingUtilities.getDeepestComponentAt(window, location.x, location.y);
}
 
Example 19
Source Project: ghidra   File: AbstractDockingTest.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Clicks the JComponent at the given point from within the given provider.
 *
 * @param provider The provider to be clicked.
 * @param button The mouse button to use (left, center, right)
 * @param x the x location of the click
 * @param y the y location of the click
 * @param clickCount the number of times to click
 * @param modifiers the modifiers to apply (Ctrl, Alt, etc; 0 is none)
 * @param popupTrigger true if this click should show a popup menu
 * @return the actual Java JComponent that was clicked
 */
public static Component clickComponentProvider(ComponentProvider provider, int button, int x,
		int y, int clickCount, int modifiers, boolean popupTrigger) {

	JComponent component = provider.getComponent();
	final Component clickComponent = SwingUtilities.getDeepestComponentAt(component, x, y);
	clickMouse(clickComponent, MouseEvent.BUTTON1, x, y, clickCount, modifiers, popupTrigger);
	return clickComponent;
}
 
Example 20
/**
 * Returns <code>true</code> if the given {@link MouseEvent} only exited to child components of
 * the specified parent {@link Component}; <code>false</code> otherwise. This fixes the problem
 * that Swing triggers MouseExited events when moving the mouse for example over a button inside
 * the panel on which the mouse listener is.
 *
 * @param parent
 * @param e
 * @return
 */
public static boolean isMouseEventExitedToChildComponents(final Component parent, final MouseEvent e) {
	if (parent == null) {
		throw new IllegalArgumentException("parent must not be null!");
	}

	return SwingUtilities.getDeepestComponentAt(parent, e.getX(), e.getY()) != null;
}