public void layoutContainer(Container target) {
   int barwidth = 0;
   int i;
   for (i = 1; i < target.getComponentCount(); i++) {
     Component m = target.getComponent(i);
     if (m.isVisible()) {
       Dimension d = m.getPreferredSize();
       if (d.width > barwidth) barwidth = d.width;
     }
   }
   Insets insets = target.insets();
   int targetw = target.size().width - insets.left - insets.right;
   int cw = targetw - barwidth;
   int targeth = target.size().height - (insets.top + insets.bottom);
   target.getComponent(0).move(insets.left, insets.top);
   target.getComponent(0).resize(cw, targeth);
   cw += insets.left;
   int h = insets.top;
   for (i = 1; i < target.getComponentCount(); i++) {
     Component m = target.getComponent(i);
     if (m.isVisible()) {
       Dimension d = m.getPreferredSize();
       if (m instanceof DecentScrollbar || m instanceof TextComponent) d.width = barwidth;
       if (m instanceof Choice && d.width > barwidth) d.width = barwidth;
       if (m instanceof Label) {
         h += d.height / 5;
         d.width = barwidth;
       }
       m.move(cw, h);
       m.resize(d.width, d.height);
       h += d.height;
     }
   }
 }
 public Dimension preferredLayoutSize(Container parent) {
   Insets insets = parent.getInsets();
   Dimension maxSize = new Dimension(insets.left + insets.right, insets.top + insets.bottom);
   for (int i = 0; i < parent.getComponentCount(); i++) {
     Dimension ps = parent.getComponent(i).getPreferredSize();
     maxSize.width += ps.width - (i < parent.getComponentCount() - 1 ? overlap : 0);
     maxSize.height = Math.max(maxSize.height, insets.top + ps.height + insets.bottom);
   }
   return maxSize;
 }
Beispiel #3
0
 public void layoutContainer(Container target) {
   Insets insets = target.getInsets();
   int ncomponents = target.getComponentCount();
   int top = 0;
   int left = insets.left;
   Dimension tps = target.getPreferredSize();
   Dimension targetSize = target.getSize();
   Component comp;
   Dimension ps;
   if (horizontalOrientation == Orientation.CENTER)
     left = left + (targetSize.width / 2) - (tps.width / 2);
   if (horizontalOrientation == Orientation.RIGHT) left = left + targetSize.width - tps.width;
   for (int i = 0; i < ncomponents; i++) {
     comp = target.getComponent(i);
     if (comp.isVisible()) {
       ps = comp.getPreferredSize();
       if (verticalOrientation == Orientation.CENTER)
         top = (targetSize.height / 2) - (ps.height / 2);
       else if (verticalOrientation == Orientation.TOP) top = insets.top;
       else if (verticalOrientation == Orientation.BOTTOM)
         top = targetSize.height - ps.height - insets.bottom;
       comp.setBounds(left, top, ps.width, ps.height);
       left += ps.width + gap;
     }
   }
 }
  @Override
  public Dimension preferredLayoutSize(final Container parent) {
    synchronized (parent.getTreeLock()) {
      final Insets in = parent.getInsets();
      final int nr = parent.getComponentCount();

      int maxW = 0;
      int maxH = 0;
      for (int i = 0; i < cols; ++i) {
        posX[i] = maxW;
        final int w = maxW;
        int h = 0;

        for (int j = 0; j < rows; ++j) {
          final int n = j * cols + i;
          if (n >= nr) break;

          final Component c = parent.getComponent(n);
          final Dimension d = c.getPreferredSize();
          if (maxW < w + d.width) maxW = w + d.width;
          if (posY[j] < h) posY[j] = h;
          else h = posY[j];
          h += d.height;
        }
        if (maxH < h) maxH = h;
      }
      width = in.left + maxW + (cols - 1) * insetX + in.right;
      height = in.top + maxH + (rows - 1) * insetY + in.bottom;

      return new Dimension(width, height);
    }
  }
 private final void printComp(final Component comp, final int deep) {
   final Rectangle rect = comp.getBounds();
   if (L.isInWorkshop) {
     System.out.println(
         comp.getClass().getName()
             + deep
             + ", x : "
             + rect.x
             + ", y : "
             + rect.y
             + ", w : "
             + rect.width
             + ", h : "
             + rect.height);
   }
   if (comp instanceof Container) {
     final Container container = (Container) comp;
     final int count = container.getComponentCount();
     for (int i = 0; i < count; i++) {
       printComp(container.getComponent(i), deep + 1);
     }
   } else if (comp instanceof JScrollPane) {
     if (L.isInWorkshop) {
       System.out.println("------This is JScrollPane-----");
     }
     printComp(((JScrollPane) comp).getViewport().getView(), deep);
   }
 }
 /**
  * Dumps the component constraints to the console.
  *
  * @param container the layout container to inspect
  */
 public static void dumpConstraints(Container container) {
   System.out.println("COMPONENT CONSTRAINTS");
   if (!(container.getLayout() instanceof FormLayout)) {
     System.out.println("The container's layout is not a FormLayout.");
     return;
   }
   FormLayout layout = (FormLayout) container.getLayout();
   int childCount = container.getComponentCount();
   for (int i = 0; i < childCount; i++) {
     Component child = container.getComponent(i);
     CellConstraints cc = layout.getConstraints(child);
     String ccString = cc == null ? "no constraints" : cc.toShortString(layout);
     System.out.print(ccString);
     System.out.print("; ");
     String childType = child.getClass().getName();
     System.out.print(childType);
     if (child instanceof JLabel) {
       JLabel label = (JLabel) child;
       System.out.print("      \"" + label.getText() + "\"");
     }
     if (child.getName() != null) {
       System.out.print("; name=");
       System.out.print(child.getName());
     }
     System.out.println();
   }
   System.out.println();
 }
