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

The following examples show how to use com.google.gwt.user.client.Event#releaseCapture() . 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: SvgArrowWidget.java    From gantt with Apache License 2.0 6 votes vote down vote up
protected void cancelMove(boolean forceReset, NativeEvent event) {
    GWT.log("Relasing captured point.");
    if (captureElement != null) {
        Event.releaseCapture(captureElement);
    }
    movePointElement.removeFromParent();
    getElement().getParentElement().removeClassName(SELECTION_STYLE_NAME);
    moveRegisteration.removeHandler();
    if (touchCancelRegisteration != null) {
        touchCancelRegisteration.removeHandler();
    }
    captureElement = null;

    if (forceReset
            || (handler != null && !handler.onArrowChanged(
                    selectPredecessorMode, event))) {
        // cancel
        resetArrow();
    }
    selectPredecessorMode = false;
    selectFollowerMode = false;
    currentPointerEventId = -1;
    pendingPointerDownEvent = null;
}
 
Example 2
Source File: SimpleDayCell.java    From calendar-component with Apache License 2.0 5 votes vote down vote up
protected void cancelItemDrag(MonthItemLabel label) {
    if (moveRegistration != null) {
        // reset position
        if (movingItem == null) {
            movingItem = getItemByWidget(label);
        }

        movingItem.setStart(dndSourceDateFrom);
        movingItem.setEnd(dndSourceDateTo);
        movingItem.setStartTime(dndSourceStartDateTime);
        movingItem.setEndTime(dndSourceEndDateTime);
        calendar.updateItemToMonthGrid(movingItem);

        // reset drag-related properties
        Event.releaseCapture(getElement());
        moveRegistration.removeHandler();
        moveRegistration = null;
        keyDownHandler.removeHandler();
        keyDownHandler = null;
        setFocus(false);
        monthEventMouseDown = false;
        startY = -1;
        startX = -1;
        movingItem = null;
        labelMouseDown = false;
        clickedWidget = null;
    }
}
 
Example 3
Source File: DateCellDayItem.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
    if (mouseMoveCanceled
            || event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        return;
    }

    Event.releaseCapture(getElement());
    setFocus(false);
    if (moveRegistration != null) {
        moveRegistration.removeHandler();
        moveRegistration = null;
    }

    int endX = event.getClientX();
    int endY = event.getClientY();
    int xDiff = 0, yDiff = 0;
    if (startX != -1 && startY != -1) {
        // Drag started
        xDiff = startX - endX;
        yDiff = startY - endY;
    }

    startX = -1;
    startY = -1;
    mouseMoveStarted = false;
    Style s = getElement().getStyle();
    s.setZIndex(1);

    if (!clickTargetsResize()) {

        // check if mouse has moved over threshold of 3 pixels
        boolean mouseMoved = (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3);

        if (!weekGrid.getCalendar().isDisabled() && mouseMoved) {
            // Item Move:
            // - calendar must be enabled
            // - calendar must not be in read-only mode
            weekGrid.itemMoved(this);

        } else if (!weekGrid.getCalendar().isDisabled() && getCalendarItem().isClickable()) {
            // Item Click:
            // - calendar must be enabled (read-only is allowed)
            EventTarget et = event.getNativeEvent().getEventTarget();
            Element e = Element.as(et);
            if (e == caption || e == eventContent
                    || e.getParentElement() == caption) {
                if (weekGrid.getCalendar().getItemClickListener() != null) {
                    weekGrid.getCalendar().getItemClickListener().itemClick(calendarItem);
                }
            }
        }

    } else {
        // click targeted resize bar
        removeGlobalResizeStyle();
        if (weekGrid.getCalendar().getItemResizeListener() != null) {
            weekGrid.getCalendar().getItemResizeListener().itemResized(calendarItem);
        }
        dateCell.recalculateItemWidths();
    }
}
 
