JAL-4298 reuse existing log level preference method
[jalview.git] / src / jalview / gui / Console.java
index 4600719..b8aad21 100644 (file)
@@ -217,30 +217,14 @@ public class Console extends WindowAdapter
     // logLevelCombo.addItem(LogLevel.ERROR);
     // logLevelCombo.addItem(LogLevel.OFF);
     // set startingLogLevel
-    if (jalview.bin.Console.log == null)
+    
+    if (jalview.bin.Console.getLogger() == null)
     {
-      try
-      {
-        startingLogLevel = LogLevel
-                .valueOf(Cache.getDefault(Cache.JALVIEWLOGLEVEL, null));
-      } catch (IllegalArgumentException e1)
-      {
-        jalview.bin.Console.debug(
-                "Invalid value for preference " + Cache.JALVIEWLOGLEVEL);
-      } catch (NullPointerException e2)
-      {
-        // no value in preferences
-      } finally
-      {
-        if (startingLogLevel == null)
-        {
-          startingLogLevel = LogLevel.INFO;
-        }
-      }
+      startingLogLevel = jalview.bin.Console.getCachedLogLevel();
     }
     else
     {
-      startingLogLevel = jalview.bin.Console.log.getLevel();
+      startingLogLevel = jalview.bin.Console.getLogger().getLevel();
     }
     setChosenLogLevelCombo();
     logLevelCombo.addActionListener(new ActionListener()
@@ -506,8 +490,16 @@ public class Console extends WindowAdapter
   {
     parent = desktop;
     // window name - get x,y,width, height possibly scaled
-    Rectangle bounds = parent.getLastKnownDimensions("JAVA_CONSOLE_");
-    if (bounds == null)
+    Rectangle bounds = parent == null ? null
+            : parent.getLastKnownDimensions("JAVA_CONSOLE_");
+    if (bounds != null)
+    {
+      frame = initFrame(
+              ChannelProperties.getProperty("app_name") + " Java Console",
+              bounds.width, bounds.height, bounds.x, bounds.y);
+    }
+    else if (parent != null && parent.getWidth() > 0
+            && parent.getHeight() > 0)
     {
       frame = initFrame(
               ChannelProperties.getProperty("app_name") + " Java Console",
@@ -518,7 +510,7 @@ public class Console extends WindowAdapter
     {
       frame = initFrame(
               ChannelProperties.getProperty("app_name") + " Java Console",
-              bounds.width, bounds.height, bounds.x, bounds.y);
+              MIN_WIDTH, MIN_HEIGHT, 10, 10);
     }
     frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
     // parent.add(frame);
@@ -554,6 +546,7 @@ public class Console extends WindowAdapter
         pin.close();
       } catch (Exception e)
       {
+        jalview.bin.Console.debug("pin.close() error", e);
       }
       try
       {
@@ -561,12 +554,14 @@ public class Console extends WindowAdapter
         pin2.close();
       } catch (Exception e)
       {
+        jalview.bin.Console.debug("pin2.close() error", e);
       }
       try
       {
         textAppender.join(10);
       } catch (Exception e)
       {
+        jalview.bin.Console.debug("textAppender.join(10) error", e);
       }
     }
     /*
@@ -626,13 +621,14 @@ public class Console extends WindowAdapter
         {
           try
           {
-            this.wait(100);
+            this.wait(100); // ##### implicated BLOCKED
             if (pin.available() == 0)
             {
               trimBuffer(false);
             }
           } catch (InterruptedException ie)
           {
+            jalview.bin.Console.debug("pin.available() error", ie);
           }
         }
 
@@ -658,13 +654,14 @@ public class Console extends WindowAdapter
         {
           try
           {
-            this.wait(100);
+            this.wait(100); // ##### implicated BLOCKED
             if (pin2.available() == 0)
             {
               trimBuffer(false);
             }
           } catch (InterruptedException ie)
           {
+            jalview.bin.Console.debug("pin.available() error", ie);
           }
         }
         while (pin2.available() != 0)
@@ -700,12 +697,16 @@ public class Console extends WindowAdapter
               displayPipe = tmp;
             }
             // simply append whole buffer
-            textArea.append(replace.toString());
-            count += replace.length();
-            if (count > byteslim)
+            synchronized (textArea.getDocument())
             {
-              trimBuffer(false);
+              textArea.append(replace.toString()); // ##### implicated BLOCKED
+              count += replace.length();
+              if (count > byteslim)
+              {
+                trimBuffer(false);
+              }
             }
+
           }
           if (displayPipe.length() == 0)
           {
@@ -718,6 +719,7 @@ public class Console extends WindowAdapter
               }
             } catch (InterruptedException e)
             {
+              jalview.bin.Console.debug("displayPipe.length() error", e);
             }
           }
         }
@@ -728,7 +730,7 @@ public class Console extends WindowAdapter
             this.wait(100);
           } catch (InterruptedException e)
           {
-
+            jalview.bin.Console.debug("this.wait(100) error", e);
           }
         }
         if (quit)
@@ -755,6 +757,7 @@ public class Console extends WindowAdapter
         this.wait(1000);
       } catch (InterruptedException ie)
       {
+        jalview.bin.Console.debug("this.wait(1000) error", ie);
       }
       throw new NullPointerException(
               MessageManager.getString("exception.application_test_npe"));
@@ -798,7 +801,7 @@ public class Console extends WindowAdapter
                 + "\nTruncated...\n";
       } catch (Exception e)
       {
-        e.printStackTrace();
+        jalview.bin.Console.warn("textArea Exception", e);
       }
     }
     // trim the buffer
@@ -822,7 +825,7 @@ public class Console extends WindowAdapter
           }
         } catch (Exception e)
         {
-          e.printStackTrace();
+          jalview.bin.Console.warn("textArea Exception", e);
         }
         // lines = textArea.getLineCount();
       }