Class 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.
  • 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
    • 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