API java : InternationalFormatter


javax.swing.text
Class InternationalFormatter

java.lang.Object
  extended by javax.swing.JFormattedTextField.AbstractFormatter
      extended by javax.swing.text.DefaultFormatter
          extended by javax.swing.text.InternationalFormatter
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
DateFormatter, NumberFormatter

public class InternationalFormatter
extends DefaultFormatter

InternationalFormatter extends DefaultFormatter, using an instance of java.text.Format to handle the conversion to a String, and the conversion from a String.

If getAllowsInvalid() is false, this will ask the Format to format the current text on every edit.

You can specify a minimum and maximum value by way of the setMinimum and setMaximum methods. In order for this to work the values returned from stringToValue must be comparable to the min/max values by way of the Comparable interface.

Be careful how you configure the Format and the InternationalFormatter, as it is possible to create a situation where certain values can not be input. Consider the date format 'M/d/yy', an InternationalFormatter that is always valid (setAllowsInvalid(false)), is in overwrite mode (setOverwriteMode(true)) and the date 7/1/99. In this case the user will not be able to enter a two digit month or day of month. To avoid this, the format should be 'MM/dd/yy'.

If InternationalFormatter is configured to only allow valid values (setAllowsInvalid(false)), every valid edit will result in the text of the JFormattedTextField being completely reset from the Format. The cursor position will also be adjusted as literal characters are added/removed from the resulting String.

InternationalFormatter's behavior of stringToValue is slightly different than that of DefaultTextFormatter, it does the following:

  1. parseObject is invoked on the Format specified by setFormat
  2. If a Class has been set for the values (setValueClass), supers implementation is invoked to convert the value returned from parseObject to the appropriate class.
  3. If a ParseException has not been thrown, and the value is outside the min/max a ParseException is thrown.
  4. The value is returned.
InternationalFormatter implements stringToValue in this manner so that you can specify an alternate Class than Format may return.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.

Since:
1.4
See Also:
Format, Comparable

Constructor Summary
InternationalFormatter()
          Creates an InternationalFormatter with no Format specified.
InternationalFormatter(Format format)
          Creates an InternationalFormatter with the specified Format instance.
 
Method Summary
 Object clone()
          Creates a copy of the DefaultFormatter.
protected  Action[] getActions()
          If getSupportsIncrement returns true, this returns two Actions suitable for incrementing/decrementing the value.
 Format.Field[] getFields(int offset)
          Returns the Format.Field constants associated with the text at offset.
 Format getFormat()
          Returns the format that dictates the legal values that can be edited and displayed.
 Comparable getMaximum()
          Returns the maximum permissible value.
 Comparable getMinimum()
          Returns the minimum permissible value.
 void install(JFormattedTextField ftf)
          Installs the DefaultFormatter onto a particular JFormattedTextField.
 void setFormat(Format format)
          Sets the format that dictates the legal values that can be edited and displayed.
 void setMaximum(Comparable max)
          Sets the maximum permissible value.
 void setMinimum(Comparable minimum)
          Sets the minimum permissible value.
 Object stringToValue(String text)
          Returns the Object representation of the String text.
 String valueToString(Object value)
          Returns a String representation of the Object value.
 
Methods inherited from class javax.swing.text.DefaultFormatter
getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
 
Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter
getFormattedTextField, invalidEdit, setEditValid, uninstall
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InternationalFormatter

public InternationalFormatter()
Creates an InternationalFormatter with no Format specified.


InternationalFormatter

public InternationalFormatter(Format format)
Creates an InternationalFormatter with the specified Format instance.

Parameters:
format - Format instance used for converting from/to Strings
Method Detail

setFormat

public void setFormat(Format format)
Sets the format that dictates the legal values that can be edited and displayed.

Parameters:
format - Format instance used for converting from/to Strings

getFormat

public Format getFormat()
Returns the format that dictates the legal values that can be edited and displayed.

Returns:
Format instance used for converting from/to Strings

setMinimum

public void setMinimum(Comparable minimum)
Sets the minimum permissible value. If the valueClass has not been specified, and minimum is non null, the valueClass will be set to that of the class of minimum.

Parameters:
minimum - Minimum legal value that can be input
See Also:
DefaultFormatter.setValueClass(java.lang.Class)

getMinimum

public Comparable getMinimum()
Returns the minimum permissible value.

Returns:
Minimum legal value that can be input

setMaximum

public void setMaximum(Comparable max)
Sets the maximum permissible value. If the valueClass has not been specified, and max is non null, the valueClass will be set to that of the class of max.

Parameters:
max - Maximum legal value that can be input
See Also:
DefaultFormatter.setValueClass(java.lang.Class)

getMaximum

public Comparable getMaximum()
Returns the maximum permissible value.

Returns:
Maximum legal value that can be input

install

public void install(JFormattedTextField ftf)
Installs the DefaultFormatter onto a particular JFormattedTextField. This will invoke valueToString to convert the current value from the JFormattedTextField to a String. This will then install the Actions from getActions, the DocumentFilter returned from getDocumentFilter and the NavigationFilter returned from getNavigationFilter onto the JFormattedTextField.

Subclasses will typically only need to override this if they wish to install additional listeners on the JFormattedTextField.

If there is a ParseException in converting the current value to a String, this will set the text to an empty String, and mark the JFormattedTextField as being in an invalid state.

While this is a public method, this is typically only useful for subclassers of JFormattedTextField. JFormattedTextField will invoke this method at the appropriate times when the value changes, or its internal state changes.

Overrides:
install in class DefaultFormatter
Parameters:
ftf - JFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.

valueToString

public String valueToString(Object value)
                     throws ParseException
Returns a String representation of the Object value. This invokes format on the current Format.

Overrides:
valueToString in class DefaultFormatter
Parameters:
value - Value to convert
Returns:
String representation of value
Throws:
ParseException - if there is an error in the conversion

stringToValue

public Object stringToValue(String text)
                     throws ParseException
Returns the Object representation of the String text.

Overrides:
stringToValue in class DefaultFormatter
Parameters:
text - String to convert
Returns:
Object representation of text
Throws:
ParseException - if there is an error in the conversion

getFields

public Format.Field[] getFields(int offset)
Returns the Format.Field constants associated with the text at offset. If offset is not a valid location into the current text, this will return an empty array.

Parameters:
offset - offset into text to be examined
Returns:
Format.Field constants associated with the text at the given position.

clone

public Object clone()
             throws CloneNotSupportedException
Creates a copy of the DefaultFormatter.

Overrides:
clone in class DefaultFormatter
Returns:
copy of the DefaultFormatter
Throws:
CloneNotSupportedException - if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
See Also:
Cloneable

getActions

protected Action[] getActions()
If getSupportsIncrement returns true, this returns two Actions suitable for incrementing/decrementing the value.

Overrides:
getActions in class JFormattedTextField.AbstractFormatter
Returns:
Array of Actions to install on JFormattedTextField

Ces informations proviennent du site de http://java.sun.com

Remarques

Contenu

Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :

Quels sont les motivations de cette démarche?

Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.

Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.

Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.

Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.

Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.

Réseaux sociaux

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.

 

Nuage de mots clés

6 mots clés dont 0 définis manuellement (plus d'information...).

Avertissement

Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.

Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.

 

Astuce pour imprimer les couleurs des cellules de tableaux : http://www.gaudry.be/ast-rf-450.html
Aucun commentaire pour cette page

© Ce document issu de l′infobrol est enregistré sous le certificat Cyber PrInterDeposit Digital Numbertection. Enregistrement IDDN n° 5329-3224
Document créé le 01/09/06 03:56, dernière modification le Vendredi 17 Juin 2011, 12:12
Source du document imprimé : http://www.gaudry.be/java-api-rf-javax/swing/text/InternationalFormatter.html Document affiché 1 fois ce mois de Juin.
St.Gaudry©07.01.02
Outils (masquer)
||
Recherche (afficher)
Recherche :

Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
15832 documents
452 astuces.
549 niouzes.
3099 definitions.
447 membres.
8115 messages.

Document genere en :
0,88 seconde

Mises à jour :
Mises à jour du site
Citation (masquer)
Chuck Norris joue à World of Warcraft ET a une vie sociale.

Anonyme [Chuck Norris fact]
 
l'infobrol
Nous sommes le Samedi 02 Juin 2012, 08:44, toutes les heures sont au format GMT+1.00 Heure, heure d'été (+1)