Java Swing Mouse delegateEventToParent(Component component, MouseEvent e)

Here you can find the source of delegateEventToParent(Component component, MouseEvent e)

Description

Sends event to parent in it's coordinate space.

License

Open Source License

Parameter

Parameter Description
component component to get parent from.
e event to send.

Declaration

public static void delegateEventToParent(Component component, MouseEvent e) 

Method Source Code


//package com.java2s;
// the terms of the GNU General Public License as published by the Free Software Foundation;

import javax.swing.*;

import java.awt.*;

import java.awt.event.MouseEvent;

public class Main {
    /**/*from   w w w. j  a v a2 s  .  c o m*/
     * Sends event to parent in it's coordinate space.
     *
     * @param component component to get parent from.
     * @param e         event to send.
     */
    public static void delegateEventToParent(Component component, MouseEvent e) {
        delegateEventToParent(component, e, false);
    }

    /**
     * Sends event to parent in it's coordinate space (if <code>direct</code> isn't set).
     *
     * @param component component to get parent from.
     * @param e         event to send.
     * @param direct    <code>TRUE</code> for direct delegation (no conversion to parent coord. space).
     */
    public static void delegateEventToParent(Component component, MouseEvent e, boolean direct) {
        Component parent = component.getParent();
        delegateEventToParent(component, parent, e, direct);
    }

    /**
     * Sends event to parent in it's coordinate space (if <code>direct</code> isn't set).
     *
     * @param component component to get parent from.
     * @param parent    parent component.
     * @param e         event to send.
     * @param direct    <code>TRUE</code> for direct delegation (no conversion to parent coord. space).
     */
    public static void delegateEventToParent(Component component, Component parent, MouseEvent e, boolean direct) {
        if (parent != null) {
            if (direct) {
                e = new MouseEvent(component, e.getID(), e.getWhen(), e.getModifiers(), e.getX(), e.getY(),
                        e.getClickCount(), e.isPopupTrigger(), e.getButton());
            } else {
                Point point = e.getPoint();
                SwingUtilities.convertPointToScreen(point, component);
                SwingUtilities.convertPointFromScreen(point, parent);
                e = new MouseEvent(parent, e.getID(), e.getWhen(), e.getModifiers(), (int) point.getX(),
                        (int) point.getY(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
            }

            parent.dispatchEvent(e);
        }
    }

    /**
     * Sends event to parent.
     *
     * @param component component to get parent from.
     * @param e         event to send.
     */
    public static void delegateEventToParent(Component component, AWTEvent e) {
        Component parent = component.getParent();
        if (parent != null)
            parent.dispatchEvent(e);
    }
}

Related

  1. convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination)
  2. convertMouseEvent(java.awt.Component source, java.awt.event.MouseEvent sourceEvent, java.awt.Component destination)
  3. convertPoint(MouseEvent evt, Component target)
  4. createButton(JComponent parent, String description, MouseListener listener)
  5. decorateComponentWithMouseOverCursorChange(final JComponent toDecorate, final int mouseEntered, final int mouseExited)
  6. disableDoubleMouseClick(Component c)
  7. forwardMouseWheelEvent(JScrollPane target, MouseWheelEvent evt)
  8. getDeepestComponentAt(final MouseEvent aEvent)
  9. inInsets(MouseEvent me)