Home » apache-harmony-6.0-src-r917296-snapshot » org.apache.harmony.awt.text » [javadoc | source]

    1   /*
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   /**
   19    * @author Alexey A. Ivanov, Evgeniya G. Maenkova
   20    */
   21   package org.apache.harmony.awt.text;
   22   
   23   import java.text.AttributedCharacterIterator;
   24   import java.text.AttributedString;
   25   
   26   import javax.swing.text.BadLocationException;
   27   import javax.swing.text.Document;
   28   import javax.swing.text.Position;
   29   
   30   /**
   31    * Stores composed text parameters: the  composed text itself,
   32    * its length and where it starts in a document. Also stores the latest
   33    * committed text start. Instance of this class is used
   34    * as a value of document property
   35    *  <code>AbstractDocument.ComposedTextProperty</code>.
   36    *
   37    */
   38   public class ComposedTextParams {
   39       private Position lastCommittedTextStart;
   40       private int composedTextLength;
   41       private Document document;
   42       private Position composedTextStart;
   43       private AttributedString composedText;
   44   
   45       public ComposedTextParams(final Document document) {
   46           this.document = document;
   47       }
   48   
   49       public int getComposedTextStart() {
   50           return composedTextStart.getOffset();
   51       }
   52   
   53       public void setComposedTextStart(final int offset) {
   54           try {
   55               composedTextStart = document.createPosition(offset);
   56           } catch (BadLocationException e) {
   57           }
   58       }
   59   
   60       public int getLastCommittedTextStart() {
   61           return lastCommittedTextStart.getOffset();
   62       }
   63   
   64       public void setLastCommittedTextStart(final int offset) {
   65           try {
   66               lastCommittedTextStart = document.createPosition(offset);
   67           } catch (BadLocationException e) {
   68           }
   69       }
   70   
   71       public void setComposedTextLength(final int length) {
   72           composedTextLength = length;
   73       }
   74   
   75       public int getComposedTextLength() {
   76           return composedTextLength;
   77       }
   78   
   79       public int getLastCommittedTextLength() {
   80           return getComposedTextStart() - getLastCommittedTextStart();
   81       }
   82   
   83       public void setComposedText(final AttributedString text) {
   84           composedText = text;
   85       }
   86   
   87       public AttributedString getComposedText() {
   88           return composedText;
   89       }
   90   
   91       public void resetComposedText() {
   92           composedTextLength = 0;
   93           composedText = null;
   94       }
   95   
   96       public void setComposedText(final AttributedCharacterIterator iterator,
   97                                   final int composedStart, final int end) {
   98           composedText = new AttributedString(iterator, composedStart, end);
   99           composedTextLength = end - composedStart;
  100       }
  101   }

Home » apache-harmony-6.0-src-r917296-snapshot » org.apache.harmony.awt.text » [javadoc | source]