@Override
 public void relocate(IFigure target) {
   if (constraint.y == 0) {
     if (durationConstraintEditPart.getCurrentSideOfParent() == PositionConstants.WEST) {
       Point r = parentFigure.getBounds().getLeft().translate(-20, -5);
       target.setBounds(new Rectangle(r, target.getPreferredSize()));
     } else {
       Point r = parentFigure.getBounds().getRight().translate(5, -5);
       target.setBounds(new Rectangle(r, target.getPreferredSize()));
     }
   } else super.relocate(target);
 }
示例#2
0
  private double getFitXZoomLevel(int which) {
    IFigure fig = getScalableFigure();

    Dimension available = getViewport().getClientArea().getSize();
    Dimension desired;
    if (fig instanceof FreeformFigure) {
      desired = ((FreeformFigure) fig).getFreeformExtent().getCopy().union(0, 0).getSize();
    } else {
      desired = fig.getPreferredSize().getCopy();
    }

    desired.width -= fig.getInsets().getWidth();
    desired.height -= fig.getInsets().getHeight();

    while (fig != getViewport()) {
      available.width -= fig.getInsets().getWidth();
      available.height -= fig.getInsets().getHeight();
      fig = fig.getParent();
    }

    double scaleX = Math.min(available.width * zoom / desired.width, getMaxZoom());
    double scaleY = Math.min(available.height * zoom / desired.height, getMaxZoom());
    if (which == 0) {
      return scaleX;
    }
    if (which == 1) {
      return scaleY;
    }
    return Math.min(scaleX, scaleY);
  }
  @SuppressWarnings("rawtypes")
  public void layout(IFigure parent) {
    Rectangle relativeArea = parent.getClientArea();
    constrainedData.area = transposer.t(relativeArea);

    // parent may not be set yet
    if (relativeArea.width == 0) return;

    Iterator iterator = parent.getChildren().iterator();
    int dx;

    initVariables(parent);
    initRow();
    int i = 0;
    while (iterator.hasNext()) {
      IFigure f = (IFigure) iterator.next();

      Rectangle bounds = getConstraint(f);

      // -- There is a constraint, process width and height
      int widthHint = bounds.width;
      int heightHint = bounds.height;
      if (widthHint == -1 || heightHint == -1) {
        Dimension _preferredSize = f.getPreferredSize(widthHint, heightHint);
        bounds = bounds.getCopy();
        if (widthHint == -1) bounds.width = _preferredSize.width;
        if (heightHint == -1) bounds.height = _preferredSize.height;
      }
      Dimension min = f.getMinimumSize(widthHint, heightHint);
      Dimension max = f.getMaximumSize();

      if (min.width > bounds.width) bounds.width = min.width;
      else if (max.width < bounds.width) bounds.width = max.width;

      if (min.height > bounds.height) bounds.height = min.height;
      else if (max.height < bounds.height) bounds.height = max.height;

      Rectangle r = new Rectangle(0, 0, bounds.width, bounds.height);

      if (constrainedData.rowCount > 0) {
        if (constrainedData.rowWidth + bounds.width > constrainedData.maxWidth) layoutRow(parent);
      }
      r.x = constrainedData.rowX;
      r.y = constrainedData.rowY;
      dx = r.width + getMinorSpacing();
      constrainedData.rowX += dx;
      constrainedData.rowWidth += dx;
      constrainedData.rowHeight = Math.max(constrainedData.rowHeight, r.height);
      constrainedData.row[constrainedData.rowCount] = f;
      constrainedData.bounds[constrainedData.rowCount] = r;
      constrainedData.rowCount++;
      i++;
    }
    if (constrainedData.rowCount != 0) layoutRow(parent);
    totalHeight = constrainedData.rowY;
    constrainedData.rowY = 0;
  }
  protected void doFillPlusMinus(IBranchPart branch, IPlusMinusPart plusMinus, LayoutInfo info) {
    Point ref = info.getReference();
    int x = ref.x;

    Rectangle topicBounds = info.getCheckedClientArea();
    int y = topicBounds.bottom();

    IFigure pmFigure = plusMinus.getFigure();
    Dimension size = pmFigure.getPreferredSize();
    Rectangle r = new Rectangle(x - size.width / 2, y, size.width, size.height);
    info.put(pmFigure, r);
  }
 @Override
 public void relocate(final IFigure targetFigure) {
   final Rectangle referenceBox = getReferenceBox().getCopy();
   getReferenceFigure().translateToAbsolute(referenceBox);
   targetFigure.translateToRelative(referenceBox);
   final Rectangle targetFigureBounds =
       new Rectangle(
           referenceBox
               .getBottomLeft()
               .getTranslated(
                   new Dimension(
                       (int) (relativeX * referenceBox.width)
                           + absoluteX
                           + referenceBox.width
                           - targetFigure.getBounds().width,
                       (int) (relativeY * referenceBox.height)
                           + absoluteY
                           - targetFigure.getPreferredSize().height)),
           targetFigure.getPreferredSize());
   targetFigure.setBounds(targetFigureBounds);
 }
    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.draw2d.ToolbarLayout#layout(org.eclipse.draw2d.IFigure)
     */
    @Override
    public void layout(IFigure parent) {
      final Rectangle clientArea = parent.getClientArea();
      int x = clientArea.x;
      int y = clientArea.y;
      final List children = parent.getChildren();
      int numChildren = children.size();

      int maxHeight = 0;
      for (int i = 0; i < numChildren; i++) {
        IFigure child = (IFigure) children.get(i);
        Dimension prefSize = getChildPreferredSize(child, clientArea.width, -1);
        maxHeight = Math.max(maxHeight, prefSize.height);
      }
      maxHeight = Math.max(maxHeight, clientArea.height);

      if (numChildren == 1) {
        IFigure child = (IFigure) children.get(0);
        Dimension prefSize = child.getPreferredSize(clientArea.width, -1);
        prefSize.width = Math.max(prefSize.width, clientArea.width);
        Rectangle newBounds = new Rectangle(x, y, prefSize.width, maxHeight);
        child.setBounds(newBounds);
      } else if (numChildren == 2) {
        int initExpressionWidth =
            (xmlTreePart.getViewer().getControl().getSize().x / 3 - 80 - 10) / 2;
        IFigure child = (IFigure) children.get(0);
        Rectangle newBounds = new Rectangle(x, y, initExpressionWidth, maxHeight);
        child.setBounds(newBounds);

        child = (IFigure) children.get(1);
        Dimension prefSize = child.getPreferredSize(clientArea.width, -1);
        prefSize.width = Math.max(prefSize.width, clientArea.width - initExpressionWidth);
        newBounds = new Rectangle(x + initExpressionWidth, y, prefSize.width, maxHeight);
        child.setBounds(newBounds);
      }
    }
 @Override
 public void relocate(IFigure target) {
   Rectangle bounds = target.getBounds().getCopy();
   Point location = null;
   if (parent instanceof ConnectorEditPart) {
     ConnectorEditPart connectorPart = (ConnectorEditPart) parent;
     PointList points = getPoints(connectorPart.getConnectionFigure());
     location = getPointForEnd(points);
   } else {
     // if the parent is any other edit part
     // use the bounds center
     location = parent.getFigure().getBounds().getCenter();
   }
   if (lastLocation == null) {
     lastLocation = location;
   }
   Dimension delta = location.getDifference(lastLocation);
   bounds.translate(delta.width, delta.height);
   lastLocation = location.getCopy();
   // if the current width is 0 then the
   // user has never set the width, calculate it
   // here using a maximum number of 400
   boolean cropWidth = false;
   if (bounds.width == 0) {
     Dimension preferred = target.getPreferredSize();
     bounds.width = preferred.width;
     bounds.width = Math.min(400, bounds.width);
     cropWidth = true;
   }
   if (bounds.width < target.getBorder().getInsets(target).getWidth()) {
     // do not allow resizing to zero
     bounds.width = target.getBorder().getInsets(target).getWidth();
   }
   // we must set the bounds to allow recalculation
   // of text height (wrapping)
   target.setBounds(bounds);
   target.validate();
   // adjust height to account for word wrapping
   bounds.height = getMinimumHeight(target);
   if (cropWidth) {
     // crop the width here, as this is not a user set
     // width and otherwise if near 400 may leave extra
     // slack
     bounds.width = getMinimumWidth(target);
   }
   target.setBounds(bounds);
 }
 /** @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure) */
 public void layout(IFigure container) {
   List children = container.getChildren();
   Rectangle rulerSize = container.getClientArea();
   for (int i = 0; i < children.size(); i++) {
     IFigure child = (IFigure) children.get(i);
     Dimension childSize = child.getPreferredSize();
     int position = ((Integer) getConstraint(child)).intValue();
     if (((RulerFigure) container).isHorizontal()) {
       childSize.height = rulerSize.height - 1;
       Rectangle.getSINGLETON().setLocation(position - (childSize.width / 2), rulerSize.y);
     } else {
       childSize.width = rulerSize.width - 1;
       Rectangle.getSINGLETON().setLocation(rulerSize.x, position - (childSize.height / 2));
     }
     Rectangle.getSINGLETON().setSize(childSize);
     child.setBounds(Rectangle.getSINGLETON());
   }
 }
  public void layout(IFigure parent) {
    Rectangle bounds = parent.getClientArea();

    for (Iterator i = parent.getChildren().iterator(); i.hasNext(); ) {
      IFigure child = (IFigure) i.next();

      Dimension r = null;
      if (!(child instanceof FreeformFigure)) {
        r = child.getPreferredSize();

        bounds.width = r.width;

        child.setBounds(bounds);

        bounds.x += r.width + getMinorSpacing();
      }
    }
  }
