# Class CodeView

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.editor.EditorView
com.codename1.ui.editor.CodeView

All Implemented Interfaces:
  `Animation, Editable, StyleListener, TextInputClient`

public class CodeView extends EditorView
The pure code editor surface. It adds syntax highlighting (via an incremental `Tokenizer`), a line number gutter, bracket / quote auto close, tab expansion, auto indent, diagnostic squiggles and a code completion popup on top of the shared `EditorView` editing engine.

- ## Field Summary

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

  ### Fields inherited from interface TextInputClient

  `KEY_BACKSPACE, KEY_COPY, KEY_CUT, KEY_DELETE, KEY_DOWN, KEY_END, KEY_ESCAPE, KEY_HOME, KEY_LEFT, KEY_PAGE_DOWN, KEY_PAGE_UP, KEY_PASTE, KEY_REDO, KEY_RIGHT, KEY_SELECT_ALL, KEY_TAB, KEY_UNDO, KEY_UP, MOD_ALT, MOD_CTRL, MOD_SHIFT`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CodeView(EditorHost host)`
  Creates a code editor view.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `documentEdited(int fromOffset)`
  Hook invoked when the document is mutated at `fromOffset`, used by feature layers (e.g. the code editor) to invalidate cached tokenization from the affected line onward.
  `protected int`
  `getContentLeftInset()`
  Returns the left inset (padding plus any gutter) at which text starts.
  `String`
  `getLanguage()`
  Returns the highlighting language id.
  `protected void`
  `handleTab(boolean dedent)`
  Handles a tab key press (delivered as `#KEY_TAB`).
  `protected boolean`
  `handleTypedText(String text)`
  Hook giving feature layers a chance to intercept typed text before the default insertion (used by the code editor for bracket / quote auto close, tab expansion and auto indent).
  `void`
  `keyPressed(int keyCode)`
  If this Component is focused, the key pressed event will call this method
  `void`
  `keyReleased(int keyCode)`
  If this Component is focused, the key released event will call this method
  `void`
  `keyRepeated(int keyCode)`
  If this Component is focused, the key repeat event will call this method.
  `void`
  `onEditorAction(int action)`
  Delivers the keyboard return key action (done / next / search / send) configured through `TextInputConfig`.
  `void`
  `onKeyCommand(int command, int modifiers)`
  Delivers a non text key command (navigation, deletion, clipboard, undo).
  `void`
  `paint(Graphics g)`
  This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
  `protected void`
  `paintBeforeContent(Graphics g, int originX, int originY, int firstLine, int lastLine, int lineHeight, Font f)`
  Hook invoked before the visible lines are drawn, used by the code editor to paint the line number gutter.
  `protected void`
  `paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)`
  Paints a single line of text.
  `protected void`
  `paintLineDecorations(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)`
  Hook invoked after a line's text is drawn, used by the code editor to paint diagnostic squiggles.
  `void`
  `pointerHover(int[] x, int[] y)`
  Invoked for devices where the pointer can hover without actually clicking the display.
  `void`
  `pointerPressed(int x, int y)`
  If this Component is focused, the pointer pressed event will call this method
  `void`
  `setCompletionEnabled(boolean enabled)`
  Enables or disables the completion popup.
  `void`
  `setDiagnostics(List<CodeDiagnostic> diagnostics)`
  Sets the diagnostics to render.
  `void`
  `setLanguage(String language)`
  Sets the highlighting language.
  `void`
  `setShowLineNumbers(boolean show)`
  Shows or hides the line number gutter.
  `void`
  `setTabSize(int tabSize)`
  Sets the number of spaces used for a tab / indentation step.
  `void`
  `setTheme(String theme)`
  Sets the color theme (`"light"` or `"dark"`).
  `void`
  `showCompletions(int reqId, List<CodeCompletion> items)`
  Called by the backend with the provider's proposals for a request.

  ### Methods inherited from class EditorView

  `animate, baseFontSizePixels, blur, calcPreferredSize, captureDocumentState, columnAtX, commitText, contentTotalHeight, contentWidth, copySelection, deinitialize, deleteSurroundingText, documentReplaced, documentReset, finishComposing, firstVisibleLine, focusGained, focusLost, getCaretOffset, getCaretRect, getConfig, getDocument, getEditingState, getEditorFont, getHorizontalScroll, getLineHeight, getMaximumVerticalScroll, getSelectionEnd, getSelectionStart, getText, getTextColor, getTextLength, getTextRange, getUndoManager, getVerticalScroll, hasSelection, host, inputFocusGained, inputFocusLost, insertText, invalidateLayout, isEditableState, laidOut, lineAtContentY, lineContentOffsetX, lineHeightAt, lineTop, lineTopContent, lineVisualSegments, longPointerPress, measureColumnX, moveCaret, offsetAtPoint, paintComposingUnderline, paintContent, pasteClipboardData, performRedo, performUndo, pointerDragged, pointerReleased, rectForOffset, refreshUndoAfterState, replaceRange, replaceRange, restoreDocumentState, scrollByPixels, selectAll, selectionRects, setBackgroundColor, setComposingText, setEditableState, setEditorHost, setFontSizeDips, setSelectionColor, setSelectionRange, setText, setTextColor, uniformLineHeight`

  ### Methods inherited from class Component

  `accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, getAbsoluteX, getAbsoluteY, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, longKeyPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### CodeView

    public CodeView(EditorHost host)
    Creates a code editor view.

- ## Method Details

  - ### setLanguage

    public void setLanguage(String language)
    Sets the highlighting language.

  - ### getLanguage

    public String getLanguage()
    Returns the highlighting language id.

  - ### setTheme

    public void setTheme(String theme)
    Sets the color theme (`"light"` or `"dark"`).

  - ### setShowLineNumbers

    public void setShowLineNumbers(boolean show)
    Shows or hides the line number gutter.

  - ### setTabSize

    public void setTabSize(int tabSize)
    Sets the number of spaces used for a tab / indentation step.

  - ### setDiagnostics

    public void setDiagnostics(List<CodeDiagnostic> diagnostics)
    Sets the diagnostics to render.

  - ### setCompletionEnabled

    public void setCompletionEnabled(boolean enabled)
    Enables or disables the completion popup.

  - ### getContentLeftInset

    protected int getContentLeftInset()
    Description copied from class: `EditorView`
    Returns the left inset (padding plus any gutter) at which text starts.
    Overrides:
      `getContentLeftInset` in class `EditorView`

  - ### paintBeforeContent

    protected void paintBeforeContent(Graphics g, int originX, int originY, int firstLine, int lastLine, int lineHeight, Font f)
    Description copied from class: `EditorView`
    Hook invoked before the visible lines are drawn, used by the code editor to paint the line number gutter. `originY` is scroll adjusted so line `n` sits at `originY + n * lineHeight`.
    Overrides:
      `paintBeforeContent` in class `EditorView`

  - ### paintLine

    protected void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)
    Description copied from class: `EditorView`

    Paints a single line of text. Subclasses override to add syntax coloring; the base implementation draws the whole line in the default text color.

    ###### Parameters

    - `g`: the graphics context

    - `line`: the zero based line index

    - `text`: the line text

    - `x`: the x pixel at which the line text starts

    - `y`: the top y pixel of the line

    - `lineHeight`: the line height

    - `f`: the font

    Overrides:
      `paintLine` in class `EditorView`

  - ### documentEdited

    protected void documentEdited(int fromOffset)
    Description copied from class: `EditorView`
    Hook invoked when the document is mutated at `fromOffset`, used by feature layers (e.g. the code editor) to invalidate cached tokenization from the affected line onward.
    Overrides:
      `documentEdited` in class `EditorView`

  - ### paintLineDecorations

    protected void paintLineDecorations(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)
    Description copied from class: `EditorView`
    Hook invoked after a line's text is drawn, used by the code editor to paint diagnostic squiggles.
    Overrides:
      `paintLineDecorations` in class `EditorView`

  - ### handleTypedText

    protected boolean handleTypedText(String text)
    Description copied from class: `EditorView`

    Hook giving feature layers a chance to intercept typed text before the default insertion (used by the code editor for bracket / quote auto close, tab expansion and auto indent). Return true when the text was consumed. The default returns false.

    ###### Parameters

    - `text`: the text being typed / committed
    Overrides:
      `handleTypedText` in class `EditorView`

  - ### handleTab

    protected void handleTab(boolean dedent)
    Description copied from class: `EditorView`

    Handles a tab key press (delivered as `#KEY_TAB`). Feature layers override this for indent / dedent behavior. The default inserts a tab character on a plain tab and does nothing on a dedent (a plain editor has no indentation to remove).

    ###### Parameters

    - `dedent`: true when shift was held (shift-tab)
    Overrides:
      `handleTab` in class `EditorView`

  - ### showCompletions

    public void showCompletions(int reqId, List<CodeCompletion> items)

    Called by the backend with the provider's proposals for a request.

    ###### Parameters

    - `reqId`: the request sequence id

    - `items`: the proposals

  - ### pointerHover

    public void pointerHover(int[] x, int[] y)
    Description copied from class: `Component`

    Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

    ###### Parameters

    - `x`: the pointer x coordinate

    - `y`: the pointer y coordinate

    Overrides:
      `pointerHover` in class `Component`

  - ### paint

    public void paint(Graphics g)
    Description copied from class: `Component`

    This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

    ###### Parameters

    - `g`: the component graphics
    Specified by:
      `paint` in interface `Animation`
    Overrides:
      `paint` in class `EditorView`

  - ### pointerPressed

    public void pointerPressed(int x, int y)
    Description copied from class: `Component`

    If this Component is focused, the pointer pressed event will call this method

    ###### Parameters

    - `x`: the pointer x coordinate

    - `y`: the pointer y coordinate

    Overrides:
      `pointerPressed` in class `EditorView`

  - ### keyPressed

    public void keyPressed(int keyCode)
    Description copied from class: `Component`

    If this Component is focused, the key pressed event will call this method

    ###### Parameters

    - `keyCode`: the key code value to indicate a physical key.
    Overrides:
      `keyPressed` in class `EditorView`

  - ### keyRepeated

    public void keyRepeated(int keyCode)
    Description copied from class: `Component`

    If this Component is focused, the key repeat event will call this method.

    ###### Parameters

    - `keyCode`: the key code value to indicate a physical key.
    Overrides:
      `keyRepeated` in class `EditorView`

  - ### keyReleased

    public void keyReleased(int keyCode)
    Description copied from class: `Component`

    If this Component is focused, the key released event will call this method

    ###### Parameters

    - `keyCode`: the key code value to indicate a physical key.
    Overrides:
      `keyReleased` in class `EditorView`

  - ### onKeyCommand

    public void onKeyCommand(int command, int modifiers)
    Description copied from interface: `TextInputClient`

    Delivers a non text key command (navigation, deletion, clipboard, undo). Text producing keys are delivered through `#commitText` instead.

    ###### Parameters

    - `command`: one of the `KEY_*` constants

    - `modifiers`: a bit mask of the `MOD_*` constants

    Specified by:
      `onKeyCommand` in interface `TextInputClient`
    Overrides:
      `onKeyCommand` in class `EditorView`

  - ### onEditorAction

    public void onEditorAction(int action)
    Description copied from interface: `TextInputClient`

    Delivers the keyboard return key action (done / next / search / send) configured through `TextInputConfig`.

    ###### Parameters

    - `action`: one of the `TextInputConfig` `ACTION_*` constants
    Specified by:
      `onEditorAction` in interface `TextInputClient`
    Overrides:
      `onEditorAction` in class `EditorView`