Esempio n. 1
0
 public void acceptMinimumSize(Component c) {
   Dimension minimumSize = getMinimumSize(c);
   c.setMinimumSize(
       new Dimension(
           Math.max(minimumSize.width, c.getMinimumSize().width),
           Math.max(minimumSize.height, c.getMinimumSize().height)));
 }
Esempio n. 2
0
  /**
   * Returns the {@link Constraints} object associated with the specified component.
   *
   * @param c the component for which to determine the constraint.
   * @return the {@link Constraints} object associated with the specified component.
   */
  public SpringLayout.Constraints getConstraints(Component c) {
    Constraints constraints = (Constraints) constraintsMap.get(c);

    if (constraints == null) {
      Container parent = c.getParent();
      constraints = new Constraints();

      if (parent != null) {
        constraints.setX(Spring.constant(parent.getInsets().left));
        constraints.setY(Spring.constant(parent.getInsets().top));
      } else {
        constraints.setX(Spring.constant(0));
        constraints.setY(Spring.constant(0));
      }
    }
    constraints.setWidth(
        Spring.constant(
            c.getMinimumSize().width, c.getPreferredSize().width, c.getMaximumSize().width));
    constraints.setHeight(
        Spring.constant(
            c.getMinimumSize().height, c.getPreferredSize().height, c.getMaximumSize().height));
    constraintsMap.put(c, constraints);

    return constraints;
  }
    public Dimension minimumLayoutSize(Container parent) {
      JToolBar tb = (JToolBar) parent;
      Insets insets = tb.getInsets();
      Dimension dim = new Dimension();
      SeaGlassContext context = getContext(tb);

      if (tb.getOrientation() == JToolBar.HORIZONTAL) {
        dim.width = tb.isFloatable() ? SeaGlassIcon.getIconWidth(handleIcon, context) : 0;
        Dimension compDim;
        for (int i = 0; i < tb.getComponentCount(); i++) {
          Component component = tb.getComponent(i);
          if (component.isVisible()) {
            compDim = component.getMinimumSize();
            dim.width += compDim.width;
            dim.height = Math.max(dim.height, compDim.height);
          }
        }
      } else {
        dim.height = tb.isFloatable() ? SeaGlassIcon.getIconHeight(handleIcon, context) : 0;
        Dimension compDim;
        for (int i = 0; i < tb.getComponentCount(); i++) {
          Component component = tb.getComponent(i);
          if (component.isVisible()) {
            compDim = component.getMinimumSize();
            dim.width = Math.max(dim.width, compDim.width);
            dim.height += compDim.height;
          }
        }
      }
      dim.width += insets.left + insets.right;
      dim.height += insets.top + insets.bottom;

      context.dispose();
      return dim;
    }
    @Override
    int getHeight(boolean isPreferred) {

      int labelHeight = (isPreferred ? l.getPreferredSize().height : l.getMinimumSize().height);

      int controlHeight = (isPreferred ? c.getPreferredSize().height : c.getMinimumSize().height);

      return Math.max(labelHeight, controlHeight);
    }
Esempio n. 5
0
  private void setSizes(Container parent) {
    int nComps = parent.getComponentCount();
    Dimension d = null;

    // Reset preferred/minimum width and height.
    preferredWidth = 0;
    preferredHeight = 0;
    minWidth = 0;
    minHeight = 0;

    for (int i = 0; i < nComps; i++) {
      Component c = parent.getComponent(i);
      if (c.isVisible()) {
        d = c.getPreferredSize();

        if (i > 0) {
          preferredWidth += d.width / 2;
          preferredHeight += vgap;
        } else {
          preferredWidth = d.width;
        }
        preferredHeight += d.height;

        minWidth = Math.max(c.getMinimumSize().width, minWidth);
        minHeight = preferredHeight;
      }
    }
  }