示例#10
0
 protected void layoutFigures(FigureCanvas fc) {
   Rectangle r = new Rectangle(fc.getViewport().getClientArea());
   if (vertical) r.transpose();
   Dimension size = blockFigure.getPreferredSize();
   Rectangle b =
       new Rectangle(
           r.x + size.width / 2,
           r.y + (r.height - SLOT_HEIGHT) / 2,
           r.width - size.width,
           SLOT_HEIGHT);
   int x = (int) (b.x + b.width * selectionRatio);
   int y = b.y + b.height - b.height / 2;
   Rectangle b2 = new Rectangle(x - size.width / 2, y - size.height / 2, size.width, size.height);
   if (vertical) {
     b.transpose();
     b2.transpose();
   }
   slotFigure.setBounds(b);
   blockFigure.setBounds(b2);
 }
  protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
    Dimension extent = null;

    for (Iterator i = container.getChildren().iterator(); i.hasNext(); ) {
      IFigure child = (IFigure) i.next();

      Dimension childSize = null;
      if (!(child instanceof FreeformFigure)) {
        childSize = child.getPreferredSize();
      }
      if (null != childSize) {
        if (null == extent) {
          extent = childSize.getCopy();
        } else {
          extent.width += childSize.width + getMinorSpacing();
          extent.height = Math.max(extent.height, childSize.height);
        }
      }
    }

    if (null != extent) {
      extent.union(container.getMinimumSize());
    } else {
      extent = container.getMinimumSize();
    }

    Insets insets = container.getInsets();
    if (null == extent) {
      extent = new Dimension(insets.getWidth(), insets.getHeight());
    } else {
      // compartment.translateToParent(extent);
      extent.expand(insets.getWidth(), insets.getHeight());
    }

    return extent;
  }
