Skip to content

Commit

Permalink
Consolidate showing of error, warning and informational messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Captain-Chaos committed Dec 2, 2022
1 parent 89a2dd4 commit d86a656
Show file tree
Hide file tree
Showing 26 changed files with 179 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static javax.swing.JOptionPane.*;
import static org.pepsoft.util.DesktopUtils.beep;
import static org.pepsoft.util.FileUtils.deleteDir;
import static org.pepsoft.util.swing.MessageUtils.showInfo;
import static org.pepsoft.worldpainter.Constants.GB;
import static org.pepsoft.worldpainter.exporting.AbstractWorldExporter.DATE_FORMAT;

Expand Down Expand Up @@ -136,7 +137,7 @@ public static synchronized boolean cleanUpBackups(File exportDir, Window parent)
}
} else {
// Manual cleanup; report the results
JOptionPane.showMessageDialog(parent, report.toString(), "Clean Up Results", INFORMATION_MESSAGE);
showInfo(parent, report.toString(), "Clean Up Results");
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.pepsoft.util.GUIUtils.scaleToUI;
import static org.pepsoft.util.GUIUtils.scaleWindow;
import static org.pepsoft.util.swing.MessageUtils.showInfo;

/**
*
Expand Down Expand Up @@ -151,7 +152,7 @@ private void donate() {
DesktopUtils.open(new URL("https://www.worldpainter.net/donate/paypal"));
Configuration config = Configuration.getInstance();
config.setDonationStatus(Configuration.DonationStatus.DONATED);
JOptionPane.showMessageDialog(this, strings.getString("the.donation.paypal.page.has.been.opened"), strings.getString("thank.you"), JOptionPane.INFORMATION_MESSAGE);
showInfo(this, strings.getString("the.donation.paypal.page.has.been.opened"), strings.getString("thank.you"));
config.logEvent(new EventVO(Constants.EVENT_KEY_DONATION_DONATE).addTimestamp());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
Expand Down
110 changes: 45 additions & 65 deletions WorldPainter/WPGUI/src/main/java/org/pepsoft/worldpainter/App.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import org.jnbt.Tag;
import org.pepsoft.minecraft.*;
import org.pepsoft.util.DesktopUtils;
import org.pepsoft.worldpainter.Dimension.Anchor;
import org.pepsoft.worldpainter.Dimension.LayerAnchor;
import org.pepsoft.worldpainter.exporting.ExportSettings;
Expand Down Expand Up @@ -48,6 +47,8 @@
import static org.pepsoft.util.AwtUtils.doLaterOnEventThread;
import static org.pepsoft.util.GUIUtils.scaleToUI;
import static org.pepsoft.util.MathUtils.clamp;
import static org.pepsoft.util.swing.MessageUtils.beepAndShowError;
import static org.pepsoft.util.swing.MessageUtils.showInfo;
import static org.pepsoft.worldpainter.Constants.V_1_17;
import static org.pepsoft.worldpainter.DefaultPlugin.ATTRIBUTE_MC_VERSION;
import static org.pepsoft.worldpainter.Dimension.Anchor.NORMAL_DETAIL;
Expand Down Expand Up @@ -313,8 +314,7 @@ public boolean saveSettings() {
// sanity checks
if ((comboBoxGenerator.getSelectedItem() == CUSTOM) && ((generatorName == null) || generatorName.trim().isEmpty())) {
buttonGeneratorOptions.requestFocusInWindow();
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "The custom world generator name has not been set.\nUse the [...] button to set it.", "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, "The custom world generator name has not been set.\nUse the [...] button to set it.", "Error");
return false;
}

Expand Down Expand Up @@ -3852,7 +3852,7 @@ private void checkBoxPopulateActionPerformed(java.awt.event.ActionEvent evt) {//
if (checkBoxPopulate.isSelected() && jCheckBox8.isSelected()) {
jCheckBox8.setSelected(false);
setControlStates();
JOptionPane.showMessageDialog(this, "\"Resources everywhere\" disabled on the Resources tab,\nto avoid duplicate resources. You may enable it again manually.", "Resources Everywhere Disabled", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "\"Resources everywhere\" disabled on the Resources tab,\nto avoid duplicate resources. You may enable it again manually.", "Resources Everywhere Disabled");
}
}//GEN-LAST:event_checkBoxPopulateActionPerformed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.net.MalformedURLException;
import java.net.URL;

import static org.pepsoft.util.swing.MessageUtils.showInfo;

/**
*
* @author pepijn
Expand Down Expand Up @@ -59,7 +61,7 @@ private void donate() {
DesktopUtils.open(new URL("https://www.worldpainter.net/donate/paypal"));
config.setDonationStatus(Configuration.DonationStatus.DONATED);
config.setShowDonationDialogAfter(config.getLaunchCount() + 100);
JOptionPane.showMessageDialog(this, "The donation PayPal page has been opened in your browser.\n\nThank you very much for donating!", "Thank You", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "The donation PayPal page has been opened in your browser.\n\nThank you very much for donating!", "Thank You");
config.logEvent(new EventVO(Constants.EVENT_KEY_DONATION_DONATE).addTimestamp());
ok();
} catch (MalformedURLException e) {
Expand All @@ -70,7 +72,7 @@ private void donate() {
private void alreadyDonated() {
config.setDonationStatus(Configuration.DonationStatus.DONATED);
config.setShowDonationDialogAfter(config.getLaunchCount() + 100);
JOptionPane.showMessageDialog(this, "Thank you very much for donating!", "Thank You", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "Thank you very much for donating!", "Thank You");
config.logEvent(new EventVO(Constants.EVENT_KEY_DONATION_ALREADY_DONATED).addTimestamp());
ok();
}
Expand All @@ -83,7 +85,7 @@ private void askLater() {
private void noThanks() {
config.setDonationStatus(Configuration.DonationStatus.NO_THANK_YOU);
config.setShowDonationDialogAfter(config.getLaunchCount() + 50);
JOptionPane.showMessageDialog(this, "Alright, no problem. We will not ask you again for a while.\nIf you change your mind, you can donate from the About screen!", "No Problem", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "Alright, no problem. We will not ask you again for a while.\nIf you change your mind, you can donate from the About screen!", "No Problem");
config.logEvent(new EventVO(Constants.EVENT_KEY_DONATION_NO_THANKS).addTimestamp());
ok();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import static org.pepsoft.util.AwtUtils.doOnEventThread;
import static org.pepsoft.util.GUIUtils.scaleToUI;
import static org.pepsoft.util.mdc.MDCUtils.gatherMdcContext;
import static org.pepsoft.util.swing.MessageUtils.showInfo;
import static org.pepsoft.worldpainter.Constants.*;

/**
Expand Down Expand Up @@ -277,7 +278,7 @@ private void email() {
URI uri = new URI("mailto", "[email protected]?subject=WorldPainter error report&body=" + body, null);
Desktop desktop = Desktop.getDesktop();
desktop.mail(uri);
JOptionPane.showMessageDialog(this, "A new email message should have been opened now for you to send.\nIf it did not work, please use the \"copy to clipboard\" button\nand manually mail the information to [email protected].", "Email Created", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "A new email message should have been opened now for you to send.\nIf it did not work, please use the \"copy to clipboard\" button\nand manually mail the information to [email protected].", "Email Created");
} catch (URISyntaxException e) {
logger.error("URI syntax error while trying to send email", e);
JOptionPane.showMessageDialog(this, "Could not create email message with error details!\nPlease use the \"copy to clipboard\" button and mail\nthe information to [email protected].", "Could Not Create Email", JOptionPane.ERROR_MESSAGE);
Expand All @@ -291,7 +292,7 @@ private void copyToClipboard() {
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection data = new StringSelection(body);
clipboard.setContents(data, data);
JOptionPane.showMessageDialog(this, "The information has been copied to the clipboard. Please paste\nit in a new email and send it to [email protected].", "Information Copied", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "The information has been copied to the clipboard. Please paste\nit in a new email and send it to [email protected].", "Information Copied");
}

private void submitInBackground() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static java.util.function.Function.identity;
import static org.pepsoft.minecraft.Constants.DIFFICULTY_HARD;
import static org.pepsoft.minecraft.Constants.DIFFICULTY_PEACEFUL;
import static org.pepsoft.util.swing.MessageUtils.beepAndShowError;
import static org.pepsoft.worldpainter.Constants.DIM_NORMAL;
import static org.pepsoft.worldpainter.DefaultPlugin.JAVA_MCREGION;
import static org.pepsoft.worldpainter.Dimension.Anchor.NORMAL_DETAIL;
Expand Down Expand Up @@ -177,17 +178,15 @@ private boolean checkCompatibility(Platform platform) {
nameOnlyMaterials.forEach((name, sources) ->
sb.append("<tr><td>").append(name).append("</td><td>").append(String.join(",", sources)).append("</td></tr>"));
sb.append("</table>");
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, sb.toString(), "Map Format Not Compatible", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, sb.toString(), "Map Format Not Compatible");
return false;
}
final String incompatibilityReason = PlatformManager.getInstance().getPlatformProvider(platform).isCompatible(platform, world);
if (incompatibilityReason != null) {
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, String.format(/* language=HTML */ "<html>" +
beepAndShowError(this, String.format(/* language=HTML */ "<html>" +
"<p>The world cannot be exported in format %s because it is not compatible:</p>" +
"<p>%s</p>" +
"</html>", platform.displayName, incompatibilityReason), "Map Format Not Compatible", JOptionPane.ERROR_MESSAGE);
"</html>", platform.displayName, incompatibilityReason), "Map Format Not Compatible");
return false;
}
return true;
Expand All @@ -204,14 +203,12 @@ protected final void export(WorldExportSettings exportSettings) {
// Check for errors
if (! new File(fieldDirectory.getText().trim()).isDirectory()) {
fieldDirectory.requestFocusInWindow();
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "The selected output directory does not exist or is not a directory.", "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, "The selected output directory does not exist or is not a directory.", "Error");
return;
}
if (fieldName.getText().trim().isEmpty()) {
fieldName.requestFocusInWindow();
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "You have not specified a name for the map.", "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, "You have not specified a name for the map.", "Error");
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/
package org.pepsoft.worldpainter;

import org.pepsoft.util.DesktopUtils;
import org.pepsoft.util.IconUtils;
import org.pepsoft.util.ProgressReceiver;
import org.pepsoft.util.ProgressReceiver.OperationCancelled;
Expand Down Expand Up @@ -49,10 +48,11 @@

import static com.google.common.primitives.Ints.asList;
import static java.awt.image.DataBuffer.*;
import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static org.pepsoft.minecraft.Constants.DEFAULT_MAX_HEIGHT_MCREGION;
import static org.pepsoft.minecraft.Constants.DEFAULT_WATER_LEVEL;
import static org.pepsoft.util.AwtUtils.doLaterOnEventThread;
import static org.pepsoft.util.swing.MessageUtils.beepAndShowError;
import static org.pepsoft.util.swing.MessageUtils.showInfo;
import static org.pepsoft.util.swing.ProgressDialog.NOT_CANCELABLE;
import static org.pepsoft.util.swing.SpinnerUtils.setMaximum;
import static org.pepsoft.util.swing.SpinnerUtils.setMinimum;
Expand Down Expand Up @@ -221,14 +221,12 @@ private HeightMapImporter createImporter(boolean interactive) {
// TODO keep this? It shouldn't be necessary!
if ((selectedFile == null) || (! selectedFile.exists())) {
if (interactive) {
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "Please select an image file to import.", "No File Selected", ERROR_MESSAGE);
beepAndShowError(this, "Please select an image file to import.", "No File Selected");
}
return null;
} else if (image == null) {
if (interactive) {
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "Please select a valid image file to import.", "No Valid Image Selected", ERROR_MESSAGE);
beepAndShowError(this, "Please select a valid image file to import.", "No Valid Image Selected");
}
return null;
}
Expand Down Expand Up @@ -544,7 +542,7 @@ private void resetDefaults() {
Configuration.getInstance().setHeightMapDefaultTheme(null);
loadDefaults();
buttonSaveAsDefaults.setEnabled(false);
JOptionPane.showMessageDialog(this, "Theme reset to factory defaults.", "Default Theme Reset", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "Theme reset to factory defaults.", "Default Theme Reset");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

import static javax.swing.JOptionPane.ERROR_MESSAGE;
import static javax.swing.JOptionPane.WARNING_MESSAGE;
import static org.pepsoft.util.GUIUtils.getUIScale;
import static org.pepsoft.util.swing.MessageUtils.beepAndShowError;
import static org.pepsoft.util.swing.MessageUtils.beepAndShowWarning;
import static org.pepsoft.worldpainter.Constants.ATTRIBUTE_KEY_PLUGINS;
import static org.pepsoft.worldpainter.Constants.ATTRIBUTE_KEY_SAFE_MODE;
import static org.pepsoft.worldpainter.plugins.WPPluginManager.DESCRIPTOR_PATH;
Expand Down Expand Up @@ -506,12 +507,10 @@ protected URLConnection openConnection(URL u) throws IOException {
app.open(file);
}
for (String error: StartupMessages.getErrors()) {
DesktopUtils.beep();
JOptionPane.showMessageDialog(app, error, "Startup Error", ERROR_MESSAGE);
beepAndShowError(app, error, "Startup Error");
}
for (String error: StartupMessages.getWarnings()) {
DesktopUtils.beep();
JOptionPane.showMessageDialog(app, error, "Startup Warning", WARNING_MESSAGE);
beepAndShowWarning(app, error, "Startup Warning");
}
if (StartupMessages.getErrors().isEmpty() && StartupMessages.getWarnings().isEmpty()) {
// Don't bother the user with this if we've already bothered them with errors and/or warnings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.net.MalformedURLException;
import java.net.URL;

import static org.pepsoft.util.swing.MessageUtils.showInfo;

/**
*
* @author pepijn
Expand Down Expand Up @@ -50,7 +52,7 @@ public static void maybeShowMerchDialog(Window parent) {
}

private void noThanks() {
JOptionPane.showMessageDialog(this, "Alright, no problem. You can access the merch store\nlater from the Help menu.", "No Problem", JOptionPane.INFORMATION_MESSAGE);
showInfo(this, "Alright, no problem. You can access the merch store\nlater from the Help menu.", "No Problem");
ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.Set;

import static java.util.Collections.singleton;
import static org.pepsoft.util.swing.MessageUtils.beepAndShowError;
import static org.pepsoft.worldpainter.App.MERGE_WARNING_KEY;
import static org.pepsoft.worldpainter.Constants.*;
import static org.pepsoft.worldpainter.Dimension.Anchor.*;
Expand Down Expand Up @@ -151,28 +152,24 @@ private void merge() {
// Check for errors
if (mapDir == null) {
fieldSelectedMapDir.requestFocusInWindow();
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "No existing map selected.", "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, "No existing map selected.", "Error");
return;
} else if (platform == null) {
fieldSelectedMapDir.requestFocusInWindow();
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "Selected map does not have a supported format.", "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, "Selected map does not have a supported format.", "Error");
return;
}
if (! checkCompatibility(platform)) {
return;
}
if ((! radioButtonExportEverything.isSelected()) && ((selectedTiles == null) || selectedTiles.isEmpty())) {
radioButtonExportEverything.requestFocusInWindow();
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "No tiles selected for merging.", "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, "No tiles selected for merging.", "Error");
return;
}
if ((! checkBoxSurface.isSelected()) && (! checkBoxNether.isSelected()) && (! checkBoxEnd.isSelected())) {
checkBoxSurface.requestFocusInWindow();
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, "No dimension selected for merging.", "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, "No dimension selected for merging.", "Error");
return;
}

Expand Down Expand Up @@ -222,8 +219,7 @@ private void merge() {
merger.performSanityChecks();
} catch (IllegalArgumentException e) {
logger.error(e.getClass().getSimpleName() + ": " + e.getMessage(), e);
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, e.getLocalizedMessage(), "Error", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, e.getLocalizedMessage(), "Error");
return;
} catch (IOException e) {
throw new RuntimeException("I/O error reading level.dat file", e);
Expand Down Expand Up @@ -431,8 +427,7 @@ private boolean checkCompatibility(Platform platform) {
nameOnlyMaterials.forEach((name, sources) ->
sb.append("<tr><td>").append(name).append("</td><td>").append(String.join(",", sources)).append("</td></tr>"));
sb.append("</table>");
DesktopUtils.beep();
JOptionPane.showMessageDialog(this, sb.toString(), "Map Format Not Compatible", JOptionPane.ERROR_MESSAGE);
beepAndShowError(this, sb.toString(), "Map Format Not Compatible");
fieldSelectedMapDir.requestFocusInWindow();
return false;
}
Expand Down
Loading

0 comments on commit d86a656

Please sign in to comment.