< prev index next >

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

Print this page




  24  */
  25 
  26 package javax.swing.text;
  27 
  28 import java.io.*;
  29 import java.text.*;
  30 import java.util.*;
  31 import javax.swing.*;
  32 
  33 /**
  34  * <code>MaskFormatter</code> is used to format and edit strings. The behavior
  35  * of a <code>MaskFormatter</code> is controlled by way of a String mask
  36  * that specifies the valid characters that can be contained at a particular
  37  * location in the <code>Document</code> model. The following characters can
  38  * be specified:
  39  *
  40  * <table class="striped">
  41  * <caption>Valid characters and their descriptions</caption>
  42  * <thead>
  43  * <tr>
  44  *    <th>Character&nbsp;</th>
  45  *    <th>Description</th>
  46  * </tr>
  47  * </thead>
  48  * <tbody>
  49  * <tr>
  50  *    <td>#</td>
  51  *    <td>Any valid number, uses <code>Character.isDigit</code>.</td>
  52  * </tr>
  53  * <tr>
  54  *    <td>'</td>
  55  *    <td>Escape character, used to escape any of the
  56  *       special formatting characters.</td>
  57  * </tr>
  58  * <tr>
  59  *    <td>U</td><td>Any character (<code>Character.isLetter</code>). All
  60  *        lowercase letters are mapped to upper case.</td>
  61  * </tr>
  62  * <tr><td>L</td><td>Any character (<code>Character.isLetter</code>). All
  63  *        upper case letters are mapped to lower case.</td>
  64  * </tr>
  65  * <tr><td>A</td><td>Any character or number (<code>Character.isLetter</code>
  66  *       or <code>Character.isDigit</code>)</td>
  67  * </tr>
  68  * <tr><td>?</td><td>Any character
  69  *        (<code>Character.isLetter</code>).</td>
  70  * </tr>
  71  * <tr><td>*</td><td>Anything.</td></tr>
  72  * <tr><td>H</td><td>Any hex character (0-9, a-f or A-F).</td></tr>






  73  * </tbody>
  74  * </table>
  75  *
  76  * <p>
  77  * Typically characters correspond to one char, but in certain languages this
  78  * is not the case. The mask is on a per character basis, and will thus
  79  * adjust to fit as many chars as are needed.
  80  * <p>
  81  * You can further restrict the characters that can be input by the
  82  * <code>setInvalidCharacters</code> and <code>setValidCharacters</code>
  83  * methods. <code>setInvalidCharacters</code> allows you to specify
  84  * which characters are not legal. <code>setValidCharacters</code> allows
  85  * you to specify which characters are valid. For example, the following
  86  * code block is equivalent to a mask of '0xHHH' with no invalid/valid
  87  * characters:
  88  * <pre>
  89  * MaskFormatter formatter = new MaskFormatter("0x***");
  90  * formatter.setValidCharacters("0123456789abcdefABCDEF");
  91  * </pre>
  92  * <p>




  24  */
  25 
  26 package javax.swing.text;
  27 
  28 import java.io.*;
  29 import java.text.*;
  30 import java.util.*;
  31 import javax.swing.*;
  32 
  33 /**
  34  * <code>MaskFormatter</code> is used to format and edit strings. The behavior
  35  * of a <code>MaskFormatter</code> is controlled by way of a String mask
  36  * that specifies the valid characters that can be contained at a particular
  37  * location in the <code>Document</code> model. The following characters can
  38  * be specified:
  39  *
  40  * <table class="striped">
  41  * <caption>Valid characters and their descriptions</caption>
  42  * <thead>
  43  *   <tr>
  44  *     <th scope="col">Character
  45  *     <th scope="col">Description

  46  * </thead>
  47  * <tbody>
  48  *   <tr>
  49  *     <th scope="row">#
  50  *     <td>Any valid number, uses {@code Character.isDigit}.

  51  *   <tr>
  52  *     <th scope="row">'
  53  *     <td>Escape character, used to escape any of the special formatting
  54  *     characters.

  55  *   <tr>
  56  *     <th scope="row">U
  57  *     <td>Any character ({@code Character.isLetter}). All lowercase letters are
  58  *     mapped to upper case.
  59  *   <tr>
  60  *     <th scope="row">L
  61  *     <td>Any character ({@code Character.isLetter}). All upper case letters
  62  *     are mapped to lower case.
  63  *   <tr>
  64  *     <th scope="row">A
  65  *     <td>Any character or number ({@code Character.isLetter} or
  66  *     {@code Character.isDigit}).
  67  *   <tr>
  68  *     <th scope="row">?
  69  *     <td>Any character ({@code Character.isLetter}).
  70  *   <tr>
  71  *     <th scope="row">*
  72  *     <td>Anything.
  73  *   <tr>
  74  *     <th scope="row">H
  75  *     <td>Any hex character (0-9, a-f or A-F).
  76  * </tbody>
  77  * </table>
  78  *
  79  * <p>
  80  * Typically characters correspond to one char, but in certain languages this
  81  * is not the case. The mask is on a per character basis, and will thus
  82  * adjust to fit as many chars as are needed.
  83  * <p>
  84  * You can further restrict the characters that can be input by the
  85  * <code>setInvalidCharacters</code> and <code>setValidCharacters</code>
  86  * methods. <code>setInvalidCharacters</code> allows you to specify
  87  * which characters are not legal. <code>setValidCharacters</code> allows
  88  * you to specify which characters are valid. For example, the following
  89  * code block is equivalent to a mask of '0xHHH' with no invalid/valid
  90  * characters:
  91  * <pre>
  92  * MaskFormatter formatter = new MaskFormatter("0x***");
  93  * formatter.setValidCharacters("0123456789abcdefABCDEF");
  94  * </pre>
  95  * <p>


< prev index next >