Beispiel #1
0
  /** Adds property descriptors to the panel */
  protected void addDescriptors(List<Property> propDescriptors) {
    if (propertyInputPanels == null) {
      propertyInputPanels = new Vector<PropertyInputPanel>(propDescriptors.size());
    }

    MutableAttributeSet properties = myConfigManager.getProperties();

    for (Property property : propDescriptors) {

      PropertyInputPanel inputPanel = property.getInputPanel();
      myPropertyPanel.add(inputPanel.getJPanel());

      /*
       * Try to get the configurer's current value and apply it to the
       * input panels
       */
      Object currentValue = properties.getAttribute(inputPanel.getName());
      if (currentValue != null) {
        inputPanel.setValue(currentValue);
      }

      propertyInputPanels.add(inputPanel);
    }

    checkPropreties();
    updateBounds();
  }
Beispiel #2
0
  /** User wants to cancel the configuration */
  private void cancelAction() {

    // setVisible(false);   // doing both this and dispose() seems to cause problems in OpenJDK (the
    // setVisible(true) call never returns)

    myConfigManager.dialogConfigurationFinished(new ConfigDialogClosedException());
    super.dispose();
  }
Beispiel #3
0
  private void advancedAction() {
    if (!isAdvancedShown) {
      isAdvancedShown = true;
      List<Property> advancedDescriptors =
          myConfigManager.getConfigurable().getSchema().getAdvancedProperties();

      addDescriptors(advancedDescriptors);
    }
    // hide the button once it's been pressed
    advancedButton.setVisible(false);
  }
Beispiel #4
0
  /** Creates ok, cancel buttons on the dialog */
  private void createButtons(JPanel panel) {
    JPanel buttonsPanel = new VerticalLayoutPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.X_AXIS));
    buttonsPanel.add(Box.createHorizontalGlue());
    buttonsPanel.setBorder(BorderFactory.createEmptyBorder(15, 0, 5, 5));

    JButton addToWorldButton = new JButton("Ok");
    ActionListener okActionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            okAction();
          }
        };
    addToWorldButton.addActionListener(okActionListener);
    addToWorldButton.registerKeyboardAction(
        okActionListener,
        KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
        JComponent.WHEN_IN_FOCUSED_WINDOW);
    buttonsPanel.add(addToWorldButton);

    JButton cancelButton = new JButton("Cancel");
    ActionListener cancelActionListener =
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            cancelAction();
          }
        };
    cancelButton.addActionListener(cancelActionListener);
    cancelButton.registerKeyboardAction(
        cancelActionListener,
        KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
        JComponent.WHEN_IN_FOCUSED_WINDOW);
    buttonsPanel.add(cancelButton);

    advancedButton = new JButton("Advanced");
    advancedButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            advancedAction();
          }
        });
    buttonsPanel.add(advancedButton);

    if (myConfigManager.getConfigurable().getSchema().getAdvancedProperties().size() == 0) {
      advancedButton.setVisible(false);
    }

    panel.add(buttonsPanel);
  }
Beispiel #5
0
  /** What happens when the user presses the OK button */
  private void okAction() {
    if (applyProperties()) {
      boolean preConfigurationSuccess = true;
      try {
        myConfigManager.getConfigurable().preConfiguration(createConfigResult());
      } catch (ConfigException e1) {
        e1.defaultHandleBehavior();
        preConfigurationSuccess = false;
      }

      if (preConfigurationSuccess) {
        // setVisible(false);  // doing both this and dispose() seems to cause problems in OpenJDK
        // (the setVisible(true) call never returns)
        dispose();

        (new TrackedAction("Configuring " + myConfigManager.getConfigurable().getTypeName()) {

              private static final long serialVersionUID = 1L;

              @Override
              protected void action() throws ActionException {
                ConfigException configException = null;

                try {
                  completeConfiguration();
                } catch (ConfigException e) {
                  configException = e;
                }

                myConfigManager.dialogConfigurationFinished(configException);
              }
            })
            .doAction();
      }
    }
  }
Beispiel #6
0
  /**
   * Initialization to be called from the constructor
   *
   * @param configManager Configuration manager parent
   * @param owner Component the dialog is to be added to
   */
  protected void initialize(UserConfigurer configManager, Component owner) {
    this.myConfigManager = configManager;
    this.owner = owner;

    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    addWindowListener(
        new java.awt.event.WindowAdapter() {
          @Override
          public void windowClosing(java.awt.event.WindowEvent evt) {
            cancelAction();
          }
        });

    setResizable(false);
    setModal(true);

    myPanel = new VerticalLayoutPanel();
    myPanel.setVisible(true);
    myPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    initPanelTop(myPanel);

    myPropertyPanel = new VerticalLayoutPanel();
    myPanel.add(myPropertyPanel);

    addDescriptors(configManager.getConfigurable().getSchema().getProperties());

    initPanelBottom(myPanel);

    createButtons(myPanel);

    // add(myPanel);

    while (true) {
      try {
        add(myPanel);
        break;
      } catch (RuntimeException e) {
        // e.printStackTrace();
        // Ubuntu 11.04 throws a sun.awt.X11.XException ~80% of the time here
      }
    }

    setMinimumSize(new Dimension(200, this.getHeight()));
    updateBounds();
  }
Beispiel #7
0
  /**
   * @param setPropertyFields if True, the user's values will be applied to the properties set
   * @return Whether the user has set all the values on the dialog correctly
   */
  private boolean processPropertiesInternal(boolean setPropertyFields, boolean showMessage) {
    Iterator<PropertyInputPanel> it = propertyInputPanels.iterator();

    while (it.hasNext()) {
      PropertyInputPanel inputPanel = it.next();
      Property property = inputPanel.getDescriptor();

      if (inputPanel.isValueSet()) {
        if (setPropertyFields) {

          myConfigManager.setProperty(property.getName(), inputPanel.getValue());
        }
      } else {
        if (showMessage) {
          UserMessages.showWarning(property.getName() + " is not set or is incomplete");
        }
        pack();
        return false;
      }
    }
    pack();
    return true;
  }
Beispiel #8
0
  /**
   * @param configManager Parent Configuration Manager
   * @param owner Component this dialog shall be added to
   */
  public ConfigDialog(UserConfigurer configManager, Dialog owner) {
    super(owner, configManager.getConfigurable().getDescription());

    initialize(configManager, owner);
  }
Beispiel #9
0
 private ConfigResult createConfigResult() {
   return new ConfigResult(myConfigManager.getProperties());
 }
Beispiel #10
0
 protected void completeConfiguration() throws ConfigException {
   myConfigManager.getConfigurable().completeConfiguration(createConfigResult());
 }