Esempio n. 6
0
 private Dimension minimumNodeSize(Node root) {
   if (root instanceof Leaf) {
     Component child = childForNode(root);
     return (child != null) ? child.getMinimumSize() : new Dimension(0, 0);
   } else if (root instanceof Divider) {
     int dividerSize = getDividerSize();
     return new Dimension(dividerSize, dividerSize);
   } else {
     Split split = (Split) root;
     List<Node> splitChildren = split.getChildren();
     int width = 0;
     int height = 0;
     if (split.isRowLayout()) {
       for (Node splitChild : splitChildren) {
         Dimension size = minimumNodeSize(splitChild);
         width += size.width;
         height = Math.max(height, size.height);
       }
     } else {
       for (Node splitChild : splitChildren) {
         Dimension size = minimumNodeSize(splitChild);
         width = Math.max(width, size.width);
         height += size.height;
       }
     }
     return new Dimension(width, height);
   }
 }
Esempio n. 7
0
  public Dimension minimumLayoutSize(Container target) {
    Dimension dim = new Dimension(0, 0);
    int nmembers = target.getComponentCount();

    for (int i = 0; i < nmembers; i++) {
      Component m = target.getComponent(i);
      if (m.isVisible()) {
        Dimension d = m.getMinimumSize();
        if (fVerticalLayout) {
          dim.width = Math.max(dim.width, d.width);
          if (i > 0) {
            dim.height += fGap;
          }
          dim.height += d.height;
        } else {
          dim.height = Math.max(dim.height, d.height);
          if (i > 0) {
            dim.width += fGap;
          }
          dim.width += d.width;
        }
      }
    }

    Insets insets = target.getInsets();
    dim.width += insets.left + insets.right;
    dim.width += 2 * fBorder.x;
    dim.height += insets.top + insets.bottom;
    dim.height += 2 * fBorder.y;
    return dim;
  }
        /** @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */
        public void componentResized(ComponentEvent evt) {
          /* 获取目标组件 */
          Component component = evt.getComponent();

          /* 获取目标组件设置的边界和最小最大尺寸 */
          Rectangle bounds = component.getBounds();
          Dimension minSize = component.getMinimumSize();
          Dimension maxSize = component.getMaximumSize();

          /* 确定目标组件新的x轴坐标及宽度 */
          if (bounds.width < minSize.width) {
            bounds.x -= (bounds.x == m_oldBounds.x ? 0 : minSize.width - bounds.width);
            bounds.width = minSize.width;

          } else if (bounds.width > maxSize.width) {
            bounds.x += (bounds.x == m_oldBounds.x ? 0 : bounds.width - maxSize.width);
            bounds.width = maxSize.width;
          }

          /* 确定目标组件新的y轴坐标及高度 */
          if (bounds.height < minSize.height) {
            bounds.y -= (bounds.y == m_oldBounds.y ? 0 : minSize.height - bounds.height);
            bounds.height = minSize.height;

          } else if (bounds.height > maxSize.height) {
            bounds.y += (bounds.y == m_oldBounds.y ? 0 : bounds.height - maxSize.height);
            bounds.height = maxSize.height;
          }

          /* 设置目标组件的新边界 */
          component.setBounds(bounds);

          /* 保存新的边界 */
          m_oldBounds = bounds;
        }
Esempio n. 9
0
  protected void enforceMinimumAndMaximumWidgetSizes(java.awt.Component component) {
    java.awt.Dimension size = component.getSize();
    boolean changed = false;

    // enforce minimum
    java.awt.Dimension minimumSize = component.getMinimumSize();
    if (size.width < minimumSize.width) {
      size.width = minimumSize.width;
      changed = true;
    }
    if (size.height < minimumSize.height) {
      size.height = minimumSize.height;
      changed = true;
    }

    // enforce maximum
    java.awt.Dimension maximumSize = component.getMaximumSize();
    if (maximumSize != null) {
      if (size.width > maximumSize.width && maximumSize.width > 0) {
        size.width = maximumSize.width;
        changed = true;
      }
      if (size.height > maximumSize.height && maximumSize.height > 0) {
        size.height = maximumSize.height;
        changed = true;
      }
    }

    if (changed) {
      component.setSize(size);
    }
  }
 @Override
 public Dimension minimumLayoutSize(Container parent) {
   Component toolbar = parent.getComponent(0);
   Dimension toolbarSize = toolbar.isVisible() ? toolbar.getMinimumSize() : new Dimension();
   Dimension contentSize = parent.getComponent(1).getMinimumSize();
   return new Dimension(
       Math.max(toolbarSize.width, contentSize.width), toolbarSize.height + contentSize.height);
 }
