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

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.windows;
  27 
  28 import java.awt.Color;
  29 import java.awt.Dimension;
  30 import java.awt.Insets;
  31 import java.awt.Point;
  32 import java.util.HashMap;
  33 import java.util.Map;

  34 import java.util.concurrent.locks.Lock;
  35 import java.util.concurrent.locks.ReadWriteLock;
  36 import java.util.concurrent.locks.ReentrantReadWriteLock;
  37 
  38 /* !!!! WARNING !!!!
  39  * This class has to be in sync with
  40  * src/solaris/classes/sun/awt/windows/ThemeReader.java
  41  * while we continue to build WinL&F on solaris
  42  */
  43 
  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("::");


 102         Long theme = widgetToTheme.get(widget);
 103         if (theme == null) {
 104             readLock.unlock();
 105             writeLock.lock();
 106             try {
 107                 theme = getThemeImpl(widget);
 108             } finally {
 109                 readLock.lock();
 110                 writeLock.unlock();// Unlock write, still hold read
 111             }
 112         }
 113         return theme;
 114     }
 115 
 116     private static native void paintBackground(int[] buffer, long theme,
 117                                                int part, int state, int x,
 118                                                int y, int w, int h, int stride);
 119 
 120     public static void paintBackground(int[] buffer, String widget,
 121            int part, int state, int x, int y, int w, int h, int stride) {



 122         readLock.lock();
 123         try {
 124             paintBackground(buffer, getTheme(widget), part, state, x, y, w, h, stride);
 125         } finally {
 126             readLock.unlock();
 127         }
 128     }
 129 
 130     private static native Insets getThemeMargins(long theme, int part,
 131                                                  int state, int marginType);
 132 
 133     public static Insets getThemeMargins(String widget, int part, int state, int marginType) {
 134         readLock.lock();
 135         try {
 136             return getThemeMargins(getTheme(widget), part, state, marginType);
 137         } finally {
 138             readLock.unlock();
 139         }
 140     }
 141 
 142     private static native boolean isThemePartDefined(long theme, int part, int state);
 143 
 144     public static boolean isThemePartDefined(String widget, int part, int state) {



 145         readLock.lock();
 146         try {
 147             return isThemePartDefined(getTheme(widget), part, state);
 148         } finally {
 149             readLock.unlock();
 150         }
 151     }
 152 
 153     private static native Color getColor(long theme, int part, int state,
 154                                          int property);
 155 
 156     public static Color getColor(String widget, int part, int state, int property) {
 157         readLock.lock();
 158         try {
 159             return getColor(getTheme(widget), part, state, property);
 160         } finally {
 161             readLock.unlock();
 162         }
 163     }
 164 




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package sun.awt.windows;
  27 
  28 import java.awt.Color;
  29 import java.awt.Dimension;
  30 import java.awt.Insets;
  31 import java.awt.Point;
  32 import java.util.HashMap;
  33 import java.util.Map;
  34 import java.util.concurrent.atomic.AtomicBoolean;
  35 import java.util.concurrent.locks.Lock;
  36 import java.util.concurrent.locks.ReadWriteLock;
  37 import java.util.concurrent.locks.ReentrantReadWriteLock;
  38 
  39 /* !!!! WARNING !!!!
  40  * This class has to be in sync with
  41  * src/solaris/classes/sun/awt/windows/ThemeReader.java
  42  * while we continue to build WinL&F on solaris
  43  */
  44 
  45 
  46 /**
  47  * Implements Theme Support for Windows XP.
  48  *
  49  * @author Sergey Salishev
  50  * @author Bino George
  51  * @author Igor Kushnirskiy
  52  */
  53 public final class ThemeReader {
  54 
  55     private static final Map<String, Long> widgetToTheme = new HashMap<>();
  56 
  57     // lock for the cache
  58     // reading should be done with readLock
  59     // writing with writeLock
  60     private static final ReadWriteLock readWriteLock =
  61         new ReentrantReadWriteLock();
  62     private static final Lock readLock = readWriteLock.readLock();
  63     private static final Lock writeLock = readWriteLock.writeLock();
  64 
  65     private static final AtomicBoolean themeEnabled = WToolkit.getWToolkit().getXPStyleEnabled();
  66 
  67     static void flush() {
  68         writeLock.lock();
  69         try {
  70             // Close old themes.
  71             for (Long value : widgetToTheme.values()) {
  72                 closeTheme(value.longValue());
  73             }
  74             widgetToTheme.clear();
  75         } finally {
  76             writeLock.unlock();
  77         }
  78     }
  79 
  80     public static native boolean isThemed();
  81 
  82     // this should be called only with writeLock held
  83     private static Long getThemeImpl(String widget) {
  84         Long theme = widgetToTheme.get(widget);
  85         if (theme == null) {
  86             int i = widget.indexOf("::");


 105         Long theme = widgetToTheme.get(widget);
 106         if (theme == null) {
 107             readLock.unlock();
 108             writeLock.lock();
 109             try {
 110                 theme = getThemeImpl(widget);
 111             } finally {
 112                 readLock.lock();
 113                 writeLock.unlock();// Unlock write, still hold read
 114             }
 115         }
 116         return theme;
 117     }
 118 
 119     private static native void paintBackground(int[] buffer, long theme,
 120                                                int part, int state, int x,
 121                                                int y, int w, int h, int stride);
 122 
 123     public static void paintBackground(int[] buffer, String widget,
 124            int part, int state, int x, int y, int w, int h, int stride) {
 125         if (!themeEnabled.get()) {
 126             return;
 127         }
 128         readLock.lock();
 129         try {
 130             paintBackground(buffer, getTheme(widget), part, state, x, y, w, h, stride);
 131         } finally {
 132             readLock.unlock();
 133         }
 134     }
 135 
 136     private static native Insets getThemeMargins(long theme, int part,
 137                                                  int state, int marginType);
 138 
 139     public static Insets getThemeMargins(String widget, int part, int state, int marginType) {
 140         readLock.lock();
 141         try {
 142             return getThemeMargins(getTheme(widget), part, state, marginType);
 143         } finally {
 144             readLock.unlock();
 145         }
 146     }
 147 
 148     private static native boolean isThemePartDefined(long theme, int part, int state);
 149 
 150     public static boolean isThemePartDefined(String widget, int part, int state) {
 151         if (!themeEnabled.get()) {
 152             return false;
 153         }
 154         readLock.lock();
 155         try {
 156             return isThemePartDefined(getTheme(widget), part, state);
 157         } finally {
 158             readLock.unlock();
 159         }
 160     }
 161 
 162     private static native Color getColor(long theme, int part, int state,
 163                                          int property);
 164 
 165     public static Color getColor(String widget, int part, int state, int property) {
 166         readLock.lock();
 167         try {
 168             return getColor(getTheme(widget), part, state, property);
 169         } finally {
 170             readLock.unlock();
 171         }
 172     }
 173