Pat, thanks for responding

I inserted image doodad with xml like:

      <image attachment="/pics/hills.jpg">
        <caption/>
      </image>

with code:

            final CMutableDocument document = editor.getDocument();
            final Point<ContentNode> point =
document.locate(Math.min(range.getAnchor(), range.getFocus()));
            final HashMap<String, String> attributes = new
HashMap<String, String>();
            attributes.put("attachment", "/pics/hills.jpg");
            final ContentElement image = document.createElement(point,
"image", attributes);
            final ContentElement caption =
document.createChildElement(image, "caption", new HashMap<String,
String>());

As I understand, others doodads work the same way.

Now I'm trying to figure out how to insert a text node. That code
makes no result:

caption.getContainerNodelet().getFirstChild().setNodeValue("image alt text");


2011/7/4 Patrick Coleman <[email protected]>:
> I'm not sure of your exact usage, but .locate(int) is part of
> LocationMapper, and goes with .getLocation(point)
> essentially, the editor's document is both a DOM document (with
> ContentNodes, -Elements and -TextNodes), indexable by 'Points' (= defined by
> parent + child after)
> but also an OT-aware document indexable by integers (e.g. 'insert the text
> "hi" at position 4').
>
> Location mapping helps convert between the two one when required - e.g. in
> this case, the selection range is integer offsets (one for anchor, one for
> node)
> and here it's picking the first of the two (Math.min) then converting that
> integer location to a point.
> So they are two ways of describing the exact same thing - there are a few
> things for which points are better (e.g. inserting an element into the tree)
> and a few for which integers are (e.g. finding the first point, OT
> operations, ...) so when conversion is required, that's then you use the
> Location Mapper.
>
> hope that helps!
> - Pat
>
>
> On 1 July 2011 18:17, Anton Starcev <[email protected]> wrote:
>
>> Hi,
>>
>> Trying to insert doodad in editor, found "locate" method:
>>
>> final Point<ContentNode> point =
>> editor.getDocument().locate(Math.min(range.getAnchor(),
>> range.getFocus()));
>>
>> but can't understand how to use it in source code and in this tutorial:
>> http://www.waveprotocol.org/code/tutorials/writing-a-doodad
>>
>>
>> Anton Startsev
>> ______________________________________________________________________
>> [email protected] | www.artlebedev.com
>>
>



-- 
Anton Startsev
______________________________________________________________________
[email protected] | www.artlebedev.com

Reply via email to