Examples of BoxModel


Examples of gwt.mosaic.client.style.BoxModel

  private int rowSpan = 1;

  private int weight = 0;

  LayoutData(Widget w) {
    this.boxModel = new BoxModel(w);
  }
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

      return WidgetHelper.getPreferredWidthImpl(this, clientHeight);
    }

    int preferredWidth = 0;

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    if (orientation == Orientation.HORIZONTAL) {
      // Include padding in constraint
      if (clientHeight != -1) {
        clientHeight = Math.max(
            clientHeight - (boxModel.getHeightContribution()), 0);
      }

      // Preferred width is the sum of the preferred widths of all widgets
      int j = 0;
      for (Widget child : getChildren()) {
        if (child.isVisible()) {
          preferredWidth += WidgetHelper.getPreferredWidth(child,
              fill ? clientHeight : -1);
          ++j;
        }
      }
     
      // Include spacing
      if (j > 1) {
        preferredWidth += spacing * (j - 1);
      }
    } else {
      // Preferred width is the maximum preferred width of all widgets
      for (Widget child : getChildren()) {
        if (child.isVisible()) {
          preferredWidth = Math.max(preferredWidth,
              WidgetHelper.getPreferredWidth(child, -1));
        }
      }
    }

    // Include left and right margin+border+padding values
    preferredWidth += boxModel.getWidthContribution();

    return (this.preferredWidth = preferredWidth);
  }
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

      return WidgetHelper.getPreferredHeightImpl(this, clientWidth);
    }

    int preferredHeight = 0;

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    if (orientation == Orientation.HORIZONTAL) {
      // Preferred height is the maximum preferred height of all widget
      for (Widget child : getChildren()) {
        if (child.isVisible()) {
          preferredHeight = Math.max(preferredHeight,
              WidgetHelper.getPreferredHeight(child));
        }
      }
    } else {
      // Include padding in constraint
      if (clientWidth != -1) {
        clientWidth = Math
            .max(clientWidth
                - boxModel.getPaddingWidthContribution(), 0);
      }

      // Preferred height is the sum of the preferred heights of all
      // widget
      int j = 0;
      for (Widget child : getChildren()) {
        if (child.isVisible()) {
          preferredHeight += WidgetHelper.getPreferredHeight(child,
              fill ? clientWidth : -1);
          ++j;
        }
      }

      // Include spacing
      if (j > 1) {
        preferredHeight += spacing * (j - 1);
      }
    }

    // Include top and bottom margin+border+padding values
    preferredHeight += boxModel.getHeightContribution();

    return (this.preferredHeight = preferredHeight);
  }
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

    }

    int preferredWidth = 0;
    int preferredHeight = 0;

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    switch (orientation) {
    case HORIZONTAL: {
      // Preferred width is the sum of the preferred widths of all widgets
      int j = 0;
      for (Widget child : getChildren()) {
        if (child.isVisible()) {
          Dimensions preferredSize = WidgetHelper
              .getPreferredSize(child);
          preferredWidth += preferredSize.getWidth();
          preferredHeight = Math.max(preferredSize.getHeight(),
              preferredHeight);
          ++j;
        }
      }

      // Include spacing
      if (j > 1) {
        preferredWidth += spacing * (j - 1);
      }

      break;
    }

    case VERTICAL: {
      // Preferred height is the sum of the preferred heights of all
      // widgets
      int j = 0;
      for (Widget child : getChildren()) {
        if (child.isVisible()) {
          Dimensions preferredSize = WidgetHelper
              .getPreferredSize(child);
          preferredWidth = Math.max(preferredSize.getWidth(),
              preferredWidth);
          preferredHeight += preferredSize.getHeight();
          ++j;
        }
      }

      // Include spacing
      if (j > 1) {
        preferredHeight += spacing * (j - 1);
      }

      break;
    }
    }

    // Include margin+border+padding
    preferredWidth += boxModel.getWidthContribution();
    preferredHeight += boxModel.getHeightContribution();

    return (preferredSize = new Dimensions(preferredWidth, preferredHeight));
  }
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

  @Override
  public int getBaseline(int width, int height) {
    int baseline = -1;
    int contentHeight = 0;

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    Insets padding = boxModel.getPadding(); // XXX

    switch (orientation) {
    case HORIZONTAL: {
      if (fill) {
        int clientHeight = Math.max(height
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

    int height = getElement().getClientHeight();

    // int preferredWidth = getPreferredWidth(fill ? height : -1);
    // width = Math.max(width, preferredWidth);

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    int totalRelativeWeight = 0;
    int totalRelativeWidth = width - boxModel.getPaddingWidthContribution();

    int[] widgetHeights = new int[n];
    int[] widgetWidths = new int[n];

    for (int i = 0; i < n; i++) {
      Widget child = getWidget(i);
      if (child.isVisible()) {
        int weight = WidgetHelper.getWeight(child);
        if (weight > 0) {
          totalRelativeWeight += weight;
        }
        if (fill) {
          int widgetHeight = Math.max(
              height - (boxModel.getPaddingHeightContribution()),
              0);
          widgetHeights[i] = widgetHeight;
          if (weight == 0) {
            widgetWidths[i] = WidgetHelper.getPreferredWidth(child,
                widgetHeight);
            totalRelativeWidth -= widgetWidths[i] + spacing;
          }
        } else {
          if (weight == 0) {
            Dimensions preferredComponentSize = WidgetHelper
                .getPreferredSize(child);
            widgetWidths[i] = preferredComponentSize.width;
            widgetHeights[i] = preferredComponentSize.height;
            totalRelativeWidth -= widgetWidths[i] + spacing;
          } else {
            widgetHeights[i] = WidgetHelper
                .getPreferredHeight(child);
          }
        }
      }
    }

    // Determine the starting x-coordinate
    int x = 0;

    if (totalRelativeWeight == 0) {
      switch (horizontalAlignment) {
      case CENTER:
        x = (width - preferredWidth) / 2;
        break;
      case RIGHT:
        x = width - preferredWidth;
        break;
      case START:
        if (LocaleInfo.getCurrentLocale().isRTL()) {
          x = width - preferredWidth;
        }
        break;
      case END:
        if (!LocaleInfo.getCurrentLocale().isRTL()) {
          x = width - preferredWidth;
        }
        break;
      }
    }

    x += boxModel.getPadding().left;

    // Lay out the widgets
    for (int i = 0; i < n; i++) {
      Widget child = getWidget(i);

      if (child.isVisible()) {
        int widgetWidth = 0;
        int widgetHeight = 0;
        int y = 0;

        int weight = WidgetHelper.getWeight(child);
        if (weight == 0) {
          widgetWidth = widgetWidths[i];
        } else {
          widgetWidth = (int) (0.5 + totalRelativeWidth
              * (double) weight / (double) totalRelativeWeight);
        }
        widgetHeight = widgetHeights[i];

        if (!fill) {
          switch (verticalAlignment) {
          case TOP:
            y = boxModel.getPadding().top;
            break;
          case MIDDLE:
            y = (height - widgetHeight) / 2;
            break;
          case BOTTOM:
            y = height - boxModel.getPadding().bottom
                - widgetHeight;
            break;
          }
        } else {
          y = boxModel.getPadding().top;
        }

        // Set the component's size and position
        WidgetHelper.setSize(child, widgetWidth, widgetHeight);
        WidgetHelper.setLocation(child, x, y);
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

    int height = getElement().getClientHeight();

    // int preferredHeight = getPreferredHeight(fill ? width : -1);
    // height = Math.max(height, preferredHeight);

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    int totalRelativeWeight = 0;
    int totalRelativeHeight = height
        - boxModel.getPaddingHeightContribution();

    int[] widgetHeights = new int[n];
    int[] widgetWidths = new int[n];

    for (int i = 0; i < n; i++) {
      Widget child = getWidget(i);
      if (child.isVisible()) {
        int weight = WidgetHelper.getWeight(child);
        if (weight > 0) {
          totalRelativeWeight += weight;
        }
        if (fill) {
          int widgetWidth = Math.max(
              width - boxModel.getPaddingWidthContribution(), 0);
          widgetWidths[i] = widgetWidth;
          if (weight == 0) {
            widgetHeights[i] = WidgetHelper.getPreferredHeight(
                child, widgetWidth);
            totalRelativeHeight -= widgetHeights[i] + spacing;
          }
        } else {
          if (weight == 0) {
            Dimensions preferredComponentSize = WidgetHelper
                .getPreferredSize(child);
            widgetWidths[i] = preferredComponentSize.getWidth();
            widgetHeights[i] = preferredComponentSize.getHeight();
            totalRelativeHeight -= widgetHeights[i] + spacing;
          } else {
            widgetWidths[i] = WidgetHelper.getPreferredWidth(child);
          }
        }
      }
    }

    // Determine the starting y-coordinate
    int y = 0;

    if (totalRelativeWeight == 0) {
      switch (verticalAlignment) {
      case MIDDLE:
        y = (height - preferredHeight) / 2;
        break;
      case BOTTOM:
        y = height - preferredHeight;
        break;
      }
    }

    y += boxModel.getPadding().top;

    // Lay out the widgets
    for (int i = 0; i < n; i++) {
      Widget child = getWidget(i);

      if (child.isVisible()) {
        int widgetWidth = 0;
        int widgetHeight = 0;
        int x = 0;

        int weight = WidgetHelper.getWeight(child);
        if (weight == 0) {
          widgetHeight = widgetHeights[i];
        } else {
          widgetHeight = (int) (0.5 + totalRelativeHeight
              * (double) weight / (double) totalRelativeWeight);
        }
        widgetWidth = widgetWidths[i];

        if (!fill) {
          switch (horizontalAlignment) {
          case LEFT:
            x = boxModel.getPadding().left;
            break;
          case CENTER:
            x = (width - widgetWidth) / 2;
            break;
          case RIGHT:
            x = width - boxModel.getPadding().right - widgetWidth;
            break;
          case START:
            if (LocaleInfo.getCurrentLocale().isRTL()) {
              x = width - boxModel.getPadding().right
                  - widgetWidth;
            } else {
              x = boxModel.getPadding().left;
            }
            break;
          case END:
            if (!LocaleInfo.getCurrentLocale().isRTL()) {
              x = boxModel.getPadding().left;
            } else {
              x = width - boxModel.getPadding().right
                  - widgetWidth;
              break;
            }
          }
        } else {
          x = boxModel.getPadding().left;
        }

        // Set the component's size and position
        WidgetHelper.setSize(child, widgetWidth, widgetHeight);
        WidgetHelper.setLocation(child, x, y);
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

    int[] relativeWeights = new int[columnCount];
    boolean[] defaultWidthColumns = new boolean[columnCount];

    int totalRelativeWeight = 0;

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    // First, we calculate the base widths of the columns, giving relative
    // columns their preferred width

    for (int i = 0; i < columnCount; i++) {
      Grid.Column column = columns.get(i);
      boolean isRelative = column.isRelative();

      LayoutData layoutData = WidgetHelper.getLayoutData(column);
      String widthHint = layoutData.getPreferredWidth();

      defaultWidthColumns[i] = (widthHint == null);

      if (isRelative) {
        relativeWeights[i] = column.getWeight();
        totalRelativeWeight += relativeWeights[i];
      }

      int columnWidth;

      if (widthHint == null || isRelative) {
        columnWidth = getPreferredColumnWidth(i);
      } else {
        columnWidth = WidgetHelper.getPreferredWidth(column);
      }

      columnWidths[i] = columnWidth;
    }

    // Next, we adjust the widths of the relative columns upwards where
    // necessary to reconcile their widths relative to one another while
    // ensuring that they still get at least their preferred width

    if (totalRelativeWeight > 0) {
      int totalRelativeWidth = 0;

      // Calculate the total relative width after the required upward
      // adjustments

      for (int i = 0; i < columnCount; i++) {
        int columnWidth = columnWidths[i];
        int relativeWeight = relativeWeights[i];

        if (relativeWeight > 0) {
          float weightPercentage = relativeWeight
              / (float) totalRelativeWeight;
          totalRelativeWidth = Math.max(totalRelativeWidth,
              (int) (columnWidth / weightPercentage));
        }
      }

      // Perform the upward adjustments using the total relative width

      for (int i = 0; i < columnCount; i++) {
        int relativeWeight = relativeWeights[i];

        if (relativeWeight > 0) {
          float weightPercentage = relativeWeight
              / (float) totalRelativeWeight;
          columnWidths[i] = (int) (weightPercentage * totalRelativeWidth);
        }
      }
    }

    // Finally, we account for spanning cells, which have been ignored thus
    // far. If any spanned cell is default-width (including relative width
    // columns), then we ensure that the sum of the widths of the spanned
    // cells is enough to satisfy the preferred width of the spanning
    // content

    for (int i = 0; i < rowCount; i++) {
      Grid.Row row = rows.get(i);

      for (int j = 0, n = row.getWidgetCount(); j < n && j < columnCount; j++) {
        Widget widget = row.getWidget(j);

        if (widget != null && widget.isVisible()) {
          int columnSpan = WidgetHelper.getColumnSpan(widget);

          if (columnSpan > 1) {
            // We might need to adjust column widths to accommodate
            // this spanning cell. First, we find out if any of the
            // spanned cells are default width and how much space
            // we've allocated thus far for those cells

            int spannedDefaultWidthCellCount = 0;
            int spannedRelativeWeight = 0;
            int spannedWidth = 0;

            for (int k = 0; k < columnSpan && j + k < columnCount; k++) {
              if (defaultWidthColumns[j + k]) {
                spannedDefaultWidthCellCount++;
              }

              spannedRelativeWeight += relativeWeights[j + k];
              spannedWidth += columnWidths[j + k];
            }

            if (spannedRelativeWeight > 0
                || spannedDefaultWidthCellCount > 0) {
              int rowHeight = row.isRelative() ? -1
                  : WidgetHelper.getPreferredHeight(row);
              int widgetPreferredWidth = WidgetHelper
                  .getPreferredWidth(widget, rowHeight);

              if (widgetPreferredWidth > spannedWidth) {
                // The widget's preferred width is larger than
                // the width we've allocated thus far, so an
                // adjustment is necessary
                int adjustment = widgetPreferredWidth
                    - spannedWidth;

                if (spannedRelativeWeight > 0) {
                  // We'll distribute the adjustment across
                  // the spanned relative columns and adjust
                  // other relative column widths to keep all
                  // relative column widths reconciled
                  float unitAdjustment = adjustment
                      / (float) spannedRelativeWeight;

                  for (int k = 0; k < columnCount; k++) {
                    int relativeWeight = relativeWeights[k];

                    if (relativeWeight > 0) {
                      int columnAdjustment = Math
                          .round(unitAdjustment
                              * relativeWeight);

                      columnWidths[k] += columnAdjustment;
                    }
                  }
                } else {
                  // We'll distribute the adjustment evenly
                  // among the default-width columns
                  for (int k = 0; k < columnSpan
                      && j + k < columnCount; k++) {
                    if (defaultWidthColumns[j + k]) {
                      int columnAdjustment = adjustment
                          / spannedDefaultWidthCellCount;

                      columnWidths[j + k] += columnAdjustment;

                      // Adjust these to avoid rounding
                      // errors
                      adjustment -= columnAdjustment;
                      spannedDefaultWidthCellCount--;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    // The preferred width of the table is the sum of the column widths,
    // plus margin+border+padding and spacing

    boolean[][] occupiedCells = getOccupiedCells();
    int visibleColumnCount = 0;

    int preferredWidth = boxModel.getWidthContribution();

    for (int j = 0; j < columnCount; j++) {
      boolean columnVisible = false;

      for (int i = 0; i < rowCount; i++) {
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

    int[] relativeWeights = new int[rowCount];
    boolean[] defaultHeightRows = new boolean[rowCount];

    int totalRelativeWeight = 0;

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    if (clientWidth < 0) {
      clientWidth = getPreferredWidth(-1);
    }

    int[] columnWidths = getColumnWidths(clientWidth);

    // First, we calculate the base heights of the rows, giving relative
    // rows their preferred height

    for (int i = 0; i < rowCount; i++) {
      Grid.Row row = rows.get(i);
      boolean isRelative = row.isRelative();

      LayoutData layoutData = WidgetHelper.getLayoutData(row);
      String heightHint = layoutData.getPreferredHeight();

      defaultHeightRows[i] = (heightHint == null);

      if (isRelative) {
        relativeWeights[i] = row.getWeight();
        totalRelativeWeight += relativeWeights[i];
      }

      int rowHeight;

      if (layoutData.getPreferredHeight() == null || isRelative) {
        rowHeight = getPreferredRowHeight(i, columnWidths);
      } else {
        rowHeight = WidgetHelper.getPreferredHeight(row);
      }

      rowHeights[i] = rowHeight;
    }

    // Next, we adjust the heights of the relative rows upwards where
    // necessary to reconcile their heights relative to one another while
    // ensuring that they still get at least their preferred height

    if (totalRelativeWeight > 0) {
      int totalRelativeHeight = 0;

      // Calculate the total relative height after the required upward
      // adjustments

      for (int i = 0; i < rowCount; i++) {
        int rowHeight = rowHeights[i];
        int relativeWeight = relativeWeights[i];

        if (relativeWeight > 0) {
          float weightPercentage = relativeWeight
              / (float) totalRelativeWeight;
          totalRelativeHeight = Math.max(totalRelativeHeight,
              (int) (rowHeight / weightPercentage));
        }
      }

      // Perform the upward adjustments using the total relative height

      for (int i = 0; i < rowCount; i++) {
        int relativeWeight = relativeWeights[i];

        if (relativeWeight > 0) {
          float weightPercentage = relativeWeight
              / (float) totalRelativeWeight;
          rowHeights[i] = (int) (weightPercentage * totalRelativeHeight);
        }
      }
    }

    // Finally, we account for spanning cells, which have been ignored thus
    // far. If any spanned cell is default-height (including relative height
    // rows), then we ensure that the sum of the heights of the spanned
    // cells is enough to satisfy the preferred height of the spanning
    // content

    for (int i = 0; i < rowCount; i++) {
      Grid.Row row = rows.get(i);

      for (int j = 0, n = row.getWidgetCount(); j < n && j < columnCount; j++) {
        Widget widget = row.getWidget(j);

        if (widget != null && widget.isVisible()) {
          int rowSpan = WidgetHelper.getRowSpan(widget);

          if (rowSpan > 1) {
            // We might need to adjust row heights to accomodate
            // this spanning cell. First, we find out if any of the
            // spanned cells are default height and how much space
            // we've allocated thus far for those cells

            int spannedDefaultHeightCellCount = 0;
            int spannedRelativeWeight = 0;
            int spannedHeight = 0;

            for (int k = 0; k < rowSpan && i + k < rowCount; k++) {
              if (defaultHeightRows[i + k]) {
                spannedDefaultHeightCellCount++;
              }

              spannedRelativeWeight += relativeWeights[i + k];
              spannedHeight += rowHeights[i + k];
            }

            if (spannedRelativeWeight > 0
                || spannedDefaultHeightCellCount > 0) {
              int widgetPreferredHeight = WidgetHelper
                  .getPreferredHeight(widget, columnWidths[j]);

              if (widgetPreferredHeight > spannedHeight) {
                // The widget's preferred height is larger
                // than the height we've allocated thus far, so
                // an adjustment is necessary
                int adjustment = widgetPreferredHeight
                    - spannedHeight;

                if (spannedRelativeWeight > 0) {
                  // We'll distribute the adjustment across
                  // the spanned relative rows and adjust
                  // other relative row heights to keep all
                  // relative row heights reconciled
                  float unitAdjustment = adjustment
                      / (float) spannedRelativeWeight;

                  for (int k = 0; k < rowCount; k++) {
                    int relativeWeight = relativeWeights[k];

                    if (relativeWeight > 0) {
                      int rowAdjustment = Math
                          .round(unitAdjustment
                              * relativeWeight);

                      rowHeights[k] += rowAdjustment;
                    }
                  }
                } else {
                  // We'll distribute the adjustment evenly
                  // among the default-height rows
                  for (int k = 0; k < rowSpan
                      && i + k < rowCount; k++) {
                    if (defaultHeightRows[i + k]) {
                      int rowAdjustment = adjustment
                          / spannedDefaultHeightCellCount;

                      rowHeights[i + k] += rowAdjustment;

                      // Adjust these to avoid rounding
                      // errors
                      adjustment -= rowAdjustment;
                      spannedDefaultHeightCellCount--;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    // The preferred height of the table pane is the sum of the row
    // heights, plus padding and spacing

    boolean[][] occupiedCells = getOccupiedCells();
    int visibleRowCount = 0;

    int preferredHeight = boxModel.getHeightContribution();

    for (int i = 0; i < rowCount; i++) {
      boolean rowVisible = false;

      for (int j = 0; j < columnCount; j++) {
View Full Code Here

Examples of gwt.mosaic.client.style.BoxModel

    int[] rowHeights = getRowHeights(height, columnWidths);
    boolean[][] occupiedCells = getOccupiedCells();

    int baseline = -1;

    BoxModel boxModel = WidgetHelper.getBoxModel(this);

    int rowY = boxModel.getPadding().top; // XXX

    for (int i = 0; i < rowCount && baseline == -1; i++) {
      Grid.Row row = rows.get(i);
      boolean rowVisible = false;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.