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

Last change on this file since 20957 was 18370, checked in by kjdon, 15 years ago

committed code submitted by Amin Hedjazi for making the GLI right to left. I worked on this code on the rtl-gli branch, then merged the branch back to the trunk at revision 18368. The branch code was slightly different in a couple of places where it shouldn't have been. So don't use the branch code next time. Start a new branch.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.5 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.*;
35import org.greenstone.gatherer.Dictionary;
36
37/** A JTextField that doesn't allow whitespace characters.
38 * @author John Thompson, Greenstone Digital Library, University of Waikato
39 * @version 2.4
40 */
41public class NonWhitespaceField
42 extends JTextField {
43
44 public NonWhitespaceField() {
45 super();
46 this.setComponentOrientation(Dictionary.getOrientation());
47 }
48
49 public NonWhitespaceField(String text) {
50 super(text);
51 this.setComponentOrientation(Dictionary.getOrientation());
52 }
53
54 protected Document createDefaultModel() {
55 return new NonWhitespaceDocument();
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}
Note: See TracBrowser for help on using the repository browser.