Example usage for java.awt Component addMouseListener

List of usage examples for java.awt Component addMouseListener

Introduction

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

Prototype

public synchronized void addMouseListener(MouseListener l) 

Source Link

Document

Adds the specified mouse listener to receive mouse events from this component.

Usage

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

/**
 * Invokes the given Function for click events on each view in the current selection. 
 * The function will receive two arguments:
 * <ol>//  w w w  .j ava 2  s  .  c  om
 * <li>a javaQuery containing the clicked view
 * <li>{@code eventData}
 * </ol>
 * @param eventData the second argument to pass to the {@code function}
 * @param function the function to invoke
 * @return
 */
public $ click(final Object eventData, final Function function) {
    for (final Component view : this.views) {
        view.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                function.invoke($.with(view), eventData);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

        });
    }
    return this;
}

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

/**
 * Invokes the given Function every time each view in the current selection is long-clicked. 
 * The only parameter passed to the given function a javaQuery instance with the long-clicked view.
 * @param function the function to call when this view is long-clicked
 * @return this/* w  ww  .  j a  va 2 s  .c om*/
 */
public $ dblclick(final Function function) {
    for (final Component view : this.views) {
        view.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2)
                    function.invoke($.with(view));
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

        });
    }
    return this;
}

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

/**
 * Invokes the given Function for long-click events on the views in the current selection. 
 * The function will receive two arguments:
 * <ol>//from  w w w .ja v  a 2 s .  co  m
 * <li>a javaQuery containing the long-clicked view
 * <li>{@code eventData}
 * </ol>
 * @param eventData the second argument to pass to the {@code function}
 * @param function the function to invoke
 * @return
 */
public $ dblclick(final Object eventData, final Function function) {
    for (final Component view : this.views) {
        view.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2)
                    function.invoke($.with(view), eventData);
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

        });
    }
    return this;
}

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

/**
 * Refreshes the listeners for swipe events
 *//*from  ww  w.  j  a v a2 s . c om*/
private void setupSwipeListener() {
    for (Component view : views) {
        view.addMouseListener(new SwipeDetector(view, new SwipeListener() {

            @Override
            public void onUpSwipe(Component v) {
                if (swipeUp != null) {
                    swipeUp.invoke($.with(v));
                } else if (swipe != null) {
                    swipe.invoke($.with(v), SwipeDetector.Direction.UP);
                }
            }

            @Override
            public void onRightSwipe(Component v) {
                if (swipeRight != null) {
                    swipeRight.invoke($.with(v));
                } else if (swipe != null) {
                    swipe.invoke($.with(v), SwipeDetector.Direction.RIGHT);
                }
            }

            @Override
            public void onLeftSwipe(Component v) {
                if (swipeLeft != null) {
                    swipeLeft.invoke($.with(v));
                } else if (swipe != null) {
                    swipe.invoke($.with(v), SwipeDetector.Direction.LEFT);
                }
            }

            @Override
            public void onDownSwipe(Component v) {
                if (swipeDown != null) {
                    swipeDown.invoke($.with(v));
                } else if (swipe != null) {
                    swipe.invoke($.with(v), SwipeDetector.Direction.DOWN);
                }
            }

            @Override
            public void onStartSwipe(Component v) {
                if (swipe != null) {
                    swipe.invoke($.with(v), SwipeDetector.Direction.START);
                }
            }

            @Override
            public void onStopSwipe(Component v) {
                if (swipe != null) {
                    swipe.invoke($.with(v), SwipeDetector.Direction.STOP);
                }
            }

        }));
    }
}

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

/**
 * Invokes the given Function every time each view in the current selection is clicked. The only 
 * parameter passed to the given function is a javaQuery instance containing the clicked view
 * @param function the function to call when this view is clicked
 * @return this/*from  ww  w.j a  v  a2s . c  o  m*/
 */
public $ click(final Function function) {
    for (final Component view : this.views) {
        if (view instanceof AbstractButton) {
            ((AbstractButton) view).addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent event) {
                    function.invoke($.with(view));
                }

            });
        } else {
            view.addMouseListener(new MouseListener() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    function.invoke($.with(view));
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseReleased(MouseEvent e) {
                }

            });
        }

    }
    return this;
}