Example usage for com.google.gwt.dom.client NativeEvent BUTTON_LEFT

List of usage examples for com.google.gwt.dom.client NativeEvent BUTTON_LEFT

Introduction

In this page you can find the example usage for com.google.gwt.dom.client NativeEvent BUTTON_LEFT.

Prototype

int BUTTON_LEFT

To view the source code for com.google.gwt.dom.client NativeEvent BUTTON_LEFT.

Click Source Link

Document

The left mouse button.

Usage

From source file:com.ait.lienzo.client.core.event.AbstractNodeMouseEvent.java

License:Open Source License

public static final boolean isButtonLeft(final MouseEvent<?> event) {
    if (null != event) {
        if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
            return true;
        }//from  ww w  .  j av  a  2s.com
    }
    return false;
}

From source file:com.ait.lienzo.client.core.shape.wires.SelectionManager.java

License:Open Source License

private static boolean isButtonLeft(MouseEvent<? extends EventHandler> event) {
    return event.getNativeButton() == NativeEvent.BUTTON_LEFT;
}

From source file:com.ait.lienzo.client.widget.panel.impl.LienzoPanelHandlerManager.java

License:Open Source License

/**
 * Stores state of pressed mouse button/*from   w w w .j  av a 2  s . c o  m*/
 *
 * @param nativeButtonCode
 */
private void checkPressedMouseButton(final int nativeButtonCode) {
    m_mouse_button_left = nativeButtonCode == NativeEvent.BUTTON_LEFT;
    m_mouse_button_middle = nativeButtonCode == NativeEvent.BUTTON_MIDDLE;
    m_mouse_button_right = nativeButtonCode == NativeEvent.BUTTON_RIGHT;
}

From source file:com.akjava.gwt.threetest.client.BoxDemo.java

License:Apache License

@Override
public void onMouseMove(MouseMoveEvent event) {
    super.onMouseMove(event);
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT && mouseDown) {
        int diffX = event.getX() - mouseDownX;
        int diffY = event.getY() - mouseDownY;
        mouseDownX = event.getX();//from   www.  j  a  va  2s .  c o m
        mouseDownY = event.getY();

        cameraControle.incrementRotationX(diffY);
        cameraControle.incrementRotationY(diffX);
    }
}

From source file:com.alkacon.geranium.client.dnd.DNDHandler.java

License:Open Source License

/**
 * @see com.google.gwt.event.dom.client.MouseDownHandler#onMouseDown(com.google.gwt.event.dom.client.MouseDownEvent)
 *///from  w  ww .ja  v  a 2  s  .  co m
public void onMouseDown(MouseDownEvent event) {

    if ((event.getNativeButton() != NativeEvent.BUTTON_LEFT) || m_dragging || (m_currentAnimation != null)) {
        // only act on left button down, ignore right click
        // also ignore if the dragging flag is still true or an animation is still running
        return;
    }
    Object source = event.getSource();
    if (!(source instanceof I_DragHandle)) {
        // source is no drag handle, wrong DNDHandler assignment ignore
        return;
    }
    I_DragHandle dragHandle = (I_DragHandle) source;
    m_draggable = dragHandle.getDraggable();
    if (m_draggable == null) {
        // cancel dragging
        return;
    }
    m_clientX = event.getClientX();
    m_clientY = event.getClientY();
    m_cursorOffsetX = DomUtil.getRelativeX(m_clientX, m_draggable.getElement());
    m_cursorOffsetY = DomUtil.getRelativeY(m_clientY, m_draggable.getElement());
    m_startLeft = m_draggable.getElement().getAbsoluteLeft();
    m_startTop = m_draggable.getElement().getAbsoluteTop();
    m_currentTarget = m_draggable.getParentTarget();
    m_dragHelper = m_draggable.getDragHelper(m_currentTarget);
    m_placeholder = m_draggable.getPlaceholder(m_currentTarget);
    // notifying controller, if false is returned, dragging will be canceled
    if (!m_controller.onDragStart(m_draggable, m_currentTarget, this)) {
        cancel();
        return;
    }
    m_draggable.onStartDrag(m_currentTarget);
    m_dragging = true;
    // add marker css class to enable drag and drop dependent styles
    Document.get().getBody().addClassName(
            com.alkacon.geranium.client.ui.css.I_LayoutBundle.INSTANCE.dragdropCss().dragStarted());
    if (m_previewHandlerRegistration != null) {
        // this should never be the case
        DebugLog.getInstance().printLine("Preview handler already registered!!!");
        m_previewHandlerRegistration.removeHandler();

    }
    DebugLog.getInstance().printLine("Registering preview handler");
    m_previewHandlerRegistration = Event.addNativePreviewHandler(m_previewHandler);
    onMove((Event) event.getNativeEvent());
}

