Skip to content

Commit 3b77bf8

Browse files
committed
JFileChooser set to allow itself to be the property listener
1 parent 75191e3 commit 3b77bf8

File tree

3 files changed

+662
-681
lines changed

3 files changed

+662
-681
lines changed

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

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
/*
2-
* Some portions of this file have been modified by Robert Hanson hansonr.at.stolaf.edu 2012-2017
3-
* for use in SwingJS via transpilation into JavaScript using Java2Script.
4-
*
52
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
63
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
74
*
@@ -28,7 +25,7 @@
2825

2926
package javax.swing;
3027

31-
//import sun.awt.AWTAccessor;
28+
import sun.awt.AWTAccessor;
3229

3330
/**
3431
* An enumeration for keys used as client properties within the Swing
@@ -84,22 +81,22 @@ enum ClientPropertyKey {
8481
PopupFactory_FORCE_HEAVYWEIGHT_POPUP(true);
8582

8683

87-
// /**
88-
// * Whether or not a {@code NotSerializableException} should be thrown
89-
// * during serialization, when the value associated with this key does
90-
// * not implement {@code Serializable}.
91-
// */
92-
// private final boolean reportValueNotSerializable;
93-
//
84+
/**
85+
* Whether or not a {@code NotSerializableException} should be thrown
86+
* during serialization, when the value associated with this key does
87+
* not implement {@code Serializable}.
88+
*/
89+
private final boolean reportValueNotSerializable;
90+
9491
// static {
9592
// AWTAccessor.setClientPropertyKeyAccessor(
9693
// new AWTAccessor.ClientPropertyKeyAccessor() {
97-
// public Object getJComponent_TRANSFER_HANDLER() {
98-
// return JComponent_TRANSFER_HANDLER;
99-
// }
94+
public Object getJComponent_TRANSFER_HANDLER() {
95+
return JComponent_TRANSFER_HANDLER;
96+
}
10097
// });
10198
// }
102-
//
99+
103100
/**
104101
* Constructs a key with the {@code reportValueNotSerializable} property
105102
* set to {@code false}.
@@ -113,15 +110,15 @@ private ClientPropertyKey() {
113110
* set to the given value.
114111
*/
115112
private ClientPropertyKey(boolean reportValueNotSerializable) {
116-
// this.reportValueNotSerializable = reportValueNotSerializable;
113+
this.reportValueNotSerializable = reportValueNotSerializable;
117114
}
118115

119-
// /**
120-
// * Returns whether or not a {@code NotSerializableException} should be thrown
121-
// * during serialization, when the value associated with this key does
122-
// * not implement {@code Serializable}.
123-
// */
124-
// public boolean getReportValueNotSerializable() {
125-
// return reportValueNotSerializable;
126-
// }
116+
/**
117+
* Returns whether or not a {@code NotSerializableException} should be thrown
118+
* during serialization, when the value associated with this key does
119+
* not implement {@code Serializable}.
120+
*/
121+
public boolean getReportValueNotSerializable() {
122+
return reportValueNotSerializable;
123+
}
127124
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -763,12 +763,17 @@ public int showDialog(Component parent, String approveButtonText) {
763763
JSUtil.notImplemented("JFileChooser.CUSTOM_DIALOG");
764764
return CANCEL_OPTION;
765765
case OPEN_DIALOG:
766-
if (!(parent instanceof PropertyChangeListener)) {
766+
if (!(parent instanceof PropertyChangeListener) && !(this instanceof PropertyChangeListener)) {
767767
warnJSDeveloper();
768768
return CANCEL_OPTION;
769769
}
770-
removePropertyChangeListener((PropertyChangeListener) parent);
771-
addPropertyChangeListener((PropertyChangeListener) parent);
770+
if (this instanceof PropertyChangeListener) {
771+
removePropertyChangeListener((PropertyChangeListener) this);
772+
addPropertyChangeListener((PropertyChangeListener) this);
773+
} else {
774+
removePropertyChangeListener((PropertyChangeListener) parent);
775+
addPropertyChangeListener((PropertyChangeListener) parent);
776+
}
772777
Runnable r = new Runnable() {
773778

774779
@Override
@@ -817,7 +822,7 @@ public void windowClosing(WindowEvent e) {
817822
}
818823

819824
private static void warnJSDeveloper() {
820-
System.err.println("JFileChooser: Component does not implement PropertyChangeListener.");
825+
System.err.println("JFileChooser: Neither component nor this implements PropertyChangeListener.");
821826
}
822827

823828
private void closeDialog() {

0 commit comments

Comments
 (0)