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: * @author Michael Danilov
019: * @version $Revision$
020: */package java.awt.event;
021:
022: import java.awt.AWTEvent;
023: import java.awt.Component;
024: import java.awt.font.TextHitInfo;
025: import java.text.AttributedCharacterIterator;
026:
027: import org.apache.harmony.awt.internal.nls.Messages;
028:
029: public class InputMethodEvent extends AWTEvent {
030:
031: private static final long serialVersionUID = 4727190874778922661L;
032:
033: public static final int INPUT_METHOD_FIRST = 1100;
034:
035: public static final int INPUT_METHOD_TEXT_CHANGED = 1100;
036:
037: public static final int CARET_POSITION_CHANGED = 1101;
038:
039: public static final int INPUT_METHOD_LAST = 1101;
040:
041: private AttributedCharacterIterator text;
042: private TextHitInfo visiblePosition;
043: private TextHitInfo caret;
044: private int committedCharacterCount;
045: private long when;
046:
047: public InputMethodEvent(Component src, int id, TextHitInfo caret,
048: TextHitInfo visiblePos) {
049: this (src, id, null, 0, caret, visiblePos);
050: }
051:
052: public InputMethodEvent(Component src, int id,
053: AttributedCharacterIterator text, int commitedCharCount,
054: TextHitInfo caret, TextHitInfo visiblePos) {
055: this (src, id, 0l, text, commitedCharCount, caret, visiblePos);
056: }
057:
058: public InputMethodEvent(Component src, int id, long when,
059: AttributedCharacterIterator text,
060: int committedCharacterCount, TextHitInfo caret,
061: TextHitInfo visiblePos) {
062: super (src, id);
063:
064: if ((id < INPUT_METHOD_FIRST) || (id > INPUT_METHOD_LAST)) {
065: // awt.18E=Wrong event id
066: throw new IllegalArgumentException(Messages
067: .getString("awt.18E")); //$NON-NLS-1$
068: }
069: if ((id == CARET_POSITION_CHANGED) && (text != null)) {
070: // awt.18F=Text must be null for CARET_POSITION_CHANGED
071: throw new IllegalArgumentException(Messages
072: .getString("awt.18F")); //$NON-NLS-1$
073: }
074: if ((text != null)
075: && ((committedCharacterCount < 0) || (committedCharacterCount > (text
076: .getEndIndex() - text.getBeginIndex())))) {
077: // awt.190=Wrong committedCharacterCount
078: throw new IllegalArgumentException(Messages
079: .getString("awt.190")); //$NON-NLS-1$
080: }
081:
082: this .when = when;
083: this .text = text;
084: this .caret = caret;
085: this .visiblePosition = visiblePos;
086: this .committedCharacterCount = committedCharacterCount;
087: }
088:
089: public TextHitInfo getCaret() {
090: return caret;
091: }
092:
093: public int getCommittedCharacterCount() {
094: return committedCharacterCount;
095: }
096:
097: public AttributedCharacterIterator getText() {
098: return text;
099: }
100:
101: public TextHitInfo getVisiblePosition() {
102: return visiblePosition;
103: }
104:
105: public long getWhen() {
106: return when;
107: }
108:
109: @Override
110: public void consume() {
111: super .consume();
112: }
113:
114: @Override
115: public boolean isConsumed() {
116: return super .isConsumed();
117: }
118:
119: @Override
120: public String paramString() {
121: /* The format is based on 1.5 release behavior
122: * which can be revealed by the following code:
123: *
124: * InputMethodEvent e = new InputMethodEvent(new Component(){},
125: * InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
126: * TextHitInfo.leading(1), TextHitInfo.trailing(2));
127: * System.out.println(e);
128: */
129: String typeString = null;
130:
131: switch (id) {
132: case INPUT_METHOD_TEXT_CHANGED:
133: typeString = "INPUT_METHOD_TEXT_CHANGED"; //$NON-NLS-1$
134: break;
135: case CARET_POSITION_CHANGED:
136: typeString = "CARET_POSITION_CHANGED"; //$NON-NLS-1$
137: break;
138: default:
139: typeString = "unknown type"; //$NON-NLS-1$
140: }
141:
142: return typeString + ",text=" + text + //$NON-NLS-1$
143: ",commitedCharCount="
144: + committedCharacterCount
145: + //$NON-NLS-1$
146: ",caret=" + caret
147: + ",visiblePosition=" + visiblePosition; //$NON-NLS-1$ //$NON-NLS-2$
148: }
149:
150: }
|