Package org.eclipse.jst.pagedesigner.css2

Examples of org.eclipse.jst.pagedesigner.css2.ICSSStyle


    }
  }

  private void setFontinfoForLine(LineBox line) {

    ICSSStyle style = getCSSStyle();
    if (style != null) {
      line.setFontMetrics(FigureUtilities.getFontMetrics(style
          .getCSSFont().getSwtFont()));
    }
  }
View Full Code Here


   */
  protected void preLayout() {
    // super.preLayout will setup the block box.
    super.preLayout();

    ICSSStyle style = this.getCSSStyle();

    _hspacing = _vspacing = 3; // default value

    if (style != null) {
      Object borderspacing = style
          .getStyleProperty(ICSSPropertyID.ATTR_BORDER_SPACING);
      if (borderspacing instanceof int[]) {
        int[] intvalues = (int[]) borderspacing;
        _hspacing = intvalues[0];
        _vspacing = intvalues[1];
      } else {
        ITagEditInfo info = (ITagEditInfo) style
            .getAdapter(ITagEditInfo.class);
        if (info != null && info.needTableDecorator()) {
          // default decorating value. to make things look more
          // separated.
          if (_hspacing < 5) {
            _hspacing = 5;
          }
          if (_vspacing < 5) {
            _vspacing = 5;
          }
        }
      }
    }

    // TODO: support caption
    _tableInfo = new TableInfo(getCSSFigure());

    // construct the table structure.
    _tableInfo.constructTable();

    // calculate the user specified width/height for table and cells.
    // contentWidth is the user specified content width. If <= 0 means no
    // user
    // specification.
    int contentWidth = this._blockBox.getContentWidth();
    int availableWidth = this._blockBox.getRecommendedContentWidth();
    int contentHeight = this._blockBox.getContentHeight();

    _tableInfo.calculateWidth(contentWidth, availableWidth);
    _tableInfo.calculateHeight(contentHeight);

    int columnCount = _tableInfo.getColumnCount();

    int columnMinWidths[] = new int[columnCount];
    int columnMaxWidths[] = new int[columnCount];

    // For each column, determine a maximum and minimum column width from
    // the cells that span only that column. The minimum is that required by
    // the cell with the largest minimum cell width (or the column 'width',
    // whichever is larger). The maximum is that required by the cell with
    // the
    // largest maximum cell width (or the column 'width', whichever is
    // larger).
    List cells = _tableInfo.getCells();
    for (int i = 0, size = cells.size(); i < size; i++) {
      TableCellInfo cellinfo = (TableCellInfo) cells.get(i);
      if (cellinfo.getColSpan() == 1) {
        int column = cellinfo.getColumnIndex();
        Dimension mincw = cellinfo.getMinCWDimension();
        Dimension maxcw = cellinfo.getMaxCWDimension();
        if (maxcw.width < mincw.width) {
          maxcw.width = mincw.width;
        }
        if (mincw.width > columnMinWidths[column]) {
          columnMinWidths[column] = mincw.width;
        }
        if (maxcw.width > columnMaxWidths[column]) {
          columnMaxWidths[column] = maxcw.width;
        }
      }
    }
    // For caption, determine a maximum and minimum width from it.
    int captionWidth = 0;
    if (_tableInfo.getCaption() != null) {
      captionWidth = _tableInfo.getCaption().getDimension().width;
    }

    // For each cell that spans more than one column, increase the
    // minimum widths of the columns it spans so that together, they
    // are at least as wide as the cell. Do the same for the maximum
    // widths. If possible, widen all spanned columns by approximately
    // the same amount.
    for (int i = 0, size = cells.size(); i < size; i++) {
      TableCellInfo cellinfo = (TableCellInfo) cells.get(i);
      int colspan = cellinfo.getColSpan();
      if (colspan > 1) {
        int column = cellinfo.getColumnIndex();
        Dimension mincw = cellinfo.getMinCWDimension();
        Dimension maxcw = cellinfo.getMaxCWDimension();

        adjustWidth(column, colspan, mincw.width, columnMinWidths);
        adjustWidth(column, colspan, maxcw.width, columnMaxWidths);
      }
    }

    int sigmaMinWidth = 0;
    int sigmaMaxWidth = 0;
    for (int i = 0; i < columnMinWidths.length; i++) {
      sigmaMinWidth += columnMinWidths[i];
      if (columnMaxWidths[i] == Integer.MAX_VALUE) {
        sigmaMaxWidth = Integer.MAX_VALUE;
      } else if (sigmaMaxWidth != Integer.MAX_VALUE) {
        sigmaMaxWidth += columnMaxWidths[i];
        if (sigmaMaxWidth < 0) {
          sigmaMaxWidth = Integer.MAX_VALUE;
        }
      }
    }
    int spacingall = (columnMinWidths.length + 1) * _hspacing;
    sigmaMinWidth += spacingall;
    if (sigmaMaxWidth != Integer.MAX_VALUE) {
      sigmaMaxWidth += spacingall;
      if (sigmaMaxWidth < 0) {
        sigmaMaxWidth = Integer.MAX_VALUE;
      }
    }

    int tableWidth = _tableInfo.getTableWidth();
    if (tableWidth > 0) {
      // If the 'table' or 'inline-table' element's 'width' property has a
      // specified value (W) other than 'auto', the property's computed
      // value
      // is the greater of W and the minimum width required by all the
      // columns
      // plus cell spacing or borders (MIN). If W is greater than MIN, the
      // extra
      // width should be distributed over the columns.
      int maxMin = Math.max(captionWidth, sigmaMinWidth);
      if (maxMin >= tableWidth) {
        tableWidth = maxMin;
      }
      distribute(tableWidth - sigmaMinWidth, columnMinWidths,
          columnMaxWidths);
    } else {
      // If the 'table' or 'inline-table' element has 'width: auto', the
      // computed
      // table width is the greater of the table's containing block width
      // and MIN.
      // However, if the maximum width required by the columns plus cell
      // spacing or
      // borders (MAX) is less than that of the containing block, use MAX.
      // int availableWidth = this.getCurrentLine().getAvailableWidth();
      int maxMin = Math.max(captionWidth, sigmaMaxWidth);
      if (maxMin <= availableWidth) {
        // TODO: if _tableInfo.hasWidthPercentage, then we need take
        // that into consideration
        // to distribute the column width. Left to next version.
        tableWidth = maxMin;
        // columnMinWidths = columnMaxWidths;
      } else {
        tableWidth = availableWidth;
      }
      distribute(tableWidth - sigmaMinWidth, columnMinWidths,
          columnMaxWidths);
    }

    // now columnMinWidths contains width for each column
    _columnWidths = columnMinWidths;

    // ok, we have finished calculating column width.
    // next we need to find out row heights.
    _rowHeights = new int[_tableInfo.getRowCount()];

    // first find out those TR that has height settings and use them.
    List rows = _tableInfo.getRows();
    for (int i = 0, size = rows.size(); i < size && i < _rowHeights.length; i++) {
      TableRowInfo rowInfo = (TableRowInfo) rows.get(i);
      if (rowInfo.getSpecifiedRowHeight() > 0) {
        _rowHeights[i] = rowInfo.getSpecifiedRowHeight();
      }
    }

    // First the cells don't span multiple rows.
    cells = _tableInfo.getCells();
    for (int i = 0, size = cells.size(); i < size; i++) {
      TableCellInfo cellinfo = (TableCellInfo) cells.get(i);
      IFigure figure = cellinfo.getFigure();
      int rowspan = cellinfo.getRowSpan();
      if (rowspan == 1) {
        int cellWidth = getCellWidth(cellinfo, _columnWidths);
        Dimension d = figure.getPreferredSize(cellWidth, cellinfo
            .getHeight());
        if (d.height > _rowHeights[cellinfo.getRowIndex()]) {
          _rowHeights[cellinfo.getRowIndex()] = d.height;
        }
      }
    }

    // Next those cells span multiple rows.
    cells = _tableInfo.getCells();
    for (int i = 0, size = cells.size(); i < size; i++) {
      TableCellInfo cellinfo = (TableCellInfo) cells.get(i);
      IFigure figure = cellinfo.getFigure();
      int rowspan = cellinfo.getRowSpan();
      if (rowspan > 1) {
        int cellWidth = getCellWidth(cellinfo, _columnWidths);
        Dimension d = figure.getPreferredSize(cellWidth, cellinfo
            .getHeight());
        if (d.height > getCellHeight(cellinfo, _rowHeights)) {
          adjustHeight(cellinfo.getRowIndex(), rowspan, d.height,
              _rowHeights);
        }
      }
    }

    // Next we may need distribute height.
    int sigmaHeight = (_tableInfo.getRowCount() + 1) * _vspacing;
    for (int i = 0; i < _rowHeights.length; i++) {
      sigmaHeight += _rowHeights[i];
    }
    if (sigmaHeight < contentHeight) {
      distributeHeights(contentHeight - sigmaHeight, _rowHeights);
    }

    // now we have calculated the width and height of all cells.
    // FIXME: border?
    Insets insets = (style == null ? new Insets() : style.getBorderInsets()
        .getAdded(style.getPaddingInsets()));
    _internalTableWidth = (_tableInfo.getColumnCount() + 1) * _hspacing;
    for (int i = 0; i < _columnWidths.length; i++) {
      _internalTableWidth += _columnWidths[i];
    }
    int minWidth = getLengthValue(style, ICSSPropertyID.ATTR_MIN_WIDTH);
View Full Code Here

   * (non-Javadoc)
   *
   * @see org.eclipse.jst.pagedesigner.css2.layout.ICSSPainter#paintFigure(org.eclipse.draw2d.Graphics)
   */
  public void paintFigure(Graphics g) {
    ICSSStyle style = this.getCSSStyle();
    if (style != null) {
      ITagEditInfo info = (ITagEditInfo) style
          .getAdapter(ITagEditInfo.class);
      if (info != null && info.needTableDecorator()) {
        List cells = _tableInfo.getCells();
        for (int i = 0, size = cells.size(); i < size; i++) {
          TableCellInfo cellInfo = (TableCellInfo) cells.get(i);
View Full Code Here

  /**
   * @param figure
   */
  public TableCaptionInfo(ICSSFigure figure) {
    super(figure);
    ICSSStyle style = figure.getCSSStyle();
    if (style != null) {
      _align = style.getStyleProperty(
          ICSSPropertyID.ATTR_HORIZONTAL_ALIGN).toString();
    }
  }
View Full Code Here

  /**
   * @return true if should expand the width to all available width.
   */
  public boolean shouldExpand() {
    ICSSStyle style = getCSSStyle();
    if (style == null) {
      return false;
    }
        return "block".equalsIgnoreCase(style.getDisplay()) //$NON-NLS-1$
            || "list-item".equalsIgnoreCase(style.getDisplay()); //$NON-NLS-1$
  }
View Full Code Here

      if (lineBox != null && !lineBox.isEmptyStringLine()) {
        getFlowContext().endLine();
      }
    }

    ICSSStyle style = getCSSStyle();

    // endLine will result in context create a new line, so we are in the
    // new line now.
    // passing in the top margin, and context will consider that when create
    // the new line.
    int marginTop = style.getMarginInsets().top;
    LineBox line = getFlowContext().getCurrentLine(marginTop);

    // Setup the one fragment for this Block with the correct X and
    // available width

    // FIXME: according to spec, when using percentage width/height, should
    // percentage to
    // the "containing block". But we don't have very good "containing
    // block" resolution
    // implementation yet.

    // calculate the min size
    // int minWidth = 0;
    // int minHeight = 0;
    // if (style != null)
    // {
    // // try to see whether there is any designer specified min size
    // ITagEditInfo info = (ITagEditInfo)
    // style.getAdapter(ITagEditInfo.class);
    // if (info != null)
    // {
    // minWidth = info.getMinWidth();
    // minHeight = info.getMinHeight();
    // }
    //
    // // CSS also has the min-width/min-height property. We should also get
    // that,
    // // and using the max of the "min-width" css property and the designer
    // specified min size.
    // int height = getLengthValue(style,ICSSPropertyID.ATTR_MIN_HEIGHT);
    // if(height > minHeight)
    // {
    // minHeight = height;
    // }
    // int width = getLengthValue(style,ICSSPropertyID.ATTR_MIN_WIDTH);
    // if(width > minWidth)
    // {
    // minWidth = width;
    // }
    // }

    // keep track of user specified size, this will be used when handling
    // the "overflow" CSS property.
    _userSpecifiedWidth = 0;
    _userSpecifiedHeight = 0;

    {
      int width = getLengthValue(style, ICSSPropertyID.ATTR_WIDTH);

      int availableWidth = line.getAvailableWidth()
          - style.getMarginInsets().getWidth();
      if (width <= 0) {
        // no width setting
        if (isCalculatingMaxWidth()) {
          _blockBox.setRecommendedWidth(Integer.MAX_VALUE);
          // _blockBox.setWidth( (minWidth>0?minWidth:0));
        } else {
          _blockBox.setRecommendedWidth(availableWidth);
          if (shouldExpand()) {
            _blockBox.setWidth(availableWidth);
          } else {
            // _blockBox.setWidth( (minWidth>0?minWidth:0));
          }
        }
      } else {
        int w = width;
        if (!style.isSizeIncludeBorderPadding()) {
          w += style.getBorderInsets().getWidth()
              + style.getPaddingInsets().getWidth();
        }
        // XXX: should we use minWidth or follow user's choice?
        // if (w < minWidth)
        // {
        // w = minWidth;
        // }
        _userSpecifiedWidth = w;
        _blockBox.setWidth(w);
        _blockBox.setRecommendedWidth(w);
      }
    }

    {
      int height = getLengthValue(style, ICSSPropertyID.ATTR_HEIGHT);
      // Object height =
      // style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT);
      // Length heightLength = (height instanceof Length) ? (Length)
      // height : null;

      if (height <= 0) {
        // if (minHeight > 0)
        // {
        // // _blockBox.setHeight(minHeight);
        // _blockBox.setRecommendedHeight(minHeight);
        // }
        // else
        {
          _blockBox.setHeight(0);
          _blockBox.setRecommendedHeight(0);
        }
      } else {
        int h = height;
        if (handlingBorderForBlock()
            && !style.isSizeIncludeBorderPadding()) {
          h += style.getBorderInsets().getHeight()
              + style.getPaddingInsets().getHeight();
        }
        // XXX: should we follow minHeight or user's choice?
        // if (minHeight > h)
        // {
        // h = minHeight;
        // }
        _userSpecifiedHeight = h;
        _blockBox.setHeight(h);
        _blockBox.setRecommendedHeight(h);
      }
    }
    _blockBox.setMarginInsets(new Insets(style.getMarginInsets()));
    if (handlingBorderForBlock()) {
      BoxUtil.setupBorderPaddingMargin(_blockBox, getCSSStyle());
    }

    // as in designer, we don't want to the element to have zero size, so
View Full Code Here

  /**
   * @param context
   */
  public void calculateCellInfo(TableInfoContext context) {
    ICSSStyle style = this.getStyle();
    _rowSpan = style.getRowSpan();
    _colSpan = style.getColSpan();

    // FIXME: we don't support rowspan and colspan to be 0.
    // by spec, 0 means span from current col/row to end.
    if (_rowSpan <= 0) {
      _rowSpan = 1;
View Full Code Here

   * @param tableInfo
   * @param tablewidth
   *            table width
   */
  public void calculateWidth(TableInfo tableInfo, int tablewidth) {
    ICSSStyle style = this.getFigure().getCSSStyle();
    if (style == null) {
      _cellWidth = -1;
    } else {
      Object width = style.getStyleProperty(ICSSPropertyID.ATTR_WIDTH);
      Length recommendedWidth = (width instanceof Length) ? (Length) width
          : null;

      int rw = 0;
      if (recommendedWidth == null || recommendedWidth.getValue() <= 0) {
        rw = 0;
      } else {
        if (recommendedWidth.isPercentage()) {
          // percentage width is used for remaining width
          // distribution, so not used here.
          int colspan = this.getColSpan();
          for (int i = 0; i < colspan; i++) {
            tableInfo.setWidthPercentage(this.getColumnIndex() + i,
                recommendedWidth.getValue() / colspan);
          }
        } else {
          rw = recommendedWidth.getValue();
          if (!style.isSizeIncludeBorderPadding()) {
            rw += style.getBorderInsets().getWidth()
                + style.getPaddingInsets().getWidth();
          }
          if (this.getColSpan() == 1) {
            tableInfo.getWidthSpecified()[this.getColumnIndex()] = true;
          }
        }
View Full Code Here

  /**
   * @param tableInfo
   * @param tableheight
   */
  public void calculateHeight(TableInfo tableInfo, int tableheight) {
    ICSSStyle style = this.getFigure().getCSSStyle();
    if (style == null) {
      _cellHeight = -1;
    } else {
      Object height = style.getStyleProperty(ICSSPropertyID.ATTR_HEIGHT);
      Length recommendedHeight = (height instanceof Length) ? (Length) height
          : null;

      int rh = 0;
      if (recommendedHeight == null || recommendedHeight.getValue() <= 0) {
        rh = 0;
      } else {
        if (recommendedHeight.isPercentage()) {
          int rowspan = this.getRowSpan();
          for (int i = 0; i < rowspan; i++) {
            tableInfo.setHeightPercentage(this.getRowIndex() + i,
                recommendedHeight.getValue() / rowspan);
          }
        } else {
          rh = recommendedHeight.getValue();
        }
        if (!style.isSizeIncludeBorderPadding()) {
          rh += style.getBorderInsets().getHeight()
              + style.getPaddingInsets().getHeight();
        }
      }
      _cellHeight = rh;
    }

View Full Code Here

    }
    return lengthValue;
  }

  private void setBlockVerticalAlign(BlockBox box) {
    ICSSStyle style = getCSSStyle();
    if (style != null) {
      box.setVerticalAlignData(style
          .getStyleProperty(ICSSPropertyID.ATTR_VERTICAL_ALIGN));
    }
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jst.pagedesigner.css2.ICSSStyle

Copyright © 2018 www.massapicom. 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.