|
From: SVN by r. <sv...@ca...> - 2008-10-12 12:04:38
|
Author: roy
Date: 2008-10-12 13:57:48 +0200 (Sun, 12 Oct 2008)
New Revision: 312
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
some fixes in method names
implemented pageup/down
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-12 11:37:51 UTC (rev 311)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-12 11:57:48 UTC (rev 312)
@@ -21,12 +21,16 @@
import nl.improved.sqlclient.Screen;
/**
- *
+ * The sqlshell window implementation for charva.
* @author roy
*/
class CharvaSQLShellWindow extends AbstractSQLShellWindow {
private SQLShellComponent textComponent;
+ /**
+ * Constructor.
+ * @param textComponent the text component for rendering the text
+ */
public CharvaSQLShellWindow(SQLShellComponent textComponent) {
this.textComponent = textComponent;
}
@@ -41,7 +45,10 @@
return Toolkit.getDefaultToolkit().getScreenRows()-1;
}
- void show() {
+ /**
+ * Force repaint of the screen.
+ */
+ void repaintScreen() {
paint(getScreen());
}
@@ -75,11 +82,11 @@
if (totalLineCount > getScreenHeight()-1) {
totalLineCount = getScreenHeight()-1;
}
- String trimmed = trim(newText);
+ String trimmed = trim(newText, screen.getPageUpCount());
if (trimmed.startsWith(textComponent.getText())) {
textComponent.append(trimmed.substring(textComponent.getText().length()));
} else {
- textComponent.replaceRange(trim(newText), 0, textComponent.getText().length());
+ textComponent.replaceRange(trimmed, 0, textComponent.getText().length());
}
Point cursorPos = screen.getCursorPosition();
try {
@@ -149,10 +156,10 @@
} else if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
handleInput(new InputKey(InputKey.SpecialKey.DELETE));
evt.consume();
- } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) {
+ } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
handleInput(new InputKey(InputKey.SpecialKey.PAGE_DOWN));
evt.consume();
- } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
+ } else if (evt.getKeyCode() == KeyEvent.VK_PAGE_UP) {
handleInput(new InputKey(InputKey.SpecialKey.PAGE_UP));
evt.consume();
} else if (evt.getKeyCode() == KeyEvent.VK_LEFT) {
@@ -180,7 +187,7 @@
evt.consume();
}
- private String trim(StringBuilder text) {
+ private String trim(StringBuilder text, int pageUpCount) {
String strText = text.toString();
if (strText.indexOf('\n') < 0) {
return strText;
@@ -191,16 +198,21 @@
return strText;
}
StringBuilder newString = new StringBuilder();
+ int offset = Math.max(0, lines.length - ((pageUpCount +1) * maxHeight));
boolean endsWithReturn = strText.endsWith("\n");
- for (int i = lines.length - maxHeight; i < lines.length; i++) {
- newString.append(lines[i]);
- if (i < lines.length-1 || endsWithReturn) {
+ for (int i = 0; i < maxHeight; i++) {
+ newString.append(lines[i+offset]);
+ if (i+offset < lines.length-1 || endsWithReturn) {
newString.append('\n');
}
}
return newString.toString();
}
+ /**
+ * Hacked version of a charva (swing) popup menu.
+ * It returns the selected menu item on hide.
+ */
private static class MyPopupMenu extends JPopupMenu {
private String selectedValue;
public MyPopupMenu(Vector items) {
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-12 11:37:51 UTC (rev 311)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-12 11:57:48 UTC (rev 312)
@@ -34,7 +34,7 @@
component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()-2
, Toolkit.getDefaultToolkit().getScreenRows()-2));
frame.add(component);
- component.sqlshellWindow.show();
+ component.sqlshellWindow.repaintScreen();
frame.pack();
frame.show();
}
|
|
From: SVN by r. <sv...@ca...> - 2008-10-14 18:57:46
|
Author: roy
Date: 2008-10-14 20:57:36 +0200 (Tue, 14 Oct 2008)
New Revision: 320
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java
Log:
made passfield have focus when username is not empty
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java 2008-10-13 18:42:25 UTC (rev 319)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaLoginDialog.java 2008-10-14 18:57:36 UTC (rev 320)
@@ -85,6 +85,10 @@
add(cancelButton, gbc);
gbc.gridx = 1;
add(okButton, gbc);
+
+ if (username != null && username.length() > 0) {
+ passfield.requestFocus();
+ }
}
public void okButtonPressedSlot() {
|
|
From: SVN by r. <sv...@ca...> - 2008-10-14 19:11:55
|
Author: roy
Date: 2008-10-14 21:11:45 +0200 (Tue, 14 Oct 2008)
New Revision: 321
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
added logfile for charva (tmpdir/charva*.out) This file will be removed on exit
fixed cursor position when screenbuffer > screensize
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 18:57:36 UTC (rev 320)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 19:11:45 UTC (rev 321)
@@ -11,10 +11,16 @@
import charva.awt.event.KeyEvent;
import charvax.swing.JMenuItem;
import charvax.swing.JPopupMenu;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import nl.improved.sqlclient.AbstractSQLShellWindow;
import nl.improved.sqlclient.InputKey;
import nl.improved.sqlclient.Point;
@@ -27,6 +33,7 @@
*/
class CharvaSQLShellWindow extends AbstractSQLShellWindow {
private SQLShellComponent textComponent;
+ private OutputStream debugOut;
/**
* Constructor.
@@ -34,6 +41,13 @@
*/
public CharvaSQLShellWindow(SQLShellComponent textComponent) {
this.textComponent = textComponent;
+ try {
+ File tmpFile = File.createTempFile("charva", ".out");
+ tmpFile.deleteOnExit();
+ debugOut = new FileOutputStream(tmpFile);
+ } catch (IOException ex) {
+ Logger.getLogger(CharvaSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
}
@Override
@@ -80,8 +94,8 @@
totalLineCount++;
}
}
- if (totalLineCount > getScreenHeight()-1) {
- totalLineCount = getScreenHeight()-1;
+ if (totalLineCount > getScreenHeight()-commandLines.size()) {
+ totalLineCount = getScreenHeight()-commandLines.size();
}
String trimmed = trim(newText, screen.getPageUpCount());
if (trimmed.startsWith(textComponent.getText())) {
@@ -114,7 +128,13 @@
@Override
public void debug(String debug) {
-
+ if (debugOut != null) {
+ try {
+ debugOut.write((debug + "\n").getBytes());
+ } catch (IOException ex) {
+ Logger.getLogger(CharvaSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
}
@Override
|
|
From: SVN by r. <sv...@ca...> - 2008-10-14 19:30:44
|
Author: roy
Date: 2008-10-14 21:30:34 +0200 (Tue, 14 Oct 2008)
New Revision: 322
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
improved caret position (again.. sigh)
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 19:11:45 UTC (rev 321)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-14 19:30:34 UTC (rev 322)
@@ -91,11 +91,11 @@
newText.append(seq.toString());
if (i < commandLines.size()-1) {
newText.append("\n");
- totalLineCount++;
}
+ totalLineCount++;
}
- if (totalLineCount > getScreenHeight()-commandLines.size()) {
- totalLineCount = getScreenHeight()-commandLines.size();
+ if (totalLineCount > getScreenHeight()-1) {
+ totalLineCount = getScreenHeight()-1;
}
String trimmed = trim(newText, screen.getPageUpCount());
if (trimmed.startsWith(textComponent.getText())) {
@@ -105,12 +105,11 @@
}
Point cursorPos = screen.getCursorPosition();
try {
- int start = textComponent.getLineStartOffset(totalLineCount - (commandLines.size() - cursorPos.y)+1);
+ 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);
+ debug("ERROR: failed to calculate line end: "+ totalLineCount +"-"+ cursorPos.y +"/"+ getScreenHeight());
}
- // TODO fix caretposition
textComponent.draw();
}
|
|
From: SVN by r. <sv...@ca...> - 2008-10-15 07:52:48
|
Author: roy
Date: 2008-10-15 09:52:40 +0200 (Wed, 15 Oct 2008)
New Revision: 323
Modified:
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
made selection work
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-14 19:30:34 UTC (rev 322)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-10-15 07:52:40 UTC (rev 323)
@@ -21,18 +21,15 @@
private CharvaSQLShellWindow sqlshellWindow = new CharvaSQLShellWindow(this);
+ public SQLShellComponent() {
+ setEditable(false);
+ }
@Override
public void processKeyEvent(KeyEvent arg0) {
//super.processKeyEvent(arg0);
sqlshellWindow.keyTyped(arg0);
}
- @Override
- public void processMouseEvent(MouseEvent arg0) {
- }
-
-
-
public static void main(String[] args) {
JFrame frame = new JFrame();
SQLShellComponent component = new SQLShellComponent();
|
|
From: SVN by r. <sv...@ca...> - 2008-10-15 15:08:15
|
Author: rotman
Date: 2008-10-15 17:06:52 +0200 (Wed, 15 Oct 2008)
New Revision: 324
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
* Style fix for static field
* Attempt to make the popup disapear again on ESC
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-15 07:52:40 UTC (rev 323)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-15 15:06:52 UTC (rev 324)
@@ -167,7 +167,7 @@
return;
}
if (evt.isActionKey()) {
- if (evt.getKeyCode() == evt.VK_ENTER) {
+ if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
handleInput(new InputKey('\n'));
evt.consume();
} else if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {
@@ -200,7 +200,7 @@
} else if (evt.getKeyCode() == KeyEvent.VK_END) {
handleInput(new InputKey(InputKey.SpecialKey.END));
evt.consume();
- }
+ }
return;
}
handleInput(new InputKey((char)evt.getKeyCode()));
@@ -250,7 +250,24 @@
}
}
+ @Override
+ public void processKeyEvent(KeyEvent evt) {
+ super.processKeyEvent(evt);
+ /*
+ * SR: Ok, so I am aware that all this logic should have been placed in a KeyListener instead...
+ * For some dark reason though it seems that if I add a keyListener to either this popup or the
+ * menuitems individually, the listener never gets the desired key events.
+ */
+ if (evt.isConsumed()) {
+ return;
+ }
+ if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ MyPopupMenu.super.hide();
+ evt.consume();
+ }
+ }
+
@Override
public void hide() {}
|
|
From: SVN by r. <sv...@ca...> - 2008-10-16 21:16:49
|
Author: roy
Date: 2008-10-16 23:16:38 +0200 (Thu, 16 Oct 2008)
New Revision: 325
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
fix hide with using backspace
escape still works.. but hiding is really slow
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-15 15:06:52 UTC (rev 324)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-10-16 21:16:38 UTC (rev 325)
@@ -251,27 +251,17 @@
}
@Override
- public void processKeyEvent(KeyEvent evt) {
- super.processKeyEvent(evt);
-
- /*
- * SR: Ok, so I am aware that all this logic should have been placed in a KeyListener instead...
- * For some dark reason though it seems that if I add a keyListener to either this popup or the
- * menuitems individually, the listener never gets the desired key events.
- */
- if (evt.isConsumed()) {
- return;
+ public void hide() {
+ if (wasCancelled()) {
+ super.hide();
}
- if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
- MyPopupMenu.super.hide();
- evt.consume();
- }
}
- @Override
- public void hide() {}
-
- private String select() {
+ /**
+ * Use this method to block the user interface and return the selected value.
+ * @return the selected value
+ */
+ public String select() {
show();
return selectedValue;
}
|
|
From: SVN by r. <sv...@ca...> - 2008-11-09 21:16:57
|
Author: roy
Date: 2008-11-09 22:16:45 +0100 (Sun, 09 Nov 2008)
New Revision: 329
Modified:
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
implement 'non native' paste and copy methods using mouse
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-11-09 21:07:33 UTC (rev 328)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-11-09 21:16:45 UTC (rev 329)
@@ -14,10 +14,13 @@
import charvax.swing.JTextArea;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
+import nl.improved.sqlclient.SQLProperties;
+import nl.improved.sqlclient.SQLUtil;
/**
*
@@ -26,6 +29,7 @@
public class SQLShellComponent extends JTextArea {
private CharvaSQLShellWindow sqlshellWindow = new CharvaSQLShellWindow(this);
+ private Point startPos;
public SQLShellComponent() {
setEditable(false);
@@ -37,24 +41,106 @@
sqlshellWindow.keyTyped(evt);
}
+ void setSelection(int pStart, int pEnd) {
+ if (!"all".equals(SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING))) {
+ return;
+ }
+ int start, end;
+ if (pEnd < pStart) {
+ end = pStart;
+ start = pEnd;
+ } else {
+ start = pStart;
+ end = pEnd;
+ }
+ end = Math.min(getText().length(), end);
+ sqlshellWindow.debug("SET SELECTION: "+ start +" -> "+ end);
+ sqlshellWindow.debug("SET TO CLIPBOARD: "+ getText().substring(start, end));
+ Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
+ final String text = getText().substring(start, Math.min(getText().length(), end));
+ Transferable tf = new Transferable() {
+
+ public DataFlavor[] getTransferDataFlavors() {
+ return new DataFlavor[] {DataFlavor.stringFlavor};
+ }
+
+ public boolean isDataFlavorSupported(DataFlavor flavor) {
+ return DataFlavor.stringFlavor == flavor;
+ }
+
+ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
+ return text;
+ }
+ };
+ clipBoard.setContents(tf, null);
+ }
+
@Override
public void processMouseEvent(MouseEvent evt) {
super.processMouseEvent(evt);
- if (evt.getModifiers() == evt.MOUSE_PRESSED) {
- if (evt.getButton() == MouseEvent.BUTTON2) {
- Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
- try {
- String clipBoardContents = (String) clipBoard.getData(DataFlavor.stringFlavor);
- //sqlshellWindow.debug(clipBoardContents);
- sqlshellWindow.insertText(clipBoardContents);
- sqlshellWindow.repaintScreen();
- } catch (UnsupportedFlavorException ex) {
- Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IOException ex) {
- Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex);
+ if (evt.getModifiers() == MouseEvent.MOUSE_CLICKED) {
+ if (evt.getButton() == MouseEvent.BUTTON1) {
+ if (evt.getClickCount() == 2) { // double click.. select word under char
+ try {
+ int line = getLineStartOffset(evt.getY()-1);
+ String text = getText();
+ int start, end;
+ for (start = line + evt.getX(); start > 0; start--) {
+ if (SQLUtil.isBreakCharacter(text.charAt(start))) {
+ break;
+ }
+ }
+ for (end = line + evt.getX(); end < text.length(); end++) {
+ if (SQLUtil.isBreakCharacter(text.charAt(end))) {
+ break;
+ }
+ }
+ setSelection(start, end);
+ } catch(Exception e) { }
}
-
}
+ } else if (evt.getModifiers() == MouseEvent.MOUSE_PRESSED) {
+ sqlshellWindow.debug("PRESSED");
+ if (evt.getButton() == MouseEvent.BUTTON1) {
+ if (startPos == null) {
+ startPos = new Point(evt.getX()-1, evt.getY()-1);
+ } else {
+ try {
+ Point endPos = new Point(evt.getX()-1, evt.getY()-1);
+ int start = getLineStartOffset(startPos.y) + startPos.x;
+ int end = getLineStartOffset(endPos.y) + endPos.x;
+ setSelection(start, end);
+ startPos = null;
+ } catch(Exception e) {}
+ }
+ }
+ if (evt.getButton() == MouseEvent.BUTTON2) { // paste from clipboard
+ String mouseHandling = SQLProperties.getProperty(SQLProperties.PropertyName.MOUSE_HANDLING);
+ if ("all".equals(mouseHandling) || "paste".equals(mouseHandling)) {
+ Clipboard clipBoard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();
+ try {
+ String clipBoardContents = (String) clipBoard.getData(DataFlavor.stringFlavor);
+ //sqlshellWindow.debug(clipBoardContents);
+ sqlshellWindow.insertText(clipBoardContents);
+ sqlshellWindow.repaintScreen();
+ } catch (UnsupportedFlavorException ex) {
+ Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex);
+ } catch (IOException ex) {
+ Logger.getLogger(SQLShellComponent.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+ }
+ } else if (evt.getModifiers() == MouseEvent.MOUSE_RELEASED) {
+ sqlshellWindow.debug("RELEASED: " + startPos);
+ Point endPos = new Point(evt.getX()-1, evt.getY()-1);
+ if (startPos != null) {
+ try {
+ int start = getLineStartOffset(startPos.y) + startPos.x;
+ int end = getLineStartOffset(endPos.y) + endPos.x;
+ setSelection(start, end);
+ startPos = null;
+ } catch(Exception e) { /* ignore */ }
+ }
}
}
|
|
From: SVN by r. <sv...@ca...> - 2008-12-22 13:45:15
|
Author: roy
Date: 2008-12-22 14:45:09 +0100 (Mon, 22 Dec 2008)
New Revision: 333
Modified:
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
remove border
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-22 12:54:27 UTC (rev 332)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-22 13:45:09 UTC (rev 333)
@@ -34,6 +34,7 @@
public SQLShellComponent() {
setEditable(false);
setEnabled(true);
+ setBorder(null);
}
@Override
public void processKeyEvent(KeyEvent evt) {
@@ -146,12 +147,19 @@
public static void main(String[] args) {
- JFrame frame = new JFrame();
+ JFrame frame = new JFrame() {
+
+ @Override
+ public void draw() {
+ //super.draw();
+ }
+
+ };
SQLShellComponent component = new SQLShellComponent();
+ frame.setLayout(null); // null layout
frame.add(component);
- //frame.pack();
- component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()-2
- , Toolkit.getDefaultToolkit().getScreenRows()-2));
+ component.setBounds(new Point(0,0), new Dimension(Toolkit.getDefaultToolkit().getScreenColumns()
+ , Toolkit.getDefaultToolkit().getScreenRows() +1));
frame.add(component);
component.sqlshellWindow.repaintScreen();
frame.pack();
|
|
From: SVN by r. <sv...@ca...> - 2008-12-22 13:47:15
|
Author: roy
Date: 2008-12-22 14:47:10 +0100 (Mon, 22 Dec 2008)
New Revision: 334
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
optimize paint (a little should be able to improve more though)
removed borders and use optimum screen
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-12-22 13:45:09 UTC (rev 333)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2008-12-22 13:47:10 UTC (rev 334)
@@ -17,6 +17,7 @@
import java.io.OutputStream;
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Vector;
import java.util.logging.Level;
@@ -52,12 +53,12 @@
@Override
public int getScreenWidth() {
- return Toolkit.getDefaultToolkit().getScreenColumns()-1;
+ return textComponent.getWidth();
}
@Override
public int getScreenHeight() {
- return Toolkit.getDefaultToolkit().getScreenRows()-1;
+ return textComponent.getHeight();
}
/**
@@ -69,8 +70,69 @@
@Override
public void paint(Screen screen) {
+ if (screen.getPageUpCount() > 0) {
+ paintSlow(screen);
+ return;
+ }
int totalLineCount = 0;
StringBuilder newText = new StringBuilder();
+ 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);
+ newText.append(seq.toString());
+ if (i < commandLines.size()-1) {
+ newText.append("\n");
+ }
+ totalLineCount++;
+ }
+ if (totalLineCount > getScreenHeight()-1) {
+ totalLineCount = getScreenHeight()-1;
+ }
+ int restLines = (getScreenHeight() -1) - totalLineCount;
+ if (restLines > 0) {
+ ArrayList<SQLCommand> commands = new ArrayList<SQLCommand>(getUnprocessedCommands());
+ Collections.reverse(commands);
+ commands: for (SQLCommand command : commands) {
+ List<? extends CharSequence> lines = command.getLines();
+ for (int i = lines.size() -1; i >=0; i--) {
+ newText.insert(0, lines.get(i) +"\n");
+ restLines--;
+ totalLineCount++;
+ if(restLines == 0) {
+ break commands;
+ }
+ }
+ }
+ }
+ if (restLines > 0) {
+ List<CharSequence> buffer = new ArrayList<CharSequence>(screen.getScreenBuffer());
+ for (int i = buffer.size() -1; i>=0; i--) {
+ newText.insert(0, buffer.get(i)+"\n");
+ restLines--;
+ totalLineCount++;
+ if(restLines == 0) {
+ break;
+ }
+ }
+ }
+ 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();
+ }
+ public void paintSlow(Screen screen) {
+ int totalLineCount = 0;
+ StringBuilder newText = new StringBuilder();
for (CharSequence seq: new ArrayList<CharSequence>(screen.getScreenBuffer())) {
newText.append(seq.toString());
newText.append("\n");
@@ -119,7 +181,7 @@
Toolkit.getDefaultToolkit().getTopWindow().hide();
}
-
+
@Override
public void beep() {
Toolkit.getDefaultToolkit().beep();
@@ -212,7 +274,7 @@
if (strText.indexOf('\n') < 0) {
return strText;
}
- int maxHeight = getScreenHeight()-1;
+ int maxHeight = getScreenHeight();
String[] lines = strText.split("\n");
if (lines.length <= maxHeight) {
return strText;
|
|
From: SVN by r. <sv...@ca...> - 2008-12-24 15:24:29
|
Author: roy
Date: 2008-12-24 16:24:23 +0100 (Wed, 24 Dec 2008)
New Revision: 341
Modified:
src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
Log:
added startup options.. currently undocumented
Modified: src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-24 15:24:02 UTC (rev 340)
+++ src/main/java/nl/improved/sqlclient/charva/SQLShellComponent.java 2008-12-24 15:24:23 UTC (rev 341)
@@ -5,6 +5,8 @@
package nl.improved.sqlclient.charva;
+import java.util.Map;
+import java.util.HashMap;
import charva.awt.Dimension;
import charva.awt.Point;
import charva.awt.Toolkit;
@@ -19,6 +21,7 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
+import nl.improved.sqlclient.SQLCommand;
import nl.improved.sqlclient.SQLProperties;
import nl.improved.sqlclient.SQLUtil;
@@ -147,6 +150,16 @@
public static void main(String[] args) {
+ Map argsMap = new HashMap<String, String>();
+ if (args.length > 0) {
+ if (args[0].equals("--help") || args.length %2 == 1) {
+ System.err.println("Usage: ");
+ System.exit(-1);
+ }
+ for (int i = 0; i < args.length; i+=2) {
+ argsMap.put(args[i], args[i+1]);
+ }
+ }
JFrame frame = new JFrame() {
@Override
@@ -163,6 +176,12 @@
frame.add(component);
component.sqlshellWindow.repaintScreen();
frame.pack();
+ if (argsMap.get("-i") != null) {
+ new nl.improved.sqlclient.AbstractSQLShellWindow.ExecuteBatchCommand(component.sqlshellWindow).execute(new SQLCommand("@"+ argsMap.get("-i")));
+ }
+ if (argsMap.get("-q") != null) {
+ return;
+ }
frame.show();
}
|
|
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;
|
|
From: SVN by r. <sv...@ca...> - 2009-01-19 15:43:57
|
Author: roy
Date: 2009-01-19 16:43:49 +0100 (Mon, 19 Jan 2009)
New Revision: 361
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
more thread handling
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-19 14:26:56 UTC (rev 360)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-19 15:43:49 UTC (rev 361)
@@ -158,7 +158,7 @@
SwingUtilities.invokeLater(eventThead);
}
- public void paintSlow(Screen screen) {
+ public void paintSlow(final Screen screen) {
int totalLineCount = 0;
StringBuilder newText = new StringBuilder();
for (CharSequence seq: new ArrayList<CharSequence>(screen.getScreenBuffer())) {
@@ -174,7 +174,7 @@
totalLineCount++;
}
}
- List<String> commandLines = formatCommandLines(screen.getShowPrompt()
+ 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);
@@ -187,20 +187,28 @@
if (totalLineCount > getScreenHeight()-1) {
totalLineCount = getScreenHeight()-1;
}
- String trimmed = trim(newText, screen.getPageUpCount());
- if (trimmed.startsWith(textComponent.getText())) {
- textComponent.append(trimmed.substring(textComponent.getText().length()));
- } else {
- textComponent.replaceRange(trimmed, 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;
+ final String trimmed = trim(newText, screen.getPageUpCount());
+ Runnable r = new Runnable() {
+
+ public void run() {
+ if (trimmed.startsWith(textComponent.getText())) {
+ textComponent.append(trimmed.substring(textComponent.getText().length()));
+ } else {
+ textComponent.replaceRange(trimmed, 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(r);
}
@Override
|
|
From: SVN by r. <sv...@ca...> - 2009-01-23 16:27:48
|
Author: roy
Date: 2009-01-23 17:27:40 +0100 (Fri, 23 Jan 2009)
New Revision: 363
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
code cleanup
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-23 16:27:25 UTC (rev 362)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-23 16:27:40 UTC (rev 363)
@@ -109,16 +109,16 @@
}
int restLines = (getScreenHeight() -1) - totalLineCount;
if (restLines > 0) {
- ArrayList<SQLCommand> commands = new ArrayList<SQLCommand>(getUnprocessedCommands());
- Collections.reverse(commands);
- commands: for (SQLCommand command : commands) {
+ ArrayList<SQLCommand> commandList = new ArrayList<SQLCommand>(getUnprocessedCommands());
+ Collections.reverse(commandList);
+ commandList: for (SQLCommand command : commandList) {
List<? extends CharSequence> lines = command.getLines();
for (int i = lines.size() -1; i >=0; i--) {
newText.insert(0, lines.get(i) +"\n");
restLines--;
totalLineCount++;
if(restLines == 0) {
- break commands;
+ break;
}
}
}
|
|
From: SVN by r. <sv...@ca...> - 2009-01-26 08:44:34
|
Author: roy
Date: 2009-01-26 09:44:29 +0100 (Mon, 26 Jan 2009)
New Revision: 371
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
remove sleep
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-26 08:42:48 UTC (rev 370)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-01-26 08:44:29 UTC (rev 371)
@@ -215,11 +215,6 @@
@Override
public void close() {
frame.hide();
- try {
- Thread.sleep(1000);
- } catch (InterruptedException ex) {
- Logger.getLogger(CharvaSQLShellWindow.class.getName()).log(Level.SEVERE, null, ex);
- }
super.close();
}
|
|
From: SVN by r. <sv...@ca...> - 2009-04-20 20:15:09
|
Author: roy
Date: 2009-04-20 22:14:57 +0200 (Mon, 20 Apr 2009)
New Revision: 405
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
remove debug statement
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-04-20 20:12:45 UTC (rev 404)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-04-20 20:14:57 UTC (rev 405)
@@ -88,7 +88,7 @@
@Override
public void paint(final Screen screen) {
- debug("PageUpCount: "+ screen.getPageUpCount());
+ //debug("PageUpCount: "+ screen.getPageUpCount());
if (screen.getPageUpCount() > 0) {
paintSlow(screen);
return;
|
|
From: SVN by r. <sv...@ca...> - 2009-08-02 15:24:23
|
Author: roy
Date: 2009-08-02 17:24:06 +0200 (Sun, 02 Aug 2009)
New Revision: 411
Modified:
src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
Log:
added some debug info
Modified: src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java
===================================================================
--- src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-07-30 07:33:38 UTC (rev 410)
+++ src/main/java/nl/improved/sqlclient/charva/CharvaSQLShellWindow.java 2009-08-02 15:24:06 UTC (rev 411)
@@ -149,6 +149,7 @@
try {
int start = textComponent.getLineStartOffset(lineCount - (commandLines.size() - cursorPos.y));
textComponent.setCaretPosition(start + cursorPos.x + (Screen.PROMPT+" >").length());
+ debug("Set caret position: "+ start+"+"+cursorPos.x+"+"+(Screen.PROMPT+" >").length());
} catch(Exception e) {
debug("ERROR: failed to calculate line end: "+ lineCount +"-"+ cursorPos.y +"/"+ getScreenHeight());
}
@@ -202,6 +203,7 @@
try {
int start = textComponent.getLineStartOffset(lineCount - (commandLines.size() - cursorPos.y));
textComponent.setCaretPosition(start + cursorPos.x + (Screen.PROMPT+" >").length());
+ debug("Set caret position: "+ start+"+"+cursorPos.x+"+"+(Screen.PROMPT+" >").length());
} catch(Exception e) {
debug("ERROR: failed to calculate line end: "+ lineCount +"-"+ cursorPos.y +"/"+ getScreenHeight());
}
|