001: /*
002: * Options.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.plaf.smoothgradient;
023:
024: import java.awt.Dimension; //import java.util.HashMap;
025: //import java.util.Map;
026:
027: import javax.swing.UIManager;
028:
029: //import com.jgoodies.clearlook.ClearLookMode;
030:
031: /* ----------------------------------------------------------
032: * CVS NOTE: Changes to the CVS repository prior to the
033: * release of version 3.0.0beta1 has meant a
034: * resetting of CVS revision numbers.
035: * ----------------------------------------------------------
036: */
037:
038: /**
039: * Provides access to several optional properties for the
040: * JGoodies L&Fs, either by a key to the <code>UIDefaults</code> table
041: * or via a method or both.
042: *
043: * @author Karsten Lentzsch
044: * @author Takis Diakoumis
045: * @version $Revision: 1.4 $
046: * @date $Date: 2006/05/14 06:56:07 $
047: */
048:
049: public final class Options {
050:
051: // Look & Feel Names ****************************************************
052: /*
053: public static final String EXT_MOTIF_NAME =
054: "com.jgoodies.plaf.motif.ExtMotifLookAndFeel";
055:
056: public static final String PLASTIC_NAME =
057: "com.jgoodies.plaf.plastic.PlasticLookAndFeel";
058:
059: public static final String PLASTIC3D_NAME =
060: "com.jgoodies.plaf.plastic.Plastic3DLookAndFeel";
061:
062: public static final String PLASTICXP_NAME =
063: "com.jgoodies.plaf.plastic.PlasticXPLookAndFeel";
064:
065: public static final String EXT_WINDOWS_NAME =
066: "com.jgoodies.plaf.windows.ExtWindowsLookAndFeel";
067:
068: public static final String DEFAULT_LOOK_NAME =
069: PLASTIC3D_NAME;
070: */
071: /**
072: * Holds a <code>Map</code> that enables the look&feel replacement
073: * mechanism to replace one look by another.
074: * Maps the original class names to their replacement class names.
075: */
076: /*
077: private static final Map LAF_REPLACEMENTS;
078: static {
079: LAF_REPLACEMENTS = new HashMap();
080: initializeDefaultReplacements();
081: }
082: */
083:
084: // Keys for Overriding Font Settings ************************************
085: /* public static final String MENU_FONT_KEY =
086: "jgoodies.menuFont";
087:
088: public static final String CONTROL_FONT_KEY =
089: "jgoodies.controlFont";
090: */
091: public static final String FONT_SIZE_HINTS_KEY = "jgoodies.fontSizeHints";
092:
093: public static final String USE_SYSTEM_FONTS_KEY = "swing.useSystemFontSettings";
094:
095: public static final String USE_SYSTEM_FONTS_APP_KEY = "Application.useSystemFontSettings";
096:
097: // Optional Global User Properties **************************************
098:
099: public static final String DEFAULT_ICON_SIZE_KEY = "jgoodies.defaultIconSize";
100: /*
101: public static final String USE_NARROW_BUTTONS_KEY =
102: "jgoodies.useNarrowButtons";
103:
104: public static final String TAB_ICONS_ENABLED_KEY =
105: "jgoodies.tabIconsEnabled";
106:
107:
108: // ClearLook Properties *************************************************
109:
110: public static final String CLEAR_LOOK_MODE_KEY =
111: "ClearLook.mode";
112:
113: public static final String CLEAR_LOOK_POLICY_KEY =
114: "ClearLook.policy";
115:
116: public static final String CLEAR_LOOK_OFF =
117: ClearLookMode.OFF.getName();
118:
119: public static final String CLEAR_LOOK_ON =
120: ClearLookMode.ON.getName();
121:
122: public static final String CLEAR_LOOK_VERBOSE =
123: ClearLookMode.VERBOSE.getName();
124:
125: public static final String CLEAR_LOOK_DEBUG =
126: ClearLookMode.DEBUG.getName();
127: */
128:
129: // Optional Client Properties *******************************************
130: /**
131: * Hint that the button margin should be narrow.
132: */
133: public static final String IS_NARROW_KEY = "jgoodies.isNarrow";
134:
135: /**
136: * Hint that the scroll pane border should be etched.
137: */
138: public static final String IS_ETCHED_KEY = "jgoodies.isEtched";
139:
140: /**
141: * Hint for the style: Single or Both, see <code>HeaderStyle</code>.
142: */
143: public static final String HEADER_STYLE_KEY = "jgoodies.headerStyle";
144:
145: /**
146: * Hint that the menu items in the menu have no icons.
147: */
148: public static final String NO_ICONS_KEY = "jgoodies.noIcons";
149:
150: /**
151: * A client property key for <code>JTree</code>s.
152: * Used with the angled and none style values.
153: */
154: public static final String TREE_LINE_STYLE_KEY = "JTree.lineStyle";
155:
156: /**
157: * A client property value for <code>JTree</code>s
158: * that indicates that lines shall be drawn.
159: */
160: public static final String TREE_LINE_STYLE_ANGLED_VALUE = "Angled";
161:
162: /**
163: * A client property value for <code>JTree</code>s
164: * that indicates that lines shall be hidden.
165: */
166: public static final String TREE_LINE_STYLE_NONE_VALUE = "None";
167:
168: /**
169: * A client property key for <code>JTabbedPane</code>s that indicates
170: * that no content border shall be painted.
171: * Supported by the Plastic look and feel family.
172: * This effect will be achieved also if the EMBEDDED property is true.
173: */
174: public static final String NO_CONTENT_BORDER_KEY = "jgoodies.noContentBorder";
175:
176: /**
177: * A client property key for <code>JTabbedPane</code>s that indicates
178: * that tabs are painted with a special embedded appearance.
179: * Supported by the Plastic look and feel family.
180: * This effect will be achieved also if the EMBEDDED property is true.
181: */
182: public static final String EMBEDDED_TABS_KEY = "jgoodies.embeddedTabs";
183:
184: // Private ****************************************************************
185:
186: private static final Dimension DEFAULT_ICON_SIZE = new Dimension(
187: 20, 20);
188:
189: // Override default constructor;
190: private Options() {
191: }
192:
193: // Accessing Options ******************************************************
194:
195: /**
196: * Answers whether a hint is set in the <code>UIManager</code>
197: * that indicates, that a look&feel may use the native system fonts.
198: */
199: public static boolean getUseSystemFonts() {
200: return UIManager.get(USE_SYSTEM_FONTS_APP_KEY).equals(
201: Boolean.TRUE);
202: }
203:
204: /**
205: * Sets a value in the <code>UIManager</code> to indicate,
206: * that a look&feel may use the native system fonts.
207: */
208: public static void setUseSystemFonts(boolean useSystemFonts) {
209: UIManager.put(USE_SYSTEM_FONTS_APP_KEY, new Boolean(
210: useSystemFonts));
211: }
212:
213: /**
214: * Answers the default icon size.
215: */
216: public static Dimension getDefaultIconSize() {
217: Dimension size = UIManager.getDimension(DEFAULT_ICON_SIZE_KEY);
218: return size == null ? DEFAULT_ICON_SIZE : size;
219: }
220:
221: /**
222: * Sets the default icon size.
223: */
224: public static void setDefaultIconSize(Dimension defaultIconSize) {
225: UIManager.put(DEFAULT_ICON_SIZE_KEY, defaultIconSize);
226: }
227:
228: /**
229: * Answers the global <code>FontSizeHints</code>, can be overriden
230: * by look specific setting.
231: */
232: public static FontSizeHints getGlobalFontSizeHints() {
233: Object value = UIManager.get(FONT_SIZE_HINTS_KEY);
234: if (value != null)
235: return (FontSizeHints) value;
236:
237: String name = SmoothGradientLookUtils.getSystemProperty(
238: FONT_SIZE_HINTS_KEY, "");
239: try {
240: return FontSizeHints.valueOf(name);
241: } catch (IllegalArgumentException e) {
242: return FontSizeHints.DEFAULT;
243: }
244: }
245:
246: /**
247: * Sets the global <code>FontSizeHints</code>.
248: */
249: public static void setGlobalFontSizeHints(FontSizeHints hints) {
250: UIManager.put(FONT_SIZE_HINTS_KEY, hints);
251: }
252:
253: /**
254: * Checks and answers if we shall use narrow button margins of 4 pixels.
255: * Sun's L&F implementations use a much wider button margin of 14 pixels,
256: * which leads to good button minimum width in the typical case.<p>
257: *
258: * Using narrow button margins can potentially cause compatibility issues,
259: * so this feature must be switched on programmatically.<p>
260: *
261: * If you use narrow margin, you should take care of minimum button width,
262: * either by the layout management or appropriate ButtonUI minimum widths.
263: */
264: /*
265: public static boolean getUseNarrowButtons() {
266: Object value = UIManager.get(USE_NARROW_BUTTONS_KEY);
267: return Boolean.TRUE.equals(value);
268: }
269: */
270: /**
271: * Sets if we use narrow or standard button margins.
272: *
273: * @see #getUseNarrowButtons
274: */
275: /*
276: public static void setUseNarrowButtons(boolean b) {
277: UIManager.put(USE_NARROW_BUTTONS_KEY, new Boolean(b));
278: }
279: */
280: /**
281: * Detects and answers if we shall use icons in <code>JTabbedPanes</code>.
282: * This has an effect only inside NetBeans, it will answer 'yes'
283: * if we are outside NetBeans.<p>
284: *
285: * If the user has set a system property, we log a message
286: * about the choosen style.
287: */
288: /*
289: public static boolean isTabIconsEnabled() {
290: // if (!LookUtils.IS_NETBEANS)
291: // return true;
292:
293: String userMode = LookUtils.getSystemProperty(TAB_ICONS_ENABLED_KEY, "");
294: boolean overridden = userMode.length() > 0;
295: Object value =
296: overridden ? userMode : UIManager.get(TAB_ICONS_ENABLED_KEY);
297:
298: boolean result =
299: overridden
300: ? userMode.equalsIgnoreCase("true")
301: : value instanceof Boolean
302: && Boolean.TRUE.equals(value);
303:
304: if (overridden) {
305: LookUtils.log(
306: "You have "
307: + (result ? "en" : "dis")
308: + "abled icons in tabbed panes.");
309: }
310: return result;
311: }
312: */
313: /**
314: * Enables or disables the use of icons in <code>JTabbedPane</code>s.
315: *
316: * @see #isTabIconsEnabled
317: */
318: /*
319: public static void setTabIconsEnabled(boolean b) {
320: UIManager.put(TAB_ICONS_ENABLED_KEY, new Boolean(b));
321: }
322: */
323: // Look And Feel Replacements *******************************************
324: /**
325: * Puts a replacement name for a given <code>LookAndFeel</code>
326: * class name in the list of all look and feel replacements.
327: */
328: /*
329: public static void putLookAndFeelReplacement(
330: String original,
331: String replacement) {
332: LAF_REPLACEMENTS.put(original, replacement);
333: }
334: */
335: /**
336: * Removes a replacement name for a given <code>LookAndFeel</code>
337: * class name from the list of all look and feel replacements.
338: */
339: /*
340: public static void removeLookAndFeelReplacement(String original) {
341: LAF_REPLACEMENTS.remove(original);
342: }
343: */
344: /**
345: * Initializes some default class name replacements, that replace
346: * Sun's Java look and feel, and Sun's Windows look and feel by
347: * the appropriate JGoodies replacements.
348: */
349: /*
350: public static void initializeDefaultReplacements() {
351: putLookAndFeelReplacement(
352: "javax.swing.plaf.metal.MetalLookAndFeel",
353: PLASTIC3D_NAME);
354: putLookAndFeelReplacement(
355: "com.sun.java.swing.plaf.windows.WindowsLookAndFeel",
356: EXT_WINDOWS_NAME);
357: putLookAndFeelReplacement(
358: "com.sun.java.swing.plaf.motif.MotifLookAndFeel",
359: EXT_MOTIF_NAME);
360: }
361: */
362: /**
363: * Answers the class name that can be used to replace the specified
364: * <code>LookAndFeel</code> class name.
365: */
366: /*
367: public static String getReplacementClassNameFor(String className) {
368: String replacement = (String) LAF_REPLACEMENTS.get(className);
369: return replacement == null ? className : replacement;
370: }
371: */
372: /**
373: * Answers the class name for a cross-platform <code>LookAndFeel</code>.
374: */
375: /*
376: public static String getCrossPlatformLookAndFeelClassName() {
377: return PLASTIC3D_NAME;
378: }
379: */
380: /**
381: * Answers the class name for a system specific <code>LookAndFeel</code>.
382: */
383: /*
384: public static String getSystemLookAndFeelClassName() {
385: String osName = System.getProperty("os.name");
386: if (osName.startsWith("Windows"))
387: return Options.EXT_WINDOWS_NAME;
388: else if (osName.startsWith("Mac"))
389: return UIManager.getSystemLookAndFeelClassName();
390: else
391: return getCrossPlatformLookAndFeelClassName();
392: }
393: */
394: }
|