Beispiel #1
0
    /**
     * Returns the minimum amount of space the layout needs.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's minimum size
     */
    public Dimension minimumLayoutSize(Container parent) {
      Dimension cpd;
      int cpWidth = 0;
      int cpHeight = 0;
      int mbWidth = 0;
      int mbHeight = 0;
      int tpWidth = 0;

      Insets i = parent.getInsets();
      JRootPane root = (JRootPane) parent;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getMinimumSize();
      } else {
        cpd = root.getSize();
      }
      if (cpd != null) {
        cpWidth = cpd.width;
        cpHeight = cpd.height;
      }

      return new Dimension(
          Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
          cpHeight + mbHeight + tpWidth + i.top + i.bottom);
    }
 @Override
 public Dimension getMinimumSize(JComponent c) {
   AbstractButton b = (AbstractButton) c;
   String style = (String) c.getClientProperty("Quaqua.Button.style");
   if (style == null) {
     style = "push";
   }
   if (style.equals("help")) {
     return getPreferredSize(c);
   }
   Dimension d = super.getMinimumSize(c);
   if (isFixedHeight(c)) {
     Dimension p = getPreferredSize(c);
     if (d != null && p != null) {
       d.height = Math.max(d.height, p.height);
     }
   }
   if (!QuaquaUtilities.isSmallSizeVariant(c)
       && style.equals("push") //
       && b.getIcon() == null
       && b.getText() != null) {
     if (d != null) {
       d.width = Math.max(d.width, UIManager.getInt("Button.minimumWidth"));
     }
   }
   return d;
 }
Beispiel #3
0
    /**
     * Returns the amount of space the layout would like to have.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's preferred size
     */
    public Dimension preferredLayoutSize(Container parent) {
      Dimension cpd, tpd;
      int cpWidth = 0;
      int cpHeight = 0;
      int mbWidth = 0;
      int mbHeight = 0;
      int tpWidth = 0;
      Insets i = parent.getInsets();
      JRootPane root = (JRootPane) parent;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getPreferredSize();
      } else {
        cpd = root.getSize();
      }
      if (cpd != null) {
        cpWidth = cpd.width;
        cpHeight = cpd.height;
      }

      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof RootPaneUI)) {
        JComponent titlePane = ((RootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          tpd = titlePane.getPreferredSize();
          if (tpd != null) {
            tpWidth = tpd.width;
          }
        }
      }

      return new Dimension(
          Math.max(Math.max(cpWidth, mbWidth), tpWidth) + i.left + i.right,
          cpHeight + mbHeight + tpWidth + i.top + i.bottom);
    }
Beispiel #4
0
 public int filterRGB(int x, int y, int rgb) {
   int r = ((rgb >> 16) & 0xff);
   int g = ((rgb >> 8) & 0xff);
   int b = (rgb & 0xff);
   int gray = Math.max(Math.max(r, g), b);
   return (rgb & 0xff000000) | (gray << 16) | (gray << 8) | (gray << 0);
 }
