⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oyoahacheckboxui.java

📁 java 开源,Swing外观:JGoodies look & feel. ... JGoodies look&feels让你的Swing 应用程序与applets看起来更漂亮.
💻 JAVA
字号:
/* ==================================================================== * Copyright (c) 2001-2003 OYOAHA. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. The names "OYOAHA" must not be used to endorse or promote products  *    derived from this software without prior written permission.  *    For written permission, please contact email@oyoaha.com. * * 3. Products derived from this software may not be called "OYOAHA", *    nor may "OYOAHA" appear in their name, without prior written *    permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL OYOAHA OR ITS CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */package com.oyoaha.swing.plaf.oyoaha.ui;import java.awt.*;import javax.swing.*;import javax.swing.plaf.*;import javax.swing.plaf.metal.*;import javax.swing.plaf.basic.*;import javax.swing.text.View;import com.oyoaha.swing.plaf.oyoaha.*;public class OyoahaCheckBoxUI extends MetalCheckBoxUI implements OyoahaButtonLikeComponent{  public static ComponentUI createUI(JComponent c)  {    return new OyoahaCheckBoxUI();  }    public boolean isBorderPainted(Component c)  {    return ((AbstractButton)c).isBorderPainted();  }  public void installUI(JComponent c)  {    super.installUI(c);    OyoahaUtilities.installRolloverListener(c);    OyoahaUtilities.setOpaque(c);  }  public void uninstallUI(JComponent c)  {    super.uninstallUI(c);    OyoahaUtilities.uninstallRolloverListener(c);    OyoahaUtilities.unsetOpaque(c);  }  public void update(Graphics g, JComponent c)  {    OyoahaUtilities.paintBackground(g,c);    paint(g,c);  }  public void paint(Graphics g, JComponent c)  {    AbstractButton b = (AbstractButton) c;    ButtonModel model = b.getModel();    Dimension size = c.getSize();    int w = size.width;    int h = size.height;    Font f = c.getFont();    g.setFont(f);    FontMetrics fm = g.getFontMetrics();    Rectangle viewRect = new Rectangle(size);    Rectangle iconRect = new Rectangle();    Rectangle textRect = new Rectangle();    Icon altIcon = b.getIcon();    Icon selectedIcon = null;    Icon disabledIcon = null;    String text = SwingUtilities.layoutCompoundLabel(        c, fm, b.getText(), altIcon != null ? altIcon : getDefaultIcon(),        b.getVerticalAlignment(), b.getHorizontalAlignment(),        b.getVerticalTextPosition(), b.getHorizontalTextPosition(),        viewRect, iconRect, textRect, getDefaultTextIconGap(b)    );    // Paint the icon    if(altIcon != null)    {      if(!model.isEnabled())      {        altIcon = b.getDisabledIcon();      }      else      if(model.isPressed() && model.isArmed())      {        altIcon = b.getPressedIcon();        if(altIcon == null)        {          // Use selected icon          altIcon = b.getSelectedIcon();        }      }      else      if(model.isSelected())      {        if(b.isRolloverEnabled() && model.isRollover())        {          altIcon = (Icon) b.getRolloverSelectedIcon();          if (altIcon == null)          {            altIcon = (Icon) b.getSelectedIcon();          }        }        else        {          altIcon = (Icon) b.getSelectedIcon();        }      }      else      if(b.isRolloverEnabled() && model.isRollover())      {        altIcon = (Icon) b.getRolloverIcon();      }      if(altIcon == null)      {        altIcon = b.getIcon();      }      altIcon.paintIcon(c, g, iconRect.x, iconRect.y);    }    else    {      getDefaultIcon().paintIcon(c, g, iconRect.x, iconRect.y);    }    // Draw the Text    if(text!=null && !text.equals(""))    {      View v = (View)c.getClientProperty("html");      if (v != null)      {        v.paint(g, textRect);      }      else      {        if(model.isEnabled())        {          // *** paint the text normally          g.setColor(b.getForeground());          BasicGraphicsUtils.drawString(g,text,model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());        }        else        {          // *** paint the text disabled          //g.setColor(b.getBackground().darker());          g.setColor(UIManager.getColor("Label.disabledForeground"));          BasicGraphicsUtils.drawString(g,text,model.getMnemonic(), textRect.x, textRect.y + fm.getAscent());        }      }    }    if(b.hasFocus() && b.isFocusPainted())    {      paintFocus(g, b, viewRect, textRect, iconRect);    }  }  protected void paintFocus(Graphics g, AbstractButton b, Rectangle viewRect, Rectangle textRect, Rectangle iconRect)  {    Rectangle focusRect = new Rectangle();    String text = b.getText();    boolean isIcon = b.getIcon() != null;    if(text != null && !text.equals(""))    {      if (!isIcon)      {        focusRect.setBounds(textRect);      }      else      {        focusRect.setBounds(iconRect.union(textRect));      }    }    else    if(isIcon)    {      focusRect.setBounds(iconRect);    }    else    {      focusRect.setBounds(viewRect);    }    g.setColor(OyoahaUtilities.getColorFromScheme(OyoahaUtilities.FOCUS));    int h = focusRect.y+focusRect.height-1;    g.drawLine(focusRect.x, focusRect.y, focusRect.x+focusRect.width-1, focusRect.y);    g.drawLine(focusRect.x, h, focusRect.x+focusRect.width-1, h);  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -