📄 loggerview.java
字号:
LogIDs ID = (LogIDs) items[i].getData("LOGID");
if (ID != null) {
boolean checked = !ignoredComponents[index].contains(ID);
((Button) items[i]).setSelection(checked);
}
}
}
}
});
listLogTypes.notifyListeners(SWT.Selection, null);
Button btn;
btn = new Button(cChecksAndButtons, SWT.PUSH);
gd = new GridData();
btn.setLayoutData(gd);
Messages.setLanguageText(btn, "LoggerView.filter.checkAll");
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int index = listLogTypes.getSelectionIndex();
Control[] items = cChecks.getChildren();
for (int i = 0; i < items.length; i++) {
if (items[i] instanceof Button) {
LogIDs ID = (LogIDs) items[i].getData("LOGID");
if (ID != null && ignoredComponents[index].contains(ID)) {
((Button) items[i]).setSelection(true);
ignoredComponents[index].remove(ID);
}
}
}
}
});
btn = new Button(cChecksAndButtons, SWT.PUSH);
gd = new GridData();
btn.setLayoutData(gd);
Messages.setLanguageText(btn, "LoggerView.filter.uncheckAll");
btn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int index = listLogTypes.getSelectionIndex();
Control[] items = cChecks.getChildren();
for (int i = 0; i < items.length; i++) {
if (items[i] instanceof Button) {
LogIDs ID = (LogIDs) items[i].getData("LOGID");
if (ID != null && !ignoredComponents[index].contains(ID)) {
((Button) items[i]).setSelection(false);
ignoredComponents[index].add(ID);
}
}
}
}
});
if (!Logger.isEnabled()) {
consoleText.setText(MessageText.getString("LoggerView.loggingDisabled")
+ "\n");
}
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.IView#getComposite()
*/
public Composite getComposite() {
return panel;
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.IView#refresh()
*/
public void refresh() {
if (bPaused)
return;
synchronized (buffer) {
if (consoleText == null || consoleText.isDisposed())
return;
for (int i = 0; i < buffer.size(); i++) {
try {
LogEvent event = (LogEvent) buffer.get(i);
int nbLinesBefore = consoleText.getLineCount();
if (nbLinesBefore > MAX_LINES)
consoleText.replaceTextRange(0, consoleText
.getOffsetAtLine(PREFERRED_LINES), "");
final StringBuffer buf = new StringBuffer();
dateFormatter.format(event.timeStamp, buf, formatPos);
buf.append("{").append(event.logID).append("} ");
buf.append(event.text);
if (event.relatedTo != null) {
buf.append("; \t| ");
for (int j = 0; j < event.relatedTo.length; j++) {
Object obj = event.relatedTo[j];
if (j > 0)
buf.append("; ");
if (obj instanceof LogRelation) {
buf.append(((LogRelation) obj).getRelationText());
} else if (obj != null) {
buf.append(obj.getClass().getName()).append(": '").append(
obj.toString()).append("'");
}
}
}
buf.append('\n');
consoleText.append(buf.toString());
int nbLinesNow = consoleText.getLineCount();
int colorIdx = -1;
if (event.entryType == LogEvent.LT_INFORMATION)
colorIdx = COLOR_INFO;
else if (event.entryType == LogEvent.LT_WARNING)
colorIdx = COLOR_WARN;
else if (event.entryType == LogEvent.LT_ERROR)
colorIdx = COLOR_ERR;
if (colors != null && colorIdx >= 0)
consoleText.setLineBackground(nbLinesBefore - 1, nbLinesNow
- nbLinesBefore, colors[colorIdx]);
} catch (Exception e) {
// don't send it to log, we might be feeding ourselves
PrintStream ps = Logger.getOldStdErr();
if (ps != null) {
ps.println("Error writing event to console:");
e.printStackTrace(ps);
}
}
}
buffer.clear();
if (bAutoScroll)
consoleText.setSelection(consoleText.getText().length());
}
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.IView#delete()
*/
public void delete() {
Logger.removeListener(this);
if (panel != null && !panel.isDisposed())
panel.dispose();
Colors.getInstance().removeColorsChangedListener(this);
}
/* (non-Javadoc)
* @see org.gudy.azureus2.ui.swt.IView#getFullTitle()
*/
public String getFullTitle() {
return MessageText.getString("ConsoleView.title.full");
}
public String getData() {
return "ConsoleView.title.short";
}
public synchronized void log(final LogEvent event) {
if (display == null || display.isDisposed())
return;
if (ignoredComponents[logTypeToIndex(event.entryType)]
.contains(event.logID))
return;
// Always display STDERR messages, as they may relate to the filter
boolean bMatch = (event.logID == LogIDs.STDERR || filter == null);
if (!bMatch && event.relatedTo != null) {
for (int i = 0; !bMatch && i < event.relatedTo.length; i++) {
Object obj = event.relatedTo[i];
if (obj == null)
continue;
for (int j = 0; !bMatch && j < filter.length; j++) {
if (obj instanceof LogRelation) {
//System.err.println(obj.getClass().getSimpleName() + " is Logrelation");
Object newObj = ((LogRelation) obj).queryForClass(filter[j]
.getClass());
if (newObj != null)
obj = newObj;
}
//System.err.println(obj.getClass().getName() + " matches " + filter[j].getClass().getSimpleName() + "?");
if (obj == filter[j])
bMatch = true;
} // for filter
} // for relatedTo
}
if (bMatch) {
synchronized (buffer) {
if (buffer.size() >= 200)
buffer.removeFirst();
buffer.add(event);
}
if (bRealtime && !bPaused) {
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
refresh();
}
});
}
}
}
public void setFilter(Object[] _filter) {
filter = _filter;
clearConsole();
}
private void clearConsole() {
if (display == null || display.isDisposed())
return;
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
consoleText.setText("");
}
});
}
public void setEnabled(boolean on) {
if (bEnabled == on)
return;
bEnabled = on;
if (on)
Logger.addListener(this);
else
Logger.removeListener(this);
}
/* (non-Javadoc)
* @see org.gudy.azureus2.plugins.PluginView#getPluginViewName()
*/
public String getPluginViewName() {
return "Console";
}
// TODO: Support multiple selection
public void dataSourceChanged(Object newDataSource) {
boolean bEnable = newDataSource != null;
if (bEnable) {
if (newDataSource instanceof Object[])
setFilter((Object[]) newDataSource);
else
setFilter(new Object[] { newDataSource });
}
setEnabled(bEnable);
}
private int logTypeToIndex(int entryType) {
switch (entryType) {
case LogEvent.LT_INFORMATION:
return 0;
case LogEvent.LT_WARNING:
return 1;
case LogEvent.LT_ERROR:
return 2;
}
return 0;
}
private int indexToLogType(int index) {
switch (index) {
case 0:
return LogEvent.LT_INFORMATION;
case 1:
return LogEvent.LT_WARNING;
case 2:
return LogEvent.LT_ERROR;
}
return LogEvent.LT_INFORMATION;
}
public void parameterChanged(String parameterName) {
if (parameterName.startsWith("Color")) {
Utils.execSWTThread(new AERunnable() {
public void runSupport() {
if (display == null || display.isDisposed())
return;
if (colors == null)
colors = new Color[3];
final Color[] newColors = { Colors.blues[Colors.BLUES_MIDLIGHT],
Colors.colorWarning, Colors.red_ConsoleView };
boolean bColorChanged = false;
for (int i = 0; i < newColors.length; i++) {
if (colors[i] == null || colors[i].isDisposed()) {
colors[i] = newColors[i];
bColorChanged = true;
}
}
if (bColorChanged && consoleText != null) {
// remove color
String text = consoleText.getText();
consoleText.setText(text);
}
}
});
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -