ewe.ui
Class Console

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

public class Console
extends EditControl
implements ScrollClient

A Console is a non-editable text display. It is optimized for fast display and so:

  • It is not-editable.
  • It only works with fixed-width (monospaced) fonts.

    By default the Console will set its font to the font returned by mApp.findFont("fixed") and there is a convenience method to change the size of the font: setFontSize()

    The wrapLength variable controls the wrap length of the Console. It should be 0 for no wrapping, -1 for wrapping to the screen size or a positive value for an explicit maximum line width.


    Field Summary
    protected static ImageBuffer blockBuffer
               
    protected static char[] emptyLine
               
    protected static ImageBuffer itemBuffer
               
     boolean localEcho
              If this is true then keys pressed are echoed (displayed) on the console.
     int maxLines
              This is the maximum number of lines to store in the Console.
     boolean showCursor
              This is true by default.
     int spacing
               
     int wrapLength
              This specifies the number of characters allowed per line, or a value of -1 indicates that incoming data should wrap to the screen size, or a value of 0 indicates no line wrapping.
     
    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, pressPoint, 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
    Console()
               
     
    Method Summary
     void append(char[] data, int start, int length, boolean updateDisplay)
               
     void append(char data, boolean updateDisplay)
              Append a single character to the console.
     void append(String data, boolean updateDisplay)
               
     boolean canGo(int orientation, int direction, int position)
               
     boolean checkSipCoverage()
               
     void clear(boolean updateDisplay)
              Clear the console text.
     void closeIO()
              If there are open Writers and Readers for this Console, this call will close them.
     IOHandle[] connectTo(Reader reader, Writer writer)
              Connect this console to a Reader and a Writer.
     IOHandle[] connectTo(Stream s)
              Connect this console to a bi-directional Stream.
    static void debug(String data)
              Send a line of data to the special debugging/standard IO console.
     boolean deleteSelection()
               
     void doPaint(Graphics g, Rect area)
               
    protected  void doPaintData(Graphics g)
              Repaint the "data" part of the Control.
     void doPaintData(Graphics g, Rect area)
               
     void doScroll(int which, int action, int value)
               
     int getActual(int direction)
               
    static Console getAppConsole()
              Get a special console used for debugging or standard input/output.
     int getCurrent(int direction)
               
     char[] getLine(int line)
               
     int getLineLength()
               
     int getNumLines()
               
     Reader getReader()
              Get a Reader that you can use to read from the console.
     int getScreenCols(boolean fullyDisplayed)
              Get the number of characters that can be partially or fully displayed on a line.
     int getScreenRows(boolean fullyDisplayed)
              Get the number of lines that can be partially or fully displayed.
     Object getSelection()
               
     String getText()
               
     int getVisible(int direction, int forSize)
               
     Writer getWriter()
              Get a Writer that you can use to write to the console.
     void gotFocus(int how)
               
     boolean hasSelection()
               
    protected  void keyPressed(KeyEvent ev)
              This gets called when a valid key is pressed.
    protected  char keyToChar(KeyEvent key)
              This converts a key press to a Unicode character for sending or displaying.
     void lostFocus(int how)
               
     boolean needScrollBar(int direction, int forSize)
               
     boolean noSelection()
               
     void onKeyEvent(KeyEvent ev)
               
    protected  boolean paintConditionalChar(Graphics g, boolean b)
               
     void paintLine(Graphics gr, int line)
               
     void popupMenuEvent(Object selectedItem)
              This is called when the user selects an item from the popup menu.
     void refresh()
              This will reposition the display to the end of the text and then do a full display refresh.
     boolean replaceSelection(Object with)
               
     void selectAll()
               
     void sendChar(char key)
              This gets called when a key was pressed by the default sendKey() method.
     void sendChars(char[] keys, int offset, int length)
              This gets called by the default sendChar() method and can also be called directly.
    protected  void sendKey(KeyEvent key)
              This gets called when a key was pressed by the default keyPressed() method.
     Control setFont(Font f)
              Call this to set the Font for the Console, which should be a fixed-width font.
     void setFontSize(int size)
              Change the size of the font.
     void setText(String text)
               
    protected  void updateDisplay()
              This does not shift the position to the end of the text, use refresh() that instead.
     void updateDisplay(int changedLines)
               
    protected  boolean wantKey(KeyEvent ev)
              This is used to decide if you wish to process a key press.
     
    Methods inherited from class ewe.ui.EditControl
    acceptsData, checkInputMethod, dataBeingRemoved, dataTransferCancelled, fixCase, getBestPassiveFlags, getColors, hasChanged, keepConditionalChar, onControlEvent, setConditionalChar, setNativeInputFlags, startActiveInput, startLocalInput, startNativeInput, takeData, update, updateData
     
    Methods inherited from class ewe.ui.Control
    activate, addListener, addTimer, amOnTopFrame, calculateSizes, calculateTextSize, cancelCut, cancelHoldDown, canEdit, chainDataChange, change, checkClipboardOperations, checkExitKey, checkMenu, checkMenuKey, checkModifiers, checkPenTransparent, clearTag, clipboardToString, clipboardTransfer, closeMenu, contains, contains, createGraphics, dataAccepted, dataDraggedOff, dataDraggedOver, dataDraggedOver, dataDroppedOn, deactivate, defaultTo, doAction, doActionKey, doBackground, doBorder, doHotKey, doMenu, dontAcceptDrop, doPaintChildren, doPaintChildren, doPaintChildren, doPaintData, doShowMenu, dragged, 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, onEvent, onLabelPenEvent, onPaint, onPenEvent, paintBackground, paintChildren, penClicked, penDoubleClicked, penHeld, penPressed, penReleased, penRightReleased, popupBeep, popupMenuClosed, popupMenuEvent, postEvent, recalculatePreferredSize, redisplay, refresh, removeListener, removeTimer, repaint, repaintDataNow, repaintNow, repaintNow, repaintNow, requestPaint, requestResizeTo, resetRect, resizeTo, restore, scrollAndRepaint, sendToListeners, set, setBorder, setCell, setClipObject, setControl, setCursor, setFixedSize, setHotKey, setHotKey, setLocation, setMaximumSize, setMenu, setMinimumSize, setPreferredSize, setPromptControl, setRect, setRect, setServer, setTag, setTags, setTextSize, setToolTip, show, shown, standardOnKeyEvent, startDragAndDrop, startDragAndDrop, startDragging, stopDragging, takeFocus, takeFromClipboard, takePromptControl, testDim, ticked, 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

    spacing

    public int spacing

    maxLines

    public int maxLines
    This is the maximum number of lines to store in the Console. By default it is 0 indicates that there is no maximum.


    showCursor

    public boolean showCursor
    This is true by default. Set it false to have no cursor displayed.


    wrapLength

    public int wrapLength
    This specifies the number of characters allowed per line, or a value of -1 indicates that incoming data should wrap to the screen size, or a value of 0 indicates no line wrapping.


    itemBuffer

    protected static ImageBuffer itemBuffer

    blockBuffer

    protected static ImageBuffer blockBuffer

    emptyLine

    protected static char[] emptyLine

    localEcho

    public boolean localEcho
    If this is true then keys pressed are echoed (displayed) on the console.

    Constructor Detail

    Console

    public Console()
    Method Detail

    setFont

    public Control setFont(Font f)
    Call this to set the Font for the Console, which should be a fixed-width font.

    Overrides:
    setFont in class Control
    Parameters:
    f - The new Font.
    Returns:
    itself.

    setFontSize

    public void setFontSize(int size)
    Change the size of the font.

    Parameters:
    size - The new size of the font.

    gotFocus

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

    lostFocus

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

    selectAll

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

    hasSelection

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

    noSelection

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

    deleteSelection

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

    replaceSelection

    public boolean replaceSelection(Object with)
    Specified by:
    replaceSelection in interface Selectable

    getSelection

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

    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.

    getScreenRows

    public int getScreenRows(boolean fullyDisplayed)
    Get the number of lines that can be partially or fully displayed.

    Parameters:
    fullyDisplayed - if this is true then only the number of fully displayed lines are returned.
    Returns:
    The number of lines that can be displayed.

    getScreenCols

    public int getScreenCols(boolean fullyDisplayed)
    Get the number of characters that can be partially or fully displayed on a line.

    Parameters:
    fullyDisplayed - if this is true then only the number of fully displayed characters are returned.
    Returns:
    The number of lines that can be displayed.

    getLine

    public char[] getLine(int line)

    updateDisplay

    protected void updateDisplay()
    This does not shift the position to the end of the text, use refresh() that instead.


    updateDisplay

    public void updateDisplay(int changedLines)

    clear

    public void clear(boolean updateDisplay)
    Clear the console text.

    Parameters:
    updateDisplay - if this is true a repaint will be done.

    getText

    public String getText()
    Overrides:
    getText in class Control

    refresh

    public void refresh()
    This will reposition the display to the end of the text and then do a full display refresh.


    append

    public void append(char data,
                       boolean updateDisplay)
    Append a single character to the console.

    Parameters:
    data - The character to append.
    updateDisplay - true to update the display after.

    append

    public void append(char[] data,
                       int start,
                       int length,
                       boolean updateDisplay)

    append

    public void append(String data,
                       boolean updateDisplay)

    paintLine

    public void paintLine(Graphics gr,
                          int line)

    doPaint

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

    doPaintData

    public void doPaintData(Graphics g,
                            Rect area)

    setText

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

    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.

    doScroll

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

    getLineLength

    public int getLineLength()

    getNumLines

    public int getNumLines()

    getActual

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

    getCurrent

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

    getVisible

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

    needScrollBar

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

    canGo

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

    getWriter

    public Writer getWriter()
    Get a Writer that you can use to write to the console.


    getReader

    public Reader getReader()
    Get a Reader that you can use to read from the console.


    closeIO

    public void closeIO()
    If there are open Writers and Readers for this Console, this call will close them.


    connectTo

    public IOHandle[] connectTo(Reader reader,
                                Writer writer)
    Connect this console to a Reader and a Writer. Two background threads are started, one to read from the reader and display all read characters on the console, and another that takes characters typed on the console and sends it to the Writer.

    Parameters:
    reader - the reader to read characters from to output on the console. If this is null then no reading is done.
    writer - the writer to send characters typed on the console to. If this is null then no writing is done.
    Returns:
    an array of two IOHandles. The IOHandle at index 0 is the handle that indicates the state of the transfer of characters from the provided reader to the console display. The IOHandle at index 1 is the handle that indicates the state of the transfer of characters typed on the console to the provided writer. If either reader or writer is null, the corresponding IOHandle will be null.

    connectTo

    public IOHandle[] connectTo(Stream s)
    Connect this console to a bi-directional Stream. This method creates an InputStreamReader() and and OutputStreamWriter() and then calls the connectTo(Reader,Writer) method. Please see that method to see how the method works.

    Parameters:
    s - the stream to read from and write to.
    Returns:
    an array of two IOHandles. The IOHandle at index 0 is the handle that indicates the state of the transfer of characters from the stream to the console display. The IOHandle at index 1 is the handle that indicates the state of the transfer of characters typed on the console to the stream. If either reader or writer is null, the corresponding IOHandle will be null.

    sendChars

    public void sendChars(char[] keys,
                          int offset,
                          int length)
    This gets called by the default sendChar() method and can also be called directly. By default, if a Reader has been opened to the Console, then this method will put the characters in the Reader's buffer.

    Parameters:
    keys - a set of characters.
    offset - the start of the characters to send.
    length - the number of characters to send.

    sendChar

    public void sendChar(char key)
    This gets called when a key was pressed by the default sendKey() method. By default this method will call the sendChars(char[] keys,int offset,int length)

    Parameters:
    key - The pressed key.

    keyToChar

    protected char keyToChar(KeyEvent key)
    This converts a key press to a Unicode character for sending or displaying. You can override this to provide more or better key mappings.

    Parameters:
    key - The pressed key.
    Returns:
    The character to convert to.

    sendKey

    protected void sendKey(KeyEvent key)
    This gets called when a key was pressed by the default keyPressed() method. By default this method calls keyToChar() on the key and calls sendChar().

    Parameters:
    key - The pressed key event.

    keyPressed

    protected void keyPressed(KeyEvent ev)
    This gets called when a valid key is pressed. By default this will echo the local character if localEcho is true and then call sendKey(). sendKey() by default will then call sendChar().

    Parameters:
    ev - The detected key event.

    wantKey

    protected boolean wantKey(KeyEvent ev)
    This is used to decide if you wish to process a key press. If this method returns true, then the key will be passed to keyPressed(KeyEvent ev) By default, this will return false only for keys considered SPECIAL except ENTER, TAB and BACKSPACE. All other keys will return true.

    Parameters:
    ev - The key event.
    Returns:
    true if you want to keep and process the key, false if not. If you return false the key will be passed to the super class implementation of onKeyEvent.

    onKeyEvent

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

    getAppConsole

    public static Console getAppConsole()
    Get a special console used for debugging or standard input/output. This Console will appear the first time data is sent to it (or read from it) and will re-appear should it be closed and data is sent to it (or read from it).


    paintConditionalChar

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

    debug

    public static void debug(String data)
    Send a line of data to the special debugging/standard IO console. See getAppConsole().


    checkSipCoverage

    public boolean checkSipCoverage()
    Overrides:
    checkSipCoverage in class EditControl