代码拉取完成,页面将自动刷新
class XWndOutput: QDockWidget
{
QScintilla _scicomm, _sciext;
static const long APPENTEVENTID = 1;
List<String> outputList = new List<String>();
List<String> outputListext = new List<String>();
Object outputlock = new Object();
static bool outputInFocus = false;
public static XWndOutput outputWnd;
Thread mergeThread = nilptr, mergeThreadext = nilptr;
QPushButton btnCls;
QWidget edtarea;
//Timer urlmon = new Timer();
bool [] output_flags = new bool[16];
int output_count = 2;
bool sciisHand = false;
QPushButton [] btnOutput = new QPushButton[16];
Pattern url_match = new Pattern("((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]" +
"+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|" +
"(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)");
public static void Output(String text, int id)
{
outputWnd.output(text, id);
}
public static bool inFocus(){
return outputWnd.hasFocus();
}
public static int registryOutput(String icon){
if (icon == nilptr || icon.length() == 0){
return -1;
}
return outputWnd.registry_Output(icon);
}
public int registry_Output(@NotNilptr String icon){
btnOutput[output_count].show();
icon = icon.replace("\\","/");
btnOutput[output_count].setStyleSheetString("qproperty-icon: url(" + icon +") off, url(" + icon +") on ;");
return output_count++;
}
public void output(String text, int id)
{
if (id <0 || id > 15){
return;
}
if (output_flags[id] == false){
return;
}
synchronized(outputlock) {
if (id < 2){
outputList.add(text);
if (mergeThread == nilptr) {
//this.Notify(APPENTEVENTID);
processOutputComm();
}
}else{
outputListext.add(text);
if (mergeThreadext == nilptr) {
//this.Notify(APPENTEVENTID);
processOutputExt();
}
}
}
}
public void Copy(){
if (_scicomm.isVisible()){
_scicomm.Copy();
}
}
public void clearComm(bool focus)
{
_scicomm.clear();
if (focus){
raise();
}
}
public void clearAll(bool focus)
{
_scicomm.clear();
_sciext.clear();
if (focus){
raise();
}
}
public void reconfig()
{
syntaxForOutput(_scicomm);
syntaxForOutput(_sciext);
}
/**
这里用到一个延迟加载的算法, LOG可能会输出上百万行, 高频率连续不断的刷新造成SCI无法及时处理,导致界面停止响应。
因此用一个单独的线程来对琐碎的log文本进行合并
但是合并时间不能太久,否则会造成输出卡顿
所以合并的时候需要计算合并的行数 然后得出合并花费的时间, 既刷新间隔,达到阈值后再显示,
阈值算法
阈值 = 显示所用时间 + 50毫秒 + 行数 / 100000 * 5 毫秒
经测试, 能有效处理百万行级别的log输出
滚动算法, 显示的最顶端行 + 可显示的行 如果小于最后行 说明被人为向上拉了, 则停止自动滚动, 反之自动滚动
*/
public void processOutputComm()
{
mergeThread = new Thread() {
void run() {
List<String> tmplist = nilptr;
synchronized(outputlock) {
tmplist = outputList;
outputList = new List<String>();
}
int interval = 50;
while(tmplist != nilptr) {
String finalstr = "";
List.Iterator<String> iter = tmplist.iterator();
while (iter.hasNext()) {
long start = _system_.currentTimeMillis();
int mgcount = 0;
while (iter.hasNext()) {
String str = iter.next();
finalstr = finalstr + str;
mgcount++;
if (mgcount > interval) {
mgcount = 0;
long curtime = _system_.currentTimeMillis();
if (curtime - start > interval) {
break;
}
}
}
runOnUi(new Runnable() {
String appstr = finalstr;
void run()override {
String _str = getContent();
if (_str != nilptr){
interval = appendTextAndScroll(_scicomm, _str);
}
}
String getContent(){
return appstr;
}
});
finalstr = "";
}
_system_.sleep(100);
synchronized(outputlock) {
if (outputList.size() == 0) {
mergeThread = nilptr;
break;
} else {
tmplist = outputList;
outputList = new List<String>();
}
}
}
}
};
mergeThread.start();
}
public int appendTextAndScroll(@NotNilptr QScintilla _sci,@NotNilptr String appstr){
long displaytime = _system_.currentTimeMillis();
bool bWrap = _sci.isWrap();
int cutcountline = 0;
if (bWrap == false){
int topline = _sci.getFirstVisibleLine();
int scrlines = _sci.getLinesOfDisplay();
topline += scrlines;
bool tobottom = true;
if (topline < _sci.countOfLine()) {
tobottom = false;
}
_sci.appendText(appstr);
cutcountline = _sci.countOfLine();
if (cutcountline > 50000){
long del_end_pos = _sci.getEndOfLine(10000);
_sci.selectAndReplace(0,del_end_pos,"");
}
if (tobottom) {
_sci.setFirstVisibleLine(cutcountline - scrlines);
}
}else{
cutcountline = _sci.countOfLine();
bool tobottom = _sci.getCurrentPosition() == _sci.getLength();
_sci.appendText(appstr);
cutcountline = _sci.countOfLine();
if (cutcountline > 50000){
long del_end_pos = _sci.getEndOfLine(10000);
_sci.selectAndReplace(0,del_end_pos,"");
cutcountline = _sci.countOfLine();
}
if (tobottom){
_sci.gotoPos(_sci.getLength());
}
}
displaytime = _system_.currentTimeMillis() - displaytime;
return displaytime + 50 + (cutcountline / 100000) * 5;
}
public void processOutputExt()
{
mergeThreadext = new Thread() {
void run() {
List<String> tmplist = nilptr;
synchronized(outputlock) {
tmplist = outputListext;
outputListext = new List<String>();
}
int interval = 50;
while(tmplist != nilptr) {
String finalstr = "";
List.Iterator<String> iter = tmplist.iterator();
while (iter.hasNext()) {
long start = _system_.currentTimeMillis();
int mgcount = 0;
while (iter.hasNext()) {
String str = iter.next();
finalstr = finalstr + str;
mgcount++;
if (mgcount > interval) {
mgcount = 0;
long curtime = _system_.currentTimeMillis();
if (curtime - start > interval) {
break;
}
}
}
runOnUi(new Runnable() {
String appstr = finalstr;
void run()override {
String _str = getContent();
if (_str != nilptr){
interval = appendTextAndScroll(_sciext, _str);
}
}
String getContent(){
return appstr;
}
});
finalstr = "";
}
_system_.sleep(100);
synchronized(outputlock) {
if (outputListext.size() == 0) {
mergeThreadext = nilptr;
break;
} else {
tmplist = outputListext;
outputListext = new List<String>();
}
}
}
}
};
mergeThreadext.start();
}
public void syntaxForOutput(@NotNilptr QScintilla _sci)
{
if (Setting.isDarkStyle()) {
syntaxForOutputDark(_sci);
return ;
}
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
//_sci.setWrap(true);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, 0xffffffff);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, 0xff222827);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, 0xff222827);
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_CLEARDOCUMENTSTYLE, 0, 0);
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
bool bmac = (_system_.getPlatformId() == 2);
if (bmac == false) {
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,"Consolas");
_sci.sendEditor(QScintilla.SCI_STYLESETSIZE, QScintilla.STYLE_DEFAULT,9);
} else {
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,"Monaco");
_sci.sendEditor(QScintilla.SCI_STYLESETSIZE, QScintilla.STYLE_DEFAULT,11);
}
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_SETSELBACK,1,0xfff1ebe5);
_sci.sendEditor(QScintilla.SCI_SETSELFORE,0,0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, 0, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 0, 65);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 1, 5);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 2, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 3, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 4, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, 0xffaf912b);
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,0xff000000,0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_SETTABWIDTH, 4);
_sci.setWrap(Setting.isOutputWrap());
}
public void syntaxForOutputDark(@NotNilptr QScintilla _sci)
{
_sci.sendEditor(QScintilla.SCI_SETCODEPAGE, QScintilla.SC_CP_UTF8);
//_sci.setWrap(true);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_DEFAULT, 0xff262525);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_DEFAULT, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, 75, 0xffefefef);
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_CLEARDOCUMENTSTYLE, 0, 0);
//_sci.sendEditor(QScintilla.STYLE_LINENUMBER, 1, 0);
bool bmac = (_system_.getPlatformId() == 2);
if (bmac == false) {
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,"Consolas");
_sci.sendEditor(QScintilla.SCI_STYLESETSIZE, QScintilla.STYLE_DEFAULT,9);
} else {
_sci.sendEditor(QScintilla.SCI_STYLESETFONT, QScintilla.STYLE_DEFAULT,"Monaco");
_sci.sendEditor(QScintilla.SCI_STYLESETSIZE, QScintilla.STYLE_DEFAULT,11);
}
_sci.sendEditor(QScintilla.SCI_STYLECLEARALL, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETEOLMODE, 1, 0);
_sci.sendEditor(QScintilla.SCI_SETSELBACK,1,0xff3e4849);
_sci.sendEditor(QScintilla.SCI_SETSELFORE,0,0);
_sci.sendEditor(QScintilla.SCI_SETMARGINTYPEN, 0, QScintilla.SC_MARGIN_NUMBER);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 0, 65);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 1, 5);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 2, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 3, 0);
_sci.sendEditor(QScintilla.SCI_SETMARGINWIDTHN, 4, 0);
_sci.sendEditor(QScintilla.SCI_STYLESETBACK, QScintilla.STYLE_LINENUMBER, 0xff262525);
_sci.sendEditor(QScintilla.SCI_STYLESETFORE, QScintilla.STYLE_LINENUMBER, 0xff666666);
_sci.sendEditor(QScintilla.SCI_SETMARGINLEFT, 0, 0);
_sci.sendEditor(QScintilla.SCI_SETCARETFORE,0xffffffff,0);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEVISIBLE, 1);
_sci.sendEditor(QScintilla.SCI_SETCARETLINEBACK, 0xff202020);
_sci.setWrap(Setting.isOutputWrap());
}
public bool onClose()override
{
/*if (urlmon != nilptr){
urlmon.cancel();
urlmon = nilptr;
}*/
return true;
}
onClickListener extclick = new onClickListener(){
void onClick(@NotNilptr QObject obj, bool checked) {
int n = (int)obj.getTag();
output_flags[n] = checked;
switch_sci(false);
}
};
public void switch_sci(bool commMain){
bool comm_show, ext_show;
for (int i =0; i < 16; i ++){
if (output_flags[i]){
if (i < 2){
comm_show = true;
}else{
ext_show = true;
}
}
}
if (ext_show && !commMain){
_scicomm.hide();
_sciext.show();
btnOutput[0].setCheck(false);
btnOutput[1].setCheck(false);
}else{
_sciext.hide();
_scicomm.show();
if (output_flags[0] == false && output_flags[1] == false){
output_flags[0] = true;
btnOutput[0].setCheck(true);
}
for (int i =2; i < 16; i ++){
btnOutput[i].setCheck(false);
}
}
}
public void onAttach()
{
edtarea = (QWidget)attachByName(new QWidget(),"edtarea");
btnOutput[0] = (QPushButton)attachByName(new QPushButton(),"btnBuild");
btnOutput[1] = (QPushButton)attachByName(new QPushButton(),"btnDebug");
for (int i =2; i < 16; i ++){
btnOutput[i] = (QPushButton)attachByName(new QPushButton(),"btnDebug_" + i);
btnOutput[i].hide();
btnOutput[i].setTag(i);
btnOutput[i].setOnClickListener(extclick);
}
btnCls = (QPushButton)attachByName(new QPushButton(),"btnCls");
btnOutput[0].setOnClickListener(new onClickListener(){
void onClick(QObject obj, bool checked) {
output_flags[0] = checked;
switch_sci(true);
}
});
btnOutput[1].setOnClickListener(new onClickListener(){
void onClick(QObject obj, bool checked) {
output_flags[1] = checked;
switch_sci(true);
}
});
btnCls.setOnClickListener(new onClickListener(){
void onClick(QObject obj, bool checked) {
_scicomm.setText("");
_sciext.setText("");
}
});
_scicomm = new QScintilla();
_sciext = new QScintilla();
initSci(_scicomm);
initSci(_sciext);
outputWnd = this;
edtarea.setOnLayoutEventListener(new onLayoutEventListener() {
void onResize(QObject obj, int w, int h, int oldw, int oldh)override {
if (_scicomm != nilptr) {
_scicomm.resize(w, h );
}
if (_sciext != nilptr) {
_sciext.resize(w, h );
}
}
});
/*urlmon.schedule(new TimerTask(){
void run(){
runOnUi(new Runnable(){
void run()override{
testUrl();
}
});
}
}, 1000, -1);*/
switch_sci(true);
output_flags[1] = true;
btnOutput[1].setCheck(true);
}
public void initSci(@NotNilptr QScintilla _sci){
__nilptr_safe(edtarea);
if (_sci.create(edtarea)) {
syntaxForOutput(_sci);
_sci.setOnSciEventListener(new SciEventListener() {
void ON_DOUBLECLICK(@NotNilptr QScintilla sci,int position, int line, int modifiers) {
String lineText = sci.getText(line);
if (lineText.length() > 0) {
Project project = XWorkspace.workspace.getCurrentProject();
try{
if (project != nilptr){
ProjectPropInterface intel = project.getPropInterface();
if (intel != nilptr){
ICompileInfo icf = intel.parseOutputLine(sci, position, line, lineText);
if (icf != nilptr){
String tarfile = icf.getFile();
int tarline = icf.getLine();
int tarrow = icf.getRow();
String tarinfo = icf.getTips();
if (tarfile != nilptr && tarfile.length() > 0){
XSourceEditor.openForFileInfo(XWorkspace.workspace, tarfile, tarline, tarrow, icf.getTitle(), tarinfo);
}
}
}
}
}catch(Exception e){
}
}
}
});
_sci.setIndicStyle(1, QScintilla.INDIC_PLAIN);
_sci.sendEditor(QScintilla.SCI_INDICSETFORE,1,0xfff0d964);
_sci.setIndicCurrent(1);
QWidget viewport = _sci.viewPort();
if (viewport != nilptr){
viewport.setOnMouseEventListener(new onMouseEventListener() {
void onMouseMove(QObject obj, int Button, int x, int y, int flags, int source)override {
if (sciisHand) {
int pos = _sci.positionFromPoint(x, y);
int start = _sci.getIndicStart(1, pos);
int end = _sci.getIndicEnd(1, start);
int dic = _sci.IndicForPosition(start);
if (dic != 0 && start != 0 && end != 0) {
_sci.setCursor(QScintilla.cursorHand);
showTips(_sci, pos, "按下鼠标左键在浏览器中访问链接.");
}
}
}
void onMouseButtonPress(QObject obj, int Button, int x, int y, int flags, int source)override {
if (sciisHand) {
int pos = _sci.positionFromPoint(x, y);
int start = _sci.getIndicStart(1, pos);
int end = _sci.getIndicEnd(1, start);
int dic = _sci.IndicForPosition(start);
if (dic != 0 && start != 0 && end != 0) {
_sci.setSelect(start, end);
String current_Url = _sci.getSelectedText();
current_Url = current_Url.trim(true);
if (current_Url.length() > 0) {
openUrl(current_Url);
}
}
}
}
});
}
_sci.setOnKeyEventListener(new onKeyEventListener() {
bool onKeyPress(QObject obj, int key, bool repeat, int count, String text, int scanCode, int virtualKey, int modifier)override {
if (key == Constant.Key_Control && sciisHand == false) {
sciisHand = true;
testUrl(_sci);
}
return true;
}
bool onKeyRelease(QObject obj, int key, bool repeat, int count, String text, int scanCode, int virtualKey, int modifier)override {
if (key == Constant.Key_Control ) {
_sci.setCursor(QScintilla.cursorText);
sciisHand = false;
}
return true;
}
});
_sci.setOnFocusEventListener(new onFocusEventListener() {
void onFocusIn(QObject obj, bool focus, int reson) {
sciisHand = false;
XFindDlg.findinOutput = true;
_sci.setCursor(QScintilla.cursorText);
}
void onFocusOut(QObject obj, bool focus, int reson) {
sciisHand = false;
_sci.setCursor(QScintilla.cursorText);
}
});
}
}
public void showTips(@NotNilptr QScintilla _sci, int position, String content)
{
_sci.showTips(position, content);
}
public QScintilla getCurrentSci(){
if (_scicomm.isVisible()){
return _scicomm;
}else{
return _sciext;
}
}
public void testUrl(@NotNilptr QScintilla _sci)
{
if (_sci.isModified()) {
String text = _sci.getText();
_sci.clearIndic(0, _sci.getLength());
_sci.setIndicCurrent(1);
if (text.length() > 0) {
Pattern.Result rt = url_match.matchAll(text, 0, -1, 0);
for (int i = 0, c = rt.length(); i < c; i++) {
int start = rt.get(i).start();
int end = rt.get(i).end();
_sci.applyIndic(start, end - start + 1);
}
}
_sci.setSavePoint();
}
}
};
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。