示例#12
0
  protected void fillSubBranches(
      IBranchPart branch, List<IBranchPart> subBranches, LayoutInfo info) {
    Rectangle area = info.getCheckedClientArea();

    Column2 col = getColumn(branch);
    Chart2 chart = col.getOwnedChart();
    int lineWidth = chart.getLineWidth();
    int cellSpacing = chart.getMinorSpacing();
    int itemSpacing = col.getMinorSpacing();

    IInsertion insertion = getCurrentInsertion(branch);
    RowHead insHead = (RowHead) MindMapUtils.getCache(branch, Spreadsheet.KEY_INSERTION_ROW_HEAD);

    int startX = info.getReference().x - col.getPrefCellWidth() / 2;
    int y = area.y + chart.getColHeadHeight() + cellSpacing / 2 + lineWidth;
    List<Row2> rows = chart.getRows();
    IInsertion rowIns =
        (IInsertion) MindMapUtils.getCache(chart.getTitle(), Spreadsheet.CACHE_ROW_INSERTION);
    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
      if (rowIns != null && rowIns.getIndex() == rowIndex) {
        y += rowIns.getSize().height + chart.getMinorSpacing() + lineWidth;
      }

      Row2 row = rows.get(rowIndex);
      int x = startX;
      boolean insertionInRow = insertion != null && row.getHead().equals(insHead);
      Cell2 cell = col.findCellByRow(row);
      if (cell != null) {
        info.add(new Rectangle(x, y, col.getPrefCellWidth(), cell.getContentHeight()));
        List<Item2> items = cell.getItems();
        int num = items.size();
        int itemY = y;
        for (int i = 0; i < num; i++) {
          Item2 item = items.get(i);
          if (insertionInRow && insertion.getIndex() == i) {
            Rectangle r = insertion.createRectangle(x, y);
            info.add(r);
            itemY += r.height + itemSpacing;
          }
          IBranchPart child = item.getBranch();
          IFigure childFigure = child.getFigure();
          Dimension size = childFigure.getPreferredSize();

          int bh = 0;
          if (!branch.getBoundaries().isEmpty()) {
            for (IBoundaryPart boundary : branch.getBoundaries()) {
              List<IBranchPart> enclosingBranches = boundary.getEnclosingBranches();
              if (child.equals(enclosingBranches.get(0))) {
                bh = boundary.getFigure().getInsets().top;
                if (boundary.getTitle() != null && boundary.getTitle().getFigure() != null) {
                  Dimension s = boundary.getTitle().getFigure().getPreferredSize();
                  bh = Math.max(bh, s.height);
                }
                List<ITopic> topics = boundary.getBoundary().getEnclosingTopics();
                if (topics.size() > 1) {
                  itemY += bh;
                }
                bh = 0;
              }
              if (child.equals(enclosingBranches.get(enclosingBranches.size() - 1))) {
                bh = boundary.getFigure().getInsets().bottom;
              }
            }
          }

          Rectangle childBounds = new Rectangle(x, itemY, size.width, size.height + 10);
          info.put(childFigure, childBounds);
          itemY += size.height + itemSpacing + bh;
        }
        if (insertionInRow && insertion.getIndex() == num) {
          info.add(insertion.createRectangle(x, y));
        }
      } else if (insertionInRow) {
        info.add(insertion.createRectangle(x, y));
      }
      y += row.getPrefCellHeight() + cellSpacing + lineWidth;
    }
    if (rowIns != null && rowIns.getIndex() == rows.size()) {
      info.add(new Rectangle(startX, y, rowIns.getSize().width, 1));
    }
  }
示例#13
0
 public void pack() {
   IFigure figure = branch.getFigure();
   figure.setSize(figure.getPreferredSize());
 }