/** Returns the ClassMemberSpecification currently represented in this dialog. */
  public ClassMemberSpecification getClassMemberSpecification() {
    String name = nameTextField.getText();
    String type = typeTextField.getText();
    String arguments = argumentsTextField.getText();

    if (name.equals("") || name.equals("*")) {
      name = null;
    }

    if (type.equals("") || type.equals("*")) {
      type = null;
    }

    if (name != null || type != null) {
      if (isField) {
        if (type == null) {
          type = ClassConstants.EXTERNAL_TYPE_INT;
        }

        type = ClassUtil.internalType(type);
      } else {
        if (type == null) {
          type = ClassConstants.EXTERNAL_TYPE_VOID;
        }

        type = ClassUtil.internalMethodDescriptor(type, ListUtil.commaSeparatedList(arguments));
      }
    }

    ClassMemberSpecification classMemberSpecification =
        new ClassMemberSpecification(0, 0, name, type);

    // Also get the access radio button settings.
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification,
        ClassConstants.INTERNAL_ACC_SYNCHRONIZED,
        synchronizedRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons);
    getClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STRICT, strictRadioButtons);

    return classMemberSpecification;
  }
  /** Sets the ClassMemberSpecification to be represented in this dialog. */
  public void setClassMemberSpecification(ClassMemberSpecification classMemberSpecification) {
    String name = classMemberSpecification.name;
    String descriptor = classMemberSpecification.descriptor;

    // Set the access radio buttons.
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PUBLIC, publicRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PRIVATE, privateRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_PROTECTED, protectedRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STATIC, staticRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_FINAL, finalRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_VOLATILE, volatileRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_TRANSIENT, transientRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification,
        ClassConstants.INTERNAL_ACC_SYNCHRONIZED,
        synchronizedRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_NATIVE, nativeRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_ABSTRACT, abstractRadioButtons);
    setClassMemberSpecificationRadioButtons(
        classMemberSpecification, ClassConstants.INTERNAL_ACC_STRICT, strictRadioButtons);

    // Set the class name text fields.
    nameTextField.setText(name == null ? "" : name);

    if (isField) {
      typeTextField.setText(descriptor == null ? "" : ClassUtil.externalType(descriptor));
    } else {
      typeTextField.setText(
          descriptor == null ? "" : ClassUtil.externalMethodReturnType(descriptor));
      argumentsTextField.setText(
          descriptor == null ? "" : ClassUtil.externalMethodArguments(descriptor));
    }
  }
Esempio 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();
  }