Example 4
Source File: DateCellDayItem.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
private void cancelMouseMove() {
    mouseMoveCanceled = true;

    // reset and remove everything related to the event handling
    Event.releaseCapture(getElement());
    setFocus(false);

    if (moveRegistration != null) {
        moveRegistration.removeHandler();
        moveRegistration = null;
    }

    mouseMoveStarted = false;
    removeGlobalResizeStyle();

    Style s = getElement().getStyle();
    s.setZIndex(1);

    // reset the position of the event
    int dateCellWidth = getDateCellWidth();
    int dayOffset = startXrelative / dateCellWidth;
    s.clearLeft();

    calendarItem.setStartTime(startDatetimeFrom);
    calendarItem.setEndTime(startDatetimeTo);

    long startFromMinutes = (startDatetimeFrom.getHours() * 60)
            + startDatetimeFrom.getMinutes();
    long range = calendarItem.getRangeInMinutes();

    startFromMinutes = calculateStartFromMinute(startFromMinutes,
            startDatetimeFrom, startDatetimeTo, dayOffset);
    if (startFromMinutes < 0) {
        range += startFromMinutes;
    }

    updatePosition(startFromMinutes, range);

    startY = -1;
    startX = -1;

    // to reset the event width
    ((DateCell) getParent()).recalculateItemWidths();
}
 
Example 5
Source File: DateCell.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public void onMouseUp(MouseUpEvent event) {

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

    Event.releaseCapture(getElement());
    setFocus(false);

    // Drag initialized?
    if (eventRangeStart >= 0) {
        Element main = getElement();
        if (eventRangeStart > eventRangeStop) {
            if (eventRangeStop <= -1) {
                eventRangeStop = 0;
            }
            int temp = eventRangeStart;
            eventRangeStart = eventRangeStop;
            eventRangeStop = temp;
        }

        // This happens for single clicks without dragging on the calendar
        if(eventRangeStart == eventRangeStop) {
            handleEventRange(event);
        }

        NodeList<Node> nodes = main.getChildNodes();

        int slotStart = -1;
        int slotEnd = -1;

        // iterate over all child nodes, until we find first the start,
        // and then the end
        for (int i = 0; i < nodes.getLength(); i++) {
            Element element = (Element) nodes.getItem(i);
            boolean isRangeElement = element.getClassName().contains("v-daterange");

            if (isRangeElement && slotStart == -1) {
                slotStart = i;
                slotEnd = i; // to catch one-slot selections

            } else if (isRangeElement) {
                slotEnd = i;

            } else if (slotStart != -1 && slotEnd != -1) {
                break; // FIXME ! is 'else if' right
            }
        }

        clearSelectionRange();

        int startMinutes = firstHour * 60 + slotStart * 30;
        int endMinutes = (firstHour * 60) + (slotEnd + 1) * 30;
        Date currentDate = getDate();

        if (weekgrid.getCalendar().getRangeSelectListener() != null) {

            SelectionRange weekSelection = new SelectionRange();
            weekSelection.sMin = startMinutes;
            weekSelection.eMin = endMinutes;
            weekSelection.setStartDay(DateConstants.toRPCDate(
                    currentDate.getYear(),
                    currentDate.getMonth(),
                    currentDate.getDate()));

            weekgrid.getCalendar().getRangeSelectListener().rangeSelected(weekSelection);
        }
        eventRangeStart = -1;

    } else {

        // Click event
        eventRangeStart = -1;
        cancelRangeSelect();
    }
}
 
Example 6
Source File: DateCell.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
public void cancelRangeSelect() {
    Event.releaseCapture(getElement());
    setFocus(false);

    clearSelectionRange();
}
 
