|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.util.text.ConsoleDocument
public class ConsoleDocument
A GUI-toolkit agnostic interface to a console document. This class assumes that the embedded document supports readers/writers locking and uses that locking protocol to ensure the integrity of the data added in this class WHY is prompt considered part of a console document rather than an interactions document?
| Nested Class Summary | |
|---|---|
(package private) class |
ConsoleDocument.ConsoleEditCondition
Class ensuring that attempts to edit document lines above the prompt are rejected. |
| Field Summary | |
|---|---|
protected java.lang.Runnable |
_beep
A runnable command to use for a notification beep. |
protected DrJavaBook |
_book
The book object used for printing that represents several pages |
protected ConsoleDocumentInterface |
_document
The embedded document storing the text and _hasPrompt property for this console model. |
protected java.lang.String |
_prompt
String to use for the prompt. |
private int |
_promptPos
Index in the document of the first place that is editable. |
static java.lang.String |
DEFAULT_CONSOLE_PROMPT
The default prompt to use in the console. |
static java.lang.String |
DEFAULT_STYLE
Default text style. |
static java.lang.String |
SYSTEM_ERR_STYLE
Style for System.err |
static java.lang.String |
SYSTEM_IN_STYLE
Style for System.in |
static java.lang.String |
SYSTEM_OUT_STYLE
Style for System.out |
| Constructor Summary | |
|---|---|
ConsoleDocument(ConsoleDocumentInterface doc)
Creates a new ConsoleDocument with the given embedded ConsoleDocumentInterface (a SwingDocument in native DrJava). |
|
| Method Summary | |
|---|---|
private void |
_addToStyleLists(int offs,
java.lang.String str,
java.lang.String style)
Adds style specifier to _stylelists. |
protected void |
_clearCurrentInputText()
Removes the text from the current prompt to the end of the document. |
private int |
_getPositionBeforePrompt()
Gets the position immediately before the prompt, or the doc length if there is no prompt. |
void |
append(java.lang.String str,
java.lang.String style)
Appends a string to this in the given named style, if the edit condition allows it. |
void |
cleanUpPrintJob()
Clears the pageable object used to hold the print job. |
void |
clearCurrentInput()
Clears the current input text. |
void |
disablePrompt()
Disables the prompt in this document. |
void |
forceInsertText(int offs,
java.lang.String str,
java.lang.String style)
Inserts a string into the document at the given offset and style, regardless of the edit condition. |
void |
forceRemoveText(int offs,
int len)
Removes a portion of the document, regardless of the edit condition. |
java.lang.String |
getCurrentInput()
Returns the string that the user has entered at the current prompt. |
java.lang.String |
getDefaultStyle()
Gets the String identifying the default style for this document if one exists; null otherwise. |
java.lang.String |
getDocText(int offs,
int len)
Returns a portion of the document. |
DocumentEditCondition |
getEditCondition()
Gets the object which determines whether an insert/remove edit should be applied based on the inputs. |
int |
getLength()
Returns the length of the document. |
java.awt.print.Pageable |
getPageable()
Returns the Pageable object for printing. |
java.lang.String |
getPrompt()
Accessor for the string used for the prompt. |
int |
getPromptLength()
Returns the length of the prompt string. |
int |
getPromptPos()
Returns the first location in the document where editing is allowed. |
java.lang.String |
getText()
Returns the entire text of the document. |
boolean |
hasPrompt()
|
void |
insertBeforeLastPrompt(java.lang.String text,
java.lang.String style)
Inserts the given string with the given attributes just before the most recent prompt. |
void |
insertNewline(int pos)
Inserts a new line at the given position. |
void |
insertPrompt()
Prints a prompt for a new input. |
void |
insertText(int offs,
java.lang.String str,
java.lang.String style)
Inserts a string into the document at the given offset and named style, if the edit condition allows it. |
void |
preparePrintJob()
This method tells the document to prepare all the DrJavaBook and PagePrinter objects. |
void |
print()
Prints the given document by bringing up a "Print" window. |
void |
removeText(int offs,
int len)
Removes a portion of the document, if the edit condition (including promptPos) allows it. |
void |
reset(java.lang.String banner)
Resets the document to a clean state. |
void |
saveCopy(FileSaveSelector selector)
Saves the contents of the document to a file. |
void |
setBeep(java.lang.Runnable beep)
Sets a runnable action to use as a beep. |
void |
setEditCondition(DocumentEditCondition condition)
Provides an object which can determine whether an insert or remove edit should be applied, based on the inputs. |
void |
setHasPrompt(boolean val)
Setter for the _hasPrompt property. |
void |
setPrompt(java.lang.String prompt)
Sets the string to use for the prompt. |
void |
setPromptPos(int newPos)
Sets the prompt position. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String DEFAULT_CONSOLE_PROMPT
public static final java.lang.String DEFAULT_STYLE
public static final java.lang.String SYSTEM_OUT_STYLE
public static final java.lang.String SYSTEM_ERR_STYLE
public static final java.lang.String SYSTEM_IN_STYLE
protected final ConsoleDocumentInterface _document
protected volatile java.lang.Runnable _beep
private volatile int _promptPos
protected volatile java.lang.String _prompt
protected volatile DrJavaBook _book
| Constructor Detail |
|---|
public ConsoleDocument(ConsoleDocumentInterface doc)
doc - the embedded ConsoleDocumentInterface object| Method Detail |
|---|
public boolean hasPrompt()
hasPrompt in interface ConsoleDocumentInterfacepublic void setHasPrompt(boolean val)
ConsoleDocumentInterface
setHasPrompt in interface ConsoleDocumentInterfacepublic java.lang.String getPrompt()
public void setPrompt(java.lang.String prompt)
prompt - String to use for the prompt.public int getPromptLength()
public DocumentEditCondition getEditCondition()
getEditCondition in interface EditDocumentInterfacepublic void setEditCondition(DocumentEditCondition condition)
setEditCondition in interface EditDocumentInterfacecondition - Object to determine legality of inputspublic int getPromptPos()
public void setPromptPos(int newPos)
newPos - the new position.public void setBeep(java.lang.Runnable beep)
beep - Runnable beep commandpublic void reset(java.lang.String banner)
public void insertPrompt()
public void disablePrompt()
public void insertNewline(int pos)
pos - Position to insert the new lineprivate int _getPositionBeforePrompt()
public void insertBeforeLastPrompt(java.lang.String text,
java.lang.String style)
text - String to insertstyle - name of style to format the string
public void insertText(int offs,
java.lang.String str,
java.lang.String style)
throws EditDocumentException
insertText in interface EditDocumentInterfaceoffs - Offset into the documentstr - String to be insertedstyle - Name of the style to use. Must have been added using addStyle.
EditDocumentException - if the offset is illegal
public void append(java.lang.String str,
java.lang.String style)
throws EditDocumentException
append in interface EditDocumentInterfacestr - String to be insertedstyle - Name of the style to use. Must have been added using addStyle.
EditDocumentException - if the offset is illegal
public void forceInsertText(int offs,
java.lang.String str,
java.lang.String style)
throws EditDocumentException
forceInsertText in interface EditDocumentInterfaceoffs - Offset into the documentstr - String to be insertedstyle - Name of the style to use. Must have been added using addStyle.
EditDocumentException - if the offset is illegal
private void _addToStyleLists(int offs,
java.lang.String str,
java.lang.String style)
public void removeText(int offs,
int len)
throws EditDocumentException
removeText in interface EditDocumentInterfaceoffs - Offset to start deleting fromlen - Number of characters to remove
EditDocumentException - if the offset or length are illegal
public void forceRemoveText(int offs,
int len)
throws EditDocumentException
forceRemoveText in interface EditDocumentInterfaceoffs - Offset to start deleting fromlen - Number of characters to remove
EditDocumentException - if the offset or length are illegalpublic int getLength()
getLength in interface EditDocumentInterface
public java.lang.String getDocText(int offs,
int len)
throws EditDocumentException
getDocText in interface EditDocumentInterfaceoffs - First offset of the desired textlen - Number of characters to return
EditDocumentException - if the offset or length are illegalpublic java.lang.String getText()
EditDocumentException - if the offset or length are illegalpublic java.lang.String getCurrentInput()
public void clearCurrentInput()
protected void _clearCurrentInputText()
public java.lang.String getDefaultStyle()
EditDocumentInterface
getDefaultStyle in interface EditDocumentInterface
public java.awt.print.Pageable getPageable()
throws java.lang.IllegalStateException
getPageable in interface EditDocumentInterfacejava.lang.IllegalStateExceptionpublic void preparePrintJob()
public void print()
throws java.awt.print.PrinterException
print in interface EditDocumentInterfacejava.awt.print.PrinterExceptionpublic void cleanUpPrintJob()
public void saveCopy(FileSaveSelector selector)
throws java.io.IOException
selector - File to save to
java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||