|
||||||||||
| 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 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 String |
_prompt
String to use for the prompt. |
private int |
_promptPos
Index in the document of the first place that is editable. |
static String |
DEFAULT_CONSOLE_PROMPT
The default prompt to use in the console. |
static String |
DEFAULT_STYLE
Default text style. |
static String |
SYSTEM_ERR_STYLE
Style for System.err |
static String |
SYSTEM_IN_STYLE
Style for System.in |
static 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,
String str,
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(String str,
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,
String str,
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. |
String |
getCurrentInput()
Returns the string that the user has entered at the current prompt. |
String |
getDefaultStyle()
Gets the String identifying the default style for this document if one exists; null otherwise. |
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. |
Pageable |
getPageable()
Returns the Pageable object for printing. |
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. |
String |
getText()
Returns the entire text of the document. |
boolean |
hasPrompt()
|
void |
insertBeforeLastPrompt(String text,
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,
String str,
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(String banner)
Resets the document to a clean state. |
void |
saveCopy(FileSaveSelector selector)
Saves the contents of the document to a file. |
void |
setBeep(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(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 String DEFAULT_CONSOLE_PROMPT
public static final String DEFAULT_STYLE
public static final String SYSTEM_OUT_STYLE
public static final String SYSTEM_ERR_STYLE
public static final String SYSTEM_IN_STYLE
protected final ConsoleDocumentInterface _document
protected volatile Runnable _beep
private volatile int _promptPos
protected volatile 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 String getPrompt()
public void setPrompt(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(Runnable beep)
beep - Runnable beep commandpublic void reset(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(String text,
String style)
text - String to insertstyle - name of style to format the string
public void insertText(int offs,
String str,
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(String str,
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,
String str,
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,
String str,
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 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 String getText()
EditDocumentException - if the offset or length are illegalpublic String getCurrentInput()
public void clearCurrentInput()
protected void _clearCurrentInputText()
public String getDefaultStyle()
EditDocumentInterface
getDefaultStyle in interface EditDocumentInterface
public Pageable getPageable()
throws IllegalStateException
getPageable in interface EditDocumentInterfaceIllegalStateExceptionpublic void preparePrintJob()
public void print()
throws PrinterException
print in interface EditDocumentInterfacePrinterExceptionpublic void cleanUpPrintJob()
public void saveCopy(FileSaveSelector selector)
throws IOException
selector - File to save to
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||