1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4  
     5  import org.aswing.Component;
     6  import org.aswing.geom.Dimension;
     7  import org.aswing.geom.Rectangle;
     8  import org.aswing.plaf.basic.frame.ResizeStrategy;
     9  
    10  /**
    11   * A basic implementation of ResizeStrategy.
    12   * 
    13   * <p>It will return the resized rectangle, the rectangle is not min than 
    14   * getResizableMinSize and not max than getResizableMaxSize if these method are defineded
    15   * in the resized comopoent.
    16   * 
    17   * @author iiley
    18   */
    19  class org.aswing.plaf.basic.frame.ResizeStrategyImp implements ResizeStrategy{
    20  	
    21  	private var wSign:Number;
    22  	private var hSign:Number;
    23  	
    24  	public function ResizeStrategyImp(wSign:Number, hSign:Number){
    25  		this.wSign = wSign;
    26  		this.hSign = hSign;
    27  	}
    28  	
    29  	/**
    30  	 * Count and return the new bounds what the component would be resized to.<br>
    31  	 * 
    32   	 * It will return the resized rectangle, the rectangle is not min than 
    33   	 * getResizableMinSize and not max than getResizableMaxSize if these method are defineded
    34   	 * in the resized comopoent.
    35  	 */
    36  	public function getBounds(com:Component, movedX:Number, movedY:Number):Rectangle{
    37  		var currentBounds:Rectangle = com.getBounds();
    38  		var minSize:Dimension = com.getMinimumSize();
    39  		var maxSize:Dimension = com.getMaximumSize();
    40  		if(minSize == undefined){
    41  			minSize = new Dimension(0, 0);
    42  		}
    43  		if(maxSize == undefined){
    44  			maxSize = new Dimension(Number.MAX_VALUE, Number.MAX_VALUE);
    45  		}		
    46  		var newX:Number;
    47  		var newY:Number;
    48  		var newW:Number;
    49  		var newH:Number;
    50  		if(wSign == 0){
    51  			newW = currentBounds.width;
    52  		}else{
    53  			newW = currentBounds.width + wSign*movedX;
    54  			newW = Math.min(maxSize.width, Math.max(minSize.width, newW));
    55  		}
    56  		if(wSign < 0){
    57  			newX = currentBounds.x + (currentBounds.width - newW);
    58  		}else{
    59  			newX = currentBounds.x;
    60  		}
    61  		
    62  		if(hSign == 0){
    63  			newH = currentBounds.height;
    64  		}else{
    65  			newH = currentBounds.height + hSign*movedY;
    66  			newH = Math.min(maxSize.height, Math.max(minSize.height, newH));
    67  		}
    68  		if(hSign < 0){
    69  			newY = currentBounds.y + (currentBounds.height - newH);
    70  		}else{
    71  			newY = currentBounds.y;
    72  		}
    73  		
    74  		return new Rectangle(newX, newY, newW, newH);
    75  	}
    76  }
    77