View Javadoc

1   package org.wcb.autohome.util;
2   
3   import javax.swing.text.PlainDocument;
4   import javax.swing.text.AttributeSet;
5   import javax.swing.text.BadLocationException;
6   
7   /***
8    /**
9    * Copyright (C) 1999  Walter Bogaardt
10   *
11   * This library is free software; you can redistribute it and/or
12   * modify it under the terms of the GNU Lesser General Public
13   * License as published by the Free Software Foundation; either
14   * version 2 of the License, or (at your option) any later version.
15   *
16   * This library is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19   * Lesser General Public License for more details.
20   *
21   * You should have received a copy of the GNU Lesser General Public
22   * License along with this library; if not, write to the Free Software
23   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
24   *
25   * Project: Alice X10 Home Automation
26   *
27   * Date: Oct 9, 2003
28   * Time: 4:43:59 PM
29   *
30   * $Log: DeviceIDFieldValidator.java,v $
31   * Revision 1.3  2003/12/30 21:20:17  wbogaardt
32   * added new file saving dialog to actually save files in .x10 extension.
33   *
34   * Revision 1.2  2003/12/22 20:51:32  wbogaardt
35   * refactored name assignments and formatted code for readability.
36   *
37   * Revision 1.1  2003/10/09 23:53:37  wbogaardt
38   * refactored class out of ModuleDetailPanel.java
39   *
40   */
41  public class DeviceIDFieldValidator extends PlainDocument{
42  	/***
43  	 * Check the entered information in the Device ID
44  	 * text field and ensure the first pos is a character
45  	 * folowed by integers. Also ensure that the first
46  	 * positon character is an upper case letter.
47  	 */
48      public void insertString(int offset, String s, AttributeSet attributeSet) throws BadLocationException {
49          if (offset > 0)
50          {
51              try
52              {
53                  Integer.parseInt(s.substring(0));
54              }
55              catch(NumberFormatException nfe)
56              {
57                  return;
58              }
59          }
60          if (offset == 0)
61          {
62              s = s.toUpperCase();
63          }
64          super.insertString(offset, s, attributeSet);
65      }
66  }
67