dojox/drawing/tools/TextBlock (version 1.10)

dojox/drawing/stencil/Text

Summary

A tool to create text fields on a canvas.

Extends stencil.Text by adding an HTML layer that can be dragged out to a certain size, and accept a text entry. Will wrap text to the width of the html field. When created programmtically, use 'auto' to shrink the width to the size of the text. Use line breaks ( \n ) to create new lines.

Usage

var foo = new TextBlock(options);
dojox/drawing/tools/TextBlock
Parameter Type Description
options undefined

Property Summary

Method Summary

  • _renderOutline() Create the hit and highlight area for the Text.
  • _setNodeAtts(shape) Internal.
  • _toggleSelected()
  • addShadow(args)
  • animate(options,create)
  • applyTransform(mx) Applies the transform to the stencil NOTE: PARTIALLY IMPLEMENTED.
  • attr(key,value) Changes properties in the style or disabled styles, depending on whether the object is enabled.
  • cleanText(txt,removeBreaks) Cleans text.
  • connect(o,e,s,m,once) Convenience method for quick connects See comments below for possiblities functions can be strings
  • connectMouse() Internal.
  • connectMult() Convenience method for batches of quick connects Handles are not returned and therefore cannot be disconnected until Shape destroy time
  • connectTextField() Internal.
  • createAnchors() Internal.
  • createTextField(txt) Internal.
  • dataToPoints(o) Converts data to points.
  • deselect(useDelay) Called when the Stencil is deselected.
  • destroy() Destroys this Stencil
  • destroyAnchors() Internal.
  • disable() Disables Stencil so it is not selectable.
  • disconnect(handles) Removes connections based on passed handles arguments
  • disconnectMouse() Internal.
  • edit() Internal?
  • enable() Enables Stencil so it is not selectable (if it was selectable to begin with).
  • execText() Internal.
  • exporter() Exports Stencil data
  • getAngle() Gets angle of Stencil NOTE: Only works for Lines, Arrows, Vectors and Axes (works on points, not transforms)
  • getBounds(absolute) Returns the coordinates of the Stencil.
  • getLabel() Get the text of the label.
  • getRadius() Gets radius (length) of Stencil.
  • getSavedCaret()
  • getSelection(node) This gets and stores the caret position in the contentEditable div (conEdit).
  • getText() Getter for text.
  • getTransform() Returns the current transform (position) of the Stencil's container
  • highlight() Changes style to the highlight theme.
  • insertText(node,val) Uses saved caret position to insert text into position and place caret at the end of insertion
  • makeFit(text,w)
  • measureText(str,width) Mechanism for measuring text.
  • moveToBack() Moves Stencil to the back of all other items on the canvas.
  • moveToFront() Moves Stencil to the front of all other items on the canvas.
  • pointsToData(p) Converts points to data
  • preventNegativePos() Internal.
  • remove() Removes shape(s), typically before a re-render No args defaults to this.shape Pass in multiple args to remove multiple shapes
  • removeShadow()
  • render(text) Renders the 'hit' object (the shape used for an expanded hit area and for highlighting) and the'shape' (the actual display object).
  • select() Called when the Stencil is selected.
  • setData(data) Setter for Stencil data; also converts data to points.
  • setLabel(text) Creates and sets a label annotation for the Stencil.
  • setPoints(points) Setter for Stencil points; also converts points to data.
  • setSavedCaret(val) Internal, called when caret needs to be moved into position after text is added
  • setSelection(node,what) Used for placing the cursor during edits and character help.
  • setText(text) Setter for text.
  • setTransform(mx) Sets the transform to the stencil NOTE: PARTIALLY IMPLEMENTED.
  • showParent(obj) Internal.
  • transformPoints(mx) Moves object to a new X Y location mx is additive.
  • typesetter(text) Register raw text, returning typeset form.
  • unhighlight() Changes style to the current theme.

Event Summary

  • _onPostRender(data) Drag-create or programmatic create calls onRender and afterwards, _onPostRender is called and manages further events.
  • onBeforeRender(stencil) Stub - Fires before render occurs.
  • onChangeData(stencil) Stub - fires on change of dimensional properties or a text change
  • onChangeStyle(stencil) Fires when styles of shape has changed
  • onChangeText(value)
  • onDelete(stencil) Stub - fires before this is destroyed
  • onDown(obj)
  • onDrag(obj)
  • onModify(stencil) Stub - fires on change of any property, including style properties
  • onMove(obj) Mouse event, fired on mousemove while mouse is not down.
  • onRender(stencil) Stub - Fires on creation.
  • onTransform(anchor) Called from anchor point mouse drag also called from plugins.Pan.checkBounds
  • onTransformBegin(anchor) Fired at the start of a transform.
  • onTransformEnd(anchor) Called from anchor point up mouse up
  • onUp(obj)

Properties

_blockExec
_caretEnd
_caretStart
_downOnCanvas
_lineHeight

The height of each line of text. Based on style information and font size.

