[Mathlib-commitlog] SF.net SVN: mathlib:[898] JMathLib/trunk/src/jmathlib/ui/common
Status: Beta
Brought to you by:
st_mueller
From: <st_...@us...> - 2009-03-01 13:27:55
|
Revision: 898 http://mathlib.svn.sourceforge.net/mathlib/?rev=898&view=rev Author: st_mueller Date: 2009-03-01 13:27:42 +0000 (Sun, 01 Mar 2009) Log Message: ----------- use Console.java from jmathlib.ui.common Added Paths: ----------- JMathLib/trunk/src/jmathlib/ui/common/Console.java Removed Paths: ------------- JMathLib/trunk/src/jmathlib/ui/common/Console.java Deleted: JMathLib/trunk/src/jmathlib/ui/common/Console.java =================================================================== --- JMathLib/trunk/src/jmathlib/ui/common/Console.java 2009-03-01 13:25:51 UTC (rev 897) +++ JMathLib/trunk/src/jmathlib/ui/common/Console.java 2009-03-01 13:27:42 UTC (rev 898) @@ -1,168 +0,0 @@ -/* - * This file is part or JMathLib - * - * Check it out at http://www.jmathlib.de - * - * Author: st...@he... - * (c) 2006-2009 - */ -package jmathlib.ui.common; - -import jmathlib.core.interfaces.RemoteAccessible; - -import java.awt.*; -import java.awt.event.*; -import java.util.Vector; - -/**Class implementing a console style window -It needs the ConsoleKeyHandler class to work*/ -public class Console extends TextArea -{ - int commandNo; - - /**store for previous commands*/ - Vector previousCommands; - - /**The position of the start of the line*/ - int lineStart; - - /**The applet containing the console*/ - RemoteAccessible callerClass; - - /**Event Handler used for handling key events*/ - //public KeyListener keyHandler; - - /**Construct the console*/ - public Console(RemoteAccessible _callerClass) - { - - commandNo = 0; - previousCommands = new Vector(10, 10); - lineStart = getText().length() + 1; - - callerClass = _callerClass; - - KeyListener keyHandler = new ConsoleKeyHandler(); - - addKeyListener(keyHandler); - } - - public void addKeyListener(KeyListener keyHandler) - { - //System.out.println("KEYLISTENER"); - System.out.println("KEY "+keyHandler); - super.addKeyListener(keyHandler); - } - - /**display the previous command in the list*/ - public void prevCommand() - { - commandNo--; - - String text = ""; - if(commandNo >= 0 && commandNo < previousCommands.size()) - { - text = ((String)previousCommands.elementAt(commandNo)).trim(); - } - else if(commandNo < 0) - { - text = ""; - commandNo = -1; - } - - // replace current command with previous command - String textArea = getText(); - int pos1 = textArea.lastIndexOf("> ") + 2; - setText(textArea.substring(0,pos1)+text); - - // set cursor at the end of the text area - setCaretPosition(getText().length()); - } - - /**display the next command in the list*/ - public void nextCommand() - { - commandNo++; - - String text = ""; - if(commandNo >= 0 && commandNo < previousCommands.size()) - { - text = ((String)previousCommands.elementAt(commandNo)).trim(); - } - else if(commandNo >= previousCommands.size()) - { - text = ""; - commandNo = previousCommands.size(); - } - - // replace current command with next command - String textArea = getText(); - int pos1 = textArea.lastIndexOf("> ") + 2; - setText(textArea.substring(0,pos1)+text); - - // set cursor at the end of the text area - setCaretPosition(getText().length()); - } - - /**Check that the cursor hasn't moved beyond the start - of the line*/ - public void checkPosition() - { - if(getCaretPosition() < lineStart) - setCaretPosition(lineStart); - } - - /**Go to the home position*/ - public void home() - { - setCaretPosition(lineStart - 1); - } - - /**Go to the end of the line*/ - public void end() - { - setCaretPosition(getText().length()); - } - - /**Interpret the current line*/ - public void interpretLine() - { - //get the text on the current line - String text = getText(); - String inputString = text.substring(text.lastIndexOf("> ") + 2, text.length()); - - /* exit application */ - if(inputString.equals("quit") || - inputString.equals("exit") ) - { - callerClass.close(); - } - - - append("\n"); - callerClass.interpretLine(inputString); - previousCommands.addElement(inputString); - commandNo = previousCommands.size(); - } - - /**Display the command prompt*/ - public void displayPrompt() - { - append("> "); - lineStart = getText().length() + 1; - setCaretPosition(lineStart); - } - - //Display a new line*/ - public void newLine() - { - append("\n"); - } - - /**Display some text on a new line*/ - public void displayText(String text) - { - append( text + "\n" ); - } - -} Added: JMathLib/trunk/src/jmathlib/ui/common/Console.java =================================================================== --- JMathLib/trunk/src/jmathlib/ui/common/Console.java (rev 0) +++ JMathLib/trunk/src/jmathlib/ui/common/Console.java 2009-03-01 13:27:42 UTC (rev 898) @@ -0,0 +1,168 @@ +/* + * This file is part or JMathLib + * + * Check it out at http://www.jmathlib.de + * + * Author: st...@he... + * (c) 2006-2009 + */ +package jmathlib.ui.common; + +import jmathlib.core.interfaces.RemoteAccessible; + +import java.awt.*; +import java.awt.event.*; +import java.util.Vector; + +/**Class implementing a console style window +It needs the ConsoleKeyHandler class to work*/ +public class Console extends TextArea +{ + int commandNo; + + /**store for previous commands*/ + Vector previousCommands; + + /**The position of the start of the line*/ + int lineStart; + + /**The applet containing the console*/ + RemoteAccessible callerClass; + + /**Event Handler used for handling key events*/ + //public KeyListener keyHandler; + + /**Construct the console*/ + public Console(RemoteAccessible _callerClass) + { + + commandNo = 0; + previousCommands = new Vector(10, 10); + lineStart = getText().length() + 1; + + callerClass = _callerClass; + + KeyListener keyHandler = new ConsoleKeyHandler(); + + addKeyListener(keyHandler); + } + + public void addKeyListener(KeyListener keyHandler) + { + //System.out.println("KEYLISTENER"); + System.out.println("KEY "+keyHandler); + super.addKeyListener(keyHandler); + } + + /**display the previous command in the list*/ + public void prevCommand() + { + commandNo--; + + String text = ""; + if(commandNo >= 0 && commandNo < previousCommands.size()) + { + text = ((String)previousCommands.elementAt(commandNo)).trim(); + } + else if(commandNo < 0) + { + text = ""; + commandNo = -1; + } + + // replace current command with previous command + String textArea = getText(); + int pos1 = textArea.lastIndexOf("> ") + 2; + setText(textArea.substring(0,pos1)+text); + + // set cursor at the end of the text area + setCaretPosition(getText().length()); + } + + /**display the next command in the list*/ + public void nextCommand() + { + commandNo++; + + String text = ""; + if(commandNo >= 0 && commandNo < previousCommands.size()) + { + text = ((String)previousCommands.elementAt(commandNo)).trim(); + } + else if(commandNo >= previousCommands.size()) + { + text = ""; + commandNo = previousCommands.size(); + } + + // replace current command with next command + String textArea = getText(); + int pos1 = textArea.lastIndexOf("> ") + 2; + setText(textArea.substring(0,pos1)+text); + + // set cursor at the end of the text area + setCaretPosition(getText().length()); + } + + /**Check that the cursor hasn't moved beyond the start + of the line*/ + public void checkPosition() + { + if(getCaretPosition() < lineStart) + setCaretPosition(lineStart); + } + + /**Go to the home position*/ + public void home() + { + setCaretPosition(lineStart - 1); + } + + /**Go to the end of the line*/ + public void end() + { + setCaretPosition(getText().length()); + } + + /**Interpret the current line*/ + public void interpretLine() + { + //get the text on the current line + String text = getText(); + String inputString = text.substring(text.lastIndexOf("> ") + 2, text.length()); + + /* exit application */ + if(inputString.equals("quit") || + inputString.equals("exit") ) + { + callerClass.close(); + } + + + append("\n"); + callerClass.interpretLine(inputString); + previousCommands.addElement(inputString); + commandNo = previousCommands.size(); + } + + /**Display the command prompt*/ + public void displayPrompt() + { + append("> "); + lineStart = getText().length() + 1; + setCaretPosition(lineStart); + } + + //Display a new line*/ + public void newLine() + { + append("\n"); + } + + /**Display some text on a new line*/ + public void displayText(String text) + { + append( text + "\n" ); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |