Class CodeView
- All Implemented Interfaces:
Animation, Editable, StyleListener, TextInputClient
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.-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSORFields inherited from interface TextInputClient
KEY_BACKSPACE, KEY_COPY, KEY_CUT, KEY_DELETE, KEY_DOWN, KEY_END, KEY_ESCAPE, KEY_HOME, KEY_LEFT, KEY_PAGE_DOWN, KEY_PAGE_UP, KEY_PASTE, KEY_REDO, KEY_RIGHT, KEY_SELECT_ALL, KEY_UNDO, KEY_UP, MOD_ALT, MOD_CTRL, MOD_SHIFT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddocumentEdited(int fromOffset) Hook invoked when the document is mutated atfromOffset, used by feature layers (e.g. the code editor) to invalidate cached tokenization from the affected line onward.protected intReturns the left inset (padding plus any gutter) at which text starts.Returns the highlighting language id.protected booleanhandleTypedText(String text) 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).voidkeyPressed(int keyCode) If this Component is focused, the key pressed event will call this methodvoidkeyReleased(int keyCode) If this Component is focused, the key released event will call this methodvoidkeyRepeated(int keyCode) If this Component is focused, the key repeat event will call this method.voidonEditorAction(int action) Delivers the keyboard return key action (done / next / search / send) configured throughTextInputConfig.voidonKeyCommand(int command, int modifiers) Delivers a non text key command (navigation, deletion, clipboard, undo).voidThis 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.protected voidpaintBeforeContent(Graphics g, int originX, int originY, int firstLine, int lastLine, int lineHeight, Font f) Hook invoked before the visible lines are drawn, used by the code editor to paint the line number gutter.protected voidPaints a single line of text.protected voidpaintLineDecorations(Graphics g, int line, String text, int x, int y, int lineHeight, Font f) Hook invoked after a line's text is drawn, used by the code editor to paint diagnostic squiggles.voidpointerHover(int[] x, int[] y) Invoked for devices where the pointer can hover without actually clicking the display.voidpointerPressed(int x, int y) If this Component is focused, the pointer pressed event will call this methodvoidsetCompletionEnabled(boolean enabled) Enables or disables the completion popup.voidsetDiagnostics(List<CodeDiagnostic> diagnostics) Sets the diagnostics to render.voidsetLanguage(String language) Sets the highlighting language.voidsetShowLineNumbers(boolean show) Shows or hides the line number gutter.voidsetTabSize(int tabSize) Sets the number of spaces used for a tab / indentation step.voidSets the color theme ("light"or"dark").voidshowCompletions(int reqId, List<CodeCompletion> items) Called by the backend with the provider's proposals for a request.Methods inherited from class EditorView
animate, baseFontSizePixels, blur, calcPreferredSize, captureDocumentState, columnAtX, commitText, contentTotalHeight, contentWidth, copySelection, deleteSurroundingText, documentReplaced, documentReset, finishComposing, firstVisibleLine, focusGained, focusLost, getCaretOffset, getCaretRect, getConfig, getDocument, getEditingState, getEditorFont, getHorizontalScroll, getLineHeight, getMaximumVerticalScroll, getSelectionEnd, getSelectionStart, getText, getTextColor, getTextLength, getTextRange, getUndoManager, getVerticalScroll, hasSelection, host, inputFocusGained, inputFocusLost, insertText, invalidateLayout, isEditableState, laidOut, lineAtContentY, lineContentOffsetX, lineHeightAt, lineTop, lineTopContent, lineVisualSegments, longPointerPress, measureColumnX, moveCaret, offsetAtPoint, paintComposingUnderline, paintContent, pasteClipboardData, performRedo, performUndo, pointerDragged, pointerReleased, rectForOffset, refreshUndoAfterState, replaceRange, replaceRange, restoreDocumentState, scrollByPixels, selectAll, selectionRects, setBackgroundColor, setComposingText, setEditableState, setFontSizeDips, setSelectionColor, setSelectionRange, setText, setTextColor, uniformLineHeightMethods inherited from class Component
accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, cancelRepaints, clearClientProperties, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, dragInitiated, drawDraggedImage, drop, fireClicked, getAbsoluteX, getAbsoluteY, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBottomGap, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getGridPosX, getGridPosY, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getSideGap, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUIManager, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initLaf, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isEnabled, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollableX, isScrollableY, isScrollVisible, isSelectableInteraction, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, longKeyPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, paramString, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, putClientProperty, refreshTheme, refreshTheme, refreshTheme, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCellRenderer, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setEnabled, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setShouldCalcPreferredSize, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains
-
Constructor Details
-
CodeView
Creates a code editor view.
-
-
Method Details
-
setLanguage
Sets the highlighting language. -
getLanguage
Returns the highlighting language id. -
setTheme
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
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:EditorViewReturns the left inset (padding plus any gutter) at which text starts.- Overrides:
getContentLeftInsetin classEditorView
-
paintBeforeContent
protected void paintBeforeContent(Graphics g, int originX, int originY, int firstLine, int lastLine, int lineHeight, Font f) Description copied from class:EditorViewHook invoked before the visible lines are drawn, used by the code editor to paint the line number gutter.originYis scroll adjusted so linensits atoriginY + n * lineHeight.- Overrides:
paintBeforeContentin classEditorView
-
paintLine
Description copied from class:EditorViewPaints 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:
paintLinein classEditorView
-
-
documentEdited
protected void documentEdited(int fromOffset) Description copied from class:EditorViewHook invoked when the document is mutated atfromOffset, used by feature layers (e.g. the code editor) to invalidate cached tokenization from the affected line onward.- Overrides:
documentEditedin classEditorView
-
paintLineDecorations
protected void paintLineDecorations(Graphics g, int line, String text, int x, int y, int lineHeight, Font f) Description copied from class:EditorViewHook invoked after a line's text is drawn, used by the code editor to paint diagnostic squiggles.- Overrides:
paintLineDecorationsin classEditorView
-
handleTypedText
Description copied from class:EditorViewHook 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:
handleTypedTextin classEditorView
-
showCompletions
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:ComponentInvoked 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:
pointerHoverin classComponent
-
-
paint
Description copied from class:ComponentThis 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:
paintin interfaceAnimation- Overrides:
paintin classEditorView
-
pointerPressed
public void pointerPressed(int x, int y) Description copied from class:ComponentIf this Component is focused, the pointer pressed event will call this method
Parameters
-
x: the pointer x coordinate -
y: the pointer y coordinate
- Overrides:
pointerPressedin classEditorView
-
-
keyPressed
public void keyPressed(int keyCode) Description copied from class:ComponentIf this Component is focused, the key pressed event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyPressedin classEditorView
-
keyRepeated
public void keyRepeated(int keyCode) Description copied from class:ComponentIf this Component is focused, the key repeat event will call this method.
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyRepeatedin classEditorView
-
keyReleased
public void keyReleased(int keyCode) Description copied from class:ComponentIf this Component is focused, the key released event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyReleasedin classEditorView
-
onKeyCommand
public void onKeyCommand(int command, int modifiers) Description copied from interface:TextInputClientDelivers a non text key command (navigation, deletion, clipboard, undo). Text producing keys are delivered through
#commitTextinstead.Parameters
-
command: one of theKEY_*constants -
modifiers: a bit mask of theMOD_*constants
- Specified by:
onKeyCommandin interfaceTextInputClient- Overrides:
onKeyCommandin classEditorView
-
-
onEditorAction
public void onEditorAction(int action) Description copied from interface:TextInputClientDelivers the keyboard return key action (done / next / search / send) configured through
TextInputConfig.Parameters
action: one of theTextInputConfigACTION_*constants
- Specified by:
onEditorActionin interfaceTextInputClient- Overrides:
onEditorActionin classEditorView
-