Package org.zkoss.zul

Class Codeeditor

java.lang.Object
org.zkoss.zk.ui.AbstractComponent
org.zkoss.zk.ui.HtmlBasedComponent
org.zkoss.zul.impl.XulElement
org.zkoss.zul.Codeeditor
All Implemented Interfaces:
Serializable, Cloneable, org.zkoss.zk.ui.Component, org.zkoss.zk.ui.ext.Disable, org.zkoss.zk.ui.ext.Readonly, org.zkoss.zk.ui.ext.Scope, org.zkoss.zk.ui.sys.ComponentCtrl

public class Codeeditor extends XulElement implements org.zkoss.zk.ui.ext.Disable, org.zkoss.zk.ui.ext.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:
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    org.zkoss.zk.ui.HtmlBasedComponent.ExtraCtrl

    Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent

    org.zkoss.zk.ui.AbstractComponent.Children, org.zkoss.zk.ui.AbstractComponent.ForwardInfo, org.zkoss.zk.ui.AbstractComponent.TargetInfo
  • Field Summary

    Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    _zclass

    Fields inherited from interface org.zkoss.zk.ui.Component

    APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE

    Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl

    AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the editor color scheme.
    Returns the syntax-highlight language.
    int
    Returns the number of columns a tab character is rendered as.
    Returns the editor content.
    protected boolean
     
    boolean
    Returns whether the editor is disabled.
    boolean
    Returns whether the gutter line numbers are shown.
    boolean
    Returns whether the editor is read-only.
    protected void
    renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer)
     
    void
    service(org.zkoss.zk.au.AuRequest request, boolean everError)
     
    void
    setColorScheme(String colorScheme)
    Sets the editor color scheme.
    void
    setDisabled(boolean disabled)
    Sets whether the editor is disabled.
    void
    setLanguage(String language)
    Sets the syntax-highlight language.
    void
    setLineNumbers(boolean lineNumbers)
    Sets whether the gutter line numbers are shown.
    void
    setReadonly(boolean readonly)
    Sets whether the editor is read-only.
    void
    setTabSize(int tabSize)
    Sets how many columns a tab character is rendered as.
    void
    Sets the editor content.

    Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent

    addSclass, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getSkeleton, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZclass, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setSkeleton, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly

    Methods inherited from class org.zkoss.zk.ui.AbstractComponent

    addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getStubonlyDescendants, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setStubonlyDescendants, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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:
      org.zkoss.zk.ui.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 org.zkoss.zk.ui.ext.Readonly
    • setReadonly

      public void setReadonly(boolean readonly)
      Sets whether the editor is read-only.
      Specified by:
      setReadonly in interface org.zkoss.zk.ui.ext.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 org.zkoss.zk.ui.ext.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 org.zkoss.zk.ui.ext.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:
      org.zkoss.zk.ui.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:
      org.zkoss.zk.ui.WrongValueException - if colorScheme is non-null and neither light nor dark.
      Since:
      11.0.0
    • isChildable

      protected boolean isChildable()
      Overrides:
      isChildable in class org.zkoss.zk.ui.AbstractComponent
    • renderProperties

      protected void renderProperties(org.zkoss.zk.ui.sys.ContentRenderer renderer) throws IOException
      Overrides:
      renderProperties in class XulElement
      Throws:
      IOException
    • service

      public void service(org.zkoss.zk.au.AuRequest request, boolean everError)
      Specified by:
      service in interface org.zkoss.zk.ui.sys.ComponentCtrl
      Overrides:
      service in class org.zkoss.zk.ui.HtmlBasedComponent