Ejemplo n.º 1
0
  /**
   * @inheritDoc このクラスではパネルを正方形に使います。
   * @see IgoOutlinePanel#setSizeHint(Point)
   */
  public void setSizeHint(Point boardSize) {
    ArgumentChecker.throwIfNull(boardSize);

    GridData gridData;
    gridData = (GridData) frame_.getLayoutData();
    gridData.widthHint = boardSize.x;

    int margin = ((GridLayout) frame_.getLayout()).marginWidth;
    gridData = (GridData) boardControl_.getLayoutData();
    gridData.widthHint = boardSize.x - frame_.getBorderWidth() * 2 - margin * 2;
    gridData.heightHint = boardSize.y - frame_.getBorderWidth() * 2 - margin * 2;

    gridData = (GridData) annotationLabel_.getLayoutData();
    gridData.widthHint = boardSize.x - frame_.getBorderWidth() * 2 - margin * 2;
  }
  private void layout(final Composite c) {
    // System.out.println("Layout" + System.currentTimeMillis());
    final Table table = (Table) c;
    Rectangle bounds = table.getBounds();
    Rectangle clientArea = table.getClientArea();
    if (WindowSystem.isGTK()) {
      bounds = table.getClientArea();
    } else {
      bounds = table.getBounds();
    }

    int displayedWidth = 0;

    int heightFilledByRows = table.getItemCount() * table.getItemHeight() + table.getHeaderHeight();
    if (firstTime) {
      displayedWidth = bounds.width - 2 * c.getBorderWidth() + widthAdjustValue;
      if (bounds.height < heightFilledByRows) {
        displayedWidth += -table.getVerticalBar().getSize().x;
      }
    } else {
      if (WindowSystem.isGTK()) {
        heightFilledByRows -= table.getHeaderHeight();
      }

      if (fillHorizontal) {
        if (bounds.height < heightFilledByRows) {
          displayedWidth = clientArea.width + widthAdjustValue;
        } else {
          displayedWidth = bounds.width + widthAdjustValue;
        }
        referenceWidth = displayedWidth;
        lastDisplayedWidth = displayedWidth;

      } else {
        int newVisibleWidth = bounds.width + widthAdjustValue;
        if (bounds.height < heightFilledByRows) {
          newVisibleWidth += -table.getVerticalBar().getSize().x;
        }

        displayedWidth =
            referenceWidth - 2 * c.getBorderWidth() - (lastDisplayedWidth - newVisibleWidth);
      }
    }

    if (firstTime) {
      referenceWidth = displayedWidth;
      lastDisplayedWidth = displayedWidth;
    }

    // XXX: Layout is being called with an invalid value the first time
    // it is being called on Linux. This method resets the
    // Layout to null so we make sure we run it only when
    // the value is OK.
    if (displayedWidth <= 1) {
      return;
    }

    Item[] tableColumns = getColumns(c);
    int size = Math.min(columnsLayoutData.size(), tableColumns.length);
    int[] widths = new int[size];
    int fixedWidth = 0;
    int numberOfWeightColumns = 0;
    int totalWeight = 0;

    // First calc space occupied by fixed columns
    for (int i = 0; i < size; i++) {
      ColumnLayoutData col = (ColumnLayoutData) columnsLayoutData.get(i);
      if (col instanceof ColumnPixelData) {
        ColumnPixelData cpd = (ColumnPixelData) col;
        int pixels = cpd.width;
        if (cpd.addTrim) {
          pixels += COLUMN_TRIM;
        }
        widths[i] = pixels;
        fixedWidth += pixels;
      } else if (col instanceof ColumnWeightData) {
        ColumnWeightData cw = (ColumnWeightData) col;
        numberOfWeightColumns++;
        // first time, use the weight specified by the column data,
        // otherwise use the actual width as the weight
        // int weight = firstTime ? cw.weight :
        // tableColumns[i].getWidth();
        int weight = cw.weight;
        totalWeight += weight;
      } else {
        Assert.isTrue(false, "Unknown column layout data"); // $NON-NLS-1$
      }
    }

    // Do we have columns that have a weight
    if (numberOfWeightColumns > 0) {
      // Now distribute the rest to the columns with weight.
      int rest = displayedWidth - fixedWidth;
      int totalDistributed = 0;
      for (int i = 0; i < size; ++i) {
        ColumnLayoutData col = (ColumnLayoutData) columnsLayoutData.get(i);
        if (col instanceof ColumnWeightData) {
          ColumnWeightData cw = (ColumnWeightData) col;
          // calculate weight as above
          // int weight = firstTime ? cw.weight :
          // tableColumns[i].getWidth();
          int weight = cw.weight;
          int pixels = totalWeight == 0 ? 0 : weight * rest / totalWeight;
          if (pixels < cw.minimumWidth) {
            pixels = cw.minimumWidth;
          }
          totalDistributed += pixels;
          widths[i] = pixels;
        }
      }

      // Distribute any remaining pixels to columns with weight.
      int diff = rest - totalDistributed;
      for (int i = 0; diff > 0; ++i) {
        if (i == size) {
          i = 0;
        }
        ColumnLayoutData col = (ColumnLayoutData) columnsLayoutData.get(i);
        if (col instanceof ColumnWeightData) {
          ++widths[i];
          --diff;
        }
      }
    }

    columnsResizingByLayout = true;

    final boolean previousVisible = table.getVisible();
    if (previousVisible) {
      table.setVisible(false);
    }

    for (int i = 0; i < size; i++) {
      setWidth(tableColumns[i], widths[i]);
    }
    table.setVisible(previousVisible);
    columnsResizingByLayout = false;
    firstTime = false;
  }