Esempio n. 11
0
  public void layoutContainer(Container parent) {
    int n = rows.size();
    Insets border = parent.getInsets();
    int lastY = border.top;

    // figure out where the second column should start
    int secondColumn = 0;
    for (int i = 0; i < n; i++) {
      Row r = (Row) rows.get(i);
      if (r instanceof NormalRow) {
        NormalRow nr = (NormalRow) r;
        secondColumn =
            Math.max(
                secondColumn,
                // nr.l.getMinimumSize().width);
                nr.getLabelWidth(false));
      }
    }
    secondColumn += border.left + EXTRA;

    for (int i = 0; i < n; i++) {
      Row r = (Row) rows.get(i);
      if (r instanceof HeaderRow) {
        // header
        Component header = ((HeaderRow) r).h;
        int w = parent.getWidth() - (border.left + border.right);
        int h = header.getMinimumSize().height;
        int x = border.left;
        int y = lastY;
        header.setBounds(x, y, w, h);
        lastY += h;
      } else if (r instanceof NormalRow) {
        // label
        JLabel l = (JLabel) ((NormalRow) r).l;
        int w1 = l.getMinimumSize().width;
        // int h1 =  l.getPreferredSize().height;
        int h1 = l.getMinimumSize().height;
        int x1 = secondColumn - w1;
        int y1 = lastY;
        l.setBounds(x1, y1, w1, h1);

        // control
        Component c = ((NormalRow) r).c;
        // WAS: int w2 = c.getPreferredSize().width;
        int w2 = c.getMaximumSize().width; // NEW!
        w2 = Math.min(w2, parent.getWidth() - (border.right + PADDING + secondColumn));
        int h2 = c.getPreferredSize().height;
        int x2 = secondColumn + PADDING; // buffer between 'em
        int y2 = lastY;
        c.setBounds(x2, y2, w2, h2);

        lastY += Math.max(h1, h2);
      }
    }

    // focus on the first one?  (is that my job?)  (is it even possible?)
  }
Esempio n. 12
0
  public void layoutContainer(Container parent) {
    Dimension ourSize = preferredLayoutSize(parent),
        // Does the following do something useful?
        // And shouldn't we cater to real instead of maximum sizes?
        // This way, if a VerticallyLaidout component had a particular size forced upon it,
        // wouldn't we neglect to scale down to using minimum sizes so long as its maximum
        // size was bigger than our preferred?	 all: [Davis]
        maxSize = parent.getMaximumSize(),
        size = parent.getSize();
    Insets isets = parent.getInsets();
    Dimension compSize;
    int n = parent.getComponentCount();
    int y;
    boolean usingPreferredSize = true;

    if (ourSize.width > maxSize.width || ourSize.height > maxSize.height) {
      ourSize = minimumLayoutSize(parent);
      usingPreferredSize = false;
    }

    switch (verticalAlignment) {
      case TOP:
        y = isets.top;
        break;
      case BOTTOM:
        y = (size.height - ourSize.height);
        break;
      default: // assume MIDDLE
        y = (size.height - ourSize.height) / 2 + isets.top;
        break;
    }
    for (int i = 0; i < n; i++) {
      Component c = parent.getComponent(i);
      compSize = usingPreferredSize ? c.getPreferredSize() : c.getMinimumSize();

      switch (horizontalAlignment) {
        case LEFT:
          c.setBounds(isets.left, y, compSize.width, compSize.height);
          break;
        case RIGHT:
          c.setBounds(
              ourSize.width - isets.right - compSize.width + isets.left,
              y,
              compSize.width,
              compSize.height);
          break;
        default: // assume CENTER
          c.setBounds(
              (ourSize.width - isets.left - isets.right - compSize.width + isets.left) / 2,
              y,
              compSize.width,
              compSize.height);
      }
      y += compSize.height + vgap;
    }
  }
