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; |