From: Ben Soares Date: Fri, 14 Aug 2020 12:01:06 +0000 (+0100) Subject: JAL-3676 More explicit tooltip about resetting log level on Console close. Also clari... X-Git-Tag: Develop-2_11_2_0-d20201215~15^2~27 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5f14ca65f127ffbe8ca3c043ac46730fe5a00423;p=jalview.git JAL-3676 More explicit tooltip about resetting log level on Console close. Also clarified code to set initial log level and re-set on close to previously set level. --- diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index e65bf61..57c51f5 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1379,6 +1379,6 @@ label.no_features_to_sort_by = No features to sort by label.ignore_hidden = Ignore hidden columns label.ignore_hidden_tooltip = Ignore any characters in hidden columns when matching label.log_level = Log level -label.log_level_tooltip = Temporarily set the log level for this console +label.log_level_tooltip = Temporarily set the log level for this console. The log level will revert to {0} when this Java console is closed. label.copy_to_clipboard = Copy to clipboard label.copy_to_clipboard_tooltip = Copy all of the log text in this console to the system clipboard diff --git a/resources/lang/Messages_es.properties b/resources/lang/Messages_es.properties index 658abff..09e597e 100644 --- a/resources/lang/Messages_es.properties +++ b/resources/lang/Messages_es.properties @@ -1380,6 +1380,6 @@ label.no_features_to_sort_by = No hay caracter label.ignore_hidden = Ignorar columnas ocultas label.ignore_hidden_tooltip = Ignorar caracteres en columnas ocultas label.log_level = Nivel del registro -label.log_level_tooltip = Establezca temporalmente el nivel de registro para esta consola +label.log_level_tooltip = Establezca temporalmente el nivel de registro para esta consola. El nivel de registro volverá a {0} cuando se cierre esta consola de Java. label.copy_to_clipboard = Copiar en el portapapeles label.copy_to_clipboard_tooltip = Copie todo el texto de registro en esta consola al portapapeles del sistema diff --git a/src/jalview/gui/Console.java b/src/jalview/gui/Console.java index 89e0134..b456025 100644 --- a/src/jalview/gui/Console.java +++ b/src/jalview/gui/Console.java @@ -100,7 +100,9 @@ public class Console extends WindowAdapter private int MIN_HEIGHT = 250; - private JComboBox logLevelCombo = new JComboBox(); + private JComboBox logLevelCombo = new JComboBox(); + + protected Level startingLogLevel = Level.INFO; public Console() { @@ -173,6 +175,9 @@ public class Console extends WindowAdapter // logLevelCombo.addItem(Level.ERROR); // logLevelCombo.addItem(Level.FATAL); // logLevelCombo.addItem(Level.OFF); + // set startingLogLevel + startingLogLevel = Cache.log == null ? Level.INFO + : Cache.log.getLevel(); setChosenLogLevelCombo(); logLevelCombo.addActionListener(new ActionListener() { @@ -197,10 +202,10 @@ public class Console extends WindowAdapter logLevelPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT); logLevelPanel.add(logLevelLabel); logLevelPanel.add(logLevelCombo); - logLevelLabel.setToolTipText( - MessageManager.getString("label.log_level_tooltip")); - logLevelCombo.setToolTipText( - MessageManager.getString("label.log_level_tooltip")); + String logLevelTooltip = MessageManager.formatMessage( + "label.log_level_tooltip", startingLogLevel.toString()); + logLevelLabel.setToolTipText(logLevelTooltip); + logLevelCombo.setToolTipText(logLevelTooltip); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; @@ -254,22 +259,25 @@ public class Console extends WindowAdapter private void setChosenLogLevelCombo() { - Level currentLogLevel = Cache.log == null ? Level.INFO - : Cache.log.getLevel(); - logLevelCombo.setSelectedItem(currentLogLevel); - if (!logLevelCombo.getSelectedItem().equals(currentLogLevel)) // currentLogLevel - // not in list + setChosenLogLevelCombo(startingLogLevel); + } + + private void setChosenLogLevelCombo(Level setLogLevel) + { + logLevelCombo.setSelectedItem(setLogLevel); + if (!logLevelCombo.getSelectedItem().equals(setLogLevel)) { - if (currentLogLevel != null && currentLogLevel instanceof Level) + // setLogLevel not (yet) in list + if (setLogLevel != null && setLogLevel instanceof Level) { // add new item to list (might be set via .jalview_properties) boolean added = false; for (int i = 0; i < logLevelCombo.getItemCount(); i++) { Level l = (Level) logLevelCombo.getItemAt(i); - if (l.isGreaterOrEqual(currentLogLevel)) + if (l.isGreaterOrEqual(setLogLevel)) { - logLevelCombo.insertItemAt(currentLogLevel, i); + logLevelCombo.insertItemAt(setLogLevel, i); added = true; break; } @@ -277,9 +285,9 @@ public class Console extends WindowAdapter if (!added) // lower priority than others or some confusion -- add to // end of list { - logLevelCombo.addItem(currentLogLevel); + logLevelCombo.addItem(setLogLevel); } - logLevelCombo.setSelectedItem(currentLogLevel); + logLevelCombo.setSelectedItem(setLogLevel); } else { @@ -799,12 +807,10 @@ public class Console extends WindowAdapter } else { - // reset log level to user preference + // reset log level to what it was before if (Cache.log != null) { - String userLogLevel = Cache.getDefault("logs.Jalview.level", - Level.INFO.toString()); - Cache.log.setLevel(Level.toLevel(userLogLevel)); + Cache.log.setLevel(startingLogLevel); } unredirectStreams();