Exemple #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);
 }
Exemple #2
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;
 }
Exemple #3
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;
 }
Exemple #4
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;
 }
Exemple #5
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;
 }
Exemple #6
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);
    }
  }