JAL-3676 code review -- added non-listed Level into dropdown list
authorBen Soares <b.soares@dundee.ac.uk>
Thu, 2 Jul 2020 14:36:41 +0000 (15:36 +0100)
committerBen Soares <b.soares@dundee.ac.uk>
Tue, 10 Nov 2020 19:31:37 +0000 (19:31 +0000)
src/jalview/gui/Console.java

index c0063c7..dc5968d 100644 (file)
@@ -162,13 +162,13 @@ public class Console extends WindowAdapter
             MessageManager.getString("label.log_level") + ":");
 
     // logLevelCombo.addItem(Level.ALL);
+    logLevelCombo.addItem(Level.TRACE);
     logLevelCombo.addItem(Level.DEBUG);
     logLevelCombo.addItem(Level.INFO);
     logLevelCombo.addItem(Level.WARN);
     // logLevelCombo.addItem(Level.ERROR);
     // logLevelCombo.addItem(Level.FATAL);
     // logLevelCombo.addItem(Level.OFF);
-    // logLevelCombo.addItem(Level.TRACE);
     setChosenLogLevelCombo();
     logLevelCombo.addActionListener(new ActionListener()
     {
@@ -253,9 +253,34 @@ public class Console extends WindowAdapter
     Level currentLogLevel = Cache.log == null ? Level.INFO
             : Cache.log.getLevel();
     logLevelCombo.setSelectedItem(currentLogLevel);
-    if (!logLevelCombo.getSelectedItem().equals(currentLogLevel))
+    if (!logLevelCombo.getSelectedItem().equals(currentLogLevel)) // currentLogLevel
+                                                                  // not in list
     {
-      logLevelCombo.setSelectedItem(Level.INFO);
+      if (currentLogLevel != null && currentLogLevel 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))
+          {
+            logLevelCombo.insertItemAt(currentLogLevel, i);
+            added = true;
+            break;
+          }
+        }
+        if (!added) // lower priority than others or some confusion -- add to
+                    // end of list
+        {
+          logLevelCombo.addItem(currentLogLevel);
+        }
+        logLevelCombo.setSelectedItem(currentLogLevel);
+      }
+      else
+      {
+        logLevelCombo.setSelectedItem(Level.INFO);
+      }
     }
   }
 
@@ -267,11 +292,6 @@ public class Console extends WindowAdapter
     cb.setContents(consoleTextSelection, null);
   }
 
-  private void setLogLevel()
-  {
-
-  }
-
   PipedOutputStream pout = null, perr = null;
 
   public void redirectStreams()