Exemple #1
0
  /**
   * Constructor.
   *
   * @throws Exception if any error occurs.
   */
  public GUIMacOSX() throws Exception {
    // Name for the dock icon and the application menu
    System.setProperty(P_ABOUT_NAME, NAME);
    // Show menu in the screen menu instead of inside the application window
    System.setProperty(P_SCREEN_MENU_BAR, "true");

    // load native java classes...
    appClass = Class.forName(C_APPLICATION);
    appObj = invoke(appClass, null, "getApplication", EC, EO);
    Class.forName(C_APPLICATION_EVENT);

    if (appObj != null) {
      invoke("addAboutMenuItem");
      invoke("setEnabledAboutMenu", true);
      invoke("addPreferencesMenuItem");
      invoke("setEnabledPreferencesMenu", true);

      addDockIcon();

      final Class<?> alc = Class.forName(C_APPLICATION_LISTENER);
      final Object listener =
          Proxy.newProxyInstance(
              getClass().getClassLoader(), new Class[] {alc}, new AppInvocationHandler());
      invoke("addApplicationListener", alc, listener);
    }
  }
Exemple #2
0
 /**
  * Invokes a method on the given object that expects multiple arguments.
  *
  * @param clazz class object to get the method from
  * @param obj object on which the method should be invoked. Can be {@code null} for static methods
  * @param method name of the method to invoke
  * @param argClasses "types" of the arguments
  * @param argObjects argument values
  * @return return value of the method
  * @throws Exception if any error occurs
  */
 private static Object invoke(
     final Class<?> clazz,
     final Object obj,
     final String method,
     final Class<?>[] argClasses,
     final Object[] argObjects)
     throws Exception {
   return clazz.getMethod(method, argClasses).invoke(obj, argObjects);
 }
Exemple #3
0
 /**
  * Returns all commands that start with the specified user input.
  *
  * @param <T> token type
  * @param en available commands
  * @param prefix user input
  * @return completions
  */
 private static <T extends Enum<T>> Enum<?>[] startWith(final Class<T> en, final String prefix) {
   Enum<?>[] list = new Enum<?>[0];
   final String t = prefix == null ? "" : prefix.toUpperCase(Locale.ENGLISH);
   for (final Enum<?> e : en.getEnumConstants()) {
     if (e.name().startsWith(t)) {
       final int s = list.length;
       list = Array.copy(list, new Enum<?>[s + 1]);
       list[s] = e;
     }
   }
   return list;
 }
Exemple #4
0
  /**
   * Starts the specified class in a separate process.
   *
   * @param clz class to start
   * @param args command-line arguments
   * @return reference to a {@link Process} instance representing the started process
   */
  public static Process start(final Class<?> clz, final String... args) {
    final String[] largs = {
      "java",
      "-Xmx" + Runtime.getRuntime().maxMemory(),
      "-cp",
      System.getProperty("java.class.path"),
      clz.getName(),
      "-D",
    };
    final StringList sl = new StringList().add(largs).add(args);

    try {
      return new ProcessBuilder(sl.toArray()).start();
    } catch (final IOException ex) {
      notexpected(ex);
      return null;
    }
  }
Exemple #5
0
 /**
  * Returns the name of the specified class.
  *
  * @param o object
  * @return class name
  */
 public static String name(final Class<?> o) {
   return o.getSimpleName();
 }