843
844 return new DefaultFormatterFactory(displayFormatter,
845 displayFormatter,editFormatter);
846 }
847 return new DefaultFormatterFactory(new DefaultFormatter());
848 }
849
850
851 /**
852 * Instances of <code>AbstractFormatterFactory</code> are used by
853 * <code>JFormattedTextField</code> to obtain instances of
854 * <code>AbstractFormatter</code> which in turn are used to format values.
855 * <code>AbstractFormatterFactory</code> can return different
856 * <code>AbstractFormatter</code>s based on the state of the
857 * <code>JFormattedTextField</code>, perhaps returning different
858 * <code>AbstractFormatter</code>s when the
859 * <code>JFormattedTextField</code> has focus vs when it
860 * doesn't have focus.
861 * @since 1.4
862 */
863 public static abstract class AbstractFormatterFactory {
864 /**
865 * Returns an <code>AbstractFormatter</code> that can handle formatting
866 * of the passed in <code>JFormattedTextField</code>.
867 *
868 * @param tf JFormattedTextField requesting AbstractFormatter
869 * @return AbstractFormatter to handle formatting duties, a null
870 * return value implies the JFormattedTextField should behave
871 * like a normal JTextField
872 */
873 public abstract AbstractFormatter getFormatter(JFormattedTextField tf);
874 }
875
876
877 /**
878 * Instances of <code>AbstractFormatter</code> are used by
879 * <code>JFormattedTextField</code> to handle the conversion both
880 * from an Object to a String, and back from a String to an Object.
881 * <code>AbstractFormatter</code>s can also enforce editing policies,
882 * or navigation policies, or manipulate the
883 * <code>JFormattedTextField</code> in any way it sees fit to
886 * An <code>AbstractFormatter</code> can only be active in
887 * one <code>JFormattedTextField</code> at a time.
888 * <code>JFormattedTextField</code> invokes
889 * <code>install</code> when it is ready to use it followed
890 * by <code>uninstall</code> when done. Subclasses
891 * that wish to install additional state should override
892 * <code>install</code> and message super appropriately.
893 * <p>
894 * Subclasses must override the conversion methods
895 * <code>stringToValue</code> and <code>valueToString</code>. Optionally
896 * they can override <code>getActions</code>,
897 * <code>getNavigationFilter</code> and <code>getDocumentFilter</code>
898 * to restrict the <code>JFormattedTextField</code> in a particular
899 * way.
900 * <p>
901 * Subclasses that allow the <code>JFormattedTextField</code> to be in
902 * a temporarily invalid state should invoke <code>setEditValid</code>
903 * at the appropriate times.
904 * @since 1.4
905 */
906 public static abstract class AbstractFormatter implements Serializable {
907 private JFormattedTextField ftf;
908
909 /**
910 * Installs the <code>AbstractFormatter</code> onto a particular
911 * <code>JFormattedTextField</code>.
912 * This will invoke <code>valueToString</code> to convert the
913 * current value from the <code>JFormattedTextField</code> to
914 * a String. This will then install the <code>Action</code>s from
915 * <code>getActions</code>, the <code>DocumentFilter</code>
916 * returned from <code>getDocumentFilter</code> and the
917 * <code>NavigationFilter</code> returned from
918 * <code>getNavigationFilter</code> onto the
919 * <code>JFormattedTextField</code>.
920 * <p>
921 * Subclasses will typically only need to override this if they
922 * wish to install additional listeners on the
923 * <code>JFormattedTextField</code>.
924 * <p>
925 * If there is a <code>ParseException</code> in converting the
926 * current value to a String, this will set the text to an empty
|
843
844 return new DefaultFormatterFactory(displayFormatter,
845 displayFormatter,editFormatter);
846 }
847 return new DefaultFormatterFactory(new DefaultFormatter());
848 }
849
850
851 /**
852 * Instances of <code>AbstractFormatterFactory</code> are used by
853 * <code>JFormattedTextField</code> to obtain instances of
854 * <code>AbstractFormatter</code> which in turn are used to format values.
855 * <code>AbstractFormatterFactory</code> can return different
856 * <code>AbstractFormatter</code>s based on the state of the
857 * <code>JFormattedTextField</code>, perhaps returning different
858 * <code>AbstractFormatter</code>s when the
859 * <code>JFormattedTextField</code> has focus vs when it
860 * doesn't have focus.
861 * @since 1.4
862 */
863 public abstract static class AbstractFormatterFactory {
864 /**
865 * Returns an <code>AbstractFormatter</code> that can handle formatting
866 * of the passed in <code>JFormattedTextField</code>.
867 *
868 * @param tf JFormattedTextField requesting AbstractFormatter
869 * @return AbstractFormatter to handle formatting duties, a null
870 * return value implies the JFormattedTextField should behave
871 * like a normal JTextField
872 */
873 public abstract AbstractFormatter getFormatter(JFormattedTextField tf);
874 }
875
876
877 /**
878 * Instances of <code>AbstractFormatter</code> are used by
879 * <code>JFormattedTextField</code> to handle the conversion both
880 * from an Object to a String, and back from a String to an Object.
881 * <code>AbstractFormatter</code>s can also enforce editing policies,
882 * or navigation policies, or manipulate the
883 * <code>JFormattedTextField</code> in any way it sees fit to
886 * An <code>AbstractFormatter</code> can only be active in
887 * one <code>JFormattedTextField</code> at a time.
888 * <code>JFormattedTextField</code> invokes
889 * <code>install</code> when it is ready to use it followed
890 * by <code>uninstall</code> when done. Subclasses
891 * that wish to install additional state should override
892 * <code>install</code> and message super appropriately.
893 * <p>
894 * Subclasses must override the conversion methods
895 * <code>stringToValue</code> and <code>valueToString</code>. Optionally
896 * they can override <code>getActions</code>,
897 * <code>getNavigationFilter</code> and <code>getDocumentFilter</code>
898 * to restrict the <code>JFormattedTextField</code> in a particular
899 * way.
900 * <p>
901 * Subclasses that allow the <code>JFormattedTextField</code> to be in
902 * a temporarily invalid state should invoke <code>setEditValid</code>
903 * at the appropriate times.
904 * @since 1.4
905 */
906 public abstract static class AbstractFormatter implements Serializable {
907 private JFormattedTextField ftf;
908
909 /**
910 * Installs the <code>AbstractFormatter</code> onto a particular
911 * <code>JFormattedTextField</code>.
912 * This will invoke <code>valueToString</code> to convert the
913 * current value from the <code>JFormattedTextField</code> to
914 * a String. This will then install the <code>Action</code>s from
915 * <code>getActions</code>, the <code>DocumentFilter</code>
916 * returned from <code>getDocumentFilter</code> and the
917 * <code>NavigationFilter</code> returned from
918 * <code>getNavigationFilter</code> onto the
919 * <code>JFormattedTextField</code>.
920 * <p>
921 * Subclasses will typically only need to override this if they
922 * wish to install additional listeners on the
923 * <code>JFormattedTextField</code>.
924 * <p>
925 * If there is a <code>ParseException</code> in converting the
926 * current value to a String, this will set the text to an empty
|