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

📄 iconfactory.java

📁 漂亮的java swing 界面
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.flat;
import java.awt.*;

import javax.swing.*;
import javax.swing.plaf.UIResource;

import java.io.Serializable;

public class IconFactory implements Serializable {
  
  private static Icon checkBoxIcon;
  private static Icon radioButtonIcon;
  private static Icon checkBoxMenuItemIcon;
  private static Icon radioButtonMenuItemIcon;
  private static Icon sliderHorizIcon;
  private static Icon sliderVertIcon;
  private static Icon treeCollapsedIcon;
  private static Icon treeExpandedIcon;
  private static Icon bandaMenuItemIcon;
  private static Icon comboFlechaIcon;
  private static Icon scrollNorthIcon;
  private static Icon scrollSouthIcon;
  private static Icon scrollEastIcon;
  private static Icon scrollWestIcon;
  
  private static Icon frameCloseIcon;
  private static Icon frameMaxIcon;
  private static Icon frameMinIcon;
  private static Icon frameAltMaximizeIcon;
  
  private static Icon spinnerNextIcon;
  private static Icon spinnerPreviousIcon;
  
  public static Icon getSpinnerNextIcon() {
    if ( spinnerNextIcon == null ) {
      spinnerNextIcon = new SpinnerNextIcon();
    }
    return spinnerNextIcon;
  }
  
  public static Icon getSpinnerPreviousIcon() {
    if ( spinnerPreviousIcon == null ) {
      spinnerPreviousIcon = new SpinnerPreviousIcon();
    }
    return spinnerPreviousIcon;
  }
  
  public static Icon getFrameCloseIcon() {
    if ( frameCloseIcon == null ) {
      frameCloseIcon = new FrameGenericIcon( "InternalFrame.NimCloseIcon", 
                                             "InternalFrame.NimCloseIconRoll", 
                                             "InternalFrame.NimCloseIconPush");
    }
    return frameCloseIcon;
  }
  
  public static Icon getFrameMaxIcon() {
    if ( frameMaxIcon == null ) {
      frameMaxIcon = new FrameGenericIcon( "InternalFrame.NimMaxIcon", 
                                           "InternalFrame.NimMaxIconRoll",
                                           "InternalFrame.NimMaxIconPush"); 
    }
    return frameMaxIcon;
  }
  
  public static Icon getFrameMinIcon() {
    if ( frameMinIcon == null ) {
      frameMinIcon = new FrameGenericIcon( "InternalFrame.NimMinIcon", 
                                           "InternalFrame.NimMinIconRoll",
                                           "InternalFrame.NimMinIconPush");
    }
    return frameMinIcon;
  }
  
  public static Icon getFrameAltMaximizeIcon() {
    if ( frameAltMaximizeIcon == null ) {
      frameAltMaximizeIcon = new FrameGenericIcon( "InternalFrame.NimResizeIcon", 
                                                   "InternalFrame.NimResizeIconRoll",
                                                   "InternalFrame.NimResizeIconPush");
    }
    return frameAltMaximizeIcon;
  }
  
  public static Icon getComboFlechaIcon() {
    if ( comboFlechaIcon == null ) {
      comboFlechaIcon = new ComboFlechaIcon();
    }
    return comboFlechaIcon;
  }

  public static Icon getBandaMenuItemIcon() {
    if ( bandaMenuItemIcon == null ) {
      bandaMenuItemIcon = new BandaMenuItemIcon();
    }
    return bandaMenuItemIcon;
  } 
  
  public static Icon getCheckBoxIcon() {
  	if ( checkBoxIcon == null ) {
	    checkBoxIcon = new CheckBoxIcon();
  	}
    return checkBoxIcon;
  }
  
  public static Icon getRadioButtonIcon() {
  	if ( radioButtonIcon == null ) {
	    radioButtonIcon = new RadioButtonIcon();
  	}
    return radioButtonIcon;
  }
  
  public static Icon getCheckBoxMenuItemIcon() {
  	if ( checkBoxMenuItemIcon == null ) {
	    checkBoxMenuItemIcon = new CheckBoxMenuItemIcon();
  	}
    return checkBoxMenuItemIcon;
  }

  public static Icon getRadioButtonMenuItemIcon() {
  	if ( radioButtonMenuItemIcon == null ) {
  	  radioButtonMenuItemIcon = new RadioButtonMenuItemIcon();
  	}
  	return radioButtonMenuItemIcon;
  }
  
  public static Icon getSliderVerticalIcon() {
  	if ( sliderVertIcon == null ) {
  	  sliderVertIcon = new SliderVerticalIcon();
  	}
  	return sliderVertIcon;
  }
  