Esempio n. 13
0
  /**
   * @param dim
   * @param cc
   */
  private Dimension rozmer(final Dimension dim, final Component cc) {
    final Dimension prs = cc.getPreferredSize();
    final Dimension mis = cc.getMinimumSize();
    final Dimension mas = cc.getMaximumSize();

    final int dx = rozmer(ratiox, dim.width, prs.width, mis.width, mas.width);
    final int dy = rozmer(ratioy, dim.height, prs.height, mis.height, mas.height);
    final Dimension v = new Dimension(dx, dy);
    return v;
  }
Esempio n. 14
0
  public Dimension preferredLayoutSize(Container parent) {
    Insets insets = parent.insets();
    int ncomponents = parent.countComponents();
    int nrows = getRows();
    int ncols = getColumns();
    int hgap = getHgap();
    int vgap = getVgap();

    if (nrows > 0) {
      ncols = (ncomponents + nrows - 1) / nrows;
    } else {
      nrows = (ncomponents + ncols - 1) / ncols;
    }

    int nComps = parent.getComponentCount();

    int y = insets.top;
    for (int row = 0; row < nrows; row++) {
      int h = 0;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          h = Math.max(h, c.getMinimumSize().height);
        }
      }
      y += h + vgap;
    }

    int x = insets.left;
    for (int col = 0; col < ncols; col++) {
      int w = 0;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          Component c = parent.getComponent(row * ncols + col);
          w = Math.max(w, c.getMinimumSize().width);
        }
      }
      x += w + hgap;
    }
    return new Dimension(x, y);
  }
Esempio n. 15
0
  /**
   * Calculates the minimum size dimensions for the specified panel given the components in the
   * specified parent container.
   */
  public Dimension minimumLayoutSize(Container container) {
    Component child = getChild(container);
    if (child == null) return new Dimension(0, 0);

    Dimension childMinSize = child.getMinimumSize();
    Insets insets = container.getInsets();

    int width = childMinSize.width + insets.left + insets.right;
    int height = childMinSize.height + insets.top + insets.bottom;
    int maxSize = Math.max(width, height);
    return new Dimension(maxSize, maxSize);
  }
Esempio n. 16
0
 public Dimension minimumLayoutSize(Container target) {
   if (_minimumLayoutSize == null) {
     int w = 0;
     int h = 0;
     for (Component c : target.getComponents()) {
       w += c.getMinimumSize().width;
       h += c.getMinimumSize().height + SEPARATOR_THICKNESS;
     }
     _minimumLayoutSize = new Dimension(w, h);
   }
   return _minimumLayoutSize;
 }
