Package org.eclipse.draw2d.geometry

Examples of org.eclipse.draw2d.geometry.Insets


    int height = 0, width = 0;
    for (int i = 0; i < children.size(); i++) {
      child = children.get(i);
      childSize = transposer.t(preferred ? getChildPreferredSize(child,
          wHint, hHint) : getChildMinimumSize(child, wHint, hHint));
      Insets inset = new Insets();
      SapphireSequenceLayoutConstraint constraint = (SapphireSequenceLayoutConstraint)getConstraint(child);
      if (constraint != null) {
        inset = transposer.t(constraint.getMarginInset());
      }
     
View Full Code Here


    IFigure child;
    int height = 0, width = Integer.MAX_VALUE;
    for (int i = 0; i < children.size(); i++) {
      child = children.get(i);
      childSize = transposer.t(getChildCellMaximumSize(child));
      Insets inset = new Insets();
      SapphireSequenceLayoutConstraint constraint = (SapphireSequenceLayoutConstraint)getConstraint(child);
      if (constraint != null) {
        inset = transposer.t(constraint.getMarginInset());
      }
      width = Math.min(width, childSize.width + (childSize.width < Integer.MAX_VALUE ? inset.left + inset.right : 0));
View Full Code Here

   */
 
  @SuppressWarnings( "unchecked" )
 
    protected Dimension calculateMinimumSize(IFigure container, int wHint, int hHint) {
    Insets insets = container.getInsets();
    if (isHorizontal()) {
      wHint = -1;
      if (hHint >= 0)
        hHint = Math.max(0, hHint - insets.getHeight());
    } else {
      hHint = -1;
      if (wHint >= 0)
        wHint = Math.max(0, wHint - insets.getWidth());
    }

    List<IFigure> children = container.getChildren();
    Dimension minSize = calculateChildrenSize(children, wHint, hHint, false);
    // Do a second pass, if necessary
    if (wHint >= 0 && minSize.width > wHint) {
      minSize = calculateChildrenSize(children, minSize.width, hHint, false);
    } else if (hHint >= 0 && minSize.width > hHint) {
      minSize = calculateChildrenSize(children, wHint, minSize.width, false);
    }

    minSize.height += Math.max(0, children.size() - 1) * spacing;
   
    Insets inset = transposer.t(this.marginInsets);
    minSize.width += inset.left + inset.right;
    minSize.height += inset.top + inset.bottom;
   
    return transposer.t(minSize)
        .expand(insets.getWidth(), insets.getHeight())
View Full Code Here

 
  @SuppressWarnings( "unchecked" )
 
    protected Dimension calculatePreferredSize(IFigure container, int wHint,
      int hHint) {
    Insets insets = container.getInsets();
    if (isHorizontal()) {
      wHint = -1;
      if (hHint >= 0)
        hHint = Math.max(0, hHint - insets.getHeight());
    } else {
      hHint = -1;
      if (wHint >= 0)
        wHint = Math.max(0, wHint - insets.getWidth());
    }

    List<IFigure> children = container.getChildren();
    Dimension prefSize = calculateChildrenSize(children, wHint, hHint, true);
    // Do a second pass, if necessary
    if (wHint >= 0 && prefSize.width > wHint) {
      prefSize = calculateChildrenSize(children, prefSize.width, hHint, true);
    } else if (hHint >= 0 && prefSize.width > hHint) {
      prefSize = calculateChildrenSize(children, wHint, prefSize.width, true);
    }

    // Constrain the preferred width by container's max width and min width
    Dimension maxSize = calculateChildrenMaximumSize(children);
    Dimension minSize = calculateChildrenSize(children, wHint, hHint, false);   
    prefSize.width = Math.min(maxSize.width, prefSize.width);
    prefSize.width = Math.max(minSize.width, prefSize.width);
   
    prefSize.height += Math.max(0, children.size() - 1) * spacing;

    Insets inset = transposer.t(this.marginInsets);
    prefSize.width += inset.left + inset.right;
    prefSize.height += inset.top + inset.bottom;

    return transposer.t(prefSize)
        .expand(insets.getWidth(), insets.getHeight())
View Full Code Here

  @SuppressWarnings( "unchecked" )
    public Dimension calculateMaximumSize(IFigure container) {
    List<IFigure> children = container.getChildren();
    Dimension maxSize = calculateChildrenMaximumSize(children);
    Insets marginInsets = transposer.t(this.marginInsets);
    if (maxSize.width < Integer.MAX_VALUE) {
      maxSize.width += marginInsets.left + marginInsets.right;
    }
    if (maxSize.height < Integer.MAX_VALUE) {
      maxSize.height += Math.max(0, children.size() - 1) * spacing;
      maxSize.height += marginInsets.top + marginInsets.bottom;
    }
    maxSize = transposer.t(maxSize);
    Insets containerInsets = container.getInsets();
    Dimension borderSize = getBorderPreferredSize(container);
    if (maxSize.width < Integer.MAX_VALUE) {
      maxSize.width += containerInsets.getWidth();
      maxSize.width = Math.max(borderSize.width, maxSize.width);
    }
    if (maxSize.height < Integer.MAX_VALUE) {
      maxSize.height += containerInsets.getHeight();
      maxSize.height = Math.max(borderSize.height, maxSize.height);
    }
    return maxSize;
  }
View Full Code Here

 
    public void layout(IFigure parent) {
    List<IFigure> children = parent.getChildren();
    int numChildren = children.size();
    Rectangle clientArea = transposer.t(parent.getClientArea());
    Insets margins = transposer.t(this.marginInsets);
   
    clientArea.x += margins.left;
    clientArea.width -= (margins.left + margins.right);

    int x = clientArea.x;
    int y = clientArea.y;
    int availableHeight = clientArea.height;

    Dimension prefSizes[] = new Dimension[numChildren];
    Dimension minSizes[] = new Dimension[numChildren];
    Dimension maxCellSizes[] = new Dimension[numChildren];
    Dimension maxChildShapeSizes[] = new Dimension[numChildren];
    int extraHeights[] = new int[numChildren];
   
    SapphireSequenceLayoutConstraint constraints[] = new SapphireSequenceLayoutConstraint[numChildren];
    Insets marginInsets[] = new Insets[numChildren];

    // Calculate the width and height hints. If it's a vertical sequence layout,
    // then ignore the height hint (set it to -1); otherwise, ignore the
    // width hint. These hints will be passed to the children of the parent
    // figure when getting their preferred size.
    int wHint = -1;
    int hHint = -1;
    if (isHorizontal()) {
      hHint = parent.getClientArea(Rectangle.SINGLETON).height - (margins.top + margins.bottom);
    } else {
      wHint = parent.getClientArea(Rectangle.SINGLETON).width - (margins.left + margins.right);
    }

    /*
     * Calculate sum of preferred heights of all children(totalHeight).
     * Cache Preferred Sizes and Minimum Sizes of all children.
     */
    IFigure child;
    int totalHeight = 0;
    int totalMinHeight = 0;
    int prefMinSumHeight = 0;
    int totalMargin = 0;
    int expandCount = 0;
   
    for (int i = 0; i < numChildren; i++) {
      child = children.get(i);
     
      SapphireSequenceLayoutConstraint constraint = (SapphireSequenceLayoutConstraint)getConstraint(child);
      if (constraint == null)
        setConstraint(child, constraint = new SapphireSequenceLayoutConstraint());
      constraints[i] = constraint;

      prefSizes[i] = transposer.t(getChildPreferredSize(child, wHint, hHint));
      minSizes[i] = transposer.t(getChildMinimumSize(child, wHint, hHint));
      maxCellSizes[i] = transposer.t(getChildCellMaximumSize(child));
      maxChildShapeSizes[i] = transposer.t(child.getMaximumSize());
      marginInsets[i] = transposer.t(constraint.getMarginInset());
     
      totalHeight += prefSizes[i].height;
      totalMinHeight += minSizes[i].height;
      totalMargin += marginInsets[i].top + marginInsets[i].bottom;
      // We need to expand the cell if the its constraint has "expand" bit on or
      // one of the children has "expand" bit on
      if (getMajorExpand(constraint) || maxChildShapeSizes[i].height > prefSizes[i].height) {
        expandCount++;
      }
    }
    totalHeight += (numChildren - 1) * spacing;
    totalHeight += totalMargin + margins.top + margins.bottom;
    totalMinHeight += (numChildren - 1) * spacing;
    totalMinHeight += totalMargin + margins.top + margins.bottom;
    prefMinSumHeight = totalHeight - totalMinHeight;
   
    int amntShrinkHeight = totalHeight
        - Math.max(availableHeight, totalMinHeight);
    int extraHeight = -amntShrinkHeight;

    if (amntShrinkHeight < 0) {
      amntShrinkHeight = 0;
    }
   
    if (extraHeight <= 0) {
      extraHeight = 0;
    } else if (expandCount > 0) {
      int averageExtraHeight = extraHeight / expandCount;

      int limitedExpansionCount = 0;
      int limitedExpansionHeightTotal = 0;
      if (expandCount > 1) {
        for (int i = 0; i < numChildren; i++) {       
          int prefHeight = prefSizes[i].height;
          int maxCellHeight = maxCellSizes[i].height;
          child = children.get(i);
          SapphireSequenceLayoutConstraint constraint = constraints[i];
          if (getMajorExpand(constraint) || maxCellHeight > prefHeight) {
            // only limited expansion since the child figure has max size constraint.
            if (maxCellHeight - prefHeight < averageExtraHeight) {
              limitedExpansionCount++;
              limitedExpansionHeightTotal += maxCellHeight - prefHeight;
            }
          }
        }       
      }
      int unlimitedExpansionAverage = limitedExpansionCount < expandCount ?
          (extraHeight - limitedExpansionHeightTotal) / (expandCount - limitedExpansionCount) : 0;

      for (int i = 0; i < numChildren; i++) {       
        int prefHeight = prefSizes[i].height;
        int maxCellHeight = maxCellSizes[i].height;
        child = children.get(i);
        SapphireSequenceLayoutConstraint constraint = constraints[i];
        if (getMajorExpand(constraint) || maxCellHeight > prefHeight) {
          // only limited expansion
          if (expandCount > 1 && (maxCellHeight - prefHeight < averageExtraHeight)) {
            extraHeights[i] = maxCellHeight - prefHeight;
          }
          else {
            extraHeights[i] = unlimitedExpansionAverage;
          }
        }
        else {
          extraHeights[i] = 0;
        }
      }         
     
    }
   
    y += margins.top;

    for (int i = 0; i < numChildren; i++) {
      int amntShrinkCurrentHeight = 0;
      child = children.get(i);

      int prefHeight = prefSizes[i].height;
      int minHeight = minSizes[i].height;
      int prefWidth = prefSizes[i].width;
      int minWidth = minSizes[i].width;
      Insets marginInset = marginInsets[i];
     
      Rectangle newBounds, availableBounds;
      int availableBoundHeight;
      SapphireSequenceLayoutConstraint constraint = constraints[i];
      if (prefMinSumHeight != 0)
View Full Code Here

    final int top = def.getMarginTop().content();
    final int bottom = def.getMarginBottom().content();
    final int left = def.getMarginLeft().content();
    final int right = def.getMarginRight().content();
 
    return new Insets(top, left, bottom, right);
  }
View Full Code Here

      this.maxWidth = def.getMaxWidth().content() != null ? def.getMaxWidth().content() - marginInsets.left - marginInsets.right : -1;
      this.maxHeight = def.getMaxHeight().content() != null ? def.getMaxHeight().content() - marginInsets.top - marginInsets.bottom : -1;
      this.minWidth = def.getMinWidth().content() != null ? def.getMinWidth().content() - marginInsets.left - marginInsets.right : -1;
      this.minHeight = def.getMinHeight().content() != null ? def.getMinHeight().content() - marginInsets.top - marginInsets.bottom : -1;
    } else {
      this.marginInsets = new Insets(0, 0, 0, 0);
    }
  }
View Full Code Here

  }

  public void layout(final SapphireDiagramEditor diagramEditor, boolean autoLayout)
  {
    final DirectedGraph graph = mapDiagramToGraph(diagramEditor);
    graph.setDefaultPadding(new Insets(PADDING));
    new NodeJoiningDirectedGraphLayout().visit(graph);
    mapGraphCoordinatesToDiagram(graph, diagramEditor, autoLayout);   
  }
View Full Code Here

  protected IFigure createFigure() {
      Label label = new Label() {

      @Override
      public Insets getInsets() {
        return new Insets(0,2,0,2);
      }
       
      };
      DiagramResourceCache resourceCache = getCastedModel().getDiagramModel().getResourceCache();
      label.setFont(resourceCache.getDefaultFont());
View Full Code Here

TOP

Related Classes of org.eclipse.draw2d.geometry.Insets

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.