  public static Icon getSliderHorizontalIcon() {
  	if ( sliderHorizIcon == null ) {
  	  sliderHorizIcon = new SliderHorizontalIcon();
  	}
  	return sliderHorizIcon;
  }
 
  public static Icon getTreeCollapsedIcon() {
  	if ( treeCollapsedIcon == null ) {
  	  treeCollapsedIcon = new TreeCollapsedIcon();
  	}
  	return treeCollapsedIcon;
  }
  
  public static Icon getTreeExpandedIcon() {
  	if ( treeExpandedIcon == null ) {
  	  treeExpandedIcon = new TreeExpandedIcon();
  	}
  	return treeExpandedIcon;
  }
  
  public static Icon getScrollBarNorthButtonIcon() {
    if ( scrollNorthIcon == null ) {
      scrollNorthIcon = new ScrollBarNorthButtonIcon();
    }
    return scrollNorthIcon;
  }
  
  public static Icon getScrollBarSouthButtonIcon() {
    if ( scrollSouthIcon == null ) {
      scrollSouthIcon = new ScrollBarSouthButtonIcon();
    }
    return scrollSouthIcon;
  }
  
  public static Icon getScrollBarEastButtonIcon() {
    if ( scrollEastIcon == null ) {
      scrollEastIcon = new ScrollBarEastButtonIcon();
    }
    return scrollEastIcon;
  }
  
  public static Icon getScrollBarWestButtonIcon() {
    if ( scrollWestIcon == null ) {
      scrollWestIcon = new ScrollBarWestButtonIcon();
    }
    return scrollWestIcon;
  }
  /******************************************************************************************/
  private static class ComboFlechaIcon implements Icon, UIResource, Serializable {
    
    private int w, h;
    
    public ComboFlechaIcon() {
      w = 15;
      h = 15;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      Icon icon = UIManager.getIcon( "ComboBox.flechaIcon");
      w = icon.getIconWidth();
      h = icon.getIconHeight();
      
      icon.paintIcon( c, g, x, y);
      
      g.setColor( LookAndFeel.getFocusColor());
      g.drawLine( x+2, y+5, x+7, y+10);
      g.drawLine( x+7, y+10, x+12, y+5);
      g.drawLine( x+2, y+4, x+7, y+9);
      g.drawLine( x+7, y+9, x+12, y+4);
    }

    public int getIconWidth() { 
      return w;
    } 

    public int getIconHeight() { 
      return h; 
    }
  }

  private static class ScrollBarNorthButtonIcon implements Icon, UIResource, Serializable {
    
    private int w, h;
    
    public ScrollBarNorthButtonIcon() {
      w = 15;
      h = 15;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      Icon icon = UIManager.getIcon( "ScrollBar.northButtonIconImage");
      w = icon.getIconWidth();
      h = icon.getIconHeight();
      
      icon.paintIcon( c, g, x, y);
      
      g.setColor( LookAndFeel.getFocusColor());
      g.drawLine( x+2, y+8, x+7, y+3);
      g.drawLine( x+7, y+3, x+12, y+8);
      g.drawLine( x+2, y+9, x+7, y+4);
      g.drawLine( x+7, y+4, x+12, y+9);
    }

    public int getIconWidth() { 
      return w;
    } 

    public int getIconHeight() { 
      return h; 
    }
  }

  /******************************************************************************************/
  private static class ScrollBarSouthButtonIcon implements Icon, UIResource, Serializable {
    private static final long serialVersionUID = -3074532619903027901L; 
    
    private int w, h;
    
    public ScrollBarSouthButtonIcon() {
      w = 15;
      h = 15;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      Icon icon = UIManager.getIcon( "ScrollBar.southButtonIconImage");
      w = icon.getIconWidth();
      h = icon.getIconHeight();
      
      icon.paintIcon( c, g, x, y);
      
      g.setColor( LookAndFeel.getFocusColor());
      g.drawLine( x+2, y+5, x+7, y+10);
      g.drawLine( x+7, y+10, x+12, y+5);
      g.drawLine( x+2, y+6, x+7, y+11);
      g.drawLine( x+7, y+11, x+12, y+6);
    }

    public int getIconWidth() { 
      return w;
    } 

    public int getIconHeight() { 
      return h; 
    }
  }

  /******************************************************************************************/
  private static class ScrollBarEastButtonIcon implements Icon, UIResource, Serializable {
    private static final long serialVersionUID = -3074532619903027901L; 
    
    private int w, h;
    
