wiki:TEXT_VIEW_MODEL

Version 20 (modified by kyli, 15 years ago) (diff)

--

Error: Macro BackLinksMenu(None) failed
compressed data is corrupt

Error: Macro TicketQuery(summary=TEXT_VIEW_MODEL, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|) failed
current transaction is aborted, commands ignored until end of transaction block

Analysis

Overview

  • After the TEXT_MODEL_REDESIGN task the positions of the caret and mark in the text views are not updating.
  • The text links and the search highlights are not visualizing.

After the task these two bugs shold be fixed.

Task requirements

  • Fix the updating of the caret, mark and search highlights position.
  • Implement search highlight visualization in the text views.
  • Implement link attachment visualization (as foreground color) in the text views.

Task result

The result should be code.

Implementation idea

  • Create a new class related to the text views that updates the indexes.
  • Create processors to help text layout draw the search highlights.
  • The processors add some attributes to the raw text (the text in the model) and produce a final text with all attributes added (as highlights and selection etc.) that can be laid out.

TEXT_MODEL_REDESIGN

How to demo

  • Run sophie, insert text frame, type some text, select some of the text.
  • Run sophie, insert text frame, type some text, add text link.
  • Run sophie, insert text frame, search an existing word from the search palette.

Design

  • Make interface TextProcessor. It will have:
    • Empty interface Options. This is the criteria for processing the text, e.g. highlight color, caret position, highlight interval, etc.
    • Interface Effect. This consists of the resulting text after a processing and the change that is generated from it (the change that if applied to the raw text, the processed one will be the result). An Effect is actually an instruction for the next processor in a processing chain.
      • public ImmText getText();
      • public TextChange getChange(); The TextChange this text processing has caused.
    • ImmText process(ImmText sourceText, T procOptions); You give the processor a text and the rules for processing, then it returns the processed text. For example: TextSelectionProcessor, which has text 'abc' and options 'caret: 2, mark:1, color: red' will return 'abc' with colored in green 'b' and 'c', as well as a caret before the 'c'.
    • Effect applyChange(Effect prevEffect, ImmText oldSource, T procOptions); Processes the text again after a TextChange has been applied to it. You could actually use process in this case, but it will do a whole processing of the text, which will be slow. So, this method's purpose is to be effective.
    • Effect setOptions(ImmText source, ImmText oldProcessed, T oldOptions, T newOptions); If the text is not modified itself, but only the options are changed, then it could perform even faster. This method should implement this idea.
  • Implement text search processor
  • Implement text link processor

