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