Created
May 18, 2011 01:39
-
-
Save colin-haber/977837 to your computer and use it in GitHub Desktop.
JConsolePane.print()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void print(String tag, String message) { | |
| AttributeSet as = StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, foregroundColor); | |
| try { | |
| if (isTimestampEnabled) { | |
| sdConsole.insertString(sdConsole.getLength(), "[" + timestampFormat.format(new Date()) + "] ", as); | |
| } | |
| sdConsole.insertString(sdConsole.getLength(), "[" , as); | |
| for (int i=0;i<tag.length();i++) { | |
| if (new Character(tag.charAt(i)).equals('\\')) { | |
| i++; | |
| } else if (new Character(tag.charAt(i)).equals('$')) { | |
| if (Character.isDigit(tag.charAt(i+1))) { | |
| as = StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, colorMap.get(Character.getNumericValue(tag.charAt(i+1)))); | |
| i++; | |
| } else { | |
| sdConsole.insertString(sdConsole.getLength(), tag.substring(i, i+1), as); | |
| } | |
| } else { | |
| sdConsole.insertString(sdConsole.getLength(), tag.substring(i, i+1), as); | |
| } | |
| } | |
| as = StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, foregroundColor); | |
| sdConsole.insertString(sdConsole.getLength(), "] ", as); | |
| for (int i=0;i<message.length();i++) { | |
| if (new Character(message.charAt(i)).equals('\\')) { | |
| i++; | |
| sdConsole.insertString(sdConsole.getLength(), message.substring(i, i+1), as); | |
| } else if (new Character(message.charAt(i)).equals('$')) { | |
| if (Character.isDigit(message.charAt(i+1))) { | |
| as = StyleContext.getDefaultStyleContext().addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, colorMap.get(Character.getNumericValue(message.charAt(i+1)))); | |
| i++; | |
| } else { | |
| sdConsole.insertString(sdConsole.getLength(), message.substring(i, i+1), as); | |
| } | |
| } else { | |
| sdConsole.insertString(sdConsole.getLength(), message.substring(i, i+1), as); | |
| } | |
| } | |
| sdConsole.insertString(sdConsole.getLength(), "\n", as); | |
| tpConsole.setCaretPosition(sdConsole.getLength()); | |
| } catch (BadLocationException e) { | |
| e.printStackTrace(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment