001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.core.gui.util;
019:
020: import javax.swing.JComponent;
021: import javax.swing.JTextField;
022:
023: import org.columba.core.gui.base.UndoDocument;
024:
025: /**
026: * Additionally registers at the FocusManager.
027: *
028: * @author fdietz
029: */
030:
031: public class CTextField extends JTextField {
032: /**
033: *
034: */
035: public CTextField() {
036: super ();
037:
038: setDocument(new UndoDocument());
039: }
040:
041: /**
042: * @param arg0
043: */
044: public CTextField(String arg0) {
045: this ();
046:
047: setText(arg0);
048: }
049:
050: /** ****************** FocusOwner implementation ************************* */
051: public JComponent getComponent() {
052: return this ;
053: }
054:
055: public boolean isCopyActionEnabled() {
056: if (getSelectedText() == null) {
057: return false;
058: }
059:
060: if (getSelectedText().length() > 0) {
061: return true;
062: }
063:
064: return false;
065: }
066:
067: public boolean isCutActionEnabled() {
068: if (getSelectedText() == null) {
069: return false;
070: }
071:
072: if (getSelectedText().length() > 0) {
073: return true;
074: }
075:
076: return false;
077: }
078:
079: public boolean isDeleteActionEnabled() {
080: if (getSelectedText() == null) {
081: return false;
082: }
083:
084: if (getSelectedText().length() > 0) {
085: return true;
086: }
087:
088: return false;
089: }
090:
091: public boolean isPasteActionEnabled() {
092: return true;
093: }
094:
095: public boolean isRedoActionEnabled() {
096: // TODO: use UndoableEditEvent to make this really work
097: return true;
098: }
099:
100: public boolean isSelectAllActionEnabled() {
101: return true;
102: }
103:
104: public boolean isUndoActionEnabled() {
105: // TODO: use UndoableEditEvent to make this really work
106: return true;
107: }
108:
109: public void delete() {
110: replaceSelection("");
111: }
112:
113: public void redo() {
114: ((UndoDocument) getDocument()).redo();
115: }
116:
117: public void undo() {
118: ((UndoDocument) getDocument()).undo();
119: }
120: }
|