Exemplo n.º 1
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;
 }
Exemplo n.º 2
0
  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);
    }
  }
Exemplo n.º 3
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();
  }