Exemplo n.º 1
0
 /**
  * Removes the '^' formatting.
  *
  * @param value
  * @return
  */
 public static String removeFormatting(final String value) {
   if (value == null) {
     return null;
   }
   PrimativeTokenizer tokenizer = PrimativeTokenizer.getStringInstance(value, debug);
   StringBuffer tooltip = new StringBuffer();
   boolean removeIndentFormatting = false;
   boolean startOfLine = true;
   Token token = null;
   try {
     tokenizer.initialize();
     token = tokenizer.next();
   } catch (IOException e) {
     return value;
   } catch (LogFile.LockException e) {
     e.printStackTrace();
     return value;
   }
   try {
     while (value != null && !token.is(Token.Type.EOF)) {
       // Remove indent formatting whitespace that comes after new-line formatting
       // character.
       if (removeIndentFormatting) {
         removeIndentFormatting = false;
         if (token.is(Token.Type.WHITESPACE)) {
           token = tokenizer.next();
           startOfLine = false;
           continue;
         }
       }
       // Remove the new-line formatting character ('^' at the beginning of the line).
       if (startOfLine && token.equals(Token.Type.SYMBOL, NEW_LINE_CHAR)) {
         // new-line may be followed by indent formatting that should be removed
         removeIndentFormatting = true;
         startOfLine = false;
       }
       // Convert end of line to a space.
       else if (token.is(Token.Type.EOL)) {
         tooltip.append(' ');
         // signal the start of the next line, so that new-line formatting
         // characters can be found
         startOfLine = true;
       } else {
         tooltip.append(token.getValue());
         startOfLine = false;
       }
       token = tokenizer.next();
     }
   } catch (IOException e) {
     return value;
   }
   return tooltip.toString();
 }
Exemplo n.º 2
0
 public void logMessage(Loggable loggable, AxisID axisID) {
   if (loggable == null) {
     return;
   }
   try {
     SwingUtilities.invokeLater(
         new AppendLater(
             Utilities.getDateTimeStamp(), loggable.getName(), loggable.getLogMessage(), axisID));
   } catch (LogFile.LockException e) {
     e.printStackTrace();
     SwingUtilities.invokeLater(new AppendLater("Unable to log message:", e.getMessage()));
   } catch (IOException e) {
     e.printStackTrace();
     SwingUtilities.invokeLater(new AppendLater("Unable to log message:", e.getMessage()));
   }
 }
Exemplo n.º 3
0
 /**
  * Uses the '^' formatting to format the value.
  *
  * @param value
  * @return
  */
 public static String[] format(final String value) {
   if (value == null) {
     return null;
   }
   PrimativeTokenizer tokenizer = PrimativeTokenizer.getStringInstance(value, debug);
   ArrayList list = new ArrayList();
   StringBuffer buffer = new StringBuffer(128);
   boolean startOfLine = true;
   boolean firstToken = true;
   Token token = null;
   try {
     tokenizer.initialize();
     token = tokenizer.next();
   } catch (IOException e) {
     return new String[] {value};
   } catch (LogFile.LockException e) {
     e.printStackTrace();
     return new String[] {value};
   }
   try {
     while (token != null && !token.is(Token.Type.EOF)) {
       if (startOfLine) {
         startOfLine = false;
         // Handle new-line character ('^' at the start of the line).
         if (token.equals(Token.Type.SYMBOL, NEW_LINE_CHAR)) {
           list.add(buffer.toString());
           buffer = new StringBuffer(128);
           startOfLine = false;
           token = tokenizer.next();
           continue;
         } else if (!firstToken) {
           // wasn't really the end of the line so convert EOL to a space.
           buffer.append(' ');
         } else {
           firstToken = false;
         }
         // still need to process the current token
       }
       if (token.is(Token.Type.EOL)) {
         // Wait to convert end-of-line to a space. If the next token is '^', then this
         // really is the end of a line.
         startOfLine = true;
       } else {
         buffer.append(token.getValue());
         startOfLine = false;
       }
       token = tokenizer.next();
     }
   } catch (IOException e) {
     return new String[] {value};
   }
   if (buffer.length() > 0) {
     list.add(buffer.toString());
   }
   if (list.size() == 0) {
     return new String[0];
   }
   if (list.size() == 1) {
     return new String[] {(String) list.get(0)};
   }
   return (String[]) list.toArray(new String[list.size()]);
 }
Exemplo n.º 4
0
 /** Append lines and lineList to textArea. */
 public void run() {
   if (newline) {
     newLine(null);
   }
   if (line1 != null) {
     logInterface.append(line1 + (timestamp != null ? " - " + timestamp : ""));
     newLine(line1);
   } else if (timestamp != null) {
     logInterface.append(timestamp);
   }
   if (line2 != null) {
     logInterface.append(line2);
     newLine(line2);
   }
   if (stringArray != null) {
     for (int i = 0; i < stringArray.length; i++) {
       if (stringArray[i] != null) {
         logInterface.append((String) stringArray[i]);
         newLine(stringArray[i]);
       }
     }
   }
   if (lineList != null) {
     int len = lineList.size();
     for (int i = 0; i < len; i++) {
       String line = lineList.get(i);
       if (line != null) {
         logInterface.append(line);
         newLine(line);
       }
     }
   }
   if (file != null && file.exists() && file.isFile() && file.canRead()) {
     logInterface.append("Logging from file: " + file.getAbsolutePath());
     newLine(null);
     try {
       LogFile logFile = LogFile.getInstance(file);
       LogFile.ReaderId id = logFile.openReader();
       String line = null;
       while ((line = logFile.readLine(id)) != null) {
         logInterface.append(line);
         newLine(line);
       }
     } catch (LogFile.LockException e) {
       e.printStackTrace();
       System.err.println("Unable to log from file.  " + e.getMessage());
     } catch (FileNotFoundException e) {
       e.printStackTrace();
       System.err.println("Unable to log from file.  " + e.getMessage());
     } catch (IOException e) {
       e.printStackTrace();
       System.err.println("Unable to log from file.  " + e.getMessage());
     }
   }
   if (!loadingFromFile) {
     logInterface.msgChanged();
   }
   if (axisID == AxisID.FIRST || axisID == AxisID.SECOND) {
     logInterface.append(axisID + " axis");
     newLine(null);
   }
 }