refactor error message display, and update RecordDialog error messages
This commit is contained in:
parent
e23156f65c
commit
bbf7f5caa9
|
@ -1,6 +1,8 @@
|
|||
package org.fenix.WorldRecord;
|
||||
|
||||
import org.fenix.llanfair.Llanfair;
|
||||
import org.fenix.llanfair.dialog.EditRun;
|
||||
import org.fenix.llanfair.dialog.LlanfairDialog;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
@ -13,8 +15,10 @@ import java.util.ArrayList;
|
|||
* Dialog window to select a world record on speedrun.com
|
||||
* @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 JButton searchButton = new JButton("Search");
|
||||
private JTextField searchField = new JTextField();
|
||||
|
@ -38,8 +42,9 @@ public class RecordDialog extends JDialog
|
|||
private EditRun editRun;
|
||||
|
||||
|
||||
public RecordDialog(EditRun editRun)
|
||||
public RecordDialog(EditRun editRun, Llanfair master)
|
||||
{
|
||||
this.master = master;
|
||||
this.editRun = editRun;
|
||||
|
||||
JPanel searchPanel = new JPanel(new FlowLayout());
|
||||
|
@ -119,7 +124,7 @@ public class RecordDialog extends JDialog
|
|||
games = WorldRecordParser.searchGames(name);
|
||||
} catch (IOException e)
|
||||
{
|
||||
showError();
|
||||
master.showError("Error searching for matching games from speedrun.com.", e);
|
||||
}
|
||||
|
||||
this.setGames(games);
|
||||
|
@ -138,7 +143,7 @@ public class RecordDialog extends JDialog
|
|||
categories = WorldRecordParser.getCategories(game);
|
||||
} catch (IOException e)
|
||||
{
|
||||
showError();
|
||||
master.showError("Error fetching game categories from speedrun.com.", e);
|
||||
}
|
||||
|
||||
this.setCategories(categories);
|
||||
|
@ -157,7 +162,7 @@ public class RecordDialog extends JDialog
|
|||
worldRecord = WorldRecordParser.getRecord(category);
|
||||
} catch (IOException e)
|
||||
{
|
||||
showError();
|
||||
master.showError("Error fetching game category world record time/owner from speedrun.com.", e);
|
||||
}
|
||||
|
||||
this.worldRecord.setText(worldRecord);
|
||||
|
@ -263,24 +268,6 @@ public class RecordDialog extends JDialog
|
|||
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
|
||||
* @return Category
|
||||
|
|
|
@ -117,7 +117,7 @@ final class Actions {
|
|||
MenuItem source = ( MenuItem ) event.getSource();
|
||||
|
||||
if ( source == MenuItem.EDIT ) {
|
||||
EditRun dialog = new EditRun( run );
|
||||
EditRun dialog = new EditRun( run, master );
|
||||
dialog.display( true, master );
|
||||
} else if ( source == MenuItem.NEW ) {
|
||||
if ( confirmOverwrite() ) {
|
||||
|
@ -143,7 +143,7 @@ final class Actions {
|
|||
} else if ( source == MenuItem.UNLOCK ) {
|
||||
master.setLockedHotkeys(false);
|
||||
} else if ( source == MenuItem.SETTINGS ) {
|
||||
EditSettings dialog = new EditSettings();
|
||||
EditSettings dialog = new EditSettings(master);
|
||||
dialog.display( true, master );
|
||||
} else if ( source == MenuItem.ABOUT ) {
|
||||
about();
|
||||
|
|
|
@ -256,10 +256,22 @@ public class Llanfair extends BorderlessFrame implements TableModelListener,
|
|||
*
|
||||
* @param message the localized error message
|
||||
*/
|
||||
void showError( String message ) {
|
||||
JOptionPane.showMessageDialog(
|
||||
this, message, Language.ERROR.get(), JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
public void showError( String message ) {
|
||||
showError(message, null);
|
||||
}
|
||||
|
||||
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
|
||||
// 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();
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,8 @@ implements ActionListener, ListSelectionListener {
|
|||
|
||||
// -------------------------------------------------------------- ATTRIBUTS
|
||||
|
||||
final private Llanfair master;
|
||||
|
||||
/**
|
||||
* Course éditée par cette boîte de dialogue.
|
||||
*/
|
||||
|
@ -126,11 +128,12 @@ implements ActionListener, ListSelectionListener {
|
|||
*
|
||||
* @param run - la course a éditer.
|
||||
*/
|
||||
public EditRun(Run run) {
|
||||
public EditRun(Run run, Llanfair master) {
|
||||
super();
|
||||
if (run == null) {
|
||||
throw new NullPointerException("EditDialog.EditDialog(): null run");
|
||||
}
|
||||
this.master = master;
|
||||
this.run = run;
|
||||
run.saveBackup();
|
||||
|
||||
|
@ -179,7 +182,7 @@ implements ActionListener, ListSelectionListener {
|
|||
try {
|
||||
recordString = new JLabel(WorldRecordParser.getRecord(recordCategory));
|
||||
} catch(Exception e) {
|
||||
RecordDialog.showError();
|
||||
this.master.showError("Error displaying selected world record information.", e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -297,7 +300,7 @@ implements ActionListener, ListSelectionListener {
|
|||
Time time = new Time(text);
|
||||
result = time.getMilliseconds();
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(this, e.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
|
||||
master.showError("Invalid delayed start time.", e);
|
||||
result = -1;
|
||||
}
|
||||
|
||||
|
@ -351,8 +354,8 @@ implements ActionListener, ListSelectionListener {
|
|||
run.moveSegmentDown(selected);
|
||||
segments.setRowSelectionInterval(selected + 1, selected + 1);
|
||||
} else if (source.equals(selectRecord)) {
|
||||
recordSelector = new RecordDialog(this);
|
||||
recordSelector.display();
|
||||
recordSelector = new RecordDialog(this, master);
|
||||
recordSelector.display(true, master);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -483,8 +486,7 @@ implements ActionListener, ListSelectionListener {
|
|||
try {
|
||||
return super.stopCellEditing();
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(editor, e.getMessage(),
|
||||
Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
|
||||
master.showError(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,14 @@
|
|||
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.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
@ -8,15 +16,6 @@ import java.awt.event.WindowListener;
|
|||
import java.util.ArrayList;
|
||||
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
|
||||
*
|
||||
|
@ -28,6 +27,8 @@ public class EditSettings extends LlanfairDialog
|
|||
|
||||
// ATTRIBUTS
|
||||
|
||||
final private Llanfair master;
|
||||
|
||||
/**
|
||||
* Bouton permettant de valider et de fermer la boîte de dialogue.
|
||||
*/
|
||||
|
@ -42,7 +43,9 @@ public class EditSettings extends LlanfairDialog
|
|||
/**
|
||||
* Construction d’une boîte de dialogue d’édition de paramètres.
|
||||
*/
|
||||
public EditSettings() {
|
||||
public EditSettings(Llanfair master) {
|
||||
this.master = master;
|
||||
|
||||
settingsTabs = new ArrayList<SettingsTab>();
|
||||
settingsTabs.add(new TabGeneral());
|
||||
settingsTabs.add(new TabLook());
|
||||
|
@ -127,7 +130,7 @@ public class EditSettings extends LlanfairDialog
|
|||
} catch (InvalidSettingException ex) {
|
||||
ex.tab.requestFocusInWindow();
|
||||
ex.field.requestFocusInWindow();
|
||||
JOptionPane.showMessageDialog(this, ex.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
|
||||
master.showError(ex.getMessage());
|
||||
}
|
||||
} else if (source.equals(reset)) {
|
||||
int option = JOptionPane.showConfirmDialog(this,
|
||||
|
@ -155,7 +158,7 @@ public class EditSettings extends LlanfairDialog
|
|||
dispose();
|
||||
} catch (InvalidSettingException ex) {
|
||||
ex.tab.grabFocus();
|
||||
JOptionPane.showMessageDialog(this, ex.getMessage(), Language.ERROR.get(), JOptionPane.ERROR_MESSAGE);
|
||||
master.showError(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue