KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jgoodies > looks > FontSizeHints


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;
32
33 /**
34  * Describes font size hints used by the JGoodies Windows look&feel;
35  * future implementations of the Plastic l&amp;f may use the same hints.<p>
36  *
37  * These hints are only applied if the dialog font is <em>Tahoma</em>,
38  * which is the default font on the majority of Windows desktops.
39  * The hints apply a size delta to increase or decrease the given
40  * system font size.<p>
41  *
42  * NOTE: This is work in progress and will probably change in the
43  * next release, to better reflect the font choice in the J2SE 1.4.".
44  *
45  * @author Karsten Lentzsch
46  * @version $Revision: 1.2 $
47  *
48  * @see Options#setGlobalFontSizeHints(FontSizeHints)
49  * @see FontUtils
50  */

51 public final class FontSizeHints {
52     
53     public static final FontSizeHints LARGE = new FontSizeHints(12, 12, 14, 14);
54     public static final FontSizeHints SYSTEM = new FontSizeHints(11, 11, 14, 14);
55     public static final FontSizeHints MIXED2 = new FontSizeHints(11, 11, 14, 13);
56     public static final FontSizeHints MIXED = new FontSizeHints(11, 11, 14, 12);
57     public static final FontSizeHints SMALL = new FontSizeHints(11, 11, 12, 12);
58     public static final FontSizeHints FIXED = new FontSizeHints(12, 12, 12, 12);
59     
60     public static final FontSizeHints DEFAULT = SYSTEM;
61     
62     
63     private final int loResMenuFontSize;
64     private final int loResControlFontSize;
65     private final int hiResMenuFontSize;
66     private final int hiResControlFontSize;
67     
68     
69     /**
70      * Constructs <code>FontSizeHints</code> for the specified menu and
71      * control fonts, both for low and high resolution environments.
72      *
73      * @param loResMenuFontSize the size of the menu font in low resolution
74      * @param loResControlFontSize the size of the control font in low resolution
75      * @param hiResMenuFontSize the size of the menu font in low resolution
76      * @param hiResControlFontSize the size of the control font in low resolution
77      */

78     public FontSizeHints(int loResMenuFontSize, int loResControlFontSize,
79                           int hiResMenuFontSize, int hiResControlFontSize) {
80         this.loResMenuFontSize = loResMenuFontSize;
81         this.loResControlFontSize = loResControlFontSize;
82         this.hiResMenuFontSize = hiResMenuFontSize;
83         this.hiResControlFontSize = hiResControlFontSize;
84     }
85     
86     
87     /**
88      * Returns the low resolution menu font size.
89      *
90      * @return the size of the menu font in low resolution mode
91      */

92     public int loResMenuFontSize() { return loResMenuFontSize; }
93
94
95     /**
96      * Returns the low resolution control font size.
97      *
98      * @return the size of the control font in low resolution mode
99      */

100     public int loResControlFontSize() { return loResControlFontSize; }
101
102
103     /**
104      * Returns the high resolution menu font size.
105      *
106      * @return the size of the menu font in high resolution mode
107      */

108     public int hiResMenuFontSize() { return hiResMenuFontSize; }
109
110
111     /**
112      * Returns the high resolution control font size.
113      *
114      * @return the size of the control font in high resolution mode
115      */

116     public int hiResControlFontSize() { return hiResControlFontSize; }
117     
118     
119     /**
120      * Returns the menu font size.
121      *
122      * @return the size of the menu font in the current resolution
123      */

124     public int menuFontSize() {
125         return LookUtils.IS_LOW_RESOLUTION ? loResMenuFontSize : hiResMenuFontSize();
126     }
127     
128     
129     /**
130      * Returns the control font size.
131      *
132      * @return the size of the control font in the current resolution
133      */

134     public int controlFontSize() {
135         return LookUtils.IS_LOW_RESOLUTION ? loResControlFontSize : hiResControlFontSize();
136     }
137     
138     
139     /**
140      * Returns the delta between the system menu font size and
141      * our menu font size hint.
142      *
143      * @return the delta between the system menu font size and
144      * our menu font size hint
145      */

146     public float menuFontSizeDelta() {
147         return menuFontSize() - SYSTEM.menuFontSize();
148     }
149     
150     
151     /**
152      * Returns the delta between system control font size and
153      * our control font size hint.
154      *
155      * @return the delta between the system control font size and
156      * our control font size hint
157      */

158     public float controlFontSizeDelta() {
159         return controlFontSize() - SYSTEM.controlFontSize();
160     }
161     
162     
163     
164     /**
165      * Looksup and returns the <code>FontSizeHints</code> for the specified name.
166      *
167      * @param name the name of the FontSizeHints object
168      * @return the associated FontSizeHints object
169      */

170     public static FontSizeHints valueOf(String JavaDoc name) {
171         if (name.equalsIgnoreCase("LARGE"))
172             return LARGE;
173         else if (name.equalsIgnoreCase("SYSTEM"))
174             return SYSTEM;
175         else if (name.equalsIgnoreCase("MIXED"))
176             return MIXED;
177         else if (name.equalsIgnoreCase("SMALL"))
178             return SMALL;
179         else if (name.equalsIgnoreCase("FIXED"))
180             return FIXED;
181         else
182             throw new IllegalArgumentException JavaDoc("Unknown font size hints name: " + name);
183     }
184 }
Popular Tags