Module org.autogui

Class GuiSwingLogManager

java.lang.Object
org.autogui.base.log.GuiLogManager
org.autogui.swing.log.GuiSwingLogManager

public class GuiSwingLogManager extends GuiLogManager
a log-manager supporting Swing GUI
     GuiSwingLogManager m = new GuiSwingLogManager();
     m.setupConsole(
               GuiSwingLogManager.replaceErr,
               GuiSwingLogManager.replaceOut,
               GuiSwingLogManager.replaceExceptionHandler,
               GuiSwingLogManager.redirectToConsole,
               GuiSwingLogManager.suppressOutputRedirection);
     GuiLogManager.setManager(m);
     ...
     frame.setContentPane(m.createWindow().getPaneWithStatusBar(frame.getContentPane()));
     ...
     GuiLogManager.log(...);
 
  • Field Details

    • views

    • console

      protected GuiLogManagerConsole console
    • replaceErr

      public static boolean replaceErr
    • replaceOut

      public static boolean replaceOut
    • replaceExceptionHandler

      public static boolean replaceExceptionHandler
    • redirectToConsole

      public static boolean redirectToConsole
    • suppressOutputRedirection

      public static boolean suppressOutputRedirection
      Since:
      1.1
  • Constructor Details

    • GuiSwingLogManager

      public GuiSwingLogManager()
  • Method Details

    • setDefaultReplace

      public static void setDefaultReplace(boolean flag)
    • setRedirectToConsole

      public static void setRedirectToConsole(boolean flag)
    • setSuppressOutputRedirection

      public static void setSuppressOutputRedirection(boolean flag)
      Parameters:
      flag - flag for suppressOutputRedirection
      Since:
      1.1
    • addView

      public Object addView(Consumer<GuiLogEntry> view)
      Parameters:
      view - might accept same entries
      Returns:
      key object for removing, currently view itself
    • addView

      Parameters:
      view - a view for log entries, might accept same entries
      Returns:
      key object for removing, currently view itself
      Since:
      1.2
    • removeView

      public void removeView(Object v)
    • setConsole

      public void setConsole(GuiLogManagerConsole console)
    • getConsole

      public GuiLogManagerConsole getConsole()
    • getOrSetSwingLogManager

      public static GuiSwingLogManager getOrSetSwingLogManager()
      Returns:
      existing manager from GuiLogManager.get() or a new manager
      Since:
      1.1
    • setupConsoleWithDefaultFlags

      public GuiLogManager setupConsoleWithDefaultFlags()
      the method calls setupConsole(boolean, boolean, boolean, boolean, boolean) with reading following properties with conjunction of static fields. those properties take "true" (default) or "false".
      • autogui.log.replaceErr
      • autogui.log.replaceOut
      • autogui.log.replaceExceptionHandler
      • autogui.log.redirectToConsole
      • autogui.log.suppressOutputRedirection
      Returns:
      this
      Since:
      1.1
      See Also:
    • setupConsole

      public GuiLogManager setupConsole(boolean replaceError, boolean replaceOutput, boolean uncaughtHandler, boolean redirectToConsole)
    • setupConsole

      public GuiLogManager setupConsole(boolean replaceError, boolean replaceOutput, boolean uncaughtHandler, boolean redirectToConsole, boolean suppressOutputRedirection)
      controls logging redirection.
           setupConsole(true, true, true, true, true);
           //default: redirect to console and GUI-list
            System.err.print("msg"); // => stderr: "[Time...] msg",  GUI-list: "[Time...] msg"
            System.out.print("msg"); // => stdout: "msg",            GUI-list: "[Time...] msg"
            logString("msg");        // => stderr: "[Time...] msg",  GUI-list: "[Time...] msg"
      
           setupConsole(false, false, true, true, true);
           //no stdout/stderr replacement.
            System.err.print("msg"); // => stderr: "msg"
            System.out.print("msg"); // => stdout: "msg"
            logString("msg");        // => stderr: "[Time...] msg",  GUI-list: "[Time...] msg"
      
           setupConsole(true, true, true, false, true);
           //no console redirection: only stdout directly write message to the console as outputs
            System.err.print("msg"); // =>                           GUI-list: "[Time...] msg"
            System.out.print("msg"); // => stdout: "msg",            GUI-list: "[Time...] msg"
            logString("msg");        // =>                           GUI-list: "[Time...] msg"
      
           setupConsole(false, false, true, false, true);
           //no stdout/stderr replacement, and no console redirection: stdout/stderr just work as original
            System.err.print("msg"); // =>  stderr: "msg"
            System.out.print("msg"); // =>  stdout: "msg"
            logString("msg");        // =>                           GUI-list: "[Time...] msg"
      
           setupConsole(true, true, true, true, false);
           //full redirection: stdout also writes to stderr
            System.err.print("msg"); // =>  stderr: "[Time...] msg",                GUI-list: "[Time...] msg"
            System.out.print("msg"); // =>  stderr: "[Time...] msg", stdout: "msg", GUI-list: "[Time...] msg"
            logString("msg");        // =>  stderr: "[Time...] msg",                GUI-list: "[Time...] msg"
      
       
      Parameters:
      replaceError - replace System.err for redirection to the GUI list
      replaceOutput - replace System.out for redirection to the GUI list
      uncaughtHandler - replace the uncaught-handler for redirection to the GUI list
      redirectToConsole - adding GuiLogManagerConsole to the manager: this means that the GUI list redirects to the console (original System.err)
      suppressOutputRedirection - avoiding redirection of redirectToConsole from replaced System.out. So work only if replaceOutput=true and redirectToConsole=true
      Returns:
      this
      Since:
      1.1
    • getErr

      public PrintStream getErr()
      Overrides:
      getErr in class GuiLogManager
    • logString

      public GuiLogEntryString logString(String str, boolean fromStandard)
      Description copied from class: GuiLogManager
      create a string entry and show it.
      Overrides:
      logString in class GuiLogManager
      Parameters:
      str - the string for the entry
      fromStandard - whether the string come from the standard output (or error) redirection
      Returns:
      the created log entry
    • logError

      public GuiLogEntryException logError(Throwable ex)
      Description copied from class: GuiLogManager
      create an exception entry and show it
      Overrides:
      logError in class GuiLogManager
      Parameters:
      ex - the exception
      Returns:
      the created entry
    • logProgress

      public GuiLogEntryProgress logProgress()
      Description copied from class: GuiLogManager
      create an active progress entry and show it. the returned progress is determinate (isIndeterminate() == false), and notifies progress changes to the manager by GuiLogManager.updateProgress(GuiLogEntryProgress)
           try (GuiLogEntryProgress p = manager.logProgress();) {
               for (...) {
                   //those methods will cause a runtime-exception if the thread is interrupted.
                   p.addValueP(0.01f)
                     .setMessage("running ...");
                   ...
                   //the running code can checks interruption
                   if (Thread.interrupted()) {
                       break;
                   }
                   ...
               }
           } catch (Exception ex) { ... }
       
      Overrides:
      logProgress in class GuiLogManager
      Returns:
      the created progress entry
    • updateProgress

      public void updateProgress(GuiLogEntryProgress p)
      Overrides:
      updateProgress in class GuiLogManager
    • show

      public void show(GuiLogEntry e)
      Description copied from class: GuiLogManager
      update display of the entry.
      Overrides:
      show in class GuiLogManager
      Parameters:
      e - the displayed entry
    • clear

      public void clear()
      Since:
      1.2
    • getFont

      public static Font getFont()
    • createWindow

      public GuiSwingLogManager.GuiSwingLogWindow createWindow()