Beispiel #7
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;
      }
    }
  }
  /*--------------------------------------------------------------------------*/
  public Dimension preferredLayoutSize(Container target) {
    synchronized (target.getTreeLock()) {
      Dimension dim = new Dimension(0, 0);
      int nmembers = target.getComponentCount();
      boolean firstVisibleComponent = true;

      for (int i = 0; i < nmembers; i++) {
        Component m = target.getComponent(i);
        if (m.isVisible()) {
          Dimension d = m.getPreferredSize();
          dim.height = Math.max(dim.height, d.height);
          if (firstVisibleComponent) {
            firstVisibleComponent = false;
          } else {
            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);
    }
  }
  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;
  }
  /**
   * Lays out the container in the specified container.
   *
   * @param parent the component which needs to be laid out
   */
  public void layoutContainer(Container parent) {
    synchronized (parent.getTreeLock()) {
      Insets insets = parent.getInsets();
      int ncomponents = parent.getComponentCount();

      if (ncomponents == 0) {
        return;
      }

      // Total parent dimensions
      Dimension size = parent.getSize();
      int totalW = size.width - (insets.left + insets.right);
      int totalH = size.height - (insets.top + insets.bottom);

      // Cell dimensions, including padding
      int totalCellW = totalW / gridSize.width;
      int totalCellH = totalH / gridSize.height;

      // Cell dimensions, without padding
      int cellW = (totalW - ((gridSize.width + 1) * hgap)) / gridSize.width;
      int cellH = (totalH - ((gridSize.height + 1) * vgap)) / gridSize.height;

      for (int i = 0; i < ncomponents; i++) {
        Component c = parent.getComponent(i);
        Rectangle rect = (Rectangle) compTable.get(c);
        if (rect != null) {
          int x = insets.left + (totalCellW * rect.x) + hgap;
          int y = insets.top + (totalCellH * rect.y) + vgap;
          int w = (cellW * rect.width) - hgap;
          int h = (cellH * rect.height) - vgap;
          c.setBounds(x, y, w, h);
        }
      }
    }
  }
Beispiel #11
0
  /**
   * Called to change the visibility of the outline.
   *
   * @param value true if visible.
   */
  public void setVisible(final boolean value) {
    if (value != isVisible()) {
      super.setVisible(value);

      Container parent = getParent();

      if ((parent != null) && (parent.getComponentCount() == 1)) {
        parent.setVisible(value);
      }

      invalidate();

      try {
        for (; parent != null; parent = parent.getParent()) {
          try {
            parent.getClass().getMethod("resetToPreferredSizes", null).invoke(parent, null);
            visibleArgs[0] = new Integer(value ? 10 : 0);
            parent.getClass().getMethod("setDividerSize", visibleParms).invoke(parent, visibleArgs);

            break;
          } catch (final Throwable ignored) {
          }
        }
      } catch (final Throwable ignored) {
      }

      djvuBean.recursiveRevalidate();
    }
  }
Beispiel #12
0
  public void layoutContainer(Container parent) {
    synchronized (parent.getTreeLock()) {
      DiagramView diagramView = (DiagramView) parent;
      DesignView designView = diagramView.getDesignView();

      double k = designView.getCorrectedZoom();

      FBounds bounds = diagramView.getContentSize();

      int offsetX = (int) Math.round((diagramView.getWidth() - bounds.width * k) / 2.0);
      int offsetY = (int) Math.round((diagramView.getHeight() - bounds.height * k) / 2.0);

      diagramView.setOffsets(offsetX, offsetY);

      if (parent.getComponentCount() > 0) {
        repositionDecorations(parent);
      }

      //            Component component = parent.getComponent(0);
      //            if (!(component instanceof NavigationTools)) {
      //                return;
      //            }
      //            component.setBounds(0, 0, parent.getWidth(), parent.getHeight());

    }
  }
Beispiel #13
0
 /**
  * Sets the font for a component and all components contained within it.
  *
  * @param c the parent component of the component subtree to set
  * @param font the font to set
  */
 public static void setFont(Component c, Font font) {
   c.setFont(font);
   if (c instanceof Container) {
     Container con = (Container) c;
     for (int i = 0; i < con.getComponentCount(); ++i) setFont(con.getComponent(i), font);
   }
 }
    @Override
    public void layoutContainer(final Container parent) {
      final int componentCount = parent.getComponentCount();
      if (componentCount == 0) return;
      final EditorEx history = myHistoryViewer;
      final EditorEx editor = componentCount == 2 ? myConsoleEditor : null;

      if (editor == null) {
        parent.getComponent(0).setBounds(parent.getBounds());
        return;
      }

      final Dimension panelSize = parent.getSize();
      if (panelSize.getHeight() <= 0) return;
      final Dimension historySize = history.getContentSize();
      final Dimension editorSize = editor.getContentSize();
      final Dimension newEditorSize = new Dimension();

      // deal with width
      final int width = Math.max(editorSize.width, historySize.width);
      newEditorSize.width = width + editor.getScrollPane().getHorizontalScrollBar().getHeight();
      history.getSoftWrapModel().forceAdditionalColumnsUsage();
      editor
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - editorSize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, editor));
      history
          .getSettings()
          .setAdditionalColumnsCount(
              2 + (width - historySize.width) / EditorUtil.getSpaceWidth(Font.PLAIN, history));

      // deal with height
      if (historySize.width == 0) historySize.height = 0;
      final int minHistorySize =
          historySize.height > 0
              ? 2 * history.getLineHeight() + (myShowSeparatorLine ? SEPARATOR_THICKNESS : 0)
              : 0;
      final int minEditorSize = editor.isViewer() ? 0 : editor.getLineHeight();
      final int editorPreferred =
          editor.isViewer() ? 0 : Math.max(minEditorSize, editorSize.height);
      final int historyPreferred = Math.max(minHistorySize, historySize.height);
      if (panelSize.height < minEditorSize) {
        newEditorSize.height = panelSize.height;
      } else if (panelSize.height < editorPreferred) {
        newEditorSize.height = panelSize.height - minHistorySize;
      } else if (panelSize.height < editorPreferred + historyPreferred) {
        newEditorSize.height = editorPreferred;
      } else {
        newEditorSize.height = editorPreferred == 0 ? 0 : panelSize.height - historyPreferred;
      }
      final Dimension newHistorySize =
          new Dimension(width, panelSize.height - newEditorSize.height);

      // apply
      editor
          .getComponent()
          .setBounds(0, newHistorySize.height, panelSize.width, newEditorSize.height);
      myForceScrollToEnd.compareAndSet(false, shouldScrollHistoryToEnd());
      history.getComponent().setBounds(0, 0, panelSize.width, newHistorySize.height);
    }
  public void setSizes(Container parent) {
    if (sizesSet) return;
    int n = parent.getComponentCount();

    preferredWidth = 0;
    preferredHeight = 0;
    minWidth = 0;
    minHeight = 0;
    maxComponentWidth = 0;
    maxComponentHeight = 0;

    // compute the maximum component widths and heights
    // and set the preferred size to the sum of the component sizes.
    for (int i = 0; i < n; i++) {
      Component c = parent.getComponent(i);
      if (c.isVisible()) {
        Dimension d = c.getPreferredSize();
        maxComponentWidth = Math.max(maxComponentWidth, d.width);
        maxComponentHeight = Math.max(maxComponentHeight, d.height);
        preferredWidth += d.width;
        preferredHeight += d.height;
      }
    }
    minWidth = preferredWidth / 2;
    minHeight = preferredHeight / 2;
    sizesSet = true;
  }
  /**
   * Calculates the preferred size dimensions for the specified panel given the components in the
   * specified parent container.
   *
   * @param target The component to be laid out.
   * @return A size deemed suitable for laying out the container.
   * @see #minimumLayoutSize
   */
  public Dimension preferredLayoutSize(Container target) {
    int count;
    Component component;
    Dimension dimension;
    Insets insets;
    Dimension ret;

    synchronized (target.getTreeLock()) {
      // get the the total height and maximum width component
      ret = new Dimension(0, 0);
      count = target.getComponentCount();
      for (int i = 0; i < count; i++) {
        component = target.getComponent(i);
        if (component.isVisible()) {
          dimension = component.getPreferredSize();
          ret.width = Math.max(ret.width, dimension.width);
          ret.height += dimension.height;
        }
      }
      insets = target.getInsets();
      ret.width += insets.left + insets.right;
      ret.height += insets.top + insets.bottom;
    }

    return (ret);
  }
