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

Last change on this file since 5589 was 5589, checked in by mdewsnip, 21 years ago

Nearly finished adding tooltips (and thank goodness for that).

  • 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/**************************************************************************************
30 * Written: 04/07/03
31 * Revised:
32 **************************************************************************************/
33import javax.swing.*;
34import javax.swing.text.*;
35/** A JTextField that doesn't allow whitespace characters.
36 * @author John Thompson, Greenstone Digital Library, University of Waikato
37 * @version 2.4
38 */
39public class NonWhitespaceField
40 extends JTextField {
41
42 public NonWhitespaceField() {
43 super();
44 }
45
46 public NonWhitespaceField(String text) {
47 super(text);
48 }
49
50 protected Document createDefaultModel() {
51 return new NonWhitespaceDocument();
52 }
53
54 static class NonWhitespaceDocument
55 extends PlainDocument {
56
57 public void insertString(int offs, String str, AttributeSet a)
58 throws BadLocationException {
59
60 if (str == null) {
61 return;
62 }
63 char[] raw = str.toCharArray();
64 StringBuffer result = new StringBuffer("");
65 for (int i = 0; i < raw.length; i++) {
66 if(!Character.isWhitespace(raw[i])) {
67 result.append(raw[i]);
68 }
69 }
70 super.insertString(offs, result.toString(), a);
71 }
72 }
73}
Note: See TracBrowser for help on using the repository browser.