Esempio n. 17
0
  /**
   * Determines the minimum size of the <code>target</code> container using this layout manager.
   *
   * <p>This method is called when a container calls its <code>getMinimumSize</code> method. Most
   * applications do not call this method directly.
   *
   * @param target the container in which to do the layout.
   * @return the minimum dimensions needed to lay out the subcomponents of the specified container.
   * @see java.awt.Container
   * @see java.awt.BorderLayout#preferredLayoutSize
   * @see java.awt.Container#getMinimumSize()
   */
  public Dimension minimumLayoutSize(Container target) {
    synchronized (target.getTreeLock()) {
      Dimension dim = new Dimension(0, 0);

      boolean ltr = target.getComponentOrientation().isLeftToRight();
      Component c = null;

      if ((c = getChild(EAST, ltr)) != null) {
        Dimension d = c.getMinimumSize();
        dim.width += d.width + hgap;
        dim.height = Math.max(d.height, dim.height);
      }
      if ((c = getChild(WEST, ltr)) != null) {
        Dimension d = c.getMinimumSize();
        dim.width += d.width + hgap;
        dim.height = Math.max(d.height, dim.height);
      }
      if ((c = getChild(CENTER, ltr)) != null) {
        Dimension d = c.getMinimumSize();
        dim.width += d.width;
        dim.height = Math.max(d.height, dim.height);
      }
      if ((c = getChild(NORTH, ltr)) != null) {
        Dimension d = c.getMinimumSize();
        dim.width = Math.max(d.width, dim.width);
        dim.height += d.height + vgap;
      }
      if ((c = getChild(SOUTH, ltr)) != null) {
        Dimension d = c.getMinimumSize();
        dim.width = Math.max(d.width, dim.width);
        dim.height += d.height + vgap;
      }

      Insets insets = target.getInsets();
      dim.width += insets.left + insets.right;
      dim.height += insets.top + insets.bottom;

      return dim;
    }
  }
Esempio n. 18
0
    /** Lays out the container in the specified panel. */
    public void layoutContainer(Container target) {
      synchronized (target.getTreeLock()) {
        Insets insets = target.getInsets();
        Dimension dim = target.getSize();

        int fullHeight = dim.height;
        int bottom = dim.height - insets.bottom - 1;
        int top = 0 + insets.top;
        int left = insets.left;
        int maxPosition = dim.width - (insets.left + insets.right) - hgap;
        int right = dim.width - insets.right;
        maxPosition = right;
        int height = bottom - top;
        int size = actions.size();
        int w, h;
        if ((grip != null) && grip.isVisible()) {
          Dimension d = grip.getPreferredSize();
          grip.setBounds(left, top + vgap, d.width, bottom - top - 2 * vgap);
          left += d.width;
          left += hgap;
        }
        for (int i = 0; i < size; i++) {
          left += hgap;
          Component comp = (Component) actions.elementAt(i);
          Dimension d;
          Dimension minSize = comp.getMinimumSize();

          if (i == size - 1) d = comp.getMaximumSize();
          else d = comp.getPreferredSize();
          w = d.width;
          h = Math.min(height, d.height);
          if ((left < maxPosition) && (left + w > maxPosition)) {
            if (maxPosition - left >= minSize.width) w = maxPosition - left;
          }

          comp.setBounds(left, (fullHeight - d.height) / 2, w, h);

          //  	  if (i == size - 1)
          //  	    d = comp.getMaximumSize();
          //  	  else
          //  	    d = comp.getPreferredSize();
          //  	  if ((left + d.width) > right)
          //  	    w = right - left;
          //  	  else
          //  	    w = d.width;
          //  	  h = Math.min (height, d.height);
          //  	  comp.setBounds (left, (fullHeight - d.height)/2, w, h);

          left += d.width;
        }
      }
    }
 /**
  * @param parent
  * @return
  */
 public Dimension minimumLayoutSize(Container parent) {
   Insets insets = parent.getInsets();
   int min_width = 0;
   int min_height = 0;
   for (int index = 0; index < parent.getComponentCount(); index++) {
     Component comp = parent.getComponent(index);
     Dimension minsz = comp.getMinimumSize();
     min_width = Math.max(minsz.width, min_width);
     min_height = Math.max(minsz.height, min_height);
   }
   return new Dimension(
       min_width + insets.left + insets.right, min_height + insets.top + insets.bottom);
 }
Esempio n. 20
0
  /**
   * Resizes the <code>TableColumn</code> to fit the width of its header cell. This method does
   * nothing if the header renderer is <code>null</code> (the default case). Otherwise, it sets the
   * minimum, maximum and preferred widths of this column to the widths of the minimum, maximum and
   * preferred sizes of the Component delivered by the header renderer. The transient "width"
   * property of this TableColumn is also set to the preferred width. Note this method is not used
   * internally by the table package.
   *
   * @see #setPreferredWidth
   */
  public void sizeWidthToFit() {
    if (headerRenderer == null) {
      return;
    }
    Component c =
        headerRenderer.getTableCellRendererComponent(null, getHeaderValue(), false, false, 0, 0);

    setMinWidth(c.getMinimumSize().width);
    setMaxWidth(c.getMaximumSize().width);
    setPreferredWidth(c.getPreferredSize().width);

    setWidth(getPreferredWidth());
  }
