|
64 | 64 | * an instance of JColorChooser.ASYNCHRONOUS_COLOR, testable as ret instanceof |
65 | 65 | * javax.swing.UIResource if the parent component implements |
66 | 66 | * PropertyChangeListener, or null if not. The final result of color selection |
67 | | - * will be returned by a PropertyChangeEvent with propertyName "SelectedColor". |
| 67 | + * will be returned by a PropertyChangeEvent with propertyName "SelectedColor" |
| 68 | + * if there are no ok/cancel action listeners defined. |
68 | 69 | * |
69 | 70 | * The parent component will automatically be registered as a listener for the |
70 | | - * created instance of JColorChooser, it is a PropertyChangeListener. |
| 71 | + * created instance of JColorChooser, it is a PropertyChangeListener only when |
| 72 | + * no action listener is indicated. |
71 | 73 | * |
72 | 74 | * <code>JColorChooser</code> provides a pane of controls designed to allow a |
73 | 75 | * user to manipulate and select a color. For information about using color |
|
110 | 112 | */ |
111 | 113 | public class JColorChooser extends JComponent { |
112 | 114 |
|
| 115 | + |
113 | 116 | private ColorSelectionModel selectionModel; |
114 | 117 |
|
115 | 118 | private JComponent previewPanel; |
@@ -223,7 +226,6 @@ public static JDialog createDialog(Component c, String title, boolean modal, JCo |
223 | 226 |
|
224 | 227 | private static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane, |
225 | 228 | ActionListener okListener, ActionListener cancelListener, boolean disposeOnHide) { |
226 | | - |
227 | 229 | Window window = JOptionPane.getWindowForComponent(c); |
228 | 230 | ColorChooserDialog dialog; |
229 | 231 | if (window instanceof Frame) { |
@@ -627,15 +629,20 @@ public ColorChooserDialog(Frame owner, String title, boolean modal, Component c, |
627 | 629 | initColorChooserDialog(c, chooserPane, okListener, cancelListener); |
628 | 630 | } |
629 | 631 |
|
| 632 | + private boolean haveActionListener; |
| 633 | + |
| 634 | + |
630 | 635 | protected void initColorChooserDialog(Component c, JColorChooser chooserPane, |
631 | 636 | ActionListener okListener, ActionListener cancelListener) { |
632 | 637 | //setResizable(false); |
| 638 | + haveActionListener = (okListener != null || cancelListener != null); |
633 | 639 |
|
634 | 640 | if (!(c instanceof PropertyChangeListener)) { |
635 | 641 | System.out.println("JColorChooser: no onDialogReturn(Object) found in component " + c); |
636 | 642 | } |
637 | 643 |
|
638 | | - ensurePropertyChangeListener(this, c); |
| 644 | + if (okListener == null && cancelListener == null) |
| 645 | + ensurePropertyChangeListener(this, c); |
639 | 646 |
|
640 | 647 | this.chooserPane = chooserPane; |
641 | 648 |
|
@@ -731,7 +738,8 @@ public void actionPerformed(ActionEvent e) { |
731 | 738 | } |
732 | 739 |
|
733 | 740 | protected void doCallback(boolean isOK) { |
734 | | - firePropertyChange("SelectedColor", null, (isOK ? chooserPane.getSelectionModel().getSelectedColor() : null)); |
| 741 | + if (!haveActionListener) |
| 742 | + firePropertyChange("SelectedColor", null, (isOK ? chooserPane.getSelectionModel().getSelectedColor() : null)); |
735 | 743 | hide(); |
736 | 744 | if (disposeOnHide) |
737 | 745 | dispose(); |
|
0 commit comments