monkey doodle
monkey doodle

Reputation: 700

how to highlight separately

I'm trying to highlight the errors of the fix message sent from client side. However, when doing so it will not follow this algorithm. If there is an error in the fix message which is just a string, it will highlight the entire string, otherwise it will just leave it unhighlighted. Basically what I'm asking is how do I highlight multiple parts, rather than highlighting the entire output once there is an error?

for example: The error I'm getting

no error - unhighlighted
error - highlighted
no error - highlighted
no error - highlighted
no error - highlighted
error - highlighted

what I want:

no error - unhighlighted
error - highlighted
no error - unhighlighted
no error - unhighlighted
no error - unhighlighted
error - highlighted

problem area

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);
}

Program

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();
}

Upvotes: 1

Views: 105

Answers (1)

Loedolff
Loedolff

Reputation: 172

You are adding (inputLine+"\n\n\n").length() twice to lengthH. You should probably do that just once? Also, it doesn't look like lengthH is properly initialized when the 'else' block executes?

Upvotes: 2

Related Questions