Class CodeViewer

All Implemented Interfaces:
Animatable<CodeViewer>, CanDrop<CodeViewer>, Clickable<CodeViewer>, Draggable<CodeViewer>, Focusable<CodeViewer>, HandleHotKey<CodeViewer>, HandleMouseEvents<CodeViewer>, Scrollable<CodeViewer>, Touchable<CodeViewer>

The Code Viewer component

The code viewer component allows you to show a code snippet, or full source code on your page with the proper syntax highlighting. This component also keeps the spacing in the text, meaning tabulators and whitespaces are kept.

Supported programming languages:

  • C
  • C++
  • Java
  • C#
  • Objective C
  • Scala
  • Ceylon
  • Pascal
  • Perl
  • PHP
  • Python
  • Cython
  • Ruby

Supported database languages:

  • SQL
  • MSSQL
  • HIVE
  • MariaDB
  • Cassandra
  • PLSQL
  • PGSQL
  • GQl

Other supported languages:

  • XML
  • HTML
  • Shell script (Bash)
  • Properties files
  • INI files

Supported events:

AnimationStart AnimationEnd, Focus FocusOut FocusIn LosesFocus Click, DoubleClick, MouseDown, MouseDown, MouseLeave, MouseMove, MouseOver, MouseOut, MouseUp, Wheel, Scrollable TouchCancel, TouchEnd, TouchMove, TouchStart, Drop, DragStart, DragEnd HotKey

Since:
1.0
Author:
JBStrap
  • Constructor Details

    • CodeViewer

      public CodeViewer(String code)
      Creates a code viewer component, with the specified code with Java syntax
      Parameters:
      code - The Java sourcecode, that will be put in the component
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • CodeViewer

      public CodeViewer(String id, String code)
      Creates a code viewer component, with the specified code with Java syntax
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      code - The Java sourcecode, that will be put in the component
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • CodeViewer

      public CodeViewer(String code, CodeViewerMode mode)
      Creates a code viewer component, with the code specified in the parameter. With the mode, the language can be set as well, so it has the current syntax highlighting.
      Parameters:
      code - The code that will be put in the component
      mode - The name of the code language, used to specify the syntax highlighting used by the component. For a list of useable syntaxes, see the CodeViewerMode enum. If null, the Java syntax highlighting will be used.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
    • CodeViewer

      public CodeViewer(String id, String code, CodeViewerMode mode)
      Creates a code viewer component, with the code specified in the parameter. With the mode, the language can be set as well, so it has the current syntax highlighting.
      Parameters:
      id - The component ID. The ID specified here will appear in the HTML tag as an ID attribute. If there are multiple components displayed, that have the same ID, the ID numbers will be numbered, in the order they are displayed. (For example, if the ID is 'COMPONENT' then it will be numbered like this: COMPONENT, COMPONENT_1, COMPONENT_2 etc.)
      code - The code that will be put in the component
      mode - The name of the code language, used to specify the syntax highlighting used by the component. For a list of useable syntaxes, see the CodeViewerMode enum. If null, the Java syntax highlighting will be used.
      Throws:
      IllegalStateException - If the component is set to be both Private and Public, through an annotation.
  • Method Details

    • init

      public void init() throws JavaScriptLoadError
      Description copied from class: Component
      The component initialization method.

      Empty method, only needs to be overwritten when making a custom component, that needs to call an initializing JavaScript on the client side. The method is called by the framework after the component is drawn, but before the afterDraw() method. The use of this method during application development is not allowed. This method is meant for inner use only.

      Overrides:
      init in class Component<CodeViewer>
      Throws:
      JavaScriptLoadError - If there was a JavaScript error during the initialization.
    • setWidth

      public CodeViewer setWidth(String width)
      Sets the width of the component
      Parameters:
      width - The width, using CSS3 standard measurements. Can be specified in percentages, pixels, or any other CSS3 unit.
      Returns:
      The code viewer component
    • setWidth

      public CodeViewer setWidth(Number width)
      Sets the width of the component in pixels
      Parameters:
      width - The width of the component in pixels
      Returns:
      The code viewer component
    • getWidth

      public String getWidth()
      Gets the width of the component
      Returns:
      The width of the component in CSS3 units as a String or null, if it wasn't specified and the component isn't visible
    • setHeight

      public CodeViewer setHeight(String height)
      Sets the height of the component
      Parameters:
      height - The height, using CSS3 standard measurements. Can be specified in percentages, pixels, or any other CSS3 unit.
      Returns:
      The code viewer component
    • setHeight

      public CodeViewer setHeight(Number height)
      Sets the height of the component in pixels
      Parameters:
      height - The height of the component in pixels
      Returns:
      The code viewer component
    • getHeight

      public String getHeight()
      Gets the height of the component
      Returns:
      The height of the component in CSS3 units as a String or null, if it wasn't specified and the component isn't visible
    • setMode

      public final CodeViewer setMode(CodeViewerMode mode)
      Sets the mode (which language syntax highlighting) the component will use.
      Parameters:
      mode - The code language. For a list of useable values, see the CodeViewerMode enum
      Returns:
      The code viewer component
    • getMode

      public CodeViewerMode getMode()
      Gets the mode (which language syntax highlighting) being used by the component
      Returns:
      The name of the language being used by the component
    • writeHTML

      public boolean writeHTML(StringWriter writer)
      Description copied from class: Component
      Creates the component's HTML equivalent

      This method doesn't need to be used during application development. This method is used when developing a custom component. When creating a custom component, this method needs to be implemented. In the parameter (StringWriter class) the component's HTML equivalent must be specified, and the method has to return with a Boolean value. This boolean value determines if the component was drawn. If the user doesn't have access right to the component, or if the component couldn't be drawn, it should return with false. Otherwise, it must return with true.

      Specified by:
      writeHTML in class Component<CodeViewer>
      Returns:
      If the componentwas drawn, true, otherwise false