Beispiel #17
0
  /**
   * Checks the component and all children to ensure that everything is pure Swing. We can only draw
   * lightweights.
   *
   * <p>We'll also set PopupMenus to heavyweight and fix JViewport blitting.
   */
  protected void verifyHierarchy(Component comp) {
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);

    if (comp instanceof JComponent) {
      ((JComponent) comp).setDoubleBuffered(false);
    }

    if (!(comp instanceof JComponent)) {
      Logger.getLogger(GLG2DCanvas.class.getName())
          .warning(
              "Drawable component and children should be pure Swing: "
                  + comp
                  + " does not inherit JComponent");
    }

    if (comp instanceof JViewport) {
      ((JViewport) comp).setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
    }

    if (comp instanceof Container) {
      Container cont = (Container) comp;
      for (int i = 0; i < cont.getComponentCount(); i++) {
        verifyHierarchy(cont.getComponent(i));
      }
    }
  }
  private boolean is(boolean first) {
    Container parent = getParent();
    if (parent == null) return false;

    int max = first ? Integer.MAX_VALUE : 0;
    ToolWindowAnchor anchor = getAnchor();
    Component c = null;
    int count = parent.getComponentCount();
    for (int i = 0; i < count; i++) {
      Component component = parent.getComponent(i);
      if (!component.isVisible()) continue;
      Rectangle r = component.getBounds();
      if (anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT) {
        if (first && (max > r.y) || (!first && max < r.y)) {
          max = r.y;
          c = component;
        }
      } else {
        if (first && (max > r.x) || (!first && max < r.x)) {
          max = r.x;
          c = component;
        }
      }
    }

    return c == this;
  }
 private void setSizes(Container parent) {
   int nComps = parent.getComponentCount();
   this.preferredWidth = 0;
   this.preferredHeight = 0;
   this.minWidth = 0;
   this.minHeight = 0;
   for (int i = 0; i < nComps; i++) {
     Component c = parent.getComponent(i);
     if (c.isVisible()) {
       Dimension d = c.getPreferredSize();
       if (this.maxCompWidth < d.width) {
         this.maxCompWidth = d.width;
       }
       if (this.maxCompHeight < d.height) {
         this.maxCompHeight = d.height;
       }
       this.preferredWidth += d.width;
       this.preferredHeight += d.height;
     }
   }
   this.preferredWidth /= 2;
   this.preferredHeight /= 2;
   this.minWidth = this.preferredWidth;
   this.minHeight = this.preferredHeight;
 }
