Exemplo n.º 1
0
  protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Icon icon = b.getIcon();
    Icon tmpIcon = null;

    if (icon == null) {
      return;
    }

    Icon selectedIcon = null;

    /* the fallback icon should be based on the selected state */
    if (model.isSelected()) {
      selectedIcon = (Icon) b.getSelectedIcon();
      if (selectedIcon != null) {
        icon = selectedIcon;
      }
    }

    if (!model.isEnabled()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getDisabledSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getDisabledIcon();
      }
    } else if (model.isPressed() && model.isArmed()) {
      tmpIcon = (Icon) b.getPressedIcon();
      if (tmpIcon != null) {
        // revert back to 0 offset
        clearTextShiftOffset();
      }
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getRolloverSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = selectedIcon;
        }
      }

      if (tmpIcon == null) {
        tmpIcon = (Icon) b.getRolloverIcon();
      }
    }

    if (tmpIcon != null) {
      icon = tmpIcon;
    }

    if (model.isPressed() && model.isArmed()) {
      icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset());
    } else {
      icon.paintIcon(c, g, iconRect.x, iconRect.y);
    }
  }
Exemplo n.º 2
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());
   }
 }
Exemplo n.º 3
0
  public void paint(Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();

    String text = layout(b, SwingUtilities2.getFontMetrics(b, g), b.getWidth(), b.getHeight());

    clearTextShiftOffset();

    // perform UI specific press action, e.g. Windows L&F shifts text
    if (model.isArmed() && model.isPressed()) {
      paintButtonPressed(g, b);
    }

    // Paint the Icon
    if (b.getIcon() != null) {
      paintIcon(g, c, iconRect);
    }

    if (text != null && !text.equals("")) {
      View v = (View) c.getClientProperty(BasicHTML.propertyKey);
      if (v != null) {
        v.paint(g, textRect);
      } else {
        paintText(g, b, textRect, text);
      }
    }

    if (b.isFocusPainted() && b.hasFocus()) {
      // paint UI specific focus
      paintFocus(g, b, viewRect, textRect, iconRect);
    }
  }
  @Override
  protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) {
    AbstractButton b = (AbstractButton) c;
    ButtonModel model = b.getModel();
    Icon icon = b.getIcon();
    Icon tmpIcon = null;
    Icon shadowIcon = null;
    boolean borderHasPressedCue = borderHasPressedCue(b);

    if (icon == null) {
      return;
    }

    if (!model.isEnabled()) {
      if (model.isSelected()) {
        tmpIcon = (Icon) b.getDisabledSelectedIcon();
      } else {
        tmpIcon = (Icon) b.getDisabledIcon();
      }
    } else if (model.isPressed() && model.isArmed()) {
      tmpIcon = (Icon) b.getPressedIcon();
      if (tmpIcon != null) {
        // revert back to 0 offset
        clearTextShiftOffset();
      } else if (icon != null && icon instanceof ImageIcon && !borderHasPressedCue) {
        // Create an icon on the fly.
        // Note: This is only needed for borderless buttons, which
        //       have no other way to provide feedback about the pressed
        //       state.
        tmpIcon =
            new ImageIcon(HalfbrightFilter.createHalfbrightImage(((ImageIcon) icon).getImage()));
        shadowIcon = new ImageIcon(ShadowFilter.createShadowImage(((ImageIcon) icon).getImage()));
      }
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      if (model.isSelected()) {
        tmpIcon = b.getRolloverSelectedIcon();
        if (tmpIcon == null) {
          tmpIcon = b.getSelectedIcon();
        }
      } else {
        tmpIcon = (Icon) b.getRolloverIcon();
      }
    } else if (model.isSelected()) {
      tmpIcon = b.getSelectedIcon();
    }

    if (tmpIcon != null) {
      icon = tmpIcon;
    }

    if (model.isPressed() && model.isArmed()) {
      if (shadowIcon != null) {
        shadowIcon.paintIcon(
            c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset() + 1);
      }
      icon.paintIcon(c, g, iconRect.x + getTextShiftOffset(), iconRect.y + getTextShiftOffset());
    } else {
      icon.paintIcon(c, g, iconRect.x, iconRect.y);
    }
  }
Exemplo n.º 5
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   JMenuItem b = (JMenuItem) c;
   ButtonModel model = b.getModel();
   Color borderColorLo = AbstractLookAndFeel.getFrameColor();
   Color borderColorHi =
       ColorHelper.brighter(AbstractLookAndFeel.getMenuSelectionBackgroundColor(), 40);
   if (c.getParent() instanceof JMenuBar) {
     if (model.isArmed() || model.isSelected()) {
       g.setColor(borderColorLo);
       g.drawLine(x, y, x + w - 1, y);
       g.drawLine(x, y, x, y + h - 1);
       g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
       g.setColor(borderColorHi);
       g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
       g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
     }
   } else {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(borderColorLo);
       g.drawLine(x, y, x + w - 1, y);
       g.drawLine(x, y + h - 1, x + w - 1, y + h - 1);
       g.setColor(borderColorHi);
       g.drawLine(x, y + 1, x + w - 2, y + 1);
     }
   }
 }
