forked from archduke31/ADBLogger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemConfigs.java
More file actions
325 lines (273 loc) · 10.2 KB
/
Copy pathSystemConfigs.java
File metadata and controls
325 lines (273 loc) · 10.2 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
/*
* Copyright (C) 2009 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package feiw;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonIOException;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.JsonSyntaxException;
import feiw.LogSource.LogFilter;
public final class SystemConfigs {
public static final int RECENTLIST_SIZE = 6;
private static String CFG_FNAME = null;
private static SystemConfigs mCfgs = null;
public static boolean mIsWindows = false;
static {
if (SWT.getPlatform().contains("win")) {
String path = System.getenv("APPDATA");
if (!path.endsWith("\\")) {
path += "\\";
}
File dir = new File(path);
if (dir.exists() && dir.canWrite()) {
CFG_FNAME = path + "superlog.cfg";
}
mIsWindows = true;
} else {
String path = System.getProperty("user.home");
if (!path.endsWith("/")) {
path += "/";
}
File dir = new File(path);
if (dir.exists() && dir.canWrite()) {
CFG_FNAME = path + ".superlog";
}
}
System.out.println("config file:" + CFG_FNAME);
mCfgs = load();
}
public static SystemConfigs instance() {
return mCfgs;
}
public final long LIVE_LOG_NOTIFYTIME = 300;
public static final class LogUrl {
public String scheme;
public String url;
public int port;
public LogUrl(String s, String u, int p) {
scheme = s;
url = u;
port = p;
}
@Override
public String toString() {
return scheme + "://" + url + ":" + port;
}
@Override
public boolean equals(Object o) {
if (o instanceof LogUrl) {
return ((LogUrl) o).url.equals(url) && (((LogUrl) o).port == port);
}
return false;
}
}
private ArrayList<LogUrl> mRecentUrls = new ArrayList<LogUrl>(10);
private class Colors {
private Color[] mForeColors;
private Color[] mBackColors;
private Color mSearchBackColor;
public Colors() {
Display disp = Display.getCurrent();
mForeColors = new Color[] { disp.getSystemColor(SWT.COLOR_BLACK), disp.getSystemColor(SWT.COLOR_DARK_RED),
disp.getSystemColor(SWT.COLOR_WHITE), disp.getSystemColor(SWT.COLOR_BLUE),
disp.getSystemColor(SWT.COLOR_DARK_BLUE), disp.getSystemColor(SWT.COLOR_DARK_GREEN),
disp.getSystemColor(SWT.COLOR_BLACK), disp.getSystemColor(SWT.COLOR_DARK_GRAY) };
mBackColors = new Color[] { disp.getSystemColor(SWT.COLOR_WHITE), disp.getSystemColor(SWT.COLOR_WHITE),
disp.getSystemColor(SWT.COLOR_RED), disp.getSystemColor(SWT.COLOR_YELLOW),
disp.getSystemColor(SWT.COLOR_WHITE), disp.getSystemColor(SWT.COLOR_WHITE),
disp.getSystemColor(SWT.COLOR_WHITE), disp.getSystemColor(SWT.COLOR_WHITE) };
mSearchBackColor = disp.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
}
}
Colors mColors = new Colors();
public static class ColorSerializer implements JsonSerializer<Color> {
@Override
public JsonElement serialize(Color arg0, Type arg1, JsonSerializationContext arg2) {
return arg2.serialize(arg0.getRGB());
}
}
public static class ColorDeserializer implements JsonDeserializer<Color> {
@Override
public Color deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
throws JsonParseException {
return new Color(Display.getCurrent(), (RGB) (arg2.deserialize(arg0, RGB.class)));
}
}
private void initDefault() {
// mRecentUrls.add(new LogUrl("qconn", "10.222.98.205", 8000));
// mRecentUrls.add(new LogUrl("qconn", "10.222.109.58", 8000));
addRecentFilter(LogFilter.newLogFilter(LogFilter.FIELD_PRIORITY, LogFilter.OP_LESSTHEN, Integer.valueOf(7)));
addRecentFilter(LogFilter.newLogFilter(LogFilter.FIELD_PRIORITY, LogFilter.OP_LESSTHEN, Integer.valueOf(6)));
addRecentFilter(LogFilter.newLogFilter(LogFilter.FIELD_PRIORITY, LogFilter.OP_LESSTHEN, Integer.valueOf(5)));
}
private SystemConfigs() {
initDefault();
if (mIsWindows) {
mLogFontName = "Couier New";
} else {
mLogFontName = "Monaco";
}
mLogFontSize = 12;
// addRecentFilter(LogFilter.newLogFilter(LogFilter.FIELD_PRIORITY,
// LogFilter.OP_LESSTHEN, Integer.valueOf(6)));
// addRecentFilter(LogFilter.newLogFilter(LogFilter.FIELD_PRIORITY,
// LogFilter.OP_LESSTHEN, Integer.valueOf(5)));
// addRecentFilter(LogFilter.newLogFilter(LogFilter.FIELD_PRIORITY,
// LogFilter.OP_LESSTHEN, Integer.valueOf(4)));
}
public Color getSearchMarkerBackground() {
return mColors.mSearchBackColor;
}
public Color getLogForeground(int level) {
return mColors.mForeColors[level];
}
public Color getLogBackground(int level) {
if (level < 5)
return mColors.mBackColors[level];
else
return null;
}
int mLogRollingLines = 200000;
public int getLogRollingLines() {
return mLogRollingLines;
}
transient ArrayList<LogFilter> mRecentFilters = new ArrayList<LogFilter>(10);
public void addRecentFilter(LogFilter f) {
// TODO: no duplicate.
mRecentFilters.add(0, f);
}
public LogFilter getRecentFilter(int i) {
if (i < mRecentFilters.size()) {
return mRecentFilters.get(i);
}
return null;
}
ArrayList<String> mRecentFiles = new ArrayList<String>(10);
public void addRecentFile(String f) {
if (mRecentFiles.contains(f)) {
mRecentFiles.remove(f);
}
mRecentFiles.add(0, f);
if (mRecentFiles.size() > 10) {
mRecentFiles.remove(mRecentFiles.size() - 1);
}
}
public String getRecentFile(int i) {
if (i < mRecentFiles.size()) {
return mRecentFiles.get(i);
}
return null;
}
public void addRecentUrl(LogUrl u) {
if (mRecentUrls.contains(u)) {
mRecentUrls.remove(u);
}
mRecentUrls.add(0, u);
if (mRecentUrls.size() > 10) {
mRecentUrls.remove(mRecentUrls.size() - 1);
}
}
public LogUrl getRecentUrl(int i) {
if (i < mRecentUrls.size()) {
return mRecentUrls.get(i);
}
return null;
}
String mAdbPath = "/Developer/SDKs/android-sdk/platform-tools";
public String getAdbPath() {
if (!mAdbPath.endsWith("/")) {
return mAdbPath + "/";
}
return mAdbPath; // /Developer/SDKs/android-sdk/platform-tools/adb";
}
public void setAdbPath(String p) {
mAdbPath = p;
}
String mLogFontName;
int mLogFontSize;
public String getLogFontName() {
return mLogFontName;
}
public int getLogFontSize() {
return mLogFontSize;
}
public void setLogFontName(final String fn) {
mLogFontName = fn;
}
public void setLogFontSize(int size) {
mLogFontSize = size;
}
public String toJson() {
return new GsonBuilder().setPrettyPrinting().serializeNulls()
.registerTypeAdapter(Color.class, new ColorSerializer()).create().toJson(this);
}
private static SystemConfigs load() {
File cfgfile = new File(CFG_FNAME);
if (cfgfile.exists()) {
try {
return new GsonBuilder().setPrettyPrinting().serializeNulls()
.registerTypeAdapter(Color.class, new ColorDeserializer()).create()
.fromJson(new InputStreamReader(new FileInputStream(cfgfile), "UTF-8"), SystemConfigs.class);
} catch (FileNotFoundException e) {
// e.printStackTrace();
} catch (JsonSyntaxException e) {
// e.printStackTrace();
} catch (JsonIOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return new SystemConfigs();
}
void save() {
if (CFG_FNAME != null) {
try {
OutputStreamWriter wr = new OutputStreamWriter(new FileOutputStream(CFG_FNAME));
wr.write(toJson());
wr.flush();
wr.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}