public class CodeView
- Object
- Component
- EditorView
- CodeView
ImplementsAnimation, 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.Constructors
public CodeView(EditorHost host) | Creates a code editor view. |
Methods
public void setLanguage(String language) | Sets the highlighting language. |
public String getLanguage() | Returns the highlighting language id. |
public void setTheme(String theme) | Sets the color theme ("light" or "dark"). |
public void setShowLineNumbers(boolean show) | Shows or hides the line number gutter. |
public void setTabSize(int tabSize) | Sets the number of spaces used for a tab / indentation step. |
public void setDiagnostics(List<CodeDiagnostic> diagnostics) | Sets the diagnostics to render. |
public void setProtectedRegionMarkers(String startMarker, String endMarker) | Protects every range delimited by matching marker strings from user edits. |
protected void replaceRange(int start, int end, String text, boolean record) | Replaces the range [start, end) with text, updating the caret, history and platform input state. |
protected boolean isEditAllowed(int start, int end) | Refuses edits that fall inside a protected region, whichever path they arrive through. |
public void setCompletionEnabled(boolean enabled) | Enables or disables the completion popup. |
protected int getContentLeftInset() | Returns the left inset (padding plus any gutter) at which text starts. |
protected void paintBeforeContent(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 void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f) | Paints a single line of text. |
protected void documentEdited(int fromOffset) | Hook invoked when the document is mutated at fromOffset, used by feature layers (e.g. the code editor) to invalidate cached tokenization from the affected line onward. |
protected void paintLineDecorations(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. |
protected boolean handleTypedText(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). |
protected void handleTab(boolean dedent) | Handles a tab key press (delivered as #KEY_TAB). |
public void showCompletions(int reqId, List<CodeCompletion> items) | Called by the backend with the provider’s proposals for a request. |
public void pointerHover(int[] x, int[] y) | Invoked for devices where the pointer can hover without actually clicking the display. |
public void paint(Graphics g) | This 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. |
public void pointerPressed(int x, int y) | If this Component is focused, the pointer pressed event will call this method |
public void keyPressed(int keyCode) | If this Component is focused, the key pressed event will call this method |
public void keyRepeated(int keyCode) | If this Component is focused, the key repeat event will call this method. |
public void keyReleased(int keyCode) | If this Component is focused, the key released event will call this method |
public void onKeyCommand(int command, int modifiers) | Delivers a non text key command (navigation, deletion, clipboard, undo). |
public void onEditorAction(int action) | Delivers the keyboard return key action (done / next / search / send) configured through TextInputConfig. |
Inherited fields
From Component
DEFAULT_CURSOR, CROSSHAIR_CURSOR, TEXT_CURSOR, WAIT_CURSOR, SW_RESIZE_CURSOR, SE_RESIZE_CURSOR, NW_RESIZE_CURSOR, NE_RESIZE_CURSOR, N_RESIZE_CURSOR, S_RESIZE_CURSOR, W_RESIZE_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, MOVE_CURSOR, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_Y, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_IMMEDIATELY_DRAG_XY, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET, BRB_OTHER, CENTER, TOP, LEFT, BOTTOM, RIGHT, BASELINE
Inherited methods
From EditorView
scrollByPixels, setEditorHost, getDocument, getUndoManager, getCaretOffset, setBackgroundColor, setTextColor, setSelectionColor, getTextColor, setText, getText, setEditableState, isEditableState, blur, baseFontSizePixels, setFontSizeDips, getEditorFont, getLineHeight, lineHeightAt, uniformLineHeight, invalidateLayout, lineTopContent, contentTotalHeight, lineAtContentY, contentWidth, hasSelection, getSelectionStart, getSelectionEnd, longPointerPress, paintContent, paintComposingUnderline, lineTop, firstVisibleLine, getHorizontalScroll, getVerticalScroll, getMaximumVerticalScroll, offsetAtPoint, consumesRawTextInput, documentReplaced, documentReset, captureDocumentState, restoreDocumentState, refreshUndoAfterState, insertText, host, deleteBackward, moveCaret, selectAll, copySelection, cutSelection, pasteClipboard, pasteClipboardData, lineContentOffsetX, measureColumnX, columnAtX, lineVisualSegments, laidOut, focusGained, focusLost, deinitialize, animate, pointerDragged, pointerReleased, commitText, setComposingText, finishComposing, deleteSurroundingText, performUndo, performRedo, getEditingState, getCaretRect, rectForOffset, getTextLength, getTextRange, selectionRects, replaceRange, setSelectionRange, getConfig, inputFocusGained, inputFocusLost, calcPreferredSize
From Component
setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, pinchReleased, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, pointerPressed, isDragAndDropOperation, pointerReleased, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, cancelRepaints, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip
Constructor details
CodeView
public CodeView(EditorHost host)Method details
setLanguage
public void setLanguage(String language)getLanguage
public String getLanguage()setTheme
public void setTheme(String theme)"light" or "dark").setShowLineNumbers
public void setShowLineNumbers(boolean show)setTabSize
public void setTabSize(int tabSize)setDiagnostics
public void setDiagnostics(List<CodeDiagnostic> diagnostics)setProtectedRegionMarkers
public void setProtectedRegionMarkers(String startMarker, String endMarker)replaceRange
protected void replaceRange(int start, int end, String text, boolean record)[start, end) with text, updating the caret, history and platform input
state.Parameters
startint- inclusive start offset
endint- exclusive end offset
textString- the replacement text (may be empty)
recordboolean- true to record the mutation for undo
isEditAllowed
protected boolean isEditAllowed(int start, int end)#replaceRange(int, int, String, boolean), so checking only there let a composing keyboard
insert provisional text into generated source that is meant to be read only.Parameters
startint- inclusive start offset of the edit
endintexclusive end offset of the edit
Returns: true when the edit may proceed
setCompletionEnabled
public void setCompletionEnabled(boolean enabled)getContentLeftInset
protected int getContentLeftInset()paintBeforeContent
protected void paintBeforeContent(Graphics g, int originX, int originY, int firstLine, int lastLine, int lineHeight, Font f)originY is scroll adjusted so line n sits at originY + n * lineHeight.paintLine
protected void paintLine(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)Parameters
gGraphics- the graphics context
lineint- the zero based line index
textString- the line text
xint- the x pixel at which the line text starts
yint- the top y pixel of the line
lineHeightint- the line height
fFont- the font
documentEdited
protected void documentEdited(int fromOffset)fromOffset, used by feature layers (e.g. the code
editor) to invalidate cached tokenization from the affected line onward.paintLineDecorations
protected void paintLineDecorations(Graphics g, int line, String text, int x, int y, int lineHeight, Font f)handleTypedText
protected boolean handleTypedText(String text)Parameters
textString- the text being typed / committed
handleTab
protected void handleTab(boolean dedent)#KEY_TAB). Feature layers override this for indent /
dedent behavior. The default inserts a tab character on a plain tab and does nothing on a
dedent (a plain editor has no indentation to remove).Parameters
dedentboolean- true when shift was held (shift-tab)
showCompletions
public void showCompletions(int reqId, List<CodeCompletion> items)Parameters
reqIdint- the request sequence id
itemsList<CodeCompletion>- the proposals
pointerHover
public void pointerHover(int[] x, int[] y)Parameters
xint[]- the pointer x coordinate
yint[]- the pointer y coordinate
paint
public void paint(Graphics g)Parameters
gGraphics- the component graphics
pointerPressed
public void pointerPressed(int x, int y)Parameters
xint- the pointer x coordinate
yint- the pointer y coordinate
keyPressed
public void keyPressed(int keyCode)Parameters
keyCodeint- the key code value to indicate a physical key.
keyRepeated
public void keyRepeated(int keyCode)Parameters
keyCodeint- the key code value to indicate a physical key.
keyReleased
public void keyReleased(int keyCode)Parameters
keyCodeint- the key code value to indicate a physical key.
onKeyCommand
public void onKeyCommand(int command, int modifiers)#commitText instead.Parameters
commandint- one of the
KEY_*constants modifiersint- a bit mask of the
MOD_*constants
onEditorAction
public void onEditorAction(int action)TextInputConfig.Parameters
actionint- one of the
TextInputConfigACTION_*constants