001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Alexey A. Ivanov, Evgeniya G. Maenkova
020: * @version $Revision$
021: */package org.apache.harmony.awt.text;
022:
023: import java.text.AttributedCharacterIterator;
024: import java.text.AttributedString;
025:
026: import javax.swing.text.BadLocationException;
027: import javax.swing.text.Document;
028: import javax.swing.text.Position;
029:
030: /**
031: * Stores composed text parameters: the composed text itself,
032: * its length and where it starts in a document. Also stores the latest
033: * committed text start. Instance of this class is used
034: * as a value of document property
035: * <code>AbstractDocument.ComposedTextProperty</code>.
036: *
037: */
038: public class ComposedTextParams {
039: private Position lastCommittedTextStart;
040: private int composedTextLength;
041: private Document document;
042: private Position composedTextStart;
043: private AttributedString composedText;
044:
045: public ComposedTextParams(final Document document) {
046: this .document = document;
047: }
048:
049: public int getComposedTextStart() {
050: return composedTextStart.getOffset();
051: }
052:
053: public void setComposedTextStart(final int offset) {
054: try {
055: composedTextStart = document.createPosition(offset);
056: } catch (BadLocationException e) {
057: }
058: }
059:
060: public int getLastCommittedTextStart() {
061: return lastCommittedTextStart.getOffset();
062: }
063:
064: public void setLastCommittedTextStart(final int offset) {
065: try {
066: lastCommittedTextStart = document.createPosition(offset);
067: } catch (BadLocationException e) {
068: }
069: }
070:
071: public void setComposedTextLength(final int length) {
072: composedTextLength = length;
073: }
074:
075: public int getComposedTextLength() {
076: return composedTextLength;
077: }
078:
079: public int getLastCommittedTextLength() {
080: return getComposedTextStart() - getLastCommittedTextStart();
081: }
082:
083: public void setComposedText(final AttributedString text) {
084: composedText = text;
085: }
086:
087: public AttributedString getComposedText() {
088: return composedText;
089: }
090:
091: public void resetComposedText() {
092: composedTextLength = 0;
093: composedText = null;
094: }
095:
096: public void setComposedText(
097: final AttributedCharacterIterator iterator,
098: final int composedStart, final int end) {
099: composedText = new AttributedString(iterator, composedStart,
100: end);
101: composedTextLength = end - composedStart;
102: }
103: }
|