-----------------------TEXT_VIEW part---------------------------------------

  • In org.sophie2.base.model.text package add new abstract class TextChange that represents the base model of a text change (applying styles ot text, replacing existing text in some interval). This class has the following abstract functions:
    • public abstract ImmText applyTo(ImmText sourceText) - This method applies the current text change to a given text and returns new text with applied change.
    • public abstract HotTextInterval getSourceDamage(ImmText sourceText) - Returns the damaged region (interval) from the source text.
    • public abstract HotTextInterval getTargetDamage(ImmText sourceText) - Returns the damaged region (interval) from the target (text after the change is made to the source text) text.
    • public abstract int updateIndex(int index, ImmText sourceText) - Updates the given index. Ex: text: ASD, the change is deleting the A; update(2) will return 1.
  • In org.sophie2.base.model.text add new class TextReplaceChange that extends TextChange. This class gives basic implementation of the TextChange's functions for a change representing replacing in the ImmText. This class has two private fields: final HotTextInterval interval and final ImmText substitution - the first one holds the interval that will be replaced and the second one holds the text for the substitution. The applyTo method simply calls ImmText#replace function.
  • In org.sophie2.base.model.text package add class TextStyleChange that extends TextChange class. This class is basic implementation of the functions in TextChange class for changes in text that represent applying styles on ImmText. It has two private fields - final HotTextInterval interval and final HotStyleDef style. The first one holds the interval that the styles will be applied to and the second one holds the styles. The applyTo method calls ImmText#applyStyle function.
  • In CommonAttr class add public static ImmList<HotAttr<?>> getAllAttr() function and remove the same from HotStyleDef class. This function gets all the attributes that are defined in the class.
  • In CommonAttr class add new public static final HotAttr<Boolean> DUMMY_ATTRIBUTE - Attribute that is true only if the char is EMPTY_CHAR.This is needed because the last text run in the text layout has to consist only of the EMPTY_CHAR in order not to be drawn and not to be handled in complicated ways.
  • In ImmTextUtils class add new method: public static ImmText createDefaultText() - Creates a text with one char equal to EMPTY_CHAR.
  • In org.sophie2.base.model.text.elements package add new final class : LayoutAttr that holds all the attributes that only the processors can apply to the text.
    • In LayoutAttr class add HotAttr<Boolean> CARET_ATTR - this attribute represents the caret in the view. True if the caret is before that char.
  • In CommonChar class add static final char EMPTY_CHAR - A dummy char inserted at the end of a text to help the text navigation. Used only in the layout.
  • In HotTextInterval class add new function: public HotTextInterval unite(HotTextInterval interval) - Unites two intervals - gets the largest possible interval from the given one and the current.
  • In ImmTextUtils add new function: public static ImmText concat(ImmText text1, ImmText text2) - Concatenates the two given texts. Keeps the styles as the origin texts.
  • Rename TextViewFlow to TextModel and add new functions as follows:
    • public abstract ImmText getRawText() - The text in the model. This is text without any attributes added for highlights, selection, etc.
    • public abstract ImmText getProcessedText() - The text that the layout use. This text differs from the raw text only by some text attributes (added for highlights, selection etc.)
      • remove the caret() and mark() properties and replace them with getCaret, setCaret, getMark and setMark.
  • In org.sophie2.base.model.text.mvc package add new class abstract class BaseTextModel extends TextModel - Basic implementation of the methods from the TextModel abstract class. This class has function public void update(TextChange change) that applies the given change to the raw text and to the processed text and updates the indexes of the caret an the mark of the model.
  • In org.sophie2.base.model.text.mvc package add new class public static class SelectionOptions<T> implements TextProcessor.Options - a class representing the options of the selection processor. This class has private final HotAttr<T> attribute, private final T value, private final HotTextInterval selectionInterval. The first one holds the attribute of the selection (CommonAttr.BACKGROUND_COLOR), the second one holds it's value (Ex: ImmColor.Blue) and the third one holds the selection interval.
  • In org.sophie2.base.model.text.mvc package add new class SelectionProcessor implements TextProcessor<SelectionOptions, DefaultTextEffect> - Processes text selection and caret.Its work consists of modifying some of the the color attributes for the selected chars, as well as to put a LayoutAttr#CARET_ATTR somewhere.
  • In org.sophie2.base.model.text.mvc.swing package add new class: SwingTextModel extends BaseTextModel - The swing realization of the {@link TextModel} class. It is used only for testing.
  • In org.sophie2.main.func.text.view package add new class : abstract class TextResourceModel extends BaseTextModel - Base implementation of the TextModel that connects the view with the text resource. It has one function: public void changeModel(final TextChange change, ResourceAccess access, final ImmText text, boolean significant, String description) - Method for updating the text model with a given TextChange. Changes the text resource, related to the view that holds the current TextResourceModel and updates the caret and mark posses to stay consistent.
  • Make the class HeadTextModel extend TextResourceModel.
  • In HotTextLogic class rename ON_SET_TEXT to ON_CHANGE_TEXT and call the changeModel when the text needs to be changed in the model(replace the AutoAction part).
    • In TextView class : EventIds rename the SET_TEXT to SET_CHANGE and set its event params to: TextChange.class, String.class, Boolean.class - the change to be made, the description of the action and the significance (if it can be undo/redo).

Implementation

(Describe and link the implementation results here (from the wiki or the repository).)

Testing

(Place the testing results here.)

Comments

(Write comments for this or later revisions here.)