Exemplo n.º 6
0
  /** Returns the current state of the passed in <code>AbstractButton</code>. */
  private int getComponentState(JComponent c) {
    int state = ENABLED;

    if (!c.isEnabled()) {
      state = DISABLED;
    }

    AbstractButton button = (AbstractButton) c;
    ButtonModel model = button.getModel();

    if (model.isPressed()) {
      if (model.isArmed()) {
        state = PRESSED;
      } else {
        state = MOUSE_OVER;
      }
    }
    if (model.isRollover()) {
      state |= MOUSE_OVER;
    }
    if (model.isSelected()) {
      state |= SELECTED;
    }
    if (c.isFocusOwner() && button.isFocusPainted()) {
      state |= FOCUSED;
    }
    if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) {
      state |= DEFAULT;
    }
    return state;
  }
  /**
   * Method which renders the text of the current button.
   *
   * <p>
   *
   * @param g Graphics context
   * @param b Current button to render
   * @param textRect Bounding rectangle to render the text.
   * @param text String to render
   * @since 1.4
   */
  @Override
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = g.getFontMetrics();
    int mnemonicIndex = Methods.invokeGetter(b, "getDisplayedMnemonicIndex", -1);
    boolean borderHasPressedCue = borderHasPressedCue(b);

    /* Draw the Text */
    if (model.isPressed() && model.isArmed() && !borderHasPressedCue) {
      g.setColor(new Color(0xa0000000, true));
      QuaquaUtilities.drawStringUnderlineCharAt(
          g,
          text,
          mnemonicIndex,
          textRect.x + getTextShiftOffset(),
          textRect.y + fm.getAscent() + getTextShiftOffset() + 1);
    }

    if (model.isEnabled()) {
      /** * paint the text normally */
      g.setColor(b.getForeground());
    } else {
      Color c = UIManager.getColor(getPropertyPrefix() + "disabledForeground");
      g.setColor((c != null) ? c : b.getForeground());
    }
    QuaquaUtilities.drawStringUnderlineCharAt(
        g,
        text,
        mnemonicIndex,
        textRect.x + getTextShiftOffset(),
        textRect.y + fm.getAscent() + getTextShiftOffset());
  }
Exemplo n.º 8
0
 public void paintIcon(Component c, Graphics g, int x, int y) {
   ButtonModel model = ((AbstractButton) c).getModel();
   if (model.isPressed() && model.isArmed()) {
     pressed.paintIcon(c, g, x, y);
   } else {
     super.paintIcon(c, g, x, y);
   }
 }
Exemplo n.º 9
0
  /** Returns the amount to shift the text/icon when painting. */
  private int getTextShiftOffset(SynthContext state) {
    AbstractButton button = (AbstractButton) state.getComponent();
    ButtonModel model = button.getModel();

    if (model.isArmed() && model.isPressed() && button.getPressedIcon() == null) {
      return state.getStyle().getInt(state, getPropertyPrefix() + "textShiftOffset", 0);
    }
    return 0;
  }
Exemplo n.º 10
0
  protected void paintText(Graphics g, AbstractButton b, Rectangle textRect, String text) {
    ButtonModel model = b.getModel();
    FontMetrics fm = JTattooUtilities.getFontMetrics(b, g, b.getFont());
    int mnemIndex;
    if (JTattooUtilities.getJavaVersion() >= 1.4) {
      mnemIndex = b.getDisplayedMnemonicIndex();
    } else {
      mnemIndex = JTattooUtilities.findDisplayedMnemonicIndex(b.getText(), model.getMnemonic());
    }
    int offs = 0;
    if (model.isArmed() && model.isPressed()) {
      offs = 1;
    }

    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
    g2D.setComposite(alpha);
    Color foreground = b.getForeground();
    Color background = b.getBackground();
    if (background instanceof ColorUIResource) {
      if (model.isPressed() && model.isArmed()) {
        foreground = AbstractLookAndFeel.getTheme().getSelectionForegroundColor();
      } else if (model.isRollover()) {
        foreground = AbstractLookAndFeel.getTheme().getRolloverForegroundColor();
      }
    }
    if (!model.isEnabled()) {
      foreground = AbstractLookAndFeel.getTheme().getDisabledForegroundColor();
    }
    if (ColorHelper.getGrayValue(foreground) > 64) {
      g2D.setColor(Color.black);
    } else {
      g2D.setColor(Color.white);
    }
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs + 1, textRect.y + offs + fm.getAscent() + 1);
    g2D.setComposite(composite);
    g2D.setColor(foreground);
    JTattooUtilities.drawStringUnderlineCharAt(
        b, g, text, mnemIndex, textRect.x + offs, textRect.y + offs + fm.getAscent());
  }
