1
4
5 import org.aswing.ASColor;
6 import org.aswing.ASFont;
7 import org.aswing.border.Border;
8 import org.aswing.Component;
9 import org.aswing.Icon;
10 import org.aswing.Insets;
11 import org.aswing.plaf.ComponentUI;
12 import org.aswing.utils.HashMap;
13
14
21 class org.aswing.UIDefaults extends HashMap{
22
23 private static var CREATE_METHOD_NAME:String = "createInstance";
24
25
26 public function UIDefaults() {
27 super();
28 }
29
30
42 public function put(key:String, value:Object){
43 var oldValue = (value == null) ? super.remove(key) : super.put(key, value);
44 return oldValue;
45 }
46
47
53 public function putDefaults(keyValueList:Array):Void{
54 for(var i:Number = 0; i < keyValueList.length; i += 2) {
55 var value = keyValueList[i + 1];
56 if (value == null) {
57 super.remove(keyValueList[i]);
58 }else {
59 super.put(keyValueList[i], value);
60 }
61 }
62 }
63
64
68 public function getUI(target:Component):ComponentUI{
69 return ComponentUI(getInstance(target.getUIClassID()));
70 }
71
72 public function getBoolean(key:String):Boolean{
73 return (get(key) == true);
74 }
75
76 public function getNumber(key:String):Number{
77 return get(key);
78 }
79
80 public function getBorder(key:String):Border{
81 var border:Border = Border(getInstance(key));
82 if(border == null){
83 border = undefined;
84 }
85 return border;
86 }
87
88 public function getIcon(key:String):Icon{
89 var icon:Icon = Icon(getInstance(key));
90 if(icon == null){
91 icon = undefined;
92 }
93 return icon;
94 }
95
96 public function getColor(key:String):ASColor{
97 var color:ASColor = ASColor(getInstance(key));
98 if(color == null){
99 color = undefined;
100 }
101 return color;
102 }
103
104 public function getFont(key:String):ASFont{
105 var font:ASFont = ASFont(getInstance(key));
106 if(font == null){
107 font = undefined;
108 }
109 return font;
110 }
111
112 public function getInsets(key:String):Insets{
113 var i:Insets = Insets(getInstance(key));
114 if(i == null){
115 i = undefined;
116 }
117 return i;
118 }
119
120
121 public function getConstructor(key:String):Function{
122 return Function(this.get(key));
123 }
124
125 public function getInstance(key:String):Object{
126 var value = this.get(key);
127 if(value instanceof Function){
128 return getCreateInstance(Function(value));
129 }else{
130 return value;
131 }
132 }
133
134 private function getCreateInstance(constructor:Function):Object{
135 var instance:Object = constructor[CREATE_METHOD_NAME]();
136 if(instance == null){
137 instance = new constructor();
138 }
139 return instance;
140 }
141 }
142