Пример #1
0
  /**
   * Paints this button.
   *
   * @param g the <tt>Graphics</tt> object used for painting
   */
  private void internalPaintComponent(Graphics2D g) {
    AntialiasingManager.activateAntialiasing(g);

    // Paint a roll over fade out.
    FadeTracker fadeTracker = FadeTracker.getInstance();

    float visibility = this.getModel().isRollover() ? 1.0f : 0.0f;
    if (fadeTracker.isTracked(this, FadeKind.ROLLOVER)) {
      visibility = fadeTracker.getFade(this, FadeKind.ROLLOVER);
    }

    visibility /= 2;

    if (visibility != 0.0f) {
      g.setColor(new Color(borderColor[0], borderColor[1], borderColor[2], visibility));

      if (bgImage != null)
        g.fillRoundRect(
            (this.getWidth() - bgImage.getWidth(null)) / 2,
            (this.getHeight() - bgImage.getHeight(null)) / 2,
            bgImage.getWidth(null) - 1,
            bgImage.getHeight(null) - 1,
            20,
            20);
      else g.fillRoundRect(0, 0, this.getWidth() - 1, this.getHeight() - 1, 20, 20);
    }

    if (bgImage != null) {
      g.drawImage(
          bgImage,
          (this.getWidth() - bgImage.getWidth(null)) / 2,
          (this.getHeight() - bgImage.getHeight(null)) / 2,
          null);
    } else {
      g.setColor(getBackground());
      g.fillRoundRect(1, 1, this.getWidth() - 2, this.getHeight() - 2, 20, 20);
    }
  }
    @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);
    }