Package org.beryx.textio.swing
Class SwingTextTerminal
- java.lang.Object
-
- org.beryx.textio.AbstractTextTerminal<SwingTextTerminal>
-
- org.beryx.textio.swing.SwingTextTerminal
-
- All Implemented Interfaces:
TextTerminal<SwingTextTerminal>
public class SwingTextTerminal extends AbstractTextTerminal<SwingTextTerminal>
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_FONT_SIZEstatic java.awt.ColorDEFAULT_INPUT_COLORstatic java.awt.ColorDEFAULT_PANE_BACKGROUNDstatic java.awt.ColorDEFAULT_PROMPT_COLOR-
Fields inherited from class org.beryx.textio.AbstractTextTerminal
DEFAULT_USER_INTERRUPT_KEY, SYSPROP_PROPERTIES_FILE_LOCATION
-
-
Constructor Summary
Constructors Constructor Description SwingTextTerminal()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()This method is typically called when a text-based input/output session has been aborted by the user or when a severe error occurred.voidappendToInput(java.lang.String message, boolean preserveCaretPosition)voiddisplay()voiddispose(java.lang.String resultData)This method is typically called at the end of a text-based input/output session in order to allow the terminal to release its screen resources.intgetBookmarkOffset(java.lang.String bookmark)static java.util.Optional<java.awt.Color>getColor(java.lang.String colorName)javax.swing.text.StyledDocumentgetDocument()javax.swing.JFramegetFrame()java.lang.StringgetPartialInput()javax.swing.JScrollPanegetScrollPane()java.lang.StringgetStyle(org.beryx.textio.swing.SwingTextTerminal.StyleData styleData)javax.swing.JTextPanegetTextPane()booleanmoveToLineStart()Moves the cursor to the start of the current line of text in order to allow overwriting the current line.voidprintln()Terminates the current line by writing the line separator string.voidrawPrint(java.lang.String message)Prints the message in its raw form.java.lang.Stringread(boolean masking)Reads a line of textbooleanregisterHandler(java.lang.String keyStroke, java.util.function.Function<SwingTextTerminal,ReadHandlerData> handler)Associates a key combination to a handler.booleanregisterUserInterruptHandler(java.util.function.Consumer<SwingTextTerminal> handler, boolean abortRead)Registers a handler that will be called in response to a user interrupt.voidreplaceInput(java.lang.String message, boolean preserveCaretPosition)booleanresetLine()Clears the current line of text.booleanresetToBookmark(java.lang.String bookmark)Clears the text after the given bookmark.booleanresetToOffset(int offset)booleansetBookmark(java.lang.String bookmark)Sets a bookmark with the given name at the current position.voidsetInputBackgroundColor(java.lang.String colorName)voidsetInputBold(boolean bold)voidsetInputColor(java.lang.String colorName)voidsetInputFontFamily(java.lang.String fontFamily)voidsetInputFontSize(int fontSize)voidsetInputItalic(boolean italic)voidsetInputSubscript(boolean subscript)voidsetInputSuperscript(boolean superscript)voidsetInputUnderline(boolean underline)voidsetPaneBackgroundColor(java.lang.String colorName)voidsetPaneIconFile(java.lang.String filePath)voidsetPaneIconResource(java.lang.String res)voidsetPaneIconUrl(java.lang.String url)voidsetPaneTitle(java.lang.String newTitle)voidsetPromptBackgroundColor(java.lang.String colorName)voidsetPromptBold(boolean bold)voidsetPromptColor(java.lang.String colorName)voidsetPromptFontFamily(java.lang.String fontFamily)voidsetPromptFontSize(int fontSize)voidsetPromptItalic(boolean italic)voidsetPromptSubscript(boolean subscript)voidsetPromptSuperscript(boolean superscript)voidsetPromptUnderline(boolean underline)voidsetUserInterruptKey(java.lang.String keyStroke)voidsetUserInterruptKey(javax.swing.KeyStroke keyStroke)protected voidupdateScrollPaneSize(boolean pack)-
Methods inherited from class org.beryx.textio.AbstractTextTerminal
addDefaultProperty, getDefaultProperties, getProperties, getPropertiesPrefixes, getPropertiesReader, init, initProperties, initProperties, initProperties
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.beryx.textio.TextTerminal
applyWithPropertiesConfigurator, dispose, executeWithPropertiesConfigurator, executeWithPropertiesPrefix, print, print, printf, printf, println, println, rawPrint
-
-
-
-
Field Detail
-
DEFAULT_FONT_SIZE
public static final int DEFAULT_FONT_SIZE
- See Also:
- Constant Field Values
-
DEFAULT_PANE_BACKGROUND
public static final java.awt.Color DEFAULT_PANE_BACKGROUND
-
DEFAULT_PROMPT_COLOR
public static final java.awt.Color DEFAULT_PROMPT_COLOR
-
DEFAULT_INPUT_COLOR
public static final java.awt.Color DEFAULT_INPUT_COLOR
-
-
Method Detail
-
getFrame
public javax.swing.JFrame getFrame()
-
getTextPane
public javax.swing.JTextPane getTextPane()
-
getScrollPane
public javax.swing.JScrollPane getScrollPane()
-
getDocument
public javax.swing.text.StyledDocument getDocument()
-
appendToInput
public void appendToInput(java.lang.String message, boolean preserveCaretPosition)
-
replaceInput
public void replaceInput(java.lang.String message, boolean preserveCaretPosition)
-
getPartialInput
public java.lang.String getPartialInput()
-
read
public java.lang.String read(boolean masking)
Description copied from interface:TextTerminalReads a line of text- Parameters:
masking- true, if the input should be masked (for example to enter a password)- Returns:
- the entered text
-
println
public void println()
Description copied from interface:TextTerminalTerminates the current line by writing the line separator string.
-
rawPrint
public void rawPrint(java.lang.String message)
Description copied from interface:TextTerminalPrints the message in its raw form. This method expects a single line of text. The behavior is undefined if the string contains line separators.
-
resetLine
public boolean resetLine()
Description copied from interface:TextTerminalClears the current line of text. Since not all terminals support this feature, the default implementation callsTextTerminal.println()and returns false.- Returns:
- true, if the terminal supports this feature and the current line has been successfully cleared.
-
moveToLineStart
public boolean moveToLineStart()
Description copied from interface:TextTerminalMoves the cursor to the start of the current line of text in order to allow overwriting the current line. Since not all terminals support this feature, the default implementation callsTextTerminal.println()and returns false.- Returns:
- true, if the terminal supports this feature and the cursor has been moved to the start of the current line.
-
setBookmark
public boolean setBookmark(java.lang.String bookmark)
Description copied from interface:TextTerminalSets a bookmark with the given name at the current position. The bookmark name can be subsequently used in a call toTextTerminal.resetToBookmark(String)in order to clear the text after this bookmark. If a bookmark with this name already exists, it will be overwritten. Since not all terminals support this feature, the default implementation does nothing and returns false.- Returns:
- true, if the terminal supports bookmarking and the bookmark has been successfully set.
-
resetToBookmark
public boolean resetToBookmark(java.lang.String bookmark)
Description copied from interface:TextTerminalClears the text after the given bookmark. The bookmark name can be subsequently used in a call toTextTerminal.resetToBookmark(String)in order to clear the text after this bookmark. Since not all terminals support this feature, the default implementation callsTextTerminal.println()and returns false.- Returns:
- true, if the terminal supports bookmarking, the given bookmark exists and the text after it has been successfully cleared.
-
getBookmarkOffset
public int getBookmarkOffset(java.lang.String bookmark)
-
resetToOffset
public boolean resetToOffset(int offset)
-
display
public void display()
-
dispose
public void dispose(java.lang.String resultData)
Description copied from interface:TextTerminalThis method is typically called at the end of a text-based input/output session in order to allow the terminal to release its screen resources. The terminal should be able to rebuild the released resources when a print or read method is subsequently called. The default implementation does nothing.- Parameters:
resultData- stringified information about the outcome of the input/output session; may be null,
-
abort
public void abort()
Description copied from interface:TextTerminalThis method is typically called when a text-based input/output session has been aborted by the user or when a severe error occurred. The default implementation does nothing.
-
registerUserInterruptHandler
public boolean registerUserInterruptHandler(java.util.function.Consumer<SwingTextTerminal> handler, boolean abortRead)
Description copied from interface:TextTerminalRegisters a handler that will be called in response to a user interrupt. The event that triggers a user interrupt is usually Ctrl+C, but in general it is terminal specific. For example, a Swing based terminal may send a user interrupt when the X close button of its window is hit. Since not all terminals support this feature, the default implementation just returns false.- Parameters:
handler- the action to be performed in response to a user interrupt.abortRead- true, if the current read operation should be aborted on user interrupt.- Returns:
- true, if the terminal supports this feature and the handler has been registered; false, otherwise.
-
setUserInterruptKey
public void setUserInterruptKey(javax.swing.KeyStroke keyStroke)
-
setUserInterruptKey
public void setUserInterruptKey(java.lang.String keyStroke)
-
registerHandler
public boolean registerHandler(java.lang.String keyStroke, java.util.function.Function<SwingTextTerminal,ReadHandlerData> handler)Description copied from interface:TextTerminalAssociates a key combination to a handler. Since not all terminals support this feature, the default implementation just returns false.- Parameters:
keyStroke- the key combination associated with the handler. It should have the same format as the argument ofKeyStroke.getKeyStroke(String).handler- the action to be performed when thekeyStrokeis detected during a read operation.- Returns:
- true, if the terminal supports this feature and the handler has been associated with the given key combination; false, otherwise.
-
getStyle
public java.lang.String getStyle(org.beryx.textio.swing.SwingTextTerminal.StyleData styleData)
-
setPromptColor
public void setPromptColor(java.lang.String colorName)
-
setPromptBackgroundColor
public void setPromptBackgroundColor(java.lang.String colorName)
-
setPromptFontFamily
public void setPromptFontFamily(java.lang.String fontFamily)
-
setPromptFontSize
public void setPromptFontSize(int fontSize)
-
setPromptBold
public void setPromptBold(boolean bold)
-
setPromptItalic
public void setPromptItalic(boolean italic)
-
setPromptUnderline
public void setPromptUnderline(boolean underline)
-
setPromptSubscript
public void setPromptSubscript(boolean subscript)
-
setPromptSuperscript
public void setPromptSuperscript(boolean superscript)
-
setInputColor
public void setInputColor(java.lang.String colorName)
-
setInputBackgroundColor
public void setInputBackgroundColor(java.lang.String colorName)
-
setInputFontFamily
public void setInputFontFamily(java.lang.String fontFamily)
-
setInputFontSize
public void setInputFontSize(int fontSize)
-
setInputBold
public void setInputBold(boolean bold)
-
setInputItalic
public void setInputItalic(boolean italic)
-
setInputUnderline
public void setInputUnderline(boolean underline)
-
setInputSubscript
public void setInputSubscript(boolean subscript)
-
setInputSuperscript
public void setInputSuperscript(boolean superscript)
-
setPaneBackgroundColor
public void setPaneBackgroundColor(java.lang.String colorName)
-
setPaneTitle
public void setPaneTitle(java.lang.String newTitle)
-
setPaneIconUrl
public void setPaneIconUrl(java.lang.String url)
-
setPaneIconFile
public void setPaneIconFile(java.lang.String filePath)
-
setPaneIconResource
public void setPaneIconResource(java.lang.String res)
-
updateScrollPaneSize
protected void updateScrollPaneSize(boolean pack)
-
getColor
public static java.util.Optional<java.awt.Color> getColor(java.lang.String colorName)
-
-