Exemplo n.º 11
0
 public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
   AbstractButton button = (AbstractButton) c;
   ButtonModel model = button.getModel();
   Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
   Color frameHiColor = ColorHelper.brighter(frameColor, 10);
   Color frameLoColor = ColorHelper.darker(frameColor, 30);
   JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h);
   if ((model.isPressed() && model.isArmed()) || model.isSelected()) {
     JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h);
   } else {
     JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h);
     JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2);
   }
 }
Exemplo n.º 12
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      if (model.isEnabled()) {
        if ((model.isPressed() && model.isArmed()) || model.isSelected()) {
          Color frameColor =
              ColorHelper.darker(AbstractLookAndFeel.getToolbarBackgroundColor(), 30);
          g.setColor(frameColor);
          g.drawRect(x, y, w - 1, h - 1);

          Graphics2D g2D = (Graphics2D) g;
          Composite composite = g2D.getComposite();
          AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f);
          g2D.setComposite(alpha);
          g.setColor(Color.black);
          g.fillRect(x + 1, y + 1, w - 2, h - 2);
          g2D.setComposite(composite);
        } else if (model.isRollover()) {
          Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
          Color frameHiColor = ColorHelper.darker(frameColor, 5);
          Color frameLoColor = ColorHelper.darker(frameColor, 20);
          JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x, y, w, h);
          frameHiColor = Color.white;
          frameLoColor = ColorHelper.brighter(frameLoColor, 60);
          JTattooUtilities.draw3DBorder(g, frameHiColor, frameLoColor, x + 1, y + 1, w - 2, h - 2);

          Graphics2D g2D = (Graphics2D) g;
          Composite composite = g2D.getComposite();
          AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
          g2D.setComposite(alpha);
          g.setColor(Color.white);
          g.fillRect(x + 2, y + 2, w - 4, h - 4);
          g2D.setComposite(composite);

          g.setColor(AbstractLookAndFeel.getFocusColor());
          g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
          g.drawLine(x + 1, y + 2, x + w - 2, y + 2);
        } else if (model.isSelected()) {
          Color frameColor = AbstractLookAndFeel.getToolbarBackgroundColor();
          Color frameHiColor = Color.white;
          Color frameLoColor = ColorHelper.darker(frameColor, 30);
          JTattooUtilities.draw3DBorder(g, frameLoColor, frameHiColor, x, y, w, h);
        }
      }
    }
Exemplo n.º 13
0
  /**
   * Returns the Icon to use for painting the button. The icon is chosen with respect to the current
   * state of the button.
   *
   * @param b button the icon is associated with
   * @return an icon
   */
  protected Icon getIcon(AbstractButton b) {
    Icon icon = b.getIcon();
    ButtonModel model = b.getModel();

    if (!model.isEnabled()) {
      icon = getSynthDisabledIcon(b, icon);
    } else if (model.isPressed() && model.isArmed()) {
      icon = getPressedIcon(b, getSelectedIcon(b, icon));
    } else if (b.isRolloverEnabled() && model.isRollover()) {
      icon = getRolloverIcon(b, getSelectedIcon(b, icon));
    } else if (model.isSelected()) {
      icon = getSelectedIcon(b, icon);
    } else {
      icon = getEnabledIcon(b, icon);
    }
    if (icon == null) {
      return getDefaultIcon(b);
    }
    return icon;
  }
