5
5
import javax .swing .*;
6
6
import java .awt .*;
7
7
import java .awt .event .ActionEvent ;
8
- import java .awt .event .ActionListener ;
8
+ import java .awt .event .WindowEvent ;
9
9
import java .io .File ;
10
10
11
11
import static processing .app .I18n ._ ;
12
12
13
13
public class PasswordAuthorizationDialog extends JDialog {
14
14
15
- protected final JButton uploadButton ;
16
- protected final JButton cancelButton ;
17
- protected final JLabel typePasswordLabel ;
18
- protected final JLabel passwordLabel ;
19
- protected final JLabel icon ;
20
- protected final JPasswordField passwordField ;
15
+ private final JPasswordField passwordField ;
21
16
22
- protected boolean cancelled ;
23
- protected String password ;
17
+ private boolean cancelled ;
18
+ private String password ;
24
19
25
20
public PasswordAuthorizationDialog (Frame parent , String dialogText ) {
26
21
super (parent , true );
27
22
28
23
this .cancelled = false ;
29
24
this .password = null ;
30
25
31
- typePasswordLabel = new JLabel ();
32
- icon = new JLabel ();
33
- passwordLabel = new JLabel ();
26
+ JLabel typePasswordLabel = new JLabel ();
27
+ JLabel icon = new JLabel ();
28
+ JLabel passwordLabel = new JLabel ();
34
29
passwordField = new JPasswordField ();
35
- uploadButton = new JButton ();
36
- cancelButton = new JButton ();
30
+ JButton uploadButton = new JButton ();
31
+ JButton cancelButton = new JButton ();
37
32
38
33
setDefaultCloseOperation (WindowConstants .DISPOSE_ON_CLOSE );
39
34
@@ -44,81 +39,71 @@ public PasswordAuthorizationDialog(Frame parent, String dialogText) {
44
39
passwordLabel .setText (_ ("Password:" ));
45
40
46
41
passwordField .setText ("" );
47
- passwordField .addActionListener (new ActionListener () {
48
- public void actionPerformed (ActionEvent evt ) {
49
- uploadButtonPressed (evt );
50
- }
51
- });
42
+ passwordField .addActionListener (PasswordAuthorizationDialog .this ::uploadButtonPressed );
52
43
53
44
uploadButton .setText (_ ("Upload" ));
54
- uploadButton .addActionListener (new ActionListener () {
55
- public void actionPerformed (ActionEvent evt ) {
56
- uploadButtonPressed (evt );
57
- }
58
- });
45
+ uploadButton .addActionListener (PasswordAuthorizationDialog .this ::uploadButtonPressed );
59
46
60
47
cancelButton .setText (_ ("Cancel" ));
61
- cancelButton .addActionListener (new ActionListener () {
62
- public void actionPerformed (ActionEvent evt ) {
63
- cancelButtonPressed (evt );
64
- }
65
- });
48
+ cancelButton .addActionListener (PasswordAuthorizationDialog .this ::cancelButtonPressed );
49
+
50
+ Base .registerWindowCloseKeys (getRootPane (), this ::cancelButtonPressed );
66
51
67
52
GroupLayout layout = new GroupLayout (getContentPane ());
68
53
getContentPane ().setLayout (layout );
69
54
layout .setHorizontalGroup (
70
- layout .createParallelGroup (GroupLayout .Alignment .LEADING )
71
- .addGroup (layout .createSequentialGroup ()
72
- .addContainerGap ()
73
- .addComponent (icon , GroupLayout .PREFERRED_SIZE , 66 , GroupLayout .PREFERRED_SIZE )
74
- .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
75
- .addGroup (layout .createParallelGroup (GroupLayout .Alignment .LEADING )
76
- .addComponent (typePasswordLabel )
77
- .addGroup (layout .createSequentialGroup ()
78
- .addComponent (passwordLabel )
79
- .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
80
- .addComponent (passwordField , GroupLayout .PREFERRED_SIZE , 300 , GroupLayout .PREFERRED_SIZE )))
81
- .addContainerGap (GroupLayout .DEFAULT_SIZE , Short .MAX_VALUE ))
82
- .addGroup (GroupLayout .Alignment .TRAILING , layout .createSequentialGroup ()
83
- .addContainerGap (GroupLayout .DEFAULT_SIZE , Short .MAX_VALUE )
84
- .addComponent (cancelButton )
85
- .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
86
- .addComponent (uploadButton )
87
- .addContainerGap ())
55
+ layout .createParallelGroup (GroupLayout .Alignment .LEADING )
56
+ .addGroup (layout .createSequentialGroup ()
57
+ .addContainerGap ()
58
+ .addComponent (icon , GroupLayout .PREFERRED_SIZE , 66 , GroupLayout .PREFERRED_SIZE )
59
+ .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
60
+ .addGroup (layout .createParallelGroup (GroupLayout .Alignment .LEADING )
61
+ .addComponent (typePasswordLabel )
62
+ .addGroup (layout .createSequentialGroup ()
63
+ .addComponent (passwordLabel )
64
+ .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
65
+ .addComponent (passwordField , GroupLayout .PREFERRED_SIZE , 300 , GroupLayout .PREFERRED_SIZE )))
66
+ .addContainerGap (GroupLayout .DEFAULT_SIZE , Short .MAX_VALUE ))
67
+ .addGroup (GroupLayout .Alignment .TRAILING , layout .createSequentialGroup ()
68
+ .addContainerGap (GroupLayout .DEFAULT_SIZE , Short .MAX_VALUE )
69
+ .addComponent (cancelButton )
70
+ .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
71
+ .addComponent (uploadButton )
72
+ .addContainerGap ())
88
73
);
89
74
layout .setVerticalGroup (
90
- layout .createParallelGroup (GroupLayout .Alignment .LEADING )
91
- .addGroup (layout .createSequentialGroup ()
92
- .addContainerGap ()
93
- .addComponent (typePasswordLabel )
94
- .addGroup (layout .createParallelGroup (GroupLayout .Alignment .LEADING )
95
- .addGroup (layout .createSequentialGroup ()
96
- .addGap (53 , 53 , 53 )
97
- .addGroup (layout .createParallelGroup (GroupLayout .Alignment .BASELINE )
98
- .addComponent (passwordLabel )
99
- .addComponent (passwordField , GroupLayout .PREFERRED_SIZE , GroupLayout .DEFAULT_SIZE , GroupLayout .PREFERRED_SIZE ))
100
- .addGap (18 , 18 , 18 ))
101
- .addGroup (GroupLayout .Alignment .TRAILING , layout .createSequentialGroup ()
102
- .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
103
- .addComponent (icon )
104
- .addGap (9 , 9 , 9 )))
105
- .addGroup (layout .createParallelGroup (GroupLayout .Alignment .BASELINE )
106
- .addComponent (uploadButton )
107
- .addComponent (cancelButton ))
108
- .addContainerGap (GroupLayout .DEFAULT_SIZE , Short .MAX_VALUE ))
75
+ layout .createParallelGroup (GroupLayout .Alignment .LEADING )
76
+ .addGroup (layout .createSequentialGroup ()
77
+ .addContainerGap ()
78
+ .addComponent (typePasswordLabel )
79
+ .addGroup (layout .createParallelGroup (GroupLayout .Alignment .LEADING )
80
+ .addGroup (layout .createSequentialGroup ()
81
+ .addGap (53 , 53 , 53 )
82
+ .addGroup (layout .createParallelGroup (GroupLayout .Alignment .BASELINE )
83
+ .addComponent (passwordLabel )
84
+ .addComponent (passwordField , GroupLayout .PREFERRED_SIZE , GroupLayout .DEFAULT_SIZE , GroupLayout .PREFERRED_SIZE ))
85
+ .addGap (18 , 18 , 18 ))
86
+ .addGroup (GroupLayout .Alignment .TRAILING , layout .createSequentialGroup ()
87
+ .addPreferredGap (LayoutStyle .ComponentPlacement .RELATED )
88
+ .addComponent (icon )
89
+ .addGap (9 , 9 , 9 )))
90
+ .addGroup (layout .createParallelGroup (GroupLayout .Alignment .BASELINE )
91
+ .addComponent (uploadButton )
92
+ .addComponent (cancelButton ))
93
+ .addContainerGap (GroupLayout .DEFAULT_SIZE , Short .MAX_VALUE ))
109
94
);
110
95
111
96
pack ();
112
97
}
113
98
114
99
private void cancelButtonPressed (ActionEvent event ) {
115
100
this .cancelled = true ;
116
- this . dispose ( );
101
+ dispatchEvent ( new WindowEvent ( this , WindowEvent . WINDOW_CLOSING ) );
117
102
}
118
103
119
- public void uploadButtonPressed (ActionEvent event ) {
104
+ private void uploadButtonPressed (ActionEvent event ) {
120
105
this .password = new String (passwordField .getPassword ());
121
- this . dispose ( );
106
+ dispatchEvent ( new WindowEvent ( this , WindowEvent . WINDOW_CLOSING ) );
122
107
}
123
108
124
109
public String getPassword () {
@@ -128,4 +113,4 @@ public String getPassword() {
128
113
public boolean isCancelled () {
129
114
return cancelled ;
130
115
}
131
- }
116
+ }
0 commit comments