Beispiel #20
0
 public Dimension preferredLayoutSize(Container target) {
   Insets insets = target.getInsets();
   Dimension compMax = new Dimension(0, 0);
   int maxheight = target.getBounds().height - (insets.top + insets.bottom + vgap * 2);
   int nmembers = target.getComponentCount();
   int visiblecount = 0;
   for (int i = 0; i < nmembers; i++) {
     Component m = target.getComponent(i);
     if (m.isVisible()) {
       ++visiblecount;
       Dimension d = m.getPreferredSize();
       compMax.width = Math.max(compMax.width, d.width);
       compMax.height = Math.max(compMax.height, d.height);
     }
   }
   if (visiblecount > 0) {
     int nrows = Math.max(1, (maxheight + compMax.height / 4) / compMax.height);
     int ncols = (visiblecount + nrows - 1) / nrows;
     compMax.height = compMax.height * nrows + vgap * (nrows - 1);
     compMax.width = compMax.width * ncols + hgap * (ncols - 1);
   }
   compMax.height += insets.top + insets.bottom + vgap * 2;
   compMax.width += insets.left + insets.right + hgap * 2;
   return compMax;
 }
Beispiel #21
0
  /**
   * Replace the current contents of the frame's content pane.
   *
   * @param panel JPanel of the new contents of the content pane.
   */
  public void replace(JPanel panel) {
    // Removes everything from the content pane.
    for (int i = 0; i < pane.getComponentCount(); i++) {
      pane.remove(i);
    }

    pane.add(panel);
  }
