KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > plastic > PlasticTheme


1 /*
2  * Copyright (c) 2001-2005 JGoodies Karsten Lentzsch. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * o Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * o Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * o Neither the name of JGoodies Karsten Lentzsch nor the names of
15  * its contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
22  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package com.jgoodies.looks.plastic;
32
33 import java.awt.Color JavaDoc;
34 import java.awt.Font JavaDoc;
35
36 import javax.swing.plaf.ColorUIResource JavaDoc;
37 import javax.swing.plaf.FontUIResource JavaDoc;
38 import javax.swing.plaf.metal.DefaultMetalTheme JavaDoc;
39
40 /**
41  * Unlike its superclass this theme class has relaxed access.
42  *
43  * @author Karsten Lentzsch
44  * @version $Revision: 1.3 $
45  */

46 public abstract class PlasticTheme extends DefaultMetalTheme JavaDoc {
47
48     // Default 3D Effect Colors *********************************************
49

50     public static final Color JavaDoc DARKEN_START = new Color JavaDoc(0, 0, 0, 0);
51     public static final Color JavaDoc DARKEN_STOP = new Color JavaDoc(0, 0, 0, 64);
52     public static final Color JavaDoc LT_DARKEN_STOP = new Color JavaDoc(0, 0, 0, 32);
53     public static final Color JavaDoc BRIGHTEN_START = new Color JavaDoc(255, 255, 255, 0);
54     public static final Color JavaDoc BRIGHTEN_STOP = new Color JavaDoc(255, 255, 255, 128);
55     public static final Color JavaDoc LT_BRIGHTEN_STOP = new Color JavaDoc(255, 255, 255, 64);
56
57     protected static final ColorUIResource JavaDoc WHITE =
58         new ColorUIResource JavaDoc(255, 255, 255);
59
60     protected static final ColorUIResource JavaDoc BLACK = new ColorUIResource JavaDoc(0, 0, 0);
61
62     protected FontUIResource JavaDoc titleFont;
63     protected FontUIResource JavaDoc controlFont;
64     protected FontUIResource JavaDoc systemFont;
65     protected FontUIResource JavaDoc userFont;
66     protected FontUIResource JavaDoc smallFont;
67
68     // Accessing Colors *****************************************************
69

70     protected ColorUIResource JavaDoc getBlack() {
71         return BLACK;
72     }
73
74     protected ColorUIResource JavaDoc getWhite() {
75         return WHITE;
76     }
77
78     public ColorUIResource JavaDoc getSystemTextColor() {
79         return getControlInfo();
80     }
81
82     public ColorUIResource JavaDoc getTitleTextColor() {
83         return getPrimary1();
84     }
85
86     public ColorUIResource JavaDoc getMenuForeground() {
87         return getControlInfo();
88     }
89
90     public ColorUIResource JavaDoc getMenuItemBackground() {
91         return getMenuBackground();
92     }
93     
94     public ColorUIResource JavaDoc getMenuItemSelectedBackground() {
95         return getMenuSelectedBackground();
96     }
97
98     public ColorUIResource JavaDoc getMenuItemSelectedForeground() {
99         return getMenuSelectedForeground();
100     }
101
102     public ColorUIResource JavaDoc getSimpleInternalFrameForeground() {
103         return getWhite();
104     }
105
106     public ColorUIResource JavaDoc getSimpleInternalFrameBackground() {
107         return getPrimary1();
108     }
109
110     public ColorUIResource JavaDoc getToggleButtonCheckColor() {
111         return getPrimary1();
112     }
113
114     // Accessing Fonts ******************************************************
115

116     public FontUIResource JavaDoc getTitleTextFont() {
117 // return getControlTextFont();
118

119         if (titleFont == null) {
120             titleFont =
121                 new FontUIResource JavaDoc(
122                     Font.getFont(
123                         "swing.plaf.metal.controlFont",
124                         new Font JavaDoc("Dialog", Font.BOLD, 12)));
125         }
126         return titleFont;
127     }
128
129     public FontUIResource JavaDoc getControlTextFont() {
130         return getFont();
131     }
132     
133     public FontUIResource JavaDoc getMenuTextFont() {
134         return getFont();
135     }
136     
137     public FontUIResource JavaDoc getSubTextFont() {
138         if (smallFont == null) {
139             smallFont =
140                 new FontUIResource JavaDoc(
141                     Font.getFont(
142                         "swing.plaf.metal.smallFont",
143                         new Font JavaDoc("Dialog", Font.PLAIN, 10)));
144         }
145         return smallFont;
146     }
147
148     public FontUIResource JavaDoc getSystemTextFont() {
149         if (systemFont == null) {
150             systemFont =
151                 new FontUIResource JavaDoc(
152                     Font.getFont(
153                         "swing.plaf.metal.systemFont",
154                         new Font JavaDoc("Dialog", Font.PLAIN, 12)));
155         }
156         return systemFont;
157     }
158
159     public FontUIResource JavaDoc getUserTextFont() {
160         if (userFont == null) {
161             userFont =
162                 new FontUIResource JavaDoc(
163                     Font.getFont(
164                         "swing.plaf.metal.userFont",
165                         new Font JavaDoc("Dialog", Font.PLAIN, 12)));
166         }
167         return userFont;
168     }
169
170     public FontUIResource JavaDoc getWindowTitleFont() {
171         return getFont();
172     }
173     
174
175     // Helper Code **********************************************************
176

177     protected FontUIResource JavaDoc getFont() {
178         if (null == controlFont)
179             controlFont = new FontUIResource JavaDoc(getFont0());
180
181         return controlFont;
182     }
183
184     protected Font JavaDoc getFont0() {
185         Font JavaDoc font = Font.getFont("swing.plaf.metal.controlFont");
186         return font != null
187             ? font.deriveFont(Font.PLAIN)
188             : new Font JavaDoc("Dialog", Font.PLAIN, 12);
189     }
190     
191     
192     // Custom Equals Implementation *****************************************
193

194     /**
195      * Plastic themes are equal if and only if their classes are the same.
196      *
197      * @return true if this theme is equal to the given object
198      */

199     public boolean equals(Object JavaDoc o) {
200         if (this == o)
201             return true;
202         if (o == null)
203             return false;
204         return getClass().equals(o.getClass());
205     }
206
207     
208     /**
209      * Returns this theme's hash code, the classes' hash code.
210      *
211      * @return this theme's hash code
212      */

213     public int hashCode() {
214         return getClass().hashCode();
215     }
216     
217
218 }
Popular Tags