Java Code Examples for com.google.gwt.user.client.Event#setCapture()

The following examples show how to use com.google.gwt.user.client.Event#setCapture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DateCell.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
    if (event.getNativeButton() == NativeEvent.BUTTON_LEFT) {
        Element e = Element.as(event.getNativeEvent().getEventTarget());
        if (e.getClassName().contains("reserved") || isDisabled()
                || !weekgrid.getParentCalendar().isRangeSelectAllowed()) {
            eventRangeStart = -1;
        } else {
            eventRangeStart = event.getY();
            eventRangeStop = eventRangeStart;
            Event.setCapture(getElement());
            setFocus(true);
        }
    }
}
 
Example 2
Source File: SimpleDayCell.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
public void startCalendarItemDrag(MouseDownEvent event, final MonthItemLabel label) {

        moveRegistration = addMouseMoveHandler(this);
        startX = event.getClientX();
        startY = event.getClientY();
        startYrelative = event.getRelativeY(label.getParent().getElement())
                % getHeigth();
        startXrelative = event.getRelativeX(label.getParent().getElement())
                % getWidth();

        CalendarItem e = getItemByWidget(label);
        dndSourceDateFrom = (Date) e.getStart().clone();
        dndSourceDateTo = (Date) e.getEnd().clone();

        dndSourceStartDateTime = (Date) e.getStartTime().clone();
        dndSourceEndDateTime = (Date) e.getEndTime().clone();

        Event.setCapture(getElement());
        keyDownHandler = addKeyDownHandler(keyDownHandler -> {
            if (keyDownHandler.getNativeKeyCode() == KeyCodes.KEY_ESCAPE) {
                cancelItemDrag(label);
            }
        });

        focus();

        GWT.log("Start drag");
    }
 
Example 3
Source File: PanListener.java    From djvu-html5 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {
	int button = event.getNativeButton();
	if ((button == NativeEvent.BUTTON_LEFT || button == NativeEvent.BUTTON_MIDDLE) && touchId == null) {
		isMouseDown = true;
		x = event.getX();
		y = event.getY();
		event.preventDefault();
		Event.setCapture(widget.getElement());
	}
}
 
Example 4
Source File: SvgArrowWidget.java    From gantt with Apache License 2.0 5 votes vote down vote up
protected void startMoving(NativeEvent event, Element element) {
    if (element.equals(startingPoint)) {
        selectPredecessorMode = true;
        startingPoint.getStyle().setVisibility(Visibility.HIDDEN);
    } else if (element.equals(endingPoint)) {
        selectFollowerMode = true;
        endingPoint.getStyle().setVisibility(Visibility.HIDDEN);
    }
    capturePointScrollTop = getElement().getParentElement()
            .getParentElement().getScrollTop();
    capturePointScrollLeft = getElement().getParentElement()
            .getParentElement().getScrollLeft();
    getParent().getElement().appendChild(movePointElement);
    getElement().getParentElement().addClassName(SELECTION_STYLE_NAME);
    GWT.log("Capturing clicked point.");
    captureElement = getElement();
    Event.setCapture(getElement());
    event.stopPropagation();

    // enable MODE for new predecessor/following step
    // selection.
    addMoveHandler();

    capturePoint = new Point(getTouchOrMouseClientX(event),
            getTouchOrMouseClientY(event));
    originalWidth = width;
    originalHeight = height;
}
 
Example 5
Source File: DateCellDayItem.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
@Override
public void onMouseDown(MouseDownEvent event) {

    startX = event.getClientX();
    startY = event.getClientY();

    if (isDisabled() || event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        return;
    }

    clickTarget = Element.as(event.getNativeEvent().getEventTarget());
    mouseMoveCanceled = false;

    if ((weekGrid.getCalendar().isItemMoveAllowed() && getCalendarItem().isMoveable())
            || (clickTargetsResize() && getCalendarItem().isResizeable())) {

        moveRegistration = addMouseMoveHandler(this);
        setFocus(true);
        try {
            startYrelative = (int) ((double) event.getRelativeY(caption) % slotHeight);
            startXrelative = (event.getRelativeX(weekGrid.getElement())
                    - weekGrid.timebar.getOffsetWidth())
                    % getDateCellWidth();
        } catch (Exception e) {
            GWT.log("Exception calculating relative start position", e);
        }
        mouseMoveStarted = false;
        Style s = getElement().getStyle();
        s.setZIndex(1000);
        startDatetimeFrom = (Date) calendarItem.getStartTime().clone();
        startDatetimeTo = (Date) calendarItem.getEndTime().clone();
        Event.setCapture(getElement());
    }

    // make sure the right cursor is always displayed
    if (clickTargetsResize() && getCalendarItem().isResizeable()) {
        addGlobalResizeStyle();
    }

    /*
     * We need to stop the event propagation or else the WeekGrid range
     * select will kick in
     */
    event.stopPropagation();
    event.preventDefault();
}
 
