ewe.ui
Class mTextPad

java.lang.Object
  extended byewe.ui.ControlBase
      extended byewe.ui.Control
          extended byewe.ui.EditControl
              extended byewe.ui.mTextPad
All Implemented Interfaces:
CellConstants, ControlConstants, EventListener, ImageRefresher, IScroll, ScrollClient, Selectable, TimerProc, UIConstants
Direct Known Subclasses:
TextDisplay

public class mTextPad
extends EditControl
implements ScrollClient, Selectable

You should use this instead of mTextArea. This is a multi-line text editor which has the ability to wrap lines to fit the display. This control is designed to be able to be the base class for a full text editor (e.g. a NotePad).


Field Summary
 boolean allowOverwrite
          If this is true (which it is by default) then the user will be allowed to switch between overwrite and insert mode using the INS key.
protected  boolean amScrolling
           
 IImage backgroundImage
           
protected static ImageBuffer blockBuffer
           
 int charWidth
          This is used to estimate line lengths.
protected  ewe.ui.textPadState curState
           
 boolean disableCursor
          Set this true to disable the cursor.
 boolean disableTextChanges
          Set this true to disable any text changes.
protected  DisplayLineSpecs dls
           
 boolean dontWantPopup
          This is false by default.
 int extraLineSpacing
          This is extra spacing placed between lines.
 int forcedActualWidth
          Set this to be a non-zero value to have a specific document width (in pixels), regardless of the length of the lines being displayed.
 FormattedTextSpecs format
          This can be used to alter things like the tab stop width.
 int inputState
          This is used to determine the state of the input.
protected static ImageBuffer itemBuffer
           
 int leftMargin
          This is the left margin.
protected  int lineHeight
           
protected  DisplayLine lines
           
 int minXScroll
          A percent figure.
 int minYScroll
          A percent figure.
protected  int numLines
           
 int rightMargin
          This is the right margin.
 boolean selectAllOnFocus
          If this is true the entire text is selected when it gains focus.
 int spacing
           
static int STATE_AUTOTAB
          This is used with the inputState variable to indicate auto-tab mode.
static int STATE_OVERWRITE
          This is used with the inputState variable to indicate overwrite mode (as opposed to insert mode).
 boolean wantReturn
          This is true by default.
 boolean wrapToScreenSize
          This is true by default - it tells the control to wrap lines to fit the display.
 
Fields inherited from class ewe.ui.EditControl
blinkId, CASE_LOWER, CASE_NORMAL, CASE_NUMBERS, CASE_SENTENCE, CASE_UPPER, colors, conditionalChar, conditionalCharIndex, doingLocalInput, doingNativeInput, FLAG_INPUT_ON_FOCUS, FLAG_KEEP_FOCUS_AFTER_INPUT, FLAG_PASSIVE, FLAG_USE_NATIVE, inFocus, inputFlags, inputMethod, justGotFocus, oldText, pageColor, startNativeOnPaint, textCase, validator
 
Fields inherited from class ewe.ui.Control
_debug, backGround, beforeRemoved, borderColor, borderStyle, borderWidth, children, columns, constraints, DoPaintMethod, dragging, dragResolution, dragTime, exitKeys, fieldTransfer, font, foreGround, haveNativePaint, height, holdDownPause, holdTick, hotKey, image, lastSelected, listeners, maxHeight, maxWidth, menuState, minHeight, minWidth, modifiers, MyClass, name, next, np, parent, penStatus, popupSound, popupSoundClip, preferredHeight, preferredWidth, prev, prompt, promptControl, rows, ss, standardBorder, standardEdge, startDragResolution, tags, tail, text, toolTip, width, x, y
 
Fields inherited from class ewe.ui.ControlBase
clipItems, clipObject, clipOwner, curPoint, currentPenEvent, debugControl, debugFlag, DidHoldDown, doubleBuffer, doubleClickTime, firstPress, globalDrawFlat, globalEditable, globalEnabled, globalPalmStyle, globalSmallControls, GotPenDown, PenIsOn, TAG_LAST_USER_DATA, TAG_USER_DATA, TAKE_FIRST_PRESS, unnamed, useNativeTextInput
 
Fields inherited from interface ewe.ui.IScroll
Higher, Horizontal, Lower, OPTION_INDICATOR_ONLY, PageHigher, PageLower, ScrollHigher, ScrollLower, TrackTo, Vertical
 
Fields inherited from interface ewe.ui.UIConstants
BDR_DOTTED, BDR_INNER, BDR_NOBORDER, BDR_OUTER, BDR_OUTLINE, BDR_RAISEDINNER, BDR_RAISEDOUTER, BDR_SUNKENINNER, BDR_SUNKENOUTER, BF_BOTTOM, BF_BOTTOMLEFT, BF_BOTTOMRIGHT, BF_BUTTON, BF_DIAGONAL, BF_DIAGONAL_ENDBOTTOMLEFT, BF_DIAGONAL_ENDBOTTOMRIGHT, BF_DIAGONAL_ENDTOPLEFT, BF_DIAGONAL_ENDTOPRIGHT, BF_EXACT, BF_FLAT, BF_LEFT, BF_MIDDLE, BF_MONO, BF_PALM, BF_RECT, BF_RIGHT, BF_SOFT, BF_SQUARE, BF_TOP, BF_TOPLEFT, BF_TOPRIGHT, EDGE_BUMP, EDGE_ETCHED, EDGE_RAISED, EDGE_SUNKEN
 