Exemplo n.º 14
0
  /**
   * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla
   * en todas partes...
   */
  static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) {
    ButtonModel model = menuItem.getModel();
    Color oldColor = g.getColor();

    int menuWidth = menuItem.getWidth();
    int menuHeight = menuItem.getHeight();

    if (menuItem.isOpaque()) {
      g.setColor(menuItem.getBackground());
      g.fillRect(0, 0, menuWidth, menuHeight);
    }

    if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected())
        || model.isArmed()) {
      RoundRectangle2D.Float boton = new RoundRectangle2D.Float();
      boton.x = 1;
      boton.y = 0;
      boton.width = menuWidth - 3;
      boton.height = menuHeight - 1;
      boton.arcwidth = 8;
      boton.archeight = 8;

      GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu());

      Graphics2D g2D = (Graphics2D) g;
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

      g.setColor(bgColor);
      g2D.fill(boton);

      g.setColor(bgColor.darker());
      g2D.draw(boton);

      g2D.setPaint(grad);
      g2D.fill(boton);

      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    }

    g.setColor(oldColor);
  }
  /**
   * Paint the component.
   *
   * @param g The graphics context for painting
   * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
   */
  protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    fRenderer.paintComponent(g2, fButtonDelegate, this, 0, 0, getWidth(), getHeight(), true);

    ButtonModel model = getModel();
    boolean doOffset = model.isPressed() && model.isArmed();
    int offsetAmount = UIManager.getInt("Button.textShiftOffset");
    double degrees = Math.toRadians(-90);

    if (fRotation == LEFT) {
      int h = getHeight();
      g2.translate(0, h);
      g2.rotate(degrees);
      if (doOffset) {
        g2.translate(-offsetAmount, offsetAmount);
      }

      fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true);
      if (doOffset) {
        g2.translate(offsetAmount, -offsetAmount);
      }
      g2.rotate(-degrees);

      g2.translate(0, -h);
    } else {
      int w = getWidth();
      g2.translate(w, 0);
      g2.rotate(-degrees);
      if (doOffset) {
        g2.translate(offsetAmount, -offsetAmount);
      }
      fRenderer.paintComponent(g2, fLabelDelegate, this, 0, 0, getHeight(), getWidth(), true);
      if (doOffset) {
        g2.translate(-offsetAmount, offsetAmount);
      }
      g2.rotate(degrees);
      g2.translate(-w, 0);
    }
  }
