예제 #1
2
  public void changeLAF(int iLAFIndex) {
    try {
      // Change LAF
      if (iLAFIndex >= marrLaf.length) iLAFIndex = marrLaf.length - 1;
      UIManager.setLookAndFeel(
          (LookAndFeel) Class.forName(marrLaf[iLAFIndex].getClassName()).newInstance());

      // Update UI
      ((JMenuItem) mvtLAFItem.elementAt(iLAFIndex)).setSelected(true);
      SwingUtilities.updateComponentTreeUI(this);
      SwingUtilities.updateComponentTreeUI(mnuMain);
      WindowManager.updateLookAndField();

      // Store config
      try {
        Hashtable prt = Global.loadHashtable(Global.FILE_CONFIG);
        prt.put("LAF", String.valueOf(iLAFIndex));
        Global.storeHashtable(prt, Global.FILE_CONFIG);
      } catch (Exception e) {
      }
    } catch (Exception e) {
      e.printStackTrace();
      MessageBox.showMessageDialog(this, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE);
    }
  }
예제 #2
0
  /**
   * Load a class specified by a file- or entry-name
   *
   * @param name name of a file or entry
   * @return class file that was denoted by the name, null if no class or does not contain a main
   *     method
   */
  private Class load(String name) {
    if (name.endsWith(".class") && name.indexOf("Test") >= 0 && name.indexOf('$') < 0) {
      String classname = name.substring(0, name.length() - ".class".length());

      if (classname.startsWith("/")) {
        classname = classname.substring(1);
      }
      classname = classname.replace('/', '.');

      try {
        final Class<?> cls = Class.forName(classname);
        cls.getMethod("main", new Class[] {String[].class});
        if (!getClass().equals(cls)) {
          return cls;
        }
      } catch (NoClassDefFoundError e) {
        // class has unresolved dependencies
        return null;
      } catch (ClassNotFoundException e) {
        // class not in classpath
        return null;
      } catch (NoSuchMethodException e) {
        // class does not have a main method
        return null;
      } catch (UnsupportedClassVersionError e) {
        // unsupported version
        return null;
      }
    }
    return null;
  }
예제 #3
0
파일: VMManager.java 프로젝트: nbearson/IDV
  /**
   * Create the given ViewManager
   *
   * @param viewDescriptor Identifies the VM
   * @param properties Property string to pass
   * @return The new one
   */
  public ViewManager createViewManager(ViewDescriptor viewDescriptor, String properties) {
    synchronized (viewManagers) {
      try {
        ViewManager viewManager = null;
        if (viewDescriptor == null) {
          viewDescriptor = new ViewDescriptor();
        }
        if (viewDescriptor.getClassNames().size() > 0) {
          Class viewManagerClass = Misc.findClass((String) viewDescriptor.getClassNames().get(0));
          Constructor ctor =
              Misc.findConstructor(
                  viewManagerClass,
                  new Class[] {IntegratedDataViewer.class, ViewDescriptor.class, String.class});

          if (ctor == null) {
            throw new IllegalArgumentException(
                "cannot create ViewManager:" + viewManagerClass.getName());
          }

          viewManager =
              (ViewManager) ctor.newInstance(new Object[] {getIdv(), viewDescriptor, properties});
        } else {
          viewManager = new MapViewManager(getIdv(), viewDescriptor, properties);
        }

        addViewManager(viewManager);
        return viewManager;
      } catch (Throwable e) {
        logException("In getViewManager", e);
        return null;
      }
    }
  }
예제 #4
0
 protected static Object newInstance(String name) {
   try {
     Class clazz = Class.forName(name);
     return clazz.newInstance();
   } catch (Exception e) {
     Logger().severe("Cannot extatiate class " + name + ": " + e.getMessage());
     return null;
   }
 }
예제 #5
0
 /**
  * A utility function that layers on top of the LookAndFeel's isSupportedLookAndFeel() method.
  * Returns true if the LookAndFeel is supported. Returns false if the LookAndFeel is not supported
  * and/or if there is any kind of error checking if the LookAndFeel is supported.
  *
  * <p>The L&F menu will use this method to detemine whether the various L&F options should be
  * active or inactive.
  */
 protected boolean isAvailableLookAndFeel(String laf) {
   try {
     Class lnfClass = Class.forName(laf);
     LookAndFeel newLAF = (LookAndFeel) (lnfClass.newInstance());
     return newLAF.isSupportedLookAndFeel();
   } catch (Exception e) { // If ANYTHING weird happens, return false
     return false;
   }
 }
예제 #6
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;
  }
예제 #7
0
 /**
  * Find the class for the projection
  *
  * @param proj projection
  * @return corresponding ProjectionClass (or null if not found)
  */
 private ProjectionClass findProjectionClass(Projection proj) {
   Class want = proj.getClass();
   ComboBoxModel projClassList = projClassCB.getModel();
   for (int i = 0; i < projClassList.getSize(); i++) {
     ProjectionClass pc = (ProjectionClass) projClassList.getElementAt(i);
     if (want.equals(pc.projClass)) {
       return pc;
     }
   }
   return null;
 }
예제 #8
0
 /** Return the control based on a control type for the PlugIn. */
 public Object getControl(String controlType) {
   try {
     Class cls = Class.forName(controlType);
     Object cs[] = getControls();
     for (int i = 0; i < cs.length; i++) {
       if (cls.isInstance(cs[i])) return cs[i];
     }
     return null;
   } catch (Exception e) { // no such controlType or such control
     return null;
   }
 }
예제 #9
0
 public void toggleLionFS() {
   try {
     Class appClass = Class.forName("com.apple.eawt.Application");
     Method getApplication = appClass.getMethod("getApplication", (Class[]) null);
     Object app = getApplication.invoke(appClass);
     Method requestToggleFullScreen = appClass.getMethod("requestToggleFullScreen", Window.class);
     requestToggleFullScreen.invoke(app, this);
   } catch (Exception e) {
     vlog.debug("Could not toggle OS X 10.7+ full-screen mode:");
     vlog.debug("  " + e.toString());
   }
 }
예제 #10
0
 static synchronized void initializeSwing() {
   if (swingInitialized) return;
   swingInitialized = true;
   try {
     /* Initialize the default focus traversal policy */
     Class[] emptyClass = new Class[0];
     Object[] emptyObject = new Object[0];
     Class clazz = Class.forName("javax.swing.UIManager");
     Method method = clazz.getMethod("getDefaults", emptyClass);
     if (method != null) method.invoke(clazz, emptyObject);
   } catch (Throwable e) {
   }
 }
예제 #11
0
    /** Creates a new key tip layer. */
    public KeyTipLayer() {
      this.setOpaque(false);

      // Support placing heavyweight components in the ribbon frame. See
      // http://today.java.net/article/2009/11/02/transparent-panel-mixing-heavyweight-and-lightweight-components.
      try {
        Class awtUtilitiesClass = Class.forName("com.sun.awt.AWTUtilities");
        Method mSetComponentMixing =
            awtUtilitiesClass.getMethod(
                "setComponentMixingCutoutShape", Component.class, Shape.class);
        mSetComponentMixing.invoke(null, this, new Rectangle());
      } catch (Throwable ignored) {
      }
    }
예제 #12
0
 /**
  * Check if the given element is an array.
  *
  * <p>Multidimensional arrays are not supported.
  *
  * <p>Non-empty 1-dimensional arrays of CompositeData and TabularData are not handled as arrays
  * but as tabular data.
  */
 public static boolean isSupportedArray(Object elem) {
   if (elem == null || !elem.getClass().isArray()) {
     return false;
   }
   Class<?> ct = elem.getClass().getComponentType();
   if (ct.isArray()) {
     return false;
   }
   if (Array.getLength(elem) > 0
       && (CompositeData.class.isAssignableFrom(ct) || TabularData.class.isAssignableFrom(ct))) {
     return false;
   }
   return true;
 }
예제 #13
0
 protected FailureDetailView createFailureDetailView() {
   String className = BaseTestRunner.getPreference(FAILUREDETAILVIEW_KEY);
   if (className != null) {
     Class viewClass = null;
     try {
       viewClass = Class.forName(className);
       return (FailureDetailView) viewClass.newInstance();
     } catch (Exception e) {
       JOptionPane.showMessageDialog(
           mainPane, "Could not create Failure DetailView - using default view");
     }
   }
   return new DefaultFailureDetailView();
 }
예제 #14
0
 private void ListValueChanged(
     javax.swing.event.ListSelectionEvent evt) { // GEN-FIRST:event_ListValueChanged
   // TODO add your handling code here:
   // String part=partno.getText();
   try {
     String sql =
         "SELECT  TYPE,ITEM_NAME,QUANTITY,MRP FROM MOTORS WHERE ITEM_NAME='"
             + List.getSelectedValue()
             + "'";
     Class.forName("com.mysql.jdbc.Driver");
     Connection con =
         (Connection)
             DriverManager.getConnection("jdbc:mysql://localhost:3306/bharatmotors", "root", "");
     Statement stmt = con.createStatement();
     ResultSet rs = stmt.executeQuery(sql);
     while (rs.next()) {
       partno.setText(rs.getString("TYPE"));
       name.setText(rs.getString("ITEM_NAME"));
       qty.setText(rs.getString("QUANTITY"));
       rate.setText(rs.getString("MRP"));
     }
   } catch (Exception e) {
     JOptionPane.showMessageDialog(null, e.toString());
   }
 } // GEN-LAST:event_ListValueChanged
예제 #15
0
 protected PanelElementAbstract createPanelElement(BasicDBObject DBO, int idx) {
   T t;
   try {
     t = clazz.newInstance();
     t.setIdx(idx);
     t.setDisplayer(panelDisplayer);
     t.setData(DBO);
     t.initPanel();
     PanelElementAbstract b;
     if (t instanceof ParameterPanel) {
       b = new PanelElementMono((ParameterPanel) t, this, maxNb > 1 && idx >= minNb, idx);
     } else {
       b =
           new PanelElementPlugin(
               (ParameterPanelPlugin) t, this, maxNb > 1 && idx >= minNb, enableTest);
       if (template != null && idx < template.panelElements.size())
         ((PanelElementPlugin) b)
             .setTemplate((PanelElementPlugin) template.panelElements.get(idx));
     }
     // System.out.println("panelElement null:"+(b==null)+ " idx:"+idx+ " "+DBO);
     return b;
   } catch (Exception e) {
     exceptionPrinter.print(e, "", Core.GUIMode);
   }
   return null;
 }
 public static void main(java.lang.String[] args) {
   String className = null;
   try {
     System.err.println("logging is done using log4j.");
     final ICQMessagingTest_Applet applet = new ICQMessagingTest_Applet();
     className = cfg.REQPARAM_MESSAGING_NETWORK_IMPL_CLASS_NAME.trim();
     CAT.info("Instantiating class \"" + className + "\"...");
     try {
       applet.plugin = (MessagingNetwork) Class.forName(className).newInstance();
       applet.plugin.init();
     } catch (Throwable tr) {
       CAT.error("ex in main", tr);
       System.exit(1);
     }
     java.awt.Frame frame = new java.awt.Frame("MessagingTest");
     frame.addWindowListener(
         new WindowAdapter() {
           public void windowClosing(WindowEvent e) {
             applet.quit();
           }
         });
     frame.add("Center", applet);
     frame.setSize(800, 650);
     frame.setLocation(150, 100);
     applet.init();
     frame.show();
     frame.invalidate();
     frame.validate();
     applet.start();
   } catch (Throwable tr) {
     CAT.error("exception", tr);
     System.exit(1);
   }
 }
예제 #17
0
  private /*synchronized*/ StructureType assignStructureType(String structType)
      throws VisualizerLoadException {

    if (debug) System.out.println("In assignStructureType with " + structType);

    // Handle objects whose constructors require args separately
    if ((structType.toUpperCase().compareTo("BAR") == 0)
        || (structType.toUpperCase().compareTo("SCAT") == 0))
      return (new BarScat(structType.toUpperCase()));
    else if ((structType.toUpperCase().compareTo("GRAPH") == 0)
        || (structType.toUpperCase().compareTo("NETWORK") == 0))
      return (new Graph_Network(structType.toUpperCase()));
    else { // Constructor for object does not require args

      try {
        return ((StructureType)
            ((Class.forName(insure_text_case_correct_for_legacy_scripts(structType)))
                .newInstance()));
      } catch (InstantiationException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      } catch (IllegalAccessException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      } catch (ClassNotFoundException e) {
        System.out.println(e);
        throw (new VisualizerLoadException(structType + " is invalid structure type"));
      }
    }
  }
예제 #18
0
  private Object getResource(String key) {

    URL url = null;
    String name = key;

    if (name != null) {

      try {
        Class c = Class.forName("content.AdvancedPanel");
        url = c.getResource(name);
      } catch (ClassNotFoundException cnfe) {
        System.err.println("Unable to find Main class");
      }
      return url;
    } else return null;
  }
예제 #19
0
  public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() == b1) {
      try {
        Class.forName("oracle.jdbc.driver.OracleDriver");
        Connection con =
            DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe", "system", "123");
        PreparedStatement ps =
            con.prepareStatement("select * from LoginForm where username=? and password=?");
        String UserName = t1.getText();
        String Password = jp1.getText();
        ps.setString(1, UserName);
        ps.setString(2, Password);
        ResultSet rs = ps.executeQuery();
        boolean flag = rs.next();
        if (flag) {
          new Main();
          f.setVisible(false);
        } else {
          JOptionPane.showMessageDialog(null, "Please Enter valid Name And Password");
        }

      } catch (Exception e) {
        System.out.println("Error:" + e);
      }
    } else if (ae.getSource() == b2) {
      t1.setText("");
      jp1.setText("");
    } else if (ae.getSource() == b3) {

      f.setVisible(false);
    }
  }
예제 #20
0
 public void actionPerformed(ActionEvent ae) {
   String cname = nameF.getText().trim();
   int state = conditions[stateC.getSelectedIndex()];
   try {
     if (isSpecialCase(cname)) {
       handleSpecialCase(cname, state);
     } else {
       JComponent comp = (JComponent) Class.forName(cname).newInstance();
       ComponentUI cui = UIManager.getUI(comp);
       cui.installUI(comp);
       results.setText("Map entries for " + cname + ":\n\n");
       if (inputB.isSelected()) {
         loadInputMap(comp.getInputMap(state), "");
         results.append("\n");
       }
       if (actionB.isSelected()) {
         loadActionMap(comp.getActionMap(), "");
         results.append("\n");
       }
       if (bindingB.isSelected()) {
         loadBindingMap(comp, state);
       }
     }
   } catch (ClassCastException cce) {
     results.setText(cname + " is not a subclass of JComponent.");
   } catch (ClassNotFoundException cnfe) {
     results.setText(cname + " was not found.");
   } catch (InstantiationException ie) {
     results.setText(cname + " could not be instantiated.");
   } catch (Exception e) {
     results.setText("Exception found:\n" + e);
     e.printStackTrace();
   }
 }
예제 #21
0
 // todo eliminate code duplication in BaseLogicalViewProjectPane
 private <T extends TreeNode> T getSelectedTreeNode(Class<T> nodeClass) {
   TreePath selectionPath = getTree().getSelectionPath();
   if (selectionPath == null) return null;
   Object selectedNode = selectionPath.getLastPathComponent();
   if (!(nodeClass.isInstance(selectedNode))) return null;
   return (T) selectedNode;
 }
예제 #22
0
 /**
  * Make the default projections from the internal list of classes.
  *
  * @return list of default projections
  */
 public static List makeDefaultProjections() {
   List defaults = new ArrayList();
   List classNames = getDefaultProjections();
   for (int i = 0; i < classNames.size(); i++) {
     String className = (String) classNames.get(i);
     try {
       Class projClass = Misc.findClass(className);
       ProjectionImpl pi = (ProjectionImpl) projClass.newInstance();
       pi.setName("Default " + pi.getProjectionTypeLabel());
       defaults.add(pi);
     } catch (Exception ee) {
       System.err.println("Error creating default projection: " + className);
       ee.printStackTrace();
     }
   }
   return defaults;
 }
예제 #23
0
 public void load_DriverJDBC() {
   try {
     Class.forName("com.mysql.jdbc.Driver");
     status_Proses(true, "Sukses!!!Driver JDBC ditemukan...", 20);
   } catch (ClassNotFoundException cnfe) {
     status_Proses(false, "Gagal!!!Driver JDBC tidak ditemukan...", 20);
   }
 }
예제 #24
0
 /**
  * Return a String representation of the object
  *
  * @return a String representation of the object
  */
 public String toString() {
   return paramType.getName()
       + " "
       + name
       + " "
       + ((reader == null) ? "-" : "R")
       + ((writer == null) ? "-" : "W");
 }
