2828 */
2929package cc .arduino .contributions .ui ;
3030
31- import cc .arduino .contributions .packages .ui .ContributionIndexTableModel ;
3231import cc .arduino .contributions .ui .listeners .AbstractKeyListener ;
3332import com .google .common .base .Predicate ;
3433import com .google .common .base .Predicates ;
4443import java .awt .event .*;
4544import java .util .Arrays ;
4645import java .util .Collection ;
47- import java .util .LinkedList ;
4846
4947import static cc .arduino .contributions .packages .ui .ContributionIndexTableModel .DESCRIPTION_COL ;
5048import static processing .app .I18n ._ ;
@@ -65,9 +63,11 @@ public abstract class InstallerJDialog<T> extends JDialog {
6563 // Real contribution table
6664 protected JTable contribTable ;
6765 // 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 ;
6969
70- abstract protected FilteredAbstractTableModel createContribModel ();
70+ abstract protected FilteredAbstractTableModel < T > createContribModel ();
7171
7272 abstract protected InstallerTableCell createCellRenderer ();
7373
@@ -76,8 +76,8 @@ public abstract class InstallerJDialog<T> extends JDialog {
7676 // Bottom:
7777 // - Progress bar
7878 protected final ProgressJProgressBar progressBar ;
79- protected final Box progressBox ;
80- protected final Box errorMessageBox ;
79+ private final Box progressBox ;
80+ private final Box errorMessageBox ;
8181 private final JLabel errorMessage ;
8282
8383 public InstallerJDialog (Frame parent , String title , ModalityType applicationModal , String noConnectionErrorMessage ) {
@@ -184,11 +184,20 @@ public void actionPerformed(ActionEvent arg0) {
184184 progressBox .add (Box .createHorizontalStrut (5 ));
185185 progressBox .add (cancelButton );
186186
187- JButton dismissErrorMessageButton = new JButton (_ ("OK" ));
187+ dismissErrorMessageButton = new JButton (_ ("OK" ));
188188 dismissErrorMessageButton .addActionListener (new ActionListener () {
189189 @ Override
190190 public void actionPerformed (ActionEvent arg0 ) {
191191 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 ));
192201 }
193202 });
194203
@@ -197,12 +206,13 @@ public void actionPerformed(ActionEvent arg0) {
197206 errorMessageBox .add (errorMessage );
198207 errorMessageBox .add (Box .createHorizontalGlue ());
199208 errorMessageBox .add (dismissErrorMessageButton );
209+ errorMessageBox .add (closeButton );
200210 errorMessageBox .setVisible (false );
201211 }
202212
203213 {
204214 JPanel progressPanel = new JPanel ();
205- progressPanel .setBorder (new EmptyBorder (7 , 7 , 7 , 7 ));
215+ progressPanel .setBorder (new EmptyBorder (7 , 10 , 7 , 10 ));
206216 progressPanel .setLayout (new BoxLayout (progressPanel , BoxLayout .Y_AXIS ));
207217 progressPanel .add (progressBox );
208218 progressPanel .add (errorMessageBox );
@@ -236,12 +246,12 @@ public void updateIndexFilter(String[] filters, Predicate<T>... additionalFilter
236246
237247 public void setErrorMessage (String message ) {
238248 errorMessage .setText ("<html><body>" + message + "</body></html>" );
239- errorMessageBox . setVisible (true );
249+ setErrorMessageVisible (true );
240250 }
241251
242252 public void clearErrorMessage () {
243253 errorMessage .setText ("" );
244- errorMessageBox . setVisible (false );
254+ setErrorMessageVisible (false );
245255 }
246256
247257 public void setProgressVisible (boolean visible , String status ) {
@@ -250,18 +260,25 @@ public void setProgressVisible(boolean visible, String status) {
250260 } else {
251261 setDefaultCloseOperation (WindowConstants .DISPOSE_ON_CLOSE );
252262 }
263+ errorMessageBox .setVisible (!visible );
253264 progressBox .setVisible (visible );
254265
255266 filterField .setEnabled (!visible );
256267 categoryChooser .setEnabled (!visible );
257268 contribTable .setEnabled (!visible );
258- errorMessageBox .setVisible (false );
259269 if (contribTable .getCellEditor () != null ) {
260270 ((InstallerTableCell ) contribTable .getCellEditor ()).setEnabled (!visible );
261271 ((InstallerTableCell ) contribTable .getCellEditor ()).setStatus (status );
262272 }
263273 }
264274
275+ private void setErrorMessageVisible (boolean visible ) {
276+ errorMessage .setVisible (visible );
277+ dismissErrorMessageButton .setVisible (visible );
278+ closeButton .setVisible (!visible );
279+ errorMessageBox .setVisible (true );
280+ }
281+
265282 protected final ActionListener categoryChooserActionListener = new ActionListener () {
266283
267284 @ Override
0 commit comments