Exemplo n.º 16
0
 /**
  * If necessary paints the background of the component, then invokes <code>paint</code>.
  *
  * @param g Graphics to paint to
  * @param c JComponent painting on
  * @throws NullPointerException if <code>g</code> or <code>c</code> is null
  * @see javax.swing.plaf.ComponentUI#update
  * @see javax.swing.plaf.ComponentUI#paint
  * @since 1.5
  */
 public void update(Graphics g, JComponent c) {
   AbstractButton button = (AbstractButton) c;
   if ((c.getBackground() instanceof UIResource)
       && button.isContentAreaFilled()
       && c.isEnabled()) {
     ButtonModel model = button.getModel();
     if (!MetalUtils.isToolBarButton(c)) {
       if (!model.isArmed()
           && !model.isPressed()
           && MetalUtils.drawGradient(
               c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
         paint(g, c);
         return;
       }
     } else if (model.isRollover()
         && MetalUtils.drawGradient(
             c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) {
       paint(g, c);
       return;
     }
   }
   super.update(g, c);
 }
Exemplo n.º 17
0
 public void paint(Graphics g, JComponent comp) {
   UIUtil.applyRenderingHints(g);
   JMenu jMenu = (JMenu) comp;
   ButtonModel buttonmodel = jMenu.getModel();
   int mnemonicIndex = jMenu.getDisplayedMnemonicIndex();
   Icon icon = getIcon();
   Icon allowedIcon = getAllowedIcon();
   Insets insets = comp.getInsets();
   resetRects();
   ourViewRect.setBounds(0, 0, jMenu.getWidth(), jMenu.getHeight());
   ourViewRect.x += insets.left;
   ourViewRect.y += insets.top;
   ourViewRect.width -= insets.right + ourViewRect.x;
   ourViewRect.height -= insets.bottom + ourViewRect.y;
   Font font = g.getFont();
   Font font1 = comp.getFont();
   g.setFont(font1);
   FontMetrics fontmetrics = g.getFontMetrics(font1);
   String s1 =
       layoutMenuItem(
           fontmetrics,
           jMenu.getText(),
           icon,
           allowedIcon,
           arrowIcon,
           jMenu.getVerticalAlignment(),
           jMenu.getHorizontalAlignment(),
           jMenu.getVerticalTextPosition(),
           jMenu.getHorizontalTextPosition(),
           ourViewRect,
           ourIconRect,
           ourTextRect,
           ourAcceleratorRect,
           ourCheckIconRect,
           ourArrowIconRect,
           jMenu.getText() != null ? defaultTextIconGap : 0,
           defaultTextIconGap);
   Color color2 = g.getColor();
   if (comp.isOpaque()) {
     g.setColor(jMenu.getBackground());
     g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight());
     if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
       if (UIUtil.isUnderAquaLookAndFeel()) {
         myAquaSelectedBackgroundPainter.paintBorder(
             comp, g, 0, 0, jMenu.getWidth(), jMenu.getHeight());
       } else {
         g.setColor(selectionBackground);
         if (allowedIcon != null) {
           g.fillRect(k, 0, jMenu.getWidth() - k, jMenu.getHeight());
         } else {
           g.fillRect(0, 0, jMenu.getWidth(), jMenu.getHeight());
           g.setColor(selectionBackground);
         }
       }
     }
     g.setColor(color2);
   }
   if (allowedIcon != null) {
     if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
       g.setColor(selectionForeground);
     } else {
       g.setColor(jMenu.getForeground());
     }
     if (useCheckAndArrow()) {
       allowedIcon.paintIcon(comp, g, ourCheckIconRect.x, ourCheckIconRect.y);
     }
     g.setColor(color2);
     if (menuItem.isArmed()) {
       drawIconBorder(g);
     }
   }
   if (icon != null) {
     if (!buttonmodel.isEnabled()) {
       icon = jMenu.getDisabledIcon();
     } else if (buttonmodel.isPressed() && buttonmodel.isArmed()) {
       icon = jMenu.getPressedIcon();
       if (icon == null) {
         icon = jMenu.getIcon();
       }
     }
     if (icon != null) {
       icon.paintIcon(comp, g, ourIconRect.x, ourIconRect.y);
     }
   }
   if (s1 != null && s1.length() > 0) {
     if (buttonmodel.isEnabled()) {
       if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
         g.setColor(selectionForeground);
       } else {
         g.setColor(jMenu.getForeground());
       }
       BasicGraphicsUtils.drawStringUnderlineCharAt(
           g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent());
     } else {
       final Object disabledForeground = UIUtil.getMenuItemDisabledForeground();
       if (disabledForeground instanceof Color) {
         g.setColor((Color) disabledForeground);
         BasicGraphicsUtils.drawStringUnderlineCharAt(
             g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent());
       } else {
         g.setColor(jMenu.getBackground().brighter());
         BasicGraphicsUtils.drawStringUnderlineCharAt(
             g, s1, mnemonicIndex, ourTextRect.x, ourTextRect.y + fontmetrics.getAscent());
         g.setColor(jMenu.getBackground().darker());
         BasicGraphicsUtils.drawStringUnderlineCharAt(
             g,
             s1,
             mnemonicIndex,
             ourTextRect.x - 1,
             (ourTextRect.y + fontmetrics.getAscent()) - 1);
       }
     }
   }
   if (arrowIcon != null) {
     if (buttonmodel.isArmed() || buttonmodel.isSelected()) {
       g.setColor(selectionForeground);
     }
     if (useCheckAndArrow()) {
       try {
         if (SystemInfo.isMac
             && myAquaInvertedArrowIcon != null
             && (buttonmodel.isArmed() || buttonmodel.isSelected())
             && UIUtil.isUnderAquaLookAndFeel()) {
           myAquaInvertedArrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y);
         } else if (SystemInfo.isMac
             && myAquaDisabledArrowIcon != null
             && !buttonmodel.isEnabled()
             && UIUtil.isUnderAquaLookAndFeel()) {
           myAquaDisabledArrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y);
         } else arrowIcon.paintIcon(comp, g, ourArrowIconRect.x, ourArrowIconRect.y);
       } catch (NullPointerException npe) {
         // GTKIconFactory$MenuArrowIcon.paintIcon since it doesn't expect to be given a null
         // instead of SynthContext
         // http://www.jetbrains.net/jira/browse/IDEADEV-22360
       }
     }
   }
   g.setColor(color2);
   g.setFont(font);
 }
