3261N/A * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * <code>DefaultFormatter</code> formats aribtrary objects. Formatting is done 0N/A * by invoking the <code>toString</code> method. In order to convert the 0N/A * value back to a String, your class must provide a constructor that 0N/A * takes a String argument. If no single argument constructor that takes a 0N/A * String is found, the returned value will be the String passed into 0N/A * <code>stringToValue</code>. 0N/A * Instances of <code>DefaultFormatter</code> can not be used in multiple 0N/A * instances of <code>JFormattedTextField</code>. To obtain a copy of 0N/A * an already configured <code>DefaultFormatter</code>, use the 0N/A * <code>clone</code> method. 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * @see javax.swing.JFormattedTextField.AbstractFormatter 0N/A /** Indicates if the value being edited must match the mask. */ 0N/A /** If true, editing mode is in overwrite (or strikethough). */ 0N/A /** If true, any time a valid edit happens commitEdit is invoked. */ 0N/A /** Class used to create new instances. */ 0N/A /** NavigationFilter that forwards calls back to DefaultFormatter. */ 0N/A /** DocumentFilter that forwards calls back to DefaultFormatter. */ 0N/A /** Used during replace to track the region to replace. */ 0N/A * Creates a DefaultFormatter. 0N/A * Installs the <code>DefaultFormatter</code> onto a particular 0N/A * <code>JFormattedTextField</code>. 0N/A * This will invoke <code>valueToString</code> to convert the 0N/A * current value from the <code>JFormattedTextField</code> to 0N/A * a String. This will then install the <code>Action</code>s from 0N/A * <code>getActions</code>, the <code>DocumentFilter</code> 0N/A * returned from <code>getDocumentFilter</code> and the 0N/A * <code>NavigationFilter</code> returned from 0N/A * <code>getNavigationFilter</code> onto the 0N/A * <code>JFormattedTextField</code>. 0N/A * Subclasses will typically only need to override this if they 0N/A * wish to install additional listeners on the 0N/A * <code>JFormattedTextField</code>. 0N/A * If there is a <code>ParseException</code> in converting the 0N/A * current value to a String, this will set the text to an empty 0N/A * String, and mark the <code>JFormattedTextField</code> as being 0N/A * in an invalid state. 0N/A * While this is a public method, this is typically only useful 0N/A * for subclassers of <code>JFormattedTextField</code>. 0N/A * <code>JFormattedTextField</code> will invoke this method at 0N/A * the appropriate times when the value changes, or its internal 0N/A * @param ftf JFormattedTextField to format for, may be null indicating 0N/A * uninstall from current JFormattedTextField. 0N/A * Sets when edits are published back to the 0N/A * <code>JFormattedTextField</code>. If true, <code>commitEdit</code> 0N/A * is invoked after every valid edit (any time the text is edited). On 0N/A * the other hand, if this is false than the <code>DefaultFormatter</code> 0N/A * does not publish edits back to the <code>JFormattedTextField</code>. 0N/A * As such, the only time the value of the <code>JFormattedTextField</code> 0N/A * will change is when <code>commitEdit</code> is invoked on 0N/A * <code>JFormattedTextField</code>, typically when enter is pressed 0N/A * or focus leaves the <code>JFormattedTextField</code>. 0N/A * @param commit Used to indicate when edits are commited back to the 0N/A * Returns when edits are published back to the 0N/A * <code>JFormattedTextField</code>. 0N/A * @return true if edits are commited after evey valid edit 0N/A * Configures the behavior when inserting characters. If 0N/A * <code>overwriteMode</code> is true (the default), new characters 0N/A * overwrite existing characters in the model. 0N/A * @param overwriteMode Indicates if overwrite or overstrike mode is used 0N/A * Returns the behavior when inserting characters. 0N/A * @return true if newly inserted characters overwrite existing characters 0N/A * Sets whether or not the value being edited is allowed to be invalid 0N/A * for a length of time (that is, <code>stringToValue</code> throws 0N/A * a <code>ParseException</code>). 0N/A * It is often convenient to allow the user to temporarily input an 0N/A * @param allowsInvalid Used to indicate if the edited value must always 0N/A * Returns whether or not the value being edited is allowed to be invalid 0N/A * for a length of time. 0N/A * @return false if the edited value must always be valid 0N/A * Sets that class that is used to create new Objects. If the 0N/A * passed in class does not have a single argument constructor that 0N/A * takes a String, String values will be used. 0N/A * @param valueClass Class used to construct return value from 0N/A * Returns that class that is used to create new Objects. 0N/A * @return Class used to constuct return value from stringToValue 0N/A * Converts the passed in String into an instance of 0N/A * <code>getValueClass</code> by way of the constructor that 0N/A * takes a String argument. If <code>getValueClass</code> 0N/A * returns null, the Class of the current value in the 0N/A * <code>JFormattedTextField</code> will be used. If this is null, a 0N/A * String will be returned. If the constructor thows an exception, a 0N/A * <code>ParseException</code> will be thrown. If there is no single 0N/A * argument String constructor, <code>string</code> will be returned. 0N/A * @throws ParseException if there is an error in the conversion 0N/A * @param string String to convert 0N/A * @return Object representation of text 0N/A * Converts the passed in Object into a String by way of the 0N/A * <code>toString</code> method. 0N/A * @throws ParseException if there is an error in the conversion 0N/A * @param value Value to convert 0N/A * @return String representation of value 0N/A * Returns the <code>DocumentFilter</code> used to restrict the characters 0N/A * that can be input into the <code>JFormattedTextField</code>. 0N/A * @return DocumentFilter to restrict edits 0N/A * Returns the <code>NavigationFilter</code> used to restrict where the 0N/A * cursor can be placed. 0N/A * @return NavigationFilter to restrict navigation 0N/A * Creates a copy of the DefaultFormatter. 0N/A * @return copy of the DefaultFormatter 0N/A * Positions the cursor at the initial location. 0N/A * Returns the initial location to position the cursor at. This forwards 0N/A * the call to <code>getNextNavigatableChar</code>. 0N/A * Subclasses should override this if they want cursor navigation 0N/A * to skip certain characters. A return value of false indicates 0N/A * the character at <code>offset</code> should be skipped when 0N/A * navigating throught the field. 0N/A * Returns true if the text in <code>text</code> can be inserted. This 0N/A * does not mean the text will ultimately be inserted, it is used if 0N/A * text can trivially reject certain characters. 0N/A * Returns the next editable character starting at offset incrementing 0N/A * the offset by <code>direction</code>. 0N/A * A convenience methods to return the result of deleting 0N/A * <code>deleteLength</code> characters at <code>offset</code> 0N/A * and inserting <code>replaceString</code> at <code>offset</code> 0N/A * in the current text field. 0N/A * Returns true if the operation described by <code>rh</code> will 0N/A * result in a legal edit. This may set the <code>value</code> 0N/A * field of <code>rh</code>. 0N/A * Invokes <code>commitEdit</code> on the JFormattedTextField. 0N/A * Pushes the value to the JFormattedTextField if the current value 0N/A * is valid and invokes <code>setEditValid</code> based on the 0N/A * validity of the value. 0N/A * Pushes the <code>value</code> to the editor if we are to 0N/A * commit on edits. If <code>value</code> is null, the current value 0N/A * will be obtained from the text component. 0N/A * Returns the next cursor position from offset by incrementing 0N/A * <code>direction</code>. This uses 0N/A * <code>getNextNavigatableChar</code> 0N/A * as well as constraining the location to the max position. 0N/A // Case where hit backspace and only characters before 0N/A // offset are fixed. 0N/A // Don't go beyond last editable character. 0N/A * Resets the cursor by using getNextCursorPosition. 0N/A * Finds the next navigatable character. 0N/A // Pending: should not assume forward! 0N/A * Returns true if the edit described by <code>rh</code> will result 0N/A * DocumentFilter method, funnels into <code>replace</code>. 0N/A * If the edit described by <code>rh</code> is legal, this will 0N/A * return true, commit the edit (if necessary) and update the cursor 0N/A * position. This forwards to <code>canReplace</code> and 0N/A * <code>isLegalInsertText</code> as necessary to determine if 0N/A * the edit is in fact legal. 0N/A * All of the DocumentFilter methods funnel into here, you should 0N/A * generally only have to override this. 0N/A * NavigationFilter method, subclasses that wish finer control should 0N/A * NavigationFilter method, subclasses that wish finer control should 0N/A * Returns the ReplaceHolder to track the replace of the specified 0N/A /** The FilterBypass that was passed to the DocumentFilter method. */ 0N/A /** Length of text to remove. */ 0N/A /** The text to insert, may be null. */ 0N/A /** AttributeSet to attach to text, may be null. */ 0N/A /** The resulting value, this may never be set. */ 0N/A /** Position the cursor should be adjusted from. If this is -1 0N/A * the cursor position will be adjusted based on the direction of 0N/A * the replace (-1: offset, 1: offset + text.length()), otherwise 0N/A * the cursor position is adusted from this position. 0N/A * NavigationFilter implementation that calls back to methods with 0N/A * same name in DefaultFormatter. 0N/A // bypass the filter 0N/A // bypass the filter 0N/A // forward the call to the UI directly 0N/A * DocumentFilter implementation that calls back to the replace 0N/A * method of DefaultFormatter. 0N/A // bypass the filter 0N/A // bypass the filter 0N/A // bypass the filter