Esempio n. 21
0
    @Override
    public Dimension minimumLayoutSize(Container parent) {
      if (parent.getComponentCount() == 0) {
        return new Dimension(0, 0);
      } else {
        int x = Integer.MAX_VALUE, y = Integer.MAX_VALUE;
        for (Component child : parent.getComponents()) {
          Dimension dim = child.getMinimumSize();
          x = Math.min(dim.width, x);
          y = Math.min(dim.height, y);
        }

        return new Dimension(x, y);
      }
    }
Esempio n. 22
0
  /** {@inheritDoc} */
  public Dimension minimumLayoutSize(final Container parent) {
    synchronized (parent.getTreeLock()) {
      int width = 0;
      int height = 0;

      for (Component comp : components) {
        Dimension size = comp.getMinimumSize();
        width = Math.max(size.width, width);
        height = Math.max(size.height, height);
      }

      Insets insets = parent.getInsets();
      width += insets.left + insets.right;
      height += insets.top + insets.bottom;

      return new Dimension(width, height);
    }
  }
  /* Required by LayoutManager. */
  public Dimension minimumLayoutSize(Container parent) {
    // System.out.println("PL: minimumLayoutSize called");
    Dimension dim = new Dimension(0, 0);

    // setSizes(parent);
    if (center != null) {
      dim = center.getMinimumSize();
      System.out.println("minimum size of center component -> " + dim);
      dim.width /= (1 - insetLeft - insetRight - zonesetLeft - zonesetRight);
      dim.height /= (1 - insetTop - insetBottom - zonesetTop - zonesetBottom);
    }

    // Always add the container's insets!
    Insets insets = parent.getInsets();
    dim.width += insets.left + insets.right;
    dim.height += insets.top + insets.bottom;

    return dim;
  }
Esempio n. 24
0
  /**
   * Calculates the minimum dimension for the specified panel given the components in the specified
   * parent container.
   *
   * @param parent the component to be laid out
   * @see #preferredLayoutSize
   */
  public Dimension minimumLayoutSize(Container parent) {
    int maxWidth = 0;
    int maxHeight = 0;
    for (java.util.Enumeration e = constraints.keys(); e.hasMoreElements(); ) {
      Component comp = (Component) e.nextElement();
      AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);

      Dimension size = comp.getMinimumSize();

      int width = ac.getWidth();
      if (width == -1) width = size.width;
      int height = ac.getHeight();
      if (height == -1) height = size.height;

      if (ac.x + width > maxWidth) maxWidth = ac.x + width;
      if (ac.y + height > maxHeight) maxHeight = ac.y + height;
    }
    return new Dimension(maxWidth, maxHeight);
  }
Esempio n. 25
0
 public Dimension minimumLayoutSize(Container target) {
   Insets insets = target.getInsets();
   Dimension dim = new Dimension(0, 0);
   int ncomponents = target.getComponentCount();
   Component comp;
   Dimension d;
   for (int i = 0; i < ncomponents; i++) {
     comp = target.getComponent(i);
     if (comp.isVisible()) {
       d = comp.getMinimumSize();
       dim.width += d.width;
       dim.height = Math.max(d.height, dim.height);
       if (i > 0) dim.width += gap;
     }
   }
   dim.width += insets.left + insets.right;
   dim.height += insets.top + insets.bottom;
   return dim;
 }
