1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4  
     5  import org.aswing.*;
     6  import org.aswing.graphices.*;
     7  
     8  /**
     9   * DecorateIcon let you can make Decorator Patten Icon.
    10   * <p>
    11   * <b>Note:You should only need to override:</b>
    12   * <ul>
    13   * <li><code>getIconWidthImp</code>
    14   * <li><code>getIconHeightImp</code>
    15   * <li><code>paintIconImp</code>
    16   * <li><code>uninstallIconImp</code>
    17   * </ul>
    18   * methods in sub-class generally.
    19   * 
    20   * @author iiley
    21   */
    22  class org.aswing.DecorateIcon implements Icon{
    23  	
    24  	private var bottomIcon:Icon;
    25  	
    26  	/**
    27  	 * DecorateIcon(icon:Icon)<br>
    28  	 * DecorateIcon()<br>
    29  	 */
    30  	public function DecorateIcon(bottomIcon:Icon){
    31  		this.bottomIcon = bottomIcon;
    32  	}
    33  	
    34  	/**
    35  	 * You should override this method to count icon width in sub-class.
    36  	 */
    37  	public function getIconWidthImp():Number{
    38  		return 0;
    39  	}
    40  	
    41  	/**
    42  	 * You should override this method to count icon height in sub-class.
    43  	 */
    44  	public function getIconHeightImp():Number{
    45  		return 0;
    46  	}
    47  	
    48  	/**
    49  	 * Override this method in sub-class to draw icon on the iconMC at the 
    50  	 * specified location.
    51  	 * @param com the component where the icon is on.
    52  	 * @param g the paint graphics
    53  	 * @param x the icon's x coordinate
    54  	 * @param y the icon's x coordinate
    55  	 */
    56  	public function paintIconImp(com:Component, g:Graphics, x:Number, y:Number):Void{
    57  	}
    58  	
    59  	/**
    60  	 * Override this method in sub-class to clear and remove the icon things you 
    61  	 * created for this component.
    62  	 * @see #uninstallIcon()
    63  	 */
    64  	public function uninstallIconImp(com:Component):Void{
    65  	}
    66  
    67  	/**
    68  	 * Return the icon's width.
    69  	 * You should not override this method, should override <code>getIconWidthImp</code>
    70  	 * @see getIconWidthImp()
    71  	 */
    72  	public function getIconWidth():Number{
    73  		var bottomWidth:Number = (bottomIcon == null ? 0 : bottomIcon.getIconWidth());
    74  		return Math.max(bottomWidth, getIconWidthImp());
    75  	}
    76  	
    77  	/**
    78  	 * Return the icon's height.
    79  	 * You should not override this method, should override <code>getIconHeightImp</code>
    80  	 * @see getIconHeightImp()
    81  	 */
    82  	public function getIconHeight():Number{
    83  		var bottomHeight:Number = (bottomIcon == null ? 0 : bottomIcon.getIconHeight());
    84  		return Math.max(bottomHeight, getIconHeightImp());
    85  	}
    86  	
    87  	/**
    88  	 * Draw the icon at the specified location.
    89  	 */
    90  	public function paintIcon(com:Component, g:Graphics, x:Number, y:Number):Void{
    91  		bottomIcon.paintIcon(com, g, x, y);
    92  		paintIconImp(com, g, x, y);
    93  	}
    94  	
    95  	/**
    96  	 * Clear the things the icon painted.
    97  	 */
    98  	public function uninstallIcon(com:Component):Void{
    99  		bottomIcon.uninstallIcon(com);
   100  		uninstallIconImp(com);
   101  	}
   102  }
   103