Exemplo n.º 1
0
 @Override
 protected boolean handleEvent(Event evt) {
   if (evt.isKeyEvent() && content != null && content.canAcceptKeyboardFocus()) {
     if (content.handleEvent(evt)) {
       content.requestKeyboardFocus();
       return true;
     }
   }
   if (super.handleEvent(evt)) {
     return true;
   }
   switch (evt.getType()) {
     case KEY_PRESSED:
     case KEY_RELEASED:
       {
         int keyCode = evt.getKeyCode();
         if (keyCode == Event.KEY_LEFT || keyCode == Event.KEY_RIGHT) {
           return scrollbarH.handleEvent(evt);
         }
         if (keyCode == Event.KEY_UP
             || keyCode == Event.KEY_DOWN
             || keyCode == Event.KEY_PRIOR
             || keyCode == Event.KEY_NEXT) {
           return scrollbarV.handleEvent(evt);
         }
         break;
       }
     case MOUSE_WHEEL:
       if (scrollbarV.isVisible()) {
         return scrollbarV.handleEvent(evt);
       }
       return false;
   }
   return evt.isMouseEvent() && contentArea.isMouseInside(evt);
 }
Exemplo n.º 2
0
  @SuppressWarnings("OverridableMethodCallInConstructor")
  public ScrollPane(Widget content) {
    this.scrollbarH = new Scrollbar(Scrollbar.Orientation.HORIZONTAL);
    this.scrollbarV = new Scrollbar(Scrollbar.Orientation.VERTICAL);
    this.contentArea = new Widget();

    Runnable cb =
        new Runnable() {
          public void run() {
            scrollContent();
          }
        };

    scrollbarH.addCallback(cb);
    scrollbarH.setVisible(false);
    scrollbarV.addCallback(cb);
    scrollbarV.setVisible(false);
    contentArea.setClip(true);
    contentArea.setTheme("");

    super.insertChild(contentArea, 0);
    super.insertChild(scrollbarH, 1);
    super.insertChild(scrollbarV, 2);
    setContent(content);
    setCanAcceptKeyboardFocus(true);
  }
Exemplo n.º 3
0
 void setAutoScrollMarker() {
   int scrollPos = scrollbarV.getValue();
   AnimationState animationState = getAnimationState();
   animationState.setAnimationState(
       STATE_AUTO_SCROLL_UP, autoScrollDirection < 0 && scrollPos > 0);
   animationState.setAnimationState(
       STATE_AUTO_SCROLL_DOWN, autoScrollDirection > 0 && scrollPos < scrollbarV.getMaxValue());
 }
Exemplo n.º 4
0
 @Override
 protected void paint(GUI gui) {
   if (dragButton != null) {
     AnimationState as = dragButton.getAnimationState();
     as.setAnimationState(STATE_DOWNARROW_ARMED, scrollbarV.isDownRightButtonArmed());
     as.setAnimationState(STATE_RIGHTARROW_ARMED, scrollbarH.isDownRightButtonArmed());
   }
   super.paint(gui);
 }
Exemplo n.º 5
0
 void scrollContent() {
   if (content instanceof Scrollable) {
     Scrollable scrollable = (Scrollable) content;
     scrollable.setScrollPosition(scrollbarH.getValue(), scrollbarV.getValue());
   } else {
     content.setPosition(
         contentArea.getX() - scrollbarH.getValue(), contentArea.getY() - scrollbarV.getValue());
   }
 }
Exemplo n.º 6
0
 @Override
 public int getMinHeight() {
   int minHeight = super.getMinHeight();
   int border = getBorderVertical();
   // minHeight = Math.max(minHeight, scrollbarV.getMinHeight() + border);
   if (fixed == Fixed.VERTICAL && content != null) {
     int sbHeight = scrollbarH.isVisible() ? scrollbarH.getMinHeight() : 0;
     minHeight = Math.max(minHeight, content.getMinHeight() + border + sbHeight);
   }
   return minHeight;
 }
Exemplo n.º 7
0
 @Override
 public int getMinWidth() {
   int minWidth = super.getMinWidth();
   int border = getBorderHorizontal();
   // minWidth = Math.max(minWidth, scrollbarH.getMinWidth() + border);
   if (fixed == Fixed.HORIZONTAL && content != null) {
     int sbWidth = scrollbarV.isVisible() ? scrollbarV.getMinWidth() : 0;
     minWidth = Math.max(minWidth, content.getMinWidth() + border + sbWidth);
   }
   return minWidth;
 }