From source file:com.alkacon.geranium.client.ui.AreaSelectPanel.java

License:Open Source License

/**
 * @see com.google.gwt.event.dom.client.MouseDownHandler#onMouseDown(com.google.gwt.event.dom.client.MouseDownEvent)
 *//* w w w. ja  v  a  2 s  .c o  m*/
public void onMouseDown(MouseDownEvent event) {

    if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        // only act on left button down, ignore right click
        return;
    }
    cacheElementSize();
    switch (m_state) {
    case EMPTY:
        DOM.setCapture(getElement());
        m_state = State.SELECTING;
        m_firstX = event.getRelativeX(getElement());
        m_firstY = event.getRelativeY(getElement());
        m_currentSelection = new PositionBean();
        setSelectPosition(m_firstX, m_firstY, 0, 0);
        showSelect(true);

        break;
    case SELECTED:

        m_firstX = event.getRelativeX(getElement());
        m_firstY = event.getRelativeY(getElement());
        if (m_mouseOverArea == null) {
            // mouse not over selection, remove selection
            clearSelection();
            fireChangeEvent(true);
            break;
        }
        switch (m_mouseOverArea) {
        case BORDER_TOP:
            m_state = State.RESIZE_HEIGHT;

            // fixing opposite border
            m_firstX = m_currentSelection.getLeft();
            m_firstY = m_currentSelection.getTop() + m_currentSelection.getHeight();
            break;
        case BORDER_BOTTOM:
            m_state = State.RESIZE_HEIGHT;

            // fixing opposite border                        
            m_firstX = m_currentSelection.getLeft();
            m_firstY = m_currentSelection.getTop();
            break;
        case BORDER_LEFT:
            m_state = State.RESIZE_WIDTH;

            // fixing opposite border
            m_firstX = m_currentSelection.getLeft() + m_currentSelection.getWidth();
            m_firstY = m_currentSelection.getTop();
            break;
        case BORDER_RIGHT:
            m_state = State.RESIZE_WIDTH;

            // fixing opposite border
            m_firstX = m_currentSelection.getLeft();
            m_firstY = m_currentSelection.getTop();
            break;
        case CENTER:
            m_state = State.DRAGGING;
            m_moveOffsetX = m_firstX - m_currentSelection.getLeft();
            m_moveOffsetY = m_firstY - m_currentSelection.getTop();
            break;
        case CORNER_BOTTOM_LEFT:
            m_state = State.SELECTING;

            // fixing opposite corner
            m_firstX = m_currentSelection.getLeft() + m_currentSelection.getWidth();
            m_firstY = m_currentSelection.getTop();
            break;
        case CORNER_BOTTOM_RIGHT:
            m_state = State.SELECTING;
            // fixing opposite corner
            m_firstX = m_currentSelection.getLeft();
            m_firstY = m_currentSelection.getTop();
            break;
        case CORNER_TOP_LEFT:
            m_state = State.SELECTING;

            // fixing opposite corner
            m_firstX = m_currentSelection.getLeft() + m_currentSelection.getWidth();
            m_firstY = m_currentSelection.getTop() + m_currentSelection.getHeight();
            break;
        case CORNER_TOP_RIGHT:
            m_state = State.SELECTING;

            // fixing opposite corner
            m_firstX = m_currentSelection.getLeft();
            m_firstY = m_currentSelection.getTop() + m_currentSelection.getHeight();
            break;
        default:
        }
        DOM.setCapture(getElement());

        break;
    case DRAGGING:
    case RESIZE_HEIGHT:
    case RESIZE_WIDTH:
    case SELECTING:
    default:
        // Messed up selection state.
        // May happen if mouse-cursor was moved outside the window or frame while button pressed and button was released outside.
        if (m_currentSelection != null) {
            m_state = State.SELECTED;
            fireChangeEvent(true);
        } else {
            // this should never happen
            clearSelection();
        }
    }

    event.preventDefault();
    event.stopPropagation();
}

