001: /*
002: * @(#)QtTextFieldPeer.java 1.12 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.awt.event.*;
032:
033: /**
034: *
035: *
036: * @author Nicholas Allen
037: */
038:
039: class QtTextFieldPeer extends QtTextComponentPeer implements
040: TextFieldPeer {
041: private static native void initIDs();
042:
043: static {
044: initIDs();
045: }
046:
047: private static final int padding = 10;
048:
049: /** Creates a new QtTextFieldPeer. */
050:
051: QtTextFieldPeer(QtToolkit toolkit, TextField target) {
052: super (toolkit, target);
053: setEchoChar(target.getEchoChar());
054: }
055:
056: protected native void create(QtComponentPeer parentPeer);
057:
058: public native void setEchoChar(char echoChar);
059:
060: public Dimension getPreferredSize(int columns) {
061: FontMetrics fm = getFontMetrics(target.getFont());
062: return new Dimension(fm.charWidth('0') * columns + 20, fm
063: .getMaxDescent()
064: + fm.getMaxAscent() + padding);
065: }
066:
067: public Dimension getMinimumSize(int columns) {
068: return getPreferredSize(columns);
069: }
070:
071: /**
072: * DEPRECATED: Replaced by setEchoChar(char echoChar).
073: */
074: public void setEchoCharacter(char c) {
075: setEchoChar(c);
076: }
077:
078: /**
079: * DEPRECATED: Replaced by getPreferredSize(int).
080: */
081: public Dimension preferredSize(int cols) {
082: return getPreferredSize(cols);
083: }
084:
085: /**
086: * DEPRECATED: Replaced by getMinimumSize(int).
087: */
088: public Dimension minimumSize(int cols) {
089: return getMinimumSize(cols);
090: }
091:
092: private void postActionEvent() {
093: QtToolkit.postEvent(new ActionEvent(target,
094: ActionEvent.ACTION_PERFORMED, getText()));
095: /*
096: * Fix bug 4818521 (deadlock).
097: *
098: * Should not use target.getText(), but use
099: * QtTextComponentPeer.getText() instead. Calling target.getText()
100: * invloves grabbing the lock associated with the target instance while
101: * the thread already owns the qt lock, which can deadlock easily with a
102: * thread which calls getText() where the lock sequence is:
103: *
104: * [target instance lock], then [qt lock].
105: */
106: }
107:
108: public boolean isFocusable() {
109: return true;
110: }
111: }
|