1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4   
     5  import org.aswing.*;
     6  import org.aswing.graphices.*;
     7  import org.aswing.plaf.*;
     8   
     9  /**
    10   *
    11   * @author iiley
    12   */
    13  class org.aswing.plaf.winxp.icon.RadioButtonIcon implements Icon, UIResource{
    14    
    15      private var highlight:ASColor;
    16      private var upperGradUp:ASColor;
    17      private var lowerGradUp:ASColor;
    18      private var dotUpperGradUp:ASColor;
    19      private var dotLowerGradUp:ASColor;
    20    
    21  
    22  	private static var instance:Icon;
    23  	/**
    24  	 * this make shared instance and construct when use.
    25  	 */	
    26  	public static function createInstance():Icon{
    27  		if(instance == null){
    28  			instance = new RadioButtonIcon();
    29  		}
    30  		return instance;
    31  	}
    32  
    33  	private function RadioButtonIcon(){
    34  		super();
    35  		var table:UIDefaults = UIManager.getLookAndFeelDefaults();
    36  		
    37  		highlight = table.getColor("RadioButton.highlight");
    38  		upperGradUp = table.getColor("RadioButton.upperGradUp");
    39  		lowerGradUp = table.getColor("RadioButton.lowerGradUp");
    40  		dotUpperGradUp = table.getColor("RadioButton.dotUpperGradUp");
    41  		dotLowerGradUp = table.getColor("RadioButton.dotLowerGradUp");
    42  	}
    43  
    44  	public function getIconWidth():Number{
    45  		return 13;
    46  	}
    47  
    48  	public function getIconHeight():Number{
    49  		return 13;
    50  	}
    51  
    52  	public function paintIcon(com:Component, g:Graphics, x:Number, y:Number):Void{
    53  		var rb:JRadioButton = JRadioButton(com);
    54  		var model:ButtonModel = rb.getModel();
    55  		var drawDot:Boolean = model.isSelected();
    56  		
    57  		var w:Number = getIconWidth();
    58  		var h:Number = getIconHeight();
    59  		var cx:Number = x + w/2;
    60  		var cy:Number = y + h/2;
    61  		var xr:Number = w/2;
    62  		var yr:Number = h/2;
    63  		
    64  		// Set up colors per RadioButtonModel condition
    65  		if (!model.isEnabled()) {
    66  			
    67  		} else if (model.isPressed()) {
    68  			
    69  		}
    70  		var sbrush:SolidBrush = new SolidBrush(highlight);
    71  		g.fillEllipse(sbrush, cx-xr, cy-yr, xr*2, yr*2);
    72  		
    73  		xr--;
    74  		yr--;
    75  		
    76  		
    77  	    var colors:Array = [upperGradUp.getRGB(), lowerGradUp.getRGB()];
    78  		var alphas:Array = [100, 100];
    79      	var ratios:Array = [50, 150];
    80  	    var matrix:Object = {matrixType:"box", x:cx-xr, y:cy-yr, w:xr*2, h:yr*2, r:(45/180)*Math.PI};        
    81  	    var gBrush:GradientBrush=new GradientBrush(GradientBrush.LINEAR, colors, alphas, ratios, matrix);
    82  		g.fillEllipse(gBrush, cx-xr, cy-yr, xr*2, yr*2);
    83  				
    84  		if(drawDot){
    85  			xr = w/5;
    86  			yr = h/5;
    87  			
    88  			colors = [dotUpperGradUp.getRGB(), dotLowerGradUp.getRGB()];
    89  			alphas= [100, 100];
    90      		ratios = [50, 150];
    91  	    	matrix = {matrixType:"box", x:cx-xr, y:cy-yr, w:xr*2, h:yr*2, r:(45/180)*Math.PI};        
    92  	    	gBrush=new GradientBrush(GradientBrush.LINEAR, colors, alphas, ratios, matrix);
    93  			g.fillEllipse(gBrush, cx-xr, cy-yr, xr*2, yr*2);
    94  			
    95  		}
    96  	}
    97  	public function uninstallIcon(com:Component):Void{
    98  	}
    99  }
   100