1
4 import org.aswing.*;
5 import org.aswing.graphices.*;
6 import org.aswing.geom.*;
7 import org.aswing.plaf.*;
8 import org.aswing.plaf.winxp.*;
9
10
11 class org.aswing.plaf.winxp.WinXpToggleButtonUI extends WinXpButtonUI{
12
13 private static var toggleButtonUI:WinXpToggleButtonUI;
14
15 private static var propertyPrefix:String = "ToggleButton" + ".";
16
17
18
19
20 public static function createInstance(c:Component):ComponentUI {
21 if(toggleButtonUI == null){
22 toggleButtonUI = new WinXpToggleButtonUI();
23 }
24 return toggleButtonUI;
25 }
26
27 private function getPropertyPrefix():String {
28 return propertyPrefix;
29 }
30
31 public function WinXpToggleButtonUI() {
32 super();
33 }
34
35
39 private function getTextShiftOffset():Number{
40 return 0;
41 }
42
43 private function paintIcon(b:AbstractButton, g:Graphics, iconRect:Rectangle):Void{
44 var model:ButtonModel = b.getModel();
45 var icon:Icon = b.getIcon();
46
47 if (!model.isEnabled()) {
48 if (model.isSelected()) {
49 icon = b.getDisabledSelectedIcon();
50 } else {
51 icon = b.getDisabledIcon();
52 }
53 } else if (model.isPressed()) {
54 icon = b.getPressedIcon();
55 if (icon == null) {
56
57 icon = b.getSelectedIcon();
58 }
59 } else if (model.isSelected()) {
60 if (b.isRollOverEnabled() && model.isRollOver()) {
61 icon = b.getRollOverSelectedIcon();
62 if (icon == null) {
63 icon = b.getSelectedIcon();
64 }
65 } else {
66 icon = b.getSelectedIcon();
67 }
68 } else if (b.isRollOverEnabled() && model.isRollOver()) {
69 icon = b.getRollOverIcon();
70 }
71
72 if (icon == null) {
73 icon = b.getIcon();
74 }
75
76 unistallLastPaintIcon(b, icon);
77 icon.paintIcon(b, g, iconRect.x, iconRect.y);
78 setJustPaintedIcon(b, icon);
79 }
80
81
84 private function paintBackGround(com:Component, g:Graphics, b:Rectangle):Void{
85 var c:AbstractButton = AbstractButton(com);
86 paintWinXPLAFButtonBackGround(c, g, b);
87 }
88
89 public function paintWinXPLAFButtonBackGround(c:AbstractButton, g:Graphics, b:Rectangle):Void{
90
91
92 if(c.isOpaque()){
93 if(c.getModel().isPressed() || c.getModel().isSelected()){
94 var table:UIDefaults = UIManager.getLookAndFeelDefaults();
95 this.upperGrad = table.getColor("Button.upperBgGradDown");
96 this.lowerGrad = table.getColor("Button.lowerBgGradDown");
97 var colors:Array = [upperGrad.getRGB(), lowerGrad.getRGB()];
98 var alphas:Array = [100,100];
99 var ratios:Array = [0, 100];
100 var matrix:Object = {matrixType:"box", x:b.x, y:b.y, w:b.width, h:b.height, r:(90/180)*Math.PI};
101 var brush:GradientBrush=new GradientBrush(GradientBrush.LINEAR, colors, alphas, ratios, matrix);
102 g.fillRoundRect(brush, b.x, b.y, b.width, b.height,3,3,3,3);
103 }
104 else{
105 var table:UIDefaults = UIManager.getLookAndFeelDefaults();
106 this.upperGrad = table.getColor("Button.upperBgGradUp");
107 this.lowerGrad = table.getColor("Button.lowerBgGradUp");
108
109 var colors:Array = [upperGrad.getRGB(), lowerGrad.getRGB()];
110 var alphas:Array = [100,100];
111 var ratios:Array = [200, 255];
112 var matrix:Object = {matrixType:"box", x:b.x, y:b.y, w:b.width, h:b.height, r:(90/180)*Math.PI};
113 var brush:GradientBrush=new GradientBrush(GradientBrush.LINEAR, colors, alphas, ratios, matrix);
114 g.fillRoundRect(brush, b.x, b.y, b.width, b.height,3,3,3,3);
115
116 }
117
118 }
119 }
120
121
122 }
123