Ticket #2495: 2495-reduced.patch

File 2495-reduced.patch, 29.9 KB (added by pap, 15 years ago)

removed the #2494 code from the patch

  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/links/TextLinkProcessor.java

    ### Eclipse Workspace Patch 1.0
    #P sophie
     
    22 
    33import java.util.HashMap; 
    44 
     5 
    56import org.sophie2.base.commons.structures.ImmTreeMap; 
    67import org.sophie2.base.commons.util.ImmColor; 
    78import org.sophie2.base.commons.util.ImmMap; 
    89import org.sophie2.base.model.text.HotAttr; 
     10import org.sophie2.base.model.text.TextChange; 
    911import org.sophie2.base.model.text.TextReplaceChange; 
    1012import org.sophie2.base.model.text.elements.CommonAttr; 
    1113import org.sophie2.base.model.text.model.ImmTextInterval; 
     
    130132 
    131133        public DefaultTextEffect applyChange(TextProcessorEffect prevEffect, ImmText oldSource, 
    132134                        ImmText oldResult, TextLinkOptions procOptions) { 
    133 //              TextChange change = prevEffect.getChange(); 
    134 //              ImmText sourceText = prevEffect.getText(); 
    135 //              ImmText toProcess = sourceText.subText(change.getTargetDamage(sourceText)); 
    136 // 
    137 //              TextReplaceChange effect = new TextReplaceChange( 
    138 //                              change.getSourceDamage(oldSource), process(toProcess, procOptions)); 
    139 // 
    140 //              ImmText result = effect.applyTo(oldResult); 
    141 //              assert result.getEnd() == sourceText.getEnd() : result.getEnd() + " : " + sourceText.getEnd(); 
    142 // 
    143 //              return new DefaultTextEffect(effect, result); 
    144                  
    145                 ImmText res = process(prevEffect.getText(), procOptions); 
    146                 return new DefaultTextEffect(ImmTextUtils.getChange(oldResult, res), res); 
     135 
     136                TextChange change = prevEffect.getChange(); 
     137                ImmText oldResult2 = prevEffect.getText(); 
     138                ImmTextInterval damagedInterval = change.getTargetDamage(oldSource); 
     139                ImmText damagedText = oldResult2.subText(damagedInterval); 
     140                damagedText = process(damagedText, procOptions); 
     141                ImmText res = ImmTextUtils.fastReplaceInterval(damagedInterval, oldResult2, damagedText); 
     142                if (res == null) { 
     143                        ImmText prefixText = oldResult2.subText(new ImmTextInterval(oldResult2.getBegin(), damagedInterval.getBegin())); 
     144                        ImmText suffixText = oldResult2.subText(new ImmTextInterval(damagedInterval.getEnd(), oldResult2.getEnd())); 
     145                        res = prefixText.concat(damagedText); 
     146                        res = res.concat(suffixText); 
     147                } 
     148                TextChange newChange = new TextReplaceChange(damagedInterval, damagedText); 
     149                return new DefaultTextEffect(newChange, res); 
    147150        } 
    148151 
    149152        public ImmText process(ImmText sourceText, TextLinkOptions procOptions) { 
     
    161164                                HashMap<HotAttr<?>, Object> values = new HashMap<HotAttr<?>, Object>(); 
    162165                                ImmColor fgColor = procOptions.getColor(linkId); 
    163166                                if (fgColor != null) { 
    164  
    165167                                        values.put(CommonAttr.FOREGROUND_COLOR, fgColor); 
    166                                         unitStyle = unitStyle.derive(values); 
    167168 
    168                                         // TODO performance could be better if the style is applied for a whole interval. 
    169                                         result = result.applyStyle(unitStyle, new ImmTextInterval(i, i+1)); 
     169                                        HotStyleDef newStyle = HotStyleDef.getEmpty().derive(values); 
     170                                        int endIndex = getEndForLinkId(sourceText, i); 
     171                                        result = result.applyStyle(newStyle, new ImmTextInterval(i, endIndex)); 
     172                                        i += endIndex; 
    170173                                } 
    171174                        } 
    172175                } 
    173176 
    174177                return result; 
    175178        } 
     179        private int getEndForLinkId(ImmText sourceText, int beginIndex) { 
     180                String linkId = sourceText.unitAt(beginIndex).getStyle().getValue(CommonAttr.LINK_ATTRIBUTE); 
     181                int endIndex  = beginIndex; 
     182                for (; endIndex < sourceText.getEnd(); ++endIndex) { 
     183                        if (! sourceText.unitAt(endIndex).getStyle().getValue(CommonAttr.LINK_ATTRIBUTE).equals(linkId)) { 
     184                                break; 
     185                        } 
     186                } 
     187                return endIndex; 
     188        } 
    176189 
    177190        public DefaultTextEffect setOptions(ImmText source, ImmText oldProcessed, 
    178191                        TextLinkOptions oldOptions, TextLinkOptions newOptions) { 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/model/TextUtils.java

     
    9797         *                      The text's prefix. 
    9898         */ 
    9999        public static ImmText getPrefix(ImmText text, int toIndex) { 
    100                 if (text.getEnd() == 0) { 
     100                if (text.getEnd() == 0 || text.getEnd() == toIndex) { 
    101101                        return text; 
    102102                } 
    103103                ImmTextInterval interval =  
     
    120120         */ 
    121121        public static ImmText getSuffix(ImmText text, int fromIndex) { 
    122122 
    123                 if (text.getEnd() == 0 && fromIndex == 0) { 
     123                if (text.getEnd() == 0 || fromIndex == text.getBegin()) { 
    124124                        return text; 
    125125                } 
    126126                int begin = ImmTextUtils.advance(text, text.getBegin(), fromIndex); 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/model/ImmHotText.java

     
    8989        public ImmHotText replace(ImmTextInterval interval, ImmText newText) { 
    9090                assert interval != null : "Interval should not be null"; 
    9191                assert newText != null : "Text should not be null"; 
    92                  
     92 
    9393                if (interval.isEmpty() && newText.getEnd() == 0) { 
    9494                        return this; 
    9595                } 
     
    114114                        newTextUnits = newTextUnits.remove(index); 
    115115                } 
    116116 
    117                 int endRunIndex = getRunEnd(0); 
     117                HotStyleDef lastUnitStyle = null; 
     118                HotStyleDef lastUsedStyle = null; 
    118119                HotStyleDef newStyle  = newStyles; 
    119120                if (newText.getEnd() >= 1) { 
    120121                        TextUnit unit = newText.unitAt(0); 
    121122                        HotStyleDef style = unit.getStyle(); 
    122                                 newStyle = newStyle.derive(style); 
     123                        lastUnitStyle = style; 
     124                        newStyle = newStyle.derive(style); 
     125                        lastUsedStyle = newStyle; 
    123126                } 
    124127 
    125128                for (int i = 0; i < newText.getEnd(); ++i, ++index) { 
    126129                        TextUnit unit = newText.unitAt(i); 
    127                         if (i >= endRunIndex) { 
    128                                 HotStyleDef style = unit.getStyle(); 
    129                                 newStyle = newStyle.replaceDerive(style); 
    130                                 endRunIndex = getRunEnd(endRunIndex + 1); 
     130                        HotStyleDef style = unit.getStyle(); 
     131                        if (lastUnitStyle != null &&  
     132                                        style.getHash().equals(lastUnitStyle.getHash())) { 
     133                                newStyle = lastUsedStyle; 
     134                        } else { 
     135                        //I do not see the difference between using derive  
     136                        //and replaceDerive(if sth. is wrong with the styles-use replaceDerive instead) 
     137                        //--diana 05-08-10 
     138                                newStyle = newStyle.derive(style); 
     139                                lastUsedStyle = newStyle; 
     140                                lastUnitStyle = style; 
    131141                        } 
    132142 
    133143                        newTextUnits =  
     
    156166        } 
    157167 
    158168        public ImmHotText applyStyle(HotStyleDef style, ImmTextInterval interval) { 
    159                  
     169 
    160170                if (interval.isEmpty()) { 
    161171                        return this; 
    162172                } 
    163                  
     173 
    164174                ImmList<TextUnit> newImmTextUnits = this.textUnits; 
     175                HotStyleDef lastUnitStyle = this.textUnits.get(interval.getBegin()).getStyle(); 
     176                HotStyleDef lastUsedStyle = this.textUnits.get(interval.getBegin()).getStyle().derive(style); 
    165177 
     178                 
    166179                // TODO what if the begin is after the end?? --kyli 
    167180                for (int i = interval.getBegin(); i < interval.getEnd(); ++i) { 
     181                        HotStyleDef unitStyle = this.textUnits.get(i).getStyle(); 
     182                        HotStyleDef newStyle = lastUsedStyle; 
     183                        if (! unitStyle.getHash().equals(lastUnitStyle.getHash())) { 
     184                                newStyle = unitStyle.derive(style); 
     185                                lastUnitStyle = unitStyle; 
     186                                lastUsedStyle = newStyle; 
     187                        } 
    168188                        TextUnit newTextUnit =  new TextUnit(this.textUnits.get(i).getChar(), 
    169                                         this.textUnits.get(i).getStyle().derive(style)); 
     189                                        newStyle); 
    170190                        newImmTextUnits = newImmTextUnits.set(i, newTextUnit); 
    171191                } 
    172192 
     
    241261                ImmHotText otherHotText = (ImmHotText) otherText; 
    242262                return new ImmHotText(this.textUnits.concat(otherHotText.textUnits)); 
    243263        } 
    244  
    245         private int getRunEnd(int i) { 
    246                 if (this.getEnd() <= i) { 
    247                         return i; 
     264         
     265        @SuppressWarnings("unused") 
     266        private ImmHotText replaceUnits(ImmTextInterval interval, ImmHotText text) { 
     267                ImmList<TextUnit> newUnits = text.textUnits; 
     268                ImmList<TextUnit> newTextUnits = this.textUnits; 
     269                assert interval.getEnd() - interval.getBegin() == newUnits.size() : "Inconsistent replace!"; 
     270                for(int i = interval.getBegin(); i < interval.getEnd(); ++i) { 
     271                        newTextUnits = newTextUnits.set(i, newUnits.get(i - interval.getBegin())); 
    248272                } 
    249                 int endIndex = i; 
    250                 assert endIndex < this.getEnd() && endIndex >= this.getBegin(); 
     273                assert newTextUnits.size() == this.textUnits.size(); 
     274                return new ImmHotText(newTextUnits); 
     275        } 
    251276 
    252                 HotStyleDef styleDef = unitAt(endIndex).getStyle(); 
    253                 while (endIndex < this.getEnd()) { 
    254                         if (! unitAt(endIndex).getStyle().equals(styleDef)) { 
    255                                 break; 
    256                         } 
    257                         ++ endIndex; 
    258                 } 
    259                 return endIndex - 1 < getBegin() ? endIndex : endIndex - 1; 
    260         } 
     277        //Currently the HotStyleDef::equals method is not fast enough to use this function ;( 
     278        //      private int getRunEnd(int i) { 
     279        //              if (this.getEnd() <= i) { 
     280        //                      return i; 
     281        //              } 
     282        //              int endIndex = i; 
     283        //              assert endIndex < this.getEnd() && endIndex >= this.getBegin(); 
     284        // 
     285        //              HotStyleDef styleDef = unitAt(endIndex).getStyle(); 
     286        //              while (endIndex < this.getEnd()) { 
     287        //                      if (! unitAt(endIndex).getStyle().equals(styleDef)) { 
     288        //                              break; 
     289        //                      } 
     290        //                      ++ endIndex; 
     291        //              } 
     292        //              return endIndex - 1 < getBegin() ? endIndex : endIndex - 1; 
     293        //      } 
    261294} 
  • modules/org.sophie2.base.connectivity/.settings/org.eclipse.jdt.launching.prefs

     
     1#Thu Aug 12 11:26:08 EEST 2010 
     2eclipse.preferences.version=1 
     3org.eclipse.jdt.launching.PREF_STRICTLY_COMPATIBLE_JRE_NOT_AVAILABLE=warning 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/CaretProcessor.java

     
    44import java.util.Map; 
    55 
    66import org.sophie2.base.model.text.HotAttr; 
     7import org.sophie2.base.model.text.TextChange; 
     8import org.sophie2.base.model.text.TextReplaceChange; 
    79import org.sophie2.base.model.text.elements.LayoutAttr; 
    810import org.sophie2.base.model.text.model.ImmText; 
    911import org.sophie2.base.model.text.model.ImmTextInterval; 
     
    4547                ImmText sourceText = prevEffect.getText(); 
    4648                ImmText newText = getStyledText(sourceText, procOptions); 
    4749 
    48                 return new DefaultTextEffect(ImmTextUtils.getChange(oldResult, newText), newText); 
     50                ImmTextInterval damagedInterval = prevEffect.getChange().getSourceDamage(oldSource); 
     51                ImmText replaceText = newText.subText(damagedInterval); 
     52                TextChange change = new TextReplaceChange(damagedInterval, replaceText); 
     53                return new DefaultTextEffect(change, newText); 
    4954        } 
    5055 
    5156        public Class<CaretOptions> getOptionsClass() { 
     
    5964        public DefaultTextEffect setOptions(ImmText source,  
    6065                        ImmText oldProcessed, CaretOptions oldOptions, CaretOptions newOptions) { 
    6166 
     67                 
    6268                ImmText newText = getStyledText(source, newOptions); 
    6369 
    6470                return new DefaultTextEffect(ImmTextUtils.getChange(oldProcessed, newText), newText); 
  • modules/org.sophie2.main.func.text/.settings/org.eclipse.core.resources.prefs

     
     1#Thu Aug 12 10:29:41 EEST 2010 
     2eclipse.preferences.version=1 
     3encoding/<project>=UTF-8 
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/rtf/ApplyRtfStylesUtility.java

     
    2020import org.sophie2.base.model.text.elements.TextAlign; 
    2121import org.sophie2.base.model.text.model.ImmHotText; 
    2222import org.sophie2.base.model.text.model.ImmText; 
    23 import org.sophie2.base.model.text.model.ImmTextInterval; 
    2423import org.sophie2.base.model.text.model.ImmTextUtils; 
    2524import org.sophie2.base.model.text.style.HotStyleDef; 
    2625import org.sophie2.main.app.commons.util.AttributedPair; 
     
    7574 
    7675                applyStyles(element, builder, entries); 
    7776 
    78  
    79                 ImmText newText = new ImmHotText(builder.toString(), null); 
     77                String text = builder.toString(); 
     78                ImmText newText = ImmTextUtils.createEmptyText(); 
    8079                int curPos = newText.getBegin(); 
    8180 
    8281                for (ElementEntry entry : entries) { 
    8382                        int length = entry.getLength(); 
    84                         ImmTextInterval interval = new ImmTextInterval(curPos, ImmTextUtils. 
    85                                         advance(newText, curPos, length)); 
    8683                        HotStyleDef def = HotStyleDef.getEmpty().derive(entry.getAttributes()); 
    87                         newText = newText.applyStyle(def, interval); 
    88                         curPos = ImmTextUtils.advance(newText, curPos, length); 
     84                        ImmText styledText = new ImmHotText(text.substring(curPos, curPos + length) , def);  
     85                        curPos += length; 
     86                        newText = newText.concat(styledText); 
    8987                } 
    9088 
    9189                return newText; 
  • modules/org.sophie2.main.func.text/src/main/java/org/sophie2/main/func/text/search/TextSearchProcessor.java

     
    44 
    55import org.sophie2.base.commons.util.ImmColor; 
    66import org.sophie2.base.model.text.HotAttr; 
     7import org.sophie2.base.model.text.TextChange; 
    78import org.sophie2.base.model.text.TextReplaceChange; 
    89import org.sophie2.base.model.text.elements.CommonAttr; 
    910import org.sophie2.base.model.text.model.ImmTextInterval; 
     
    3132        } 
    3233 
    3334        private static TextSearchProcessor instance = null; 
    34  
     35         
    3536        /** 
    3637         * Gets the only instance of this processor. 
    3738         *  
     
    6364 
    6465                ImmText newResult = process(sourceText, procOptions); 
    6566 
    66                 return new DefaultTextEffect( 
    67                                 ImmTextUtils.getChange(oldResult, newResult), newResult); 
     67                ImmTextInterval damagedInterval = prevEffect.getChange().getSourceDamage(oldSource); 
     68                ImmText damagedText = newResult.subText(damagedInterval); 
     69                TextChange change = new TextReplaceChange(damagedInterval, damagedText); 
     70                 
     71                return new DefaultTextEffect(change, newResult); 
    6872        } 
    6973 
    7074        public Class<TextSearchOptions> getOptionsClass() { 
     
    7377 
    7478        public ImmText process(ImmText sourceText, TextSearchOptions procOptions) { 
    7579 
     80                ImmTextInterval searchedInterval = procOptions.getInterval(); 
     81                if (searchedInterval.isEmpty()) { 
     82                        return sourceText; 
     83                } 
    7684                HashMap<HotAttr<?>, Object> styleValues = new HashMap<HotAttr<?>, Object>(); 
    7785                styleValues.put(CommonAttr.BACKGROUND_COLOR, procOptions.getColor()); 
    7886 
    7987                HotStyleDef style = HotStyleDef.getEmpty().derive(styleValues); 
    80                 if (procOptions.getInterval().getBegin() >= sourceText.getBegin() && 
    81                                 procOptions.getInterval().getEnd() <= sourceText.getEnd()) { 
    82                         return sourceText.applyStyle(style, procOptions.getInterval()); 
     88                if (searchedInterval.getBegin() >= sourceText.getBegin() && 
     89                                searchedInterval.getEnd() <= sourceText.getEnd()) { 
     90                        return sourceText.applyStyle(style, searchedInterval); 
    8391                } 
    8492                return sourceText; 
    8593        } 
     
    119127                private final ImmTextInterval interval; 
    120128                private final ImmColor highlightColor; 
    121129 
     130                @Override 
     131                public boolean equals(Object o) { 
     132                        if (o == null) { 
     133                                return false; 
     134                        } 
     135                        if (! (o instanceof TextSearchOptions)) { 
     136                                return false; 
     137                        } 
     138                        TextSearchOptions opts = (TextSearchOptions) o; 
     139                        return this.highlightColor.equals(opts.getColor())  
     140                                                && this.interval.equals(opts.getInterval()); 
     141                } 
    122142                /** 
    123143                 * Default constructor. 
    124144                 *  
  • modules/org.sophie2.extra.func.spellcheck/src/main/java/org/sophie2/extra/func/spellcheck/UnderliningProcessor.java

     
    44import java.util.List; 
    55 
    66import org.sophie2.base.model.text.HotAttr; 
     7import org.sophie2.base.model.text.TextChange; 
    78import org.sophie2.base.model.text.TextReplaceChange; 
    89import org.sophie2.base.model.text.elements.LayoutAttr; 
    910import org.sophie2.base.model.text.model.ImmText; 
    1011import org.sophie2.base.model.text.model.ImmTextInterval; 
    11 import org.sophie2.base.model.text.model.ImmTextUtils; 
    1212import org.sophie2.base.model.text.mvc.DefaultTextEffect; 
    1313import org.sophie2.base.model.text.mvc.TextProcessor; 
    1414import org.sophie2.base.model.text.mvc.TextProcessorEffect; 
     
    4949                ImmText sourceText = prevEffect.getText(); 
    5050                ImmText newResult = process(sourceText, procOptions); 
    5151 
    52                 return new DefaultTextEffect( 
    53                                 ImmTextUtils.getChange(oldResult, newResult), newResult); 
     52                ImmTextInterval damagedInterval = prevEffect.getChange().getSourceDamage(oldSource); 
     53                ImmText damagedText = newResult.subText(damagedInterval); 
     54                TextChange change = new TextReplaceChange(damagedInterval, damagedText); 
     55                return new DefaultTextEffect(change, newResult); 
    5456        } 
    5557 
    5658        public Class<UnderlineOptions> getOptionsClass() { 
     
    7072                         
    7173                        if (procOptions.getIntervals() != null) { 
    7274                                for (ImmTextInterval interval : procOptions.getIntervals()) { 
    73                                         if (interval.getBegin() >= result.getBegin() &&  
     75                                        if (!interval.isEmpty() && interval.getBegin() >= result.getBegin() &&  
    7476                                                interval.getEnd() <= result.getEnd ()){ 
    7577                                                result = result.applyStyle(style, interval); 
    7678                                        } 
     
    8688                        UnderlineOptions newOptions) { 
    8789         
    8890                ImmText result = process (source, newOptions); 
    89                  
     91 
    9092                //TODO: this is possibly slow and unneeded 
    9193                ImmTextInterval oldDamagedInterval = new ImmTextInterval (oldProcessed.getBegin(), oldProcessed.getEnd()); 
    9294                ImmTextInterval newDamagedInterval = new ImmTextInterval (result.getBegin(), result.getEnd()); 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/mvc/SelectionProcessor.java

     
    4444 
    4545        public DefaultTextEffect applyChange(TextProcessorEffect prevEffect, 
    4646                        ImmText oldSource, ImmText oldResult, SelectionOptions procOptions) { 
    47          
     47 
    4848                ImmText sourceText = prevEffect.getText(); 
    4949                ImmText newText = processText(sourceText, procOptions);  
    5050 
    5151                assert newText.getEnd() ==  
    5252                        sourceText.getEnd() : newText.getEnd() + " : " + sourceText.getEnd(); 
     53                ImmTextInterval damagedInterval = prevEffect.getChange().getSourceDamage(oldSource); 
     54                ImmText damagedText = newText.subText(damagedInterval); 
    5355 
    54                         return new DefaultTextEffect(ImmTextUtils.getChange(oldResult, newText), newText); 
     56                TextChange change = new TextReplaceChange(damagedInterval, damagedText); 
     57                return new DefaultTextEffect(change, newText); 
    5558        } 
    5659 
    5760        public Class<SelectionOptions> getOptionsClass() { 
     
    7578                Object value = procOptions.getValue(); 
    7679                ImmTextInterval selectionInterval = procOptions.getSelection(); 
    7780 
     81                if (selectionInterval.isEmpty()) { 
     82                        return sourceText; 
     83                } 
    7884                if (ImmTextUtils.isIndexInText(selectionInterval.getBegin(), sourceText) && 
    7985                                ImmTextUtils.isIndexInText(selectionInterval.getEnd(), sourceText)) {  
    8086 
     
    9399        public DefaultTextEffect setOptions(ImmText source,  
    94100                        ImmText oldProcessed, SelectionOptions oldOptions, SelectionOptions newOptions) { 
    95101 
     102                ImmText newText; 
     103                if (newOptions.equals(oldOptions)) { 
     104                        newText = oldProcessed; 
     105                } else { 
     106                        newText = processText(source, newOptions); 
     107                } 
    96108                ImmTextInterval damagedInterval =  
    97109                        oldOptions.getSelection().unite(newOptions.getSelection()); 
    98110 
    99                 ImmText newText = processText(source, newOptions); 
    100  
    101111                TextChange change =  
    102112                        new TextReplaceChange(damagedInterval, newText.subText(damagedInterval)); 
    103113 
  • modules/org.sophie2.extra.func.spellcheck/src/test/java/org/sophie2/extra/func/spellcheck/SpellCheckDemoTest.java

     
    327327                                String textStr = modelText.toString(); 
    328328 
    329329                                List<String> misspelled = new LinkedList<String> (); 
    330                                 SpellCheckUtility.getMisspelledWords (misspelled, null, textStr); 
     330                                //SpellCheckUtility.getMisspelledWords (misspelled, null, textStr); 
    331331 
    332332                                DefaultListModel model = (DefaultListModel) listMisspelled.getModel(); 
    333333 
  • modules/org.sophie2.base.connectivity/.settings/org.eclipse.jdt.core.prefs

     
    1 #Wed Oct 21 16:55:23 EEST 2009 
     1#Thu Aug 12 11:26:08 EEST 2010 
    22eclipse.preferences.version=1 
    33org.eclipse.jdt.core.builder.cleanOutputFolder=clean 
    44org.eclipse.jdt.core.builder.duplicateResourceTask=warning 
     
    1616org.eclipse.jdt.core.codeComplete.localSuffixes= 
    1717org.eclipse.jdt.core.codeComplete.staticFieldPrefixes= 
    1818org.eclipse.jdt.core.codeComplete.staticFieldSuffixes= 
     19org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes= 
     20org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes= 
    1921org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 
    2022org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 
    2123org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/model/ImmTextUtils.java

     
    11package org.sophie2.base.model.text.model; 
    22 
     3import java.lang.reflect.InvocationTargetException; 
     4import java.lang.reflect.Method; 
    35import java.util.HashMap; 
    46import java.util.Map; 
    57 
     
    7072        public static int advance(ImmText text, int index, int offset) { 
    7173                if (!isIndexInText(index, text)) { 
    7274                        throw new IllegalArgumentException("The input index does not " + 
    73                         "belong to the current text: " + index + " text: " + text + ":"); 
     75                                        "belong to the current text: " + index + " text: " + text + ":"); 
    7476                } 
    7577 
    7678                int newIndex = index + offset; 
     
    9698         *             New concatenate text.  
    9799         */ 
    98100        public static ImmText concat(ImmText text1, ImmText text2) { 
    99                  
     101 
    100102                return text1.concat(text2); 
    101 //              ImmText replacedText = text1.replace(new ImmTextInterval(text1.getEnd(), 
    102 //                              text1.getEnd()), text2); 
    103 //              int endText1 = text1.getEnd(); 
    104 //              for (int i = text2.getBegin(); i < text2.getEnd(); ++i) { 
    105 //                      int pos = i + endText1; 
    106 //                      replacedText = replacedText.applyStyle( 
    107 //                                      HotStyleDef.getDefault().derive(text2.unitAt(i).getStyle()), 
    108 //                                      new ImmTextInterval(pos, pos + 1)); 
    109 //              } 
    110 //              return replacedText; 
     103                //              ImmText replacedText = text1.replace(new ImmTextInterval(text1.getEnd(), 
     104                //                              text1.getEnd()), text2); 
     105                //              int endText1 = text1.getEnd(); 
     106                //              for (int i = text2.getBegin(); i < text2.getEnd(); ++i) { 
     107                //                      int pos = i + endText1; 
     108                //                      replacedText = replacedText.applyStyle( 
     109                //                                      HotStyleDef.getDefault().derive(text2.unitAt(i).getStyle()), 
     110                //                                      new ImmTextInterval(pos, pos + 1)); 
     111                //              } 
     112                //              return replacedText; 
    111113        } 
    112114 
    113115        /** 
     
    145147                                text.getStyleValue(attribute, new ImmTextInterval(beginPosition, beginPosition)))) { 
    146148                        beginPosition = advance(text, beginPosition, - 1); 
    147149                } 
    148                  
     150 
    149151                if (!(beginPosition == text.getBegin() && value.equals( 
    150152                                text.getStyleValue(attribute, new ImmTextInterval(beginPosition, beginPosition))))) { 
    151153                        beginPosition = advance(text, beginPosition, 1); 
     
    195197                return text.unitAt(position).getStyle().getValue(attribute); 
    196198        } 
    197199 
    198          
     200 
    199201        /** 
    200202         * Creates a change that modifies the source text to the result. 
    201203         *  
     
    208210         *                              change.applyTo(source).getStyledHash().equals(result.getStyledHash). 
    209211         */ 
    210212        public static TextChange getChange(ImmText source, ImmText result) { 
    211                  
     213 
    212214                // FIXME this implementation is dummy.. --kyli@2010-05-20 
    213215                return new TextReplaceChange( 
    214216                                new ImmTextInterval(source.getBegin(), source.getEnd()), result); 
    215217        } 
     218        /** 
     219         * Method for fast(faster than using the replace function of the text) replacing interval of a text with another text.  
     220         * The replacing text should be the same length as the interval. The styles of the new text are not derived -  
     221         * they are the same as using concat function. 
     222         *  
     223         * @param interval 
     224         *                              The interval to be replaced. 
     225         * @param oldText 
     226         *                              The text to be replaced. 
     227         * @param replacedText 
     228         *                              The replacing text. 
     229         * @return 
     230         *                      The new replaced text. 
     231         */ 
     232        public static ImmText fastReplaceInterval(ImmTextInterval interval, ImmText oldText, ImmText replacedText) { 
     233                if(! (oldText instanceof ImmHotText) || ! (replacedText instanceof ImmHotText)) { 
     234                        return null; 
     235                } 
     236                ImmHotText oldHotText = (ImmHotText) oldText; 
     237                ImmHotText replacedHotText = (ImmHotText) replacedText; 
     238                try { 
     239                        Method m = oldHotText.getClass().getDeclaredMethod("replaceUnits", ImmTextInterval.class, ImmHotText.class); 
     240                        m.setAccessible(true); 
     241                        try { 
     242                                return (ImmText) m.invoke(oldHotText, interval, replacedHotText); 
     243                        } catch (IllegalArgumentException e) { 
     244                                return null; 
     245                        } catch (IllegalAccessException e) { 
     246                                return null; 
     247                        } catch (InvocationTargetException e) { 
     248                                return null; 
     249                        } 
     250                } catch (SecurityException e) { 
     251                        return null; 
     252                } catch (NoSuchMethodException e) { 
     253                        return null; 
     254                } 
     255        } 
    216256} 
  • modules/org.sophie2.base.model.text/src/main/java/org/sophie2/base/model/text/style/HotStyleDef.java

     
    44import java.util.Iterator; 
    55import java.util.Map; 
    66 
     7import org.sophie2.base.commons.structures.ImmTreeList; 
    78import org.sophie2.base.commons.structures.ImmTreeMap; 
    89import org.sophie2.base.commons.util.Hash; 
    910import org.sophie2.base.commons.util.Hashable; 
    1011import org.sophie2.base.commons.util.Hasher; 
    11 import org.sophie2.base.commons.util.AccessCreateCollectionUtil; 
    1212import org.sophie2.base.commons.util.ImmList; 
    1313import org.sophie2.base.commons.util.ImmMap; 
    14 import org.sophie2.base.commons.util.ImmMap.ImmEntry; 
    1514import org.sophie2.base.model.text.HotAttr; 
    1615import org.sophie2.base.model.text.elements.CommonAttr; 
    1716import org.sophie2.base.model.text.model.TextUnit; 
     
    3736        private static final Map<ImmMap<HotAttr<?>, Object>, HotStyleDef> usedStyles =  
    3837                new HashMap<ImmMap<HotAttr<?>,Object>, HotStyleDef>(); 
    3938 
    40  
     39        private Hash hashCode = null; 
     40         
    4141        private HotStyleDef(ImmMap<HotAttr<?>, Object> values) { 
    4242                // Disable direct instantiation. 
    4343                ImmMap<HotAttr<?>, Object> allValues = values; 
     
    8080         *                      The style's attributes. 
    8181         */ 
    8282        public ImmList<HotAttr<?>> getAttributeKeys() { 
    83                 ImmList<HotAttr<?>> keys = AccessCreateCollectionUtil.<HotAttr<?>>createDosImmList(); 
    84                 for (ImmEntry<HotAttr<?>, Object> entry : this.attrValues.asList()) { 
    85                         keys = keys.add(entry.getKey()); 
    86                 } 
    87                 return keys; 
     83                return ImmTreeList.create(this.attrValues.toMap().keySet()); 
    8884        } 
    8985 
    9086 
     
    242238        } 
    243239 
    244240        public Hash getHash() { 
    245  
    246                 Hasher hasher = new Hasher(); 
    247                 // XXX values may not be hash-able..  
    248                 // think of a smarter realization of HotStyleDef!! --kyli 
    249                 Iterator<ImmMap.ImmEntry<HotAttr<?>, Object>> it = this.attrValues.iterator(); 
    250                 while (it.hasNext()) { 
    251                         ImmMap.ImmEntry<HotAttr<?>, Object> entry = it.next(); 
    252                         hasher.addHashed(entry.getKey().getHash()); 
    253                         hasher.addObject(entry.getValue()); 
     241                if (this.hashCode == null) { 
     242                        Hasher hasher = new Hasher(); 
     243                        // XXX values may not be hash-able..  
     244                        // think of a smarter realization of HotStyleDef!! --kyli 
     245                        Iterator<ImmMap.ImmEntry<HotAttr<?>, Object>> it = this.attrValues.iterator(); 
     246                        while (it.hasNext()) { 
     247                                ImmMap.ImmEntry<HotAttr<?>, Object> entry = it.next(); 
     248                                hasher.addHashed(entry.getKey().getHash()); 
     249                                hasher.addObject(entry.getValue()); 
     250                        } 
     251                        this.hashCode = hasher.toHash(); 
    254252                } 
    255                 return hasher.toHash(); 
     253                return this.hashCode; 
    256254        } 
    257255} 
     256 No newline at end of file