-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolLogger.java
171 lines (154 loc) · 4.28 KB
/
ToolLogger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package paint;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author jchic
*/
public class ToolLogger {
// MEMBER VARIABLES
private CanvasManager canvasManager;
private Thread thread;
private final int SLEEPTIME = 1000;
private int counter = 0;
private int writeTime = 0;
private boolean sameTool = true;
private InteractMode oldTool, tool;
private PrintWriter writer;
// CONSTRUCTOR
/**
* Constructor. Sets up the thread for the writing to the logging.
*
*/
public ToolLogger() {
// setting the old tool to the default tool
tool = oldTool = InteractMode.PAN;
// creating the new thread
thread = new Thread(() -> {
//CanvasManager canvasMan;
while(true)
handleLog();
});
thread.setDaemon(true);
}
// METHODS
/**
* Starts the timer thread.
*/
public void start(){
thread.start();
}
/**
* Stops the timer thread by joining it.
*/
public void stop(){
try {
thread.join();
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
private void handleLog(){
// every second it'll update it's counter
while (sameTool){
try {
Thread.sleep(SLEEPTIME);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
counter++;
}
sameTool = true;
String toolName;
switch(oldTool){
case PAN:
toolName = "Pan";
break;
case SELECT:
toolName = "Select";
break;
case COLOR_GRABBER:
toolName = "Color Grabber";
break;
case LINE:
toolName = "Line";
break;
case BRUSH:
toolName = "Brush";
break;
case BUCKET:
toolName = "Bucket";
break;
case ERASER:
toolName = "Eraser";
break;
case TEXT:
toolName = "Text";
break;
case SQUARE_OUTLINE:
toolName = "Square Outline";
break;
case SQUARE_FILL:
toolName = "Square Fill";
break;
case RECTANGLE_OUTLINE:
toolName = "Rectangle Outline";
break;
case RECTANGLE_FILL:
toolName = "Rectangle Fill";
break;
case ELLIPSE_OUTLINE:
toolName = "Ellipse Outline";
break;
case ELLIPSE_FILL:
toolName = "Ellipse Fill";
break;
case CIRCLE_OUTLINE:
toolName = "Circle Outline";
break;
case CIRCLE_FILL:
toolName = "Circle Fill";
break;
case SHAPE:
toolName = "Shape";
break;
default:
toolName = "Unknown";
break;
}
// setting up the logger's writing out
FileWriter fileWriter;
try {
fileWriter = new FileWriter("logs/tool.txt");
} catch (IOException ex) {
fileWriter = null;
}
writer = new PrintWriter(fileWriter);
// Writing out the tool & the time used
/*try{
} catch (IOException ex){
ex.printStackTrace();
}*/
writer.printf("%s",toolName);
writer.printf("%d",writeTime);
writer.print("--------------------------------------");
writer.close();
}
public void update(InteractMode mode){
oldTool = tool;
tool = mode;
writeTime = counter;
counter = 0;
sameTool = false;
}
}