001: /*
002: * @(#)QtTextAreaPeer.java 1.14 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.qt;
028:
029: import java.awt.*;
030: import sun.awt.peer.*;
031: import java.security.AccessController;
032: import sun.security.action.GetPropertyAction;
033:
034: /**
035: *
036: *
037: * @author Nicholas Allen
038: */
039:
040: class QtTextAreaPeer extends QtTextComponentPeer implements
041: TextAreaPeer {
042: /** Creates a new QtTextAreaPeer. */
043:
044: QtTextAreaPeer(QtToolkit toolkit, TextArea target) {
045: super (toolkit, target);
046: }
047:
048: protected void create(QtComponentPeer parentPeer) {
049: // currently, this following property is an undocumented property to determine
050: // whether or not wordwrap on word boundaries should be used. If true, it will
051: // be used. Otherwise, lines will break on any character.
052:
053: String prop = (String) AccessController
054: .doPrivileged(new GetPropertyAction(
055: "sun.textarea.wordwrap"));
056: if (prop == null) {
057: create(parentPeer, false);
058: } else if (prop.toLowerCase().equals("true")) {
059: create(parentPeer, true);
060: } else {
061: create(parentPeer, false);
062: }
063: }
064:
065: protected native void create(QtComponentPeer parentPeer,
066: boolean wordwrap);
067:
068: protected native void insertNative(String text, int pos);
069:
070: native int getExtraWidth();
071:
072: native int getExtraHeight();
073:
074: public void insert(String text, int pos) {
075: if (text != null)
076: insertNative(text, pos);
077: }
078:
079: protected native void replaceRangeNative(String text, int start,
080: int end);
081:
082: public void replaceRange(String text, int start, int end) {
083: if (text != null)
084: replaceRangeNative(text, start, end);
085: }
086:
087: public Dimension getPreferredSize(int rows, int columns) {
088: FontMetrics fm = getFontMetrics(target.getFont());
089:
090: /* Calculate proper size for text area
091: */
092: int colWidth = fm.charWidth('0');
093: int rowHeight = fm.getHeight();
094: //int rowHeight = fm.getMaxAscent() + fm.getMaxDescent();
095:
096: // The getExtraWidth() and getExtraHeight() calls, inspired from J2SE,
097: // calculate the extra space for scrollbars and other margins.
098: return new Dimension(columns * colWidth + getExtraWidth(), rows
099: * rowHeight + getExtraHeight());
100: }
101:
102: public Dimension getMinimumSize(int rows, int columns) {
103: return getMinimumSize();
104: }
105:
106: /**
107: * DEPRECATED: Replaced by insert(String, int).
108: */
109: public void insertText(String txt, int pos) {
110: insert(txt, pos);
111: }
112:
113: /**
114: * DEPRECATED: Replaced by ReplaceRange(String, int, int).
115: */
116: public void replaceText(String txt, int start, int end) {
117: replaceRange(txt, start, end);
118: }
119:
120: /**
121: * DEPRECATED: Replaced by getPreferredSize(int, int).
122: */
123: public Dimension preferredSize(int rows, int cols) {
124: return getPreferredSize(rows, cols);
125: }
126:
127: /**
128: * DEPRECATED: Replaced by getMinimumSize(int, int).
129: */
130: public Dimension minimumSize(int rows, int cols) {
131: return getMinimumSize(rows, cols);
132: }
133:
134: public boolean isFocusable() {
135: return true;
136: }
137: }
|