コード例 #1
0
ファイル: MultiParameterPanel.java プロジェクト: cmci/tango
 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;
 }
コード例 #2
0
ファイル: Main.java プロジェクト: nagyistoce/jabberskype
 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;
   }
 }
コード例 #3
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;
   }
 }
コード例 #4
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();
 }
コード例 #5
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;
 }
コード例 #6
0
ファイル: Toolkit.java プロジェクト: andreasbaumann/tomato
  /**
   * 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());
    }
  }
コード例 #7
0
ファイル: JRootApp.java プロジェクト: jhanysel/SysNeo-POS
  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();
  }
コード例 #8
0
ファイル: GUI.java プロジェクト: sametkaya/BLM305
 boolean tryDir(String d) {
   ClassLoader L = getClass().getClassLoader();
   File p = new File(d, PACKAGE);
   // System.out.println("Try "+p);
   if (!p.exists() || !p.isDirectory()) return false;
   for (File f : p.listFiles()) {
     String s = f.getName();
     if (!s.endsWith(".class")) continue;
     String name = s.substring(0, s.length() - 6);
     try {
       Class<?> c = L.loadClass(PACKAGE + "." + name);
       if (!Quotation.class.isAssignableFrom(c)) continue;
       Q.put(name, (Quotation) c.newInstance());
       System.out.println("  " + name);
       // ClassNotFoundException InstantiationException IllegalAccessException
     } catch (Exception e) {
       continue;
     }
   }
   return Q.size() > 0;
 }
コード例 #9
0
    protected void loadAirspacesFromPath(String path, Collection<Airspace> airspaces) {
      File file = ExampleUtil.saveResourceToTempFile(path, ".zip");
      if (file == null) return;

      try {
        ZipFile zipFile = new ZipFile(file);

        ZipEntry entry = null;
        for (Enumeration<? extends ZipEntry> e = zipFile.entries();
            e.hasMoreElements();
            entry = e.nextElement()) {
          if (entry == null) continue;

          String name = WWIO.getFilename(entry.getName());

          if (!(name.startsWith("gov.nasa.worldwind.render.airspaces") && name.endsWith(".xml")))
            continue;

          String[] tokens = name.split("-");

          try {
            Class c = Class.forName(tokens[0]);
            Airspace airspace = (Airspace) c.newInstance();
            BufferedReader input =
                new BufferedReader(new InputStreamReader(zipFile.getInputStream(entry)));
            String s = input.readLine();
            airspace.restoreState(s);
            airspaces.add(airspace);

            if (tokens.length >= 2) {
              airspace.setValue(AVKey.DISPLAY_NAME, tokens[1]);
            }
          } catch (Exception ex) {
            ex.printStackTrace();
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
コード例 #10
0
 /** Reaction to buttons and combo boxes. */
 public void actionPerformed(ActionEvent e) {
   String cmd = e.getActionCommand();
   if (cmdCtrlProp.equals(cmd)) {
     try {
       Class c =
           Class.forName("aurora.hwc.control.Panel" + myController.getClass().getSimpleName());
       AbstractPanelController cp = (AbstractPanelController) c.newInstance();
       cp.initialize(myController, null);
     } catch (Exception ex) {
     }
   }
   if (cmdCtrlList.equals(cmd)) {
     JComboBox cb = (JComboBox) e.getSource();
     if (cb.getSelectedIndex() > 0) {
       myController = (AbstractControllerComplex) listCControllers.getSelectedItem();
       buttonProp.setEnabled(true);
     } else {
       buttonProp.setEnabled(false);
       myController = null;
     }
     myMonitor.setMyController(myController);
   }
   return;
 }
