kawa
Class ReplDocument
java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.DefaultStyledDocument
kawa.ReplDocument
- All Implemented Interfaces:
- java.awt.event.FocusListener, java.io.Serializable, java.util.EventListener, javax.swing.event.DocumentListener, javax.swing.text.Document, javax.swing.text.StyledDocument
public class ReplDocument
- extends javax.swing.text.DefaultStyledDocument
- implements javax.swing.event.DocumentListener, java.awt.event.FocusListener
A Swing document that implements a read-eval-print-loop.
- See Also:
- Serialized Form
Nested classes/interfaces inherited from class javax.swing.text.DefaultStyledDocument |
javax.swing.text.DefaultStyledDocument.AttributeUndoableEdit, javax.swing.text.DefaultStyledDocument.ElementBuffer, javax.swing.text.DefaultStyledDocument.ElementSpec, javax.swing.text.DefaultStyledDocument.SectionElement |
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument |
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement |
Field Summary |
static javax.swing.text.Style |
defaultStyle
|
int |
endMark
End of pending input. |
static javax.swing.text.Style |
inputStyle
|
int |
outputMark
The offset where output from process is inserted. |
static javax.swing.text.Style |
redStyle
|
static javax.swing.text.StyleContext |
styles
|
Fields inherited from class javax.swing.text.DefaultStyledDocument |
buffer, BUFFER_SIZE_DEFAULT |
Fields inherited from class javax.swing.text.AbstractDocument |
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName |
Fields inherited from interface javax.swing.text.Document |
StreamDescriptionProperty, TitleProperty |
Methods inherited from class javax.swing.text.DefaultStyledDocument |
addDocumentListener, addStyle, create, createDefaultRoot, getBackground, getCharacterElement, getDefaultRootElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, getStyleNames, insert, insertUpdate, removeDocumentListener, removeStyle, removeUpdate, setCharacterAttributes, setLogicalStyle, setParagraphAttributes, styleChanged |
Methods inherited from class javax.swing.text.AbstractDocument |
addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface javax.swing.text.Document |
addUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, putProperty, remove, removeUndoableEditListener, render |
styles
public static javax.swing.text.StyleContext styles
defaultStyle
public static javax.swing.text.Style defaultStyle
inputStyle
public static javax.swing.text.Style inputStyle
redStyle
public static javax.swing.text.Style redStyle
outputMark
public int outputMark
- The offset where output from process is inserted.
endMark
public int endMark
- End of pending input.
If
endMark > 0
then the area between outputMark and endMark
is pending input that hasn't been sent to the process yet.
ReplDocument
public ReplDocument(Language language,
Environment penvironment,
boolean shared)
deleteOldText
public void deleteOldText()
- Delete old text, prior to line containing outputMark.
insertString
public void insertString(int pos,
java.lang.String str,
javax.swing.text.AttributeSet style)
- Specified by:
insertString
in interface javax.swing.text.Document
- Overrides:
insertString
in class javax.swing.text.AbstractDocument
write
public void write(java.lang.String str,
javax.swing.text.AttributeSet style)
- Insert output from the client at the outputMark.
Done indirectly, using SwingUtilities.invokeLater, so it can and should
should be called by user threads, not the event thread.
checkingPendingInput
public void checkingPendingInput()
- Check if there is any pending input.
Can and should be called by user threads, not the event thread.
The tricky aspect is supporting type-ahead and other multi-line input,
since we want prompts and other output to be properly interleaved.
focusGained
public void focusGained(java.awt.event.FocusEvent e)
- Specified by:
focusGained
in interface java.awt.event.FocusListener
focusLost
public void focusLost(java.awt.event.FocusEvent e)
- Specified by:
focusLost
in interface java.awt.event.FocusListener
changedUpdate
public void changedUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
changedUpdate
in interface javax.swing.event.DocumentListener
insertUpdate
public void insertUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
insertUpdate
in interface javax.swing.event.DocumentListener
removeUpdate
public void removeUpdate(javax.swing.event.DocumentEvent e)
- Specified by:
removeUpdate
in interface javax.swing.event.DocumentListener
textValueChanged
public void textValueChanged(javax.swing.event.DocumentEvent e)
addDocumentCloseListener
public void addDocumentCloseListener(ReplDocument.DocumentCloseListener listener)
- Register a DocumentCloseListener.
removeDocumentCloseListener
public void removeDocumentCloseListener(ReplDocument.DocumentCloseListener listener)