public Dimension preferredLayoutSize(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.getPreferredSize();
            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.getPreferredSize();
            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;
    }
Esempio n. 2
0
  /**
   * Used to forcibly insert items at the end of the primary menu. Useful if you have items that you
   * don't want who knows how many levels deep in the more structure.
   */
  public void insertStatic(Component c) {
    // Determine if the Component can fit already
    // If yes
    //   Just do a regular insert, we're done.
    // else
    //   do
    //      Put the standard item closest to the more
    //      menu in the more menu
    //   until the static component (c) can fit in this menu
    //   do a regular insert(component)

    double componentHeight = c.getPreferredSize().getHeight();

    if ((myHeight + componentHeight) < maximumHeight - componentHeight) {
      // Force the component to go below the moreMenu
      super.add(c);
      myHeight += c.getPreferredSize().getHeight();
    } else {
      int itemCount = getMenuComponentCount();
      Component componentToMove = null;
      do {
        // the standard item is 1 before
        // the more menu hence -1
        int index = getComponentIndex(moreMenu);
        componentToMove = getComponentAtIndex(index - 1);

        moreMenu.insert(componentToMove, 0);
        // super.remove(componentToMove);
        myHeight -= componentToMove.getPreferredSize().getHeight();
        itemCount = getMenuComponentCount();
      } while ((componentHeight + myHeight) >= maximumHeight);
      super.add(c);
      myHeight += c.getPreferredSize().getHeight();
    }
  }
Esempio n. 3
0
    /**
     * Calculates the maximum size dimensions for the specified panal given the components in the
     * specified parent container.
     */
    public Dimension maximumLayoutSize(Container target) {
      synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int size = actions.size();
        if ((grip != null) && grip.isVisible()) {
          Dimension d = grip.getPreferredSize();
          dim.width += d.width;
          dim.width += hgap;
        }
        Component last = null;
        for (int i = 0; i < size; i++) {
          Component comp = (Component) actions.elementAt(i);
          if (comp.isVisible()) {
            Dimension d = comp.getPreferredSize();
            dim.width += d.width;
            dim.height = Math.max(dim.height, d.height);
            dim.width += hgap;
            last = comp;
          }
        }
        if (last != null) {
          Dimension prefSize = last.getPreferredSize();
          Dimension maxSize = last.getMaximumSize();
          if (prefSize != maxSize) {
            dim.width = dim.width - prefSize.width + maxSize.width;
            dim.height = Math.max(dim.height, maxSize.height);
          }
        }
        Insets insets = target.getInsets();
        dim.width += insets.left + insets.right;
        dim.height += insets.top + insets.bottom;

        return dim;
      }
    }
Esempio n. 4
0
  public void packColumn(JTable table, int vColIndex, int margin) {
    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
    TableColumn col = colModel.getColumn(vColIndex);
    int width = 0;

    // Get width of column header
    TableCellRenderer renderer = col.getHeaderRenderer();
    if (renderer == null) {
      renderer = table.getTableHeader().getDefaultRenderer();
    }
    Component comp =
        renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0, 0);
    width = comp.getPreferredSize().width;

    // Get maximum width of column data
    for (int r = 0; r < table.getRowCount(); r++) {
      renderer = table.getCellRenderer(r, vColIndex);
      comp =
          renderer.getTableCellRendererComponent(
              table, table.getValueAt(r, vColIndex), false, false, r, vColIndex);
      width = Math.max(width, comp.getPreferredSize().width);
    }

    // Add margin
    width += 2 * margin;

    // Set the width
    col.setPreferredWidth(width);
  }
 public void
     setColumnWidths() { // See
                         // "http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#custom"
   int n = getModel().getColumnCount();
   for (int j = 0; j < n; ++j) {
     TableColumn column = getColumnModel().getColumn(j);
     TableCellRenderer headerRenderer = column.getHeaderRenderer();
     if (headerRenderer == null)
       headerRenderer = getTableHeader().getDefaultRenderer(); // the new 1.3 way
     Component columnComponent =
         headerRenderer.getTableCellRendererComponent(
             this, column.getHeaderValue(), false, false, -1, j);
     Component cellComponent =
         getDefaultRenderer(getColumnClass(j))
             .getTableCellRendererComponent(this, getModel().getValueAt(0, j), false, false, 0, j);
     int wantWidth =
         Math.max(
             columnComponent.getPreferredSize().width
                 + 10, // fudge factor ... seems to always be too small otherwise (on x86 Linux)
             cellComponent.getPreferredSize().width
                 + 10 // fudge factor ... seems to always be too small otherwise (on Mac OS X)
             );
     column.setPreferredWidth(wantWidth);
   }
 }