Example 7
Source File: SimpleDayCell.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
    if (event.getNativeButton() != NativeEvent.BUTTON_LEFT) {
        return;
    }

    if (moveRegistration != null) {
        Event.releaseCapture(getElement());
        moveRegistration.removeHandler();
        moveRegistration = null;
        keyDownHandler.removeHandler();
        keyDownHandler = null;
    }

    Widget w = (Widget) event.getSource();
    if (w == bottomspacer && monthEventMouseDown) {
        GWT.log("Mouse up over bottomspacer");

    } else if (clickedWidget instanceof MonthItemLabel  && monthEventMouseDown) {

        MonthItemLabel mel = (MonthItemLabel) clickedWidget;

        int endX = event.getClientX();
        int endY = event.getClientY();
        int xDiff = 0, yDiff = 0;
        if (startX != -1 && startY != -1) {
            xDiff = startX - endX;
            yDiff = startY - endY;
        }
        startX = -1;
        startY = -1;
        prevDayDiff = 0;
        prevWeekDiff = 0;

        if (xDiff < -3 || xDiff > 3 || yDiff < -3 || yDiff > 3) {
            itemMoved(movingItem);

        } else if (calendar.getItemClickListener() != null) {
            CalendarItem e = getItemByWidget(mel);

            if(e.isClickable())
            calendar.getItemClickListener().itemClick(e);
        }

        movingItem = null;

    } else if (w == this) {
        getMonthGrid().setSelectionReady();

    } else if (w instanceof Label && labelMouseDown) {
        if (calendar.getDateClickListener() != null) {
            calendar.getDateClickListener().dateClick(DateConstants.toRPCDate(date));
        }
    }

    monthEventMouseDown = false;
    labelMouseDown = false;
    clickedWidget = null;
}
 
Example 8
Source File: SimpleDayCell.java    From calendar-component with Apache License 2.0 4 votes vote down vote up
@Override
public void onMouseMove(MouseMoveEvent event) {

    if (clickedWidget instanceof MonthItemLabel && !monthEventMouseDown
            || (startY < 0 && startX < 0)) {
        return;
    }

    if (calendar.isDisabled()) {
        Event.releaseCapture(getElement());
        monthEventMouseDown = false;
        startY = -1;
        startX = -1;
        return;
    }

    int currentY = event.getClientY();
    int currentX = event.getClientX();
    int moveY = (currentY - startY);
    int moveX = (currentX - startX);
    if ((moveY < 5 && moveY > -6) && (moveX < 5 && moveX > -6)) {
        return;
    }

    int dateCellWidth = getWidth();
    int dateCellHeigth = getHeigth();

    Element parent = getMonthGrid().getElement();
    int relativeX = event.getRelativeX(parent);
    int relativeY = event.getRelativeY(parent);
    int weekDiff;

    if (moveY > 0) {
        weekDiff = (startYrelative + moveY) / dateCellHeigth;
    } else {
        weekDiff = (moveY - (dateCellHeigth - startYrelative))
                / dateCellHeigth;
    }

    int dayDiff;
    if (moveX >= 0) {
        dayDiff = (startXrelative + moveX) / dateCellWidth;
    } else {
        dayDiff = (moveX - (dateCellWidth - startXrelative))
                / dateCellWidth;
    }
    // Check boundaries
    if (relativeY < 0
            || relativeY >= (calendar.getMonthGrid().getRowCount()
                    * dateCellHeigth)
            || relativeX < 0
            || relativeX >= (calendar.getMonthGrid().getColumnCount()
                    * dateCellWidth)) {
        return;
    }

    MonthItemLabel widget = (MonthItemLabel) clickedWidget;

    CalendarItem item = movingItem;
    if (item == null) {
        item = getItemByWidget(widget);
    }

    Date from = item.getStart();
    Date to = item.getEnd();

    long daysMs = dayDiff * DateConstants.DAYINMILLIS;
    long weeksMs = weekDiff * DateConstants.WEEKINMILLIS;

    setDates(item, from, to, weeksMs + daysMs, false);

    item.setStart(from);
    item.setEnd(to);

    if (widget.isTimeSpecificEvent()) {
        Date start = new Date();
        Date end = new Date();

        setDates(item, start, end, weeksMs + daysMs, true);

        item.setStartTime(start);
        item.setEndTime(end);

    } else {

        item.setStartTime(new Date(from.getTime()));
        item.setEndTime(new Date(to.getTime()));
    }

    updateDragPosition(widget, dayDiff, weekDiff);
}
 
Example 9
Source File: PanListener.java    From djvu-html5 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onMouseUp(MouseUpEvent event) {
	isMouseDown = false;
	Event.releaseCapture(widget.getElement());
}
 
Example 10
Source File: InputSlider.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void onMouseUp(Event event) {
	if (this.dragging) {
		this.dragging = false;
		Event.releaseCapture(InputSlider.this.getElement());
	}
}
 
Example 11
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 12
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;
    }
}