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); }
/** 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); }
/** 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(); } } }
/** * 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(); }
/** * @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); }
protected void completeConfiguration() throws ConfigException { myConfigManager.getConfigurable().completeConfiguration(createConfigResult()); }