Пример #1
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);
 }
Пример #2
0
  /**
   * The following theme parameters are required by the scroll pane:
   *
   * <table>
   * <tr>
   * <th>Parameter name</th>
   * <th>Type</th>
   * <th>Description</th>
   * </tr>
   * <tr>
   * <td>autoScrollArea</td>
   * <td>integer</td>
   * <td>The size of the auto scroll area</td>
   * </tr>
   * <tr>
   * <td>autoScrollSpeed</td>
   * <td>integer</td>
   * <td>The speed in pixels to scroll every 50 ms</td>
   * </tr>
   * <tr>
   * <td>hasDragButton</td>
   * <td>boolean</td>
   * <td>If the dragButton should be shown or not</td>
   * </tr>
   * <tr>
   * <td>scrollbarsAlwaysVisible</td>
   * <td>boolean</td>
   * <td>Show scrollbars always (true) or only when needed (false)</td>
   * </tr>
   * </table>
   *
   * <br>
   * The following optional parameters can be used to change the appearance of the scroll pane:
   *
   * <table>
   * <tr>
   * <th>Parameter name</th>
   * <th>Type</th>
   * <th>Description</th>
   * </tr>
   * <tr>
   * <td>hscrollbarOffset</td>
   * <td>Dimension</td>
   * <td>Moves the horizontal scrollbar but does not change the available area
   * for the scroll content.</td>
   * </tr>
   * <tr>
   * <td>vscrollbarOffset</td>
   * <td>Dimension</td>
   * <td>Moves the vertical scrollbar but does not change the available area
   * for the scroll content.</td>
   * </tr>
   * <tr>
   * <td>contentScrollbarSpacing</td>
   * <td>Dimension</td>
   * <td>An optional spacing between the scrollbar and the content area. This
   * is only applied when the corresponding scrollbar is visible. It should be
   * &gt;= 0.</td>
   * </tr>
   * </table>
   *
   * @param themeInfo the theme info
   */
  protected void applyThemeScrollPane(ThemeInfo themeInfo) {
    autoScrollArea = themeInfo.getParameter("autoScrollArea", 5);
    autoScrollSpeed = themeInfo.getParameter("autoScrollSpeed", autoScrollArea * 2);
    hscrollbarOffset =
        themeInfo.getParameterValue("hscrollbarOffset", false, Dimension.class, Dimension.ZERO);
    vscrollbarOffset =
        themeInfo.getParameterValue("vscrollbarOffset", false, Dimension.class, Dimension.ZERO);
    contentScrollbarSpacing =
        themeInfo.getParameterValue(
            "contentScrollbarSpacing", false, Dimension.class, Dimension.ZERO);
    scrollbarsAlwaysVisible = themeInfo.getParameter("scrollbarsAlwaysVisible", false);

    boolean hasDragButton = themeInfo.getParameter("hasDragButton", false);
    if (hasDragButton && dragButton == null) {
      dragButton = new DraggableButton();
      dragButton.setTheme("dragButton");
      dragButton.setListener(
          new DraggableButton.DragListener() {
            public void dragStarted() {
              scrollbarH.externalDragStart();
              scrollbarV.externalDragStart();
            }

            public void dragged(int deltaX, int deltaY) {
              scrollbarH.externalDragged(deltaX, deltaY);
              scrollbarV.externalDragged(deltaX, deltaY);
            }

            public void dragStopped() {
              scrollbarH.externalDragStopped();
              scrollbarV.externalDragStopped();
            }
          });
      super.insertChild(dragButton, 3);
    } else if (!hasDragButton && dragButton != null) {
      assert super.getChild(3) == dragButton;
      super.removeChild(3);
      dragButton = null;
    }
  }
Пример #3
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);
    }
  }