From fd86db8856109e69c21a5f4102bc8dd94664ae1f Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 12 Sep 2023 10:43:20 +0100 Subject: [PATCH] JAL-4285 Better checkFiles processing. Better dialog. --- resources/lang/Messages.properties | 2 +- resources/lang/Messages_es.properties | 3 +- src/jalview/bin/Commands.java | 64 +++++++++++++-------------------- src/jalview/bin/Jalview.java | 18 +++++++--- src/jalview/gui/Desktop.java | 38 ++++++++++++++++---- 5 files changed, 71 insertions(+), 54 deletions(-) diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index d1e4536..70eeb95 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1467,4 +1467,4 @@ label.all_known_alignment_files = All known alignment files label.command_line_arguments = Command Line Arguments warning.using_old_command_line_arguments = It looks like you are using old command line arguments. These are now deprecated and will be removed in a future release of Jalview.\nFind out about the new command line arguments at\n warning.using_mixed_command_line_arguments = Jalview cannot use both old (-arg) and new (--arg) command line arguments. Please check your command line arguments.\ne.g. {0} and {1} -warning.the_following_errors = The following errors and warnings occurred whilst processing files. +warning.the_following_errors = The following errors and warnings occurred whilst processing files: diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 999c8cd..a0b9292 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1441,5 +1441,4 @@ label.all_known_alignment_files = Todos los archivos de alineaci label.command_line_arguments = Argumentos de línea de comando warning.using_old_command_line_arguments = Parece que estás utilizando argumentos antiguos de línea de comando. Estos ahora están en desuso y se eliminarán en una versión futura de Jalview.\nObtenga más información sobre los nuevos argumentos de la línea de comando en\n warning.using_mixed_command_line_arguments = Jalview no puede utilizar argumentos de línea de comando antiguos (-arg) y nuevos (--arg). Verifique los argumentos de su línea de comando.\ne.g. {0} y {1} -warning.the_following_errors = Se produjeron los siguientes errores y advertencias al procesar archivos. - +warning.the_following_errors = Se produjeron los siguientes errores y advertencias al procesar archivos: diff --git a/src/jalview/bin/Commands.java b/src/jalview/bin/Commands.java index 8312b29..ba72831 100644 --- a/src/jalview/bin/Commands.java +++ b/src/jalview/bin/Commands.java @@ -143,8 +143,9 @@ public class Commands } // report errors - Console.debug("All errors from command line argument commands:\n" - + errorsToString()); + Console.warn( + "The following errors and warnings occurred whilst processing files:\n" + + errorsToString()); // gui errors reported in Jalview if (argParser.getBoolean(Arg.QUIT)) @@ -178,7 +179,7 @@ public class Commands return true; } - boolean isError = false; + Boolean isError = Boolean.valueOf(false); // set wrap scope here so it can be applied after structures are opened boolean wrap = false; @@ -692,14 +693,10 @@ public class Commands AppJmol jmol = (AppJmol) sview; try { - whatNext wn = this.checksBeforeWritingToFile(avm, subVals, - false, structureImageFilename, "structure image"); - if (wn == whatNext.ERROR) - { - isError = true; - continue; - } - else if (wn == whatNext.CONTINUE) + boolean success = this.checksBeforeWritingToFile(avm, + subVals, false, structureImageFilename, + "structure image", isError); + if (!success) { continue; } @@ -794,7 +791,7 @@ public class Commands return false; } - boolean isError = false; + Boolean isError = Boolean.valueOf(false); if (avm.containsArg(Arg.IMAGE)) { for (ArgValue av : avm.getArgValueList(Arg.IMAGE)) @@ -836,14 +833,9 @@ public class Commands Console.info("Writing " + file); - whatNext wn = this.checksBeforeWritingToFile(avm, subVal, false, - fileName, "image"); - if (wn == whatNext.ERROR) - { - isError = true; - continue; - } - else if (wn == whatNext.CONTINUE) + boolean success = checksBeforeWritingToFile(avm, subVal, false, + fileName, "image", isError); + if (!success) { continue; } @@ -921,7 +913,7 @@ public class Commands return false; } - boolean isError = false; + Boolean isError = Boolean.valueOf(false); if (avm.containsArg(Arg.OUTPUT)) { @@ -988,14 +980,9 @@ public class Commands } } - whatNext wn = this.checksBeforeWritingToFile(avm, subVals, true, - fileName, ff.getName()); - if (wn == whatNext.ERROR) - { - isError = true; - continue; - } - else if (wn == whatNext.CONTINUE) + boolean success = checksBeforeWritingToFile(avm, subVals, true, + fileName, ff.getName(), isError); + if (!success) { continue; } @@ -1113,14 +1100,9 @@ public class Commands errors.add(errorMessage); } - private enum whatNext - { - OKAY, CONTINUE, ERROR; - } - - private whatNext checksBeforeWritingToFile(ArgValuesMap avm, + private boolean checksBeforeWritingToFile(ArgValuesMap avm, SubVals subVal, boolean includeBackups, String filename, - String adjective) + String adjective, Boolean isError) { File file = new File(filename); @@ -1145,7 +1127,7 @@ public class Commands + Arg.OVERWRITE.argString() + (includeBackups ? " or " + Arg.BACKUPS.argString() : "") + " set"); - return whatNext.CONTINUE; + return false; } boolean mkdirs = ArgParser.getFromSubValArgOrPref(avm, Arg.MKDIRS, @@ -1158,10 +1140,11 @@ public class Commands + "' does not exist for " + adjective + " file '" + filename + "'." + (mkdirs ? "" : " Try using " + Arg.MKDIRS.argString())); - return whatNext.ERROR; + isError = true; + return false; } - return whatNext.OKAY; + return true; } public List getErrors() @@ -1174,8 +1157,9 @@ public class Commands StringBuilder sb = new StringBuilder(); for (String error : errors) { + if (sb.length() > 0) + sb.append("\n"); sb.append("- " + error); - sb.append("\n"); } return sb.toString(); } diff --git a/src/jalview/bin/Jalview.java b/src/jalview/bin/Jalview.java index dbc1d88..2c07296 100755 --- a/src/jalview/bin/Jalview.java +++ b/src/jalview/bin/Jalview.java @@ -2060,13 +2060,13 @@ public class Jalview if (oldStyle) { String warning = MessageManager - .getString("warning.using_old_command_line_arguments") - + "https://www.jalview.org/help/html/features/commandline.html"; + .getString("warning.using_old_command_line_arguments"); + String url = "https://www.jalview.org/help/html/features/commandline.html"; if (Desktop.instance != null) { String cont = MessageManager.getString("label.continue"); - Desktop.instance.nonBlockingDialog(32, 2, title, warning, cont, + Desktop.instance.nonBlockingDialog(32, 2, title, warning, url, cont, JvOptionPane.WARNING_MESSAGE, false, false); } } @@ -2077,8 +2077,16 @@ public class Jalview String message = MessageManager .getString("warning.the_following_errors"); String ok = MessageManager.getString("action.ok"); - Desktop.instance.nonBlockingDialog(60, 16, title, - message + "\n" + j.getCommands().errorsToString(), ok, + int shortest = 60; + List errors = j.getCommands().getErrors(); + for (int i = 0; i < errors.size(); i++) + { + shortest = Math.min(shortest, errors.get(i).length()); + } + Desktop.instance.nonBlockingDialog( + Math.max(message.length(), Math.min(60, shortest)), + Math.min(errors.size(), 20), title, message, + j.getCommands().errorsToString(), ok, JvOptionPane.WARNING_MESSAGE, true, true); } } diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index f0753bc..ee24c25 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -22,6 +22,7 @@ package jalview.gui; import java.awt.BorderLayout; import java.awt.Color; +import java.awt.Component; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; @@ -3744,24 +3745,26 @@ public class Desktop extends jalview.jbgui.GDesktop public void nonBlockingDialog(String title, String message, String button, int type, boolean scrollable, boolean modal) { - nonBlockingDialog(32, 2, title, message, button, type, scrollable, + nonBlockingDialog(32, 2, title, message, null, button, type, scrollable, modal); } public void nonBlockingDialog(int width, int height, String title, - String message, String button, int type, boolean scrollable, - boolean modal) + String message, String boxtext, String button, int type, + boolean scrollable, boolean modal) { if (type < 0) { type = JvOptionPane.WARNING_MESSAGE; } + JLabel jl = new JLabel(message); + JTextArea jta = new JTextArea(height, width); // jta.setLineWrap(true); jta.setEditable(false); jta.setWrapStyleWord(true); jta.setAutoscrolls(true); - jta.setText(message); + jta.setText(boxtext); JScrollPane jsp = scrollable ? new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, @@ -3769,10 +3772,33 @@ public class Desktop extends jalview.jbgui.GDesktop : null; JvOptionPane jvp = JvOptionPane.newOptionDialog(this); + + JPanel jp = new JPanel(); + jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS)); + + if (message != null) + { + jl.setAlignmentX(Component.LEFT_ALIGNMENT); + jp.add(jl); + } + if (boxtext != null) + { + if (scrollable) + { + jsp.setAlignmentX(Component.LEFT_ALIGNMENT); + jp.add(jsp); + } + else + { + jta.setAlignmentX(Component.LEFT_ALIGNMENT); + jp.add(jta); + } + } + jvp.setResponseHandler(JOptionPane.YES_OPTION, () -> { }); - jvp.showDialogOnTopAsync(this, scrollable ? jsp : jta, title, - JOptionPane.YES_OPTION, type, null, new Object[] + jvp.showDialogOnTopAsync(this, jp, title, JOptionPane.YES_OPTION, type, + null, new Object[] { button }, button, modal, null, false); } -- 1.7.10.2