Class AceEditor
java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
cn.mapway.document.ui.client.component.ace.AceEditor
- All Implemented Interfaces:
com.google.gwt.event.logical.shared.HasAttachHandlers,com.google.gwt.event.shared.HasHandlers,com.google.gwt.user.client.EventListener,com.google.gwt.user.client.TakesValue<String>,com.google.gwt.user.client.ui.HasText,com.google.gwt.user.client.ui.HasVisibility,com.google.gwt.user.client.ui.IsRenderable,com.google.gwt.user.client.ui.IsWidget,com.google.gwt.user.client.ui.RequiresResize
public class AceEditor
extends com.google.gwt.user.client.ui.Composite
implements com.google.gwt.user.client.ui.RequiresResize, com.google.gwt.user.client.ui.HasText, com.google.gwt.user.client.TakesValue<String>
A GWT widget for the Ajax.org Code Editor (ACE).
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled -
Field Summary
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotation(int row, int column, String text, AceAnnotationType type) Add an annotation to a the localannotationsJsArray<AceAnnotation>, but does not set it on the editorvoidaddCommand(AceCommandDescription description) Add user defined command.static voidaddCompletionProvider(AceCompletionProvider provider) Add anAceCompletionProviderto provide custom code completions.intaddFloatingMarker(AceRange range, String clazz, AceMarkerType type) Adds a floating marker into this editor (the marker follows lines changes as insertions, suppressions...).intaddMarker(AceRange range, String clazz, AceMarkerType type, boolean inFront) Adds a static marker into this editor.voidaddOnChangeHandler(AceEditorCallback callback) Register a handler for change events generated by the editor.voidRegister a handler for cursor position change events generated by the editor.voidClear any annotations from the editor and reset the localannotationsJsArray<AceAnnotation>voiddestroy()Cleans up the entire editor.voidexecCommand(AceCommand command) Execute a command with no arguments.voidexecCommand(AceCommand command, AceCommandArgs args) Execute a command with arguments (in case args is not null).voidexecCommand(String command) Execute a command possibly containing string argument.voidexecCommand(String command, AceCommandArgs args) Execute a command with arguments (in case args is not null).voidexecCommand(String command, String arg) Execute a command with arguments (in case args is not null).voidfocus()Causes the editor to gain input focus.getCommandDescription(String command) Construct java wrapper for registered Ace command.Get the current cursor position.intGive font sizeintgetIndexFromPosition(AceEditorCursorPosition position) Gets the given document position as a zero-based index.getLine(int row) Get the line of text at the given row number.intRetrieves the number of lines in the editor.Gets all the displayed markers.getPositionFromIndex(int index) Gets a document position from a supplied zero-based index.Prepare a wrapper around Ace Selection object.getText()Get the complete text in the editor as a String.getValue()voidgotoLine(int line) Go to given line.voidinitializeCommandLine(AceCommandLine cmdLine) Bind command line and editor.voidinsertAtCursor(String text) Insert given text at the cursor.List names of all Ace commands.voidonResize()voidCall this to force the editor contents to be redisplayed.static voidRemoves all existing completers from the langtools
This can be used to disable all completers including local completers, which can be very useful when completers are used on very large files (as the local completer tokenizes every word to put in the selected list).
NOTE: This method may be removed, and replaced with another solution.voidRemove all the displayed markers.voidremoveCommand(AceCommand command) Remove a command from the editor.voidremoveCommandByName(String command) Remove commands, that may not be required, from the editorvoidremoveMarker(int markerId) Removes the marker with the specified ID.voidSet any annotations which have been added viaaddAnnotationon the editorvoidsetAutocompleteEnabled(boolean b) Set whether or not autocomplete is enabled.voidsetFontSize(int fontSize) Set integer font size.voidsetFontSize(String fontSize) Set font size.voidsetHighlightSelectedWord(boolean highlightSelectedWord) Set or unset highlighting of currently selected word.voidsetHScrollBarAlwaysVisible(boolean hScrollBarAlwaysVisible) Set whether or not the horizontal scrollbar is always visible.voidsetMode(AceEditorMode mode) Set the mode.voidsetModeByName(String shortModeName) Set the mode by name.voidsetReadOnly(boolean readOnly) Set or unset read-only mode.voidsetShowGutter(boolean showGutter) Set whether or not the gutter is shown.voidsetShowPrintMargin(boolean showPrintMargin) Set or unset the visibility of the print margin.voidsetTabSize(int tabSize) Set tab size.voidSet the complete text in the editor from a String.voidsetTheme(AceEditorTheme theme) Set the theme.voidsetThemeByName(String themeName) Set the theme by name.voidsetUseSoftTabs(boolean useSoftTabs) Set whether or not soft tabs should be used.voidsetUseWorker(boolean useWorker) Enable a worker for the current session.voidsetUseWrapMode(boolean useWrapMode) Set whether to use wrap mode or notvoidvoidCall this method to start the editor.Methods inherited from class com.google.gwt.user.client.ui.Composite
claimElement, getWidget, initializeClaimedElement, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidgetMethods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEventsMethods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
-
Constructor Details
-
AceEditor
public AceEditor()Preferred constructor. -
AceEditor
Deprecated.Do not use this constructor: just use the default constructor.- Parameters:
unused- this parameter is ignored
-
-
Method Details
-
startEditor
public void startEditor()Call this method to start the editor. Make sure that the widget has been attached to the DOM tree before calling this method. -
redisplay
public void redisplay()Call this to force the editor contents to be redisplayed. There seems to be a problem when an AceEditor is embedded in a LayoutPanel: the editor contents don't appear, and it refuses to accept focus and mouse events, until the browser window is resized. Calling this method works around the problem by forcing the underlying editor to redisplay itself fully. (?) -
destroy
public void destroy()Cleans up the entire editor. -
setTheme
Set the theme.- Parameters:
theme- the theme (one of the values in theAceEditorThemeenumeration)
-
setThemeByName
Set the theme by name.- Parameters:
themeName- the theme name (e.g., "twilight")
-
setMode
Set the mode.- Parameters:
mode- the mode (one of the values in theAceEditorModeenumeration)
-
setModeByName
Set the mode by name.- Parameters:
shortModeName- name of mode (e.g., "eclipse")
-
setUseWorker
public void setUseWorker(boolean useWorker) Enable a worker for the current session.- Parameters:
useWorker- true to enable a worker otherwise false
-
addOnChangeHandler
Register a handler for change events generated by the editor.- Parameters:
callback- the change event handler
-
addOnCursorPositionChangeHandler
Register a handler for cursor position change events generated by the editor.- Parameters:
callback- the cursor position change event handler
-
getFontSize
public int getFontSize()Give font size- Returns:
- font size
-
setFontSize
Set font size.- Parameters:
fontSize- the font size to set, e.g., "16px"
-
setFontSize
public void setFontSize(int fontSize) Set integer font size.- Parameters:
fontSize- the font size to set, e.g., 16
-
getText
Get the complete text in the editor as a String.- Specified by:
getTextin interfacecom.google.gwt.user.client.ui.HasText- Returns:
- the text in the editor
-
focus
public void focus()Causes the editor to gain input focus. -
getLineCount
public int getLineCount()Retrieves the number of lines in the editor.- Returns:
- The number of lines in the editor.
-
setText
Set the complete text in the editor from a String.- Specified by:
setTextin interfacecom.google.gwt.user.client.ui.HasText- Parameters:
text- the text to set in the editor
-
getLine
Get the line of text at the given row number.- Parameters:
row- the row number- Returns:
- the line of text at that row number
-
insertAtCursor
Insert given text at the cursor.- Parameters:
text- text to insert at the cursor
-
getCursorPosition
Get the current cursor position.- Returns:
- the current cursor position
-
getIndexFromPosition
Gets the given document position as a zero-based index.- Parameters:
position- the position to obtain the absolute index of (base zero)- Returns:
- An index to the current location in the document
-
getPositionFromIndex
Gets a document position from a supplied zero-based index.- Parameters:
index- (base zero)- Returns:
- A position object showing the row and column of the supplied index in the document
-
setUseSoftTabs
public void setUseSoftTabs(boolean useSoftTabs) Set whether or not soft tabs should be used.- Parameters:
useSoftTabs- true if soft tabs should be used, false otherwise
-
setTabSize
public void setTabSize(int tabSize) Set tab size. (Default is 4.)- Parameters:
tabSize- the tab size to set
-
gotoLine
public void gotoLine(int line) Go to given line.- Parameters:
line- the line to go to
-
setHScrollBarAlwaysVisible
public void setHScrollBarAlwaysVisible(boolean hScrollBarAlwaysVisible) Set whether or not the horizontal scrollbar is always visible.- Parameters:
hScrollBarAlwaysVisible- true if the horizontal scrollbar is always visible, false if it is hidden when not needed
-
setShowGutter
public void setShowGutter(boolean showGutter) Set whether or not the gutter is shown.- Parameters:
showGutter- true if the gutter should be shown, false if it should be hidden
-
setReadOnly
public void setReadOnly(boolean readOnly) Set or unset read-only mode.- Parameters:
readOnly- true if editor should be set to readonly, false if the editor should be set to read-write
-
setHighlightSelectedWord
public void setHighlightSelectedWord(boolean highlightSelectedWord) Set or unset highlighting of currently selected word.- Parameters:
highlightSelectedWord- true to highlight currently selected word, false otherwise
-
setShowPrintMargin
public void setShowPrintMargin(boolean showPrintMargin) Set or unset the visibility of the print margin.- Parameters:
showPrintMargin- true if the print margin should be shown, false otherwise
-
addAnnotation
Add an annotation to a the localannotationsJsArray<AceAnnotation>, but does not set it on the editor- Parameters:
row- to which the annotation should be addedcolumn- to which the annotation appliestext- to display as a tooltip with the annotationtype- to be displayed (one of the values in theAceAnnotationTypeenumeration)
-
setAnnotations
public void setAnnotations()Set any annotations which have been added viaaddAnnotationon the editor -
clearAnnotations
public void clearAnnotations()Clear any annotations from the editor and reset the localannotationsJsArray<AceAnnotation> -
removeCommand
Remove a command from the editor.- Parameters:
command- the command (one of the values in theAceCommandenumeration)
-
execCommand
Execute a command with no arguments. SeeAceCommandvalues for example.- Parameters:
command- the command (one of the values in theAceCommandenumeration)
-
execCommand
Execute a command with arguments (in case args is not null). SeeAceCommandvalues for example.- Parameters:
command- the command (one of the values in theAceCommandenumeration)args- command arguments (string or map)
-
execCommand
Execute a command possibly containing string argument.- Parameters:
command- the command which could be one or two words separated by whitespaces
-
execCommand
Execute a command with arguments (in case args is not null).- Parameters:
command- one word commandarg- command argument
-
execCommand
Execute a command with arguments (in case args is not null).- Parameters:
command- one word commandargs- command arguments of typeAceCommandArgs
-
removeCommandByName
Remove commands, that may not be required, from the editor- Parameters:
command- to be removed, one of "gotoline", "findnext", "findprevious", "find", "replace", "replaceall"
-
getCommandDescription
Construct java wrapper for registered Ace command.- Parameters:
command- name of command- Returns:
- command description
-
listCommands
List names of all Ace commands.- Returns:
- names of all Ace commands
-
addCommand
Add user defined command.- Parameters:
description- command description
-
setUseWrapMode
public void setUseWrapMode(boolean useWrapMode) Set whether to use wrap mode or not- Parameters:
useWrapMode- true if word wrap should be used, false otherwise
-
onResize
public void onResize()- Specified by:
onResizein interfacecom.google.gwt.user.client.ui.RequiresResize
-
setValue
- Specified by:
setValuein interfacecom.google.gwt.user.client.TakesValue<String>
-
getValue
- Specified by:
getValuein interfacecom.google.gwt.user.client.TakesValue<String>
-
setAutocompleteEnabled
public void setAutocompleteEnabled(boolean b) Set whether or not autocomplete is enabled.- Parameters:
b- true if autocomplete should be enabled, false if not
-
removeAllExistingCompleters
public static void removeAllExistingCompleters()Removes all existing completers from the langtools
This can be used to disable all completers including local completers, which can be very useful when completers are used on very large files (as the local completer tokenizes every word to put in the selected list).
NOTE: This method may be removed, and replaced with another solution. It works at point of check-in, but treat this as unstable for now. -
addCompletionProvider
Add anAceCompletionProviderto provide custom code completions. Warning: this is an experimental feature of AceGWT. It is possible that the API will change in an incompatible way in future releases.- Parameters:
provider- theAceCompletionProvider
-
addMarker
Adds a static marker into this editor.- Parameters:
range- anAceRange.clazz- a CSS class that must be applied to the marker.type- anAceMarkerType.inFront- set to 'true' if the marker must be in front of the text, 'false' otherwise.- Returns:
- The marker ID. This id can be then use to remove a marker from the editor.
-
addFloatingMarker
Adds a floating marker into this editor (the marker follows lines changes as insertions, suppressions...).- Parameters:
range- anAceRange.clazz- a CSS class that must be applied to the marker.type- anAceMarkerType.- Returns:
- The marker ID. This id can be then use to remove a marker from the editor.
-
removeMarker
public void removeMarker(int markerId) Removes the marker with the specified ID.- Parameters:
markerId- the marker ID.
-
getMarkers
Gets all the displayed markers.- Returns:
- An unmodifiable Mapping between markerID and the displayed range.
-
removeAllMarkers
public void removeAllMarkers()Remove all the displayed markers. -
getSelection
Prepare a wrapper around Ace Selection object.- Returns:
- a wrapper around Ace Selection object
-
initializeCommandLine
Bind command line and editor. For default implementation of command line you can useAceCommandLine cmdLine = new AceDefaultCommandLine(textBox)where textBox could be for instance standard GWT TextBox or TextArea.- Parameters:
cmdLine- implementation of command line
-