| 58 | } |
| 59 | |
| 60 | public void addText(final String playerName, final Color playerColor, final String message) |
| 61 | { |
| 62 | SwingUtilities.invokeLater( |
| 63 | new Runnable() |
| 64 | { |
| 65 | public void run() |
| 66 | { |
| 67 | boolean autoScrolls = getVerticalScrollBar().getMaximum() - (getVerticalScrollBar().getValue() + getVerticalScrollBar().getVisibleAmount()) < 20; |
| 68 | |
| 69 | if(playerName == null) |
| 70 | { |
| 71 | try |
| 72 | { |
| 73 | text.insertString(text.getLength(), message+"\n", systemStyle); |
| 74 | } |
| 75 | catch (BadLocationException e) |
| 76 | { |
| 77 | e.printStackTrace(); |
| 78 | } |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | StyleConstants.setForeground(nameStyle, playerColor); |
| 83 | StyleConstants.setBold(nameStyle, true); |
| 84 | |
| 85 | try |
| 86 | { |
| 87 | text.insertString(text.getLength(), playerName+": ", nameStyle); |
| 88 | text.insertString(text.getLength(), message+"\n", messageStyle); |
| 89 | } |
| 90 | catch (BadLocationException e) |
| 91 | { |
| 92 | e.printStackTrace(); |
| 93 | } |
| 94 | |
| 95 | } |
| 96 | |
| 97 | if(autoScrolls) |
| 98 | { |
| 99 | //this.getVerticalScrollBar().setValue(this.getVerticalScrollBar().getMaximum()-this.getVerticalScrollBar().getVisibleAmount()); |
| 100 | textPane.setCaretPosition(text.getLength()); |
| 101 | } |
| 102 | |
| 103 | revalidate(); |
| 104 | } |
| 105 | } |
| 106 | ); |
| 107 | |
| 108 | } |
| 109 | |
| 110 | public void emptyText() |
| 111 | { |