Beispiel #22
0
 /**
  * Sets the foreground and background color for a component and all components contained within
  * it.
  *
  * @param c the parent component of the component subtree to set
  * @param back the background color to set
  * @param fore the foreground color to set
  */
 public static void setColor(Component c, Color back, Color fore) {
   c.setBackground(back);
   c.setForeground(fore);
   if (c instanceof Container) {
     Container con = (Container) c;
     for (int i = 0; i < con.getComponentCount(); ++i) setColor(con.getComponent(i), back, fore);
   }
 }
 private void wireDragAndDrop(Component comp) {
   comp.setDropTarget(new DropTarget(this, new JitterbugDropHandler()));
   if (comp instanceof Container) {
     Container cont = (Container) comp;
     for (int i = 0; i < cont.getComponentCount(); i++) {
       wireDragAndDrop(cont.getComponent(i));
     }
   }
 }
  public static final Component getChildAtLine(
      Container container, Point point, boolean horizontal) {
    if (horizontal) {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component component = container.getComponent(i);
        if (point.x >= component.getX() && point.x < component.getX() + component.getWidth())
          return component;
      }
    } else {
      for (int i = 0; i < container.getComponentCount(); i++) {
        Component component = container.getComponent(i);
        if (point.y >= component.getY() && point.y < component.getY() + component.getHeight())
          return component;
      }
    }

    return null;
  }
 public static void setAllOpaque(Container container, boolean opaque) {
   if (container instanceof JComponent) {
     ((JComponent) container).setOpaque(opaque);
     for (int i = 0; i < container.getComponentCount(); i++) {
       Component component = container.getComponent(i);
       if (component instanceof Container) setAllOpaque((Container) component, opaque);
     }
   }
 }
