Example usage for java.awt.event MouseEvent MouseEvent

List of usage examples for java.awt.event MouseEvent MouseEvent

Introduction

In this page you can find the example usage for java.awt.event MouseEvent MouseEvent.

Prototype

public MouseEvent(Component source, int id, long when, int modifiers, int x, int y, int clickCount,
        boolean popupTrigger) 

Source Link

Document

Constructs a MouseEvent object with the specified source component, type, modifiers, coordinates, click count, and popupTrigger flag.

Usage

From source file:com.jcraft.weirdx.DDXWindowImp.java

@SuppressWarnings("unused")
public void mouseDragged(MouseEvent e) {

    if (threeButton) {
        if (threeBstate != s) {
            if (threeBstate == sp) {
                procPressed(threeBPressed);
                threeBPressed = null;//from  ww  w .ja  v a2  s  .c om
                threeBstate = s;
            } else if (threeBstate == spp) {
                e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(),
                        (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK)))
                                | InputEvent.BUTTON2_MASK,
                        e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger());
            } else if (threeBstate == sppr) {
                return;
            }
        }
    }

    if (window == null)
        return;

    // calc abs cursor position use old window position for calculation
    // as mouseDragged (if you use Panel) delivers its coordinates relative to the position after mousepressed
    // UPDATE: this was a bug of the IBM JDK
    //    int x=e.getX()+oldwindowx;
    //    int y=e.getY()+oldwindowy;
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    // set new drag position (absolute)
    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();

    // button 1 -> 16
    // button 2 -> 8
    // button 3 -> 4
    // shift -> 1
    // control -> 2
    // alt -> 12 ?? 

    int state = 0;
    int detail = 0;

    if ((mod & InputEvent.BUTTON1_MASK) != 0) {
        state |= (1 << 8);
        detail = 1;
    }
    if ((mod & InputEvent.BUTTON2_MASK) != 0) {
        state |= (1 << 9);
        detail = 2;
    }
    if ((mod & InputEvent.BUTTON3_MASK) != 0) {
        state |= (1 << 10);
        detail = 3;
    }
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    XWindow.sprite.hot.state = state;

    px = x;
    py = y;

    event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py, e.getX(), e.getY(), state,
            1);

    try {
        if (!XWindow.checkMotion(event, window)) {
            return;
        }
        event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py,
                px - XWindow.sprite.win.x, py - XWindow.sprite.win.y, state, 1);
        if (XWindow.grab != null) {
            XWindow.sendGrabbedEvent(event, false, 1);
        } else {
            XWindow.sendDeviceEvent(XWindow.sprite.win, event, XWindow.grab, null, 1);
        }
    } catch (Exception ee) {
    }
}

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JPasswordField createPasswordField(DocumentListener... docListeners) {
    final JPasswordField field = new JPasswordField();
    final Border oldBorder = field.getBorder();
    if (docListeners != null) {
        for (DocumentListener docListener : docListeners) {
            field.getDocument().addDocumentListener(docListener);
            field.getDocument().putProperty("owner", field);
        }/*  w  ww.  j a  va  2  s.  c  o  m*/
    }
    final InputVerifier verifier = new InputVerifier() {
        @Override
        public boolean verify(final JComponent input) {
            final JPasswordField field = (JPasswordField) input;
            char[] txt = field.getPassword();
            if (txt.length == 0) {
                // Run in EDT to avoid deadlock in case this gets called
                // from not swing thread
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        field.setToolTipText(UILabels.STL50084_CANT_BE_BLANK.getDescription());
                        input.setBackground(UIConstants.INTEL_LIGHT_RED);
                        input.setBorder(BorderFactory.createLineBorder(UIConstants.INTEL_RED, 2));
                        // show tooltip immediately
                        ToolTipManager.sharedInstance()
                                .mouseMoved(new MouseEvent(field, 0, 0, 0, 0, 0, 0, false));
                    }
                });
                return false;
            } else {
                Util.runInEDT(new Runnable() {
                    @Override
                    public void run() {
                        input.setBackground(UIConstants.INTEL_WHITE);
                        input.setBorder(oldBorder);
                    }
                });
                return true;
            }
        }

    };

    DocumentListener dynamicChecker = new DocumentListener() {

        @Override
        public void insertUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            verifier.verify(field);
        }

    };
    field.getDocument().addDocumentListener(dynamicChecker);

    // Add the input verifier
    field.setInputVerifier(verifier);

    return field;
}

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

/**
 * Triggers a click event on the views in the current selection
 * @return this/*ww w  . j a  v a2  s.c  om*/
 */
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  www.j av  a  2  s .  c  o m*/
 */
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;
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Shuffle" selection.//from www .ja v a 2 s  .  c  om
 */
public void pressShuffle() {
    final MouseEvent smevt = new MouseEvent(this, MouseEvent.MOUSE_RELEASED, 0, 1, 0, 0, 1, false);
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acShuffle.processEvent(smevt);
            return null;
        }
    });
}

From source file:javazoom.jlgui.player.amp.PlayerApplet.java

/**
 * Simulates "Repeat" selection.//from w ww  .  j a va2 s. c om
 */
public void pressRepeat() {
    final MouseEvent rmevt = new MouseEvent(this, MouseEvent.MOUSE_RELEASED, 0, 1, 0, 0, 1, false);
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            acRepeat.processEvent(rmevt);
            return null;
        }
    });
}