我试图突出显示从客户端发送的修复消息的错误。但是,这样做时它不会遵循此算法。如果修复消息中有错误只是一个字符串,它将突出显示整个字符串,否则它将不突出显示。基本上我要问的是如何突出显示多个部分,而不是在出现错误时突出显示整个输出?
例如:我得到的错误
no error - unhighlighted
error - highlighted
no error - highlighted
no error - highlighted
no error - highlighted
error - highlighted
我想要的是:
no error - unhighlighted
error - highlighted
no error - unhighlighted
no error - unhighlighted
no error - unhighlighted
error - highlighted
问题区
if(outputLine.equals("No errors")) {
tfCSVLine.append(outputLine+"\n\n\n");
lengthH += (inputLine+"\n\n\n").length();
}
else {
tfCSVLine.append(outputLine+"\n\n\n");
int pos = inputLine.indexOf(inputLine, 0);
int len = lengthH;
lengthH += (inputLine+"\n\n\n").length();
h.addHighlight(len, lengthH+(inputLine+"\n\n\n").length(),
DefaultHighlighter.DefaultPainter);
}
程序
Highlighter h = tfFIXMsg.getHighlighter();
try {
int lengthH = 0;
while ((inputLine = in.readLine()) != null) {
System.out.println ("Server: " + inputLine);
tfFIXMsg.append( inputLine + "\n\n\n");
if (inputLine.trim().equals("Bye.")) {
System.out.println("Exit program");
break;
}
Scanner input1 = new Scanner(new File(csvName));
Scanner input2 = new Scanner(new File(csvName));
Scanner input3 = new Scanner(new File(csvName));
Scanner input4 = new Scanner(new File(csvName));
String csvline = getCsvLineVal(getLocation34CSV(
getTag34Value(Tag34Location(getTagCSV(parseFixMsg(
inputLine ,inputLine))), getValueCSV( parseFixMsg(
inputLine ,inputLine))), getVal34(input1,input2)),
getCSVLine( input3, input4) );
outputLine = compareClientFixCSV( getTagCSV(parseFixMsg(
inputLine ,inputLine)), getValueCSV(parseFixMsg(
inputLine ,inputLine)), getCSVTag(csvline), getCSVValue(csvline));
out.println(outputLine);
if(outputLine.equals("No errors")) {
tfCSVLine.append(outputLine+"\n\n\n");
lengthH += (inputLine+"\n\n\n").length();
}
else {
tfCSVLine.append(outputLine+"\n\n\n");
int pos = inputLine.indexOf(inputLine, 0);
int len = lengthH;
lengthH += (inputLine+"\n\n\n").length();
h.addHighlight(len, lengthH+(inputLine+"\n\n\n").length(),
DefaultHighlighter.DefaultPainter);
}
input1.close();
input2.close();
input3.close();
input4.close();
}