1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4   
     5  import org.aswing.*;
     6  import org.aswing.plaf.basic.*;
     7  import org.aswing.geom.*;
     8  import org.aswing.plaf.*;
     9  import org.aswing.graphices.*;
    10   
    11  /**
    12   * Basic ToggleButton implementation.
    13   * To implement a Diff ToggleButton UI, generally you should:
    14   * <ul>
    15   * 	<li>extends your ButtonUI to inherite diff features of buttons.
    16   * 	<li>initialize differnt UI defaults for buttons in your LAF class, for example: Button.border, 
    17   * 	Button.font, ToggleButton.backgound XXXButton.foreground...
    18   * </ul>
    19   * @author iiley
    20   */
    21  class org.aswing.plaf.basic.BasicToggleButtonUI extends BasicButtonUI{
    22  	
    23      // Shared UI object
    24      private static var toggleButtonUI:BasicToggleButtonUI;
    25      
    26      private static var propertyPrefix:String = "ToggleButton" + ".";
    27  
    28      // ********************************
    29      //          Create PLAF
    30      // ********************************
    31      public static function createInstance(c:Component):ComponentUI {
    32      	if(toggleButtonUI == null){
    33      		toggleButtonUI = new BasicToggleButtonUI();
    34      	}
    35          return toggleButtonUI;
    36      }
    37  
    38      private function getPropertyPrefix():String {
    39          return propertyPrefix;
    40      }
    41      
    42      public function BasicToggleButtonUI() {
    43      	super();
    44      }
    45          
    46      /**
    47       * Overriden so that the text will not be rendered as shifted for
    48       * Toggle buttons and subclasses.
    49       */
    50      private function getTextShiftOffset():Number{
    51      	return 0;
    52      }
    53      
    54      private function paintIcon(b:AbstractButton, g:Graphics, iconRect:Rectangle):Void{
    55          var model:ButtonModel = b.getModel();
    56          var icon:Icon = b.getIcon();
    57  
    58  		if (!model.isEnabled()) {
    59  			if (model.isSelected()) {
    60  				icon = b.getDisabledSelectedIcon();
    61  			} else {
    62  				icon = b.getDisabledIcon();
    63  			}
    64  		} else if (model.isPressed()) {
    65  			icon = b.getPressedIcon();
    66  			if (icon == null) {
    67  				// Use selected icon
    68  				icon = b.getSelectedIcon();
    69  			}
    70  		} else if (model.isSelected()) {
    71  			if (b.isRollOverEnabled() && model.isRollOver()) {
    72  				icon = b.getRollOverSelectedIcon();
    73  				if (icon == null) {
    74  					icon = b.getSelectedIcon();
    75  				}
    76  			} else {
    77  				icon = b.getSelectedIcon();
    78  			}
    79  		} else if (b.isRollOverEnabled() && model.isRollOver()) {
    80  			icon = b.getRollOverIcon();
    81  		}
    82  
    83  		if (icon == null) {
    84  			icon = b.getIcon();
    85  		}
    86  
    87          unistallLastPaintIcon(b, icon);
    88          icon.paintIcon(b, g, iconRect.x, iconRect.y);
    89      	setJustPaintedIcon(b, icon);
    90      }
    91      
    92  	private function paintBackGround(com:Component, g:Graphics, b:Rectangle):Void{
    93  		super.paintBackGround(com, g, b);
    94  	}
    95  }
    96