Exemplo n.º 18
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      if (!JTattooUtilities.isLeftToRight(c)) {
        x += GAP;
      }
      int w = getIconWidth() - GAP;
      int h = getIconHeight();
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      Graphics2D g2D = (Graphics2D) g;
      if (button.isEnabled()) {
        if ((button.isRolloverEnabled() && model.isRollover())) {
          JTattooUtilities.fillHorGradient(
              g, AbstractLookAndFeel.getTheme().getRolloverColors(), x + 1, y + 1, w - 1, h - 1);
        } else {
          if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) {
            JTattooUtilities.fillHorGradient(
                g, AbstractLookAndFeel.getTheme().getFocusColors(), x + 1, y + 1, w - 1, h - 1);
          } else {
            JTattooUtilities.fillHorGradient(
                g, AbstractLookAndFeel.getTheme().getCheckBoxColors(), x + 1, y + 1, w - 1, h - 1);
          }
        }
      } else {
        JTattooUtilities.fillHorGradient(
            g, AbstractLookAndFeel.getTheme().getDisabledColors(), x + 1, y + 1, w - 1, h - 1);
      }

      Color frameColor =
          ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6);
      Color loFrameColor =
          ColorHelper.darker(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 50);

      g.setColor(frameColor);
      g.drawRect(x, y, w, h);
      Composite savedComposite = g2D.getComposite();
      AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f);
      g2D.setComposite(alpha);
      g.setColor(loFrameColor);
      g.drawLine(x + 1, y + 1, x + w - 1, y + 1);
      g.drawLine(x + 1, y + 1, x + 1, y + h - 1);
      g2D.setComposite(savedComposite);

      Icon checkIcon;
      Icon checkDisabledIcon;
      Icon checkInverseIcon;
      if (AbstractLookAndFeel.getTheme().isSmallFontSize()) {
        checkIcon = SMALL_CHECK_ICON;
        checkDisabledIcon = SMALL_CHECK_DISABLED_ICON;
        checkInverseIcon = SMALL_CHECK_INVERSE_ICON;
      } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) {
        checkIcon = MEDIUM_CHECK_ICON;
        checkDisabledIcon = MEDIUM_CHECK_DISABLED_ICON;
        checkInverseIcon = MEDIUM_CHECK_INVERSE_ICON;
      } else {
        checkIcon = LARGE_CHECK_ICON;
        checkDisabledIcon = LARGE_CHECK_DISABLED_ICON;
        checkInverseIcon = LARGE_CHECK_INVERSE_ICON;
      }
      int xi = x + ((w - checkIcon.getIconWidth()) / 2) + 1;
      int yi = y + ((h - checkIcon.getIconHeight()) / 2);
      int gv = ColorHelper.getGrayValue(AbstractLookAndFeel.getButtonForegroundColor());
      if (model.isPressed() && model.isArmed()) {
        Color bc =
            gv > 128
                ? AbstractLookAndFeel.getTheme().getSelectionForegroundColor()
                : AbstractLookAndFeel.getTheme().getSelectionBackgroundColor();
        Color fc = gv > 128 ? ColorHelper.brighter(bc, 20) : ColorHelper.darker(bc, 40);
        g.setColor(fc);
        g.drawRect(x + 4, y + 4, w - 8, h - 8);
        g.setColor(bc);
        g.fillRect(x + 5, y + 5, w - 9, h - 9);
      } else if (model.isSelected()) {
        if (!model.isEnabled()) {
          checkDisabledIcon.paintIcon(c, g, xi + 1, yi);
        } else {
          if (gv > 128) {
            checkIcon.paintIcon(c, g, xi, yi);
          } else {
            checkInverseIcon.paintIcon(c, g, xi + 1, yi + 1);
          }
        }
      }
    }
Exemplo n.º 19
0
  protected void paintBackground(Graphics g, AbstractButton b) {
    if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) {
      return;
    }

    if (!(b.isBorderPainted() && (b.getBorder() instanceof UIResource))) {
      super.paintBackground(g, b);
      return;
    }

    int width = b.getWidth();
    int height = b.getHeight();
    ButtonModel model = b.getModel();
    Graphics2D g2D = (Graphics2D) g;
    Composite composite = g2D.getComposite();
    Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    if (((width < 64) || (height < 16)) && ((b.getText() == null) || b.getText().length() == 0)) {
      if (model.isSelected()) {
        Color color = ColorHelper.darker(b.getBackground(), 20);
        g2D.setColor(color);
        g2D.fillRect(0, 0, width - 1, height - 1);
        if (model.isEnabled()) {
          g2D.setColor(AbstractLookAndFeel.getFrameColor());
        } else {
          g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
        }
        g2D.drawRect(0, 0, width - 1, height - 1);
      } else {
        Color[] colors = null;
        if (b.getBackground() instanceof ColorUIResource) {
          if (!model.isEnabled()) {
            colors = AbstractLookAndFeel.getTheme().getDisabledColors();
          } else if (b.isRolloverEnabled() && model.isRollover()) {
            colors = AbstractLookAndFeel.getTheme().getRolloverColors();
          } else {
            colors = AbstractLookAndFeel.getTheme().getButtonColors();
          }
        } else {
          colors =
              ColorHelper.createColorArr(
                  ColorHelper.brighter(b.getBackground(), 20),
                  ColorHelper.darker(b.getBackground(), 20),
                  20);
        }
        JTattooUtilities.fillHorGradient(g, colors, 0, 0, width - 1, height - 1);
        if (model.isEnabled()) {
          g2D.setColor(AbstractLookAndFeel.getFrameColor());
        } else {
          g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
        }
        g2D.drawRect(0, 0, width - 1, height - 1);
        AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
        g2D.setComposite(alpha);
        g2D.setColor(Color.white);
        g2D.drawRect(1, 1, width - 3, height - 3);
      }
    } else if (model.isPressed() && model.isArmed()) {
      int d = height - 2;
      Color color = AbstractLookAndFeel.getTheme().getSelectionBackgroundColor();
      g2D.setColor(color);
      g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d);

      g2D.setColor(ColorHelper.darker(color, 40));
      g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d);
    } else if (model.isSelected()) {
      int d = height - 2;
      Color color = ColorHelper.darker(b.getBackground(), 20);
      g2D.setColor(color);
      g2D.fillRoundRect(0, 0, width - 1, height - 1, d, d);

      if (model.isEnabled()) {
        g2D.setColor(AbstractLookAndFeel.getFrameColor());
      } else {
        g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
      }
      g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d);
    } else {
      int d = height - 2;

      Color[] colors = null;
      if (b.getBackground() instanceof ColorUIResource) {
        if (!model.isEnabled()) {
          colors = AbstractLookAndFeel.getTheme().getDisabledColors();
        } else if (b.isRolloverEnabled() && model.isRollover()) {
          colors = AbstractLookAndFeel.getTheme().getRolloverColors();
        } else {
          colors = AbstractLookAndFeel.getTheme().getButtonColors();
        }
      } else {
        colors =
            ColorHelper.createColorArr(
                ColorHelper.brighter(b.getBackground(), 20),
                ColorHelper.darker(b.getBackground(), 20),
                20);
      }

      Shape savedClip = g.getClip();
      Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, d, d));
      clipArea.intersect(new Area(savedClip));
      g2D.setClip(clipArea);
      JTattooUtilities.fillHorGradient(g, colors, 0, 0, width, height);
      g2D.setClip(savedClip);

      if (model.isEnabled()) {
        g2D.setColor(AbstractLookAndFeel.getFrameColor());
      } else {
        g2D.setColor(ColorHelper.brighter(AbstractLookAndFeel.getFrameColor(), 20));
      }
      g2D.drawRoundRect(0, 0, width - 1, height - 1, d, d);

      AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
      g2D.setComposite(alpha);
      g2D.setColor(Color.white);
      g2D.drawRoundRect(1, 1, width - 3, height - 3, d - 2, d - 2);
    }
    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
    g2D.setComposite(composite);
  }
