1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4   
     5  import org.aswing.ASColor;
     6  import org.aswing.border.Border;
     7  import org.aswing.border.DecorateBorder;
     8  import org.aswing.Component;
     9  import org.aswing.geom.Rectangle;
    10  import org.aswing.graphices.Graphics;
    11  import org.aswing.graphices.Pen;
    12  import org.aswing.Insets;
    13  
    14  /**
    15   * A border that draw a line at one side of a component.
    16   * @author iiley
    17   */
    18  class org.aswing.border.SideLineBorder extends DecorateBorder {
    19  	
    20      /**
    21       * The north side constraint (top of component).
    22       */
    23      public static var NORTH:Number  = 0;
    24  
    25      /**
    26       * The south side constraint (bottom of component).
    27       */
    28      public static var SOUTH:Number  = 1;
    29  
    30      /**
    31       * The east side constraint (right side of component).
    32       */
    33      public static var EAST :Number  = 2;
    34  
    35      /**
    36       * The west side constraint (left side of component).
    37       */
    38      public static var WEST :Number  = 3;
    39  	
    40  	private var side:Number;
    41  	private var color:ASColor;
    42  	private var thickness:Number;
    43  	
    44  	/**
    45  	 * SideLineBorder(interior:Border, side:Number, color:ASColor, thickness:Number) <br>
    46  	 * SideLineBorder(interior:Border, side:Number, color:ASColor) <br>
    47  	 * SideLineBorder(interior:Border, side:Number) <br>
    48  	 * SideLineBorder(interior:Border) <br>
    49  	 * SideLineBorder() <br>
    50  	 * <p>
    51  	 * @param interior interior border. Default is null;
    52  	 * @param side the side of the line. Must be one of bottom value:
    53  	 * <ul>
    54  	 *   <li>#NORTH
    55  	 *   <li>#SOUTH
    56  	 *   <li>#EAST
    57  	 *   <li>#WEST
    58  	 * </ul>
    59  	 * .Default is NORTH.
    60  	 * @param color the color of the border. Default is ASColor.BLACK
    61  	 * @param thickness the thickness of the border. Default is 1
    62  	 */
    63  	public function SideLineBorder(interior:Border, side:Number, color:ASColor, thickness:Number) {
    64  		super(interior);
    65  		this.side = (side == undefined ? NORTH : side);
    66  		this.color = (color == undefined ? ASColor.BLACK : color);
    67  		this.thickness = (thickness == undefined ? 1 : thickness);
    68  	}
    69  
    70  	
    71      public function paintBorderImp(c:Component, g:Graphics, b:Rectangle):Void{
    72   		var pen:Pen = new Pen(color, thickness);
    73   		var x1:Number, x2:Number, y1:Number, y2:Number;
    74   		if(side == SOUTH){
    75   			x1 = b.x;
    76   			y1 = b.y + b.height - thickness/2;
    77   			x2 = b.x + b.width;
    78   			y2 = y1;
    79   		}else if(side == EAST){
    80   			x1 = b.x + b.width - thickness/2;
    81   			y1 = b.y;
    82   			x2 = x1;
    83   			y2 = b.y + b.height;
    84   		}else if(side == WEST){
    85   			x1 = b.x + thickness/2;
    86   			y1 = b.y;
    87   			x2 = x1;
    88   			y2 = b.y + b.height;
    89   		}else{
    90   			x1 = b.x;
    91   			y1 = b.y + thickness/2;
    92   			x2 = b.x + b.width;
    93   			y2 = y1;
    94   		}
    95   		g.drawLine(pen, x1, y1, x2, y2);
    96      }
    97      
    98      public function getBorderInsetsImp(c:Component, b:Rectangle):Insets{
    99      	var i:Insets = new Insets();
   100   		if(side == SOUTH){
   101   			i.bottom = thickness;
   102   		}else if(side == EAST){
   103   			i.right = thickness;
   104   		}else if(side == WEST){
   105   			i.left = thickness;
   106   		}else{
   107   			i.top = thickness;
   108   		}
   109      	return i;
   110      }
   111  }
   112