Debug.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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(). Also look if a message is important
  75. * enough to be printed
  76. *
  77. * @param s
  78. * String to be printed on the console
  79. *
  80. * @param severity
  81. * the severity of the message (1 = INFORMATION, 2 = WARNING, 3 =
  82. * ERROR)
  83. */
  84. public static void out(String s, int severity) {
  85. if (severity >= logLevel) {
  86. if (DEBUG_ENABLED) {
  87. System.out.println(s);
  88. }
  89. if (severity < 3) {
  90. Platform.runLater(() -> ConsoleManager.addNormalText(s));
  91. } else {
  92. Platform.runLater(() -> ConsoleManager.addErrorText(s));
  93. }
  94. }
  95. }
  96. /**
  97. * Short form for System.out.println().
  98. *
  99. * @param s
  100. * Integer to be printed on the console
  101. */
  102. public static void out(int s) {
  103. if (DEBUG_ENABLED) {
  104. System.out.println(s);
  105. }
  106. }
  107. /**
  108. * Prints out an XML event.
  109. *
  110. * @param e
  111. * the event to print out
  112. */
  113. public static void out(XMLEvent e) {
  114. MyFileSourceGraphML t = new MyFileSourceGraphML();
  115. switch (e.getEventType()) {
  116. case XMLStreamConstants.START_ELEMENT:
  117. Debug.out(t.gotWhat(e.getEventType(), e.asStartElement().getName().getLocalPart()));
  118. break;
  119. case XMLStreamConstants.END_ELEMENT:
  120. Debug.out(t.gotWhat(e.getEventType(), e.asEndElement().getName().getLocalPart()));
  121. break;
  122. case XMLStreamConstants.ATTRIBUTE:
  123. Debug.out(t.gotWhat(e.getEventType(), ((Attribute) e).getName().getLocalPart()));
  124. break;
  125. default:
  126. Debug.out(e.toString());
  127. }
  128. }
  129. }