Esempio n. 6
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 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;
     }
   }
 }
    @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. 9
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;
        }
      }
    }
 public void layoutContainer(Container parent) {
   Insets insets = parent.getInsets();
   int maxWidth = parent.getSize().width - (insets.left + insets.right);
   int maxHeight = parent.getSize().height - (insets.top + insets.bottom);
   int nComps = parent.getComponentCount();
   if (this.sizeUnknown) {
     setSizes(parent);
   }
   Component c;
   if (nComps < 2) {
     c = parent.getComponent(0);
     if (c.isVisible()) {
       Dimension d = c.getPreferredSize();
       c.setBounds(0, 0, d.width, d.height);
       return;
     }
     return;
   }
   double radialCurrent = Math.toRadians(SpiderWebPlot.DEFAULT_START_ANGLE);
   double radialIncrement = 6.283185307179586d / ((double) nComps);
   int midX = maxWidth / 2;
   int midY = maxHeight / 2;
   int a = midX - this.maxCompWidth;
   int b = midY - this.maxCompHeight;
   for (int i = 0; i < nComps; i++) {
     c = parent.getComponent(i);
     if (c.isVisible()) {
       d = c.getPreferredSize();
       double d2 = (double) midX;
       double d3 = (double) a;
       int x =
           (int)
               (((r0 - (r0 * Math.cos(radialCurrent)))
                       - (d.getWidth() / DateAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS))
                   + ((double) insets.left));
       d2 = (double) midY;
       d3 = (double) b;
       c.setBounds(
           x,
           (int)
               (((r0 - (r0 * Math.sin(radialCurrent)))
                       - (d.getHeight()
                           / DateAxis.DEFAULT_AUTO_RANGE_MINIMUM_SIZE_IN_MILLISECONDS))
                   + ((double) insets.top)),
           d.width,
           d.height);
     }
     radialCurrent += radialIncrement;
   }
 }
Esempio n. 11
0
 /**
  * Size each column to something reasonable We do this by getting the width of the letter 'M" from
  * the default Table Header Renderer and set the preferred width of the column as the width of
  * some number of 'M's.
  *
  * @return int
  */
 private int getStandardCharacterWidth() {
   // The preferredSize of the component is more than just the character
   // So we remove the extra determining the delta
   // between one and two chars
   final JTableHeader th = getTableHeader();
   final TableCellRenderer renderer = th.getDefaultRenderer();
   Component comp =
       renderer.getTableCellRendererComponent(this, ONE_STANDARD_CHARACTER, false, false, 0, 0);
   final int oneStandardCharacterWidth = comp.getPreferredSize().width;
   comp =
       renderer.getTableCellRendererComponent(this, TWO_STANDARD_CHARACTERS, false, false, 0, 0);
   final int twoStandardCharactersWidth = comp.getPreferredSize().width;
   return twoStandardCharactersWidth - oneStandardCharacterWidth;
 }
Esempio n. 12
0
 @Override
 public Insets getBorderInsets(Component c) {
   Dimension size = comp.getPreferredSize();
   Insets insets = border.getBorderInsets(c);
   insets.top = Math.max(insets.top, size.height);
   return insets;
 }
Esempio n. 13
0
    public void pack() {
      Component component = getComponent();

      if (component != null) {
        component.setSize(component.getPreferredSize());
      }
    }
Esempio n. 14
0
  private int getHeaderHeight() {
    if ((header == null) || (header.getTable() == null)) {
      return 0;
    }
    int height = 0;
    boolean accomodatedDefault = false;
    TableColumnModel columnModel = header.getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
      TableColumn aColumn = columnModel.getColumn(column);
      boolean isDefault = (aColumn.getHeaderRenderer() == null);

      if (!isDefault || !accomodatedDefault) {
        Component comp = getHeaderRenderer(column);
        int rendererHeight = comp.getPreferredSize().height;
        height = Math.max(height, rendererHeight);

        // Configuring the header renderer to calculate its preferred size
        // is expensive. Optimise this by assuming the default renderer
        // always has the same height as the first non-zero height that
        // it returns for a non-null/non-empty value.
        if (isDefault && rendererHeight > 0) {
          Object headerValue = aColumn.getHeaderValue();
          if (headerValue != null) {
            headerValue = headerValue.toString();

            if (headerValue != null && !headerValue.equals("")) {
              accomodatedDefault = true;
            }
          }
        }
      }
    }
    return height + 2;
  }
Esempio n. 15
0
    @Override
    public java.awt.Dimension preferredLayoutSize(java.awt.Container parent) {
      synchronized (parent.getTreeLock()) {
        org.lgna.croquet.CardOwnerComposite cardOwner =
            (org.lgna.croquet.CardOwnerComposite) getComposite();

        int widthMax = 0;
        int heightMax = 0;

        for (org.lgna.croquet.Composite<?> card : cardOwner.getCards()) {
          if (cardOwner.isCardAccountedForInPreferredSizeCalculation(card)) {
            java.awt.Component awtChild = card.getRootComponent().getAwtComponent();
            java.awt.Dimension awtChildPreferredSize = awtChild.getPreferredSize();
            widthMax = Math.max(widthMax, awtChildPreferredSize.width);
            heightMax = Math.max(heightMax, awtChildPreferredSize.height);
          }
        }
        java.awt.Insets insets = parent.getInsets();
        int hgap = this.getHgap();
        int vgap = this.getVgap();
        return new java.awt.Dimension(
            hgap + insets.left + widthMax + insets.right + hgap,
            vgap + insets.top + heightMax + insets.bottom + vgap);
      }
    }
Esempio n. 16
0
  private static Pair<Image, Point> createDragImage(
      final Tree tree, final Component c, Point dragOrigin, boolean adjustToPathUnderDragOrigin) {
    if (c instanceof JComponent) {
      ((JComponent) c).setOpaque(true);
    }

    c.setForeground(tree.getForeground());
    c.setBackground(tree.getBackground());
    c.setFont(tree.getFont());
    c.setSize(c.getPreferredSize());
    final BufferedImage image =
        new BufferedImage(c.getWidth(), c.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
    c.paint(g2);
    g2.dispose();

    Point point = new Point(-image.getWidth(null) / 2, -image.getHeight(null) / 2);

    if (adjustToPathUnderDragOrigin) {
      TreePath path = tree.getPathForLocation(dragOrigin.x, dragOrigin.y);
      if (path != null) {
        Rectangle bounds = tree.getPathBounds(path);
        point = new Point(bounds.x - dragOrigin.x, bounds.y - dragOrigin.y);
      }
    }

    return new Pair<Image, Point>(image, point);
  }
Esempio n. 17
0
  private void packColumns(int inMargin) {
    TableModel model = this.table.getModel();
    DefaultTableColumnModel columnModel = (DefaultTableColumnModel) table.getColumnModel();

    for (int col = 0; col < this.table.getColumnCount(); col++) {
      TableColumn column = columnModel.getColumn(col);

      int width = 0;

      // determine widest row in column
      for (int row = 0; row < this.table.getRowCount(); row++) {
        TableCellRenderer renderer = this.table.getCellRenderer(row, col);
        Component component =
            renderer.getTableCellRendererComponent(
                this.table, this.table.getValueAt(row, col), false, false, row, col);

        width = Math.max(width, component.getPreferredSize().width);
      }

      // add the margin
      width += 2 * inMargin;

      column.setPreferredWidth(width);
    }
  }
Esempio n. 18
0
  /**
   * Calculates the optimal width for the header of the given table. The calculation is based on the
   * preferred width of the header renderer.
   *
   * @param table the table to calculate the column width
   * @param col the column to calculate the widths
   * @return the width, -1 if error
   */
  public static int calcHeaderWidth(JTable table, int col) {
    if (table == null) return -1;

    if (col < 0 || col > table.getColumnCount()) {
      System.out.println("invalid col " + col);
      return -1;
    }

    JTableHeader header = table.getTableHeader();
    TableCellRenderer defaultHeaderRenderer = null;
    if (header != null) defaultHeaderRenderer = header.getDefaultRenderer();
    TableColumnModel columns = table.getColumnModel();
    TableModel data = table.getModel();
    TableColumn column = columns.getColumn(col);
    int width = -1;
    TableCellRenderer h = column.getHeaderRenderer();
    if (h == null) h = defaultHeaderRenderer;
    if (h != null) {
      // Not explicitly impossible
      Component c =
          h.getTableCellRendererComponent(table, column.getHeaderValue(), false, false, -1, col);
      width = c.getPreferredSize().width + 5;
    }

    return width;
  }
 private void disposeAndUpdate(boolean update) {
   if (myView != null) {
     boolean visible = myView.isVisible();
     myView.setVisible(false);
     Container container = myContent.getParent();
     if (container != null) {
       container.remove(myContent);
     }
     if (myView instanceof Window) {
       myViewBounds = myView.getBounds();
       Window window = (Window) myView;
       if (!push(UIUtil.getWindow(myOwner), window)) {
         window.dispose();
       }
     } else {
       Container parent = myView.getParent();
       if (parent == null) {
         myViewBounds = new Rectangle(myContent.getPreferredSize());
       } else {
         myViewBounds = new Rectangle(myView.getBounds());
         parent.remove(myView);
         Point point = new Point(myViewBounds.x, myViewBounds.y);
         SwingUtilities.convertPointToScreen(point, parent);
         myViewBounds.x = point.x;
         myViewBounds.y = point.y;
       }
     }
     myView = null;
     if (update && visible) {
       setVisible(true);
     }
   }
 }
Esempio n. 20
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;
      }
    }
  }
 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;
 }
Esempio n. 22
0
  @Override
  public int getRowHeight() {
    if (myRowHeightIsComputing) {
      return super.getRowHeight();
    }

    if (myRowHeight < 0) {
      try {
        myRowHeightIsComputing = true;
        for (int row = 0; row < getRowCount(); row++) {
          for (int column = 0; column < getColumnCount(); column++) {
            final TableCellRenderer renderer = getCellRenderer(row, column);
            if (renderer != null) {
              final Object value = getValueAt(row, column);
              final Component component =
                  renderer.getTableCellRendererComponent(this, value, true, true, row, column);
              if (component != null) {
                final Dimension size = component.getPreferredSize();
                myRowHeight = Math.max(size.height, myRowHeight);
              }
            }
          }
        }
      } finally {
        myRowHeightIsComputing = false;
      }
    }

    if (myMinRowHeight == null) {
      myMinRowHeight = getFontMetrics(UIManager.getFont("Label.font")).getHeight();
    }

    return Math.max(myRowHeight, myMinRowHeight);
  }
    @Override
    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      setFont(table.getFont());
      setText((value == null) ? "" : " " + value.toString());

      if ((row == -1) && (column == 0)) { // No. column header
        int width_header = getPreferredSize().width + 2;
        int width_numbers = 25;

        if (data.getRowCount() > 0) {
          TableCellRenderer r = table.getCellRenderer(data.getRowCount() - 1, 0);
          Component c =
              r.getTableCellRendererComponent(
                  table,
                  ((ConstructionTableData) data).getValueAt(data.getRowCount() - 1, 0),
                  false,
                  false,
                  data.getRowCount() - 1,
                  0);
          // width = Math.max(width, c.getPreferredSize().width +2);
          width_numbers = Math.max(width_numbers, c.getPreferredSize().width + 2);
        }

        // tableColumns[0].setMaxWidth(width);
        tableColumns[0].setMinWidth(width_numbers);
        tableColumns[0].setMaxWidth(Math.max(width_numbers, width_header));
        // tableColumns[0].setPreferredWidth(width);
      }

      return this;
    }
Esempio n. 24
0
  @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 static Point fixPopupLocation(final Component contents, final int x, final int y) {
      if (!(contents instanceof JToolTip)) return new Point(x, y);

      final PointerInfo info;
      try {
        info = MouseInfo.getPointerInfo();
      } catch (InternalError e) {
        // http://www.jetbrains.net/jira/browse/IDEADEV-21390
        // may happen under Mac OSX 10.5
        return new Point(x, y);
      }
      int deltaY = 0;

      if (info != null) {
        final Point mouse = info.getLocation();
        deltaY = mouse.y - y;
      }

      final Dimension size = contents.getPreferredSize();
      final Rectangle rec = new Rectangle(new Point(x, y), size);
      ScreenUtil.moveRectangleToFitTheScreen(rec);

      if (rec.y < y) {
        rec.y += deltaY;
      }

      return rec.getLocation();
    }
Esempio n. 26
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;
     }
   }
 }
Esempio n. 27
0
    public void layoutContainer(Container parent) {
      Dimension size = parent.getSize();
      Insets insets = parent.getInsets();
      int itop = insets.top;
      int ileft = insets.left;
      int ibottom = insets.bottom;
      int iright = insets.right;

      int rightWidth = right.getPreferredSize().width;
      int bottomHeight = bottom.getPreferredSize().height;
      int centerWidth = size.width - rightWidth - ileft - iright;
      int centerHeight = size.height - bottomHeight - itop - ibottom;

      center.setBounds(ileft, itop, centerWidth, centerHeight);

      right.setBounds(ileft + centerWidth, itop, rightWidth, centerHeight);

      // Lay out all status components, in order
      Enumeration status = leftOfScrollBar.elements();
      while (status.hasMoreElements()) {
        Component comp = (Component) status.nextElement();
        Dimension dim = comp.getPreferredSize();
        comp.setBounds(ileft, itop + centerHeight, dim.width, bottomHeight);
        ileft += dim.width;
      }

      bottom.setBounds(
          ileft, itop + centerHeight, size.width - rightWidth - ileft - iright, bottomHeight);
    }
Esempio n. 28
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;
 }
Esempio n. 29
0
  /**
   * 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);
  }
Esempio n. 30
0
 public Dimension preferredLayoutSize(Container parent) {
   return LayoutUtil.add(
       useSelectedComponentSize
           ? component == null ? new Dimension(0, 0) : component.getPreferredSize()
           : LayoutUtil.getMaxPreferredSize(parent.getComponents()),
       parent.getInsets());
 }