|
||||||||||
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?
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. |
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 | |
---|---|
protected void |
_clearCurrentInputText()
Removes the text from the current prompt to the end of the document. |
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 |
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
protected volatile String _prompt
protected volatile DrJavaBook _book
Constructor Detail |
---|
public ConsoleDocument(ConsoleDocumentInterface doc)
doc
- the embedded ConsoleDocumentInterface objectMethod Detail |
---|
public boolean hasPrompt()
hasPrompt
in interface ConsoleDocumentInterface
public void setHasPrompt(boolean val)
ConsoleDocumentInterface
setHasPrompt
in interface ConsoleDocumentInterface
public String getPrompt()
public void setPrompt(String prompt)
prompt
- String to use for the prompt.public int getPromptLength()
public DocumentEditCondition getEditCondition()
getEditCondition
in interface EditDocumentInterface
public void setEditCondition(DocumentEditCondition condition)
setEditCondition
in interface EditDocumentInterface
condition
- 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 linepublic void insertBeforeLastPrompt(String text, String style)
text
- String to insertstyle
- name of style to format the stringpublic void insertText(int offs, String str, String style) throws EditDocumentException
insertText
in interface EditDocumentInterface
offs
- 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 illegalpublic void append(String str, String style) throws EditDocumentException
append
in interface EditDocumentInterface
str
- String to be insertedstyle
- Name of the style to use. Must have been added using addStyle.
EditDocumentException
- if the offset is illegalpublic void forceInsertText(int offs, String str, String style) throws EditDocumentException
forceInsertText
in interface EditDocumentInterface
offs
- 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 illegalpublic void removeText(int offs, int len) throws EditDocumentException
removeText
in interface EditDocumentInterface
offs
- Offset to start deleting fromlen
- Number of characters to remove
EditDocumentException
- if the offset or length are illegalpublic void forceRemoveText(int offs, int len) throws EditDocumentException
forceRemoveText
in interface EditDocumentInterface
offs
- 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 EditDocumentInterface
offs
- 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 EditDocumentInterface
IllegalStateException
public void preparePrintJob()
public void print() throws PrinterException
print
in interface EditDocumentInterface
PrinterException
public void cleanUpPrintJob()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |