Ejemplo n.º 1
0
  /**
   * Returns a short string representation of this constraints object. This method can use the given
   * <code>FormLayout</code> to display extra information how default alignments are mapped to
   * concrete alignments. Therefore it asks the related column and row as specified by this
   * constraints object.
   *
   * @param layout the layout to be presented as a string
   * @return a short string representation of this constraints object
   */
  public String toShortString(FormLayout layout) {
    StringBuffer buffer = new StringBuffer("(");
    buffer.append(formatInt(gridX));
    buffer.append(", ");
    buffer.append(formatInt(gridY));
    buffer.append(", ");
    buffer.append(formatInt(gridWidth));
    buffer.append(", ");
    buffer.append(formatInt(gridHeight));
    buffer.append(", \"");
    buffer.append(hAlign.abbreviation());
    if (hAlign == DEFAULT && layout != null) {
      buffer.append('=');
      ColumnSpec colSpec = gridWidth == 1 ? layout.getColumnSpec(gridX) : null;
      buffer.append(concreteAlignment(hAlign, colSpec).abbreviation());
    }
    buffer.append(", ");
    buffer.append(vAlign.abbreviation());
    if (vAlign == DEFAULT && layout != null) {
      buffer.append('=');
      RowSpec rowSpec = gridHeight == 1 ? layout.getRowSpec(gridY) : null;
      buffer.append(concreteAlignment(vAlign, rowSpec).abbreviation());
    }
    buffer.append("\"");
    if (!(EMPTY_INSETS.equals(insets))) {
      buffer.append(", ");
      buffer.append(insets);
    }

    buffer.append(')');
    return buffer.toString();
  }
Ejemplo n.º 2
0
 /**
  * Sets the component's bounds using the given component and cell bounds.
  *
  * @param c the component to set bounds
  * @param layout the FormLayout instance that computes the bounds
  * @param cellBounds the cell's bounds
  * @param minWidthMeasure measures the minimum width
  * @param minHeightMeasure measures the minimum height
  * @param prefWidthMeasure measures the preferred width
  * @param prefHeightMeasure measures the preferred height
  */
 void setBounds(
     Control c,
     FormLayout layout,
     Rectangle cellBounds,
     FormLayout.Measure minWidthMeasure,
     FormLayout.Measure minHeightMeasure,
     FormLayout.Measure prefWidthMeasure,
     FormLayout.Measure prefHeightMeasure) {
   ColumnSpec colSpec = gridWidth == 1 ? layout.getColumnSpec(gridX) : null;
   RowSpec rowSpec = gridHeight == 1 ? layout.getRowSpec(gridY) : null;
   Alignment concreteHAlign = concreteAlignment(this.hAlign, colSpec);
   Alignment concreteVAlign = concreteAlignment(this.vAlign, rowSpec);
   Insets concreteInsets = this.insets != null ? this.insets : EMPTY_INSETS;
   int cellX = cellBounds.x + concreteInsets.getLeft();
   int cellY = cellBounds.y + concreteInsets.getTop();
   int cellW = cellBounds.width - concreteInsets.getLeft() - concreteInsets.getRight();
   int cellH = cellBounds.height - concreteInsets.getTop() - concreteInsets.getBottom();
   int compW = componentSize(c, colSpec, cellW, minWidthMeasure, prefWidthMeasure);
   int compH = componentSize(c, rowSpec, cellH, minHeightMeasure, prefHeightMeasure);
   int x = origin(concreteHAlign, cellX, cellW, compW);
   int y = origin(concreteVAlign, cellY, cellH, compH);
   int w = extent(concreteHAlign, cellW, compW);
   int h = extent(concreteVAlign, cellH, compH);
   c.setBounds(x, y, w, h);
 }