static void fixWindowManager() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();

    if (toolkit.getClass().getName().equals("sun.awt.X11.XToolkit")) {

      // Oracle Bug #6528430 - provide proper app name on Linux
      try {
        Field awtAppClassNameField = toolkit.getClass().getDeclaredField("awtAppClassName");
        awtAppClassNameField.setAccessible(true);
        awtAppClassNameField.set(toolkit, Resource.getAppName());
      } catch (NoSuchFieldException | IllegalAccessException ex) {
        Logger.getLogger(StaticUIMethods.class.getName())
            .log(Level.INFO, ex.getLocalizedMessage(), ex);
      }

      // Workaround for main menu, pop-up & mouse issues for Gnome 3 shell and Cinnamon
      if ("gnome-shell".equals(System.getenv("DESKTOP_SESSION"))
          || "cinnamon".equals(System.getenv("DESKTOP_SESSION"))
          || "gnome".equals(System.getenv("DESKTOP_SESSION"))
          || (System.getenv("XDG_CURRENT_DESKTOP") != null
              && System.getenv("XDG_CURRENT_DESKTOP").contains("GNOME"))) {
        try {
          Class<?> x11_wm = Class.forName("sun.awt.X11.XWM");

          Field awt_wMgr = x11_wm.getDeclaredField("awt_wmgr");
          awt_wMgr.setAccessible(true);

          Field other_wm = x11_wm.getDeclaredField("OTHER_WM");
          other_wm.setAccessible(true);

          if (awt_wMgr.get(null).equals(other_wm.get(null))) {
            Field metaCity_Wm = x11_wm.getDeclaredField("METACITY_WM");
            metaCity_Wm.setAccessible(true);
            awt_wMgr.set(null, metaCity_Wm.get(null));
            Logger.getLogger(StaticUIMethods.class.getName())
                .info("Installed window manager workaround");
          }
        } catch (ClassNotFoundException
            | NoSuchFieldException
            | SecurityException
            | IllegalArgumentException
            | IllegalAccessException ex) {
          Logger.getLogger(StaticUIMethods.class.getName())
              .log(Level.INFO, ex.getLocalizedMessage(), ex);
        }
      }
    }
  }
Esempio n. 2
0
  /**
   * @param methodName getter method
   * @param clazz value object class
   * @return attribute name related to the specified getter method
   */
  private String getAttributeName(String methodName, Class classType) {
    String attributeName = null;
    if (methodName.startsWith("is"))
      attributeName =
          methodName.substring(2, 3).toLowerCase()
              + (methodName.length() > 3 ? methodName.substring(3) : "");
    else
      attributeName =
          methodName.substring(3, 4).toLowerCase()
              + (methodName.length() > 4 ? methodName.substring(4) : "");

    // an attribute name "Xxxx" becomes "xxxx" and this is not correct!
    try {
      Class c = classType;
      boolean attributeFound = false;
      while (!c.equals(Object.class)) {
        try {
          c.getDeclaredField(attributeName);
          attributeFound = true;
          break;
        } catch (Throwable ex2) {
          c = c.getSuperclass();
        }
      }
      if (!attributeFound) {
        // now trying to find an attribute having the first character in upper case (e.g. "Xxxx")
        String name = attributeName.substring(0, 1).toUpperCase() + attributeName.substring(1);
        c = classType;
        while (!c.equals(Object.class)) {
          try {
            c.getDeclaredField(name);
            attributeFound = true;
            break;
          } catch (Throwable ex2) {
            c = c.getSuperclass();
          }
        }
        if (attributeFound) attributeName = name;
      }
    } catch (Throwable ex1) {
    }

    return attributeName;
  }
 public static Field makeAccessible(Class<?> target, String fieldName) {
   try {
     final Field field = target.getDeclaredField(fieldName);
     return (Field)
         AccessController.doPrivileged(
             new PrivilegedExceptionAction<Object>() {
               public Object run() throws IllegalAccessException, InvocationTargetException {
                 if (!field.isAccessible()) field.setAccessible(true);
                 return field;
               }
             });
   } catch (NoSuchFieldException | PrivilegedActionException e) {
     System.out.print("");
   } // keep quiet IError.printStackTrace(e); }
   return null;
 }