sticky documentation popup [take 1]
[fedora-idea.git] / platform / platform-impl / src / com / intellij / openapi / wm / impl / AWTUtilitiesWrapper.java
blobfe756a1da8b2e2c517929a30b13a75d7fbd4a95b
1 /*
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;
18 import java.awt.*;
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;
29 static void init() {
30 try {
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();
35 if (kinds != null) {
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) {
48 // ignore
50 catch (SecurityException ex) {
51 // ignore
53 catch (ClassNotFoundException ex) {
54 // ignore
58 static {
59 init();
62 private static boolean isSupported(Method method, Object kind) {
63 if (awtUtilitiesClass == null || method == null) {
64 return false;
66 try {
67 Object ret = method.invoke(null, kind);
68 if (ret instanceof Boolean) {
69 return ((Boolean)ret).booleanValue();
72 catch (IllegalAccessException ex) {
73 // ignore
75 catch (IllegalArgumentException ex) {
76 // ignore
78 catch (InvocationTargetException ex) {
79 // ignore
81 return false;
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) {
99 return;
101 try {
102 method.invoke(null, window, value);
104 catch (IllegalAccessException ex) {
105 // ignore
107 catch (IllegalArgumentException ex) {
108 // ignore
110 catch (InvocationTargetException ex) {
111 // ignore
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));