Ejemplo n.º 1
0
 private void initStringClass(Class<E> clazz) {
   this.dialogInputs = new JComponent[] {new JLabel("ID"), getTextField()};
   try {
     this.constructor = clazz.getConstructor(String.class);
   } catch (NoSuchMethodException ignored) {
   }
 }
Ejemplo n.º 2
0
 public void loadMacros() {
   File f = new File(System.getProperty("user.dir"));
   String[] files = f.list();
   for (int i = 0; i < files.length; i++) {
     try {
       if (files[i].startsWith("macro_")
           && files[i].endsWith(".class")
           && files[i].indexOf('$') == -1) {
         System.out.println(files[i]);
         Class clazz = Class.forName(files[i].substring(0, files[i].length() - ".class".length()));
         Macro macro =
             (Macro)
                 clazz
                     .getConstructor(new Class[] {mudclient_Debug.class})
                     .newInstance(new Object[] {inner});
         String[] commands = macro.getCommands();
         for (int j = 0; j < commands.length; j++) {
           System.out.println("command registered:" + commands[j]);
           mudclient_Debug.macros.put(commands[j], macro);
         }
       }
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
Ejemplo n.º 3
0
 public static void invoke(String aClass, String aMethod, Class[] params, Object[] args)
     throws Exception {
   Class c = Class.forName(aClass);
   Constructor constructor = c.getConstructor(params);
   Method m = c.getDeclaredMethod(aMethod, params);
   Object i = constructor.newInstance(args);
   Object r = m.invoke(i, args);
 }
Ejemplo n.º 4
0
  public static Object loadFrame(
      JopSession session, String className, String instance, boolean scrollbar)
      throws ClassNotFoundException {

    if (className.indexOf(".pwg") != -1) {
      GrowFrame frame =
          new GrowFrame(
              className, session.getGdh(), instance, new GrowFrameCb(session), session.getRoot());
      frame.validate();
      frame.setVisible(true);
    } else {
      Object frame;
      if (instance == null) instance = "";

      JopLog.log(
          "JopSpider.loadFrame: Loading frame \"" + className + "\" instance \"" + instance + "\"");
      try {
        Class clazz = Class.forName(className);
        try {
          Class argTypeList[] =
              new Class[] {session.getClass(), instance.getClass(), boolean.class};
          Object argList[] = new Object[] {session, instance, new Boolean(scrollbar)};
          System.out.println("JopSpider.loadFrame getConstructor");
          Constructor constructor = clazz.getConstructor(argTypeList);

          try {
            frame = constructor.newInstance(argList);
          } catch (Exception e) {
            System.out.println(
                "Class instanciation error: "
                    + className
                    + " "
                    + e.getMessage()
                    + " "
                    + constructor);
            return null;
          }
          // frame = clazz.newInstance();
          JopLog.log("JopSpider.loadFrame openFrame");
          openFrame(frame);
          return frame;
        } catch (NoSuchMethodException e) {
          System.out.println("NoSuchMethodException: Unable to get frame constructor " + className);
        } catch (Exception e) {
          System.out.println(
              "Exception: Unable to get frame class " + className + " " + e.getMessage());
        }
      } catch (ClassNotFoundException e) {
        System.out.println("Class not found: " + className);
        throw new ClassNotFoundException();
      }
      return null;
    }
    return null;
  }
Ejemplo n.º 5
0
 /**
  * This function is called when we want to create a Plugin with a File accepted by the
  * PluginFilter
  *
  * @param file the file found
  * @return the Plugin created
  */
 protected Plugin createPlugin(File file) {
   Class<?> c = null;
   Plugin plugin = null;
   try {
     c = Class.forName("plugins." + file.getName().substring(0, file.getName().length() - 6));
     plugin = (Plugin) c.getConstructor().newInstance();
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
   return plugin;
 }
Ejemplo n.º 6
0
 /**
  * Create the default projection for the default class
  *
  * @return a default projection
  */
 private ProjectionImpl makeDefaultProjection() {
   // the default constructor
   try {
     Constructor c = projClass.getConstructor(VOIDCLASSARG);
     return (ProjectionImpl) c.newInstance(VOIDOBJECTARG);
   } catch (Exception ee) {
     System.err.println(
         "ProjectionManager makeDefaultProjection failed to construct class " + projClass);
     System.err.println("   " + ee);
     return null;
   }
 }
Ejemplo n.º 7
0
  private static void exportScreenshotEpsGraphics(
      Component target, File selectedFile, boolean paintOffscreen) throws IOException {

    if (!SnapshotUtilities.canExportScreenshotEps()) {
      String msg =
          "ERROR: EPS output requires EPSGraphics library. See https://www.broadinstitute.org/software/igv/third_party_tools#epsgraphics";
      log.error(msg);
      return;
    }

    Graphics2D g = null;
    FileOutputStream fos = null;
    try {
      Class colorModeClass = RuntimeUtils.loadClassForName(EPSColorModeClassName, null);
      Class graphicsClass = RuntimeUtils.loadClassForName(EPSClassName, null);

      Constructor constructor =
          graphicsClass.getConstructor(
              String.class,
              OutputStream.class,
              int.class,
              int.class,
              int.class,
              int.class,
              colorModeClass);

      Object colorModeValue = Enum.valueOf(colorModeClass, "COLOR_RGB");

      // EpsGraphics stores directly in a file
      fos = new FileOutputStream(selectedFile);
      g =
          (Graphics2D)
              constructor.newInstance(
                  "eps", fos, 0, 0, target.getWidth(), target.getHeight(), colorModeValue);

      choosePaint(target, g, paintOffscreen);

      graphicsClass.getMethod("close").invoke(g);

    } catch (Exception e) {
      log.error(e.getMessage(), e);
    } finally {
      if (fos != null) {
        fos.flush();
        fos.close();
      }
    }
  }
Ejemplo n.º 8
0
 protected void initObjectClass(Class<E> clazz) {
   Field[] fields = clazz.getDeclaredFields();
   this.dialogInputs = new JComponent[fields.length * 2];
   for (int i = 0; i < fields.length; i++) {
     this.dialogInputs[2 * i] = new JLabel(fields[i].getName());
     this.dialogInputs[2 * i + 1] = (i == 0) ? getTextField() : getTextArea();
   }
   this.dialogInputs[1].setEnabled(false);
   Class[] classes = new Class[fields.length];
   for (int i = 0; i < classes.length; i++) {
     classes[i] = String.class;
   }
   try {
     this.constructor = clazz.getConstructor(classes);
   } catch (NoSuchMethodException ignored) {
   }
 }
Ejemplo n.º 9
0
  public Object getBean(String beanfactory) throws BeanFactoryException {

    // For backwards compatibility
    beanfactory = mapNewClass(beanfactory);

    BeanFactory bf = m_aBeanFactories.get(beanfactory);
    if (bf == null) {

      // testing sripts
      if (beanfactory.startsWith("/")) {
        bf = new BeanFactoryScript(beanfactory);
      } else {
        // Class BeanFactory
        try {
          Class bfclass = Class.forName(beanfactory);

          if (BeanFactory.class.isAssignableFrom(bfclass)) {
            bf = (BeanFactory) bfclass.newInstance();
          } else {
            // the old construction for beans...
            Constructor constMyView = bfclass.getConstructor(new Class[] {AppView.class});
            Object bean = constMyView.newInstance(new Object[] {this});

            bf = new BeanFactoryObj(bean);
          }

        } catch (Exception e) {
          // ClassNotFoundException, InstantiationException, IllegalAccessException,
          // NoSuchMethodException, InvocationTargetException
          throw new BeanFactoryException(e);
        }
      }

      // cache the factory
      m_aBeanFactories.put(beanfactory, bf);

      // Initialize if it is a BeanFactoryApp
      if (bf instanceof BeanFactoryApp) {
        ((BeanFactoryApp) bf).init(this);
      }
    }
    return bf.getBean();
  }
Ejemplo n.º 10
0
 public static boolean canExportScreenshotEps() {
   Constructor constr = null;
   try {
     Class colorModeClass = RuntimeUtils.loadClassForName(EPSColorModeClassName, null);
     Class graphicsClass = RuntimeUtils.loadClassForName(EPSClassName, null);
     constr =
         graphicsClass.getConstructor(
             String.class,
             OutputStream.class,
             int.class,
             int.class,
             int.class,
             int.class,
             colorModeClass);
   } catch (Exception e) {
     // pass
   }
   return constr != null;
 }
Ejemplo n.º 11
0
  private void addTool(String key, Class tool) {
    Class[] constructArgs = null;
    if (key.equals("XMLToolPanel")) {
      constructArgs = new Class[3];
      constructArgs[0] = vnmr.ui.SessionShare.class;
      constructArgs[1] = String.class;
      constructArgs[2] = String.class;
    } else {
      constructArgs = new Class[1];
      constructArgs[0] = vnmr.ui.SessionShare.class;
    }

    try {
      Constructor c = tool.getConstructor(constructArgs);
      vobjs.put(key, c);
    } catch (NoSuchMethodException nse) {
      Messages.postError("Problem initiating " + key + " area.");
      Messages.writeStackTrace(nse, tool + " not found.");
    } catch (SecurityException se) {
      Messages.postError("Problem initiating " + key + " area.");
      Messages.writeStackTrace(se);
    }
  }
Ejemplo n.º 12
0
  /** Look on disk for an editor with the class name 'ocName'. */
  PluggableEditor loadEditorFromDisk(String ocName) {
    // if here, we need to look on disk for a pluggable editor class...
    log.finer("looking for ocName: " + ocName);
    try {
      Class c = myLoader.loadClass(ocName);
      Constructor constructor = c.getConstructor(new Class[0]);

      // XXX If the pluggable editor has an error in the constructor, under some
      // XXX circumstances it can fail so badly that this call never returns, and
      // XXX the thread hangs!  It doesn't even get to the exception handler below...
      // XXX but sometimes if the constructor fails everything works as expected.  Wierd.
      PluggableEditor editor = (PluggableEditor) constructor.newInstance(new Object[0]);

      editors.put(ocName, editor); // add the new editor to our list
      return editor;
    } catch (Exception e) // expected condition - just means no pluggable editor available
    {
      if (e
          instanceof
          InvocationTargetException) // rare exception - an error was encountered in the plugin's
                                     // constructor.
      {
        log.warning("unable to load special editor for: '" + ocName + "' " + e);
        if (JXConfig.debugLevel >= 1) {
          log.warning("Error loading plugin class: ");
          ((InvocationTargetException) e).getTargetException().printStackTrace();
        }
      }

      log.log(Level.FINEST, "'Expected' Error loading " + ocName, e);
      editors.put(ocName, NONE); // add a blank place holder - we can't load
      // an editor for this, and there's no point looking again. (change if want dynamic loading,
      // i.e. look *every* time)
    }
    return null; // only here if an error has occured.
  }
Ejemplo n.º 13
0
  /**
   * Creates a new <code>java.awt.Frame</code>. This frame is the root for the AWT components that
   * will be embedded within the composite. In order for the embedding to succeed, the composite
   * must have been created with the SWT.EMBEDDED style.
   *
   * <p>IMPORTANT: As of JDK1.5, the embedded frame does not receive mouse events. When a
   * lightweight component is added as a child of the embedded frame, the cursor does not change. In
   * order to work around both these problems, it is strongly recommended that a heavyweight
   * component such as <code>java.awt.Panel</code> be added to the frame as the root of all
   * components.
   *
   * @param parent the parent <code>Composite</code> of the new <code>java.awt.Frame</code>
   * @return a <code>java.awt.Frame</code> to be the parent of the embedded AWT components
   * @exception IllegalArgumentException
   *     <ul>
   *       <li>ERROR_NULL_ARGUMENT - if the parent is null
   *       <li>ERROR_INVALID_ARGUMENT - if the parent Composite does not have the SWT.EMBEDDED style
   *     </ul>
   *
   * @since 3.0
   */
  public static Frame new_Frame(final Composite parent) {
    if (parent == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
    if ((parent.getStyle() & SWT.EMBEDDED) == 0) {
      SWT.error(SWT.ERROR_INVALID_ARGUMENT);
    }

    final int /*long*/ handle = parent.view.id;

    Class clazz = null;
    try {
      String className =
          embeddedFrameClass != null ? embeddedFrameClass : "apple.awt.CEmbeddedFrame";
      if (embeddedFrameClass == null) {
        clazz = Class.forName(className, true, ClassLoader.getSystemClassLoader());
      } else {
        clazz = Class.forName(className);
      }
    } catch (ClassNotFoundException cne) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, cne);
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_UNSPECIFIED, e, " [Error while starting AWT]");
    }

    initializeSwing();
    Object value = null;
    Constructor constructor = null;
    try {
      constructor = clazz.getConstructor(new Class[] {long.class});
      value = constructor.newInstance(new Object[] {new Long(handle)});
    } catch (Throwable e) {
      SWT.error(SWT.ERROR_NOT_IMPLEMENTED, e);
    }
    final Frame frame = (Frame) value;
    frame.addNotify();

    parent.setData(EMBEDDED_FRAME_KEY, frame);

    /* Forward the iconify and deiconify events */
    final Listener shellListener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Deiconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_DEICONIFIED));
                      }
                    });
                break;
              case SWT.Iconify:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_ICONIFIED));
                      }
                    });
                break;
            }
          }
        };
    Shell shell = parent.getShell();
    shell.addListener(SWT.Deiconify, shellListener);
    shell.addListener(SWT.Iconify, shellListener);

    /*
     * Generate the appropriate events to activate and deactivate
     * the embedded frame. This is needed in order to make keyboard
     * focus work properly for lightweights.
     */
    Listener listener =
        new Listener() {
          public void handleEvent(Event e) {
            switch (e.type) {
              case SWT.Dispose:
                Shell shell = parent.getShell();
                shell.removeListener(SWT.Deiconify, shellListener);
                shell.removeListener(SWT.Iconify, shellListener);
                parent.setVisible(false);
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        try {
                          frame.dispose();
                        } catch (Throwable e) {
                        }
                      }
                    });
                break;
              case SWT.FocusIn:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(true)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
              case SWT.Deactivate:
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        if (!frame.isActive()) return;
                        try {
                          Class clazz = frame.getClass();
                          Method method =
                              clazz.getMethod(
                                  "synthesizeWindowActivation", new Class[] {boolean.class});
                          if (method != null)
                            method.invoke(frame, new Object[] {new Boolean(false)});
                        } catch (Throwable e) {
                          e.printStackTrace();
                        }
                      }
                    });
                break;
            }
          }
        };

    parent.addListener(SWT.FocusIn, listener);
    parent.addListener(SWT.Deactivate, listener);
    parent.addListener(SWT.Dispose, listener);

    parent
        .getDisplay()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (parent.isDisposed()) return;
                final Rectangle clientArea = parent.getClientArea();
                EventQueue.invokeLater(
                    new Runnable() {
                      public void run() {
                        frame.setSize(clientArea.width, clientArea.height);
                        frame.validate();

                        // Bug in Cocoa AWT? For some reason the frame isn't showing up on first
                        // draw.
                        // Toggling visibility seems to be the only thing that works.
                        frame.setVisible(false);
                        frame.setVisible(true);
                      }
                    });
              }
            });

    return frame;
  }
Ejemplo n.º 14
0
 private Action tryDefaultConstructor(final Class aClass) throws Exception {
   final Constructor constructor = aClass.getConstructor(EditorCoreAPI.class);
   return (Action) constructor.newInstance(myCoreAPI);
 }