|
From: SVN by r. <sv...@ca...> - 2008-11-07 21:58:45
|
Author: roy
Date: 2008-11-07 22:31:58 +0100 (Fri, 07 Nov 2008)
New Revision: 326
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
Log:
added method insertText
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-10-16 21:16:38 UTC (rev 325)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-11-07 21:31:58 UTC (rev 326)
@@ -16,7 +16,6 @@
package nl.improved.sqlclient;
import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
@@ -492,10 +491,38 @@
*/
protected void repaint() {
if (isRunning()) {
- paint(getScreen());
+ waitAndPaint();
+ //paint(getScreen());
}
}
+ long wait = 0;
+ Thread t;
+ private class RepaintThread extends Thread {
+ @Override
+ public void run() {
+ while (true) {
+ try {
+ Thread.sleep(5);
+ } catch (InterruptedException ex) {
+ Logger.getLogger(AbstractSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ if (wait <= (System.currentTimeMillis() +5) ) {
+ paint(screen);
+ return;
+ }
+ }
+ }
+ }
+
+ private synchronized void waitAndPaint() {
+ wait = System.currentTimeMillis();
+ if (t == null || !t.isAlive()) {
+ t = new RepaintThread();
+ t.start();
+ }
+ }
+
/**
* Paints the screen.
* @param screen the screen to be painted
@@ -654,63 +681,7 @@
} else {
newText = Character.toString(inp.getCharacter());
}
- if (newText.equals("\n")) {
- newLine(); // TODO Fix return in middle of an other line
- } else {
- Point cursorPosition = screen.getCursorPosition();
- List<StringBuffer> editableLines = getEditableCommand().getEditableLines();
- StringBuffer currentLine = editableLines.get(cursorPosition.y);
- if (cursorPosition.x > currentLine.length()) {
- for (int i = currentLine.length(); i < cursorPosition.x; i++) {
- currentLine.append(' ');
- }
- debug("WARNING: Fixing: cursorposition: "+ cursorPosition.x +" /" + currentLine.length());
- }
- currentLine.insert(cursorPosition.x, newText);
- cursorPosition.x += newText.length();
- // check if the new line is becoming too long
- if (currentLine.length() > screen.MAX_LINE_LENGTH) {
- // TODO search for lastspace that is not between '' ??
- int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" ");
- int lastChar = currentLine.charAt(lastSpace);
- if (lastSpace == -1) {
- lastSpace = currentLine.length();
- }
- // check if there are enough 'next' lines
- // if not.. add one
- if (editableLines.size()-1 == cursorPosition.y) {
- StringBuffer newLine = new StringBuffer();
- editableLines.add(newLine);
- }
- // check if the nextline has enough room for the new word
- // if not.. add a new line
- if (editableLines.get(cursorPosition.y+1).length()
- + (currentLine.length()-lastSpace+1) > screen.MAX_LINE_LENGTH) {
- StringBuffer newLine = new StringBuffer();
- editableLines.add(cursorPosition.y+1, newLine);
- }
- // fetch the next line
- StringBuffer nextLine = editableLines.get(cursorPosition.y+1);
- // if the nextline already has some text.. add a space in front of it
- // if there is not already a 'breaking character' there
- if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) {
- nextLine.insert(0, ' ');
- }
- // insert the new text at the beginning
- nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length()));
- currentLine.delete(lastSpace, currentLine.length());
- if (lastChar == ' ') {
- nextLine.deleteCharAt(0);
- cursorPosition.x--;
- }
- // check if the cursor postition > the new line length
- // calculate new x and go to nextline
- if (cursorPosition.x >= lastSpace) {
- cursorPosition.x = cursorPosition.x - (lastSpace);
- cursorPosition.y++;
- }
- }
- }
+ insertText(newText);
}
}
} catch(Throwable t) {
@@ -719,6 +690,66 @@
repaint();
}
+ public void insertText(CharSequence newText) {
+ if (newText.equals("\n")) {
+ newLine(); // TODO Fix return in middle of an other line
+ } else {
+ Point cursorPosition = screen.getCursorPosition();
+ List<StringBuffer> editableLines = getEditableCommand().getEditableLines();
+ StringBuffer currentLine = editableLines.get(cursorPosition.y);
+ if (cursorPosition.x > currentLine.length()) {
+ for (int i = currentLine.length(); i < cursorPosition.x; i++) {
+ currentLine.append(' ');
+ }
+ debug("WARNING: Fixing: cursorposition: "+ cursorPosition.x +" /" + currentLine.length());
+ }
+ currentLine.insert(cursorPosition.x, newText);
+ cursorPosition.x += newText.length();
+ // check if the new line is becoming too long
+ if (currentLine.length() > screen.MAX_LINE_LENGTH) {
+ // TODO search for lastspace that is not between '' ??
+ int lastSpace = SQLUtil.getLastBreakIndex(currentLine.toString());//currentLine.lastIndexOf(" ");
+ int lastChar = currentLine.charAt(lastSpace);
+ if (lastSpace == -1) {
+ lastSpace = currentLine.length();
+ }
+ // check if there are enough 'next' lines
+ // if not.. add one
+ if (editableLines.size()-1 == cursorPosition.y) {
+ StringBuffer newLine = new StringBuffer();
+ editableLines.add(newLine);
+ }
+ // check if the nextline has enough room for the new word
+ // if not.. add a new line
+ if (editableLines.get(cursorPosition.y+1).length()
+ + (currentLine.length()-lastSpace+1) > screen.MAX_LINE_LENGTH) {
+ StringBuffer newLine = new StringBuffer();
+ editableLines.add(cursorPosition.y+1, newLine);
+ }
+ // fetch the next line
+ StringBuffer nextLine = editableLines.get(cursorPosition.y+1);
+ // if the nextline already has some text.. add a space in front of it
+ // if there is not already a 'breaking character' there
+ if (nextLine.length() > 0 && ! SQLUtil.isBreakCharacter(nextLine.charAt(0))) {
+ nextLine.insert(0, ' ');
+ }
+ // insert the new text at the beginning
+ nextLine.insert(0, currentLine.subSequence(lastSpace, currentLine.length()));
+ currentLine.delete(lastSpace, currentLine.length());
+ if (lastChar == ' ') {
+ nextLine.deleteCharAt(0);
+ cursorPosition.x--;
+ }
+ // check if the cursor postition > the new line length
+ // calculate new x and go to nextline
+ if (cursorPosition.x >= lastSpace) {
+ cursorPosition.x = cursorPosition.x - (lastSpace);
+ cursorPosition.y++;
+ }
+ }
+ }
+ }
+
/**
* Return the editable version of the commandlines.
* If editing a previous command clone it and return the clone
|