Fields inherited from interface ewe.ui.CellConstants
BORDER, BOTTOM, CELLFLAG, CELLMASK, CENTER, CONTROLMASK, DONTCHANGE, DONTFILL, DONTSTRETCH, EAST, FILL, FIXEDSIZE, GROW, HCENTER, HCONTRACT, HEXPAND, HFILL, HGROW, HSHRINK, HSTRETCH, INITIALLY_CLOSED, INITIALLY_MINIMIZED, INITIALLY_PREFERRED_SIZE, INSETS, LEFT, MAXIMUMSIZE, MINIMUMSIZE, NORTH, NORTHEAST, NORTHWEST, PREFERREDSIZE, RECT, RIGHT, SHRINK, SOUTH, SOUTHEAST, SOUTHWEST, SPAN, STRETCH, TEXTSIZE, TOP, VCENTER, VCONTRACT, VEXPAND, VFILL, VGROW, VSHRINK, VSTRETCH, WEST
 
Fields inherited from interface ewe.ui.ControlConstants
All, AlwaysEnabled, AlwaysRecalculateSizes, ByDeferredMouse, ByDeferredPen, ByFrameChange, ByKeyboard, ByMouse, ByPen, ByRequest, CalculatedSizes, Disabled, DisablePopupMenu, DisplayOnly, Down, DrawFlat, Flag, ForceResize, HasData, Invisible, KeepImage, KeepSIP, Left, MakeMenuAtLeastAsWide, Maximize, Minimize, MouseSensitive, NoFocus, NotAnEditor, NotEditable, PaintDataOnly, PaintOutsideOnly, PenTransparent, PreferredSizeOnly, Right, SendUpKeyEvents, SendUpPenEvents, ShowSIP, ShrinkToNothing, SmallControl, SpecialBackground, TakeControlEvents, TakesKeyFocus, Transparent, Up, WantDrag, WantHoldDown
 
Fields inherited from interface ewe.fx.ImageRefresher
KEEP_VISIBLE
 
Constructor Summary
mTextPad()
           
mTextPad(int rows, int columns)
           
mTextPad(String text)
           
 
Method Summary
 boolean acceptsData(Object data, DragContext how)
          This should indicate whether this control will accept the data either via a drag and drop or via a paste operation.
 DisplayLine addDisplayLine(String newLine, DisplayLine addBefore)
           
 void addDisplayLines(DisplayLine newSequence, DisplayLine addBefore)
           
 void appendText(String what, boolean moveToEnd)
           
protected  void applySpecialFormat(int formatIndex, int lineIndex, DisplayLine theLine, FormattedTextSpecs format)
           
protected  String autoTab(String currentLine, String newLine)
           
 DisplayLine breakLineBefore(DisplayLine dataLine, int index)
          This forces a line break in the specified data line immediately before the specified index.
protected  void calculateSizes()
          Override this to calculate the preferred, minimum and maximum size of your control.
 boolean canGo(int orientation, int direction, int position)
           
 void checkScrolls()
           
 boolean checkSipCoverage()
           
protected  void clearCursor()
           
 void clearSelection()
          This clears the selection but does not update the screen.
 void dataAccepted(Control by, Object theData, String action)
          This is called either when data that was cut from this control was pasted into another control, OR when data that was dragged from this control is dropped into another control.
 void dataDraggedOff(Object data)
          This is called when data that was previously dragged into the control has now been dragged off.
 void dataDraggedOver(Object data, Point p, PenEvent ev)
          This is called when data is being dragged into the control.
 boolean dataDroppedOn(Object data, Point where, DragContext dc)
          This is called by a drop from a drag and drop operation.
protected  void dataTransferCancelled(Object data)
          This gets called either when that was cut from this control was not placed into another control (either it was rejected by a paste or a subsequent copy/cut into the clipboard occured before the data was pasted) or a drag and drop was initiated but not completed.
 boolean deleteSelection()
           
 void displayLinesChanged()
           
 void doPaint(Graphics g, Rect area)
           
protected  void doPaintData(Graphics g)
          Repaint the "data" part of the Control.
protected  void doPaintData(Graphics g, Rect area)
           
 void doScroll(int which, int action, int value)
           
protected  boolean doShowMenu(Point p)
          Used to show the menu associated with the Control.
 void dragged(DragContext dc)
          This is called during the drag operation.
protected  void drawSpecialFormat(int formatIndex, int lineIndex, DisplayLine theLine, FormattedTextSpecs format, Graphics g, Color background)
           
 int ensureBlankLines(DisplayLine dataLine, int count, boolean above)
          Insert blank lines before or after the specified data line so that there are at least count number of blank lines before or after the data line.
protected  boolean fix()
           
protected  void fixText()
           
 int getActual(int which)
           
 int getAvailableWidth()
           
 int getBaselineHeight()
          Returns the height in pixels from the top of a line down to the baseline of the font.
 Point getCharAt(Point onControl)
          Get the line and character index of the character at the point specified (relative to the origin of the mTextPad).
 Point getCharAt(Point onControl, boolean bestGuess, boolean halfWay)
          Get the line and character index of the character at the point specified (relative to the origin of the mTextPad).
protected  boolean getCharRect(int ch, int ln, Rect dest)
           
 int getCurrent(int which)
           
 Point getCursorPosition()
          Get the character location of the cursor (caret).
protected  boolean getCursorRect(int ch, int ln, Rect dest)
           
 Dimension getIndexLocation(int characterIndex, Dimension dest)
          This locates the row and column index of a character from the original text in the list of DisplayLines.
 int getLeftPosition()
          Return how many pixels the display is shifted to the right.
protected  DisplayLine getLine()
           
 DisplayLine getLine(int index)
          Get the DisplayLine at the specified index.
 String getLineAt(int index)
          Get the line at the specified index.
 String getLineAt(int index, boolean trueLine)
          Get the line at the specified index.
 int getLineHeight()
          Returns the height in pixels of each line (all lines are the same height).
 int getLineLength(int index, boolean trueLength)
          Return the length of the line in characters, with or without the ending line feed.
 String[] getLines()
          Get all the lines.
 int getNumLines()
          Return the number of lines being displayed.
