1919public class AsyncFileChooser extends JFileChooser implements PropertyChangeListener {
2020
2121 private int optionSelected ;
22- private Runnable ok ; // sorry, no CANCEL in JavaScript
22+ private Runnable ok , cancel ; // sorry, no CANCEL in JavaScript for file open
2323 private static boolean notified ;
2424
2525 public AsyncFileChooser () {
@@ -65,15 +65,15 @@ public int showSaveDialog(Component frame) {
6565 /**
6666 *
6767 * @param frame
68- * @param type "open" or "save"
68+ * @param btnLabel "open" or "save"
6969 * @param ok
7070 * @param cancel must be null; JavaScript cannot capture a cancel from a file dialog
7171 */
72- public void showDialog (Component frame , String type , Runnable ok , Runnable cancel ) {
72+ public void showDialog (Component frame , String btnLabel , Runnable ok , Runnable cancel ) {
7373 this .ok = ok ;
74- if (cancel != null )
74+ if (getDialogType () != JFileChooser . SAVE_DIALOG && cancel != null )
7575 notifyCancel ();
76- process (super .showDialog (frame , type ));
76+ process (super .showDialog (frame , btnLabel ));
7777 }
7878
7979 /**
@@ -90,15 +90,17 @@ public void showOpenDialog(Component frame, Runnable ok, Runnable cancel) {
9090 }
9191
9292 /**
93+ *
94+ * This just completes the set. It is not necessary for JavaScript, because JavaScript
95+ * will just throw up a simple modal OK/Cancel message anyway.
9396 *
9497 * @param frame
9598 * @param ok
96- * @param cancel must be null; JavaScript cannot capture a cancel from a file dialog
99+ * @param cancel must be null
97100 */
98101 public void showSaveDialog (Component frame , Runnable ok , Runnable cancel ) {
99102 this .ok = ok ;
100- if (cancel != null )
101- notifyCancel ();
103+ this .cancel = cancel ;
102104 process (super .showSaveDialog (frame ));
103105 }
104106
@@ -124,6 +126,8 @@ private void process(int ret) {
124126 optionSelected = ret ;
125127 File f = getSelectedFile ();
126128 if (f == null ) {
129+ if (cancel != null )
130+ cancel .run ();
127131 return ; // Sorry, JavaScript cannot do this, so we also do not do it in Java.
128132 }
129133 ok .run ();
0 commit comments