protected void uninstallListeners() { if (propertyChangeListener != null) { optionPane.removePropertyChangeListener(propertyChangeListener); propertyChangeListener = null; } handler = null; }
/** * Shows dialog and wait for answer. Returns next dialog, or null if it there is no next dialog. */ public final ConfigDialog showDialog() { /* making non modal dialog */ dialogGate = new CountDownLatch(1); dialogPanel = null; /* TODO: disabled caching because back button wouldn't work with dialogPanel.setContentPane(optionPane) method it would work with optionPane.createDialog... but that causes lockups with old javas and gnome. */ if (dialogPanel == null) { final ImageIcon[] icons = getIcons(); MyButton defaultButtonClass = null; final List<JComponent> allOptions = new ArrayList<JComponent>(additionalOptions); if (skipButtonEnabled()) { skipButton = new JCheckBox(Tools.getString("Dialog.ConfigDialog.SkipButton")); skipButton.setEnabled(false); skipButton.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light")); skipButton.addItemListener(skipButtonListener()); allOptions.add(skipButton); } final String[] buttons = buttons(); /* populate buttonToObjectMap */ for (int i = 0; i < buttons.length; i++) { options[i] = new MyButton(buttons[i], icons[i]); options[i].setBackgroundColor(Tools.getDefaultColor("ConfigDialog.Button")); allOptions.add(options[i]); buttonToObjectMap.put(buttons[i], options[i]); if (buttons[i].equals(defaultButton())) { defaultButtonClass = options[i]; } } /* create option pane */ final JPanel b = body(); final MyButton dbc = defaultButtonClass; Tools.invokeAndWait( new Runnable() { public void run() { optionPane = new JOptionPane( b, getMessageType(), JOptionPane.DEFAULT_OPTION, icon(), allOptions.toArray(new JComponent[allOptions.size()]), dbc); optionPane.setPreferredSize(new Dimension(dialogWidth(), dialogHeight())); optionPane.setMaximumSize(new Dimension(dialogWidth(), dialogHeight())); optionPane.setMinimumSize(new Dimension(dialogWidth(), dialogHeight())); optionPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Dark")); final Container mainFrame = Tools.getGUIData().getMainFrame(); if (mainFrame instanceof JApplet) { final JFrame noframe = new JFrame(); dialogPanel = new JDialog(noframe); dialogPanel.setContentPane(optionPane); } else { dialogPanel = new JDialog((JFrame) mainFrame); dialogPanel.setContentPane(optionPane); } dialogPanel.setModal(false); dialogPanel.setResizable(true); } }); /* set location like the previous dialog */ } /* add action listeners */ final Map<MyButton, OptionPaneActionListener> optionPaneActionListeners = new HashMap<MyButton, OptionPaneActionListener>(); for (final MyButton o : options) { final OptionPaneActionListener ol = new OptionPaneActionListener(); optionPaneActionListeners.put(o, ol); o.addActionListener(ol); } final PropertyChangeListener propertyChangeListener = new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent evt) { if (JOptionPane.VALUE_PROPERTY.equals(evt.getPropertyName()) && !"uninitializedValue".equals(evt.getNewValue())) { optionPaneAnswer = optionPane.getValue(); dialogGate.countDown(); } } }; optionPane.addPropertyChangeListener(propertyChangeListener); initDialog(); Tools.invokeAndWait( new Runnable() { public void run() { dialogPanel.setPreferredSize(new Dimension(dialogWidth(), dialogHeight())); dialogPanel.setMaximumSize(new Dimension(dialogWidth(), dialogHeight())); dialogPanel.setMinimumSize(new Dimension(dialogWidth(), dialogHeight())); dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrame()); dialogPanel.setVisible(true); } }); SwingUtilities.invokeLater( new Runnable() { public void run() { dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrameContentPane()); /* although the location was set before, it is set again as a * workaround for gray dialogs with nothing in it, that appear * in some comination of Java and compiz. */ } }); initDialogAfterVisible(); try { dialogGate.await(); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); } if (optionPaneAnswer instanceof String) { setPressedButton((String) optionPaneAnswer); } else { setPressedButton(cancelButton()); } optionPane.removePropertyChangeListener(propertyChangeListener); /* remove action listeners */ for (final MyButton o : options) { o.removeActionListener(optionPaneActionListeners.get(o)); } dialogPanel.dispose(); return checkAnswer(); }