1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4  
     5  import org.aswing.*;
     6  import org.aswing.geom.*;
     7  import org.aswing.graphices.*;
     8  import org.aswing.border.*;
     9  
    10  /**
    11   * @author iiley
    12   */
    13  class org.aswing.border.LineBorder extends DecorateBorder{
    14  	
    15  	private var color:ASColor;
    16  	private var thickness:Number;
    17  	private var round:Number;
    18  	
    19  	/**
    20  	 * LineBorder(interior:Border, color:ASColor, thickness:Number, roundedCorners:Boolean)<br>
    21  	 * LineBorder(interior:Border, color:ASColor, thickness:Number)<br>
    22  	 * LineBorder(interior:Border, color:ASColor)<br>
    23  	 * LineBorder(interior:Border)<br>
    24  	 * LineBorder()<br>
    25  	 * @param interior interior border. Default is null;
    26  	 * @param color the color of the border. Default is ASColor.BLACK
    27  	 * @param thickness the thickness of the border. Default is 1
    28  	 * @param round round rect radius, default is 0 means normal rectangle, not rect.
    29  	 */
    30  	public function LineBorder(interior:Border, color:ASColor, thickness:Number, round:Number){
    31  		super(interior);
    32  		this.color = (color == undefined ? ASColor.BLACK : color);
    33  		this.thickness = (thickness == undefined ? 1 : thickness);
    34  		this.round = (round == undefined ? 0 : round);
    35  		this.round = Math.max(0, this.round);
    36  	}
    37  	
    38      public function paintBorderImp(c:Component, g:Graphics, b:Rectangle):Void{
    39   		var t:Number = thickness;
    40      	if(round <= 0){
    41      		g.drawRectangle(new Pen(color, thickness), b.x + t/2, b.y + t/2, b.width - t, b.height - t);
    42      	}else{
    43      		g.fillRoundRectRingWithThickness(new SolidBrush(color), b.x, b.y, b.width, b.height, round, t);
    44      	}
    45      }
    46      
    47      public function getBorderInsetsImp(c:Component, bounds:Rectangle):Insets{
    48      	var width:Number = Math.ceil(thickness + round - round*0.707106781186547); //0.707106781186547 = Math.sin(45 degrees);
    49      	return new Insets(width, width, width, width);
    50      }
    51  
    52  	public function getColor():ASColor {
    53  		return color;
    54  	}
    55  
    56  	public function setColor(color:ASColor):Void {
    57  		this.color = color;
    58  	}
    59  
    60  	public function getThickness():Number {
    61  		return thickness;
    62  	}
    63  
    64  	public function setThickness(thickness:Number):Void {
    65  		this.thickness = thickness;
    66  	}
    67  
    68  	public function getRound():Number {
    69  		return round;
    70  	}
    71  
    72  	public function setRound(round:Number):Void {
    73  		this.round = round;
    74  	}    
    75  }
    76