Esempio n. 1
0
  void buildConfigPanel() {
    try {
      Config config = playerObjects.getConfig();
      for (Field field : config.getClass().getDeclaredFields()) {
        Annotation excludeAnnotation = field.getAnnotation(ReflectionHelper.Exclude.class);
        if (excludeAnnotation == null) { // so, this field is not excluded
          Class<?> fieldType = field.getType();
          Method getMethod = getGetMethod(config.getClass(), field.getType(), field.getName());
          if (getMethod != null) {
            Object value = getMethod.invoke(config);
            if (fieldType == String.class) {
              addTextBox(field.getName(), (String) value);
            }
            if (fieldType == boolean.class || fieldType == Boolean.class) {
              addBooleanComponent(field.getName(), (Boolean) value);
            }
            if (fieldType == float.class || fieldType == Float.class) {
              addTextBox(field.getName(), "" + value);
            }
            if (fieldType == int.class || fieldType == Integer.class) {
              addTextBox(field.getName(), "" + value);
            }
          } else {
            playerObjects
                .getLogFile()
                .WriteLine("No get accessor method for config field " + field.getName());
          }
        }
      }
    } catch (Exception e) {
      playerObjects.getLogFile().WriteLine(Formatting.exceptionToStackTrace(e));
    }

    configGridLayout.setRows(configGridLayout.getRows() + 2);

    configRevertButton = new JButton("Revert");
    configReloadButton = new JButton("Reload");
    configApplyButton = new JButton("Apply");
    configSaveButton = new JButton("Save");

    configRevertButton.addActionListener(new ConfigRevert());
    configReloadButton.addActionListener(new ConfigReload());
    configApplyButton.addActionListener(new ConfigApply());
    configSaveButton.addActionListener(new ConfigSave());

    configPanel.add(configRevertButton);
    configPanel.add(configReloadButton);
    configPanel.add(configApplyButton);
    configPanel.add(configSaveButton);
  }
Esempio n. 2
0
  void addBooleanComponent(String name, boolean currentValue) {
    configGridLayout.setRows(configGridLayout.getRows() + 1);
    addConfigLabel(name);

    JCheckBox checkBox = new JCheckBox();
    checkBox.setSelected(currentValue);

    componentByName.put(name, checkBox);
    configPanel.add(checkBox);
  }
Esempio n. 3
0
  void addTextBox(String name, String currentValue) {
    configGridLayout.setRows(configGridLayout.getRows() + 1);
    addConfigLabel(name);

    JTextField textField = new JTextField();
    textField.setText(currentValue);

    componentByName.put(name, textField);
    configPanel.add(textField);
  }
Esempio n. 4
0
 void addConfigLabel(String labelName) {
   JLabel label = new JLabel(labelName);
   configPanel.add(label);
 }