001: /*
002: * @(#)PPCTextComponentPeer.java 1.9 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package sun.awt.pocketpc;
028:
029: import java.security.*;
030: import java.awt.*;
031: import java.awt.event.*;
032: import java.awt.datatransfer.*;
033: import sun.awt.peer.*;
034:
035: abstract class PPCTextComponentPeer extends PPCComponentPeer implements
036: TextComponentPeer {
037: private static native void initIDs();
038:
039: static {
040: initIDs();
041: }
042:
043: /** Creates a new PPCTextComponentPeer. */
044: PPCTextComponentPeer(TextComponent target) {
045: super (target);
046: }
047:
048: // PPCComponentPeer overrides
049:
050: public void setBackground(Color c) {
051: TextComponent tc = (TextComponent) target;
052: if (tc.isEditable()) {
053: c = c.brighter();
054: }
055: super .setBackground(c);
056: }
057:
058: // TextComponentPeer implementation
059:
060: public void setEditable(boolean editable) {
061: enableEditing(editable);
062: setBackground(((TextComponent) target).getBackground());
063: }
064:
065: public native String getText();
066:
067: public native void setText(String txt);
068:
069: public native int getSelectionStart();
070:
071: public native int getSelectionEnd();
072:
073: public native void select(int selStart, int selEnd);
074:
075: void initialize() {
076: TextComponent tc = (TextComponent) target;
077: String text = tc.getText();
078:
079: if (text != null) {
080: setText(text);
081: }
082: select(tc.getSelectionStart(), tc.getSelectionEnd());
083: setEditable(tc.isEditable());
084:
085: super .initialize();
086: }
087:
088: void clearRectBeforePaint(Graphics g, Rectangle r) {
089: // Overload to do nothing for native components
090: }
091:
092: native void enableEditing(boolean e);
093:
094: public boolean isFocusTraversable() {
095: return true;
096: }
097:
098: /*
099: * Set the caret position by doing an empty selection. This
100: * unfortunately resets the selection, but seems to be the
101: * only way to get this to work.
102: */
103: public void setCaretPosition(int pos) {
104: select(pos, pos);
105: }
106:
107: /*
108: * Get the caret position by looking up the end of the current
109: * selection.
110: */
111: public int getCaretPosition() {
112: return getSelectionStart();
113: };
114:
115: /*
116: * Post a new TextEvent when the value of a text component changes.
117: */
118: public void valueChanged() {
119: postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
120: }
121:
122: }
|