1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4   
     5  import org.aswing.*;
     6  import org.aswing.graphices.*;
     7  import org.aswing.geom.*;
     8  import org.aswing.plaf.*; 
     9  import org.aswing.plaf.basic.*;
    10   
    11  /**
    12   *
    13   * @author iiley
    14   */
    15  class org.aswing.plaf.asw.ASWingButtonUI extends BasicButtonUI{
    16  	/*shared instance*/
    17  	private static var asWingButtonUI:ASWingButtonUI;
    18  	
    19      public static function createInstance(c:Component):ComponentUI {
    20      	if(asWingButtonUI == null){
    21      		asWingButtonUI = new ASWingButtonUI();
    22      	}
    23          return asWingButtonUI;
    24      }
    25      
    26      public function ASWingButtonUI(){
    27      	super();
    28      }
    29      
    30      /**
    31       * Paint gradient background for AsWing LAF Buttons.
    32       */
    33      private function paintBackGround(com:Component, g:Graphics, b:Rectangle):Void{
    34      	var c:AbstractButton = AbstractButton(com);
    35      	paintASWingLAFButtonBackGround(c, g, b);
    36      }
    37      
    38      public static function paintASWingLAFButtonBackGround(c:AbstractButton, g:Graphics, b:Rectangle):Void{
    39  		var bgColor:ASColor = (c.getBackground() == null ? ASColor.WHITE : c.getBackground());
    40  
    41  		if(c.isOpaque()){
    42  			if(c.getModel().isPressed() || c.getModel().isSelected()){
    43  				g.fillRectangle(new SolidBrush(bgColor), b.x, b.y, b.width, b.height);
    44  				return;
    45  			}
    46  			g.fillRectangle(new SolidBrush(bgColor), b.x, b.y, b.width, b.height);
    47  			var x1:Number = b.x;
    48  			var y1:Number = b.y;
    49  			var x2:Number = x1 + b.width;
    50  			var y2:Number = y1 + b.height;
    51  	        var colors:Array = [0xFFFFFF, 0xFFFFFF];
    52  			var alphas:Array = [75, 0];
    53  			var ratios:Array = [0, 100];
    54  		    var matrix:Object = {matrixType:"box", x:x1, y:y1, w:b.width, h:b.height, r:(90/180)*Math.PI};        
    55  	        var brush:GradientBrush=new GradientBrush(GradientBrush.LINEAR, colors, alphas, ratios, matrix);
    56  	        g.fillRectangle(brush,x1,y1,x2-3,y2);
    57  		}    	
    58      }
    59  	
    60  }
    61