Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / javax / swing / JFormattedTextField.java
blobf544aec117f35bfb7dd2b3d89d6e0daf7886c8a4
1 /* JFormattedTextField.java --
2 Copyright (C) 2003, 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing;
41 import java.awt.event.FocusEvent;
42 import java.io.Serializable;
43 import java.text.Format;
44 import java.text.ParseException;
46 import javax.swing.text.Document;
47 import javax.swing.text.DocumentFilter;
48 import javax.swing.text.NavigationFilter;
50 /**
51 * @author Michael Koch
52 * @since 1.4
54 public class JFormattedTextField extends JTextField
56 private static final long serialVersionUID = 5464657870110180632L;
58 public abstract static class AbstractFormatter implements Serializable
60 private static final long serialVersionUID = -5193212041738979680L;
62 private JFormattedTextField textField;
64 public AbstractFormatter ()
66 //Do nothing here.
69 protected Object clone ()
70 throws CloneNotSupportedException
72 throw new InternalError ("not implemented");
75 protected Action[] getActions ()
77 return textField.getActions();
80 protected DocumentFilter getDocumentFilter ()
82 throw new InternalError ("not implemented");
85 protected JFormattedTextField getFormattedTextField ()
87 return textField;
90 protected NavigationFilter getNavigationFilter ()
92 return textField.getNavigationFilter();
95 public void install(JFormattedTextField textField)
97 if (this.textField != null)
98 uninstall();
100 this.textField = textField;
103 public void uninstall ()
105 this.textField = null;
108 protected void invalidEdit ()
110 textField.invalidEdit();
113 protected void setEditValid (boolean valid)
115 textField.editValid = valid;
118 public abstract Object stringToValue (String text)
119 throws ParseException;
121 public abstract String valueToString (Object value)
122 throws ParseException;
125 public abstract static class AbstractFormatterFactory
127 public AbstractFormatterFactory ()
129 // Do nothing here.
132 public abstract AbstractFormatter getFormatter (JFormattedTextField tf);
135 static class FormatterFactoryWrapper extends AbstractFormatterFactory
137 AbstractFormatter formatter;
139 public FormatterFactoryWrapper(AbstractFormatter formatter)
141 this.formatter = formatter;
144 public AbstractFormatter getFormatter(JFormattedTextField tf)
146 return formatter;
150 public static final int COMMIT = 0;
151 public static final int COMMIT_OR_REVERT = 1;
152 public static final int REVERT = 2;
153 public static final int PERSIST = 3;
155 private Object value;
156 private int focusLostBehavior = COMMIT_OR_REVERT;
157 private AbstractFormatterFactory formatterFactory;
158 private boolean editValid = true;
160 public JFormattedTextField ()
162 this((AbstractFormatterFactory) null, null);
165 public JFormattedTextField (Format format)
167 throw new InternalError ("not implemented");
170 public JFormattedTextField (AbstractFormatter formatter)
172 this(new FormatterFactoryWrapper(formatter), null);
175 public JFormattedTextField (AbstractFormatterFactory factory)
177 this(factory, null);
180 public JFormattedTextField (AbstractFormatterFactory factory, Object value)
182 this.formatterFactory = factory;
183 this.value = value;
186 public JFormattedTextField (Object value)
188 this.value = value;
191 public void commitEdit ()
192 throws ParseException
194 throw new InternalError ("not implemented");
197 public Action[] getActions ()
199 throw new InternalError ("not implemented");
202 public int getFocusLostBehavior()
204 return focusLostBehavior;
207 public AbstractFormatter getFormatter ()
209 if (formatterFactory == null)
210 return null;
212 return formatterFactory.getFormatter(this);
215 public AbstractFormatterFactory getFormatterFactory ()
217 return formatterFactory;
220 public String getUIClassID ()
222 return "FormattedTextFieldUI";
225 public Object getValue ()
227 return value;
230 protected void invalidEdit ()
232 UIManager.getLookAndFeel().provideErrorFeedback(this);
235 public boolean isEditValid ()
237 return editValid;
240 protected void processFocusEvent (FocusEvent evt)
242 throw new InternalError ("not implemented");
245 public void setDocument(Document newDocument)
247 Document oldDocument = getDocument();
249 if (oldDocument == newDocument)
250 return;
252 super.setDocument(newDocument);
255 public void setFocusLostBehavior(int behavior)
257 if (behavior != COMMIT
258 && behavior != COMMIT_OR_REVERT
259 && behavior != PERSIST
260 && behavior != REVERT)
261 throw new IllegalArgumentException("invalid behavior");
263 this.focusLostBehavior = behavior;
266 protected void setFormatter (AbstractFormatter formatter)
268 AbstractFormatter oldFormatter = null;
270 if (formatterFactory != null)
271 oldFormatter = formatterFactory.getFormatter(this);
273 if (oldFormatter == formatter)
274 return;
276 setFormatterFactory(new FormatterFactoryWrapper(formatter));
277 firePropertyChange("formatter", oldFormatter, formatter);
280 public void setFormatterFactory (AbstractFormatterFactory factory)
282 if (formatterFactory == factory)
283 return;
285 AbstractFormatterFactory oldFactory = formatterFactory;
286 formatterFactory = factory;
287 firePropertyChange("formatterFactory", oldFactory, factory);
290 public void setValue (Object newValue)
292 if (value == newValue)
293 return;
295 Object oldValue = value;
296 value = newValue;
297 firePropertyChange("value", oldValue, newValue);