Esempio n. 26
0
 /**
  * Algorithm for calculating the largest minimum or preferred cell size.
  *
  * <p>Largest cell size is calculated by getting the applicable size of each component and keeping
  * the maximum value, dividing the component's width by the number of columns it is specified to
  * occupy and dividing the component's height by the number of rows it is specified to occupy.
  *
  * @param parent the container in which to do the layout.
  * @param isPreferred true for calculating preferred size, false for calculating minimum size.
  * @return the largest cell size required.
  */
 protected Dimension getLargestCellSize(Container parent, boolean isPreferred) {
   int ncomponents = parent.getComponentCount();
   Dimension maxCellSize = new Dimension(0, 0);
   for (int i = 0; i < ncomponents; i++) {
     Component c = parent.getComponent(i);
     Rectangle rect = (Rectangle) compTable.get(c);
     if (c != null && rect != null) {
       Dimension componentSize;
       if (isPreferred) {
         componentSize = c.getPreferredSize();
       } else {
         componentSize = c.getMinimumSize();
       }
       // Note: rect dimensions are already asserted to be > 0 when the
       // component is added with constraints
       maxCellSize.width = Math.max(maxCellSize.width, componentSize.width / rect.width);
       maxCellSize.height = Math.max(maxCellSize.height, componentSize.height / rect.height);
     }
   }
   return maxCellSize;
 }
Esempio n. 27
0
  public void layoutContainer(Container target) {
    Insets insets = target.getInsets();
    int nmembers = target.getComponentCount();
    int x = insets.left + fBorder.x;
    int y = insets.top + fBorder.y;

    for (int i = 0; i < nmembers; i++) {
      Component m = target.getComponent(i);
      if (m.isVisible()) {
        Dimension d = m.getMinimumSize();
        m.setBounds(x, y, d.width, d.height);
        if (fVerticalLayout) {
          y += d.height;
          y += fGap;
        } else {
          x += d.width;
          x += fGap;
        }
      }
    }
  }
Esempio n. 28
0
    @Override
    public Dimension minimumLayoutSize(Container target) {
      synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int nmembers = target.getComponentCount();

        Insets insets = target.getInsets();
        int maxwidth = target.getWidth() - (insets.left + insets.right + getHgap() * 2);
        int width = 0;
        int height = 0;
        int component = 0;
        for (int i = 0; i < nmembers; i++, component++) {
          Component m = target.getComponent(i);
          if (m.isVisible()) {
            Dimension d = m.getMinimumSize();
            if (component > 0) {
              if (width + d.width > maxwidth) {
                dim.width = Math.max(dim.width, width);
                dim.height += height + getVgap();
                width = 0;
                height = 0;
                component = 0;
              }
              width += getHgap();
            }
            height = Math.max(height, d.height);
            width += d.width;
          }
        }
        dim.width = Math.max(dim.width, width);
        dim.height += height;

        dim.width += insets.left + insets.right + getHgap() * 2;
        dim.height += insets.top + insets.bottom + getVgap() * 2;
        return dim;
      }
    }
  /*--------------------------------------------------------------------------*/
  public Dimension minimumLayoutSize(Container target) {
    synchronized (target.getTreeLock()) {
      Dimension dim = new Dimension(0, 0);
      int nmembers = target.getComponentCount();

      for (int i = 0; i < nmembers; i++) {
        Component m = target.getComponent(i);
        if (m.isVisible()) {
          Dimension d = m.getMinimumSize();
          dim.height = Math.max(dim.height, d.height);
          if (i > 0) {
            dim.width += hgap;
          }
          dim.width += d.width;
        }
      }

      Insets insets = target.getInsets();
      dim.width += insets.left + insets.right + hgap * 2;
      dim.height += insets.top + insets.bottom + vgap * 2;

      return (dim);
    }
  }
 /**
  * A debugging utility that prints to stdout the component's minimum, preferred, and maximum
  * sizes.
  */
 public static void printSizes(Component c) {
   System.out.println("minimumSize = " + c.getMinimumSize());
   System.out.println("preferredSize = " + c.getPreferredSize());
   System.out.println("maximumSize = " + c.getMaximumSize());
 }