001 /*
002 * Copyright (c) Holger Pfaff - http://pfaff.ws
003 *
004 * This software maybe used for any purpose provided the
005 * above copyright notice is retained. It is supplied as is.
006 * No warranty expressed or implied - Use at your own risk.
007 */
008
009 import java.awt.Dimension;
010 import java.awt.TextComponent;
011 import java.awt.event.TextListener;
012
013 /**
014 * (#)AwtText.java
015 * @author Holger Pfaff
016 * @version 3.2 19-Mar-2004<br><br>
017 *
018 * Base class for EditField and EditText. All wrappers around the
019 * standard AWT Text[Field|Area] to overcome resizing-, font- and
020 * coloring problems.
021 *
022 */
023
024 public class AwtText extends Awt {
025
026 /**
027 * the TextComp we want to wrap ...
028 */
029 protected TextComponent textcomp;
030
031 /**
032 * Default constructor
033 */
034 public AwtText() {
035 setLayout(null);
036 setInsets(insets);
037 }
038
039 /**
040 * implement Awt.measure()
041 */
042 public Dimension measure() {
043 return textcomp.getMinimumSize();
044 }
045
046 /**
047 * overwrite invalidate to set Font
048 */
049 public void invalidate() {
050 setFont(textcomp);
051 super.invalidate();
052 }
053
054 /**
055 * overwrite validate to set Size
056 */
057 public void validate() {
058 textcomp.setSize(getSize());
059 }
060
061 /**
062 * overwrite setBounds to set Size of wrapped comp
063 */
064 public void setBounds(int x, int y, int w, int h) {
065 textcomp.setBounds(0, 0, w, h);
066 super.setBounds(x, y, w, h);
067 }
068
069 /**
070 * implement TextComponent.addTextListener()
071 */
072 public void addTextListener(TextListener l) {
073 textcomp.addTextListener(l);
074 }
075
076 /**
077 * implement TextComponent.removeTextListener()
078 */
079 public void removeTextListener(TextListener l) {
080 textcomp.removeTextListener(l);
081 }
082
083 /**
084 * implement TextComponent.getCaretPosition()
085 */
086 public int getCaretPosition() {
087 return textcomp.getCaretPosition();
088 }
089
090 /**
091 * implement TextComponent.setCaretPosition()
092 */
093 public void setCaretPosition(int position) {
094 textcomp.setCaretPosition(position);
095 }
096
097 /**
098 * implement TextComponent.isEditable()
099 */
100 public boolean isEditable() {
101 return textcomp.isEditable();
102 }
103
104 /**
105 * implement TextComponent.setEditable()
106 */
107 public void setEditable(boolean b) {
108 textcomp.setEditable(b);
109 }
110
111 /**
112 * implement TextComponent.setText()
113 */
114 public void setText(String t) {
115 textcomp.setText(t);
116 }
117
118 /**
119 * implement TextComponent.getText()
120 */
121 public String getText() {
122 return textcomp.getText();
123 }
124
125 /**
126 * implement TextComponent.getSelectedText()
127 */
128 public String getSelectedText() {
129 return textcomp.getSelectedText();
130 }
131
132 /**
133 * implement TextComponent.getSelectionStart()
134 */
135 public int getSelectionStart() {
136 return textcomp.getSelectionStart();
137 }
138
139 /**
140 * implement TextComponent.setSelectionStart()
141 */
142 public void setSelectionStart(int selectionStart){
143 textcomp.setSelectionStart(selectionStart);
144 }
145
146 /**
147 * implement TextComponent.getSelectionEnd()
148 */
149 public int getSelectionEnd() {
150 return textcomp.getSelectionEnd();
151 }
152
153 /**
154 * implement TextComponent.setSelectionEnd()
155 */
156 public void setSelectionEnd(int selectionEnd) {
157 textcomp.setSelectionEnd(selectionEnd);
158 }
159
160 /**
161 * implement TextComponent.select()
162 */
163 public void select(int selectionStart, int selectionEnd) {
164 textcomp.select(selectionStart, selectionEnd);
165 }
166
167 /**
168 * implement TextComponent.selectAll()
169 */
170 public void selectAll() {
171 textcomp.selectAll();
172 }
173 }