Beispiel #26
0
 public static void recursiveSetBackground(Component comp, Color color) {
   if (comp instanceof JToolBar || comp instanceof JButton) return;
   comp.setBackground(color);
   if (comp instanceof Container) {
     Container cc = (Container) comp;
     for (int i = 0; i < cc.getComponentCount(); i++)
       recursiveSetBackground(cc.getComponent(i), color);
   }
 }
Beispiel #27
0
 protected void setBorderToRollover(Component c) {
   if (c instanceof AbstractButton) {
     super.setBorderToRollover(c);
   } else if (c instanceof Container) {
     Container cont = (Container) c;
     for (int i = 0; i < cont.getComponentCount(); i++)
       super.setBorderToRollover(cont.getComponent(i));
   }
 }
Beispiel #28
0
  /**
   * <code>PlanWorks</code> - constructor
   *
   * @param constantMenus - <code>JMenu[]</code> -
   */
  public PlanWorks(JMenu[] constantMenus) {
    super(name, constantMenus);
    projectMenu.setEnabled(false);
    currentProjectName = "";
    currentProject = null;
    viewManager = null;
    sequenceDirChooser = new DirectoryChooser();
    createDirectoryChooser();
    // Closes from title bar
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
    if (isMaxScreen) {
      Rectangle maxRectangle =
          GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
      this.setSize((int) maxRectangle.getWidth(), (int) maxRectangle.getHeight());
      this.setLocation(0, 0);
    } else {
      this.setSize(DESKTOP_FRAME_WIDTH, DESKTOP_FRAME_HEIGHT);
      this.setLocation(FRAME_X_LOCATION, FRAME_Y_LOCATION);
    }
    Container contentPane = getContentPane();
    for (int i = 0, n = contentPane.getComponentCount(); i < n; i++) {
      // System.err.println( "i " + i + " " +
      //                    contentPane.getComponent( i).getClass().getName());
      if (contentPane.getComponent(i) instanceof MDIDesktopPane) {
        ((MDIDesktopPane) contentPane.getComponent(i))
            .setBackground(ViewConstants.VIEW_BACKGROUND_COLOR);
        break;
      }
    }
    supportedViewNames = Utilities.sortStringKeySet(viewClassNameMap);
    this.setVisible(true);
    if (usingSplash) {
      this.toBack();
    }

    setProjectMenuEnabled(CREATE_MENU_ITEM, true);
    setProjectMenuEnabled(ADDSEQ_MENU_ITEM, false);
    setProjectMenuEnabled(DELSEQ_MENU_ITEM, false);
    if ((PwProject.listProjects() != null) && (PwProject.listProjects().size() > 0)) {
      setProjectMenuEnabled(OPEN_MENU_ITEM, true);
      setProjectMenuEnabled(DELETE_MENU_ITEM, true);
    } else {
      setProjectMenuEnabled(OPEN_MENU_ITEM, false);
      setProjectMenuEnabled(DELETE_MENU_ITEM, false);
    }
    projectMenu.setEnabled(true);
    windowBuilt = true;
    if (usingSplash) {
      this.toFront();
    }
  } // end constructor
Beispiel #29
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;
    }
  }
 @Override
 public Dimension preferredLayoutSize(final Container parent) {
   Dimension result = new Dimension();
   for (int i = 0; i < parent.getComponentCount(); i++) {
     final Dimension prefSize = parent.getComponent(i).getPreferredSize();
     result.width += prefSize.width;
     result.height = Math.max(prefSize.height, result.height);
   }
   return result;
 }