Ejemplo n.º 1
0
  public void onMouseUp(MouseUpEvent event) {
    if (mouseMoveCanceled) {
      return;
    }

    Event.releaseCapture(getElement());
    setFocus(false);
    if (moveRegistration != null) {
      moveRegistration.removeHandler();
      moveRegistration = null;
    }
    int endX = event.getClientX();
    int endY = event.getClientY();
    int xDiff = startX - endX;
    int 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().isDisabledOrReadOnly() && mouseMoved) {
        // Event Move:
        // - calendar must be enabled
        // - calendar must not be in read-only mode
        weekGrid.eventMoved(this);
      } else if (!weekGrid.getCalendar().isDisabled()) {
        // Event 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().getEventClickListener() != null) {
            weekGrid.getCalendar().getEventClickListener().eventClick(calendarEvent);
          }
        }
      }

    } else { // click targeted resize bar
      removeGlobalResizeStyle();
      if (weekGrid.getCalendar().getEventResizeListener() != null) {
        weekGrid.getCalendar().getEventResizeListener().eventResized(calendarEvent);
      }
    }
  }
Ejemplo n.º 2
0
  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();

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

    long startFromMinutes = (startDatetimeFrom.getHours() * 60) + startDatetimeFrom.getMinutes();
    long range = calendarEvent.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()).recalculateEventWidths();
  }
Ejemplo n.º 3
0
  @SuppressWarnings("deprecation")
  public void onMouseMove(MouseMoveEvent event) {
    if (startY < 0 && startX < 0) {
      return;
    }
    if (isDisabled()) {
      Event.releaseCapture(getElement());
      mouseMoveStarted = false;
      startY = -1;
      startX = -1;
      removeGlobalResizeStyle();
      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;
    }
    if (!mouseMoveStarted) {
      setWidth(moveWidth);
      getElement().getStyle().setMarginLeft(0, Unit.PX);
      mouseMoveStarted = true;
    }

    HorizontalPanel parent = (HorizontalPanel) getParent().getParent();
    int relativeX = event.getRelativeX(parent.getElement()) - weekGrid.timebar.getOffsetWidth();
    int halfHourDiff = 0;
    if (moveY > 0) {
      halfHourDiff = (startYrelative + moveY) / slotHeight;
    } else {
      halfHourDiff = (moveY - startYrelative) / slotHeight;
    }

    int dateCellWidth = getDateCellWidth();
    long dayDiff = 0;
    if (moveX >= 0) {
      dayDiff = (startXrelative + moveX) / dateCellWidth;
    } else {
      dayDiff = (moveX - (dateCellWidth - startXrelative)) / dateCellWidth;
    }

    int dayOffset = relativeX / dateCellWidth;

    // sanity check for right side overflow
    int dateCellCount = weekGrid.getDateCellCount();
    if (dayOffset >= dateCellCount) {
      dayOffset--;
      dayDiff--;
    }

    int dayOffsetPx = calculateDateCellOffsetPx(dayOffset) + weekGrid.timebar.getOffsetWidth();

    GWT.log(
        "DateCellWidth: "
            + dateCellWidth
            + " dayDiff: "
            + dayDiff
            + " dayOffset: "
            + dayOffset
            + " dayOffsetPx: "
            + dayOffsetPx
            + " startXrelative: "
            + startXrelative
            + " moveX: "
            + moveX);

    if (relativeX < 0 || relativeX >= getDatesWidth()) {
      return;
    }

    Style s = getElement().getStyle();

    Date from = calendarEvent.getStartTime();
    Date to = calendarEvent.getEndTime();
    long duration = to.getTime() - from.getTime();

    if (!clickTargetsResize() && weekGrid.getCalendar().isEventMoveAllowed()) {
      long daysMs = dayDiff * DateConstants.DAYINMILLIS;
      from.setTime(startDatetimeFrom.getTime() + daysMs);
      from.setTime(from.getTime() + ((long) halfHourInMilliSeconds * halfHourDiff));
      to.setTime((from.getTime() + duration));

      calendarEvent.setStartTime(from);
      calendarEvent.setEndTime(to);
      calendarEvent.setStart(new Date(from.getTime()));
      calendarEvent.setEnd(new Date(to.getTime()));

      // Set new position for the event
      long startFromMinutes = (from.getHours() * 60) + from.getMinutes();
      long range = calendarEvent.getRangeInMinutes();
      startFromMinutes = calculateStartFromMinute(startFromMinutes, from, to, dayOffsetPx);
      if (startFromMinutes < 0) {
        range += startFromMinutes;
      }
      updatePosition(startFromMinutes, range);

      s.setLeft(dayOffsetPx, Unit.PX);

      if (weekGrid.getDateCellWidths() != null) {
        s.setWidth(weekGrid.getDateCellWidths()[dayOffset], Unit.PX);
      } else {
        setWidth(moveWidth);
      }

    } else if (clickTarget == topResizeBar) {
      long oldStartTime = startDatetimeFrom.getTime();
      long newStartTime = oldStartTime + ((long) halfHourInMilliSeconds * halfHourDiff);

      if (!isTimeRangeTooSmall(newStartTime, startDatetimeTo.getTime())) {
        newStartTime = startDatetimeTo.getTime() - getMinTimeRange();
      }

      from.setTime(newStartTime);

      calendarEvent.setStartTime(from);
      calendarEvent.setStart(new Date(from.getTime()));

      // Set new position for the event
      long startFromMinutes = (from.getHours() * 60) + from.getMinutes();
      long range = calendarEvent.getRangeInMinutes();

      updatePosition(startFromMinutes, range);

    } else if (clickTarget == bottomResizeBar) {
      long oldEndTime = startDatetimeTo.getTime();
      long newEndTime = oldEndTime + ((long) halfHourInMilliSeconds * halfHourDiff);

      if (!isTimeRangeTooSmall(startDatetimeFrom.getTime(), newEndTime)) {
        newEndTime = startDatetimeFrom.getTime() + getMinTimeRange();
      }

      to.setTime(newEndTime);

      calendarEvent.setEndTime(to);
      calendarEvent.setEnd(new Date(to.getTime()));

      // Set new position for the event
      long startFromMinutes = (startDatetimeFrom.getHours() * 60) + startDatetimeFrom.getMinutes();
      long range = calendarEvent.getRangeInMinutes();
      startFromMinutes = calculateStartFromMinute(startFromMinutes, from, to, dayOffsetPx);
      if (startFromMinutes < 0) {
        range += startFromMinutes;
      }
      updatePosition(startFromMinutes, range);
    }
  }
Ejemplo n.º 4
0
    @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, Unit.PX);
          glassElem.getStyle().setWidth(width, 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;
            LayoutData layout = (LayoutData) target.getLayoutData();
            if (layout.size == 0) {
              // Restore the old size.
              // setAssociatedWidgetSize(layout.oldSize);
              setAssociatedWidgetSize(200);

              setStyleName("gwt-SplitLayoutPanel-myHDragger_right");
            } else {
              /*
               * Collapse to size 0. We change the size instead of hiding the
               * widget because hiding the widget can cause issues if the
               * widget contains a flash component.
               */
              layout.oldSize = layout.size;
              setAssociatedWidgetSize(0);
              setStyleName("gwt-SplitLayoutPanel-myHDragger_left");
            }
            // }
            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;
      }
    }