refactor error message display, and update RecordDialog error messages

This commit is contained in:
Gered 2018-06-20 20:18:31 -04:00
parent e23156f65c
commit bbf7f5caa9
5 changed files with 54 additions and 50 deletions

View file

@ -1,6 +1,8 @@
package org.fenix.WorldRecord; package org.fenix.WorldRecord;
import org.fenix.llanfair.Llanfair;
import org.fenix.llanfair.dialog.EditRun; import org.fenix.llanfair.dialog.EditRun;
import org.fenix.llanfair.dialog.LlanfairDialog;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@ -13,8 +15,10 @@ import java.util.ArrayList;
* Dialog window to select a world record on speedrun.com * Dialog window to select a world record on speedrun.com
* @author 4ilo 2018 * @author 4ilo 2018
*/ */
public class RecordDialog extends JDialog public class RecordDialog extends LlanfairDialog
{ {
final private Llanfair master;
private JLabel searchLabel = new JLabel("Search game:"); private JLabel searchLabel = new JLabel("Search game:");
private JButton searchButton = new JButton("Search"); private JButton searchButton = new JButton("Search");
private JTextField searchField = new JTextField(); private JTextField searchField = new JTextField();
@ -38,8 +42,9 @@ public class RecordDialog extends JDialog
private EditRun editRun; private EditRun editRun;
public RecordDialog(EditRun editRun) public RecordDialog(EditRun editRun, Llanfair master)
{ {
this.master = master;
this.editRun = editRun; this.editRun = editRun;
JPanel searchPanel = new JPanel(new FlowLayout()); JPanel searchPanel = new JPanel(new FlowLayout());
@ -119,7 +124,7 @@ public class RecordDialog extends JDialog
games = WorldRecordParser.searchGames(name); games = WorldRecordParser.searchGames(name);
} catch (IOException e) } catch (IOException e)
{ {
showError(); master.showError("Error searching for matching games from speedrun.com.", e);
} }
this.setGames(games); this.setGames(games);
@ -138,7 +143,7 @@ public class RecordDialog extends JDialog
categories = WorldRecordParser.getCategories(game); categories = WorldRecordParser.getCategories(game);
} catch (IOException e) } catch (IOException e)
{ {
showError(); master.showError("Error fetching game categories from speedrun.com.", e);
} }
this.setCategories(categories); this.setCategories(categories);
@ -157,7 +162,7 @@ public class RecordDialog extends JDialog
worldRecord = WorldRecordParser.getRecord(category); worldRecord = WorldRecordParser.getRecord(category);
} catch (IOException e) } catch (IOException e)
{ {
showError(); master.showError("Error fetching game category world record time/owner from speedrun.com.", e);
} }
this.worldRecord.setText(worldRecord); this.worldRecord.setText(worldRecord);
@ -263,24 +268,6 @@ public class RecordDialog extends JDialog
categoryListModel.removeAllElements(); categoryListModel.removeAllElements();
} }
public static void showError()
{
JOptionPane.showMessageDialog(null, "Could not connect to speedrun.com",
"Error", JOptionPane.ERROR_MESSAGE);
}
/**
* Show the dialog
*/
public void display()
{
setAlwaysOnTop(true);
setModalityType(ModalityType.APPLICATION_MODAL);
pack();
setLocationRelativeTo(getOwner());
setVisible(true);
}
/** /**
* Get the selected category object * Get the selected category object
* @return Category * @return Category

View file

@ -117,7 +117,7 @@ final class Actions {
MenuItem source = ( MenuItem ) event.getSource(); MenuItem source = ( MenuItem ) event.getSource();
if ( source == MenuItem.EDIT ) { if ( source == MenuItem.EDIT ) {
EditRun dialog = new EditRun( run ); EditRun dialog = new EditRun( run, master );
dialog.display( true, master ); dialog.display( true, master );
} else if ( source == MenuItem.NEW ) { } else if ( source == MenuItem.NEW ) {
if ( confirmOverwrite() ) { if ( confirmOverwrite() ) {
@ -143,7 +143,7 @@ final class Actions {
} else if ( source == MenuItem.UNLOCK ) { } else if ( source == MenuItem.UNLOCK ) {
master.setLockedHotkeys(false); master.setLockedHotkeys(false);
} else if ( source == MenuItem.SETTINGS ) { } else if ( source == MenuItem.SETTINGS ) {
EditSettings dialog = new EditSettings(); EditSettings dialog = new EditSettings(master);
dialog.display( true, master ); dialog.display( true, master );
} else if ( source == MenuItem.ABOUT ) { } else if ( source == MenuItem.ABOUT ) {
about(); about();

View file

@ -256,10 +256,22 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
* *
* @param message the localized error message * @param message the localized error message
*/ */
void showError( String message ) { public void showError( String message ) {
JOptionPane.showMessageDialog( showError(message, null);
this, message, Language.ERROR.get(), JOptionPane.ERROR_MESSAGE }
);
public void showError(String message, Throwable ex) {
String errorMessage;
if (ex != null)
errorMessage = message + "\n\n" + ex.toString();
else
errorMessage = message;
JOptionPane pane = new JOptionPane(errorMessage, JOptionPane.ERROR_MESSAGE);
JDialog dialog = pane.createDialog(Language.ERROR.get());
dialog.setAlwaysOnTop(true);
dialog.setVisible(true);
dialog.dispose();
} }
/** /**
@ -528,7 +540,7 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
// problem. e.g. on OS X, if an exception is thrown a dialog telling the user that the // problem. e.g. on OS X, if an exception is thrown a dialog telling the user that the
// application has requested some accessibility-related access shows up. // application has requested some accessibility-related access shows up.
JOptionPane.showMessageDialog(this, Language.GLOBAL_HOTKEYS_STARTUP_ERROR, Language.ERROR.get(), JOptionPane.ERROR_MESSAGE); showError(Language.GLOBAL_HOTKEYS_STARTUP_ERROR.get());
this.dispose(); this.dispose();
return false; return false;
} }

View file

@ -43,6 +43,8 @@ implements ActionListener, ListSelectionListener {
// -------------------------------------------------------------- ATTRIBUTS // -------------------------------------------------------------- ATTRIBUTS
final private Llanfair master;
/** /**
* Course éditée par cette boîte de dialogue. * Course éditée par cette boîte de dialogue.
*/ */
@ -126,11 +128,12 @@ implements ActionListener, ListSelectionListener {
* *
* @param run - la course a éditer. * @param run - la course a éditer.
*/ */
public EditRun(Run run) { public EditRun(Run run, Llanfair master) {
super(); super();
if (run == null) { if (run == null) {
throw new NullPointerException("EditDialog.EditDialog(): null run"); throw new NullPointerException("EditDialog.EditDialog(): null run");
} }
this.master = master;
this.run = run; this.run = run;
run.saveBackup(); run.saveBackup();
@ -179,7 +182,7 @@ implements ActionListener, ListSelectionListener {
try { try {
recordString = new JLabel(WorldRecordParser.getRecord(recordCategory)); recordString = new JLabel(WorldRecordParser.getRecord(recordCategory));
} catch(Exception e) { } catch(Exception e) {
RecordDialog.showError(); this.master.showError("Error displaying selected world record information.", e);
} }
} }
else { else {
@ -297,7 +300,7 @@ implements ActionListener, ListSelectionListener {
Time time = new Time(text); Time time = new Time(text);
result = time.getMilliseconds(); result = time.getMilliseconds();
} catch (Exception e) { } catch (Exception e) {
JOptionPane.showMessageDialog(this, e.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE); master.showError("Invalid delayed start time.", e);
result = -1; result = -1;
} }
@ -351,8 +354,8 @@ implements ActionListener, ListSelectionListener {
run.moveSegmentDown(selected); run.moveSegmentDown(selected);
segments.setRowSelectionInterval(selected + 1, selected + 1); segments.setRowSelectionInterval(selected + 1, selected + 1);
} else if (source.equals(selectRecord)) { } else if (source.equals(selectRecord)) {
recordSelector = new RecordDialog(this); recordSelector = new RecordDialog(this, master);
recordSelector.display(); recordSelector.display(true, master);
} }
} }
@ -483,8 +486,7 @@ implements ActionListener, ListSelectionListener {
try { try {
return super.stopCellEditing(); return super.stopCellEditing();
} catch (Exception e) { } catch (Exception e) {
JOptionPane.showMessageDialog(editor, e.getMessage(), master.showError(e.getMessage());
Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
return false; return false;
} }
} }

View file

@ -1,6 +1,14 @@
package org.fenix.llanfair.dialog; package org.fenix.llanfair.dialog;
import java.awt.GridBagLayout; import org.fenix.llanfair.Language;
import org.fenix.llanfair.Llanfair;
import org.fenix.utils.gui.GBC;
import org.fenix.utils.locale.LocaleDelegate;
import org.fenix.utils.locale.LocaleEvent;
import org.fenix.utils.locale.LocaleListener;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
@ -8,15 +16,6 @@ import java.awt.event.WindowListener;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.*;
import org.fenix.llanfair.Language;
import org.fenix.llanfair.config.Settings;
import org.fenix.utils.gui.GBC;
import org.fenix.utils.locale.LocaleDelegate;
import org.fenix.utils.locale.LocaleEvent;
import org.fenix.utils.locale.LocaleListener;
/** /**
* ConfigDialog * ConfigDialog
* *
@ -28,6 +27,8 @@ public class EditSettings extends LlanfairDialog
// ATTRIBUTS // ATTRIBUTS
final private Llanfair master;
/** /**
* Bouton permettant de valider et de fermer la boîte de dialogue. * Bouton permettant de valider et de fermer la boîte de dialogue.
*/ */
@ -42,7 +43,9 @@ public class EditSettings extends LlanfairDialog
/** /**
* Construction dune boîte de dialogue dédition de paramètres. * Construction dune boîte de dialogue dédition de paramètres.
*/ */
public EditSettings() { public EditSettings(Llanfair master) {
this.master = master;
settingsTabs = new ArrayList<SettingsTab>(); settingsTabs = new ArrayList<SettingsTab>();
settingsTabs.add(new TabGeneral()); settingsTabs.add(new TabGeneral());
settingsTabs.add(new TabLook()); settingsTabs.add(new TabLook());
@ -127,7 +130,7 @@ public class EditSettings extends LlanfairDialog
} catch (InvalidSettingException ex) { } catch (InvalidSettingException ex) {
ex.tab.requestFocusInWindow(); ex.tab.requestFocusInWindow();
ex.field.requestFocusInWindow(); ex.field.requestFocusInWindow();
JOptionPane.showMessageDialog(this, ex.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE); master.showError(ex.getMessage());
} }
} else if (source.equals(reset)) { } else if (source.equals(reset)) {
int option = JOptionPane.showConfirmDialog(this, int option = JOptionPane.showConfirmDialog(this,
@ -155,7 +158,7 @@ public class EditSettings extends LlanfairDialog
dispose(); dispose();
} catch (InvalidSettingException ex) { } catch (InvalidSettingException ex) {
ex.tab.grabFocus(); ex.tab.grabFocus();
JOptionPane.showMessageDialog(this, ex.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE); master.showError(ex.getMessage());
} }
} }