01: /*
02: * @(#)XPUtils.java
03: *
04: * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
05: */
06: package com.jidesoft.plaf;
07:
08: import com.jidesoft.utils.SystemInfo;
09:
10: import java.awt.*;
11:
12: /**
13: * Util class for XP style.
14: */
15: public class XPUtils {
16: public static final String PROPERTY_THEMEACTIVE = "win.xpstyle.themeActive";
17: public static final String PROPERTY_COLORNAME = "win.xpstyle.colorName";
18: public static final String PROPERTY_DLLNAME = "win.xpstyle.dllName";
19: public static final String DEFAULT = "Default";
20: public static final String GRAY = "Gray";
21: public static final String BLUE = "NormalColor";
22: public static final String HOMESTEAD = "HomeStead";
23: public static final String METALLIC = "Metallic";
24:
25: /**
26: * Checks if the XP style is on. Even on Windows XP OS, user can choose Classic style
27: * or XP style. This method will tell you if XP style is on.
28: * <p/>
29: * Please note it will return the correct value only if it's
30: * jdk1.4.2 and above. Otherwise it will throw UnsupportedOperationException.
31: *
32: * @return true if XP style in on.
33: * @throws UnsupportedOperationException if jdk version is not 1.4.2 or above.
34: */
35: public static boolean isXPStyleOn()
36: throws UnsupportedOperationException {
37: if (SystemInfo.isJdk142Above()) {
38: Toolkit toolkit = Toolkit.getDefaultToolkit();
39: return Boolean.TRUE.equals(toolkit
40: .getDesktopProperty(PROPERTY_THEMEACTIVE));
41: } else {
42: throw new UnsupportedOperationException(
43: "JDK 1.4.2 and up is required to support this method call.");
44: }
45: }
46:
47: /**
48: * Gets the color name. On Windows XP, it could be one of the values BLUE, HOMESTEAD or METALLIC. If XP style is not on
49: * or the system is not Windows XP at all, it will return null.
50: * <p/>
51: * Please note it will return the correct value only if it's
52: * jdk1.4.2 and above. Otherwise it will throw UnsupportedOperationException.
53: *
54: * @return the color name of XP theme.
55: * @throws UnsupportedOperationException if jdk version is not 1.4.2 or above.
56: */
57: public static String getColorName()
58: throws UnsupportedOperationException {
59: if (SystemInfo.isJdk142Above()) {
60: Toolkit toolkit = Toolkit.getDefaultToolkit();
61: return (String) toolkit
62: .getDesktopProperty(PROPERTY_COLORNAME);
63: } else {
64: throw new UnsupportedOperationException(
65: "JDK 1.4.2 and up is required to support this method call.");
66: }
67: }
68:
69: private static String getXPStyleDll() {
70: Toolkit toolkit = Toolkit.getDefaultToolkit();
71: return (String) toolkit.getDesktopProperty(PROPERTY_DLLNAME);
72: }
73:
74: public static void main(String[] args) {
75: try {
76: System.out.println(XPUtils.isXPStyleOn());
77: } catch (UnsupportedOperationException e) {
78: System.out.println("Unknown XP style because "
79: + e.getMessage());
80: }
81: try {
82: System.out.println(XPUtils.getColorName());
83: } catch (UnsupportedOperationException e) {
84: System.out.println("Unknown XP color because "
85: + e.getMessage());
86: }
87: System.out.println(XPUtils.getXPStyleDll());
88: }
89: }
|