示例#1
0
  void enableLionFS() {
    try {
      String version = System.getProperty("os.version");
      String[] tokens = version.split("\\.");
      int major = Integer.parseInt(tokens[0]), minor = 0;
      if (tokens.length > 1) minor = Integer.parseInt(tokens[1]);
      if (major < 10 || (major == 10 && minor < 7))
        throw new Exception("Operating system version is " + version);

      Class fsuClass = Class.forName("com.apple.eawt.FullScreenUtilities");
      Class argClasses[] = new Class[] {Window.class, Boolean.TYPE};
      Method setWindowCanFullScreen = fsuClass.getMethod("setWindowCanFullScreen", argClasses);
      setWindowCanFullScreen.invoke(fsuClass, this, true);

      Class fsListenerClass = Class.forName("com.apple.eawt.FullScreenListener");
      InvocationHandler fsHandler = new MyInvocationHandler(cc);
      Object proxy =
          Proxy.newProxyInstance(
              fsListenerClass.getClassLoader(), new Class[] {fsListenerClass}, fsHandler);
      argClasses = new Class[] {Window.class, fsListenerClass};
      Method addFullScreenListenerTo = fsuClass.getMethod("addFullScreenListenerTo", argClasses);
      addFullScreenListenerTo.invoke(fsuClass, this, proxy);

      canDoLionFS = true;
    } catch (Exception e) {
      vlog.debug("Could not enable OS X 10.7+ full-screen mode:");
      vlog.debug("  " + e.toString());
    }
  }
 /*
  *  Use reflection to make a test compilable on not Mac OS X
  */
 private static void enableFullScreen(Window window) {
   try {
     Class fullScreenUtilities = Class.forName("com.apple.eawt.FullScreenUtilities");
     Method setWindowCanFullScreen =
         fullScreenUtilities.getMethod("setWindowCanFullScreen", Window.class, boolean.class);
     setWindowCanFullScreen.invoke(fullScreenUtilities, window, true);
     Class fullScreenListener = Class.forName("com.apple.eawt.FullScreenListener");
     Object listenerObject =
         Proxy.newProxyInstance(
             fullScreenListener.getClassLoader(),
             new Class[] {fullScreenListener},
             new InvocationHandler() {
               @Override
               public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                 switch (method.getName()) {
                   case "windowEnteringFullScreen":
                     windowEnteringFullScreen = true;
                     break;
                   case "windowEnteredFullScreen":
                     windowEnteredFullScreen = true;
                     break;
                 }
                 return null;
               }
             });
     Method addFullScreenListener =
         fullScreenUtilities.getMethod(
             "addFullScreenListenerTo", Window.class, fullScreenListener);
     addFullScreenListener.invoke(fullScreenUtilities, window, listenerObject);
   } catch (Exception e) {
     throw new RuntimeException("FullScreen utilities not available", e);
   }
 }
 @Nullable
 public static Image loadFromResource(@NonNls String s) {
   int stackFrameCount = 2;
   Class callerClass = Reflection.getCallerClass(stackFrameCount);
   while (callerClass != null
       && callerClass.getClassLoader() == null) { // looks like a system class
     callerClass = Reflection.getCallerClass(++stackFrameCount);
   }
   if (callerClass == null) {
     callerClass = Reflection.getCallerClass(1);
   }
   return loadFromResource(s, callerClass);
 }
示例#4
0
  @Nullable
  public static Icon findIcon(
      @NotNull String path, @NotNull final Class aClass, boolean computeNow) {
    path = undeprecate(path);
    if (isReflectivePath(path)) return getReflectiveIcon(path, aClass.getClassLoader());

    URL myURL = aClass.getResource(path);
    if (myURL == null) {
      if (STRICT) throw new RuntimeException("Can't find icon in '" + path + "' near " + aClass);
      return null;
    }
    return findIcon(myURL);
  }