source: trunk/gli/src/org/greenstone/gatherer/gui/NonWhitespaceField.java@ 4939

Last change on this file since 4939 was 4939, checked in by jmt12, 21 years ago

Major changes to CDM.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1/**
2 *#########################################################################
3 *
4 * A component of the Gatherer application, part of the Greenstone digital
5 * library suite from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Author: John Thompson, Greenstone Digital Library, University of Waikato
9 *
10 * Copyright (C) 1999 New Zealand Digital Library Project
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 *########################################################################
26 */
27package org.greenstone.gatherer.gui;
28/**************************************************************************************
29 * Written: 04/07/03
30 * Revised:
31 **************************************************************************************/
32import javax.swing.*;
33import javax.swing.text.*;
34/** A JTextField that doesn't allow whitespace characters.
35 * @author John Thompson, Greenstone Digital Library, University of Waikato
36 * @version 2.4
37 */
38public class NonWhitespaceField
39 extends JTextField {
40
41 public NonWhitespaceField() {
42 super();
43 }
44
45 public NonWhitespaceField(String text) {
46 super(text);
47 }
48
49 protected Document createDefaultModel() {
50 return new NonWhitespaceDocument();
51 }
52
53 static class NonWhitespaceDocument
54 extends PlainDocument {
55
56 public void insertString(int offs, String str, AttributeSet a)
57 throws BadLocationException {
58
59 if (str == null) {
60 return;
61 }
62 char[] raw = str.toCharArray();
63 StringBuffer result = new StringBuffer("");
64 for (int i = 0; i < raw.length; i++) {
65 if(!Character.isWhitespace(raw[i])) {
66 result.append(raw[i]);
67 }
68 }
69 super.insertString(offs, result.toString(), a);
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.