Example 6
Source File: InputSlider.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void onMouseDown(Event event) {
	this.dragging = true;
	Event.setCapture(InputSlider.this.getElement());
	this.killEvent(event);
	InputSlider.this.handleWidget.moveHandleToPosition(this.getRelativeX(event));
}
 
Example 7
Source File: FinderPanel.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    switch (event.getTypeInt()) {
        case Event.ONMOUSEDOWN:
            mouseDown = true;

  /*
   * Resize glassElem to take up the entire scrollable window area,
   * which is the greater of the scroll size and the client size.
   */
            int width = Math.max(Window.getClientWidth(),
                    Document.get().getScrollWidth());
            int height = Math.max(Window.getClientHeight(),
                    Document.get().getScrollHeight());
            glassElem.getStyle().setHeight(height, Style.Unit.PX);
            glassElem.getStyle().setWidth(width, Style.Unit.PX);
            Document.get().getBody().appendChild(glassElem);

            offset = getEventPosition(event) - getAbsolutePosition();
            Event.setCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEUP:
            mouseDown = false;

            glassElem.removeFromParent();

            // Handle double-clicks.
            // Fake them since the double-click event aren't fired.
            if (this.toggleDisplayAllowed) {
                double now = Duration.currentTimeMillis();
                if (now - this.lastClick < DOUBLE_CLICK_TIMEOUT) {
                    now = 0;
                    toggleCollapsedState();
                }
                this.lastClick = now;
            }

            Event.releaseCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEMOVE:
            if (mouseDown) {
                int size;
                if (reverse) {
                    size = getTargetPosition() + getTargetSize() - getSplitterSize()
                            - getEventPosition(event) + offset;
                } else {
                    size = getEventPosition(event) - getTargetPosition() - offset;
                }
                ((LayoutData) target.getLayoutData()).hidden = false;
                setAssociatedWidgetSize(size);
                event.preventDefault();
            }
            break;
    }
}
 
Example 8
Source File: CollapsibleSplitLayoutPanel.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    switch (event.getTypeInt()) {
        case Event.ONMOUSEDOWN:
            mouseDown = true;

  /*
   * Resize glassElem to take up the entire scrollable window area,
   * which is the greater of the scroll size and the client size.
   */
            int width = Math.max(Window.getClientWidth(),
                    Document.get().getScrollWidth());
            int height = Math.max(Window.getClientHeight(),
                    Document.get().getScrollHeight());
            glassElem.getStyle().setHeight(height, Style.Unit.PX);
            glassElem.getStyle().setWidth(width, Style.Unit.PX);
            Document.get().getBody().appendChild(glassElem);

            offset = getEventPosition(event) - getAbsolutePosition();
            Event.setCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEUP:
            mouseDown = false;

            glassElem.removeFromParent();

            // Handle double-clicks.
            // Fake them since the double-click event aren't fired.
            if (this.toggleDisplayAllowed) {
                double now = Duration.currentTimeMillis();
                if (now - this.lastClick < DOUBLE_CLICK_TIMEOUT) {
                    now = 0;
                    toggleCollapsedState();
                }
                this.lastClick = now;
            }

            Event.releaseCapture(getElement());
            event.preventDefault();
            break;

        case Event.ONMOUSEMOVE:
            if (mouseDown) {
                int size;
                if (reverse) {
                    size = getTargetPosition() + getTargetSize() - getSplitterSize()
                            - getEventPosition(event) + offset;
                } else {
                    size = getEventPosition(event) - getTargetPosition() - offset;
                }
                ((LayoutData) target.getLayoutData()).hidden = false;
                setAssociatedWidgetSize(size);
                event.preventDefault();
            }
            break;
    }
}