src/windows/classes/sun/awt/windows/ThemeReader.java

Print this page




  44 
  45 /**
  46  * Implements Theme Support for Windows XP.
  47  *
  48  * @author Sergey Salishev
  49  * @author Bino George
  50  * @author Igor Kushnirskiy
  51  */
  52 public final class ThemeReader {
  53 
  54     private static final Map<String, Long> widgetToTheme = new HashMap<>();
  55 
  56     // lock for the cache
  57     // reading should be done with readLock
  58     // writing with writeLock
  59     private static final ReadWriteLock readWriteLock =
  60         new ReentrantReadWriteLock();
  61     private static final Lock readLock = readWriteLock.readLock();
  62     private static final Lock writeLock = readWriteLock.writeLock();
  63 


  64     static void flush() {
  65         writeLock.lock();
  66         try {
  67             // Close old themes.
  68             for (Long value : widgetToTheme.values()) {
  69                 closeTheme(value.longValue());
  70             }
  71             widgetToTheme.clear();
  72         } finally {
  73             writeLock.unlock();
  74         }
  75     }
  76 
  77     public static native boolean isThemed();




  78 
  79     // this should be called only with writeLock held
  80     private static Long getThemeImpl(String widget) {
  81         Long theme = widgetToTheme.get(widget);
  82         if (theme == null) {
  83             int i = widget.indexOf("::");
  84             if (i > 0) {
  85                 // We're using the syntax "subAppName::controlName" here, as used by msstyles.
  86                 // See documentation for SetWindowTheme on MSDN.
  87                 setWindowTheme(widget.substring(0, i));
  88                 theme = openTheme(widget.substring(i+2));
  89                 setWindowTheme(null);
  90             } else {
  91                 theme = openTheme(widget);
  92             }
  93             widgetToTheme.put(widget, theme);
  94         }
  95         return theme;
  96     }
  97 




  44 
  45 /**
  46  * Implements Theme Support for Windows XP.
  47  *
  48  * @author Sergey Salishev
  49  * @author Bino George
  50  * @author Igor Kushnirskiy
  51  */
  52 public final class ThemeReader {
  53 
  54     private static final Map<String, Long> widgetToTheme = new HashMap<>();
  55 
  56     // lock for the cache
  57     // reading should be done with readLock
  58     // writing with writeLock
  59     private static final ReadWriteLock readWriteLock =
  60         new ReentrantReadWriteLock();
  61     private static final Lock readLock = readWriteLock.readLock();
  62     private static final Lock writeLock = readWriteLock.writeLock();
  63 
  64     static volatile boolean xpStyleEnabled;
  65 
  66     static void flush() {
  67         writeLock.lock();
  68         try {
  69             // Close old themes.
  70             for (Long value : widgetToTheme.values()) {
  71                 closeTheme(value.longValue());
  72             }
  73             widgetToTheme.clear();
  74         } finally {
  75             writeLock.unlock();
  76         }
  77     }
  78 
  79     public static native boolean isThemed();
  80 
  81     public static boolean isXPStyleEnabled() {
  82         return xpStyleEnabled;
  83     }
  84 
  85     // this should be called only with writeLock held
  86     private static Long getThemeImpl(String widget) {
  87         Long theme = widgetToTheme.get(widget);
  88         if (theme == null) {
  89             int i = widget.indexOf("::");
  90             if (i > 0) {
  91                 // We're using the syntax "subAppName::controlName" here, as used by msstyles.
  92                 // See documentation for SetWindowTheme on MSDN.
  93                 setWindowTheme(widget.substring(0, i));
  94                 theme = openTheme(widget.substring(i+2));
  95                 setWindowTheme(null);
  96             } else {
  97                 theme = openTheme(widget);
  98             }
  99             widgetToTheme.put(widget, theme);
 100         }
 101         return theme;
 102     }
 103