Analysis
Overview
There are different anchoring modes defining the way a frame should move according to the frame it is anchored to: In this revision of the task only character mode anchor will be implemented. Since drag n drop is not ready yet, the anchor hud will be used for defining where to anchor the frame. The goal of this revision is to implement anchoring support and demonstrate it's working.
Task requirements
- Create anchor halo. It should be draggable and clickable halo.
- Create anchor HUD with two dropdowns - Frame (frame list) and position (numbers) (like in trigger HUD). When the anchor is implemented, position dropdown won't be needed and will be removed.
- Frame defines to which frame will this be anchored and position - to which position of the text.
- When a frame is attached to a position, when position is moved the frame is moved with the same offset as the position. This means that if the character is moved with 10 px right and down, the frame will be moved too.
- The frame can be moved by the user
- A frame cannot be attached to itself.
Task result
The result of this task is source code.
Implementation idea
Create an interface named Attachment.
Related
How to demo
- Create a book, insert text frame, type in some text
- Insert second frame, click anchor halo, select the first frame from the dropdown and position 3 for example
- Move cursor in position 1 and type in some more text.
Design
In order to provide the anchoring prototype the following changes are made:
- in org.sophie2.base.model.text package add interface Attachable which is used to determine which elements could be attached to other ones
(the new interface is just a marker ).
- in ImmHotText class add ImmMap<Interval,Attachment> and change the constructors of the class(in order to initialize the new map)
- in ImmHotText class add getter method getAttachmentMap that returns the map with the text's attachments.
- in org.sophie2.main.func.text.content.view package add a new enum AnchorMode. It holds the five modes of the anchoring.
- PAGE - this mode anchors the resource to the page
- FRAME - this mode anchors the resource to the frame (the visible result is when the frame is moved the anchored resource frame should also move).
- LINE - this mode anchors the resource to a line of the text.
- CHARACTER - this mode anchors the resource to a single character of the text (if the character changes it's position the anchored resource frame should also do so).
- INLINE - this is the only one mode that treates the resource as a 'character' of the text - the resource frame is placed next to the place it has been anchored in the text frame. The other modes places the anchored frame outside the place it has been anchored to.
- add a new package org.sophie2.base.model.text.anchoring
- in org.sophie2.base.model.text.anchoring package add a new class AnchorText implements Attachment. It is used for anchoring in the text. This class contains :
- final mode : AnchorMode
- final resourceRef : ResourceRefR4
- constructor with two parameters and getters for the mode and for the resourceRef.
- in org.sophie2.main.app.commons.frame package add a new class AnchorView extends ElementView. It's idea is to visualize the anchor as an element in the frame. It's childView prop is of type FrameView. This class has public abstract ResourceH getAnchoredModel() method.
- in org.sophie2.main.func.text.anchoring package add a new class AnchorTextView extends AnchorView that represents views of the anchors in the text.
- the anchored resources of type ResourceRefR4 will be children of HotTextResourceH (they will be in stored in KEY_CHILDREN).
- in FrameView add ListProp<AnchorView> that holds all the anchored views in the frame(with annotation Own)
- in HotTextLogic class add ON_INSERT_ANCHOR that contains the logic of adding an anchor to the current text.
- in org.sophie2.main.func.text.anchoring package add a new class TextAnchorHaloButton extends HudHaloButton for the anchoring hud.
- in org.sophie2.main.func.text.anchoring package add a new class TextAnchorHud with two children TextAnchorHud.TextAttachmentComboBox.class,
TextAnchorHud.TextCharacterComboBox.class - the first is to show all the available frames to be attached and the second is to show the available positions in the text that the resource can be attached to.
tests can be found here: [6639][6641]
Implementation
(Implementation results should be described and linked here (from the wiki or the repository))
Testing
Comments
(Write comments for this or later revisions here.)