001: /*
002: * @(#)PPCTextFieldPeer.java 1.8 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.awt.*;
030: import sun.awt.peer.*;
031: import java.awt.event.*;
032:
033: class PPCTextFieldPeer extends PPCTextComponentPeer implements
034: TextFieldPeer {
035: private static native void initIDs();
036:
037: static {
038: initIDs();
039: }
040:
041: /** Creates a new PPCTextFieldPeer. */
042: PPCTextFieldPeer(TextField target) {
043: super (target);
044: }
045:
046: public Dimension getMinimumSize() {
047: FontMetrics fm = getFontMetrics(((TextField) target).getFont());
048: return new Dimension(fm.stringWidth(getText()) + 24, fm
049: .getHeight() + 8);
050: }
051:
052: // TextFieldPeer implementation
053:
054: /* This should eventually be a direct native method. */
055: public void setEchoChar(char c) {
056: setEchoCharacter(c);
057: }
058:
059: public Dimension getPreferredSize(int cols) {
060: return getMinimumSize(cols);
061: }
062:
063: public Dimension getMinimumSize(int cols) {
064: FontMetrics fm = getFontMetrics(((TextField) target).getFont());
065: return new Dimension(fm.charWidth('0') * cols + 24, fm
066: .getHeight() + 8);
067: }
068:
069: native void create(PPCComponentPeer parent);
070:
071: void initialize() {
072: TextField tf = (TextField) target;
073: if (tf.echoCharIsSet()) {
074: setEchoChar(tf.getEchoChar());
075: }
076: super .initialize();
077: }
078:
079: // native callbacks
080:
081: void handleAction() {
082: PPCToolkit.postEvent(new ActionEvent(target,
083: ActionEvent.ACTION_PERFORMED, getText()));
084: }
085:
086: // deprecated methods
087:
088: /**
089: * DEPRECATED but, for now, called by setEchoChar(char).
090: */
091: public native void setEchoCharacter(char c);
092:
093: /**
094: * DEPRECATED
095: */
096: public Dimension minimumSize() {
097: return getMinimumSize();
098: }
099:
100: /**
101: * DEPRECATED
102: */
103: public Dimension minimumSize(int cols) {
104: return getMinimumSize(cols);
105: }
106:
107: /**
108: * DEPRECATED
109: */
110: public Dimension preferredSize(int cols) {
111: return getPreferredSize(cols);
112: }
113: }
|