Package org.zkoss.zul

Class Codeeditor

All Implemented Interfaces:
Serializable, Cloneable, Component, Disable, Readonly, Scope, ComponentCtrl

public class Codeeditor extends XulElement implements Disable, Readonly
A code editor that loads and edits source code with syntax highlighting.

The Community Edition build provides basic editing: setting/loading the content (setValue(java.lang.String)), choosing the highlight language (setLanguage(java.lang.String)), toggling read-only (isReadonly()) and line numbers (setLineNumbers(boolean)), and an optional light/dark editor color scheme (setColorScheme(java.lang.String)). Edits are reported to the server through the standard onChange/onChanging events carrying an InputEvent, so value participates in data binding the same way as other input components.

Advanced capabilities (autocomplete, lint, code folding, multi-cursor, search/replace, diff) are not part of the CE build; they are layered on by the EE module through a client-side extension hook, so an application can adopt them later without changing the component or the ZUL.

Since:
11.0.0
Author:
peakerlee
See Also:
  • Constructor Details

    • Codeeditor

      public Codeeditor()
    • Codeeditor

      public Codeeditor(String value)
  • Method Details

    • getValue

      public String getValue()
      Returns the editor content.

      Default: an empty string.

    • setValue

      public void setValue(String value)
      Sets the editor content.
      Parameters:
      value - the source code; null is treated as an empty string.
      Since:
      11.0.0
    • getLanguage

      public String getLanguage()
      Returns the syntax-highlight language.

      Default: "plain".

    • setLanguage

      public void setLanguage(String language)
      Sets the syntax-highlight language.
      Parameters:
      language - one of plain, html, xml, java, javascript, css, json, sql, markdown; null resets it to the default "plain".
      Throws:
      WrongValueException - if language is non-null and not an accepted token.
      Since:
      11.0.0
    • isReadonly

      public boolean isReadonly()
      Returns whether the editor is read-only.

      Default: false.

      Specified by:
      isReadonly in interface Readonly
    • setReadonly

      public void setReadonly(boolean readonly)
      Sets whether the editor is read-only.
      Specified by:
      setReadonly in interface Readonly
      Parameters:
      readonly - whether to forbid editing the content.
      Since:
      11.0.0
    • isDisabled

      public boolean isDisabled()
      Returns whether the editor is disabled.

      Default: false.

      Specified by:
      isDisabled in interface Disable
    • setDisabled

      public void setDisabled(boolean disabled)
      Sets whether the editor is disabled. A disabled editor cannot be edited or focused and is shown dimmed; unlike setReadonly(boolean), which keeps the content focusable and selectable.
      Specified by:
      setDisabled in interface Disable
      Parameters:
      disabled - whether to disable the editor.
      Since:
      11.0.0
    • isLineNumbers

      public boolean isLineNumbers()
      Returns whether the gutter line numbers are shown.

      Default: true.

    • setLineNumbers

      public void setLineNumbers(boolean lineNumbers)
      Sets whether the gutter line numbers are shown.
      Parameters:
      lineNumbers - whether to show the line-number gutter.
      Since:
      11.0.0
    • getTabSize

      public int getTabSize()
      Returns the number of columns a tab character is rendered as.

      Default: 4.

    • setTabSize

      public void setTabSize(int tabSize)
      Sets how many columns a tab character is rendered as. The indent character itself is always a tab; this only changes its displayed width.
      Parameters:
      tabSize - a positive column count; the default is 4.
      Throws:
      WrongValueException - if tabSize is less than 1.
      Since:
      11.0.0
    • getColorScheme

      public String getColorScheme()
      Returns the editor color scheme.

      Default: "light".

    • setColorScheme

      public void setColorScheme(String colorScheme)
      Sets the editor color scheme. This is the editor's own light/dark surface, not the page theme selected through Themes.
      Parameters:
      colorScheme - light or dark; null resets it to the default "light".
      Throws:
      WrongValueException - if colorScheme is non-null and neither light nor dark.
      Since:
      11.0.0
    • isChildable

      protected boolean isChildable()
      Description copied from class: AbstractComponent
      Returns whether this component can have a child.

      Default: return true (means it can have children).

      Overrides:
      isChildable in class AbstractComponent
    • renderProperties

      protected void renderProperties(ContentRenderer renderer) throws IOException
      Description copied from class: HtmlBasedComponent
      Renders the content of this component, excluding the enclosing tags and children.

      See also ZK Client-side Reference: Property Rendering

      Overrides:
      renderProperties in class XulElement
      Throws:
      IOException
    • service

      public void service(AuRequest request, boolean everError)
      Description copied from class: HtmlBasedComponent
      Processes an AU request.

      Default: it handles onClick, onDoubleClick, onRightClick onMove, onSize, onZIndex.

      Specified by:
      service in interface ComponentCtrl
      Overrides:
      service in class HtmlBasedComponent
      everError - whether any error ever occurred before processing this request.
      See Also: