28
28
*/
29
29
package cc .arduino .contributions .ui ;
30
30
31
- import cc .arduino .contributions .packages .ui .ContributionIndexTableModel ;
32
31
import cc .arduino .contributions .ui .listeners .AbstractKeyListener ;
33
32
import com .google .common .base .Predicate ;
34
33
import com .google .common .base .Predicates ;
44
43
import java .awt .event .*;
45
44
import java .util .Arrays ;
46
45
import java .util .Collection ;
47
- import java .util .LinkedList ;
48
46
49
47
import static cc .arduino .contributions .packages .ui .ContributionIndexTableModel .DESCRIPTION_COL ;
50
48
import static processing .app .I18n ._ ;
@@ -65,9 +63,11 @@ public abstract class InstallerJDialog<T> extends JDialog {
65
63
// Real contribution table
66
64
protected JTable contribTable ;
67
65
// Model behind the table
68
- protected FilteredAbstractTableModel <T > contribModel ;
66
+ protected final FilteredAbstractTableModel <T > contribModel ;
67
+ private final JButton closeButton ;
68
+ private final JButton dismissErrorMessageButton ;
69
69
70
- abstract protected FilteredAbstractTableModel createContribModel ();
70
+ abstract protected FilteredAbstractTableModel < T > createContribModel ();
71
71
72
72
abstract protected InstallerTableCell createCellRenderer ();
73
73
@@ -76,8 +76,8 @@ public abstract class InstallerJDialog<T> extends JDialog {
76
76
// Bottom:
77
77
// - Progress bar
78
78
protected final ProgressJProgressBar progressBar ;
79
- protected final Box progressBox ;
80
- protected final Box errorMessageBox ;
79
+ private final Box progressBox ;
80
+ private final Box errorMessageBox ;
81
81
private final JLabel errorMessage ;
82
82
83
83
public InstallerJDialog (Frame parent , String title , ModalityType applicationModal , String noConnectionErrorMessage ) {
@@ -184,11 +184,20 @@ public void actionPerformed(ActionEvent arg0) {
184
184
progressBox .add (Box .createHorizontalStrut (5 ));
185
185
progressBox .add (cancelButton );
186
186
187
- JButton dismissErrorMessageButton = new JButton (_ ("OK" ));
187
+ dismissErrorMessageButton = new JButton (_ ("OK" ));
188
188
dismissErrorMessageButton .addActionListener (new ActionListener () {
189
189
@ Override
190
190
public void actionPerformed (ActionEvent arg0 ) {
191
191
clearErrorMessage ();
192
+ setErrorMessageVisible (false );
193
+ }
194
+ });
195
+
196
+ closeButton = new JButton (_ ("Close" ));
197
+ closeButton .addActionListener (new ActionListener () {
198
+ @ Override
199
+ public void actionPerformed (ActionEvent arg0 ) {
200
+ InstallerJDialog .this .dispatchEvent (new WindowEvent (InstallerJDialog .this , WindowEvent .WINDOW_CLOSING ));
192
201
}
193
202
});
194
203
@@ -197,12 +206,13 @@ public void actionPerformed(ActionEvent arg0) {
197
206
errorMessageBox .add (errorMessage );
198
207
errorMessageBox .add (Box .createHorizontalGlue ());
199
208
errorMessageBox .add (dismissErrorMessageButton );
209
+ errorMessageBox .add (closeButton );
200
210
errorMessageBox .setVisible (false );
201
211
}
202
212
203
213
{
204
214
JPanel progressPanel = new JPanel ();
205
- progressPanel .setBorder (new EmptyBorder (7 , 7 , 7 , 7 ));
215
+ progressPanel .setBorder (new EmptyBorder (7 , 10 , 7 , 10 ));
206
216
progressPanel .setLayout (new BoxLayout (progressPanel , BoxLayout .Y_AXIS ));
207
217
progressPanel .add (progressBox );
208
218
progressPanel .add (errorMessageBox );
@@ -236,12 +246,12 @@ public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilter
236
246
237
247
public void setErrorMessage (String message ) {
238
248
errorMessage .setText ("<html><body>" + message + "</body></html>" );
239
- errorMessageBox . setVisible (true );
249
+ setErrorMessageVisible (true );
240
250
}
241
251
242
252
public void clearErrorMessage () {
243
253
errorMessage .setText ("" );
244
- errorMessageBox . setVisible (false );
254
+ setErrorMessageVisible (false );
245
255
}
246
256
247
257
public void setProgressVisible (boolean visible , String status ) {
@@ -250,18 +260,25 @@ public void setProgressVisible(boolean visible, String status) {
250
260
} else {
251
261
setDefaultCloseOperation (WindowConstants .DISPOSE_ON_CLOSE );
252
262
}
263
+ errorMessageBox .setVisible (!visible );
253
264
progressBox .setVisible (visible );
254
265
255
266
filterField .setEnabled (!visible );
256
267
categoryChooser .setEnabled (!visible );
257
268
contribTable .setEnabled (!visible );
258
- errorMessageBox .setVisible (false );
259
269
if (contribTable .getCellEditor () != null ) {
260
270
((InstallerTableCell ) contribTable .getCellEditor ()).setEnabled (!visible );
261
271
((InstallerTableCell ) contribTable .getCellEditor ()).setStatus (status );
262
272
}
263
273
}
264
274
275
+ private void setErrorMessageVisible (boolean visible ) {
276
+ errorMessage .setVisible (visible );
277
+ dismissErrorMessageButton .setVisible (visible );
278
+ closeButton .setVisible (!visible );
279
+ errorMessageBox .setVisible (true );
280
+ }
281
+
265
282
protected final ActionListener categoryChooserActionListener = new ActionListener () {
266
283
267
284
@ Override
0 commit comments