    public ScrollBarEastButtonIcon() {
      w = 15;
      h = 15;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      Icon icon = UIManager.getIcon( "ScrollBar.eastButtonIconImage");
      w = icon.getIconWidth();
      h = icon.getIconHeight();
      
      icon.paintIcon( c, g, x, y);
      
      g.setColor( LookAndFeel.getFocusColor());
      g.drawLine( x+5, y+2, x+10, y+7);
      g.drawLine( x+10, y+7, x+5, y+12);
      g.drawLine( x+6, y+2, x+11, y+7);
      g.drawLine( x+11, y+7, x+6, y+12);
    }

    public int getIconWidth() { 
      return w;
    } 

    public int getIconHeight() { 
      return h; 
    }
  }

  /******************************************************************************************/
  private static class ScrollBarWestButtonIcon implements Icon, UIResource, Serializable {
    private static final long serialVersionUID = -3074532619903027901L; 
    
    private int w, h;
    
    public ScrollBarWestButtonIcon() {
      w = 15;
      h = 15;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      Icon icon = UIManager.getIcon( "ScrollBar.westButtonIconImage");
      w = icon.getIconWidth();
      h = icon.getIconHeight();
      
      icon.paintIcon( c, g, x, y);
      
      g.setColor( LookAndFeel.getFocusColor());
      g.drawLine( x+9, y+2, x+4, y+7);
      g.drawLine( x+4, y+7, x+9, y+12);
      g.drawLine( x+10, y+2, x+5, y+7);
      g.drawLine( x+5, y+7, x+10, y+12);
    }

    public int getIconWidth() { 
      return w;
    } 

    public int getIconHeight() { 
      return h; 
    }
  }
  
  /******************************************************************************************/
  private static class CheckBoxIcon implements Icon, UIResource, Serializable { 
    private static final long serialVersionUID = 7191199235214123414L;
    
    private int w, h;
    
    public CheckBoxIcon() {
      w = 21;
      h = 21;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
	    JCheckBox b = (JCheckBox) c;
	    ButtonModel model = b.getModel();

	    boolean isEnabled = model.isEnabled();
      boolean isOn = model.isSelected() || model.isPressed();
	    
      g.setColor( LookAndFeel.getControl());
      g.fillRect( x+4,y+3, 13,15);
      g.drawLine( x+3,y+4, x+3,y+16);
      g.drawLine( x+17,y+4, x+17,y+16);
      
	    Icon icono = UIManager.getIcon( "CheckBox.iconBase");
      icono.paintIcon( c, g, x, y);

      if ( isOn ) {
        g.setColor( LookAndFeel.getFocusColor());
        g.fillRect( x+4,y+3, 13,15);
        g.drawLine( x+3,y+4, x+3,y+16);
        g.drawLine( x+17,y+4, x+17,y+16);
      }
      
      if ( model.isArmed() && isEnabled ) {
        g.setColor( new Color( 255,255,155, 127));
        g.fillRect( x+5,y+5, 11,11);
      }
      
      if ( isOn ) {
        icono = UIManager.getIcon( "CheckBox.iconTick");
        icono.paintIcon( c, g, x, y);
      }
  	}

	  public int getIconWidth() { 
      return w;
    } 

	  public int getIconHeight() { 
      return h; 
    }
  }
  
  /******************************************************************************************/
  private static class RadioButtonIcon implements Icon, UIResource, Serializable { 
    private int w, h;
    
    public RadioButtonIcon() {
      w = 21;
      h = 21;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
	    JRadioButton b = (JRadioButton) c;
	    ButtonModel model = b.getModel();

	    boolean isEnabled = model.isEnabled();
      boolean isOn = model.isSelected() || model.isPressed();
	    
      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      g2D.setColor( LookAndFeel.getControl());
      g2D.fillOval( x+3,y+3, 15,15);
      
	    Icon icono = UIManager.getIcon( "RadioButton.iconBase");
      icono.paintIcon( c, g, x, y);

      if ( isOn ) {
        g2D.setColor( LookAndFeel.getFocusColor());
        g2D.fillOval( x+3,y+3, 15,15);
      }
      
      if ( model.isArmed() && isEnabled ) {
        g2D.setColor( new Color( 255,255,155, 127));
        g2D.fillOval( x+5,y+5, 11,11);
      }
      
      if ( isOn ) {
        icono = UIManager.getIcon( "RadioButton.iconTick");
        icono.paintIcon( c, g, x, y);
      }
      
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
  	}

	  public int getIconWidth() { 
      return w;
    } 

	  public int getIconHeight() { 
      return h; 
    }
  }
  
  /******************************************************************************************/
  private static class CheckBoxMenuItemIcon implements Icon, UIResource, Serializable { 
    
    private int w, h;

⌨️ 快捷键说明

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