Exemplo n.º 8
0
 @Override
 public int getPreferredInnerHeight() {
   if (content != null) {
     switch (fixed) {
       case HORIZONTAL:
         return content.getPreferredHeight();
       case VERTICAL:
         int prefHeight =
             computeSize(
                 content.getMinHeight(), content.getPreferredHeight(), content.getMaxHeight());
         if (scrollbarH.isVisible()) {
           prefHeight += scrollbarH.getPreferredHeight();
         }
         return prefHeight;
     }
   }
   return 0;
 }
Exemplo n.º 9
0
 @Override
 public int getPreferredInnerWidth() {
   if (content != null) {
     switch (fixed) {
       case HORIZONTAL:
         int prefWidth =
             computeSize(
                 content.getMinWidth(), content.getPreferredWidth(), content.getMaxWidth());
         if (scrollbarV.isVisible()) {
           prefWidth += scrollbarV.getPreferredWidth();
         }
         return prefWidth;
       case VERTICAL:
         return content.getPreferredWidth();
     }
   }
   return 0;
 }
Exemplo n.º 10
0
 void doAutoScroll() {
   scrollbarV.setValue(scrollbarV.getValue() + autoScrollDirection * autoScrollSpeed);
   setAutoScrollMarker();
 }
Exemplo n.º 11
0
 public int getMaxScrollPosX() {
   return scrollbarH.getMaxValue();
 }
Exemplo n.º 12
0
 public int getScrollPositionY() {
   return scrollbarV.getValue();
 }
Exemplo n.º 13
0
 public int getMaxScrollPosY() {
   return scrollbarV.getMaxValue();
 }
Exemplo n.º 14
0
 public void setScrollPositionY(int pos) {
   scrollbarV.setValue(pos);
 }
