Example usage for java.awt Component getMouseListeners

List of usage examples for java.awt Component getMouseListeners

Introduction

In this page you can find the example usage for java.awt Component getMouseListeners.

Prototype

public synchronized MouseListener[] getMouseListeners() 

Source Link

Document

Returns an array of all the mouse listeners registered on this component.

Usage

From source file:Main.java

/**
 * Inserts the mouse listener at the particular index in the listeners' chain.
 *
 * @param component/*from  ww  w  . ja v  a 2 s. c o  m*/
 * @param l
 * @param index
 */
public static void insertMouseListener(Component component, MouseListener l, int index) {
    MouseListener[] listeners = component.getMouseListeners();

    for (MouseListener listener : listeners) {
        component.removeMouseListener(listener);
    }

    for (int i = 0; i < listeners.length; i++) {
        MouseListener listener = listeners[i];

        if (index == i) {
            component.addMouseListener(l);
        }

        component.addMouseListener(listener);
    }

    // inex is too large, add to the end.
    if (index > listeners.length - 1) {
        component.addMouseListener(l);
    }
}

From source file:Main.java

public static Map<Component, List<MouseListener>> storeMouseListeners(final JComponent root) {
    final Map<Component, List<MouseListener>> map = new HashMap<Component, List<MouseListener>>();
    for (final Component c : getAllSubComponents(root)) {
        map.put(c, new ArrayList<MouseListener>());
        for (final MouseListener m : c.getMouseListeners()) {
            c.removeMouseListener(m);//from w  ww. ja v a  2  s.  c o m
            map.get(c).add(m);
        }
    }
    return map;
}

From source file:Main.java

/**
 * Remove mouse listeners form the argument component.
 * //w w  w  .j  a  v  a 2  s. c om
 * @param cmp The component.
 */
public static void removeMouseListeners(Component cmp) {
    MouseListener[] listeners = cmp.getMouseListeners();
    if (listeners != null) {
        for (MouseListener listener : listeners) {
            cmp.removeMouseListener(listener);
        }
    }
}

From source file:org.nuclos.client.ui.collect.component.CollectableComboBox.java

private static void removeAllJPopupMenuListeners(Component comp) {
    for (MouseListener ml : comp.getMouseListeners()) {
        if (ml instanceof JPopupMenuListener) {
            comp.removeMouseListener(ml);
        }//from  w w  w.java  2  s  .c  o  m
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Removes the Mouse Listeners./*from   w  w w  .  j  a va2 s .  c om*/
 * @param c component
 */
public static void removeMouseListeners(final Component c) {
    if (c != null) {
        for (MouseListener l : c.getMouseListeners()) {
            c.removeMouseListener(l);
        }
        for (MouseMotionListener l : c.getMouseMotionListeners()) {
            c.removeMouseMotionListener(l);
        }
    }
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Triggers a click event on the views in the current selection
 * @return this// w ww.  j  av a 2 s  .c o m
 */
public $ click() {
    for (Component view : this.views) {
        for (MouseListener ml : view.getMouseListeners()) {
            ml.mousePressed(new MouseEvent(view, 0, 0, 0, view.getWidth() / 2, view.getHeight() / 2, 1, false));
        }
    }
    return this;
}

From source file:self.philbrown.javaQuery.$.java

/**
 * Triggers a long-click event on this each view in the current selection
 * @return this//from  w w  w .j a  va 2s .c  om
 */
public $ dblclick() {
    for (Component view : this.views) {
        for (MouseListener ml : view.getMouseListeners()) {
            ml.mousePressed(new MouseEvent(view, 0, 0, 0, view.getWidth() / 2, view.getHeight() / 2, 2, false));
        }
    }
    return this;
}