コード例 #1
0
ファイル: IdeaTitledBorder.java プロジェクト: ernestp/consulo
 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)));
 }
コード例 #2
0
 @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);
 }
コード例 #3
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);
  }
コード例 #4
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;
        }
      }
    }
 /**
  * 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());
 }
コード例 #6
0
  /**
   * Creates the appropriate object to represent each of the objects in <code>buttons</code> and
   * adds it to <code>container</code>. This differs from addMessageComponents in that it will
   * recurse on <code>buttons</code> and that if button is not a Component it will create an
   * instance of JButton.
   */
  protected void addButtonComponents(Container container, Object[] buttons, int initialIndex) {
    if (buttons != null && buttons.length > 0) {
      boolean sizeButtonsToSame = getSizeButtonsToSameWidth();
      boolean createdAll = true;
      int numButtons = buttons.length;
      JButton[] createdButtons = null;
      int maxWidth = 0;

      if (sizeButtonsToSame) {
        createdButtons = new JButton[numButtons];
      }

      for (int counter = 0; counter < numButtons; counter++) {
        Object button = buttons[counter];
        Component newComponent;

        if (button instanceof Component) {
          createdAll = false;
          newComponent = (Component) button;
          container.add(newComponent);
          hasCustomComponents = true;

        } else {
          JButton aButton;

          if (button instanceof ButtonFactory) {
            aButton = ((ButtonFactory) button).createButton();
          } else if (button instanceof Icon) aButton = new JButton((Icon) button);
          else aButton = new JButton(button.toString());

          aButton.setName("OptionPane.button");
          aButton.setMultiClickThreshhold(
              DefaultLookup.getInt(optionPane, this, "OptionPane.buttonClickThreshhold", 0));
          configureButton(aButton);

          container.add(aButton);

          ActionListener buttonListener = createButtonActionListener(counter);
          if (buttonListener != null) {
            aButton.addActionListener(buttonListener);
          }
          newComponent = aButton;
        }
        if (sizeButtonsToSame && createdAll && (newComponent instanceof JButton)) {
          createdButtons[counter] = (JButton) newComponent;
          maxWidth = Math.max(maxWidth, newComponent.getMinimumSize().width);
        }
        if (counter == initialIndex) {
          initialFocusComponent = newComponent;
          if (initialFocusComponent instanceof JButton) {
            JButton defaultB = (JButton) initialFocusComponent;
            defaultB.addHierarchyListener(
                new HierarchyListener() {
                  public void hierarchyChanged(HierarchyEvent e) {
                    if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) != 0) {
                      JButton defaultButton = (JButton) e.getComponent();
                      JRootPane root = SwingUtilities.getRootPane(defaultButton);
                      if (root != null) {
                        root.setDefaultButton(defaultButton);
                      }
                    }
                  }
                });
          }
        }
      }
      ((ButtonAreaLayout) container.getLayout())
          .setSyncAllWidths((sizeButtonsToSame && createdAll));
      /* Set the padding, windows seems to use 8 if <= 2 components,
      otherwise 4 is used. It may actually just be the size of the
      buttons is always the same, not sure. */
      if (DefaultLookup.getBoolean(optionPane, this, "OptionPane.setButtonMargin", true)
          && sizeButtonsToSame
          && createdAll) {
        JButton aButton;
        int padSize;

        padSize = (numButtons <= 2 ? 8 : 4);

        for (int counter = 0; counter < numButtons; counter++) {
          aButton = createdButtons[counter];
          aButton.setMargin(new Insets(2, padSize, 2, padSize));
        }
      }
    }
  }
コード例 #7
0
ファイル: JBeanEditor.java プロジェクト: fommil/common-utils
 //        @Override
 //        public Component prepareEditor(TableCellEditor editor, int row, int column) {
 //            Component prepareEditor = super.prepareEditor(editor, row, column);
 //            customiseMinimumDimensions(prepareEditor.getMinimumSize(), row, column);
 //            return prepareEditor;
 //        }
 @Override
 public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
   Component prepareRenderer = super.prepareRenderer(renderer, row, column);
   customiseMinimumDimensions(prepareRenderer.getMinimumSize(), row, column);
   return prepareRenderer;
 }
コード例 #8
0
  public void layoutContainer(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;
    }

    // Set heights
    int x;
    int y;
    int nFills = 0;
    boolean[] fills = new boolean[nrows];
    int lastFillRow = -1;
    int nComps = parent.getComponentCount();

    y = insets.top;
    for (int row = 0; row < nrows; row++) {
      // Find largest minimum height for this 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);
        }
      }
      // Set heights for this row
      x = insets.left;
      for (int col = 0; col < ncols; col++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int w = c.getWidth();
          c.setBounds(x, y, w, h);
          x += w + hgap;
          if (col == 0 && getFillRow(c)) {
            fills[row] = true;
          }
        }
      }
      y += h + vgap;
      if (fills[row]) {
        nFills++;
        lastFillRow = row;
      }
    }

    // Fill heights
    if (nFills > 0 && y < parent.getHeight()) {
      // How much height to add
      int hAdd = (parent.getHeight() - y) / nFills;
      int hAdded = 0;
      for (int row = 0; row < nrows; row++) {
        if (fills[row]) {
          if (row == lastFillRow) {
            // Compensate for rounding error
            hAdd = parent.getHeight() - (y + hAdded);
          }
          for (int col = 0; col < ncols; col++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x, b.y + hAdded, b.width, b.height + hAdd);
            }
          }
          hAdded += hAdd;
        }
      }
    }

    // Set widths
    nFills = 0;
    fills = new boolean[ncols];
    int lastFillCol = -1;

    x = insets.left;
    for (int col = 0; col < ncols; col++) {
      // Find largest minimum width for this column
      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);
        }
      }
      // Set widths for this column
      y = insets.top;
      for (int row = 0; row < nrows; row++) {
        if (row * ncols + col < nComps) {
          JComponent c = (JComponent) parent.getComponent(row * ncols + col);
          int h = c.getHeight();
          c.setBounds(x, y, w, h);
          y += h + vgap;
          if (row == 0 && getFillColumn(c)) {
            fills[col] = true;
          }
        }
      }
      x += w + hgap;
      if (fills[col]) {
        nFills++;
        lastFillCol = col;
      }
    }

    // Fill widths
    if (nFills > 0 && x < parent.getWidth()) {
      // How much width to add
      int wAdd = (parent.getWidth() - x) / nFills;
      int wAdded = 0;
      for (int col = 0; col < ncols; col++) {
        if (fills[col]) {
          if (col == lastFillCol) {
            wAdd = parent.getWidth() - (x + wAdded);
          }
          for (int row = 0; row < nrows; row++) {
            if (row * ncols + col < nComps) {
              Component c = parent.getComponent(row * ncols + col);
              Rectangle b = c.getBounds();
              c.setBounds(b.x + wAdded, b.y, b.width + wAdd, b.height);
            }
          }
          wAdded += wAdd;
        }
      }
    }
  }