Ejemplo n.º 1
0
 public void itemStateChanged(ItemEvent e) {
   AbstractButton button = (AbstractButton) e.getSource();
   DitherPanel parent = (DitherPanel) button.getParent();
   if (e.getStateChange() == ItemEvent.SELECTED) {
     button.setIcon((Icon) button.getClientProperty(SELECTED));
     parent.setDithering(true);
     parent.setBackground(ThemeFileHandler.FILTER_TITLE_COLOR.getValue());
   } else {
     button.setIcon((Icon) button.getClientProperty(DESELECTED));
     parent.setDithering(false);
     parent.setBackground(UIManager.getColor("TabbedPane.background"));
   }
 }
Ejemplo n.º 2
0
 protected void paintBackground(Graphics g, AbstractButton b) {
   if (!b.isContentAreaFilled() || (b.getParent() instanceof JMenuBar)) {
     return;
   }
   int width = b.getWidth();
   int height = b.getHeight();
   Graphics2D g2D = (Graphics2D) g;
   Shape savedClip = g.getClip();
   if ((b.getBorder() != null) && b.isBorderPainted() && (b.getBorder() instanceof UIResource)) {
     Area clipArea = new Area(new Rectangle2D.Double(1, 1, width - 2, height - 2));
     if (savedClip != null) {
       clipArea.intersect(new Area(savedClip));
     }
     g2D.setClip(clipArea);
   }
   super.paintBackground(g, b);
   g2D.setClip(savedClip);
 }
Ejemplo n.º 3
0
  /**
   * Paint xp button background.
   *
   * @param nomalColor the nomal color
   * @param g the g
   * @param c the c
   */
  public static void paintXPButtonBackground(NormalColor nomalColor, Graphics g, JComponent c) {
    AbstractButton b = (AbstractButton) c;

    //		BEXPStyle xp = BEXPStyle.getXP();

    boolean toolbar = (b.getParent() instanceof JToolBar);
    //		Part part = getXPButtonType(b);

    if (b.isContentAreaFilled()) // && xp != null)
    {
      ButtonModel model = b.getModel();
      //			Skin skin = xp.getSkin(b, part);

      // normal, rollover/activated/focus, pressed, disabled, default
      //			State state = State.NORMAL;
      if (toolbar) {
        //				if (model.isArmed() && model.isPressed())
        //				{
        //					state = State.PRESSED;
        //				}
        //				else if (!model.isEnabled())
        //				{
        //					state = State.DISABLED;
        //				}
        //				else if (model.isSelected() && model.isRollover())
        //				{
        //					state = State.HOTCHECKED;
        //				}
        //				else if (model.isSelected())
        //				{
        //					state = State.CHECKED;
        //				}
        //				else if (model.isRollover())
        //				{
        //					state = State.HOT;
        //				}
      } else {
        //				if (model.isArmed() && model.isPressed() || model.isSelected())
        //				{
        //					state = State.PRESSED;
        //				}
        //				else if (!model.isEnabled())
        //				{
        //					state = State.DISABLED;
        //				}
        //				else if (model.isRollover() || model.isPressed())
        //				{
        //					state = State.HOT;
        //				}
        //				else if (b instanceof JButton
        //						&& ((JButton) b).isDefaultButton())
        //				{
        //					state = State.DEFAULTED;
        //				}
        //				else if (c.hasFocus())
        //				{
        //					state = State.HOT;
        //				}
      }
      Dimension d = c.getSize();
      int dx = 0;
      int dy = 0;
      int dw = d.width;
      int dh = d.height;

      Border border = c.getBorder();
      Insets insets;
      if (border != null) {
        // Note: The border may be compound, containing an outer
        // opaque border (supplied by the application), plus an
        // inner transparent margin border. We want to size the
        // background to fill the transparent part, but stay
        // inside the opaque part.
        insets = BEButtonUI.getOpaqueInsets(border, c);
      } else {
        insets = c.getInsets();
      }
      if (insets != null) {
        dx += insets.left;
        dy += insets.top;
        dw -= (insets.left + insets.right);
        dh -= (insets.top + insets.bottom);
      }

      /** ************************* 以下代码由jb2011改造自WindowsButtonUI START ******************* */
      if (toolbar) {
        // 此状态下JToggleButton和JButton使用各自的背景实现,2012-10-16前无论是不是JToggleButton都是使用该种实是不太合理的
        if (model.isRollover() || model.isPressed()) {
          if (c instanceof JToggleButton)
            __Icon9Factory__.getInstance()
                .getToggleButtonIcon_RoverGreen()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          else
            __Icon9Factory__.getInstance()
                .getButtonIcon_PressedOrange()
                .draw((Graphics2D) g, dx, dy, dw, dh);
        } else if (model.isSelected()) // state == State.CHECKED)//||state == State.HOTCHECKED)
        {
          __Icon9Factory__.getInstance()
              .getToggleButtonIcon_CheckedGreen()
              .draw((Graphics2D) g, dx, dy, dw, dh);
        } else {
          // TODO 其它状态下的按钮背景样式需要完善,要不然看起来太硬!
          //					skin.paintSkin(g, dx, dy, dw, dh, state);
        }
      } else {
        try {
          // TODO 其它状态下的按钮背景样式需要完善,要不然看起来太硬!

          //					if(state == State.PRESSED)
          if (model.isArmed() && model.isPressed() || model.isSelected())
            __Icon9Factory__.getInstance()
                .getButtonIcon_PressedOrange()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          //					else if(state == State.DISABLED)
          else if (!model.isEnabled())
            __Icon9Factory__.getInstance()
                .getButtonIcon_DisableGray()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          else if (model.isRollover())
            __Icon9Factory__.getInstance()
                .getButtonIcon_rover()
                .draw((Graphics2D) g, dx, dy, dw, dh);
          else {
            if (nomalColor == NormalColor.green) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalGreen()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            } else if (nomalColor == NormalColor.red) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalRed()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            } else if (nomalColor == NormalColor.blue) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalBlue()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            } else if (nomalColor == NormalColor.lightBlue) {
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalLightBlue()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
            }
            //						else if(nomalColor==NormalColor.red)
            //						{
            //							//红色按钮禁用状态时为更好地突出禁用状态,用深灰按钮
            //							if(state == State.DISABLED)
            //								__Icon9Factory__.getInstance().getButtonIcon_NormalGray().draw((Graphics2D)g,
            // dx, dy, dw, dh);
            //							else
            //								__Icon9Factory__.getInstance().getButtonIcon_NormalRed().draw((Graphics2D)g,
            // dx, dy, dw, dh);
            //						}
            else
              __Icon9Factory__.getInstance()
                  .getButtonIcon_NormalGray()
                  .draw((Graphics2D) g, dx, dy, dw, dh);
          }
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
      /** ************************* 以下代码由JS改造自WindowsButtonUI END ******************* */
    }
  }
Ejemplo n.º 4
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);
  }