1  /*
     2   Copyright aswing.org, see the LICENCE.txt.
     3  */
     4   
     5  
     6  import org.aswing.*;
     7  import org.aswing.plaf.ASColorUIResource;
     8  import org.aswing.plaf.ASFontUIResource;
     9  import org.aswing.plaf.InsetsUIResource;
    10  
    11  
    12   
    13  /**
    14   * Note: All empty object should be undefined.
    15   * Undefined means not set, if it is null, means that user set it to be null, so LAF value will not be use. 
    16   * @author iiley
    17   */
    18  class org.aswing.plaf.basic.BasicLookAndFeel extends LookAndFeel{
    19  	
    20  	/**
    21  	 * Can't construct, need to extends it to make a completed LAF and implements features.
    22  	 */
    23  	private function BasicLookAndFeel(){
    24  	}
    25  	
    26  	public function getDefaults():UIDefaults{
    27  		var table:UIDefaults  = new UIDefaults();
    28  
    29  		initClassDefaults(table);
    30  		initSystemColorDefaults(table);
    31  		initSystemFontDefaults(table);
    32  		initComponentDefaults(table);
    33  	
    34  		return table;
    35  	}
    36  	
    37  	private function initClassDefaults(table:UIDefaults):Void{
    38  		var uiDefaults:Array = [
    39  			   "ButtonUI", org.aswing.plaf.basic.BasicButtonUI,
    40  			   "PanelUI", org.aswing.plaf.basic.BasicPanelUI,
    41  			   "ToggleButtonUI", org.aswing.plaf.basic.BasicToggleButtonUI,
    42  			   "RadioButtonUI", org.aswing.plaf.basic.BasicRadioButtonUI,
    43  			   "CheckBoxUI", org.aswing.plaf.basic.BasicCheckBoxUI,
    44  			   "ScrollBarUI", org.aswing.plaf.basic.BasicScrollBarUI,
    45  			   "ScrollPaneUI", org.aswing.plaf.basic.BasicScrollPaneUI,
    46  			   "ViewportUI", org.aswing.plaf.basic.BasicViewportUI,
    47  			   "WindowUI", org.aswing.plaf.basic.BasicWindowUI,
    48  			   "FrameUI", org.aswing.plaf.basic.BasicFrameUI,
    49  			   "ListUI",org.aswing.plaf.basic.BasicListUI,
    50  			   "LabelUI",org.aswing.plaf.basic.BasicLabelUI,
    51  			   "ToolTipUI",org.aswing.plaf.basic.BasicToolTipUI,
    52  			   "TextFieldUI", org.aswing.plaf.basic.BasicTextFieldUI,
    53  			   "TextAreaUI", org.aswing.plaf.basic.BasicTextAreaUI,
    54  			   "ToolBarUI", org.aswing.plaf.basic.BasicToolBarUI,
    55  			   "AccordionUI", org.aswing.plaf.basic.BasicAccordionUI,
    56  			   "ComboBoxUI", org.aswing.plaf.basic.BasicComboBoxUI,
    57  			   "SeparatorUI", org.aswing.plaf.basic.BasicSeparatorUI,
    58  			   "ProgressBarUI", org.aswing.plaf.basic.BasicProgressBarUI
    59  			   ];
    60  		table.putDefaults(uiDefaults);
    61  	}
    62  	
    63  	private function initSystemColorDefaults(table:UIDefaults):Void{
    64  			var defaultSystemColors:Array = [
    65  				  "activeCaption", 0xE0E0E0, /* Color for captions (title bars) when they are active. */
    66  			      "activeCaptionText", 0x000000, /* Text color for text in captions (title bars). */
    67  			    "activeCaptionBorder", 0xC0C0C0, /* Border color for caption (title bar) window borders. */
    68  			        "inactiveCaption", 0x808080, /* Color for captions (title bars) when not active. */
    69  			    "inactiveCaptionText", 0xC0C0C0, /* Text color for text in inactive captions (title bars). */
    70  			  "inactiveCaptionBorder", 0xC0C0C0, /* Border color for inactive caption (title bar) window borders. */
    71  				         "window", 0xCCCCCC, /* Default color for the interior of windows */
    72  				   "windowBorder", 0x000000, /* ??? */
    73  				     "windowText", 0x000000, /* ??? */
    74  					   "menu", 0xC0C0C0, /* Background color for menus */
    75  				       "menuText", 0x000000, /* Text color for menus  */
    76  					   "text", 0xC0C0C0, /* Text background color */
    77  				       "textText", 0x000000, /* Text foreground color */
    78  				  "textHighlight", 0x000080, /* Text background color when selected */
    79  			      "textHighlightText", 0xFFFFFF, /* Text color when selected */
    80  			       "textInactiveText", 0x808080, /* Text color when disabled */
    81  				        "control", 0xF4F4F4,//0xEFEFEF, /* Default color for controls (buttons, sliders, etc) */
    82  				    "controlText", 0x000000, /* Default color for text in controls */
    83  			       "controlHighlight", 0xEEEEEE, /* Specular highlight (opposite of the shadow) */
    84  			     "controlLtHighlight", 0x666666, /* Highlight color for controls */
    85  				  "controlShadow", 0xC7C7C5, /* Shadow color for controls */
    86  			        "controlDkShadow", 0x666666, /* Dark shadow color for controls */
    87  				      "scrollbar", 0xE0E0E0 /* Scrollbar background (usually the "track") */
    88  			];
    89  					
    90  					
    91  			for(var i:Number=0; i<defaultSystemColors.length; i+=2){
    92  				table.put(defaultSystemColors[i], new ASColorUIResource(defaultSystemColors[i+1]));
    93  			}
    94  					
    95  	}
    96  	
    97  	private function initSystemFontDefaults(table:UIDefaults):Void{
    98  		var defaultSystemFonts:Array = [
    99  				"systemFont", new ASFontUIResource("Tahoma", 11), 
   100  				"menuFont", new ASFontUIResource("Tahoma", 11), 
   101  				"controlFont", new ASFontUIResource("Tahoma", 11), 
   102  				"windowFont", new ASFontUIResource("Tahoma", 11)
   103  		];
   104  		table.putDefaults(defaultSystemFonts);
   105  	}
   106  	
   107  	private function initComponentDefaults(table:UIDefaults):Void{
   108  	   // *** JButton
   109  	    var comDefaults:Array = [
   110  	    	"Button.background", new ASColorUIResource(0xE7E7E5),
   111  	    	"Button.foreground", table.get("controlText"),
   112  	    	"Button.opaque", true,  
   113  	    	"Button.focusable", true,  
   114  	    	"Button.shadow", table.getColor("controlShadow"),        
   115          	"Button.darkShadow", table.getColor("controlDkShadow"),        
   116          	"Button.light", table.getColor("controlHighlight"),       
   117         		"Button.highlight", table.getColor("controlLtHighlight"),
   118          	"Button.font", table.getFont("controlFont"),
   119  			"Button.border", org.aswing.plaf.basic.border.ButtonBorder,
   120  			"Button.margin", new InsetsUIResource(0, 0, 0, 0),
   121  			"Button.textShiftOffset", 1];
   122  	    table.putDefaults(comDefaults);
   123  	    
   124  	    // *** ToggleButton
   125  	    comDefaults = [
   126  	    "ToggleButton.background", table.get("control"),
   127  	    "ToggleButton.foreground", table.get("controlText"),
   128      	"ToggleButton.opaque", true,  
   129      	"ToggleButton.focusable", true,  
   130  	    "ToggleButton.shadow", table.getColor("controlShadow"),
   131          "ToggleButton.darkShadow", table.getColor("controlDkShadow"),
   132          "ToggleButton.light", table.getColor("controlHighlight"),
   133          "ToggleButton.highlight", table.getColor("controlLtHighlight"),
   134          	"ToggleButton.font", table.getFont("controlFont"),
   135  		    "ToggleButton.border", org.aswing.plaf.basic.border.ButtonBorder,
   136  		    "ToggleButton.margin", new InsetsUIResource(0, 0, 0, 0),
   137  		    "ToggleButton.textShiftOffset", 1];
   138  	    table.putDefaults(comDefaults);
   139  	    
   140  	    // *** RadioButton
   141  	    comDefaults = [
   142  	    "RadioButton.background", table.get("control"),
   143  	    "RadioButton.foreground", table.get("controlText"),
   144      	"RadioButton.opaque", false,  
   145      	"RadioButton.focusable", true,  
   146  	    "RadioButton.shadow", new ASColorUIResource(0xEAEAEA),
   147          "RadioButton.darkShadow", table.getColor("controlDkShadow"),
   148          "RadioButton.light",table.getColor("controlHighlight"),
   149          "RadioButton.highlight",table.getColor("controlLtHighlight"),
   150          	"RadioButton.font", table.getFont("controlFont"),
   151  		    "RadioButton.icon", org.aswing.plaf.basic.icon.RadioButtonIcon,
   152  		    "RadioButton.margin", new InsetsUIResource(0, 0, 0, 0),
   153  		    "RadioButton.textShiftOffset", 1];
   154  	    table.putDefaults(comDefaults);	    
   155  	    	    
   156  	    // *** CheckBox
   157  	    comDefaults = [
   158  	    "CheckBox.background", table.get("control"),
   159  	    "CheckBox.foreground", table.get("controlText"),
   160      	"CheckBox.opaque", false,  
   161      	"CheckBox.focusable", true,  
   162  	    "CheckBox.shadow", table.getColor("controlShadow"),
   163          "CheckBox.darkShadow", table.getColor("controlDkShadow"),
   164          "CheckBox.light", new ASColorUIResource(0xCCCCCC),
   165          "CheckBox.highlight", table.getColor("controlLtHighlight"),
   166          	"CheckBox.font", table.getFont("controlFont"),
   167  		    "CheckBox.icon", org.aswing.plaf.basic.icon.CheckBoxIcon,
   168  		    "CheckBox.margin", new InsetsUIResource(0, 0, 0, 0),
   169  		    "CheckBox.textShiftOffset", 1];
   170  	    table.putDefaults(comDefaults);
   171  	    
   172  	    // *** ScrollBar
   173  	    comDefaults = [
   174  	    "ScrollBar.background", new ASColorUIResource(0xD0D0D0),
   175  	    "ScrollBar.foreground", table.get("controlText"),
   176      	"ScrollBar.opaque", true,  
   177      	"ScrollBar.focusable", true,  
   178  	    "ScrollBar.shadow", table.getColor("controlShadow"),
   179          "ScrollBar.darkShadow", table.getColor("controlDkShadow"),
   180          "ScrollBar.light", table.getColor("controlHighlight"),
   181          "ScrollBar.highlight", table.getColor("controlLtHighlight"),
   182          	"ScrollBar.font", table.getFont("controlFont"),
   183  	    	"ScrollBar.border", undefined,
   184  		    "ScrollBar.thumb", table.get("control"),
   185  		    "ScrollBar.thumbShadow", table.get("controlShadow"),
   186  		    "ScrollBar.thumbDarkShadow", table.get("controlDkShadow"),
   187  		    "ScrollBar.thumbHighlight", table.get("controlHighlight")
   188  		    ];
   189  	    table.putDefaults(comDefaults);
   190  	    
   191  	    // *** ScrollPane
   192  	    comDefaults = [
   193          "ScrollPane.darkShadow", table.getColor("controlDkShadow"),
   194      	"ScrollPane.opaque", false,  
   195      	"ScrollPane.focusable", true  
   196  	    ];
   197  	    table.putDefaults(comDefaults);
   198  	    
   199  	    // *** Viewport
   200  	    comDefaults = [
   201  	    "Viewport.border", undefined,
   202      	"Viewport.opaque", false,  
   203      	"Viewport.focusable", true,
   204  	    "Viewport.background", table.get("window"),
   205  	    "Viewport.foreground", table.get("windowText")
   206  	    ];
   207  	    table.putDefaults(comDefaults);
   208  	    	    
   209  	    // *** Panel
   210  	    comDefaults = [
   211  	    "Panel.background", table.get("window"),
   212  	    "Panel.foreground", table.get("windowText"),
   213      	"Panel.opaque", false,  
   214      	"Panel.focusable", true
   215  	    ];
   216  	    table.putDefaults(comDefaults);
   217  	    
   218  	    // *** Window
   219  	    comDefaults = [
   220  	    "Window.background", table.get("window"),
   221  	    "Window.foreground", table.get("windowText"),
   222      	"Window.opaque", true,  
   223      	"Window.focusable", true,
   224  	    "Window.modalColor", table.get("controlShadow"),
   225  	    "Window.contentPaneBorder", undefined
   226  	    ];
   227  	    table.putDefaults(comDefaults);
   228  
   229  	    // *** Frame
   230  	    comDefaults = [
   231  	    "Frame.background", table.get("window"),
   232  	    "Frame.foreground", table.get("windowText"),
   233      	"Frame.opaque", true,  
   234      	"Frame.focusable", true,
   235  	    "Frame.activeCaption", table.get("activeCaption"),
   236  	    "Frame.activeCaptionText", table.get("activeCaptionText"),
   237  	    "Frame.activeCaptionBorder", table.get("activeCaptionBorder"),
   238  	    "Frame.inactiveCaption", table.get("inactiveCaption"),
   239  	    "Frame.inactiveCaptionText", table.get("inactiveCaptionText"),
   240  	    "Frame.inactiveCaptionBorder", table.get("inactiveCaptionBorder"),
   241  	    "Frame.resizeArrow", table.get("inactiveCaption"),
   242  	    "Frame.resizeArrowLight", table.get("window"),
   243  	    "Frame.resizeArrowDark", table.get("activeCaptionText"),
   244  	    "Frame.titleBarUI", org.aswing.plaf.basic.frame.TitleBarUI,
   245  	    "Frame.resizer", org.aswing.plaf.basic.frame.Resizer,
   246  	    "Frame.font", table.get("windowFont"),
   247  	    "Frame.border", org.aswing.plaf.basic.border.FrameBorder,
   248  	    "Frame.icon", org.aswing.plaf.basic.frame.TitleIcon,
   249  	    "Frame.iconifiedIcon", org.aswing.plaf.basic.icon.FrameIconifiedIcon,
   250  	    "Frame.normalIcon", org.aswing.plaf.basic.icon.FrameNormalIcon,
   251  	    "Frame.maximizeIcon", org.aswing.plaf.basic.icon.FrameMaximizeIcon,
   252  	    "Frame.closeIcon", org.aswing.plaf.basic.icon.FrameCloseIcon
   253  	    ];
   254  	    table.putDefaults(comDefaults);	    
   255  	    
   256  	   // *** JLabel
   257  	    comDefaults = [
   258  	    "Label.background", new ASColorUIResource(0xE7E7E5),
   259  	    "Label.foreground", table.get("controlText"),
   260      	"Label.opaque", false,  
   261      	"Label.focusable", true,
   262          	"Label.font", table.getFont("controlFont"),
   263  		    "Label.border", undefined];
   264  	    table.putDefaults(comDefaults);
   265  	    
   266  	   // *** JToolTip
   267  	    comDefaults = [
   268  	    "ToolTip.background", new ASColorUIResource(0xFFFFD5),
   269  	    "ToolTip.foreground", table.get("controlText"),
   270      	"ToolTip.opaque", true,  
   271      	"ToolTip.focusable", true,
   272  	    	"ToolTip.borderColor", table.get("controlText"),
   273          	"ToolTip.font", table.getFont("controlFont"),
   274  		    "ToolTip.border", org.aswing.plaf.basic.border.ToolTipBorder];
   275  	    table.putDefaults(comDefaults);
   276  	    
   277  	     // *** List
   278  	    comDefaults = [
   279  	    "List.background", table.get("control"),
   280  	    "List.foreground", table.get("controlText"),
   281      	"List.opaque", false,  
   282      	"List.focusable", true,
   283  	    "List.itemBackground", table.get("control"),
   284  	    "List.itemForeground", table.get("controlText"),
   285          "List.itemSelectedBackground", new ASColorUIResource(0x444444),
   286  	    "List.itemSelectedForeground", table.get("control"),
   287  	    	"List.border", undefined
   288  	    ];
   289  	    table.putDefaults(comDefaults);
   290  
   291  	     // *** TextField
   292  	    comDefaults = [
   293  	    "TextField.background", new ASColorUIResource(0xF3F3F3),
   294  	    "TextField.foreground", new ASColorUIResource(0x000000),
   295      	"TextField.opaque", true,  
   296      	"TextField.focusable", true,
   297          "TextField.shadow", new ASColorUIResource(0x999999),
   298          "TextField.darkShadow", new ASColorUIResource(0xDCDEDD),
   299          "TextField.light", new ASColorUIResource(0xDCDEDD),
   300          "TextField.highlight", new ASColorUIResource(0x666666),
   301          	"TextField.font", table.getFont("controlFont"),
   302  		    "TextField.border", org.aswing.plaf.basic.border.TextFieldBorder];
   303  	    table.putDefaults(comDefaults);
   304  	    
   305  	     // *** TextArea
   306  	    comDefaults = [
   307  	    "TextArea.background", new ASColorUIResource(0xF3F3F3),
   308  	    "TextArea.foreground", new ASColorUIResource(0x000000),
   309      	"TextArea.opaque", true,  
   310      	"TextArea.focusable", true,
   311          "TextArea.shadow", new ASColorUIResource(0x999999),
   312          "TextArea.darkShadow", new ASColorUIResource(0xDCDEDD),
   313          "TextArea.light", new ASColorUIResource(0xDCDEDD),
   314          "TextArea.highlight", new ASColorUIResource(0x666666),
   315          	"TextArea.font", table.getFont("controlFont"),
   316  		    "TextArea.border", org.aswing.plaf.basic.border.TextAreaBorder];
   317  	    table.putDefaults(comDefaults);
   318  	    
   319  	    // *** ToolBar
   320  	    comDefaults = [
   321  	    "ToolBar.background", table.get("window"),
   322  	    "ToolBar.foreground", table.get("windowText"),
   323      	"ToolBar.opaque", true,  
   324      	"ToolBar.focusable", true,
   325  	    "ToolBar.buttonBorder", org.aswing.plaf.basic.border.ToolBarButtonBorder
   326  	    ];
   327  	    table.putDefaults(comDefaults);
   328  	    
   329  	    // *** ComboBox
   330  	    comDefaults = [
   331  	    "ComboBox.background", table.get("control"),
   332  	    "ComboBox.foreground", table.get("controlText"),
   333      	"ComboBox.opaque", true,
   334      	"ComboBox.focusable", true,
   335      	"ComboBox.shadow", table.getColor("controlShadow"),        
   336      	"ComboBox.darkShadow", table.getColor("controlDkShadow"),        
   337      	"ComboBox.light", table.getColor("controlHighlight"),       
   338     		"ComboBox.highlight", table.getColor("controlLtHighlight"),
   339  	    "ComboBox.border", org.aswing.plaf.basic.border.ComboBoxBorder
   340  	    ];
   341  	    table.putDefaults(comDefaults);
   342  	    
   343  	    // *** Separator
   344  	    comDefaults = [
   345  	    "Separator.background", new ASColorUIResource(0xcccccc),
   346  	    "Separator.foreground", new ASColorUIResource(0x444444),
   347      	"Separator.opaque", false,
   348      	"Separator.focusable", false
   349  	    ];
   350  	    table.putDefaults(comDefaults);
   351  	    
   352  	    // *** ProgressBar
   353  	    comDefaults = [
   354  	    "ProgressBar.background", table.get("window"),
   355  	    "ProgressBar.foreground", table.get("windowText"),
   356      	"ProgressBar.opaque", false,
   357      	"ProgressBar.focusable", false,        	
   358      	"ProgressBar.font", new ASFontUIResource("Tahoma", 9),
   359  		"ProgressBar.border", org.aswing.plaf.basic.border.ProgressBarBorder,
   360      	"ProgressBar.icon", org.aswing.plaf.basic.icon.ProgressBarIcon,
   361  		"ProgressBar.progressColor", new ASColorUIResource(0x3366CC)
   362  	    ];
   363  	    table.putDefaults(comDefaults);
   364  	}
   365  	
   366  }
   367