View Javadoc

1   package SocialSteeringsBeta;
2   
3   import cz.cuni.amis.pogamut.base3d.worldview.object.Location;
4   import java.io.BufferedWriter;
5   import java.io.File;
6   import java.io.FileWriter;
7   import java.util.Calendar;
8   import java.util.GregorianCalendar;
9   import java.util.HashMap;
10  
11  
12  /**
13   *
14   * @author Petr
15   * DEBUG class
16   */
17  public class SOC_STEER_LOG {
18  
19      public static boolean DEBUG = true;
20      private static HashMap<String, StringBuilder> log = new HashMap<String, StringBuilder>();
21      private static Calendar calendar = new GregorianCalendar();
22  
23       public static HashMap<String, Location> logFlags = new HashMap<String,Location>();
24     // private static StoryController controller;
25  
26      @Deprecated
27      private static final String KDefault = "default";
28      private static final String KPath = "./log/quarrel/";
29  
30      public static final String KParse = "parse";
31      public static final String KError = "error";
32      public static String KAnimation = "anim";
33      public static String KMinibeatChain = "MinibeatChain";
34      static String KSync = "sync";
35  
36      @Deprecated
37      public static void AddLogLine(String s) {
38  
39          AddLogLine(s, KDefault);
40      }
41      /**
42       message, file
43       * @param message
44       * @param file 
45       */
46      public static synchronized void AddLogLine(String message, String file) {
47          if (log.get(file) == null) {
48              log.put(file, new StringBuilder(""));
49  
50          }
51          log.get(file).append("\n\r\n");
52          log.get(file).append(message);
53      }
54  
55      @Deprecated
56      public static void AddLogLineWithDate(String mes) {
57          AddLogLineWithDate(mes, KDefault);
58      }
59  
60      /**
61       message, file
62       * @param mes
63       * @param file
64       */
65      public static synchronized void AddLogLineWithDate(String mes, String file) {
66          
67          AddLogLine(Date(), file);
68          AddLogLine(mes, file);
69      }
70      
71      @Deprecated
72      public static void PrintLog() {
73          PrintLog(KDefault);
74      }
75      public static void PrintLog(String file) {
76          if (log.get(file) == null) {
77              return;
78          }
79          String ret = log.get(file).toString();
80          if (file != null) {
81              System.out.print(ret);
82          }
83      }
84  
85      @Deprecated
86      public static void DiscardLog() {
87          DiscardLog(KDefault);
88      }
89      public static void DiscardLog(String file) {
90          log.remove(file);
91      }
92  
93      /**
94       *
95       * @param file
96       */
97      public static void DumpToFile(String file) {
98          if (log.get(file) == null) {
99              return;
100         }
101         String ret = log.get(file).toString();
102         String path = KPath + file/* + Date() */+ "SOC.log";
103         try {
104             // Create file
105             File f = new File(path);
106             if(!f.exists())
107             {
108                 f.createNewFile();
109             }else
110             {
111                 ret = "\n\r\nNEW LOG\n\r\n" + ret;
112             }
113             FileWriter fstream = new FileWriter(path);
114             BufferedWriter out = new BufferedWriter(fstream);
115 
116             out.write(ret);
117             //Close the output stream
118             out.close();
119         } catch (Exception e) {
120             e.printStackTrace();
121         }
122     }
123 
124     public static void DumpAllContent()
125     {
126         for(String s : log.keySet())
127         {
128             DumpToFile(s);
129         }
130     }
131 
132     private static String Date()
133     {
134         calendar = new GregorianCalendar();
135         int hour = calendar.get(Calendar.HOUR);
136         int minute = calendar.get(Calendar.MINUTE);
137         int second = calendar.get(Calendar.SECOND);
138         int millisecond = calendar.get(Calendar.MILLISECOND);
139 
140         return "\nTIME--" + hour + "-" + minute + "-" + second + "-" + millisecond;
141 
142     }
143 
144     @Deprecated
145     public static void DumpToFile() {
146         DumpToFile(KDefault);
147     }
148 
149 
150 //    public static void setController(StoryController c)
151 //    {
152 //        controller = c;
153 //    }
154     public static void setNewFlag(String name, Location place)
155     {
156         logFlags.put(name, place);
157         //debuging command ktery placne do sceny nejaky token na danou pozici..
158         //CommandSpawnActor c = new CommandSpawnActor();
159         //c.setId(name);
160         //c.setLocation(place);
161         //c.setType("GameBotsUE2.GBTextureMarker");
162         //nebo
163         //c.setType("GameBotsUE2.GBPlaneMarker");
164         //controller.getControlServer().getAct().act(c);
165       
166     }
167     public static void removeFlag(String name)
168     {
169        logFlags.remove(name);
170     }
171 }