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
-
Field Summary
Fields inherited from class com.jbstrap.ui.Component
animation, attributes, backgroundColor, borderColor, color, defaultHotKeyHandler, handlers, hotKeys, styleClasses, textAlign, toolTip, toolTipPosition
-
Constructor Summary
ConstructorDescriptionCodeViewer
(String code) Creates a code viewer component, with the specified code with Java syntaxCodeViewer
(String code, CodeViewerMode mode) Creates a code viewer component, with the code specified in the parameter.CodeViewer
(String id, String code) Creates a code viewer component, with the specified code with Java syntaxCodeViewer
(String id, String code, CodeViewerMode mode) Creates a code viewer component, with the code specified in the parameter. -
Method Summary
Modifier and TypeMethodDescriptionGets the height of the componentgetMode()
Gets the mode (which language syntax highlighting) being used by the componentgetWidth()
Gets the width of the componentvoid
init()
The component initialization method.Sets the height of the component in pixelsSets the height of the componentfinal CodeViewer
setMode
(CodeViewerMode mode) Sets the mode (which language syntax highlighting) the component will use.Sets the width of the component in pixelsSets the width of the componentboolean
writeHTML
(StringWriter writer) Creates the component's HTML equivalentMethods inherited from class com.jbstrap.ui.Component
_hide, _setAttribute, addAllowedRole, addComponent, addComponent, addComponents, addDeniedRole, addHandler, addStyle, addStyleClass, addStyleClasses, afterDraw, clearfix, closeTag, combinateAccess, containsStyle, containsStyleClass, draw, drawSubComponents, error, flattendComponentTree, getAccess, getAccessMode, getAllowedRoles, getAttribute, getAttributes, getBackgroundColor, getBorderColor, getClient, getComponentById, getComponents, getComponents, getComponentsByClass, getData, getDeniedRoles, getHandlers, getId, getLanguageCode, getName, getParent, getParent, getRegisteredEvents, getStyle, getStyleClasses, getTextAlign, getTextColor, getToolTip, getToolTipPosition, getTypeName, getUI, insertComponentAfter, insertComponentBefore, isAccess, isDrawn, isEnabled, isEventBubbling, isVisible, onHide, onHotKeyEventHandler, onShow, openTag, redraw, removeAllComponents, removeAllowedRole, removeAllStyleClasses, removeAttribute, removeComponent, removeComponent, removeComponents, removeDeniedRole, removeHandler, removeStyle, removeStyle, removeStyleClass, removeStyleClasses, replaceComponent, replaceStyleClass, runAfterDraw, runJavaScript, runJavaScript, runJavaScript, runOnHide, runOnShow, say, setAttribute, setBackgroundColor, setBorder, setBorderColor, setData, setDisplayType, setEnabled, setEventBubbling, setFlex, setFloating, setHeight100, setHeight25, setHeight50, setHeight75, setHeightAuto, setLanguage, setMargin, setName, setOverflow, setPadding, setParent, setScrollable, setSelectionType, setShadow, setStyle, setTextAlign, setTextColor, setToolTip, setToolTipPosition, setVisible, setWidth100, setWidth25, setWidth50, setWidth75, setWidthAuto, showNotification, showNotification, showProcessIndicator, toggleStyleClass
Methods inherited from class com.jbstrap.core.messagebus.MessageBus
closeMessageBus, messageBusOpened, openMessageBus, renewSubscription, sendMessageToMessageBus, subscribeMessageBus, unsubscribeAllListeners, unsubscribeMessageBus
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jbstrap.ui.Animatable
addAnimationEndHandler, addAnimationStartHandler, getAnimation, removeAnimation, setAnimation
Methods inherited from interface com.jbstrap.ui.CanDrop
addDropEventHandler
Methods inherited from interface com.jbstrap.ui.Clickable
addClickHandler, addDoubleClickHandler
Methods inherited from interface com.jbstrap.ui.Draggable
addDragEndEventHandler, addDragStartEventHandler, setDraggable
Methods inherited from interface com.jbstrap.ui.Focusable
addFocusHandler, addFocusInHandler, addFocusOutHandler, addLosesFocusHandler, setFocus
Methods inherited from interface com.jbstrap.ui.HandleHotKey
addHotKey, addHotKey, removeHotKey, removeHotKeys
Methods inherited from interface com.jbstrap.ui.HandleMouseEvents
addMouseDownHandler, addMouseEnterHandler, addMouseLeaveHandler, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler
Methods inherited from interface com.jbstrap.ui.Scrollable
addScrollHandler
Methods inherited from interface com.jbstrap.ui.Touchable
addTouchCancelHandler, addTouchEndHandler, addTouchMoveHandler, addTouchStartHandler
-
Constructor Details
-
CodeViewer
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
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
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 componentmode
- The name of the code language, used to specify the syntax highlighting used by the component. For a list of useable syntaxes, see theCodeViewerMode
enum. Ifnull
, the Java syntax highlighting will be used.- Throws:
IllegalStateException
- If the component is set to be both Private and Public, through an annotation.
-
CodeViewer
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 componentmode
- The name of the code language, used to specify the syntax highlighting used by the component. For a list of useable syntaxes, see theCodeViewerMode
enum. Ifnull
, 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
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 classComponent<CodeViewer>
- Throws:
JavaScriptLoadError
- If there was a JavaScript error during the initialization.
-
setWidth
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
Sets the width of the component in pixels- Parameters:
width
- The width of the component in pixels- Returns:
- The code viewer component
-
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
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
Sets the height of the component in pixels- Parameters:
height
- The height of the component in pixels- Returns:
- The code viewer component
-
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
Sets the mode (which language syntax highlighting) the component will use.- Parameters:
mode
- The code language. For a list of useable values, see theCodeViewerMode
enum- Returns:
- The code viewer component
-
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
Description copied from class:Component
Creates the component's HTML equivalentThis 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 withfalse
. Otherwise, it must return withtrue
.- Specified by:
writeHTML
in classComponent<CodeViewer>
- Returns:
- If the componentwas drawn,
true
, otherwisefalse
-