From source file:com.allen_sauer.gwt.dnd.client.MouseDragHandler.java

License:Apache License

@Override
public void onMouseDown(MouseDownEvent event) {
    // *******************************************************************
    // Note: the draggable (or its draghandle) receives mouse down events,
    // but the capturing widget will receive mouse move/up events.
    // *******************************************************************
    if (dragging == ACTIVELY_DRAGGING || dragging == DRAGGING_NO_MOVEMENT_YET) {
        // Ignore additional mouse buttons depressed while still dragging
        return;/*from ww  w .  j ava 2  s. com*/
    }

    Widget sender = (Widget) event.getSource();
    int x = event.getX();
    int y = event.getY();

    int button = event.getNativeButton();

    if (button != NativeEvent.BUTTON_LEFT) {
        return;
    }

    if (mouseDownWidget != null) {
        // For multiple overlapping draggable widgets, ignore all but first onMouseDown
        return;
    }

    // mouse down (not first mouse move) determines draggable widget
    mouseDownWidget = sender;
    context.draggable = dragHandleMap.get(mouseDownWidget).getDragable();
    assert context.draggable != null;

    if (!toggleKey(event) && !context.selectedWidgets.contains(context.draggable)) {
        context.dragController.clearSelection();
        context.dragController.toggleSelection(context.draggable);
    }

    // prevent browser image dragging in Firefox et al.
    if (mouseDownWidget instanceof Image) {
        event.preventDefault();
    }

    mouseDownOffsetX = x;
    mouseDownOffsetY = y;
    WidgetLocation loc1 = new WidgetLocation(mouseDownWidget, null);
    if (mouseDownWidget != context.draggable) {
        WidgetLocation loc2 = new WidgetLocation(context.draggable, null);
        mouseDownOffsetX += loc1.getLeft() - loc2.getLeft();
        mouseDownOffsetY += loc1.getTop() - loc2.getTop();
    }
    if (context.dragController.getBehaviorDragStartSensitivity() == 0 && !toggleKey(event)) {
        // set context.mouseX/Y before startDragging() is called
        context.mouseX = x + loc1.getLeft();
        context.mouseY = y + loc1.getTop();
        startDragging();
        if (dragging == NOT_DRAGGING) {
            return;
        }
        actualMove(context.mouseX, context.mouseY);
    } else {
        mouseDownPageOffsetX = mouseDownOffsetX + loc1.getLeft();
        mouseDownPageOffsetY = mouseDownOffsetY + loc1.getTop();
        startCapturing();
    }
}

From source file:com.allen_sauer.gwt.dnd.client.MouseDragHandler.java

License:Apache License

@Override
public void onMouseUp(MouseUpEvent event) {
    // *******************************************************************
    // Note: the draggable (or its draghandle) receives mouse down events,
    // but the capturing widget will receive mouse move/up events.
    // *******************************************************************
    Widget sender = (Widget) event.getSource();
    Element elem = sender.getElement();
    // TODO optimize for the fact that elem is at (0,0)
    int x = event.getRelativeX(elem);
    int y = event.getRelativeY(elem);

    int button = event.getNativeButton();
    if (button != NativeEvent.BUTTON_LEFT) {
        return;/*from  w  w w  . j a  v  a 2 s .  c o m*/
    }

    // in case mouse down occurred elsewhere
    if (mouseDownWidget == null) {
        return;
    }

    try {
        if (dragging == NOT_DRAGGING) {
            doSelectionToggle(event);
            return;
        }

        // Proceed with the drop
        try {
            synthesizeAsyncMouseUp(event);
            drop(x, y);
            if (dragging != ACTIVELY_DRAGGING) {
                doSelectionToggle(event);
            }
        } finally {
            dragEndCleanup();
        }
    } finally {
        mouseDownWidget = null;
        dragEndCleanup();
    }
}

From source file:com.appkit.interactions.client.dnd.MouseDragHandler.java

License:Apache License

@Override
public void onMouseDown(MouseDownEvent event) {

    event.preventDefault();/*w  w  w .  j  a v  a2s  .c o m*/

    // *******************************************************************
    // Note: the draggable (or its draghandle) receives mouse down events,
    // but the capturing widget will receive mouse move/up events.
    // *******************************************************************
    if (dragging == ACTIVELY_DRAGGING || dragging == DRAGGING_NO_MOVEMENT_YET) {
        // Ignore additional mouse buttons depressed while still dragging
        return;
    }

    //RootPanel.getBodyElement().getStyle().setCursor(Style.Cursor.MOVE);

    Widget sender = (Widget) event.getSource();

    int x = event.getX();
    int y = event.getY();

    int button = event.getNativeButton();

    if (button != NativeEvent.BUTTON_LEFT) {
        return;
    }

    if (mouseDownWidget != null) {
        // For multiple overlapping draggable widgets, ignore all but first onMouseDown
        return;
    }

    // mouse down (not first mouse move) determines draggable widget
    mouseDownWidget = sender;
    context.draggable = dragHandleMap.get(mouseDownWidget).getDragable();
    //assert context.draggable != null;

    if (!toggleKey(event) && !context.selectedWidgets.contains(context.draggable)) {
        context.dragController.clearSelection();
        context.dragController.toggleSelection(context.draggable);
    }

    mouseDownOffsetX = x;
    mouseDownOffsetY = y;
    WidgetLocation loc1 = new WidgetLocation(mouseDownWidget, null);
    if (mouseDownWidget != context.draggable) {
        WidgetLocation loc2 = new WidgetLocation(context.draggable, null);
        mouseDownOffsetX += loc1.getLeft() - loc2.getLeft();
        mouseDownOffsetY += loc1.getTop() - loc2.getTop();
    }
    if (context.dragController.getBehaviorDragStartSensitivity() == 0 && !toggleKey(event)) {
        // set context.mouseX/Y before startDragging() is called
        context.mouseX = x + loc1.getLeft();
        context.mouseY = y + loc1.getTop();
        startDragging();
        if (dragging == NOT_DRAGGING) {
            return;
        }
        actualMove(context.mouseX, context.mouseY);
    }
    /* else {
    mouseDownPageOffsetX = mouseDownOffsetX + loc1.getLeft();
    mouseDownPageOffsetY = mouseDownOffsetY + loc1.getTop();
    startCapturing();
    } */
}

From source file:com.appkit.interactions.client.dnd.MouseDragHandler.java

License:Apache License

@Override
public void onMouseUp(MouseUpEvent event) {
    // *******************************************************************
    // Note: the draggable (or its draghandle) receives mouse down events,
    // but the capturing widget will receive mouse move/up events.
    // *******************************************************************
    Widget sender = (Widget) event.getSource();
    Element elem = sender.getElement();
    // TODO optimize for the fact that elem is at (0,0)
    int x = event.getRelativeX(elem);
    int y = event.getRelativeY(elem);

    RootPanel.getBodyElement().getStyle().setCursor(Style.Cursor.DEFAULT);

    int button = event.getNativeButton();
    if (button != NativeEvent.BUTTON_LEFT) {
        return;//from   ww w .  ja v a  2  s .com
    }

    // in case mouse down occurred elsewhere
    if (mouseDownWidget == null) {
        return;
    }

    try {
        if (dragging == NOT_DRAGGING) {
            doSelectionToggle(event);
            return;
        }

        // Proceed with the drop
        try {
            synthesizeAsyncMouseUp(event);
            drop(x, y);
            if (dragging != ACTIVELY_DRAGGING) {
                doSelectionToggle(event);
            }
        } finally {
            dragEndCleanup();
        }
    } finally {
        mouseDownWidget = null;
        dragEndCleanup();
    }
}