Exemplo n.º 15
0
  @Override
  protected void layout() {
    if (content != null) {
      int innerWidth = getInnerWidth();
      int innerHeight = getInnerHeight();
      int availWidth = innerWidth;
      int availHeight = innerHeight;
      innerWidth += vscrollbarOffset.getX();
      innerHeight += hscrollbarOffset.getY();
      int scrollbarHX = hscrollbarOffset.getX();
      int scrollbarHY = innerHeight;
      int scrollbarVX = innerWidth;
      int scrollbarVY = vscrollbarOffset.getY();
      int requiredWidth;
      int requiredHeight;
      boolean repeat;
      boolean visibleH = false;
      boolean visibleV = false;

      switch (fixed) {
        case HORIZONTAL:
          requiredWidth = availWidth;
          requiredHeight = content.getPreferredHeight();
          break;
        case VERTICAL:
          requiredWidth = content.getPreferredWidth();
          requiredHeight = availHeight;
          break;
        default:
          requiredWidth = content.getPreferredWidth();
          requiredHeight = content.getPreferredHeight();
          break;
      }

      // System.out.println("required="+requiredWidth+","+requiredHeight+"
      // avail="+availWidth+","+availHeight);

      int hScrollbarMax = 0;
      int vScrollbarMax = 0;

      // don't add scrollbars if we have zero size
      if (availWidth > 0 && availHeight > 0) {
        do {
          repeat = false;

          if (fixed != Fixed.HORIZONTAL) {
            hScrollbarMax = Math.max(0, requiredWidth - availWidth);
            if (hScrollbarMax > 0
                || scrollbarsAlwaysVisible
                || ((scrollbarsToggleFlags & 3) == 3)) {
              repeat |= !visibleH;
              visibleH = true;
              int prefHeight = scrollbarH.getPreferredHeight();
              scrollbarHY = innerHeight - prefHeight;
              availHeight = Math.max(0, scrollbarHY - contentScrollbarSpacing.getY());
            }
          } else {
            hScrollbarMax = 0;
            requiredWidth = availWidth;
          }

          if (fixed != Fixed.VERTICAL) {
            vScrollbarMax = Math.max(0, requiredHeight - availHeight);
            if (vScrollbarMax > 0
                || scrollbarsAlwaysVisible
                || ((scrollbarsToggleFlags & 12) == 12)) {
              repeat |= !visibleV;
              visibleV = true;
              int prefWidth = scrollbarV.getPreferredWidth();
              scrollbarVX = innerWidth - prefWidth;
              availWidth = Math.max(0, scrollbarVX - contentScrollbarSpacing.getX());
            }
          } else {
            vScrollbarMax = 0;
            requiredHeight = availHeight;
          }
        } while (repeat);
      }

      // if a scrollbar visibility state has changed set it's flag to
      // detect layout loops
      if (visibleH && !scrollbarH.isVisible()) {
        scrollbarsToggleFlags |= 1;
      }
      if (!visibleH && scrollbarH.isVisible()) {
        scrollbarsToggleFlags |= 2;
      }
      if (visibleV && !scrollbarV.isVisible()) {
        scrollbarsToggleFlags |= 4;
      }
      if (!visibleV && scrollbarV.isVisible()) {
        scrollbarsToggleFlags |= 8;
      }

      boolean changedH = visibleH ^ scrollbarH.isVisible();
      boolean changedV = visibleV ^ scrollbarV.isVisible();
      if (changedH || changedV) {
        if ((changedH && fixed == Fixed.VERTICAL) || (changedV && fixed == Fixed.HORIZONTAL)) {
          invalidateLayout();
        } else {
          invalidateLayoutLocally();
        }
      }

      int pageSizeX, pageSizeY;
      if (content instanceof CustomPageSize) {
        CustomPageSize customPageSize = (CustomPageSize) content;
        pageSizeX = customPageSize.getPageSizeX(availWidth);
        pageSizeY = customPageSize.getPageSizeY(availHeight);
      } else {
        pageSizeX = availWidth;
        pageSizeY = availHeight;
      }

      scrollbarH.setVisible(visibleH);
      scrollbarH.setMinMaxValue(0, hScrollbarMax);
      scrollbarH.setSize(
          Math.max(0, scrollbarVX - scrollbarHX), Math.max(0, innerHeight - scrollbarHY));
      scrollbarH.setPosition(getInnerX() + scrollbarHX, getInnerY() + scrollbarHY);
      scrollbarH.setPageSize(Math.max(1, pageSizeX));
      scrollbarH.setStepSize(Math.max(1, pageSizeX / 10));

      scrollbarV.setVisible(visibleV);
      scrollbarV.setMinMaxValue(0, vScrollbarMax);
      scrollbarV.setSize(
          Math.max(0, innerWidth - scrollbarVX), Math.max(0, scrollbarHY - scrollbarVY));
      scrollbarV.setPosition(getInnerX() + scrollbarVX, getInnerY() + scrollbarVY);
      scrollbarV.setPageSize(Math.max(1, pageSizeY));
      scrollbarV.setStepSize(Math.max(1, pageSizeY / 10));

      if (dragButton != null) {
        dragButton.setVisible(visibleH && visibleV);
        dragButton.setSize(
            Math.max(0, innerWidth - scrollbarVX), Math.max(0, innerHeight - scrollbarHY));
        dragButton.setPosition(getInnerX() + scrollbarVX, getInnerY() + scrollbarHY);
      }

      contentArea.setPosition(getInnerX(), getInnerY());
      contentArea.setSize(availWidth, availHeight);
      if (content instanceof Scrollable) {
        content.setPosition(contentArea.getX(), contentArea.getY());
        content.setSize(availWidth, availHeight);
      } else if (expandContentSize) {
        content.setSize(Math.max(availWidth, requiredWidth), Math.max(availHeight, requiredHeight));
      } else {
        content.setSize(Math.max(0, requiredWidth), Math.max(0, requiredHeight));
      }

      AnimationState animationState = getAnimationState();
      animationState.setAnimationState(STATE_HORIZONTAL_SCROLLBAR_VISIBLE, visibleH);
      animationState.setAnimationState(STATE_VERTICAL_SCROLLBAR_VISIBLE, visibleV);

      scrollContent();
    } else {
      scrollbarH.setVisible(false);
      scrollbarV.setVisible(false);
    }
  }
Exemplo n.º 16
0
 public int getScrollPositionX() {
   return scrollbarH.getValue();
 }
Exemplo n.º 17
0
 /**
  * Tries to make the specified vertical area completely visible. If it is larger then the vertical
  * page size then it scrolls to the start of the area.
  *
  * @param start the position of the area
  * @param size size of the area
  * @param extra the extra space which should be visible around the area
  * @see Scrollbar#scrollToArea(int, int, int)
  */
 public void scrollToAreaY(int start, int size, int extra) {
   scrollbarV.scrollToArea(start, size, extra);
 }