2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.wm
.impl
;
19 import java
.lang
.reflect
.InvocationTargetException
;
20 import java
.lang
.reflect
.Method
;
22 public class AWTUtilitiesWrapper
{
24 private static Class
<?
> awtUtilitiesClass
;
25 private static Class
<?
> translucencyClass
;
26 private static Method mIsTranslucencySupported
, mIsTranslucencyCapable
, mSetWindowShape
, mSetWindowOpacity
, mSetWindowOpaque
;
27 public static Object PERPIXEL_TRANSPARENT
, TRANSLUCENT
, PERPIXEL_TRANSLUCENT
;
31 awtUtilitiesClass
= Class
.forName("com.sun.awt.AWTUtilities");
32 translucencyClass
= Class
.forName("com.sun.awt.AWTUtilities$Translucency");
33 if (translucencyClass
.isEnum()) {
34 Object
[] kinds
= translucencyClass
.getEnumConstants();
36 PERPIXEL_TRANSPARENT
= kinds
[0];
37 TRANSLUCENT
= kinds
[1];
38 PERPIXEL_TRANSLUCENT
= kinds
[2];
41 mIsTranslucencySupported
= awtUtilitiesClass
.getMethod("isTranslucencySupported", translucencyClass
);
42 mIsTranslucencyCapable
= awtUtilitiesClass
.getMethod("isTranslucencyCapable", GraphicsConfiguration
.class);
43 mSetWindowShape
= awtUtilitiesClass
.getMethod("setWindowShape", Window
.class, Shape
.class);
44 mSetWindowOpacity
= awtUtilitiesClass
.getMethod("setWindowOpacity", Window
.class, float.class);
45 mSetWindowOpaque
= awtUtilitiesClass
.getMethod("setWindowOpaque", Window
.class, boolean.class);
47 catch (NoSuchMethodException ex
) {
50 catch (SecurityException ex
) {
53 catch (ClassNotFoundException ex
) {
62 private static boolean isSupported(Method method
, Object kind
) {
63 if (awtUtilitiesClass
== null || method
== null) {
67 Object ret
= method
.invoke(null, kind
);
68 if (ret
instanceof Boolean
) {
69 return ((Boolean
)ret
).booleanValue();
72 catch (IllegalAccessException ex
) {
75 catch (IllegalArgumentException ex
) {
78 catch (InvocationTargetException ex
) {
84 public static boolean isTranslucencySupported(Object kind
) {
85 if (!isTranslucencyAPISupported()) return false;
86 return isSupported(mIsTranslucencySupported
, kind
);
89 public static boolean isTranslucencyAPISupported() {
90 return translucencyClass
!= null;
93 public static boolean isTranslucencyCapable(GraphicsConfiguration gc
) {
94 return isSupported(mIsTranslucencyCapable
, gc
);
97 private static void set(Method method
, Window window
, Object value
) {
98 if (awtUtilitiesClass
== null || method
== null) {
102 method
.invoke(null, window
, value
);
104 catch (IllegalAccessException ex
) {
107 catch (IllegalArgumentException ex
) {
110 catch (InvocationTargetException ex
) {
115 public static void setWindowShape(Window window
, Shape shape
) {
116 set(mSetWindowShape
, window
, shape
);
119 public static void setWindowOpacity(Window window
, float opacity
) {
120 set(mSetWindowOpacity
, window
, Float
.valueOf(opacity
));
123 public static void setWindowOpaque(Window window
, boolean opaque
) {
124 set(mSetWindowOpaque
, window
, Boolean
.valueOf(opaque
));