public class TextEditorInputMode extends Object implements IInputMode
IInputMode
that displays a TextArea
instance in the CanvasControl
to let the user edit
a text.
Hitting escape or enter will cancel or stop editing.
This mode is Exclusive
by default.
Type | Property and Description |
---|---|
StringProperty |
editorText
Gets the current text property of the text input editor.
|
Constructor and Description |
---|
TextEditorInputMode()
Creates a new instance using a default text box.
|
TextEditorInputMode(TextArea textBox)
Creates a new instance using the given text box instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addEditingCanceledListener(IEventHandler<TextEventArgs> editingCanceledEvent)
Adds the given listener for the
EditingCanceled event that occurs if the editing has not been finished. |
void |
addEditingStartedListener(IEventHandler<TextEventArgs> editingStartedEvent)
Adds the given listener for the
EditingStarted event that occurs when text editing is started. |
void |
addTextEditedListener(IEventHandler<TextEventArgs> textEditedEvent)
Adds the given listener for the
TextEdited event that occurs once the text has been edited. |
protected void |
adjustPosition()
Adjusts the position of the text box in the
CanvasControl . |
void |
cancel()
Cancels editing of the text box.
|
void |
clear()
Resets the contents of the text box.
|
protected TextInputControl |
createTextBox()
Factory method that creates a default text box.
|
StringProperty |
editorTextProperty()
Gets the current text property of the text input editor.
|
protected void |
ensureVisible()
Adjusts the
Viewport of the CanvasControl so the TextBox is in
the visible area. |
IPoint |
getAnchor()
Gets the anchor of the text box.
|
IEventRecognizer |
getCancelRecognizer()
Gets the
IEventRecognizer to detect when editing the text shall be canceled. |
protected ConcurrencyController |
getController()
Returns the installed
Controller . |
String |
getEditorText()
Gets the current text of the text input editor.
|
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
IEventRecognizer |
getLineBreakRecognizer()
Gets the
IEventRecognizer to detect the key gesture for new line breaks. |
IPoint |
getLocation()
Gets the location of the text box in world coordinates.
|
protected double |
getMaximumZoom(SizeD textBoxSize)
Determines the text box's maximum zoom value.
|
protected double |
getMinimumZoom(SizeD textBoxSize)
Determines the text box's minimum zoom value.
|
int |
getPriority()
The priority of this input mode.
|
IEventRecognizer |
getStopRecognizer()
Gets the
IEventRecognizer to detect when editing the text shall be stopped. |
TextInputControl |
getTextBox()
Gets the text box to use for displaying and editing.
|
protected RectD |
getTextBoxBounds()
Returns the bounds of the TextBox.
|
IPoint |
getUpVector()
Gets the point that describes the "up"-vector that will be used to determine the orientation of the text box in the
world coordinate system.
|
void |
install(IInputModeContext context,
ConcurrencyController controller)
Installs this mode into the given context that is provided by the canvas.
|
protected void |
installTextBox()
Installs the text box in the canvas and puts focus into it.
|
boolean |
isAutoCommittingOnFocusLostEnabled()
Gets a property that determines whether the text edited should be committed if the focus gets lost or the editing should
be canceled.
|
boolean |
isAutoFlippingTextBoxEnabled()
Gets a value indicating whether to automatically flip the orientation of the text box if the
UpVector
actually points downwards. |
boolean |
isAutoFocusingCanvasOnEditorClosedEnabled()
Gets a property that determines whether this mode should try to
Node.requestFocus() the Canvas
once the editor is closed via a keyboard gesture. |
boolean |
isAutoStartEditingEnabled()
Determines whether this mode should automatically fire up the editor once it gets installed.
|
boolean |
isEditing()
Gets the current editing state of the editor.
|
boolean |
isEnabled()
Gets the enabled state of this input mode.
|
boolean |
isExclusive()
Gets a value indicating whether this mode will be the only one running when it has the mutex.
|
protected void |
onBeginEditing()
Called when editing starts.
|
protected void |
onCanceled()
Called after
cancel() has been called. |
protected void |
onCancelEditing()
Called when editing gets canceled.
|
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onEditingCanceled(TextEventArgs args)
Raises the
EditingCanceled event. |
protected void |
onEditingStarted(TextEventArgs args)
Raises the
EditingStarted event. |
protected void |
onStopEditing()
Called when editing is stopped.
|
protected void |
onStopped()
Called after
stop() has been called. |
protected void |
onTextEdited(TextEventArgs args)
Raises the
TextEdited event. |
void |
removeEditingCanceledListener(IEventHandler<TextEventArgs> editingCanceledEvent)
Removes the given listener for the
EditingCanceled event that occurs if the editing has not been finished. |
void |
removeEditingStartedListener(IEventHandler<TextEventArgs> editingStartedEvent)
Removes the given listener for the
EditingStarted event that occurs when text editing is started. |
void |
removeTextEditedListener(IEventHandler<TextEventArgs> textEditedEvent)
Removes the given listener for the
TextEdited event that occurs once the text has been edited. |
void |
setAnchor(IPoint value)
Sets the anchor of the text box.
|
void |
setAutoCommittingOnFocusLostEnabled(boolean value)
Sets a property that determines whether the text edited should be committed if the focus gets lost or the editing should
be canceled.
|
void |
setAutoFlippingTextBoxEnabled(boolean value)
Sets a value indicating whether to automatically flip the orientation of the text box if the
UpVector
actually points downwards. |
void |
setAutoFocusingCanvasOnEditorClosedEnabled(boolean value)
Sets a property that determines whether this mode should try to
Node.requestFocus() the Canvas
once the editor is closed via a keyboard gesture. |
void |
setAutoStartEditingEnabled(boolean value)
Determines whether this mode should automatically fire up the editor once it gets installed.
|
void |
setCancelRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer to detect when editing the text shall be canceled. |
void |
setEditing(boolean value)
Sets the current editing state of the editor.
|
void |
setEditorText(String text)
Sets the current text of the text input editor.
|
void |
setEnabled(boolean value)
Sets the enabled state of this input mode.
|
void |
setExclusive(boolean value)
Sets a value indicating whether this mode will be the only one running when it has the mutex.
|
void |
setLineBreakRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer to detect the key gesture for new line breaks. |
void |
setLocation(IPoint value)
Sets the location of the text box in world coordinates.
|
void |
setPriority(int value)
The priority of this input mode.
|
void |
setStopRecognizer(IEventRecognizer value)
Sets the
IEventRecognizer to detect when editing the text shall be stopped. |
void |
setTextBox(TextInputControl value)
Sets the text box to use for displaying and editing.
|
void |
setUpVector(IPoint value)
Sets the point that describes the "up"-vector that will be used to determine the orientation of the text box in the
world coordinate system.
|
protected boolean |
showInViewCoordinates(SizeD textBoxSize)
Determines whether the text box should be displayed in the view coordinate system instead of in the world coordinate
system.
|
boolean |
stop()
Stops editing and returns
true . |
void |
uninstall(IInputModeContext context)
Uninstalls this mode from the given context.
|
protected void |
uninstallTextBox()
Called to remove the text box from the application.
|
public StringProperty editorTextProperty
public TextEditorInputMode()
public TextEditorInputMode(TextArea textBox)
textBox
- The text box to use.public final void addEditingCanceledListener(IEventHandler<TextEventArgs> editingCanceledEvent)
EditingCanceled
event that occurs if the editing has not been finished.editingCanceledEvent
- The listener to add.removeEditingCanceledListener(IEventHandler)
public final void addEditingStartedListener(IEventHandler<TextEventArgs> editingStartedEvent)
EditingStarted
event that occurs when text editing is started.editingStartedEvent
- The listener to add.removeEditingStartedListener(IEventHandler)
public final void addTextEditedListener(IEventHandler<TextEventArgs> textEditedEvent)
TextEdited
event that occurs once the text has been edited.textEditedEvent
- The listener to add.removeTextEditedListener(IEventHandler)
protected void adjustPosition()
CanvasControl
.public void cancel()
cancel
in interface IInputMode
public void clear()
protected TextInputControl createTextBox()
public StringProperty editorTextProperty()
protected void ensureVisible()
Viewport
of the CanvasControl
so the TextBox is in
the visible area.
Called once when the editing starts.
public final IPoint getAnchor()
The anchor is the point inside the coordinate system of the text box that shall coincide with the Location
in the world coordinate system. The X and Y values are expressed as relative width/height ratios.
setAnchor(IPoint)
public final IEventRecognizer getCancelRecognizer()
IEventRecognizer
to detect when editing the text shall be canceled.
When the provided KeyEventArgs
are recognized, cancel()
is called.
KeyCode.ESCAPE
.getLineBreakRecognizer()
,
getStopRecognizer()
,
setCancelRecognizer(IEventRecognizer)
protected final ConcurrencyController getController()
Controller
.public String getEditorText()
public final IInputModeContext getInputModeContext()
IInputMode
null
if this instance is not installed.
Note that this instance should not be passed down to subordinate modes or instances. Instead a corresponding context
that has this instance set as the ParentInputMode
should be used.
getInputModeContext
in interface IInputMode
public final IEventRecognizer getLineBreakRecognizer()
IEventRecognizer
to detect the key gesture for new line breaks.
When the provided KeyEventArgs
are recognized, a new line break is inserted at the current curret position.
KeyCode.ENTER
while ModifierKeys.SHORTCUT
is
pressed.getCancelRecognizer()
,
getStopRecognizer()
,
setLineBreakRecognizer(IEventRecognizer)
public final IPoint getLocation()
setLocation(IPoint)
protected double getMaximumZoom(SizeD textBoxSize)
By default, the text box zoom is limited to a value smaller than 3 or a dynamic threshold if the size of the text box
would otherwise occupy a significant amount of space in the editor. Override and return Double.MAX_VALUE
to
effectively switch off the maximum zoom threshold.
textBoxSize
- The size of the text box to display.protected double getMinimumZoom(SizeD textBoxSize)
By default, the text box zoom is limited to a value greater than 0.1 or a font size greater than 8 if the zoom is taken
into account. Override and return Double.NEGATIVE_INFINITY
to effectively switch off this minimum zoom
threshold.
textBoxSize
- The size of the text box to display.public final int getPriority()
IInputMode
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
getPriority
in interface IInputMode
public final IEventRecognizer getStopRecognizer()
IEventRecognizer
to detect when editing the text shall be stopped.
When the provided KeyEventArgs
are recognized, stop()
is called.
KeyCode.ENTER
while ModifierKeys.SHORTCUT
is not
pressed.getLineBreakRecognizer()
,
getCancelRecognizer()
,
setStopRecognizer(IEventRecognizer)
public final TextInputControl getTextBox()
com.yworks.yfiles.input.TextEditorInputMode#createTextBox()
factory method
to create the instance to use during one editing. The same instance is then used for future text editing
until #setTextBox(javafx.scene.control.Control)
is called with a different instance.#setTextBox(javafx.scene.control.Control)
protected RectD getTextBoxBounds()
public final IPoint getUpVector()
The default is 0, -1
.
setUpVector(IPoint)
public void install(IInputModeContext context, ConcurrencyController controller)
In general a mode can only be installed into a single canvas at all times.
This method is called to initialize this instance. Subclasses should override this method to register the corresponding event handler delegates for the various input events they need to register with.
Overriding implementations should call the base implementation, first.
install
in interface IInputMode
context
- The context that this instance shall be installed into. The same instance will be passed to this instance during
IInputMode.uninstall(IInputModeContext)
. A reference to the context may be kept and queried during the time
the mode is installed.controller
- The Controller
for this mode.IInputMode.uninstall(IInputModeContext)
protected void installTextBox()
public final boolean isAutoCommittingOnFocusLostEnabled()
The default behavior is to cancel the editing process.
setAutoCommittingOnFocusLostEnabled(boolean)
public final boolean isAutoFlippingTextBoxEnabled()
UpVector
actually points downwards.
The default is true
.
true
if the text box should be flipped if necessary; false
otherwise.setAutoFlippingTextBoxEnabled(boolean)
public final boolean isAutoFocusingCanvasOnEditorClosedEnabled()
Node.requestFocus()
the Canvas
once the editor is closed via a keyboard gesture.
The default is true
setAutoFocusingCanvasOnEditorClosedEnabled(boolean)
public final boolean isAutoStartEditingEnabled()
If this mode is permanently installed, set this flag to false
and set the Editing
flag to true
in order to start editing.
setAutoStartEditingEnabled(boolean)
public final boolean isEditing()
Setting a new value will trigger the onBeginEditing()
and onCancelEditing()
methods respectively.
setEditing(boolean)
public boolean isEnabled()
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
setEnabled(boolean)
public final boolean isExclusive()
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
setExclusive(boolean)
protected void onBeginEditing()
Requests the input mutex, and installs the text box.
protected void onCanceled()
cancel()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
protected void onCancelEditing()
Removes the text box and releases the input mutex.
protected void onConcurrencyControllerActivated()
Active
property of the installed ConcurrencyController
has been set to true
.
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
protected void onConcurrencyControllerDeactivated()
Active
property of the installed ConcurrencyController
has been set to false
.
Can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
protected void onEditingCanceled(TextEventArgs args)
EditingCanceled
event.args
- The event argumentprotected void onEditingStarted(TextEventArgs args)
EditingStarted
event.args
- The event argument.protected void onStopEditing()
Triggers the TextEdited
event, removes the box and releases the input
mutex.
protected void onStopped()
stop()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
protected void onTextEdited(TextEventArgs args)
TextEdited
event.args
- The event arguments.public final void removeEditingCanceledListener(IEventHandler<TextEventArgs> editingCanceledEvent)
EditingCanceled
event that occurs if the editing has not been finished.editingCanceledEvent
- The listener to remove.addEditingCanceledListener(IEventHandler)
public final void removeEditingStartedListener(IEventHandler<TextEventArgs> editingStartedEvent)
EditingStarted
event that occurs when text editing is started.editingStartedEvent
- The listener to remove.addEditingStartedListener(IEventHandler)
public final void removeTextEditedListener(IEventHandler<TextEventArgs> textEditedEvent)
TextEdited
event that occurs once the text has been edited.textEditedEvent
- The listener to remove.addTextEditedListener(IEventHandler)
public final void setAnchor(IPoint value)
The anchor is the point inside the coordinate system of the text box that shall coincide with the Location
in the world coordinate system. The X and Y values are expressed as relative width/height ratios.
value
- The Anchor to set.getAnchor()
public final void setAutoCommittingOnFocusLostEnabled(boolean value)
The default behavior is to cancel the editing process.
value
- The AutoCommittingOnFocusLostEnabled to set.isAutoCommittingOnFocusLostEnabled()
public final void setAutoFlippingTextBoxEnabled(boolean value)
UpVector
actually points downwards.
The default is true
.
value
- true
if the text box should be flipped if necessary; false
otherwise.isAutoFlippingTextBoxEnabled()
public final void setAutoFocusingCanvasOnEditorClosedEnabled(boolean value)
Node.requestFocus()
the Canvas
once the editor is closed via a keyboard gesture.
The default is true
value
- The AutoFocusingCanvasOnEditorClosedEnabled to set.isAutoFocusingCanvasOnEditorClosedEnabled()
public final void setAutoStartEditingEnabled(boolean value)
If this mode is permanently installed, set this flag to false
and set the Editing
flag to true
in order to start editing.
value
- The AutoStartEditingEnabled to set.isAutoStartEditingEnabled()
public final void setCancelRecognizer(IEventRecognizer value)
IEventRecognizer
to detect when editing the text shall be canceled.
When the provided KeyEventArgs
are recognized, cancel()
is called.
value
- The cancel recognizer. The default recognizer checks for KeyCode.ESCAPE
.getLineBreakRecognizer()
,
getStopRecognizer()
,
getCancelRecognizer()
public final void setEditing(boolean value)
Setting a new value will trigger the onBeginEditing()
and onCancelEditing()
methods respectively.
value
- The Editing to set.isEditing()
public void setEditorText(String text)
text
- of the text input editor.public void setEnabled(boolean value)
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
value
- The Enabled to set.isEnabled()
public final void setExclusive(boolean value)
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
value
- The Exclusive to set.isExclusive()
public final void setLineBreakRecognizer(IEventRecognizer value)
IEventRecognizer
to detect the key gesture for new line breaks.
When the provided KeyEventArgs
are recognized, a new line break is inserted at the current curret position.
value
- The line break recognizer. The default recognizer checks for KeyCode.ENTER
while ModifierKeys.SHORTCUT
is
pressed.getCancelRecognizer()
,
getStopRecognizer()
,
getLineBreakRecognizer()
public final void setLocation(IPoint value)
value
- The Location to set.getLocation()
public final void setPriority(int value)
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
value
- The Priority to set.getPriority()
public final void setStopRecognizer(IEventRecognizer value)
IEventRecognizer
to detect when editing the text shall be stopped.
When the provided KeyEventArgs
are recognized, stop()
is called.
value
- The stop recognizer. The default recognizer checks for KeyCode.ENTER
while ModifierKeys.SHORTCUT
is not
pressed.getLineBreakRecognizer()
,
getCancelRecognizer()
,
getStopRecognizer()
public final void setTextBox(TextInputControl value)
value
- The TextBox to set.getTextBox()
public final void setUpVector(IPoint value)
The default is 0, -1
.
value
- The UpVector to set.getUpVector()
protected boolean showInViewCoordinates(SizeD textBoxSize)
If enabled, the zoom value used to scale the text box is 1. Otherwise, the zoom value is determined by the zoom level of
the CanvasControl
limited by the values returned by the methods getMinimumZoom(SizeD)
and
getMaximumZoom(SizeD)
.
textBoxSize
- The size of the text box to display.false
.getMinimumZoom(SizeD)
,
getMaximumZoom(SizeD)
public boolean stop()
true
.stop
in interface IInputMode
base.Stop()
IInputMode.cancel()
public void uninstall(IInputModeContext context)
This code should clean up all changes made to the canvas in the IInputMode.install(IInputModeContext, ConcurrencyController)
method. After a mode has been uninstalled it can be installed again into the same or another canvas.
Overriding implementations should call the base implementation after their own code.
uninstall
in interface IInputMode
context
- The context to deregister from. This is the same instance that had been passed to IInputMode.install(IInputModeContext, ConcurrencyController)
during installation.protected void uninstallTextBox()