< prev index next >

src/java.desktop/share/classes/javax/swing/text/DateFormatter.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing.text;
  26 
  27 import java.awt.event.*;
  28 import java.text.*;
  29 import java.util.*;
  30 import javax.swing.*;
  31 import javax.swing.text.*;
  32 
  33 /**
  34  * DateFormatter is an <code>InternationalFormatter</code> that does its
  35  * formatting by way of an instance of <code>java.text.DateFormat</code>.
  36  * <p>
  37  * <strong>Warning:</strong>
  38  * Serialized objects of this class will not be compatible with
  39  * future Swing releases. The current serialization support is
  40  * appropriate for short term storage or RMI between applications running
  41  * the same version of Swing.  As of 1.4, support for long term storage
  42  * of all JavaBeans&trade;
  43  * has been added to the <code>java.beans</code> package.
  44  * Please see {@link java.beans.XMLEncoder}.
  45  *
  46  * @see java.text.DateFormat
  47  *
  48  * @since 1.4
  49  */
  50 @SuppressWarnings("serial") // Same-version serialization only
  51 public class DateFormatter extends InternationalFormatter {
  52     /**
  53      * This is shorthand for
  54      * <code>new DateFormatter(DateFormat.getDateInstance())</code>.
  55      */
  56     public DateFormatter() {
  57         this(DateFormat.getDateInstance());
  58     }
  59 
  60     /**
  61      * Returns a DateFormatter configured with the specified
  62      * <code>Format</code> instance.
  63      *
  64      * @param format Format used to dictate legal values
  65      */
  66     public DateFormatter(DateFormat format) {
  67         super(format);
  68         setFormat(format);
  69     }
  70 
  71     /**
  72      * Sets the format that dictates the legal values that can be edited
  73      * and displayed.
  74      * <p>
  75      * If you have used the nullary constructor the value of this property
  76      * will be determined for the current locale by way of the
  77      * <code>Dateformat.getDateInstance()</code> method.
  78      *
  79      * @param format DateFormat instance used for converting from/to Strings
  80      */
  81     public void setFormat(DateFormat format) {
  82         super.setFormat(format);
  83     }
  84 
  85     /**
  86      * Returns the Calendar that <code>DateFormat</code> is associated with,
  87      * or if the <code>Format</code> is not a <code>DateFormat</code>
  88      * <code>Calendar.getInstance</code> is returned.
  89      */
  90     private Calendar getCalendar() {
  91         Format f = getFormat();
  92 
  93         if (f instanceof DateFormat) {
  94             return ((DateFormat)f).getCalendar();
  95         }
  96         return Calendar.getInstance();
  97     }
  98 
  99 
 100     /**
 101      * Returns true, as DateFormatterFilter will support
 102      * incrementing/decrementing of the value.
 103      */
 104     boolean getSupportsIncrement() {
 105         return true;
 106     }
 107 
 108     /**




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing.text;
  26 
  27 import java.awt.event.*;
  28 import java.text.*;
  29 import java.util.*;
  30 import javax.swing.*;
  31 import javax.swing.text.*;
  32 
  33 /**
  34  * DateFormatter is an {@code InternationalFormatter} that does its
  35  * formatting by way of an instance of {@code java.text.DateFormat}.
  36  * <p>
  37  * <strong>Warning:</strong>
  38  * Serialized objects of this class will not be compatible with
  39  * future Swing releases. The current serialization support is
  40  * appropriate for short term storage or RMI between applications running
  41  * the same version of Swing.  As of 1.4, support for long term storage
  42  * of all JavaBeans&trade;
  43  * has been added to the {@code java.beans} package.
  44  * Please see {@link java.beans.XMLEncoder}.
  45  *
  46  * @see java.text.DateFormat
  47  *
  48  * @since 1.4
  49  */
  50 @SuppressWarnings("serial") // Same-version serialization only
  51 public class DateFormatter extends InternationalFormatter {
  52     /**
  53      * This is shorthand for
  54      * {@code new DateFormatter(DateFormat.getDateInstance())}.
  55      */
  56     public DateFormatter() {
  57         this(DateFormat.getDateInstance());
  58     }
  59 
  60     /**
  61      * Returns a DateFormatter configured with the specified
  62      * {@code Format} instance.
  63      *
  64      * @param format Format used to dictate legal values
  65      */
  66     public DateFormatter(DateFormat format) {
  67         super(format);
  68         setFormat(format);
  69     }
  70 
  71     /**
  72      * Sets the format that dictates the legal values that can be edited
  73      * and displayed.
  74      * <p>
  75      * If you have used the nullary constructor the value of this property
  76      * will be determined for the current locale by way of the
  77      * {@code Dateformat.getDateInstance()} method.
  78      *
  79      * @param format DateFormat instance used for converting from/to Strings
  80      */
  81     public void setFormat(DateFormat format) {
  82         super.setFormat(format);
  83     }
  84 
  85     /**
  86      * Returns the Calendar that {@code DateFormat} is associated with,
  87      * or if the {@code Format} is not a {@code DateFormat}
  88      * {@code Calendar.getInstance} is returned.
  89      */
  90     private Calendar getCalendar() {
  91         Format f = getFormat();
  92 
  93         if (f instanceof DateFormat) {
  94             return ((DateFormat)f).getCalendar();
  95         }
  96         return Calendar.getInstance();
  97     }
  98 
  99 
 100     /**
 101      * Returns true, as DateFormatterFilter will support
 102      * incrementing/decrementing of the value.
 103      */
 104     boolean getSupportsIncrement() {
 105         return true;
 106     }
 107 
 108     /**


< prev index next >