Debug.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package de.tu_darmstadt.informatik.tk.scopviz.debug;
  2. import javax.xml.stream.XMLStreamConstants;
  3. import javax.xml.stream.events.Attribute;
  4. import javax.xml.stream.events.XMLEvent;
  5. import de.tu_darmstadt.informatik.tk.scopviz.io.MyFileSourceGraphML;
  6. import de.tu_darmstadt.informatik.tk.scopviz.ui.ConsoleManager;
  7. import javafx.application.Platform;
  8. /**
  9. * Debug class to allow easy, static access to console output.
  10. *
  11. * @author Matthias Wilhelm
  12. * @version 1.1
  13. *
  14. */
  15. public final class Debug {
  16. private static int logLevel = 2;
  17. /**
  18. * @return the logLevel (1 = INFORMTAION, 2 = WARNING, 3 = ERROR)
  19. */
  20. public static int getLogLevel() {
  21. return logLevel;
  22. }
  23. /**
  24. * All Logs with a severity smaller than the loglevel will be ignored
  25. *
  26. * @param logLevel
  27. * the logLevel to set
  28. */
  29. public static void setLogLevel(int logLevel) {
  30. Debug.logLevel = logLevel;
  31. }
  32. /**
  33. * Private Constructor to prevent instantiation.
  34. */
  35. private Debug() {
  36. }
  37. /**
  38. * Flag that determines whether to start the program in Debug Mode, loading
  39. * a Graph for testing on startup and enabling Debug output to the Console.
  40. */
  41. public static final boolean DEBUG_ENABLED = true;
  42. /**
  43. * Returns the Location of the File for the testing Graph.
  44. *
  45. * @return a sample underlay graph for the Program
  46. */
  47. public static String getDefaultUnderlayGraph() {
  48. String fileName = null;
  49. fileName = "/underlay1.graphml";
  50. return fileName;
  51. }
  52. /**
  53. * Returns the Location of the File for the testing Graph.
  54. *
  55. * @return a sample operator graph for the Program
  56. */
  57. public static String getDefaultOperatorGraph() {
  58. String fileName = null;
  59. fileName = "/operatorgraph1.graphml";
  60. return fileName;
  61. }
  62. /**
  63. * Short form for System.out.println().
  64. *
  65. * @param s
  66. * String to be printed on the console
  67. */
  68. public static void out(String s) {
  69. if (DEBUG_ENABLED) {
  70. System.out.println(s);
  71. }
  72. }
  73. /**
  74. * Short form for System.out.println().
  75. *
  76. * @param s
  77. * Object to be printed on the console
  78. */
  79. public static void out(Object s) {
  80. if (DEBUG_ENABLED) {
  81. System.out.println("DEBUG: " + s);
  82. }
  83. }
  84. /**
  85. * Short form for System.out.println(). Also look if a message is important
  86. * enough to be printed
  87. *
  88. * @param s
  89. * String to be printed on the console
  90. *
  91. * @param severity
  92. * the severity of the message (1 = INFORMATION, 2 = WARNING, 3 =
  93. * ERROR)
  94. */
  95. public static void out(String s, int severity) {
  96. if (severity >= logLevel) {
  97. if (DEBUG_ENABLED) {
  98. System.out.println(s);
  99. }
  100. if (severity < 3) {
  101. Platform.runLater(() -> ConsoleManager.addNormalText(s));
  102. } else {
  103. Platform.runLater(() -> ConsoleManager.addErrorText(s));
  104. }
  105. }
  106. }
  107. /**
  108. * Short form for System.out.println().
  109. *
  110. * @param s
  111. * Integer to be printed on the console
  112. */
  113. public static void out(int s) {
  114. if (DEBUG_ENABLED) {
  115. System.out.println(s);
  116. }
  117. }
  118. /**
  119. * Prints out an XML event.
  120. *
  121. * @param e
  122. * the event to print out
  123. */
  124. public static void out(XMLEvent e) {
  125. MyFileSourceGraphML t = new MyFileSourceGraphML();
  126. switch (e.getEventType()) {
  127. case XMLStreamConstants.START_ELEMENT:
  128. Debug.out(t.gotWhat(e.getEventType(), e.asStartElement().getName().getLocalPart()));
  129. break;
  130. case XMLStreamConstants.END_ELEMENT:
  131. Debug.out(t.gotWhat(e.getEventType(), e.asEndElement().getName().getLocalPart()));
  132. break;
  133. case XMLStreamConstants.ATTRIBUTE:
  134. Debug.out(t.gotWhat(e.getEventType(), ((Attribute) e).getName().getLocalPart()));
  135. break;
  136. default:
  137. Debug.out(e.toString());
  138. }
  139. }
  140. }