align

Text horizontal alignment. Options: start, middle, end

anchorType
baseRender
drawingType
draws
enabled

Whether the Stencil is enabled or not.

minimumSize

The minimum size allowed for a render. If the size is less, the shape is destroyed.

selectOnExec

Whether the Stencil is selected when the text field is executed or not

setup
showEmpty

If true and there is no text in the data, the TextBlock Is displayed and focused and awaits input.

StencilData

The data used to create the dojox.gfx Text

StencilPoints
type
valign

Text vertical alignment Options: top, middle, bottom (FIXME: bottom not supported)

Methods

_renderOutline()

Create the hit and highlight area for the Text.

_setNodeAtts(shape)

Internal. Sets the rawNode attribute. (Or in Silverlight an "object attribute". "stencil" is used by the application to determine if something is selectable or not. This also sets the mouse custom events like: "onStencilUp". To disable the selectability, make the att "", which causes a standard mouse event. Labels are special and used to select master stencils.

Parameter Type Description
shape undefined
_toggleSelected()
addShadow(args)
Parameter Type Description
args Object
animate(options,create)
Parameter Type Description
options undefined
create undefined
applyTransform(mx)

Applies the transform to the stencil

NOTE: PARTIALLY IMPLEMENTED. Only applies x y coords.

Parameter Type Description
mx undefined
attr(key,value)

Changes properties in the style or disabled styles, depending on whether the object is enabled. Also can be used to change most position and size props.

Parameter Type Description
key String | Object
value String | Number
Optional
cleanText(txt,removeBreaks)

Cleans text. Strings HTML chars and double spaces and optionally removes line breaks.

Parameter Type Description
txt String
removeBreaks Boolean
Returns:undefined
connect(o,e,s,m,once)

Convenience method for quick connects See comments below for possiblities functions can be strings

Parameter Type Description
o undefined
e undefined
s undefined
m undefined
once Boolean

If true, the connection happens only once then disconnects. Five args are required for this functionality.

Returns:undefined
connectMouse()

Internal. Registers this Stencil to receive mouse events.

connectMult()

Convenience method for batches of quick connects Handles are not returned and therefore cannot be disconnected until Shape destroy time

connectTextField()

Internal. Creates the connections to the contenteditable HTML node.

createAnchors()

Internal. Creates HTML nodes at each corner of the contenteditable div. These nodes are draggable and will resize the div horizontally.

createTextField(txt)

Internal. Inserts the contenteditable HTML node into its parent node, and styles it.

Parameter Type Description
txt String
Returns:undefined
dataToPoints(o)

Converts data to points.

Parameter Type Description
o Object
Returns:Array
deselect(useDelay)

Called when the Stencil is deselected. NOTE: Calling this will not deselect the Stencil calling this just sets the style to the current theme. 'manager.Stencil' should be used for selecting and deselecting Stencils.

Parameter Type Description
useDelay Boolean

Adds slight delay before the style is set.

destroy()

Destroys this Stencil

destroyAnchors()

Internal. Destroys HTML anchors.

disable()

Disables Stencil so it is not selectable. Changes the color to the disabled style.

disconnect(handles)

Removes connections based on passed handles arguments

Parameter Type Description
handles Handle | Array
disconnectMouse()

Internal. Unregisters this Stencil from receiving mouse events.

edit()

Internal? Method used to instantiate the contenteditable HTML node.

enable()

Enables Stencil so it is not selectable (if it was selectable to begin with). Changes the color to the current style.

execText()

Internal. Method fired when text is executed, via mouse-click-off, ESC key or Enter key.

exporter()

Exports Stencil data

Returns:undefined
getAngle()

Gets angle of Stencil NOTE: Only works for Lines, Arrows, Vectors and Axes (works on points, not transforms)

Returns:undefined
getBounds(absolute)

Returns the coordinates of the Stencil. This is often different than the data or the points.

NOTE: Won't work for paths or annotations (labels, Axes, arrow tips) They should overwrite.

NOTE: Primarily used for checking for if shape is off canvas. Therefore Lines could get flipped. Use absolute to prevent this.

Parameter Type Description
absolute Boolean

Keeps lines from flipping (see note).

Returns:object
getLabel()

Get the text of the label.

Returns:undefined | null
getRadius()

Gets radius (length) of Stencil.

NOTE: Only works for Lines, Arrows and Vectors (not for Ellipse, Axes has its own version)

Returns:undefined
getSavedCaret()
Returns:object
getSelection(node)

This gets and stores the caret position in the contentEditable div (conEdit). NOTE: Doesn't work with html nodes inside the div.

Parameter Type Description
node undefined
getText()

Getter for text.

Returns:undefined
getTransform()

Returns the current transform (position) of the Stencil's container

Returns:object
highlight()

Changes style to the highlight theme.

insertText(node,val)

Uses saved caret position to insert text into position and place caret at the end of insertion

Parameter Type Description
node undefined
val undefined
makeFit(text,w)
Parameter Type Description
text undefined
w undefined
Returns:object
measureText(str,width)

Mechanism for measuring text. SVG nor VML have a way of determining the width or height of a block of text. This method creates an HTML text block and those measurements are used for displaying the SVG/VML text.

Parameter Type Description
str String

The text to display and measure.

width Number

If the width is not provided, it will be assumed that the text is one line and the width will be measured and the _lineHeight used for th height. If width is provided, word-wrap is assumed, and line breaks will be inserted into the text at each point where a word wraps in the HTML. The height is then measured.

Returns:object
moveToBack()

Moves Stencil to the back of all other items on the canvas.

moveToFront()

Moves Stencil to the front of all other items on the canvas.

pointsToData(p)

Converts points to data

Parameter Type Description
p Array
Returns:object
preventNegativePos()

Internal. Prevent item from being drawn/rendered less than zero on the X or Y.

remove()

Removes shape(s), typically before a re-render No args defaults to this.shape Pass in multiple args to remove multiple shapes

removeShadow()
render(text)

Renders the 'hit' object (the shape used for an expanded hit area and for highlighting) and the'shape' (the actual display object). Text is slightly different than other implementations. Instead of calling render twice, it calls _createHilite for the 'hit'

Parameter Type Description
text String

Changes text if sent. Be sure to use the setText and not to call this directly.

select()

Called when the Stencil is selected. NOTE: Calling this will not select the Stencil calling this just sets the style to the 'selected' theme. 'manager.Stencil' should be used for selecting Stencils.

setData(data)

Setter for Stencil data; also converts data to points. See individual Stencils for specific data properties.

Parameter Type Description
data StencilData
setLabel(text)

Creates and sets a label annotation for the Stencil. If Stencil contains a labelPosition method, that will be used for positioning. Otherwise dojox.drawing.util.positioning.label is used.

Parameter Type Description
text String

The text to set as the label.

setPoints(points)

Setter for Stencil points; also converts points to data. See individual Stencils for specific points properties.

Parameter Type Description
points StencilPoints
setSavedCaret(val)

Internal, called when caret needs to be moved into position after text is added

Parameter Type Description
val undefined
setSelection(node,what)

Used for placing the cursor during edits and character help. Takes the values: end, beg, start, all or any numerical value (in which case the number will constitute the caret position)

Parameter Type Description
node undefined
what undefined
setText(text)

Setter for text.

Parameter Type Description
text undefined
setTransform(mx)

Sets the transform to the stencil

NOTE: PARTIALLY IMPLEMENTED. Only applies x y coords.

Parameter Type Description
mx Object
showParent(obj)

Internal. Builds the parent node for the contenteditable HTML node.

Parameter Type Description
obj EventObject
transformPoints(mx)

Moves object to a new X Y location mx is additive. So mx.dx=1 will move the stencil 1 pixel to the right from wherever it was.

Parameter Type Description
mx undefined
typesetter(text)

Register raw text, returning typeset form. Uses function dojox.drawing.stencil.Text.typeset for typesetting, if it exists.

Parameter Type Description
text undefined
Returns:undefined
unhighlight()

Changes style to the current theme.

Events

_onPostRender(data)

Drag-create or programmatic create calls onRender and afterwards, _onPostRender is called and manages further events.

Parameter Type Description
data Object
onBeforeRender(stencil)

Stub - Fires before render occurs.

Parameter Type Description
stencil Object
onChangeData(stencil)

Stub - fires on change of dimensional properties or a text change

Parameter Type Description
stencil Object
onChangeStyle(stencil)

Fires when styles of shape has changed

Parameter Type Description
stencil Object
onChangeText(value)
Parameter Type Description
value undefined
onDelete(stencil)

Stub - fires before this is destroyed

Parameter Type Description
stencil Stencil
onDown(obj)
Parameter Type Description
obj EventObject
onDrag(obj)
Parameter Type Description
obj EventObject
onModify(stencil)

Stub - fires on change of any property, including style properties

Parameter Type Description
stencil Object
onMove(obj)

Mouse event, fired on mousemove while mouse is not down. NOTE: Not currently implemented

Parameter Type Description
obj EventObject
onRender(stencil)

Stub - Fires on creation. Drawing connects to this (once!) to be notified of drag completion. But only if it was registered as a Tool. Creating Stencil in and of itself does not register it.

This should fire at the end of creation (not during drag)

Parameter Type Description
stencil Object
onTransform(anchor)

Called from anchor point mouse drag also called from plugins.Pan.checkBounds

Parameter Type Description
anchor ? manager.Anchor
onTransformBegin(anchor)

Fired at the start of a transform. This would be an anchor drag or a selection.

Parameter Type Description
anchor ? manager.Anchor
onTransformEnd(anchor)

Called from anchor point up mouse up

Parameter Type Description
anchor manager.Anchor
onUp(obj)
Parameter Type Description
obj EventObject
Error in the documentation? Can’t find what you are looking for? Let us know!