@Override
 public void layoutContainer(Container parent) {
   int width = parent.getWidth();
   int height = parent.getHeight();
   Component toolbar = parent.getComponent(0);
   Dimension toolbarSize = toolbar.isVisible() ? toolbar.getPreferredSize() : new Dimension();
   toolbar.setBounds(0, 0, width, toolbarSize.height);
   parent.getComponent(1).setBounds(0, toolbarSize.height, width, height - toolbarSize.height);
 }
예제 #2
0
 public int getHeight() {
   float fHeight;
   int height;
   fHeight = scale * nativeGetMaxDepth();
   height = Math.round(fHeight) + (2 * margin);
   if (parentContainer == null) {
     return height;
   } else {
     return FTAUtilities.max(height, parentContainer.getHeight());
   }
 }
예제 #3
0
    @Override
    protected void paintComponent(Graphics g) {
      JRibbonFrame ribbonFrame = (JRibbonFrame) SwingUtilities.getWindowAncestor(this);
      if (!ribbonFrame.isShowingKeyTips()) return;

      // don't show keytips on inactive windows
      if (!ribbonFrame.isActive()) return;

      Collection<KeyTipManager.KeyTipLink> keyTips =
          KeyTipManager.defaultManager().getCurrentlyShownKeyTips();
      if (keyTips != null) {
        Graphics2D g2d = (Graphics2D) g.create();
        RenderingUtils.installDesktopHints(g2d);

        for (KeyTipManager.KeyTipLink keyTip : keyTips) {
          // don't display keytips on components in popup panels
          if (SwingUtilities.getAncestorOfClass(JPopupPanel.class, keyTip.comp) != null) continue;

          // don't display key tips on hidden components
          Rectangle compBounds = keyTip.comp.getBounds();
          if (!keyTip.comp.isShowing()
              || (compBounds.getWidth() == 0)
              || (compBounds.getHeight() == 0)) continue;

          Dimension pref =
              KeyTipRenderingUtilities.getPrefSize(g2d.getFontMetrics(), keyTip.keyTipString);

          Point prefCenter = keyTip.prefAnchorPoint;
          Point loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, this);
          Container bandControlPanel =
              SwingUtilities.getAncestorOfClass(AbstractBandControlPanel.class, keyTip.comp);
          if (bandControlPanel != null) {
            // special case for controls in threesome
            // ribbon band rows
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.TOP_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = 0;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = 0;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.MID_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight() / 2;
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight() / 2;
            }
            if (hasClientPropertySetToTrue(keyTip.comp, BasicBandControlPanelUI.BOTTOM_ROW)) {
              loc = SwingUtilities.convertPoint(keyTip.comp, prefCenter, bandControlPanel);
              loc.y = bandControlPanel.getHeight();
              loc = SwingUtilities.convertPoint(bandControlPanel, loc, this);
              // prefCenter.y = keyTip.comp.getHeight();
            }
          }

          KeyTipRenderingUtilities.renderKeyTip(
              g2d,
              this,
              new Rectangle(
                  loc.x - pref.width / 2, loc.y - pref.height / 2, pref.width, pref.height),
              keyTip.keyTipString,
              keyTip.enabled);
        }

        g2d.dispose();
      }
    }
예제 #4
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;
        }
      }
    }
  }