Skip to content

Commit 9d5ebbe

Browse files
hansonrhansonr
authored andcommitted
row sorter fixes
1 parent f0c67c5 commit 9d5ebbe

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

sources/net.sf.j2s.java.core/src/javax/swing/JColorChooser.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@
6464
* an instance of JColorChooser.ASYNCHRONOUS_COLOR, testable as ret instanceof
6565
* javax.swing.UIResource if the parent component implements
6666
* 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.
6869
*
6970
* 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.
7173
*
7274
* <code>JColorChooser</code> provides a pane of controls designed to allow a
7375
* user to manipulate and select a color. For information about using color
@@ -110,6 +112,7 @@
110112
*/
111113
public class JColorChooser extends JComponent {
112114

115+
113116
private ColorSelectionModel selectionModel;
114117

115118
private JComponent previewPanel;
@@ -223,7 +226,6 @@ public static JDialog createDialog(Component c, String title, boolean modal, JCo
223226

224227
private static JDialog createDialog(Component c, String title, boolean modal, JColorChooser chooserPane,
225228
ActionListener okListener, ActionListener cancelListener, boolean disposeOnHide) {
226-
227229
Window window = JOptionPane.getWindowForComponent(c);
228230
ColorChooserDialog dialog;
229231
if (window instanceof Frame) {
@@ -627,15 +629,20 @@ public ColorChooserDialog(Frame owner, String title, boolean modal, Component c,
627629
initColorChooserDialog(c, chooserPane, okListener, cancelListener);
628630
}
629631

632+
private boolean haveActionListener;
633+
634+
630635
protected void initColorChooserDialog(Component c, JColorChooser chooserPane,
631636
ActionListener okListener, ActionListener cancelListener) {
632637
//setResizable(false);
638+
haveActionListener = (okListener != null || cancelListener != null);
633639

634640
if (!(c instanceof PropertyChangeListener)) {
635641
System.out.println("JColorChooser: no onDialogReturn(Object) found in component " + c);
636642
}
637643

638-
ensurePropertyChangeListener(this, c);
644+
if (okListener == null && cancelListener == null)
645+
ensurePropertyChangeListener(this, c);
639646

640647
this.chooserPane = chooserPane;
641648

@@ -731,7 +738,8 @@ public void actionPerformed(ActionEvent e) {
731738
}
732739

733740
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));
735743
hide();
736744
if (disposeOnHide)
737745
dispose();

0 commit comments

Comments
 (0)