KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > izforge > izpack > gui > ButtonFactory


1 /*
2  * IzPack - Copyright 2001-2007 Julien Ponge, All Rights Reserved.
3  *
4  * http://www.izforge.com/izpack/
5  * http://developer.berlios.de/projects/izpack/
6  *
7  * Copyright 2002 Jan Blok
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package com.izforge.izpack.gui;
23
24 import java.awt.Color JavaDoc;
25
26 import javax.swing.Action JavaDoc;
27 import javax.swing.Icon JavaDoc;
28 import javax.swing.JButton JavaDoc;
29
30 /**
31  * This class makes it possible to use default buttons on macosx platform
32  */

33 public class ButtonFactory
34 {
35
36     private static boolean useHighlightButtons = false;
37
38     private static boolean useButtonIcons = false;
39
40     /**
41      * Enable icons for buttons This setting has no effect on OSX
42      */

43     public static void useButtonIcons()
44     {
45         useButtonIcons(true);
46     }
47
48     /**
49      * Enable or disable icons for buttons This setting has no effect on OSX
50      *
51      * @param useit flag which determines the behavior
52      */

53     public static void useButtonIcons(boolean useit)
54     {
55         if (System.getProperty("mrj.version") == null)
56         {
57             useButtonIcons = useit;
58         }
59     }
60
61     /**
62      * Enable highlight buttons This setting has no effect on OSX
63      */

64     public static void useHighlightButtons()
65     {
66         useHighlightButtons(true);
67     }
68
69     /**
70      * Enable or disable highlight buttons This setting has no effect on OSX
71      *
72      * @param useit flag which determines the behavior
73      */

74     public static void useHighlightButtons(boolean useit)
75     {
76         if (System.getProperty("mrj.version") == null)
77         {
78             useHighlightButtons = useit;
79         }
80         useButtonIcons(useit);
81     }
82
83     public static JButton JavaDoc createButton(Icon JavaDoc icon, Color JavaDoc color)
84     {
85         if (useHighlightButtons)
86         {
87             if (useButtonIcons)
88                 return new HighlightJButton(icon, color);
89             else
90                 return new HighlightJButton("", color);
91
92         }
93         else
94         {
95             if (useButtonIcons)
96             {
97                 return new JButton JavaDoc(icon);
98             }
99             else
100             {
101                 return new JButton JavaDoc();
102             }
103         }
104     }
105
106     public static JButton JavaDoc createButton(String JavaDoc text, Color JavaDoc color)
107     {
108         if (useHighlightButtons)
109         {
110             return new HighlightJButton(text, color);
111         }
112         else
113         {
114             return new JButton JavaDoc(text);
115         }
116     }
117
118     public static JButton JavaDoc createButton(String JavaDoc text, Icon JavaDoc icon, Color JavaDoc color)
119     {
120         if (useHighlightButtons)
121         {
122             if (useButtonIcons)
123                 return new HighlightJButton(text, icon, color);
124             else
125                 return new HighlightJButton(text, color);
126         }
127         else
128         {
129             if (useButtonIcons)
130             {
131                 return new JButton JavaDoc(text, icon);
132             }
133             else
134             {
135                 return new JButton JavaDoc(text);
136             }
137         }
138     }
139
140     public static JButton JavaDoc createButton(Action JavaDoc a, Color JavaDoc color)
141     {
142         if (useHighlightButtons)
143         {
144             return new HighlightJButton(a, color);
145         }
146         else
147         {
148             return new JButton JavaDoc(a);
149         }
150     }
151
152 }
153
Popular Tags