View Javadoc

1   // %2642300606:hoplugins.commons.ui%
2   package hoplugins.commons.ui;
3   
4   import hoplugins.Commons;
5   
6   import hoplugins.commons.utils.Debug;
7   
8   import plugins.IDebugWindow;
9   
10  import java.awt.Dimension;
11  import java.awt.Point;
12  
13  
14  /***
15   * TODO Debug window helper class
16   *
17   * @author kenmooda
18   */
19  public class DebugWindow {
20      //~ Static fields/initializers -----------------------------------------------------------------
21  
22      private static IDebugWindow debugWindow;
23  
24      //~ Constructors -------------------------------------------------------------------------------
25  
26      /***
27       * Private default constructor.
28       */
29      private DebugWindow() {
30          // Empty.
31      }
32  
33      //~ Methods ------------------------------------------------------------------------------------
34  
35      /***
36       * Sets info text on HO panel.
37       *
38       * @param text Info text
39       */
40      public static synchronized void setInfoText(String text) {
41          Commons.getModel().getGUI().getInfoPanel().setLangInfoText(text);
42      }
43  
44      /***
45       * Appends the stack trace of the given exception to the debug window. The debug window is set
46       * visible, if it is hidden or it has been closed.
47       *
48       * @param e Exception
49       */
50      public static synchronized void debug(Exception e) {
51          getDebugWindow().append(e);
52          getDebugWindow().setVisible(true);
53          Debug.logException(e);
54      }
55  
56      /***
57       * Appends the given string to the debug window. The debug window is set visible, if it is
58       * hidden or it has been closed.
59       *
60       * @param s String
61       */
62      public static synchronized void debug(String s) {
63          getDebugWindow().append(s);
64          getDebugWindow().setVisible(true);
65          Debug.log(s);
66      }
67  
68      /***
69       * Get the debug window instance.
70       *
71       * @return IDebugWindow
72       */
73      private static synchronized IDebugWindow getDebugWindow() {
74          if (debugWindow == null) {
75              debugWindow = Commons.getModel().getGUI().createDebugWindow(new Point(100, 200),
76                                                                          new Dimension(700, 400));
77          }
78  
79          return debugWindow;
80      }
81  }