Package edu.wisc.ssec.mcidasv.jython
Class Console
java.lang.Object
edu.wisc.ssec.mcidasv.jython.Console
- All Implemented Interfaces:
KeyListener,Runnable,EventListener
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumMaps a "jython action" to a keystroke.static classstatic enumprivate class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]Offset array used when actual offsets cannot be determined.private static final StringNot used yet.private ConsoleCallbackA hook that allows external classes to respond to events.private DocumenttextPane's internal representation.private final booleanprivate static final FontAll text will appear in this font.Jython statements entered by the user.private RunnerThread that handles Jython command execution.private static final org.slf4j.LoggerLoggerobject for Jython consoles.private MenuWranglerprivate JPanelPanel that holdstextPane.private static final StringNormal jython prompt.private static final StringPrompt that indicates more input is needed.private JTextPaneWhere the user interacts with the Jython interpreter.protected static final ColorColor of text coming from "stderr".protected static final ColorColor of text coming from "stdout".protected static final ColorColor of the Jython text as it is being entered.protected static final ColorNot used just yet...private static final StringActualStringof whitespace to insert for blocks and whatnot.private StringTitle of the console window. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPretendHistory(String line) private booleancanInsertAt(int position) Determines whether or notpositionis an acceptable place to insert text.voidejectObject(org.python.core.PyObject pyObject) voidejectObjectByName(String name) protected voidInserts a newline character at the end of the input.voidDisplays an error.voidgeneratedError(String text) Displays error output.voidgeneratedOutput(String text) Displays non-error output that was not the result of an "associated"Command.static intgetBlockDepth(String line, String whitespace) Returns the "block depth" of a given line of Jython.intReturns the Jython statements as entered by the user, ordered from first to last.Returns a subset of Jython's local namespace containing only variables that are "pure" Java objects.org.python.core.PyObjectgetJythonObject(String var) Retrieves the specified Jython variable from the interpreters local namespace.intgetLineJython(int lineNumber) Returns the line of Jython that occupies a specified line number.intgetLineOffsetEnd(int lineNumber) int[]getLineOffsets(int lineNumber) intgetLineOffsetStart(int lineNumber) getLineText(int lineNumber) Returns the line of text that occupies the specified line number.Returns a copy of Jython's local namespace.intgetOffsetLine(int offset) Returns the line number that contains the specified offset.getPanel()Returns the panel containing the various UI components.static intgetPromptLength(String line) protected JTextPaneReturns theJTextPaneused by the console.static StringgetUserPath(String[] args) voidvoidvoidMoves the caret to the end of the line it is currently on, rather than the end of the document.voidHandles the user pressing enter by basically grabbing the line of jython under the caret.voidHandles the user hitting theHomekey.voidvoidInserts the contents ofWHITESPACEwherever the cursor is located.voidhandleUp()private static booleanvoidinjectObject(String name, Object object) Inserts the specified object into Jython's local namespace using the specified name.protected voidDoes the actual work of displaying color-coded messages intextPane.protected voidinsertAtCaret(Color color, String text) voidNoop.voidNoop.voidprivate int[]Returns the offsets of the beginning and end of the last line.static voidvoidShows the prompt that indicates more input is needed.voidmoreInput(int blockLevel) private booleanDetermines whether or not the caret is on the last line.voidprompt()Shows the normal Jython prompt.voidqueueBatch(String name, List<String> commands) Sends a batch of Jython commands to the interpreter.voidSends a line of Jython to the interpreter viajythonRunnerand saves it to the history.voidDisplays non-error output.voidrun()Puts together the GUI once EventQueue has processed all other pending events.voidRuns the file specified bypathin theInterpreter.voidsetCallbackHandler(ConsoleCallback newHandler) Registers a new callback handler with the console.private voidWill eventually display an initial greeting to the user.static voidtestConsole(boolean exitOnClose)
-
Field Details
-
TXT_NORMAL
Color of the Jython text as it is being entered. -
TXT_GOOD
Color of text coming from "stdout". -
TXT_WARN
Not used just yet... -
TXT_ERROR
Color of text coming from "stderr". -
logger
Loggerobject for Jython consoles. -
BAD_OFFSETS
Offset array used when actual offsets cannot be determined. -
PS1
Normal jython prompt.- See Also:
-
PS2
Prompt that indicates more input is needed.- See Also:
-
WHITESPACE
ActualStringof whitespace to insert for blocks and whatnot.- See Also:
-
BANNER
Not used yet. -
FONT
All text will appear in this font. -
jythonHistory
Jython statements entered by the user. -
jythonRunner
Thread that handles Jython command execution. -
callback
A hook that allows external classes to respond to events. -
textPane
Where the user interacts with the Jython interpreter. -
document
textPane's internal representation. -
panel
Panel that holdstextPane. -
windowTitle
Title of the console window. -
exitOnClose
-
-
Constructor Details
-
Console
public Console()Build a console with no initial commands. -
Console
-
Console
Builds a console and executes a list of Jython statements. It's been useful for dirty tricks needed during setup.- Parameters:
initialCommands- Jython statements to execute.
-
-
Method Details
-
getPanel
Returns the panel containing the various UI components. -
getTextPane
Returns theJTextPaneused by the console. -
injectObject
Inserts the specified object into Jython's local namespace using the specified name.Example:
console.injectObject("test", new PyJavaInstance("a test"))Allows the interpreter to refer to theString"a test"astest.- Parameters:
name- Object name as it will appear within the interpreter.object- Object to place in the interpreter's local namespace.
-
ejectObjectByName
-
ejectObject
-
runFile
Runs the file specified bypathin theInterpreter.- Parameters:
name-__name__attribute to use for loadingpath.path- The path to the Jython file.
-
result
Displays non-error output.- Parameters:
text- The message to display.
-
error
Displays an error.- Parameters:
text- The error message.
-
prompt
Shows the normal Jython prompt. -
generatedOutput
Displays non-error output that was not the result of an "associated"Command.- Parameters:
text- The text to display.- See Also:
-
generatedError
Displays error output. Differs fromerror(String)in that this is intended for output not "associated" with aCommand.Example: say you fire off a background thread. If it generates an error somehow, this is the method you want.
- Parameters:
text- The error message.
-
moreInput
Shows the prompt that indicates more input is needed. -
moreInput
-
showBanner
Will eventually display an initial greeting to the user.- Throws:
BadLocationException- Upon attempting to clear out an invalid portion of the document.
-
endln
Inserts a newline character at the end of the input.- Parameters:
color- Perhaps this should go!?
-
insert
Does the actual work of displaying color-coded messages intextPane.- Parameters:
color- The color of the message.text- The actual message.
-
insertAtCaret
-
canInsertAt
Determines whether or notpositionis an acceptable place to insert text. Currently the criteria for "acceptable" means thatpositionis located within the last (or active) line, and not within eitherPS1orPS2.- Parameters:
position- Position to test. Values less than zero are not allowed.- Returns:
- Whether or not text can be inserted at
position.
-
getLineCount
- Returns:
- Number of lines in the document.
-
getLineOffsetStart
-
getLineOffsetEnd
-
getLineOffsets
-
getOffsetLine
Returns the line number that contains the specified offset.- Parameters:
offset- Offset whose line number you want.- Returns:
- Line number.
-
locateLastLine
Returns the offsets of the beginning and end of the last line. -
onLastLine
Determines whether or not the caret is on the last line. -
getCaretLine
- Returns:
- The line number of the caret's offset within the text.
-
getLineText
Returns the line of text that occupies the specified line number.- Parameters:
lineNumber- Line number whose text is to be returned.- Returns:
- Either the line of text or null if there was an error.
-
getLineJython
Returns the line of Jython that occupies a specified line number. This is different thangetLineText(int)in that bothPS1andPS2are removed from the returned line.- Parameters:
lineNumber- Line number whose text is to be returned.- Returns:
- Either the line of Jython or null if there was an error.
-
getPromptLength
- Parameters:
line- The line in question. Cannot benull.- Returns:
- Either the prompt length or zero if there was none.
- Throws:
NullPointerException- iflineisnull.
-
getBlockDepth
Returns the "block depth" of a given line of Jython.Examples:
"print 'x'" -> 0 " print 'x'" -> 1 " die()" -> 3
- Parameters:
line- Line to test. Can't benull.whitespace- The indentStringused withline. Can't benull.- Returns:
- Either the block depth (
>= 0) or-1if there was an error.
-
setCallbackHandler
Registers a new callback handler with the console. Note that to maximize utility, this method also registers the same handler withjythonRunner.- Parameters:
newHandler- The new callback handler.- Throws:
NullPointerException- if the new handler is null.
-
getJythonReferencesTo
-
getJavaInstances
Returns a subset of Jython's local namespace containing only variables that are "pure" Java objects.- Returns:
- Jython variable names mapped to their Java instantiation.
-
getJythonObject
Retrieves the specified Jython variable from the interpreters local namespace.- Parameters:
var- Variable name to retrieve.- Returns:
- Either the variable or null. Note that null will also be
returned if
Runner.copyLocals()returned null.
-
getLocalNamespace
Returns a copy of Jython's local namespace.- Returns:
- Jython variable names mapped to
PyObjects.
-
handlePaste
-
handleHome
-
handleEnd
Moves the caret to the end of the line it is currently on, rather than the end of the document. -
handleUp
-
handleDown
-
handleTab
Inserts the contents ofWHITESPACEwherever the cursor is located. -
handleDelete
-
handleEnter
Handles the user pressing enter by basically grabbing the line of jython under the caret. If the caret is on the last line, the line is queued for execution. Otherwise the line is reinserted at the end of the document--this lets the user preview a previous command before they rerun it. -
getHistory
Returns the Jython statements as entered by the user, ordered from first to last.- Returns:
- User's history.
-
queueLine
Sends a line of Jython to the interpreter viajythonRunnerand saves it to the history.- Parameters:
line- Jython to queue for execution.
-
queueBatch
Sends a batch of Jython commands to the interpreter. This is different than simply callingqueueLine(String)for each command; the interpreter will attempt to execute each batched command before returning "control" to the console.This method is mostly useful for restoring Console sessions. Each command in
commandswill appear in the console as though the user typed it. The batch of commands will also be saved to the history.- Parameters:
name- Identifier for the batch. Doesn't need to be unique, merely non-null.commands- The commands to execute.
-
addPretendHistory
-
run
Puts together the GUI once EventQueue has processed all other pending events. -
keyPressed
Noop.- Specified by:
keyPressedin interfaceKeyListener
-
keyReleased
Noop.- Specified by:
keyReleasedin interfaceKeyListener
-
keyTyped
- Specified by:
keyTypedin interfaceKeyListener
-
hasAction
-
getUserPath
-
testConsole
-
main
-