コード例 #11
0
ファイル: WhatsNew.java プロジェクト: tzkiki32/quollwriter
  public WhatsNew(AbstractProjectViewer pv, boolean onlyShowCurrentVersion)
      throws GeneralException {

    super(pv);

    String wn = Environment.getProperty(Constants.WHATS_NEW_VERSION_VIEWED_PROPERTY_NAME);

    if (wn == null) {

      wn = "0";
    }

    // Get the current whats new version (i.e. old).
    Version lastWhatsNewVersion = new Version(wn);

    boolean betasAllowed =
        Environment.getUserProperties()
            .getPropertyAsBoolean(Constants.OPTIN_TO_BETA_VERSIONS_PROPERTY_NAME);

    try {

      String whatsNew = Environment.getResourceFileAsString(Constants.WHATS_NEW_FILE);

      // Load up all the whats new for greater versions.
      Element root = JDOMUtils.getStringAsElement(whatsNew);

      java.util.List verEls = JDOMUtils.getChildElements(root, XMLConstants.version, false);

      // Assume they are in the right order
      // TODO: Enforce the order and/or sort.
      for (int i = 0; i < verEls.size(); i++) {

        Element vEl = (Element) verEls.get(i);

        String id = JDOMUtils.getAttributeValue(vEl, XMLConstants.id, true);

        Version v = new Version(id);
        /*
                      if ((v.isBeta ())
                          &&
                          (!betasAllowed)
                         )
                      {

                          // Ignore, the user isn't interested in betas.
                          continue;

                      }
        */
        if ((lastWhatsNewVersion.isNewer(v))
            || ((onlyShowCurrentVersion) && (v.isSame(Environment.getQuollWriterVersion())))) {

          String c = WhatsNewComponentProvider.class.getName();

          int ind = c.lastIndexOf(".");

          if (ind > 0) {

            c = c.substring(0, ind);
          }

          WhatsNewComponentProvider compProv = null;

          String cl = JDOMUtils.getAttributeValue(vEl, XMLConstants.clazz, false);

          if (!cl.equals("")) {

            Class clz = null;

            try {

              clz = Class.forName(cl);

              if (WhatsNewComponentProvider.class.isAssignableFrom(clz)) {

                compProv = (WhatsNewComponentProvider) clz.newInstance();
              }

            } catch (Exception e) {

            }
          }

          // This is a version we are interested in.
          java.util.List itemEls =
              JDOMUtils.getChildElements(vEl, WhatsNewItem.XMLConstants.root, true);

          java.util.List<WhatsNewItem> its = new ArrayList();

          for (int j = 0; j < itemEls.size(); j++) {

            Element itEl = (Element) itemEls.get(j);

            WhatsNewItem it = new WhatsNewItem(itEl, compProv, pv);

            if (it.onlyIfCurrentVersion) {

              if (!Environment.getQuollWriterVersion().isSame(v)) {

                continue;
              }
            }

            if ((it.description == null) && (it.component == null)) {

              Environment.logMessage(
                  "Whats new item has no description or component, referenced by: "
                      + JDOMUtils.getPath(itEl));

              continue;
            }

            its.add(it);
          }

          if (its.size() > 0) {

            this.items.put(v, its);
          }
        }
      }

    } catch (Exception e) {

      throw new GeneralException("Unable to init whats new", e);
    }
  }
コード例 #12
0
  /** Generates Configuration tab. */
  private void fillConfigurationPanel() {
    JPanel desc = new JPanel(new GridLayout(2, 0));
    desc.setBorder(BorderFactory.createTitledBorder("Description"));
    desc.add(
        new JLabel("<html><font color=\"blue\">" + myMonitor.getDescription() + "</font></html>"));
    desc.add(cbEnabled);
    cbEnabled.setSelected(enabled);
    cbEnabled.addChangeListener(this);
    confPanel.add(desc);
    JPanel mlpanel = new JPanel(new GridLayout(1, 0));
    mlpanel.setBorder(BorderFactory.createTitledBorder("Monitored Network Elements"));
    montable = new JTable(montablemodel);
    montable.setPreferredScrollableViewportSize(new Dimension(200, 100));
    montable.getColumnModel().getColumn(0).setPreferredWidth(140);
    montable.getColumnModel().getColumn(1).setPreferredWidth(60);
    montable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              int row = montable.rowAtPoint(new Point(e.getX(), e.getY()));
              AbstractNetworkElement ne = null;
              if ((row >= 0) && (row < myMonitor.getPredecessors().size()))
                ne = myMonitor.getPredecessors().get(row);
              else return;
              treePane.actionSelected(ne, true);
            }
            return;
          }
        });
    mlpanel.add(new JScrollPane(montable));
    confPanel.add(mlpanel);
    JPanel cpanel = new JPanel(new GridLayout(1, 0));
    cpanel.setBorder(BorderFactory.createTitledBorder("Controlleded Network Elements"));
    ctrltable = new JTable(ctrltablemodel);
    ctrltable.setPreferredScrollableViewportSize(new Dimension(200, 100));
    ctrltable.getColumnModel().getColumn(0).setPreferredWidth(140);
    ctrltable.getColumnModel().getColumn(1).setPreferredWidth(60);
    ctrltable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
              int row = ctrltable.rowAtPoint(new Point(e.getX(), e.getY()));
              AbstractNetworkElement ne = null;
              if ((row >= 0) && (row < myMonitor.getSuccessors().size()))
                ne = myMonitor.getSuccessors().get(row);
              else return;
              treePane.actionSelected(ne, true);
            }
            return;
          }
        });
    cpanel.add(new JScrollPane(ctrltable));
    confPanel.add(cpanel);
    JPanel pcl = new JPanel(new FlowLayout());
    // controller list
    buttonProp.setEnabled(false);
    buttonProp.setActionCommand(cmdCtrlProp);
    buttonProp.addActionListener(this);
    pcl.setBorder(BorderFactory.createTitledBorder("Complex Controller"));
    buttonProp.setEnabled(false);
    listCControllers = new JComboBox();
    listCControllers.addItem("None");
    String[] ctrlClasses = myMonitor.getComplexControllerClasses();
    for (int i = 0; i < ctrlClasses.length; i++) {
      if ((myController != null)
          && (myController.getClass().getName().compareTo(ctrlClasses[i]) == 0)) {
        listCControllers.addItem(myController);
        listCControllers.setSelectedIndex(i + 1);
        buttonProp.setEnabled(true);
      } else {
        try {
          Class cl = Class.forName(ctrlClasses[i]);
          AbstractControllerComplex cc = (AbstractControllerComplex) cl.newInstance();
          cc.setMyMonitor(myMonitor);
          cc.initialize();
          listCControllers.addItem(cc);
        } catch (Exception e) {
        }
      }
    }
    listCControllers.setActionCommand(cmdCtrlList);
    listCControllers.addActionListener(this);
    pcl.add(listCControllers);
    pcl.add(buttonProp);
    confPanel.add(pcl);

    return;
  }
コード例 #13
0
  public QSAdminGUI(QSAdminMain qsadminMain, JFrame parentFrame) {
    this.parentFrame = parentFrame;
    Container cp = this;
    qsadminMain.setGUI(this);
    cp.setLayout(new BorderLayout(5, 5));
    headerPanel = new HeaderPanel(qsadminMain, parentFrame);
    mainCommandPanel = new MainCommandPanel(qsadminMain);
    cmdConsole = new CmdConsole(qsadminMain);
    propertiePanel = new PropertiePanel(qsadminMain);

    if (headerPanel == null
        || mainCommandPanel == null
        || cmdConsole == null
        || propertiePanel == null) {
      throw new RuntimeException("Loading of one of gui component failed.");
    }

    headerPanel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    cp.add(headerPanel, BorderLayout.NORTH);
    JScrollPane propertieScrollPane = new JScrollPane(propertiePanel);
    // JScrollPane commandScrollPane = new JScrollPane(mainCommandPanel);
    JSplitPane splitPane =
        new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, mainCommandPanel, cmdConsole);
    splitPane.setOneTouchExpandable(false);
    splitPane.setDividerLocation(250);
    // splitPane.setDividerLocation(0.70);

    tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.addTab("Main", ball, splitPane, "Main Commands");
    tabbedPane.addTab("Get/Set", ball, propertieScrollPane, "Properties Panel");

    QSAdminPluginConfig qsAdminPluginConfig = null;
    PluginPanel pluginPanel = null;
    // -- start of loadPlugins
    try {
      File xmlFile = null;
      ClassLoader classLoader = null;
      Class mainClass = null;

      File file = new File(pluginDir);
      File dirs[] = null;

      if (file.canRead()) dirs = file.listFiles(new DirFileList());

      for (int i = 0; dirs != null && i < dirs.length; i++) {
        xmlFile = new File(dirs[i].getAbsolutePath() + File.separator + "plugin.xml");
        if (xmlFile.canRead()) {
          qsAdminPluginConfig = PluginConfigReader.read(xmlFile);
          if (qsAdminPluginConfig.getActive().equals("yes")
              && qsAdminPluginConfig.getType().equals("javax.swing.JPanel")) {
            classLoader = ClassUtil.getClassLoaderFromJars(dirs[i].getAbsolutePath());
            mainClass = classLoader.loadClass(qsAdminPluginConfig.getMainClass());
            logger.fine("Got PluginMainClass " + mainClass);
            pluginPanel = (PluginPanel) mainClass.newInstance();
            if (JPanel.class.isInstance(pluginPanel) == true) {
              logger.info("Loading plugin : " + qsAdminPluginConfig.getName());
              pluginPanelMap.put("" + (2 + i), pluginPanel);
              plugins.add(pluginPanel);
              tabbedPane.addTab(
                  qsAdminPluginConfig.getName(),
                  ball,
                  (JPanel) pluginPanel,
                  qsAdminPluginConfig.getDesc());
              pluginPanel.setQSAdminMain(qsadminMain);
              pluginPanel.init();
            }
          } else {
            logger.info(
                "Plugin "
                    + dirs[i]
                    + " is disabled so skipping "
                    + qsAdminPluginConfig.getActive()
                    + ":"
                    + qsAdminPluginConfig.getType());
          }
        } else {
          logger.info("No plugin configuration found in " + xmlFile + " so skipping");
        }
      }
    } catch (Exception e) {
      logger.warning("Error loading plugin : " + e);
      logger.fine("StackTrace:\n" + MyString.getStackTrace(e));
    }
    // -- end of loadPlugins

    tabbedPane.addChangeListener(
        new ChangeListener() {
          int selected = -1;
          int oldSelected = -1;

          public void stateChanged(ChangeEvent e) {
            // if plugin
            selected = tabbedPane.getSelectedIndex();
            if (selected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + selected)).activated();
            }
            if (oldSelected >= 2) {
              ((PluginPanel) pluginPanelMap.get("" + oldSelected)).deactivated();
            }
            oldSelected = selected;
          }
        });

    // tabbedPane.setBorder(BorderFactory.createEmptyBorder(0,5,5,5));
    cp.add(tabbedPane, BorderLayout.CENTER);

    buildMenu();
  }