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

📄 iconfactory.java

📁 漂亮的java swing 界面
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    public CheckBoxMenuItemIcon() {
      w = 21;
      h = 0;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
	    JMenuItem b = (JMenuItem) c;
	    ButtonModel model = b.getModel();

      x = 1; y = 0;
	    boolean isEnabled = model.isEnabled();
      boolean isOn = model.isSelected() || model.isPressed();
	   
      Icon icono = UIManager.getIcon( "MenuCheckBox.iconBase");
      icono.paintIcon( c, g, x, y);

      if ( !isEnabled ) {
  	    g.setColor( new Color( 0,0,0, 63));
  	    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);
      }
      else 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( "MenuCheckBox.iconTick");
        icono.paintIcon( c, g, x, y);
      }
      
      g.setColor( Utils.getRolloverColor());
      g.fillRect( 0,0, 22,b.getHeight());
      
      g.setColor( Utils.getSombra());
      g.drawLine( 22,0, 22,b.getHeight());
      g.setColor( Utils.getBrillo());
      g.drawLine( 23,0, 23,b.getHeight());
  	}

	  public int getIconWidth() { 
      return w;
    } 

	  public int getIconHeight() { 
      return h; 
    }
  }
  
  /******************************************************************************************/
  private static class BandaMenuItemIcon implements Icon, UIResource, Serializable { 
    private static final long serialVersionUID = 8191199335214123414L;
    
    private int w, h;
    public BandaMenuItemIcon() {
      w = 21;
      h = 0;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      JMenuItem b = (JMenuItem) c;
      
      g.setColor( Utils.getRolloverColor());
      g.fillRect( 0,0, 22,b.getHeight());
      
      g.setColor( Utils.getSombra());
      g.drawLine( 22,0, 22,b.getHeight());
      g.setColor( Utils.getBrillo());
      g.drawLine( 23,0, 23,b.getHeight());
    }

    public int getIconWidth() { 
      return w;
    } 

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

      x = 1; y = 0;
	    boolean isEnabled = model.isEnabled();
      boolean isOn = model.isSelected() || model.isPressed();
	    
	    Icon icono = UIManager.getIcon( "MenuRadioButton.iconBase");
      icono.paintIcon( c, g, x, y);

      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      if ( !isEnabled ) {
        g2D.setColor( new Color( 0,0,0, 63));
        g2D.fillOval( x+3,y+3, 15,15);
      }
      else 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( "MenuRadioButton.iconTick");
        icono.paintIcon( c, g, x, y);
      }
      
      g.setColor( Utils.getRolloverColor());
      g.fillRect( 0,0, 22,b.getHeight());
      
      g.setColor( Utils.getSombra());
      g.drawLine( 22,0, 22,b.getHeight());
      g.setColor( Utils.getBrillo());
      g.drawLine( 23,0, 23,b.getHeight());
      
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
  	}

	  public int getIconWidth() { 
      return w;
    } 

	  public int getIconHeight() { 
      return h; 
    }
  }
  
  /***************************************************************************************************************/
  private static class SliderVerticalIcon implements Icon, UIResource, Serializable { 
    private static final long serialVersionUID = 3191199335214123414L;
    
    private int w, h;
    
    public SliderVerticalIcon() {
      w = 21;
      h = 19;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
	    if ( c.hasFocus() ) {
        g2D.setColor( LookAndFeel.getFocusColor());
        g2D.fillOval( x+1,y+4, 17,11);
      }
      else if ( !c.isEnabled() ) {
        g2D.setColor( Color.gray);
        g2D.fillOval( x+1,y+4, 17,11);
      }
	    
      Icon icono = UIManager.getIcon( "Slider.verticalThumbIconImage");
      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 SliderHorizontalIcon implements Icon, UIResource, Serializable {
    private static final long serialVersionUID = 1191199335214123414L;
    
    private int w, h;
    
    public SliderHorizontalIcon() {
      w = 19;
      h = 21;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      if ( c.hasFocus() ) {
        g2D.setColor( LookAndFeel.getFocusColor());
        g2D.fillOval( x+3,y+2, 11,17);
      }
      else if ( !c.isEnabled() ) {
        g2D.setColor( Color.gray);
        g2D.fillOval( x+3,y+2, 11,17);
      }
      
      Icon icono = UIManager.getIcon( "Slider.horizontalThumbIconImage");
      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 TreeCollapsedIcon implements Icon, UIResource, Serializable { 
    
    private int w, h;
    
    public TreeCollapsedIcon() {
      w = 18;
      h = 18;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      g.translate( x, y);
      
      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      g2D.setColor( LookAndFeel.getFocusColor());
      g2D.fillOval( 2,2, 14,14);
      
      g2D.setColor( LookAndFeel.getBlack());
      g2D.drawLine( 11,11, 7,7);
      g2D.drawLine( 11,11, 7,11);
      g2D.drawLine( 11,11, 11,7);
      
      Icon icono = UIManager.getIcon( "Tree.PelotillaIcon");
      icono.paintIcon( c, g, 0,0);
      
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
      
      g.translate( -x, -y);
  	}

	  public int getIconWidth() { 
      return w;
    } 

	  public int getIconHeight() { 
      return h; 
    }
  }
  
  /***************************************************************************************************************/
  private static class TreeExpandedIcon implements Icon, UIResource, Serializable { 
    
    private int w, h;
    
    public TreeExpandedIcon() {
      w = 18;
      h = 18;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      g.translate( x, y);
      
      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      g2D.setColor( LookAndFeel.getFocusColor());
      g2D.fillOval( 2,2, 14,14);
      
      g2D.setColor( LookAndFeel.getBlack());
      g2D.drawLine( 10,10, 6,6);
      g2D.drawLine( 6,6, 6,10);
      g2D.drawLine( 6,6, 10,6);
      
      Icon icono = UIManager.getIcon( "Tree.PelotillaIcon");
      icono.paintIcon( c, g, 0,0);
      
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
      
      g.translate( -x, -y);
  	}

	  public int getIconWidth() { 
      return w;
    } 

	  public int getIconHeight() { 
      return h; 
    }
  }
  
  /***************************************************************************************************************/
  private static class FrameGenericIcon implements Icon, UIResource, Serializable {
    
    private String sIcono, sIconoR, sIconoP; 
    private int w, h;
    
    public FrameGenericIcon( String icon, String iconR, String iconP) {
      w = 20;
      h = 20;
      
      sIcono = icon;
      sIconoR = iconR;
      sIconoP = iconP;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      ButtonModel model = ((JButton)c).getModel();

      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      Icon icono = null;
      if ( model.isPressed() ) {
        g2D.setColor( LookAndFeel.getFocusColor());
        g2D.fillRoundRect( x,y, w,h, 4,4);
        icono = UIManager.getIcon( sIconoP);
      }
      else if ( model.isRollover() ) {
        icono = UIManager.getIcon( sIconoR);
      }
      else {
        icono = UIManager.getIcon( sIcono);
      }

      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 SpinnerNextIcon implements Icon, UIResource, Serializable { 
    private static final long serialVersionUID = 8191199334213423414L;
    
    private int w, h;
    
    public SpinnerNextIcon() {
      w = 7;
      h = 5;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      g.translate( x, y);
      
      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      if ( !c.isEnabled() ) {
        g2D.setColor( LookAndFeel.getInactiveControlTextColor());
      }
      else {
        ButtonModel mod = ((JButton)c).getModel();
        if ( mod.isPressed() ) {
          g2D.setColor( LookAndFeel.getFocusColor());
        }
        else {
          g2D.setColor( LookAndFeel.getControlTextColor());
        }
      }
      
      g2D.drawLine( 1,3, 3,1);
      g2D.drawLine( 3,1, 5,3);
      g2D.drawLine( 1,4, 3,2);
      g2D.drawLine( 3,2, 5,4);
      
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
      
      g.translate( -x,-y);
    }

    public int getIconWidth() { 
      return w;
    } 

    public int getIconHeight() { 
      return h; 
    }
  }
  
  /***************************************************************************************************************/
  private static class SpinnerPreviousIcon implements Icon, UIResource, Serializable { 
    
    private int w, h;
    
    public SpinnerPreviousIcon() {
      w = 7;
      h = 5;
    }
    
    public void paintIcon( Component c, Graphics g, int x, int y ) {
      g.translate( x, y);
      
      Graphics2D g2D = (Graphics2D)g;
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      
      if ( !c.isEnabled() ) {
        g2D.setColor( LookAndFeel.getInactiveControlTextColor());
      }
      else {
        ButtonModel mod = ((JButton)c).getModel();
        if ( mod.isPressed() ) {
          g2D.setColor( LookAndFeel.getFocusColor());
        }
        else {
          g2D.setColor( LookAndFeel.getControlTextColor());
        }
      }
      
      g2D.drawLine( 1,1, 3,3);
      g2D.drawLine( 3,3, 5,1);
      g2D.drawLine( 1,2, 3,4);
      g2D.drawLine( 3,4, 5,2);
      
      g2D.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
      
      g.translate( -x,-y);
    }

    public int getIconWidth() { 
      return w;
    } 

    public int getIconHeight() { 
      return h; 
    }
  }
}

⌨️ 快捷键说明

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