Exemplo n.º 20
0
    public void paintIcon(Component c, Graphics g, int x, int y) {
      if (!JTattooUtilities.isLeftToRight(c)) {
        x += GAP;
      }
      int w = getIconWidth() - GAP;
      int h = getIconHeight();

      Graphics2D g2D = (Graphics2D) g;
      AbstractButton button = (AbstractButton) c;
      ButtonModel model = button.getModel();
      Color colors[];
      if (button.isEnabled()) {
        if ((button.isRolloverEnabled() && model.isRollover())
            || (model.isPressed() && model.isArmed())) {
          colors = AbstractLookAndFeel.getTheme().getRolloverColors();
        } else {
          if (AbstractLookAndFeel.getTheme().doShowFocusFrame() && button.hasFocus()) {
            colors = AbstractLookAndFeel.getTheme().getFocusColors();
          } else {
            colors = AbstractLookAndFeel.getTheme().getCheckBoxColors();
          }
        }
      } else {
        colors = AbstractLookAndFeel.getTheme().getDisabledColors();
      }

      Color frameColor =
          ColorHelper.brighter(AbstractLookAndFeel.getTheme().getButtonBackgroundColor(), 6);
      Shape savedClip = g.getClip();
      Area clipArea = new Area(new Ellipse2D.Double(x, y, w + 1, h + 1));
      if (savedClip != null) {
        clipArea.intersect(new Area(savedClip));
      }
      g2D.setClip(clipArea);
      JTattooUtilities.fillHorGradient(g, colors, x, y, w, h);
      g2D.setClip(savedClip);

      Object savedRederingHint = g2D.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setColor(frameColor);
      g.drawOval(x, y, w, h);

      if (model.isSelected()) {
        if (model.isEnabled()) {
          Color fc = AbstractLookAndFeel.getForegroundColor();
          if (ColorHelper.getGrayValue(colors[0]) < 128) {
            if (ColorHelper.getGrayValue(fc) < 128) {
              g2D.setColor(Color.white);
            } else {
              g2D.setColor(fc);
            }
          } else {
            if (ColorHelper.getGrayValue(fc) > 128) {
              g2D.setColor(Color.black);
            } else {
              g2D.setColor(fc);
            }
          }
        } else {
          g.setColor(AbstractLookAndFeel.getDisabledForegroundColor());
        }
        if (AbstractLookAndFeel.getTheme().isSmallFontSize()) {
          g2D.fillOval(x + 4, y + 4, w - 7, h - 7);
        } else if (AbstractLookAndFeel.getTheme().isMediumFontSize()) {
          g2D.fillOval(x + 4, y + 4, w - 7, h - 7);
        } else {
          g2D.fillOval(x + 5, y + 5, w - 9, h - 9);
        }
      }
      g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, savedRederingHint);
    }
