From: Hendrik <nh...@us...> - 2007-04-12 21:41:00
|
Update of /cvsroot/arianne/stendhal/src/games/stendhal/client/gui In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv26331/src/games/stendhal/client/gui Modified Files: Tag: VERSION_00_RELEASE_59 KTextEdit.java Log Message: backported mort's fix Index: KTextEdit.java =================================================================== RCS file: /cvsroot/arianne/stendhal/src/games/stendhal/client/gui/KTextEdit.java,v retrieving revision 1.13 retrieving revision 1.13.2.1 diff -C2 -d -r1.13 -r1.13.2.1 *** KTextEdit.java 12 Apr 2007 14:09:35 -0000 1.13 --- KTextEdit.java 12 Apr 2007 21:40:42 -0000 1.13.2.1 *************** *** 90,101 **** * clear the text */ ! public void clearText() { ! textPane.setText(""); ! } /** * insert a header */ ! public void insertHeader(String header) { Document doc = textPane.getDocument(); try { --- 90,102 ---- * clear the text */ ! // Not needed, consider deletion ! // public void clearText() { ! // textPane.setText(""); ! // } /** * insert a header */ ! private void insertHeader(String header) { Document doc = textPane.getDocument(); try { *************** *** 108,112 **** } ! public void insertTimestamp(String header) { Document doc = textPane.getDocument(); try { --- 109,113 ---- } ! private void insertTimestamp(String header) { Document doc = textPane.getDocument(); try { *************** *** 119,123 **** } ! public void insertText(String text, Color color) { Document doc = textPane.getDocument(); try { --- 120,124 ---- } ! private void insertText(String text, Color color) { Document doc = textPane.getDocument(); try { *************** *** 139,144 **** i++; } ! ! doc.insertString(doc.getLength(), "\r\n", getColor(color)); } catch (BadLocationException ble) { System.err.println("Couldn't insert initial text."); --- 140,152 ---- i++; } ! } catch (BadLocationException ble) { ! System.err.println("Couldn't insert initial text."); ! } ! } ! ! private void insertNewline() { ! Document doc = textPane.getDocument(); ! try { ! doc.insertString(doc.getLength(), "\r\n", getColor(Color.black)); } catch (BadLocationException ble) { System.err.println("Couldn't insert initial text."); *************** *** 171,183 **** // position. We will only auto-scroll down if the user is not currently // reading old texts (like IRC clients do). ! JScrollBar vbar = scrollPane.getVerticalScrollBar(); // The + 10 was determined by trial-and-error. I don't know // why it doesn't work properly without it. It probably has // to do with the newline at the end. ! boolean autoScroll = (vbar.getValue() + vbar.getVisibleAmount() + 10 >= vbar.getMaximum()); java.text.Format formatter = new java.text.SimpleDateFormat("[HH:mm] "); String dateString = formatter.format(new Date()); insertTimestamp(dateString); insertHeader(header); --- 179,198 ---- // position. We will only auto-scroll down if the user is not currently // reading old texts (like IRC clients do). ! final JScrollBar vbar = scrollPane.getVerticalScrollBar(); ! ! // System.out.println(); ! // System.out.println("value: " + vbar.getValue()); ! // System.out.println("visible: " + vbar.getVisibleAmount()); ! // System.out.println("maximum: " + vbar.getMaximum()); // The + 10 was determined by trial-and-error. I don't know // why it doesn't work properly without it. It probably has // to do with the newline at the end. ! boolean autoScroll = (vbar.getValue() + vbar.getVisibleAmount() == vbar.getMaximum()); ! // System.out.println("autoscroll: " + autoScroll); java.text.Format formatter = new java.text.SimpleDateFormat("[HH:mm] "); String dateString = formatter.format(new Date()); + insertNewline(); insertTimestamp(dateString); insertHeader(header); *************** *** 185,189 **** if (autoScroll) { ! textPane.setCaretPosition(textPane.getDocument().getLength()); } } --- 200,210 ---- if (autoScroll) { ! // This didn't scroll all the way down. ! // textPane.setCaretPosition(textPane.getDocument().getLength()); ! SwingUtilities.invokeLater(new Runnable() { ! public void run() { ! vbar.setValue(vbar.getMaximum()); ! } ! }); } } |