1 /* 2 Copyright aswing.org, see the LICENCE.txt. 3 */ 4 5 6 import org.aswing.*; 7 import org.aswing.border.*; 8 import org.aswing.geom.*; 9 import org.aswing.graphices.*; 10 11 /** 12 * DecorateBorder make your border can represented as many border arounded. 13 * <p> 14 * <b>Note:You should only need to override:</b> 15 * <ul> 16 * <li><code>paintBorderImp</code> 17 * <li><code>uninstallBorderImp</code> 18 * <li><code>getBorderInsetsImp</code> 19 * </ul> 20 * methods in sub-class generally. 21 * 22 * @author iiley 23 */ 24 class org.aswing.border.DecorateBorder implements Border{ 25 26 private var interior:Border; 27 28 public function DecorateBorder(interior:Border){ 29 this.interior = interior; 30 } 31 32 /** 33 * Override this method in sub-class to draw border on the specified mc. 34 * @param c the component for which this border is being painted 35 * @param g the paint graphics 36 * @param bounds the bounds of border 37 */ 38 public function paintBorderImp(com:Component, g:Graphics, bounds:Rectangle):Void{ 39 } 40 41 /** 42 * Override this method in sub-class to clear and remove the border things you 43 * created for this component. 44 * @param com 45 * @see #uninstallBorder 46 */ 47 public function uninstallBorderImp(com:Component):Void{ 48 } 49 50 /** 51 * You should override this method to count this border's insets. 52 * @see #getBorderInsets 53 */ 54 public function getBorderInsetsImp(c:Component, bounds:Rectangle):Insets{ 55 return new Insets(); 56 } 57 58 /** 59 * call <code>super.paintBorder</code> paint the border first and then 60 * paint the interior border on the interior bounds. 61 * <br> 62 * Note:subclass should not override this method, should override paintBorderImp. 63 * @see #paintBorderImp 64 */ 65 public function paintBorder(c:Component, g:Graphics, bounds:Rectangle):Void{ 66 paintBorderImp(c, g, bounds); 67 //then paint interior border 68 if(interior != null){ 69 var interiorBounds:Rectangle = getBorderInsetsImp(c, bounds).getInsideBounds(bounds); 70 interior.paintBorder(c, g, interiorBounds); 71 } 72 } 73 74 75 /** 76 * call <code>super.uninstallBorder</code> unpaint the border first and then 77 * uninstall the interior border . 78 * <br> 79 * Note:subclass should not override this method, should override paintBorderImp. 80 * @see #uninstallBorderImp 81 */ 82 public function uninstallBorder(c:Component):Void{ 83 uninstallBorderImp(c); 84 //then unistall interior border 85 if(interior != null){ 86 interior.uninstallBorder(c); 87 } 88 } 89 90 91 /** 92 * Returns the insets of the border.<br> 93 * Note:subclass should not override this method, should override getBorderInsetsImp. 94 * @see #getBorderInsetsImp 95 * @param c the component for which this border insets value applies 96 * @param bounds the bounds of the border would paint in. 97 */ 98 public function getBorderInsets(c:Component, bounds:Rectangle):Insets{ 99 var insets:Insets = getBorderInsetsImp(c, bounds); 100 if(interior != null){ 101 var interiorBounds:Rectangle = insets.getInsideBounds(bounds); 102 insets.addInsets(interior.getBorderInsets(c, interiorBounds)); 103 } 104 return insets; 105 } 106 } 107