Exemplo n.º 21
0
  public void paint(final Graphics g, final JComponent c) {
    final AnchoredButton button = (AnchoredButton) c;

    final String text = button.getText();
    final Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    final FontMetrics fm = button.getFontMetrics(button.getFont());
    ourViewInsets = c.getInsets(ourViewInsets);

    ourViewRect.x = ourViewInsets.left;
    ourViewRect.y = ourViewInsets.top;

    final ToolWindowAnchor anchor = button.getAnchor();

    // Use inverted height & width
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      ourViewRect.height = c.getWidth() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getHeight() - (ourViewInsets.top + ourViewInsets.bottom);
    } else {
      ourViewRect.height = c.getHeight() - (ourViewInsets.left + ourViewInsets.right);
      ourViewRect.width = c.getWidth() - (ourViewInsets.top + ourViewInsets.bottom);
    }

    ourIconRect.x = ourIconRect.y = ourIconRect.width = ourIconRect.height = 0;
    ourTextRect.x = ourTextRect.y = ourTextRect.width = ourTextRect.height = 0;

    final String clippedText =
        SwingUtilities.layoutCompoundLabel(
            c,
            fm,
            text,
            icon,
            button.getVerticalAlignment(),
            button.getHorizontalAlignment(),
            button.getVerticalTextPosition(),
            button.getHorizontalTextPosition(),
            ourViewRect,
            ourIconRect,
            ourTextRect,
            button.getText() == null ? 0 : button.getIconTextGap());

    // Paint button's background

    final Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    final ButtonModel model = button.getModel();

    final Color background = button.getBackground();

    Color toBorder = model.isRollover() ? new Color(0, 0, 0, 50) : null;
    final boolean vertical = anchor == ToolWindowAnchor.LEFT || anchor == ToolWindowAnchor.RIGHT;

    if (model.isArmed() && model.isPressed() || model.isSelected()) {
      g2.setColor(new Color(0, 0, 0, 30));
      g2.fillRect(3, 3, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);

      g2.setColor(new Color(0, 0, 0, 120));
      g2.drawLine(2, 2, 3 + button.getWidth() - (vertical ? 7 : 6), 2);
      g2.drawLine(2, 3, 2, 3 + button.getHeight() - 7);

      g2.setColor(new Color(0, 0, 0, 40));
      g2.drawRect(3, 3, button.getWidth() - (vertical ? 7 : 6), button.getHeight() - 7);

      g2.setColor(new Color(255, 255, 255, 110));
      g2.drawLine(
          3,
          button.getHeight() - 3,
          3 + button.getWidth() - (vertical ? 6 : 5),
          button.getHeight() - 3);
      g2.drawLine(
          3 + button.getWidth() - (vertical ? 6 : 5),
          2,
          3 + button.getWidth() - (vertical ? 6 : 5),
          3 + button.getHeight() - 7);

      toBorder = null;
    }

    if (toBorder != null) {
      g.setColor(toBorder);
      g.drawRect(2, 2, button.getWidth() - (vertical ? 6 : 5), button.getHeight() - 6);
    }

    AffineTransform tr = null;
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      tr = g2.getTransform();
      if (ToolWindowAnchor.RIGHT == anchor) {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(c, g2, ourIconRect.y, ourIconRect.x);
        }
        g2.rotate(Math.PI / 2);
        g2.translate(0, -c.getWidth());
      } else {
        if (icon != null) { // do not rotate icon
          icon.paintIcon(
              c, g2, ourIconRect.y, c.getHeight() - ourIconRect.x - icon.getIconHeight());
        }
        g2.rotate(-Math.PI / 2);
        g2.translate(-c.getHeight(), 0);
      }
    } else {
      if (icon != null) {
        icon.paintIcon(c, g2, ourIconRect.x, ourIconRect.y);
      }
    }

    // paint text

    if (text != null) {
      if (model.isEnabled()) {
        if (model.isArmed() && model.isPressed() || model.isSelected()) {
          g.setColor(background);
        } else {
          g.setColor(button.getForeground());
        }
      } else {
        g.setColor(background.darker());
      }
      /* Draw the Text */
      if (model.isEnabled()) {
        /** * paint the text normally */
        g.setColor(button.getForeground());
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      } else {
        /** * paint the text disabled ** */
        if (model.isSelected()) {
          g.setColor(c.getBackground());
        } else {
          g.setColor(getDisabledTextColor());
        }
        BasicGraphicsUtils.drawString(
            g, clippedText, button.getMnemonic2(), ourTextRect.x, ourTextRect.y + fm.getAscent());
      }
    }
    if (ToolWindowAnchor.RIGHT == anchor || ToolWindowAnchor.LEFT == anchor) {
      g2.setTransform(tr);
    }
  }