|
From: SVN by r. <sv...@ca...> - 2008-08-05 12:16:35
|
Author: roy
Date: 2008-08-05 14:16:24 +0200 (Tue, 05 Aug 2008)
New Revision: 282
Modified:
src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
src/main/java/nl/improved/sqlclient/commands/Command.java
src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
Log:
some code cleanup
added catch execption for executing commands
improve close window
Modified: src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-03 20:03:00 UTC (rev 281)
+++ src/main/java/nl/improved/sqlclient/AbstractSQLShellWindow.java 2008-08-05 12:16:24 UTC (rev 282)
@@ -422,7 +422,11 @@
output(cmd.sql.getLines());
repaint();
if (/*direct ||*/ !cmd.cmd.backgroundProcessSupported()) {
- output(cmd.cmd.execute(cmd.sql));
+ try {
+ output(cmd.cmd.execute(cmd.sql));
+ } catch(Exception e) {
+ error(e);
+ }
repaint();
} else {
commandThread = new CommandThread(cmd.cmd) {
@@ -617,6 +621,12 @@
Point cursorPosition = screen.getCursorPosition();
List<StringBuilder> editableLines = getEditableCommand().getEditableLines();
StringBuilder 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
@@ -652,6 +662,7 @@
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
Modified: src/main/java/nl/improved/sqlclient/commands/Command.java
===================================================================
--- src/main/java/nl/improved/sqlclient/commands/Command.java 2008-08-03 20:03:00 UTC (rev 281)
+++ src/main/java/nl/improved/sqlclient/commands/Command.java 2008-08-05 12:16:24 UTC (rev 282)
@@ -15,10 +15,8 @@
*/
package nl.improved.sqlclient.commands;
-import java.util.List;
import nl.improved.sqlclient.SQLCommand;
import nl.improved.sqlclient.Point;
-import nl.improved.sqlclient.SQLUtil;
import nl.improved.sqlclient.TabCompletionInfo;
/**
* Implement this interface to add a specific command to the sql client.
Modified: src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-08-03 20:03:00 UTC (rev 281)
+++ src/main/java/nl/improved/sqlclient/jcurses/SQLShellWindow.java 2008-08-05 12:16:24 UTC (rev 282)
@@ -19,6 +19,8 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import jcurses.event.ActionEvent;
import jcurses.event.ActionListener;
import jcurses.system.CharColor;
@@ -47,7 +49,10 @@
private Window window;
private boolean dontRepaint = false;
private boolean repaint = true;
+ private String debugString;
+ private Object lockObject = new Object();
+
/**
* Default constructor.
*/
@@ -78,10 +83,8 @@
*/
@Override
public void debug(String debug) {
- synchronized(this) {
- CharColor color = new CharColor(CharColor.BLUE, CharColor.YELLOW);
- Toolkit.printString(debug, 1, getScreenHeight()-1, color);
- }
+ debugString = debug;
+ repaint = true;
}
@@ -148,16 +151,24 @@
if (!dontRepaint && repaint) {
try {
synchronized(this) {
- paint(screen);
+ _paint(screen);
}
} catch(Throwable t) {
error(t);
}
}
try {
- Thread.sleep(200);
- } catch(Exception e) {}
+ synchronized(lockObject) {
+ lockObject.wait(1000);
+ }
+ } catch (InterruptedException ex) {
+ /* ignore */
+ }
}
+ super.close();
+ //window.close();
+ window.hide();
+ window.close();
}
/**
@@ -165,8 +176,10 @@
*/
@Override
public void close() {
- super.close();
+ /*
+ super.close();
window.close();
+ */
}
@@ -197,7 +210,19 @@
*/
@Override
public void paint(Screen screen) {
- synchronized(this) {
+ if (isRunning()) {
+ repaint = true;
+ synchronized(lockObject) {
+ lockObject.notify();
+ }
+ }
+ }
+
+ private void _paint(Screen screen) {
+ if (!isRunning()) {
+ return;
+ }
+ synchronized(lockObject) {
CharColor color = new CharColor(CharColor.BLACK, CharColor.WHITE, CharColor.BOLD, CharColor.BOLD);
List<CharSequence> tmpList = new ArrayList<CharSequence>();
@@ -252,6 +277,11 @@
}
}
Toolkit.printString(cursorChar, Screen.PROMPT.length() +"> ".length() + cursorPosition.x, lineNr-(commandLines.getLines().size() -cursorPosition.y)-startLine, color);
+ if (debugString != null) {
+ color = new CharColor(CharColor.BLUE, CharColor.YELLOW);
+ Toolkit.printString(debugString, 1, getScreenHeight()-1, color);
+ }
+ repaint = false;
}
}
@@ -277,6 +307,9 @@
protected void repaint() {
if (isRunning()) {
repaint = true;
+ synchronized(lockObject) {
+ lockObject.notify();
+ }
}
}
|