001: /*
002: * @(#)PPCTextAreaPeer.java 1.10 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:
032: class PPCTextAreaPeer extends PPCTextComponentPeer implements
033: TextAreaPeer {
034:
035: private static native void initIDs();
036:
037: static {
038: initIDs();
039: }
040:
041: /** Creates a new PPCTextAreaPeer. */
042: PPCTextAreaPeer(TextArea target) {
043: super (target);
044: }
045:
046: public Dimension getMinimumSize() {
047: return getMinimumSize(10, 60);
048: }
049:
050: // TextAreaPeer implementation
051:
052: /* This should eventually be a direct native method. */
053: public void insert(String txt, int pos) {
054: insertText(txt, pos);
055: }
056:
057: /* This should eventually be a direct native method. */
058: public void replaceRange(String txt, int start, int end) {
059: replaceText(txt, start, end);
060: }
061:
062: public Dimension getPreferredSize(int rows, int cols) {
063: return getMinimumSize(rows, cols);
064: }
065:
066: public Dimension getMinimumSize(int rows, int cols) {
067: FontMetrics fm = getFontMetrics(((TextArea) target).getFont());
068: PPCToolkit toolkit = (PPCToolkit) Toolkit.getDefaultToolkit();
069:
070: int extraWidth = 2 * toolkit.frameWidth;
071: int extraHeight = 2 * toolkit.frameHeight;
072: int hsbHeight = toolkit.hsbHeight;
073: int hsbMinWidth = toolkit.hsbMinWidth;
074: int vsbMinHeight = toolkit.vsbMinHeight;
075: int vsbWidth = toolkit.vsbWidth;
076:
077: int sbv = ((TextArea) target).getScrollbarVisibility();
078: Dimension dim = new Dimension(fm.charWidth('0') * cols, fm
079: .getHeight()
080: * rows);
081: switch (sbv) {
082: case TextArea.SCROLLBARS_HORIZONTAL_ONLY:
083: dim.height += hsbHeight;
084: if (dim.width < hsbMinWidth) {
085: dim.width = hsbMinWidth;
086: }
087: break;
088: case TextArea.SCROLLBARS_VERTICAL_ONLY:
089: dim.width += vsbWidth;
090: if (dim.height < vsbMinHeight) {
091: dim.height = vsbMinHeight;
092: }
093: break;
094: case TextArea.SCROLLBARS_BOTH:
095: if (dim.height < vsbMinHeight) {
096: dim.height = vsbMinHeight;
097: }
098: if (dim.width < hsbMinWidth) {
099: dim.width = hsbMinWidth;
100: }
101: dim.height += hsbHeight;
102: dim.width += vsbWidth;
103: break;
104:
105: case TextArea.SCROLLBARS_NONE:
106: break;
107: }
108: dim.width += extraWidth;
109: dim.height += extraHeight;
110: return dim;
111: }
112:
113: native void create(PPCComponentPeer parent);
114:
115: // native callbacks
116:
117: // deprecated methods
118:
119: /**
120: * DEPRECATED but, for now, still called by insert(String, int).
121: */
122: public void insertText(String txt, int pos) {
123: replaceText(txt, pos, pos);
124: }
125:
126: /**
127: * DEPRECATED but, for now, still called by replaceRange(String, int, int).
128: */
129: public native void replaceText(String txt, int start, int end);
130:
131: /**
132: * DEPRECATED
133: */
134: public Dimension minimumSize() {
135: return getMinimumSize();
136: }
137:
138: /**
139: * DEPRECATED
140: */
141: public Dimension minimumSize(int rows, int cols) {
142: return getMinimumSize(rows, cols);
143: }
144:
145: /**
146: * DEPRECATED
147: */
148: public Dimension preferredSize(int rows, int cols) {
149: return getPreferredSize(rows, cols);
150: }
151: }
|