예제 #25
0
  public void connectItems(String query)
        // PRE:  query must be initialized
        // POST: Updates the list of Items based on the query.
      {
    String driver = "org.apache.derby.jdbc.ClientDriver"; // Driver for DB
    String url = "jdbc:derby://localhost:1527/ShopDataBase"; // Url for DB
    String user = "******"; // Username for db
    String pass = "******"; // Password for db
    Connection myConnection; // Connection obj to db
    Statement stmt; // Statement to execute a result appon
    ResultSet results; // A set containing the returned results
    int rowcount; // Num objects in the resultSet
    int i; // Index for the array

    try { // Try connection to db

      Class.forName(driver).newInstance(); // Create our db driver

      myConnection = DriverManager.getConnection(url, user, pass); // Initalize our connection

      stmt =
          myConnection.createStatement(
              ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE); // Create a new statement
      results = stmt.executeQuery(query); // Store the results of our query

      rowcount = 0;
      if (results.last()) // Go to the last result
      {
        rowcount = results.getRow();
        results.beforeFirst();
      }
      itemsArray = new Item[rowcount];

      i = 0;
      while (results.next()) // Itterate through the results set
      {
        itemsArray[i] =
            new Item(
                results.getInt("item_id"),
                results.getString("item_name"),
                results.getString("item_type"),
                results.getInt("price"),
                results.getInt("owner_id"),
                results.getString("item_path")); // Creat new Item
        i++;
      }

      results.close(); // Close the ResultSet
      stmt.close(); // Close the statement
      myConnection.close(); // Close the connection to db

    } catch (Exception e) // Cannot connect to db
    {
      System.err.println(e.toString());
      System.err.println("Error, something went horribly wrong in connectItems!");
    }
  }
예제 #26
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());
    }
  }
예제 #27
0
  public void stateChanged(ChangeEvent ce) {
    Object ob = ce.getSource();
    Class<?> cl = ob.getClass();

    if (Debug) {
      System.out.println("MyChangeListener: got stateChanged: Object: " + ob.toString() + "\n");
      System.out.println("MyChangeListener: got stateChanged: Class: " + cl.getName() + "\n");
    }

    if (cl.getName().equals("javax.swing.JTabbedPane")) {
      if (pane == ce.getSource()) {
        int index = pane.getSelectedIndex();
        mLook.stateChanged(index);
      } else {
        System.out.println("The source does NOT equal pane\n");
      }
    }
  }
 /*
  * Recursive method which returns a count of the number of listeners in
  * EventListener, handling the (common) case of l actually being an
  * AWTEventMulticaster.  Additionally, only listeners of type listenerType
  * are counted.  Method modified to fix bug 4513402.  -bchristi
  */
 private static int getListenerCount(EventListener l, Class listenerType) {
   if (l instanceof AWTEventMulticaster) {
     AWTEventMulticaster mc = (AWTEventMulticaster) l;
     return getListenerCount(mc.a, listenerType) + getListenerCount(mc.b, listenerType);
   } else {
     // Only count listeners of correct type
     return listenerType.isInstance(l) ? 1 : 0;
   }
 }
예제 #29
0
 public QueryTableModel() {
   cache = new Vector();
   try {
     Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
   } catch (java.lang.Exception e) {
     System.err.println("Class not found exception : ");
     System.err.println(e.getMessage());
   }
 } // konstr. sonu
예제 #30
0
  /**
   * Returns an instance of the default toolkit. The default toolkit is the subclass of <code>
   * Toolkit</code> specified in the system property <code>awt.toolkit</code>, or <code>
   * gnu.java.awt.peer.gtk.GtkToolkit</code> if the property is not set.
   *
   * @return An instance of the system default toolkit.
   * @error AWTError If the toolkit cannot be loaded.
   */
  public static Toolkit getDefaultToolkit() {
    if (toolkit != null) return (toolkit);

    String toolkit_name = System.getProperty("awt.toolkit", default_toolkit_name);

    try {
      Class cls = Class.forName(toolkit_name);
      Object obj = cls.newInstance();

      if (!(obj instanceof Toolkit))
        throw new AWTError(toolkit_name + " is not a subclass of " + "java.awt.Toolkit");

      toolkit = (Toolkit) obj;
      return (toolkit);
    } catch (Exception e) {
      throw new AWTError("Cannot load AWT toolkit: " + e.getMessage());
    }
  }