public abstract class Editor<O extends OutputManager<?>> extends LabeledDataContainer<O,EditorConfig> implements TextSelection
Besides what was known from Progress manuals, the following facts describe some peculiarities in the redirected output found experimentally:
Modifier and Type | Class and Description |
---|---|
protected static class |
Editor.Line
Internal text representation element.
|
protected class |
Editor.LocalFocusListener
Some actions on focus hanging.
|
Widget.ZOrderClass
Modifier and Type | Field and Description |
---|---|
protected static char |
CR
Carrage return character.
|
protected boolean |
forceRedraw
Flag indicating if the processed event forced a re-draw.
|
protected boolean |
insert
Insert mode.
|
protected static char |
LF
line feed character
|
private static int |
MAX_SIZE
Maximum capacity of the editor.
|
protected static java.util.Map<java.lang.Integer,java.lang.Integer> |
maxSizes
Max data size in widget.
|
protected java.util.List<Editor.Line> |
parsedText
Editor content parsed into separate string.
|
private static java.util.regex.Pattern |
RTRIM
trailing spaces
|
protected static java.lang.String |
SPACE
single space string
|
protected static java.lang.String |
SPACE_LF
space & lf
|
protected boolean |
widgetFocused
Widget in focus flag.
|
config
location, mousePtr, nativeInsets, physicalLocation
Constructor and Description |
---|
Editor(WidgetId id,
EditorConfig cfg)
Special constructor used to restore component using given configuration.
|
Modifier and Type | Method and Description |
---|---|
protected abstract int |
absoluteX()
Get absolute horizontal position in text.
|
protected int |
absoluteY()
Get absolute vertical position in text.
|
protected void |
backspace()
Handle BACKSPACE key.
|
protected void |
bell()
Handle BELL event.
|
protected boolean |
canPlaceChar()
Determine if a character can be placed in the editor.
|
void |
clear()
Clear input variable.
|
int |
contentLength()
Gets the actual content length (not the LENGTH attribute).
|
Widget<O> |
currentFocus()
Returns this component directly because it is not a container (it has no child
components.
|
protected void |
cursorBeginOfLine()
Move cursor to beginning of the line.
|
protected void |
cursorDown()
Move cursor one row down, if possible.
|
protected void |
cursorEndOfLine()
Move cursor to the end of line.
|
protected void |
cursorEndOfPrevLine()
Move the cursor to the end of the previous line.
|
protected void |
cursorHome()
Move cursor to the start position.
|
protected void |
cursorLeft()
Move cursor one char left, if possible.
|
private void |
cursorPageDown()
Scroll one page down.
|
private void |
cursorPageUp()
Scroll one page up.
|
protected void |
cursorPos(int pos)
Split absolute horizontal cursor position into two components - position
of the first visible character and relative cursor position in the
visible region.
|
protected void |
cursorRight()
Move cursor one char right.
|
protected void |
cursorUp()
Move cursor one row up, if possible.
|
Widget<O> |
defaultFocus()
Returns this component directly because it is not a container (it has no child
components.
|
protected boolean |
deleteCharacter()
Delete character at current cursor position.
|
protected void |
deleteCharacterKey()
Delete character at current cursor position - called by
processKeyEvent(com.goldencode.p2j.ui.client.event.KeyInput) . |
boolean |
deleteLine()
Delete the line of text in which the cursor currently resides.
|
private boolean |
deleteLineWorker()
Delete the line of text in which the cursor currently resides.
|
protected boolean |
deleteToEndOfLine()
Delete to end of line.
|
void |
draw()
Draws text.
|
abstract void |
draw(Color color)
Actual drawing routine.
|
void |
drawCaret()
Sets position of terminal's cursor.
|
abstract void |
drawCaretUnconditionally()
Sets position of terminal's cursor unconditionally (even if this editor is not in focus).
|
boolean |
editorReadFile(java.lang.String name)
Loads the file from the client side filesystem.
|
boolean |
editorSaveFile(java.lang.String name)
Save the content in the widgets in the client side filesystem.
|
private int |
findRow(int pos)
Find row number for a position
|
boolean |
focusTraversable()
This component will receive an input focus when Tab or Shift-Tab is
pressed.
|
int |
fullHeight()
Returns the number of lines the editor is holding.
|
int |
getCursorChar()
Gets the cursor in the current line
|
int |
getCursorLine()
Gets the cursor liner
|
int |
getCursorOffset()
Gets the cursor offset
|
protected FocusListener |
getFocusListener()
Get the focus listener instance.
|
int |
getLength()
Gets the content length, compatible with the LENGTH attribute.
|
protected Editor.Line |
getLine()
Get reference to the line under absolute cursor position.
|
int |
getLineCount()
Obtain the number of current lines displayed (parsed) by this editor.
|
java.lang.String |
getLineText(int k)
Obtain the text displayed on a specified line.
|
protected abstract int |
getNextSplitPosition(java.lang.String line,
int splitAfter)
Get the next split position of this line, so that it fits the editor.
|
java.lang.String |
getText()
Get screen representation of the data.
|
BaseDataType |
getValue()
Getting the BaseDataType object representing the current value.
|
protected abstract boolean |
goToNewLine(java.lang.String subtext,
boolean placeChar)
Check if the given text needs to output on a new line.
|
void |
initialize(WidgetId id,
EditorConfig cfg)
Replacement API for the logic which should exist in the widget's c'tor, but the logic
can't be executed as it depends on the widget being registered into the official registry.
|
private int |
inSameLime(int start,
int end)
Check if there are now LFs between positions
|
protected abstract boolean |
insertBlankLineOnLF()
Determine if a blank line needs to be inserted when RETURN key is pressed on a empty line.
|
boolean |
insertFile(java.lang.String fileNameToLoad)
Inserts content of a file at the current cursor position.
|
boolean |
insertString(java.lang.String txt)
Inserts string at the current cursor position.
|
protected int |
lastRow()
Maximal value of the absolute Y coordinate.
|
boolean |
manageSystemActions()
Check if the current widget can manage non-global system actions on its own, and not via the
enclosing event loop.
|
protected abstract void |
mergeLines(int row)
Merge line with subsequent one(s) if possible
|
protected void |
parseContent(java.lang.String source,
int row,
boolean placeChar)
Parse content of the editor and prepare array of displayable values.
|
protected java.util.List<Editor.Line> |
parseContentImpl(java.lang.String source,
int start,
int offset,
boolean placeChar)
Worker to parse content of the editor and prepare array of displayable values.
|
protected void |
placeChar(char ch)
Place character at current cursor position.
|
protected void |
placeLF()
Place new line character at current cursor position.
|
protected abstract java.lang.String |
processEOLChars(java.lang.String src)
Processing for unusual EOL characters in different UI modes.
|
void |
processKeyEvent(KeyInput ke)
Process KeyEvents for this widget.
|
protected void |
refresh()
Refresh the editor.
|
private boolean |
replaceInterval(int start,
int end,
java.lang.String txt)
Replace subinterval of the editor content
|
boolean |
replaceSelectionText(java.lang.String txt)
Replace selection of the editor content with a given string.
|
boolean |
replaceString(java.lang.String from,
java.lang.String to,
int flag)
Replace given substring of the editor content with a given string
|
void |
requestFocus()
Requesting the focus to the widget.
|
protected java.lang.String |
resolveContent()
Get a string representation of this editor's content.
|
protected java.lang.String |
rtrim(java.lang.String value)
Remove trailing whitespaces
|
java.lang.Boolean |
search(java.lang.String pattern,
int mode)
Searches for a specified string starting from the current text caret position.
|
boolean |
setCursorChar(int pos)
Sets the cursor position in the current line
|
boolean |
setCursorChar(int pos,
boolean redraw)
Sets the cursor position in the current line
|
boolean |
setCursorLine(int line)
Sets the cursor line
|
protected boolean |
setCursorLineAndChar(int line,
int offset)
Sets the cursor line offset
|
boolean |
setCursorOffset(int offset)
Sets the cursor offset.
|
boolean |
setSelection(int start,
int end)
Selects text in a widget between start and end points.
|
void |
setValue(BaseDataType value)
Sets the new variable value in the editor.
|
protected void |
splitLine(java.lang.String line,
int row,
int splitAfter)
Replace line, splitting it if necessary
|
protected void |
updateOffset()
Update widget content;
|
afterConfigUpdate, config, defaultMousePtr, destroy, getColon, getColumnLabelText, getColumnMnemonic, getLabelInstance, getLabelText, getMnemonic, getTo, isForceLabel, isModified, isNoLabels, isRightAligned, postprocessConfig, setColumnMnemonic, setHidden, setLabelInstance, setMnemonic, setNoLabels, setVisible, setWasVisible, wasVisible
minimumSize
add, add, add, addDirectly, belongsTo, checkWidget, childrenLocation, clipping, clipRectangle, currentFocus, cycleFocus, detach, dimension, doLayout, endSizeChange, findMouseSource, firstFocus, focus, focusWorker, get, getClipRect, getEffectiveScrollableSize, getFocusInt, getIgnoreFocus, getLayout, getScrollableSize, getWidgetsList, hasFocusable, height, insets, lastFocus, moveAfterTabItem, moveBeforeTabItem, moveToBottom, moveToBottomInClass, moveToTop, moveToTopInClass, moveToZpos, nextFocus, normalizeZOrder, prepareWidgets, prevFocus, remove, repaint, replace, setFocus, setFocusInt, setHeight, setIgnoreFocus, setInsets, setLayout, setSize, setSize, setWidth, startSizeChange, unrealize, updateSizeWorker, widgets, width
_setHidden, _setVisible, activateDirectManipulation, addFocusListener, addKeyListener, afterConfigUpdateBase, ancestor, ancestorId, autoResize, bounds, clear, clearWidget, clipRectangle, clipRectangle, clipWith, createMouseHoverAction, deactivateDirectManipulation, debug, disable, displayPhysicalLocation, enable, enclosingFrame, forceCursorOnFocus, forceVisibility, getActualBounds, getAndResetBitmap, getAndSetBitmap, getBitmapCopy, getCustomMousePointer, getDefaultEvent, getEffectiveMousePointer, getId, getLoadedMousePointer, getMenuMouse, getMouseActions, getPortableMouseEventCoordinates, getSelectedText, getState, getTextHeight, getTextHeightNative, getTextWidth, getTextWidthNative, getVisiblePart, getZOrderClass, hasFocus, hidden, hide, highlighted, ignoreAction, isDirectManipulationCapable, isDirectManipulationRequired, isDisplayed, isEnabled, isFocusable, isHeader, isRealized, isRMBEntrySupported, isTabStop, isThreeD, isTotallyObscured, isVisible, location, mouseActions, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, moveToBottom, moveToTop, name, navigable, parent, parent, parentOrSelf, physicalBounds, physicalDimension, physicalLocation, prepParentLocation, processDirectManipulationEvent, processEvent, processFocusEvent, processKeyListeners, processMnemonic, processMnemonicImpl, processSystemKey, raiseLegacyMouseEvents, refresh, registerWidgetStateListener, repaint, requestSync, resetBitmap, resizeTo, resolveFont, resolveTitleFont, screen, screenDimension, screenHeight, screenLocation, screenPhysicalLocation, screenWidth, setBitmap, setEnabled, setHighlighted, setLocation, setLocation, setMousePointer, setParent, setPhysicalLocation, setState, show, supportsCustomMousePointer, sync, topLevelWindow, toString, translate, window
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
invalidateSelection, isSelectionValid, removeSelectedText
addFocusListener, addKeyListener, ancestor, ancestorId, bounds, clearWidget, dimension, displayPhysicalLocation, enclosingFrame, enforceDefaultMousePtr, findMouseSource, forceCursorOnFocus, forceVisibility, getActualBounds, getCustomMousePointer, getEffectiveMousePointer, getId, getLegacyWidget, getLoadedMousePointer, getMenuMouse, getMouseActions, getSelectedText, getState, getVisiblePart, getZOrderClass, hasFocus, height, hidden, hide, highlighted, insets, isDirectManipulable, isDisplayed, isEnabled, isFocusable, isHeader, isRealized, isRMBEntrySupported, isTabStop, isThreeD, isTotallyObscured, isVisible, location, minimumSize, moveToBottom, moveToTop, name, navigable, parent, parent, parentOrSelf, physicalBounds, physicalDimension, physicalLocation, processDirectManipulationEvent, processEvent, processFocusEvent, processKeyListeners, processMnemonic, raiseLegacyMouseEvents, repaint, repaint, requestSync, resizeTo, screen, screenLocation, screenPhysicalLocation, setEnabled, setHighlighted, setLocation, setLocation, setMousePointer, setParent, setPhysicalLocation, setState, show, supportsCustomMousePointer, topLevelWindow, unrealize, width, window
mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased
createMnemonic, getMnemonicCharacter, getMnemonicKeyCode, getMnemonicLabel, isMnemonicSupported, updateMnemonic
protected static final char LF
protected static final char CR
protected static final java.lang.String SPACE
protected static final java.lang.String SPACE_LF
private static final java.util.regex.Pattern RTRIM
protected java.util.List<Editor.Line> parsedText
protected boolean widgetFocused
protected static final java.util.Map<java.lang.Integer,java.lang.Integer> maxSizes
protected boolean insert
protected boolean forceRedraw
private static int MAX_SIZE
public Editor(WidgetId id, EditorConfig cfg)
Call initialize(com.goldencode.p2j.ui.WidgetId, com.goldencode.p2j.ui.EditorConfig)
to finish the widget initialization.
id
- The widget's ID.cfg
- Configuration data.public abstract void drawCaretUnconditionally()
public abstract void draw(Color color)
color
- Color for drawing.protected abstract boolean goToNewLine(java.lang.String subtext, boolean placeChar)
subtext
- The text.placeChar
- flag indicating if this call is from placeChar(char)
.true
if the text will output on a new line.protected abstract boolean insertBlankLineOnLF()
protected abstract void mergeLines(int row)
row
- line's rowprotected abstract int getNextSplitPosition(java.lang.String line, int splitAfter)
line
- The line to be split.splitAfter
- minimal split position.protected abstract int absoluteX()
protected abstract java.lang.String processEOLChars(java.lang.String src)
src
- the string to be processed.public boolean editorReadFile(java.lang.String name)
name
- The file name for the file to be loaded.TRUE
if operation successful FALSE
otherwise.public boolean editorSaveFile(java.lang.String name)
name
- The file name for the file to be written.TRUE
if operation successful FALSE
otherwise.public void initialize(WidgetId id, EditorConfig cfg)
This API is called after the widget is created and added to the registry.
initialize
in interface WidgetWithConfig<EditorConfig>
id
- The widget's ID.cfg
- The config used to initialize this widget.public BaseDataType getValue()
getValue
in interface DataContainer
public void requestFocus()
requestFocus
in interface Widget<O extends OutputManager<?>>
requestFocus
in class FixedSizeContainer<O extends OutputManager<?>>
public void drawCaret()
drawCaret
in interface Widget<O extends OutputManager<?>>
drawCaret
in class AbstractWidget<O extends OutputManager<?>>
public void draw()
DisplayFormat.Presentation
instance is
rendered into screen value. Screen value is left justified or padded to
the right bound with spaces. Non first lines are filled with spaces. If
widget is focused then after rendering terminal's cursor is set to
appropriate position in the widget.draw
in interface Widget<O extends OutputManager<?>>
draw
in class AbstractContainer<O extends OutputManager<?>>
protected void refresh()
public java.lang.String getText()
getText
in interface DataContainer
public void clear()
public boolean focusTraversable()
focusTraversable
in interface Widget<O extends OutputManager<?>>
focusTraversable
in class AbstractContainer<O extends OutputManager<?>>
true
if this component is enabled and visible.public Widget<O> currentFocus()
currentFocus
in interface Container<O extends OutputManager<?>>
currentFocus
in class AbstractContainer<O extends OutputManager<?>>
Container.currentFocus()
public Widget<O> defaultFocus()
defaultFocus
in interface Container<O extends OutputManager<?>>
defaultFocus
in class AbstractContainer<O extends OutputManager<?>>
Container.defaultFocus()
public void setValue(BaseDataType value)
setValue
in interface DataContainer
value
- New value for the screen buffer.public void processKeyEvent(KeyInput ke)
processKeyEvent
in interface Widget<O extends OutputManager<?>>
processKeyEvent
in class AbstractContainer<O extends OutputManager<?>>
ke
- Key event structure.public boolean deleteLine()
true
if the line was deleted.public boolean setSelection(int start, int end)
setSelection
in interface TextSelection
start
- Starting offset.end
- Ending offset.true
if the operation succeeded.public boolean setCursorLine(int line)
line
- the new cursor line valuetrue
if the cursor line is valid and setpublic int getCursorLine()
public boolean setCursorChar(int pos)
pos
- the new cursor position valuetrue
if the cursor position is valid and setpublic boolean setCursorChar(int pos, boolean redraw)
pos
- The new cursor position value.redraw
- Request redraw/sync.true
if the cursor position is valid and set.public int getCursorChar()
public boolean setCursorOffset(int offset)
offset
- the new offset value. Use -1 to move the caret at the end (MOVE-TO-EOF).true
if the cursor offset is valid and set.protected boolean setCursorLineAndChar(int line, int offset)
line
- the new cursor line valueoffset
- the new offset valuetrue
if the cursor offset is valid and setpublic int getCursorOffset()
public int getLength()
public int contentLength()
public int getLineCount()
public java.lang.String getLineText(int k)
null
is returned.k
- The line whose text is requested.k
line (0-base).public boolean insertString(java.lang.String txt)
txt
- The string to be inserted.true
if the string is inserted.public boolean insertFile(java.lang.String fileNameToLoad)
fileNameToLoad
- The file to be inserted.true
if the file was successfully inserted.public boolean replaceSelectionText(java.lang.String txt)
txt
- the replacement stringtrue
if the selection is replacedprivate boolean replaceInterval(int start, int end, java.lang.String txt)
start
- start of the intervalend
- end of the intervaltxt
- replacement texttrue
if replacement done.public boolean replaceString(java.lang.String from, java.lang.String to, int flag)
from
- the string to be replacedto
- the replacement stringflag
- the replacement mode flag as described in 4GL EDITOR:REPLACE documentationtrue
if the replacement was performedpublic java.lang.Boolean search(java.lang.String pattern, int mode)
pattern
- The string to be search. No wildcard allowed.mode
- a combinations of flags that specifies the type of search to be performed. The
following values are accepted:
Type of search | Flag value |
---|---|
EditorWidget.FIND_NEXT_OCCURRENCE | 1 |
EditorWidget.FIND_PREV_OCCURRENCE | 2 |
EditorWidget.FIND_CASE_SENSITIVE | 4 |
EditorWidget.FIND_WRAP_AROUND | 16 |
EditorWidget.FIND_SELECT | 32 |
false
. Objects that extends it will
implement their search and return the result accordingly.private int findRow(int pos)
pos
- positionprivate int inSameLime(int start, int end)
start
- first positionend
- second positionpublic boolean manageSystemActions()
manageSystemActions
in class AbstractWidget<O extends OutputManager<?>>
true
as the widget has its own event management.private void cursorPageUp()
private void cursorPageDown()
private boolean deleteLineWorker()
true
if anything is deleted.protected int lastRow()
public int fullHeight()
protected void cursorBeginOfLine()
protected boolean deleteToEndOfLine()
true
if text was deleted.protected void bell()
protected void backspace()
protected void cursorEndOfPrevLine()
protected void cursorHome()
protected void cursorEndOfLine()
protected Editor.Line getLine()
Line
at current position.protected void cursorPos(int pos)
pos
- The new absolute cursor position.protected void cursorDown()
protected void cursorUp()
protected void cursorRight()
protected void cursorLeft()
protected void placeLF()
protected boolean canPlaceChar()
true
if the editor is not read-only.protected void placeChar(char ch)
ch
- Character to place.protected void splitLine(java.lang.String line, int row, int splitAfter)
line
- line's contentrow
- line's rowsplitAfter
- minimal split positionprotected int absoluteY()
protected void deleteCharacterKey()
processKeyEvent(com.goldencode.p2j.ui.client.event.KeyInput)
.protected final boolean deleteCharacter()
true
if something was deleted.protected void parseContent(java.lang.String source, int row, boolean placeChar)
source
- Source string to parse.row
- Row index to start parsing from.placeChar
- Set to true
if called from placeChar(char)
method in insert mode.protected java.util.List<Editor.Line> parseContentImpl(java.lang.String source, int start, int offset, boolean placeChar)
Sub-classes can override this, to i.e. use cached metrics.
source
- Source string to parse.start
- Row index to start parsing from.offset
- Text offset to start parsing from.placeChar
- Set to true
if called from placeChar(char)
method in insert mode.protected final java.lang.String resolveContent()
protected FocusListener getFocusListener()
protected java.lang.String rtrim(java.lang.String value)
value
- the string to be truncatedprotected void updateOffset()