Beispiel #5
0
    /**
     * Returns the maximum amount of space the layout can use.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's maximum size
     */
    public Dimension maximumLayoutSize(Container target) {
      Dimension cpd;
      int cpWidth = Integer.MAX_VALUE;
      int cpHeight = Integer.MAX_VALUE;
      int mbWidth = Integer.MAX_VALUE;
      int mbHeight = Integer.MAX_VALUE;
      int tpWidth = Integer.MAX_VALUE;
      int tpHeight = Integer.MAX_VALUE;
      Insets i = target.getInsets();
      JRootPane root = (JRootPane) target;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getMaximumSize();
        if (cpd != null) {
          cpWidth = cpd.width;
          cpHeight = cpd.height;
        }
      }

      int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
      // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
      // Only will happen if sums to more than 2 billion units.  Not likely.
      if (maxHeight != Integer.MAX_VALUE) {
        maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
      }

      int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
      // Similar overflow comment as above
      if (maxWidth != Integer.MAX_VALUE) {
        maxWidth += i.left + i.right;
      }

      return new Dimension(maxWidth, maxHeight);
    }
  /** Removes all highlights. */
  public void removeAllHighlights() {
    TextUI mapper = component.getUI();
    if (getDrawsLayeredHighlights()) {
      int len = highlights.size();
      if (len != 0) {
        int minX = 0;
        int minY = 0;
        int maxX = 0;
        int maxY = 0;
        int p0 = -1;
        int p1 = -1;
        for (int i = 0; i < len; i++) {
          HighlightInfo hi = highlights.elementAt(i);
          if (hi instanceof LayeredHighlightInfo) {
            LayeredHighlightInfo info = (LayeredHighlightInfo) hi;
            minX = Math.min(minX, info.x);
            minY = Math.min(minY, info.y);
            maxX = Math.max(maxX, info.x + info.width);
            maxY = Math.max(maxY, info.y + info.height);
          } else {
            if (p0 == -1) {
              p0 = hi.p0.getOffset();
              p1 = hi.p1.getOffset();
            } else {
              p0 = Math.min(p0, hi.p0.getOffset());
              p1 = Math.max(p1, hi.p1.getOffset());
            }
          }
        }
        if (minX != maxX && minY != maxY) {
          component.repaint(minX, minY, maxX - minX, maxY - minY);
        }
        if (p0 != -1) {
          try {
            safeDamageRange(p0, p1);
          } catch (BadLocationException e) {
          }
        }
        highlights.removeAllElements();
      }
    } else if (mapper != null) {
      int len = highlights.size();
      if (len != 0) {
        int p0 = Integer.MAX_VALUE;
        int p1 = 0;
        for (int i = 0; i < len; i++) {
          HighlightInfo info = highlights.elementAt(i);
          p0 = Math.min(p0, info.p0.getOffset());
          p1 = Math.max(p1, info.p1.getOffset());
        }
        try {
          safeDamageRange(p0, p1);
        } catch (BadLocationException e) {
        }

        highlights.removeAllElements();
      }
    }
  }
    /**
     * Returns the maximum amount of space the layout can use.
     *
     * @param the Container for which this layout manager is being used
     * @return a Dimension object containing the layout's maximum size
     */
    public Dimension maximumLayoutSize(Container target) {
      Dimension cpd, mbd, tpd;
      int cpWidth = Integer.MAX_VALUE;
      int cpHeight = Integer.MAX_VALUE;
      int mbWidth = Integer.MAX_VALUE;
      int mbHeight = Integer.MAX_VALUE;
      int tpWidth = Integer.MAX_VALUE;
      int tpHeight = Integer.MAX_VALUE;
      Insets i = target.getInsets();
      JRootPane root = (JRootPane) target;

      if (root.getContentPane() != null) {
        cpd = root.getContentPane().getMaximumSize();
        if (cpd != null) {
          cpWidth = cpd.width;
          cpHeight = cpd.height;
        }
      }

      if (root.getMenuBar() != null) {
        mbd = root.getMenuBar().getMaximumSize();
        if (mbd != null) {
          mbWidth = mbd.width;
          mbHeight = mbd.height;
        }
      }

      if (root.getWindowDecorationStyle() != JRootPane.NONE
          && (root.getUI() instanceof HokageRootPaneUI)) {
        JComponent titlePane = ((HokageRootPaneUI) root.getUI()).getTitlePane();
        if (titlePane != null) {
          tpd = titlePane.getMaximumSize();
          if (tpd != null) {
            tpWidth = tpd.width;
            tpHeight = tpd.height;
          }
        }
      }

      int maxHeight = Math.max(Math.max(cpHeight, mbHeight), tpHeight);
      // Only overflows if 3 real non-MAX_VALUE heights, sum to > MAX_VALUE
      // Only will happen if sums to more than 2 billion units.  Not likely.
      if (maxHeight != Integer.MAX_VALUE) {
        maxHeight = cpHeight + mbHeight + tpHeight + i.top + i.bottom;
      }

      int maxWidth = Math.max(Math.max(cpWidth, mbWidth), tpWidth);
      // Similar overflow comment as above
      if (maxWidth != Integer.MAX_VALUE) {
        maxWidth += i.left + i.right;
      }

      return new Dimension(maxWidth, maxHeight);
    }
 /*
  * Borders are handled by the UI since they are shared between cells
  * and therefore must overlay after the painting of the cells
  */
 private void paintBorders(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
   // Include borders from adjacent rows/columns of the clip region
   rowMin = Math.max(0, rowMin - 1);
   rowMax = Math.min(grid.getRowCount() - 1, rowMax + 1);
   colMin = Math.max(0, colMin - 1);
   colMax = Math.min(grid.getColumnCount() - 1, colMax + 1);
   for (int row = rowMin; row <= rowMax; row++) {
     for (int column = colMin; column <= colMax; column++) {
       Rectangle cellRect = grid.getCellBounds(row, column);
       paintBorder(g, cellRect, row, column);
     }
   }
 }
    private static boolean computeIntersection(Rectangle dest, int rx, int ry, int rw, int rh) {
      int x1 = Math.max(rx, dest.x);
      int x2 = Math.min(rx + rw, dest.x + dest.width);
      int y1 = Math.max(ry, dest.y);
      int y2 = Math.min(ry + rh, dest.y + dest.height);
      dest.x = x1;
      dest.y = y1;
      dest.width = x2 - x1;
      dest.height = y2 - y1;

      if (dest.width <= 0 || dest.height <= 0) {
        return false;
      }
      return true;
    }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#paintButtonBackground
   * (java.awt.Graphics, java.awt.Rectangle)
   */
  @Override
  protected void paintButtonBackground(Graphics graphics, Rectangle toFill) {
    if (SubstanceCoreUtilities.isButtonNeverPainted(this.commandButton)) return;

    ButtonModel actionModel = this.commandButton.getActionModel();
    PopupButtonModel popupModel = ((JCommandButton) this.commandButton).getPopupModel();
    Rectangle actionArea = this.getLayoutInfo().actionClickArea;
    Rectangle popupArea = this.getLayoutInfo().popupClickArea;

    BufferedImage fullAlphaBackground =
        CommandButtonBackgroundDelegate.getCombinedCommandButtonBackground(
            this.commandButton, actionModel, actionArea, popupModel, popupArea);

    // Two special cases here:
    // 1. Button has flat appearance and doesn't show the popup
    // 2. Button is disabled.
    // For both cases, we need to set custom translucency.
    boolean isFlat =
        this.commandButton.isFlat()
            && !((JCommandButton) this.commandButton).getPopupModel().isPopupShowing();
    boolean isSpecial = isFlat || !this.commandButton.isEnabled();
    float extraAlpha = 1.0f;
    if (isSpecial) {
      if (isFlat) {
        float extraActionAlpha = 0.0f;
        for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry :
            getActionTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) {
          ComponentState activeState = activeEntry.getKey();
          if (activeState.isDisabled()) continue;
          if (activeState == ComponentState.ENABLED) continue;
          extraActionAlpha += activeEntry.getValue().getContribution();
        }
        float extraPopupAlpha = 0.0f;
        for (Map.Entry<ComponentState, StateTransitionTracker.StateContributionInfo> activeEntry :
            getPopupTransitionTracker().getModelStateInfo().getStateContributionMap().entrySet()) {
          ComponentState activeState = activeEntry.getKey();
          if (activeState.isDisabled()) continue;
          if (activeState == ComponentState.ENABLED) continue;
          extraPopupAlpha += activeEntry.getValue().getContribution();
        }
        extraAlpha = Math.max(extraActionAlpha, extraPopupAlpha);
      } else {
        ComponentState actionAreaState = ComponentState.getState(actionModel, this.commandButton);
        if (actionAreaState.isDisabled()) {
          extraAlpha = SubstanceColorSchemeUtilities.getAlpha(this.commandButton, actionAreaState);
        }
      }
    }
    // System.out.println(extraAlpha);
    extraAlpha = Math.min(1.0f, extraAlpha);
    if (extraAlpha > 0.0f) {
      Graphics2D g2d = (Graphics2D) graphics.create();
      g2d.setComposite(
          LafWidgetUtilities.getAlphaComposite(this.commandButton, extraAlpha, graphics));
      g2d.drawImage(fullAlphaBackground, 0, 0, null);
      g2d.dispose();
    }
  }
 protected void setButtonsSize() {
   int nMaxWidth = 0, nMaxHeight = 0;
   Dimension objSize;
   Iterator objIterator = buttons.values().iterator();
   while (objIterator.hasNext()) {
     JButton objButton = (JButton) objIterator.next();
     objButton.setPreferredSize(null);
     objSize = objButton.getPreferredSize();
     nMaxWidth = Math.max(nMaxWidth, objSize.width);
     nMaxHeight = Math.max(nMaxHeight, objSize.height);
   }
   objSize = new Dimension(nMaxWidth, nMaxHeight);
   d = objSize;
   objIterator = buttons.values().iterator();
   while (objIterator.hasNext()) {
     ((JButton) objIterator.next()).setPreferredSize(objSize);
   }
 }
 /**
  * Restricts the region based on the receivers offsets and messages the painter to paint the
  * region.
  */
 void paintLayeredHighlights(
     Graphics g, int p0, int p1, Shape viewBounds, JTextComponent editor, View view) {
   int start = getStartOffset();
   int end = getEndOffset();
   // Restrict the region to what we represent
   p0 = Math.max(start, p0);
   p1 = Math.min(end, p1);
   // Paint the appropriate region using the painter and union
   // the effected region with our bounds.
   union(
       ((LayeredHighlighter.LayerPainter) painter)
           .paintLayer(g, p0, p1, viewBounds, editor, view));
 }
 @Override
 public Dimension getMaximumSize(JComponent c) {
   String style = (String) c.getClientProperty("Quaqua.Button.style");
   if (style != null && style.equals("help")) {
     return getPreferredSize(c);
   }
   Dimension d = super.getMaximumSize(c);
   if (isFixedHeight(c)) {
     Dimension p = getPreferredSize(c);
     d.height = Math.max(d.height, p.height);
   }
   return d;
 }
    void union(Shape bounds) {
      if (bounds == null) return;

      Rectangle alloc;
      if (bounds instanceof Rectangle) {
        alloc = (Rectangle) bounds;
      } else {
        alloc = bounds.getBounds();
      }
      if (width == 0 || height == 0) {
        x = alloc.x;
        y = alloc.y;
        width = alloc.width;
        height = alloc.height;
      } else {
        width = Math.max(x + width, alloc.x + alloc.width);
        height = Math.max(y + height, alloc.y + alloc.height);
        x = Math.min(x, alloc.x);
        width -= x;
        y = Math.min(y, alloc.y);
        height -= y;
      }
    }
  /**
   * Changes a highlight.
   *
   * @param tag the highlight tag
   * @param p0 the beginning of the range &gt;= 0
   * @param p1 the end of the range &gt;= p0
   * @exception BadLocationException if the specified location is invalid
   */
  public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException {
    if (p0 < 0) {
      throw new BadLocationException("Invalid beginning of the range", p0);
    }

    if (p1 < p0) {
      throw new BadLocationException("Invalid end of the range", p1);
    }

    Document doc = component.getDocument();
    if (tag instanceof LayeredHighlightInfo) {
      LayeredHighlightInfo lhi = (LayeredHighlightInfo) tag;
      if (lhi.width > 0 && lhi.height > 0) {
        component.repaint(lhi.x, lhi.y, lhi.width, lhi.height);
      }
      // Mark the highlights region as invalid, it will reset itself
      // next time asked to paint.
      lhi.width = lhi.height = 0;
      lhi.p0 = doc.createPosition(p0);
      lhi.p1 = doc.createPosition(p1);
      safeDamageRange(Math.min(p0, p1), Math.max(p0, p1));
    } else {
      HighlightInfo info = (HighlightInfo) tag;
      int oldP0 = info.p0.getOffset();
      int oldP1 = info.p1.getOffset();
      if (p0 == oldP0) {
        safeDamageRange(Math.min(oldP1, p1), Math.max(oldP1, p1));
      } else if (p1 == oldP1) {
        safeDamageRange(Math.min(p0, oldP0), Math.max(p0, oldP0));
      } else {
        safeDamageRange(oldP0, oldP1);
        safeDamageRange(p0, p1);
      }
      info.p0 = doc.createPosition(p0);
      info.p1 = doc.createPosition(p1);
    }
  }
    /**
     * Paints a portion of a highlight.
     *
     * @param g the graphics context
     * @param offs0 the starting model offset &gt;= 0
     * @param offs1 the ending model offset &gt;= offs1
     * @param bounds the bounding box of the view, which is not necessarily the region to paint.
     * @param c the editor
     * @param view View painting for
     * @return region drawing occurred in
     */
    public Shape paintLayer(
        Graphics g, int offs0, int offs1, Shape bounds, JTextComponent c, View view) {
      Color color = getColor();

      if (color == null) {
        g.setColor(c.getSelectionColor());
      } else {
        g.setColor(color);
      }

      Rectangle r;

      if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset()) {
        // Contained in view, can just use bounds.
        if (bounds instanceof Rectangle) {
          r = (Rectangle) bounds;
        } else {
          r = bounds.getBounds();
        }
      } else {
        // Should only render part of View.
        try {
          // --- determine locations ---
          Shape shape =
              view.modelToView(offs0, Position.Bias.Forward, offs1, Position.Bias.Backward, bounds);
          r = (shape instanceof Rectangle) ? (Rectangle) shape : shape.getBounds();
        } catch (BadLocationException e) {
          // can't render
          r = null;
        }
      }

      if (r != null) {
        // If we are asked to highlight, we should draw something even
        // if the model-to-view projection is of zero width (6340106).
        r.width = Math.max(r.width, 1);

        g.fillRect(r.x, r.y, r.width, r.height);
      }

      return r;
    }
    /**
     * Paints the border for the specified component with the specified position and size.
     *
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

      Border border = getBorder();

      if (label == null) {
        if (border != null) {
          border.paintBorder(c, g, x, y, width, height);
        }
        return;
      }

      Rectangle grooveRect =
          new Rectangle(
              x + EDGE_SPACING,
              y + EDGE_SPACING,
              width - (EDGE_SPACING * 2),
              height - (EDGE_SPACING * 2));

      Dimension labelDim = label.getPreferredSize();
      int baseline = label.getBaseline(labelDim.width, labelDim.height);
      int ascent = Math.max(0, baseline);
      int descent = labelDim.height - ascent;
      int diff;
      Insets insets;

      if (border != null) {
        insets = border.getBorderInsets(c);
      } else {
        insets = new Insets(0, 0, 0, 0);
      }

      diff = Math.max(0, ascent / 2 + TEXT_SPACING - EDGE_SPACING);
      grooveRect.y += diff;
      grooveRect.height -= diff;
      compLoc.y = grooveRect.y + insets.top / 2 - (ascent + descent) / 2 - 1;

      int justification;
      if (c.getComponentOrientation().isLeftToRight()) {
        justification = LEFT;
      } else {
        justification = RIGHT;
      }

      switch (justification) {
        case LEFT:
          compLoc.x = grooveRect.x + TEXT_INSET_H + insets.left;
          break;
        case RIGHT:
          compLoc.x =
              (grooveRect.x + grooveRect.width - (labelDim.width + TEXT_INSET_H + insets.right));
          break;
      }

      // If title is positioned in middle of border AND its fontsize
      // is greater than the border's thickness, we'll need to paint
      // the border in sections to leave space for the component's background
      // to show through the title.
      //
      if (border != null) {
        if (grooveRect.y > compLoc.y - ascent) {
          Rectangle clipRect = new Rectangle();

          // save original clip
          Rectangle saveClip = g.getClipBounds();

          // paint strip left of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(clipRect, x, y, compLoc.x - 1 - x, height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip right of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x + labelDim.width + 1,
              y,
              x + width - (compLoc.x + labelDim.width + 1),
              height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip below text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x - 1,
              compLoc.y + ascent + descent,
              labelDim.width + 2,
              y + height - compLoc.y - ascent - descent)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // restore clip
          g.setClip(saveClip);

        } else {
          border.paintBorder(c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
        }

        label.setLocation(compLoc);
        label.setSize(labelDim);
      }
    }
 private int clipToRange(int i, int a, int b) {
   return Math.min(Math.max(i, a), b - 1);
 }
    @Override
    public void paint(Graphics g) {
      Color origColor;
      boolean isPressed, isRollOver, isEnabled;
      int w, h, size;

      w = getWidth();
      h = getHeight();
      origColor = g.getColor();
      isPressed = getModel().isPressed();
      isRollOver = getModel().isRollover();
      isEnabled = isEnabled();

      g.setColor(getBackground());
      g.fillRect(0, 0, w, h);

      g.setColor(shadow);
      // Using the background color set above
      if (direction == WEST) {
        g.drawLine(0, 0, 0, h - 1); // left
        g.drawLine(w - 1, 0, w - 1, 0); // right
      } else g.drawLine(w - 2, h - 1, w - 2, 0); // right

      g.drawLine(0, 0, w - 2, 0); // top

      if (isRollOver) {
        // do highlights or shadows
        Color color1;
        Color color2;

        if (isPressed) {
          color2 = Color.WHITE;
          color1 = shadow;
        } else {
          color1 = Color.WHITE;
          color2 = shadow;
        }

        g.setColor(color1);

        if (direction == WEST) {
          g.drawLine(1, 1, 1, h - 1); // left
          g.drawLine(1, 1, w - 2, 1); // top
          g.setColor(color2);
          g.drawLine(w - 1, h - 1, w - 1, 1); // right
        } else {
          g.drawLine(0, 1, 0, h - 1);
          g.drawLine(0, 1, w - 3, 1); // top
          g.setColor(color2);
          g.drawLine(w - 3, h - 1, w - 3, 1); // right
        }
      }

      // g.drawLine(0, h - 1, w - 1, h - 1); //bottom

      // If there's no room to draw arrow, bail
      if (h < 5 || w < 5) {
        g.setColor(origColor);
        return;
      }

      if (isPressed) {
        g.translate(1, 1);
      }

      // Draw the arrow
      size = Math.min((h - 4) / 3, (w - 4) / 3);
      size = Math.max(size, 2);

      boolean highlight = false;

      if (!highlightedTabs.isEmpty()
          && ((direction == WEST && tabScroller.scrollBackwardButton.isEnabled())
              || (direction == EAST && tabScroller.scrollForwardButton.isEnabled()))) {
        Rectangle viewRect = tabScroller.viewport.getViewRect();

        if (direction == WEST) {
          int leadingTabIndex = getClosestTab(viewRect.x, viewRect.y);

          for (int i = 0; i < leadingTabIndex; i++) {
            if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) {
              highlight = true;
              break;
            }
          }
        } else {
          int leadingTabIndex = getClosestTab(viewRect.x + viewRect.y, viewRect.y);

          for (int i = leadingTabIndex; i < tabPane.getTabCount(); i++) {
            if (highlightedTabs.contains(i) && !isScrollTabVisible(i)) {
              highlight = true;
              break;
            }
          }
        }

        if (highlight) {
          Image img =
              DesktopUtilActivator.getImage(
                  direction == WEST
                      ? "service.gui.icons.TAB_UNREAD_BACKWARD_ICON"
                      : "service.gui.icons.TAB_UNREAD_FORWARD_ICON");

          int wi = img.getWidth(null);

          g.drawImage(img, (w - wi) / 2, (h - size) / 2 - 2 /* 2 borders 1px width*/, null);
        }
      }

      if (!highlight) paintTriangle(g, (w - size) / 2, (h - size) / 2, size, direction, isEnabled);

      // Reset the Graphics back to it's original settings
      if (isPressed) {
        g.translate(-1, -1);
      }
      g.setColor(origColor);
    }
  public static Dimension getPreferredSize(AbstractButton b) {
    String style = (String) b.getClientProperty("Quaqua.Button.style");
    if (style == null) {
      style = "push";
    }
    if (style.equals("help")) {
      Icon helpIcon = UIManager.getIcon("Button.helpIcon");
      Insets insets = b.getInsets();

      return new Dimension(
          helpIcon.getIconWidth() + insets.left + insets.right,
          helpIcon.getIconHeight() + insets.top + insets.bottom);
    }
    if (b.getComponentCount() > 0) {
      return null;
    }

    int textIconGap = Methods.invokeGetter(b, "getIconTextGap", 4);
    Icon icon = (Icon) b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    viewR.x = viewR.y = 0;
    viewR.width = Short.MAX_VALUE;
    viewR.height = Short.MAX_VALUE;
    iconR.x = iconR.y = iconR.width = iconR.height = 0;
    textR.x = textR.y = textR.width = textR.height = 0;

    SwingUtilities.layoutCompoundLabel(
        (JComponent) b,
        fm,
        text,
        icon,
        b.getVerticalAlignment(),
        b.getHorizontalAlignment(),
        b.getVerticalTextPosition(),
        b.getHorizontalTextPosition(),
        viewR,
        iconR,
        textR,
        (text == null ? 0 : textIconGap));

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    // if (b.isBorderPainted()) {
    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;
    // }
    if (!QuaquaUtilities.isSmallSizeVariant(b)
        && style.equals("push")
        && b.getIcon() == null
        && b.getText() != null) {
      r.width = Math.max(r.width, UIManager.getInt("Button.minimumWidth"));
    }
    return r.getSize();
  }