Example #1
0
 protected void paintBackground(Graphics g, JComponent c, int x, int y, int w, int h) {
   JMenuItem b = (JMenuItem) c;
   ButtonModel model = b.getModel();
   if (c.getParent() instanceof JMenuBar) {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   } else {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     } else if (!AbstractLookAndFeel.getTheme().isMenuOpaque()) {
       Graphics2D g2D = (Graphics2D) g;
       Composite composite = g2D.getComposite();
       AlphaComposite alpha =
           AlphaComposite.getInstance(
               AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
       g2D.setComposite(alpha);
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
       g2D.setComposite(composite);
     } else {
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   }
   if (menuItem.isSelected() && menuItem.isArmed()) {
     g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
   } else {
     g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
   }
 }
Example #2
0
  /**
   * Overrides the <code>paintComponent</code> method of <tt>JButton</tt> to paint the button
   * background and icon, and all additional effects of this configurable button.
   *
   * @param g The Graphics object.
   */
  @Override
  protected void paintComponent(Graphics g) {
    Graphics2D g1 = (Graphics2D) g.create();
    try {
      internalPaintComponent(g1);
    } finally {
      g1.dispose();
    }

    super.paintComponent(g);
  }
  private void internalPaintTabBackground(
      Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) {
    BufferedImage leftImg = null;
    BufferedImage middleImg = null;
    BufferedImage rightImg = null;

    Graphics2D g2 = (Graphics2D) g;

    AntialiasingManager.activateAntialiasing(g2);

    int tabOverlap = 0;

    if (isSelected) {
      if (tabPane.isEnabledAt(tabIndex)) {
        leftImg = DesktopUtilActivator.getImage(SELECTED_TAB_LEFT_BG);
        middleImg = DesktopUtilActivator.getImage(SELECTED_TAB_MIDDLE_BG);
        rightImg = DesktopUtilActivator.getImage(SELECTED_TAB_RIGHT_BG);

        tabOverlap = TAB_OVERLAP;
      } else {
        leftImg = DesktopUtilActivator.getImage(TAB_LEFT_BG);
        middleImg = DesktopUtilActivator.getImage(TAB_MIDDLE_BG);
        rightImg = DesktopUtilActivator.getImage(TAB_RIGHT_BG);
      }
    } else {
      leftImg = DesktopUtilActivator.getImage(TAB_LEFT_BG);
      middleImg = DesktopUtilActivator.getImage(TAB_MIDDLE_BG);
      rightImg = DesktopUtilActivator.getImage(TAB_RIGHT_BG);
    }

    // Remove the existing gap between the tabs and the panel, which is due
    // to the removal of the tabbed pane border.
    y++;
    // If the current tab is not the selected tab we paint it 2 more pixels
    // to the bottom in order to create the disabled look.
    if (!isSelected) y += 2;

    g2.drawImage(leftImg, x, y, null);
    g2.drawImage(
        middleImg,
        x + leftImg.getWidth(),
        y,
        w - leftImg.getWidth() - rightImg.getWidth() + tabOverlap,
        leftImg.getHeight(),
        null);
    g2.drawImage(rightImg, x + w - rightImg.getWidth() + tabOverlap, y, null);
  }
Example #4
0
 protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
   Graphics2D g2D = (Graphics2D) g;
   Object savedRenderingHint = null;
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     savedRenderingHint = g2D.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
     g2D.setRenderingHint(
         RenderingHints.KEY_TEXT_ANTIALIASING,
         AbstractLookAndFeel.getTheme().getTextAntiAliasingHint());
   }
   if (menuItem.isSelected() && menuItem.isArmed()) {
     g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
   } else {
     g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
   }
   super.paintText(g, menuItem, textRect, text);
   if (AbstractLookAndFeel.getTheme().isTextAntiAliasingOn()) {
     g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, savedRenderingHint);
   }
 }
Example #5
0
  private static int[] makeGradientPallet() {
    BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    Point2D start = new Point2D.Float(0f, 0f);
    Point2D end = new Point2D.Float(99f, 0f);
    float[] dist = {0f, .5f, 1f};
    Color[] colors = {Color.RED, Color.YELLOW, Color.GREEN};
    g2.setPaint(new LinearGradientPaint(start, end, dist, colors));
    g2.fillRect(0, 0, 100, 1);
    g2.dispose();

    int width = image.getWidth(null);
    int[] pallet = new int[width];
    PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width);
    try {
      pg.grabPixels();
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
    return pallet;
  }
Example #6
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);
    }
  }