|
From: SVN by r. <sv...@ca...> - 2009-01-19 14:27:03
|
Author: roy
Date: 2009-01-19 15:26:56 +0100 (Mon, 19 Jan 2009)
New Revision: 360
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
use swingutilities to change text
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-19 07:50:57 UTC (rev 359)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-19 14:26:56 UTC (rev 360)
@@ -14,6 +14,7 @@
import charvax.swing.JMenuItem;
import charvax.swing.JPopupMenu;
import charvax.swing.JTextArea;
+import charvax.swing.SwingUtilities;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -85,15 +86,15 @@
}
@Override
- public void paint(Screen screen) {
+ public void paint(final Screen screen) {
debug("PageUpCount: "+ screen.getPageUpCount());
if (screen.getPageUpCount() > 0) {
paintSlow(screen);
return;
}
int totalLineCount = 0;
- StringBuilder newText = new StringBuilder();
- List<String> commandLines = formatCommandLines(screen.getShowPrompt()
+ final StringBuilder newText = new StringBuilder();
+ final List<String> commandLines = formatCommandLines(screen.getShowPrompt()
, screen.getEmptyLine(),(List<CharSequence>) getCommand().getLines());
for (int i = 0; i < commandLines.size(); i++) {
CharSequence seq = commandLines.get(i);
@@ -133,19 +134,29 @@
}
}
}
- /*if (newText.toString().startsWith(textComponent.getText())) {
- textComponent.append(newText.substring(textComponent.getText().length()));
- } else {*/
- textComponent.replaceRange(newText.toString(), 0, textComponent.getText().length());
- //}
- Point cursorPos = screen.getCursorPosition();
- try {
- int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y));
- textComponent.setCaretPosition(start + cursorPos.x + (Screen.PROMPT+" >").length());
- } catch(Exception e) {
- debug("ERROR: failed to calculate line end: "+ totalLineCount +"-"+ cursorPos.y +"/"+ getScreenHeight());
- }
- textComponent.draw();
+
+ final int lineCount = totalLineCount;
+ Runnable eventThead = new Runnable() {
+
+ public void run() {
+ if (newText.toString().startsWith(textComponent.getText())) {
+ textComponent.append(newText.substring(textComponent.getText().length()));
+ } else {
+ textComponent.replaceRange(newText.toString(), 0, textComponent.getText().length());
+ }
+ Point cursorPos = screen.getCursorPosition();
+ try {
+ int start = textComponent.getLineStartOffset(lineCount - (commandLines.size() - cursorPos.y));
+ textComponent.setCaretPosition(start + cursorPos.x + (Screen.PROMPT+" >").length());
+ } catch(Exception e) {
+ debug("ERROR: failed to calculate line end: "+ lineCount +"-"+ cursorPos.y +"/"+ getScreenHeight());
+ }
+ textComponent.draw();
+ }
+
+ };
+
+ SwingUtilities.invokeLater(eventThead);
}
public void paintSlow(Screen screen) {
int totalLineCount = 0;
|