protected  Point getPenChar(Point onControl)
           
 int getScreenRows()
           
 ScrollablePanel getScrollablePanel()
           
 Object getSelection()
           
 Rect getSelectionRange()
          This returns the selected area, or null if there is no selection.
protected  int getSpecialFormatCount(int lineIndex, DisplayLine theLine)
           
 Object getState()
          Get an Object that can be used to restore the text display to the same state later (using setState().
 String getText()
           
 Menu getTextPadMenu(Menu addTo)
           
protected  FormattedTextSpecs getTextPositions(int lineIndex, DisplayLine line)
           
 FormattedTextSpecs getTextPositions(int lineIndex, DisplayLine line, FormattedTextSpecs format, int[] posBuffer, boolean useFormatters)
           
 int getTextWidth()
          If wrapToScreenSize is true, this returns the width of the widest word.
 int getTopLine()
          Return the index of the top line of the display in the complete list of lines.
 int getTrueCharIndex(int lineIndex, int charIndex)
          Get the index of the character in the original text, given the line index and character index on screen.
 int getTrueCharIndex(Point charPosition)
          Get the index of the character in the original text, given the line index and character index on screen.
 int getVisible(int which, int forSize)
           
 void gotFocus(int how)
           
 boolean hasSelection()
           
 void lostFocus(int how)
           
 boolean needScrollBar(int which, int forSize)
           
 boolean newCursorPos(int ch, int ln, boolean takeSel)
          This calls newCursorPos(int ch,int ln,boolean takeSel,boolean leaveSel) with leaveSel set to false.
 boolean newCursorPos(int ch, int ln, boolean takeSel, boolean leaveSel)
          This is used to move the cursor position AND update the display accordingly.
 boolean noSelection()
           
 void onEvent(Event ev)
           
 void onKeyEvent(KeyEvent ev)
           
 void onPenEvent(PenEvent ev)
          Called to handle an incoming PenEvent.
protected  boolean paintConditionalChar(Graphics g, boolean highlight)
           
 void paintCursor(Graphics gr)
           
 void paintCursor(Graphics gr, boolean sticky)
           
 void paintLastChar(Graphics g)
           
 void paintLastChar(Graphics g, char toErase)
           
 void paintLine(Graphics g, int index)
           
 void paintLine(Graphics g, int index, DisplayLine theLine)
           
 void paintLines(int from, int to)
           
protected  void paintLinesFrom(int index)
           
 void penDoubleClicked(Point where)
          Called if the Pen or Mouse button is double clicked on the Control.
 void penPressed(Point where)
          Called when the Pen or Mouse button is pressed on the control.
 void penReleased(Point where)
          Called when the Pen or Mouse button is released on the control.
protected  void popupMenuClosed(Menu m)
          This gets closed after the popup menu for the Control has closed.
 void popupMenuEvent(Object selectedItem)
          This is called when the user selects an item from the popup menu.
 void pushDisplayLine(String newLine, int newFlags, DisplayLine pushDown)
           
protected  void rearrange(DisplayLine firstLine, int indexOfFirst, DisplayLine lastLine, boolean repaint)
          This re-arrange the section the cursor is on and following sections up to lastSection.
 void removeDisplayLine(DisplayLine toRemove)
          Remove a single DisplayLine
protected  boolean removeSelection()
          This deletes any selected area and updates the cursor, but it does not do a resplitting of the lines nor does it do a repaint.
 void replaceDisplayLines(DisplayLine newSequence, DisplayLine firstToReplace, DisplayLine lastToReplace)
           
protected  void replaceLines(DisplayLine start, int length, DisplayLine newLines)
           
 boolean replaceSelection(Object with)
          This will replace the current selection with the provided Object.
 void resizeTo(int width, int height)
          This will change the width and height values.
 DisplayLine resplit(DisplayLine firstLine, int numLines, int forWidth, DisplayLine.WidthProvider widthProvider, FontMetrics fm, String newText)
          Resplit and replace lines of text, possibly substituting new text.
 void scrollTo(int lineIndex, boolean placeLineAtBottom)
          Scroll the display so that the specified line is now visible.
 void selectAll()
           
 Control setAsStaticDisplay(boolean makeScrollBar)
          This modifies the mTextPad to be a static text display - where the cursor is never displayed and the cursor keys will scroll the display.
protected  void setNativeInputFlags(TextInputParameters tip)
           
 boolean setSelectionRange(int originalCharacterIndex, int numCharacters)
          This sets the current selection and will also move the cursor to the end of the selection.
 boolean setSelectionRange(int startChar, int startLine, int endChar, int endLine)
          This sets the current selection and will also move the cursor to the end of the selection.
 boolean setState(Object state)
          Reset the display to the state as provided by getState().
 void setText(String what)
           
protected  void splitLines(int width)
           
 DisplayLine splitLines(String text, DisplayLine.WidthProvider widthProvider, FontMetrics fontMetrics, FormattedTextSpecs fts)
          This is used by TextFormatters to split text for display.
 DisplayLine splitLines(String text, int forWidth, FontMetrics fontMetrics, FormattedTextSpecs fts)
          This is used by TextFormatters to split text for display.
 void startDragging(DragContext dc)
          This is called to indicate the start of a pen/mouse drag operation.
 void ticked(int id, int elapsed)
           
 void update()
           
 void update(boolean doChecks)
           
protected  void updateScrolls()
           
 
Methods inherited from class ewe.ui.EditControl
checkInputMethod, dataBeingRemoved, fixCase, getBestPassiveFlags, getColors, hasChanged, keepConditionalChar, onControlEvent, setConditionalChar, startActiveInput, startLocalInput, startNativeInput, takeData, updateData
 
Methods inherited from class ewe.ui.Control
activate, addListener, addTimer, amOnTopFrame, calculateTextSize, cancelCut, cancelHoldDown, canEdit, chainDataChange, change, checkClipboardOperations, checkExitKey, checkMenu, checkMenuKey, checkModifiers, checkPenTransparent, clearTag, clipboardToString, clipboardTransfer, closeMenu, contains, contains, createGraphics, dataDraggedOver, deactivate, defaultTo, doAction, doActionKey, doBackground, doBorder, doHotKey, doMenu, dontAcceptDrop, doPaintChildren, doPaintChildren, doPaintChildren, doPaintData, exitEntry, fillBackground, formClosing, fromClipboard, fromField, fromField, getAllDescendants, getAllSubControls, getBackground, getChildren, getChildrenBackwards, getClipboardMenu, getClipObject, getControlBuffer, getControlBuffer, getDataRect, getDataToCopy, getDataToDragAndDrop, getDim, getDisplayText, getDragAndDropContext, getFont, getFontMetrics, getFontMetrics, getForeground, getFrame, getFrameOrContainer, getGraphics, getImage, getLastSelected, getLocation, getMaximumSize, getMenu, getMinimumSize, getModifiers, getNext, getNextKeyFocus, getParent, getPasswordCharacter, getPosInFrame, getPosInParent, getPreferredSize, getPrompt, getPromptText, getRect, getRect, getServer, getSize, getSizes, getSubControls, getTag, getToolTip, getWindow, hasModifier, hasPopupFormAttached, hasTag, inheritModifiers, isChildOf, isModal, isOnMe, isSomeonesHotKey, make, makeFrameTopMost, makeHot, menuIsActive, modify, modifyAll, modifyAll, notifyAction, notifyDataChange, notifyDataChange, notNative_doPaintChildren, oldButWorksDoPaintChildren, oldPaintChildren, oldPostEvent, onLabelPenEvent, onPaint, paintBackground, paintChildren, penClicked, penHeld, penRightReleased, popupBeep, popupMenuEvent, postEvent, recalculatePreferredSize, redisplay, refresh, removeListener, removeTimer, repaint, repaintDataNow, repaintNow, repaintNow, repaintNow, requestPaint, requestResizeTo, resetRect, restore, scrollAndRepaint, sendToListeners, set, setBorder, setCell, setClipObject, setControl, setCursor, setFixedSize, setFont, setHotKey, setHotKey, setLocation, setMaximumSize, setMenu, setMinimumSize, setPreferredSize, setPromptControl, setRect, setRect, setServer, setTag, setTags, setTextSize, setToolTip, show, shown, standardOnKeyEvent, startDragAndDrop, startDragAndDrop, stopDragging, takeFocus, takeFromClipboard, takePromptControl, testDim, toClipboard, toField, toField, toString, toTextData, transferPenPress, transferPenPress, tryDragAndDrop, tryNext, tryStartMenu, willAcceptDrop, willShowFrame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 
Methods inherited from interface ewe.ui.ScrollClient
getServer, setServer
 

Field Detail

lines

protected DisplayLine lines

dls

protected DisplayLineSpecs dls

backgroundImage

public IImage backgroundImage

wrapToScreenSize

public boolean wrapToScreenSize
This is true by default - it tells the control to wrap lines to fit the display.


spacing

public int spacing

dontWantPopup

public boolean dontWantPopup
This is false by default. Set it true if you do not want a text popup to be displayed if the SIP covers this control.


wantReturn

public boolean wantReturn
This is true by default. If it is false, then pressing Enter will not cause a new line to be inserted into the data, but rather a DataChangeEvent will be sent and the focus will move to the next line.


minXScroll

public int minXScroll
A percent figure. Defaults to 30%


minYScroll

public int minYScroll
A percent figure. Defaults to 80%


selectAllOnFocus

public boolean selectAllOnFocus
If this is true the entire text is selected when it gains focus.


allowOverwrite

public boolean allowOverwrite
If this is true (which it is by default) then the user will be allowed to switch between overwrite and insert mode using the INS key.


charWidth

public int charWidth
This is used to estimate line lengths.


disableCursor

public boolean disableCursor
Set this true to disable the cursor. With this mode the the cursor keys will scroll the display up and down.


disableTextChanges

public boolean disableTextChanges
Set this true to disable any text changes. The mTextPad will therefore just act as a text display.


numLines

protected int numLines

lineHeight

protected int lineHeight

inputState

public int inputState
This is used to determine the state of the input. It will consist of a set of bit flags or'ed together. These flags include: STATE_OVERWRITE, STATE_AUTOTAB


STATE_OVERWRITE

public static final int STATE_OVERWRITE
This is used with the inputState variable to indicate overwrite mode (as opposed to insert mode).

See Also:
Constant Field Values

STATE_AUTOTAB

public static final int STATE_AUTOTAB
This is used with the inputState variable to indicate auto-tab mode.

See Also:
Constant Field Values

leftMargin

public int leftMargin
This is the left margin.


rightMargin

public int rightMargin
This is the right margin.


extraLineSpacing

public int extraLineSpacing
This is extra spacing placed between lines.


itemBuffer

protected static ImageBuffer itemBuffer

blockBuffer

protected static ImageBuffer blockBuffer

format

public FormattedTextSpecs format
This can be used to alter things like the tab stop width. Do not set this to null.


amScrolling

protected boolean amScrolling

forcedActualWidth

public int forcedActualWidth
Set this to be a non-zero value to have a specific document width (in pixels), regardless of the length of the lines being displayed.


curState

protected ewe.ui.textPadState curState
Constructor Detail

mTextPad

public mTextPad()

mTextPad

public mTextPad(int rows,
                int columns)

mTextPad

public mTextPad(String text)
Method Detail

getTextPadMenu

public Menu getTextPadMenu(Menu addTo)

doShowMenu

protected boolean doShowMenu(Point p)
Description copied from class: Control
Used to show the menu associated with the Control. This will be called by tryStartMenu() which is what you should use instead.

Overrides:
doShowMenu in class Control
Parameters:
p - The point where the pen was pressed.
Returns:
true always.

popupMenuClosed

protected void popupMenuClosed(Menu m)
Description copied from class: Control
This gets closed after the popup menu for the Control has closed. You can clear the menu by doing setMenu(null).

Overrides:
popupMenuClosed in class Control

getLineHeight

public int getLineHeight()
Returns the height in pixels of each line (all lines are the same height).


getBaselineHeight

public int getBaselineHeight()
Returns the height in pixels from the top of a line down to the baseline of the font.


calculateSizes

protected void calculateSizes()
Description copied from class: Control
Override this to calculate the preferred, minimum and maximum size of your control. This is only called once unless the modifier flag AlwaysRecalculateSizes is true. During the calculation you will set the variables preferredWidth, preferredHeight, etc. directly.

Overrides:
calculateSizes in class Control

getAvailableWidth

public int getAvailableWidth()

getNumLines

public int getNumLines()
Return the number of lines being displayed.


getTextWidth

public int getTextWidth()
If wrapToScreenSize is true, this returns the width of the widest word. Otherwise it will return the width of the widest line.


resizeTo

public void resizeTo(int width,
                     int height)
Description copied from class: Control
This will change the width and height values.

Overrides:
resizeTo in class Control

displayLinesChanged

public void displayLinesChanged()

pushDisplayLine

public void pushDisplayLine(String newLine,
                            int newFlags,
                            DisplayLine pushDown)

addDisplayLine

public DisplayLine addDisplayLine(String newLine,
                                  DisplayLine addBefore)

addDisplayLines

public void addDisplayLines(DisplayLine newSequence,
                            DisplayLine addBefore)

ensureBlankLines

public int ensureBlankLines(DisplayLine dataLine,
                            int count,
                            boolean above)
Insert blank lines before or after the specified data line so that there are at least count number of blank lines before or after the data line.

Parameters:
dataLine - The data line.
count - The number of blank lines.
above - if this is true the blank lines will be added before (above) the data line.
Returns:
the number of lines that were inserted.

breakLineBefore

public DisplayLine breakLineBefore(DisplayLine dataLine,
                                   int index)
This forces a line break in the specified data line immediately before the specified index. The left-over data on the line is placed into another line placed after the data line. Note that if there are no characters after the index and the line does not end with a line feed then the line will not be broken and null will be returned.

Parameters:
dataLine - The dataLine to break.
index - The index of the character before which a break will be added.
Returns:
The DisplayLine containing the extra characters that was added after the display line.

replaceDisplayLines

public void replaceDisplayLines(DisplayLine newSequence,
                                DisplayLine firstToReplace,
                                DisplayLine lastToReplace)

removeDisplayLine

public void removeDisplayLine(DisplayLine toRemove)
Remove a single DisplayLine


splitLines

public DisplayLine splitLines(String text,
                              int forWidth,
                              FontMetrics fontMetrics,
                              FormattedTextSpecs fts)
This is used by TextFormatters to split text for display. Usually the lines returned are used to replace lines already in the mTextPad

Parameters:
text - The text to split.
forWidth - The width in pixels to split for.
fontMetrics - The font metrics to use. If this is null then the mTextPad's metrics will be used.
fts - The FormattedTextSpecs to use. If this is null then the mTextPad's specs will be used.
Returns:
The list of DisplayLines created.

splitLines

public DisplayLine splitLines(String text,
                              DisplayLine.WidthProvider widthProvider,
                              FontMetrics fontMetrics,
                              FormattedTextSpecs fts)
This is used by TextFormatters to split text for display. Usually the lines returned are used to replace lines already in the mTextPad

Parameters:
text - The text to split.
widthProvider - An object to provide the width of each line.
fontMetrics - The font metrics to use. If this is null then the mTextPad's metrics will be used.
fts - The FormattedTextSpecs to use. If this is null then the mTextPad's specs will be used.
Returns:
The list of DisplayLines created.

resplit

public DisplayLine resplit(DisplayLine firstLine,
                           int numLines,
                           int forWidth,
                           DisplayLine.WidthProvider widthProvider,
                           FontMetrics fm,
                           String newText)
Resplit and replace lines of text, possibly substituting new text. The first DisplayLine is re-used with a new "line" and "displayWidth" value.

Parameters:
firstLine - The first DisplayLine in the sequence.
numLines - The number of lines in the sequence.
forWidth - The width to wrap the lines to. Can be zero if widthProvider is used.
widthProvider - An optional DisplayLine.WidthProvider to provide widths for each line.
fm - The FontMetrics to use, can be null to use the mTextPad's FontMetrics.
newText - Optional new text, if null then the original text is used.
Returns:
The first DisplayLine of the newly split lines.

splitLines

protected void splitLines(int width)

getCharRect

protected boolean getCharRect(int ch,
                              int ln,
                              Rect dest)

getCursorRect

protected boolean getCursorRect(int ch,
                                int ln,
                                Rect dest)

setText

public void setText(String what)
Overrides:
setText in class Control

getText

public String getText()
Overrides:
getText in class Control

getLines

public String[] getLines()
Get all the lines. Additional verbose

Returns:

fixText

protected void fixText()

getScreenRows

public int getScreenRows()

paintLastChar

public void paintLastChar(Graphics g)

paintLastChar

public void paintLastChar(Graphics g,
                          char toErase)

deleteSelection

public boolean deleteSelection()
Specified by:
deleteSelection in interface Selectable

paintLine

public void paintLine(Graphics g,
                      int index)

getSpecialFormatCount

protected int getSpecialFormatCount(int lineIndex,
                                    DisplayLine theLine)

applySpecialFormat

protected void applySpecialFormat(int formatIndex,
                                  int lineIndex,
                                  DisplayLine theLine,
                                  FormattedTextSpecs format)

drawSpecialFormat

protected void drawSpecialFormat(int formatIndex,
                                 int lineIndex,
                                 DisplayLine theLine,
                                 FormattedTextSpecs format,
                                 Graphics g,
                                 Color background)

getTextPositions

public FormattedTextSpecs getTextPositions(int lineIndex,
                                           DisplayLine line,
                                           FormattedTextSpecs format,
                                           int[] posBuffer,
                                           boolean useFormatters)

getTextPositions

protected FormattedTextSpecs getTextPositions(int lineIndex,
                                              DisplayLine line)

paintLine

public void paintLine(Graphics g,
                      int index,
                      DisplayLine theLine)

doPaint

public void doPaint(Graphics g,
                    Rect area)
Overrides:
doPaint in class Control

paintCursor

public void paintCursor(Graphics gr)

paintCursor

public void paintCursor(Graphics gr,
                        boolean sticky)

doPaintData

protected void doPaintData(Graphics g)
Description copied from class: Control
Repaint the "data" part of the Control. This is only used for Controls with the HasData modifier. These are controls that distinguish between their data (e.g. contained text) and non-data (e.g. border) on-screen display.

Overrides:
doPaintData in class Control
Parameters:
g - The Graphics object to paint to.

doPaintData

protected void doPaintData(Graphics g,
                           Rect area)

paintLines

public void paintLines(int from,
                       int to)

paintLinesFrom

protected void paintLinesFrom(int index)

getScrollablePanel

public ScrollablePanel getScrollablePanel()

update

public void update()
Overrides:
update in class EditControl

update

public void update(boolean doChecks)

getActual

public int getActual(int which)
Specified by:
getActual in interface ScrollClient

getVisible

public int getVisible(int which,
                      int forSize)
Specified by:
getVisible in interface ScrollClient

getCurrent

public int getCurrent(int which)
Specified by:
getCurrent in interface ScrollClient

needScrollBar

public boolean needScrollBar(int which,
                             int forSize)
Specified by:
needScrollBar in interface ScrollClient

canGo

public boolean canGo(int orientation,
                     int direction,
                     int position)
Specified by:
canGo in interface ScrollClient

doScroll

public void doScroll(int which,
                     int action,
                     int value)
Specified by:
doScroll in interface ScrollClient

checkScrolls

public void checkScrolls()

updateScrolls

protected void updateScrolls()

ticked

public void ticked(int id,
                   int elapsed)
Specified by:
ticked in interface TimerProc
Overrides:
ticked in class Control

popupMenuEvent

public void popupMenuEvent(Object selectedItem)
Description copied from class: Control
This is called when the user selects an item from the popup menu.

Overrides:
popupMenuEvent in class Control
Parameters:
selectedItem - The item selected.

selectAll

public void selectAll()
Specified by:
selectAll in class EditControl

checkSipCoverage

public boolean checkSipCoverage()
Overrides:
checkSipCoverage in class EditControl

gotFocus

public void gotFocus(int how)
Overrides:
gotFocus in class Control

lostFocus

public void lostFocus(int how)
Overrides:
lostFocus in class Control

setNativeInputFlags

protected void setNativeInputFlags(TextInputParameters tip)
Overrides:
setNativeInputFlags in class EditControl

fix

protected boolean fix()

newCursorPos

public boolean newCursorPos(int ch,
                            int ln,
                            boolean takeSel)
This calls newCursorPos(int ch,int ln,boolean takeSel,boolean leaveSel) with leaveSel set to false.


newCursorPos

public boolean newCursorPos(int ch,
                            int ln,
                            boolean takeSel,
                            boolean leaveSel)
This is used to move the cursor position AND update the display accordingly.

Parameters:
ch - The character position on the line.
ln - The line.
takeSel - If this is true then the selection will be extended to the new cursor position. If it is false AND leaveSel is also false, any selected area will be deselected. If this is false AND leaveSel is true, the selection will be left as is.
leaveSel - If this is true AND takeSel is false, then the selection will not be altered.
Returns:
true if the display was repainted during the function call, false if it has not been repainted.

getTopLine

public int getTopLine()
Return the index of the top line of the display in the complete list of lines.


getLeftPosition

public int getLeftPosition()
Return how many pixels the display is shifted to the right.


getCharAt

public Point getCharAt(Point onControl,
                       boolean bestGuess,
                       boolean halfWay)
Get the line and character index of the character at the point specified (relative to the origin of the mTextPad).

Parameters:
onControl - The x and y co-ordinate within the mTextPad.
bestGuess - if this is true and the point is not on a character, the location of the closest character is returned.
halfWay - if this is true then once the point is more than half-way through a character it is considered on the next character.
Returns:
The location of the character ( x = character index in line, y = line index), or null if the point is not actually on a character and bestGuess is false

getPenChar

protected Point getPenChar(Point onControl)

getCharAt

public Point getCharAt(Point onControl)
Get the line and character index of the character at the point specified (relative to the origin of the mTextPad).

Parameters:
onControl - The x and y co-ordinate within the mTextPad.
Returns:
The location of the character ( x = character index in line, y = line index), or null if the point is not actually on a character.

clearCursor

protected void clearCursor()

getLineAt

public String getLineAt(int index)
Get the line at the specified index. Any line feeds or ending spaces are added to the end so that it represents the true line.

Parameters:
index - The index of the line.
Returns:
The line text, or null if the line index is invalid.

getLineAt

public String getLineAt(int index,
                        boolean trueLine)
Get the line at the specified index. Any line feeds or ending spaces are added to the end so that it represents the true line IF trueLine is true.

Parameters:
index - The index of the line.
trueLine - if this is true then ending line feeds or spaces are added to the line. If not, then the line is returned as it is on the display.
Returns:
The line text, or null if the line index is invalid.

getLineLength

public int getLineLength(int index,
                         boolean trueLength)
Return the length of the line in characters, with or without the ending line feed.

Parameters:
trueLength - if this is true, then any ending line feed is also included in the length, otherwise only the number of displayed characters is counted.
Returns:
the length of the line or -1 if the line index is invalid.

getTrueCharIndex

public int getTrueCharIndex(int lineIndex,
                            int charIndex)
Get the index of the character in the original text, given the line index and character index on screen.

Parameters:
lineIndex - The line it is displayed on screen.
charIndex - The character index within the on-screen line.
Returns:
The index of the character in the original text or -1 if the character is invalid.

getTrueCharIndex

public int getTrueCharIndex(Point charPosition)
Get the index of the character in the original text, given the line index and character index on screen.

Parameters:
charPosition - The character position on screen where y = the line it is displayed on screen, and x is the character index within the on-screen line.
Returns:
The index of the character in the original text or -1 if the character is invalid.

getLine

public DisplayLine getLine(int index)
Get the DisplayLine at the specified index. Once you can get following display lines by using the "next" member of the returned DisplayLine.


getLine

protected DisplayLine getLine()

noSelection

public boolean noSelection()
Specified by:
noSelection in interface Selectable

getSelection

public Object getSelection()
Specified by:
getSelection in interface Selectable

removeSelection

protected boolean removeSelection()
This deletes any selected area and updates the cursor, but it does not do a resplitting of the lines nor does it do a repaint. It returns true if there was a selection to be removed.
The cursor will be positioned immediately before the text after the selection area.


rearrange

protected void rearrange(DisplayLine firstLine,
                         int indexOfFirst,
                         DisplayLine lastLine,
                         boolean repaint)
This re-arrange the section the cursor is on and following sections up to lastSection. It will do a repaint if asked. If lastSection is null only the cursor section will be re-arranged.


replaceSelection

public boolean replaceSelection(Object with)
This will replace the current selection with the provided Object. The Object can be a string or an array of strings (each representing a line). If there is no selection the data will be inserted at the cursor position. The cursor will always be moved to the end of the inserted data.

Specified by:
replaceSelection in interface Selectable

hasSelection

public boolean hasSelection()
Specified by:
hasSelection in interface Selectable

clearSelection

public void clearSelection()
This clears the selection but does not update the screen. Call repaintNow() to update the screen.


penPressed

public void penPressed(Point where)
Description copied from class: Control
Called when the Pen or Mouse button is pressed on the control. This is called by the onPenEvent(PenEvent ev) method.

Within this method you can use the Control.currentPenEvent value to find out more about the PenEvent that caused this - including any modifiers (e.g. SHIFT keys) or determine if the left or right mouse button was pressed.

Overrides:
penPressed in class Control
Parameters:
where - The point on the Control where the pen was pressed.

penDoubleClicked

public void penDoubleClicked(Point where)
Description copied from class: Control
Called if the Pen or Mouse button is double clicked on the Control. This is called by the onPenEvent(PenEvent ev) method.

Within this method you can use the Control.currentPenEvent value to find out more about the PenEvent that caused this - including any modifiers (e.g. SHIFT keys) or determine if the left or right mouse button was pressed.

By default this method simply calls the penClicked() method.

Overrides:
penDoubleClicked in class Control
Parameters:
where - The point on the Control where the pen was double-clicked.

penReleased

public void penReleased(Point where)
Description copied from class: Control
Called when the Pen or Mouse button is released on the control. This is called by the onPenEvent(PenEvent ev) method.

Within this method you can use the Control.currentPenEvent value to find out more about the PenEvent that caused this - including any modifiers (e.g. SHIFT keys) or determine if the left or right mouse button was pressed.

Overrides:
penReleased in class Control
Parameters:
where - The point on the Control where the pen was released.

startDragging

public void startDragging(DragContext dc)
Description copied from class: Control
This is called to indicate the start of a pen/mouse drag operation. This will only get called if the WantDrag modifier has been set for this control. Within this method you can call startDragAndDrop() or tryDragAndDrop() to begin a data DragAndDrop operation.

Overrides:
startDragging in class Control
Parameters:
dc - A DragContext indicating information about the dragging.

dragged

public void dragged(DragContext dc)
Description copied from class: Control
This is called during the drag operation. It is also called by default by the startDragging() method if you do not override it.

Overrides:
dragged in class Control
Parameters:
dc - The DragContext for the dragging operation.

replaceLines

protected void replaceLines(DisplayLine start,
                            int length,
                            DisplayLine newLines)

autoTab

protected String autoTab(String currentLine,
                         String newLine)

onKeyEvent

public void onKeyEvent(KeyEvent ev)
Overrides:
onKeyEvent in class Control

acceptsData

public boolean acceptsData(Object data,
                           DragContext how)
Description copied from class: Control
This should indicate whether this control will accept the data either via a drag and drop or via a paste operation.

Overrides:
acceptsData in class EditControl

dataDraggedOver

public void dataDraggedOver(Object data,
                            Point p,
                            PenEvent ev)
Description copied from class: Control
This is called when data is being dragged into the control. Within this method the control should call either willAcceptDrop() or dontAcceptDrop() to indicate its willingness to accept the data.

By default this method calls dataDraggedOver(Object data) - which itself by default calls acceptsData() to determine whether to call willAcceptDrop() or dontAcceptDrop().

Overrides:
dataDraggedOver in class Control
Parameters:
data - The data being dragged.
p - The current location of the pen/mouse.
ev - The PenEvent that prompted this call.

dataDraggedOff

public void dataDraggedOff(Object data)
Description copied from class: Control
This is called when data that was previously dragged into the control has now been dragged off.

Overrides:
dataDraggedOff in class Control
Parameters:
data - the data being dragged.

onPenEvent

public void onPenEvent(PenEvent ev)
Description copied from class: Control
Called to handle an incoming PenEvent. By default this dispatches the event to the various pen handling methods like penPressed()

Overrides:
onPenEvent in class Control
Parameters:
ev - The incoming PenEvent.

dataDroppedOn

public boolean dataDroppedOn(Object data,
                             Point where,
                             DragContext dc)
Description copied from class: Control
This is called by a drop from a drag and drop operation. By default it will call takeData() unless it is from itself, in which case the data is rejected and this returns false.

Overrides:
dataDroppedOn in class Control

dataAccepted

public void dataAccepted(Control by,
                         Object theData,
                         String action)
Description copied from class: Control
This is called either when data that was cut from this control was pasted into another control, OR when data that was dragged from this control is dropped into another control.

Overrides:
dataAccepted in class Control
Parameters:
by - The Control that accepted the data.
theData - The data being transferred.
action - This is either "copy" or "move" indicating if the data is meant to be copied to the other control or moved to the other Control.

dataTransferCancelled

protected void dataTransferCancelled(Object data)
Description copied from class: Control
This gets called either when that was cut from this control was not placed into another control (either it was rejected by a paste or a subsequent copy/cut into the clipboard occured before the data was pasted) or a drag and drop was initiated but not completed.

Overrides:
dataTransferCancelled in class EditControl

getCursorPosition

public Point getCursorPosition()
Get the character location of the cursor (caret).

Returns:
A new Point where the x value represents the character index on the line the cursor is on (starting from 0) and the y value represents line index of the line the cursor is on.

getSelectionRange

public Rect getSelectionRange()
This returns the selected area, or null if there is no selection. The x and y co-ordinates of the returned Rect mark the character and line index of the first character selected. Add the width of the returned Rect to the x value to find the index of the character just after the last selected character. Add the height of the returned Rect to the y value to find the index of the line of the last selected character.


setSelectionRange

public boolean setSelectionRange(int startChar,
                                 int startLine,
                                 int endChar,
                                 int endLine)
This sets the current selection and will also move the cursor to the end of the selection.

Parameters:
startChar - Character index of the start of the selection.
startLine - Line index of the start of the selection.
endChar - Character index of the end of the selection.
endLine - Line index of the start of the selection.
Returns:
True if the screen has been updated, false if not. If it returns false then you should call repaintNow() at some point to update the display correctly.

getIndexLocation

public Dimension getIndexLocation(int characterIndex,
                                  Dimension dest)
This locates the row and column index of a character from the original text in the list of DisplayLines.

Parameters:
characterIndex - The original index of the character.
dest - a destination Dimension to hold the results. It can be null, in which case a new one will be allocated and returned.
Returns:
A Dimension object where the width variable denotes the index within the line and the height variable donates the index of the line. It will return null if the index is not in the orignal text.

setSelectionRange

public boolean setSelectionRange(int originalCharacterIndex,
                                 int numCharacters)
This sets the current selection and will also move the cursor to the end of the selection.

Parameters:
originalCharacterIndex - The index of the start character as it was in the original text.
numCharacters - The number of characters to select.
Returns:
True if the screen has been updated, false if not. If it returns false then you should call repaintNow() at some point to update the display correctly.

appendText

public void appendText(String what,
                       boolean moveToEnd)

scrollTo

public void scrollTo(int lineIndex,
                     boolean placeLineAtBottom)
Scroll the display so that the specified line is now visible. A repaint is done.

Parameters:
lineIndex - The line to make visible.
placeLineAtBottom - If this is true the line will be placed at the bottom of the screen, otherwise it will be placed at the top.

getState

public Object getState()
Get an Object that can be used to restore the text display to the same state later (using setState(). This method essentially will return a reference to the data that is displayed as the first line on-screen. Calling setState() will attempt to replace that line back on top.


setState

public boolean setState(Object state)
Reset the display to the state as provided by getState().

Parameters:
state - The object returned by getState().
Returns:
true if successfully restored the state, false otherwise.

onEvent

public void onEvent(Event ev)
Specified by:
onEvent in interface EventListener
Overrides:
onEvent in class Control

setAsStaticDisplay

public Control setAsStaticDisplay(boolean makeScrollBar)
This modifies the mTextPad to be a static text display - where the cursor is never displayed and the cursor keys will scroll the display.

The method returns the mTextPad itself if makeScrollBar is false. If makeScrollBar is true it will return a ScrollablePanel() that contains this mTextPad. The returned ScrollablePanel will be a VerticalScrollPanel on a SmartPhone, or a ScrollBarPanel on any other platform.


paintConditionalChar

protected boolean paintConditionalChar(Graphics g,
                                       boolean highlight)
Specified by:
paintConditionalChar in class EditControl