source: gli/branches/rtl-gli/src/org/greenstone/gatherer/gui/EmailField.java@ 18297

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

interface updated to display right to left for rtl languages. This code is thanks to Amin Hejazi. It seems to be only partially complete. Amin was working with Greenstone 3 so might have missed some panels

  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
Line 
1package org.greenstone.gatherer.gui;
2
3import java.awt.*;
4import java.util.regex.*;
5import javax.swing.*;
6import javax.swing.event.*;
7import javax.swing.text.*;
8import org.greenstone.gatherer.Dictionary;
9
10public class EmailField
11 extends JTextField
12 implements DocumentListener {
13
14 static final public Pattern EMAIL_PATTERN = Pattern.compile("([^()\\-<> @,;:\"][^()<> @,;:\"]*|\"[^()<>@,;:\"]+\")@([A-Za-z](-*[A-Za-z0-9])*(\\.[A-Za-z](-*[A-Za-z0-9])*)*)");
15
16 private boolean invalid = false;
17 private Color background;
18 private Color invalid_background;
19
20 public EmailField(Color invalid_background) {
21 super();
22 this.setComponentOrientation(Dictionary.getOrientation());
23 this.invalid_background = invalid_background;
24 }
25
26 public EmailField(String email, Color invalid_background) {
27 super(email);
28 this.invalid_background = invalid_background;
29 }
30
31 /** Gives notification that an attribute or set of attributes changed.
32 * @param e
33 */
34 public void changedUpdate(DocumentEvent e) {
35 validateEmail();
36 }
37
38 /** Gives notification that there was an insert into the document.
39 * @param e
40 */
41 public void insertUpdate(DocumentEvent e) {
42 validateEmail();
43 }
44
45 /** Gives notification that a portion of the document has been removed.
46 * @param e
47 */
48 public void removeUpdate(DocumentEvent e) {
49 validateEmail();
50 }
51
52 private void validateEmail() {
53 Matcher m = EMAIL_PATTERN.matcher(getText());
54 if(m.matches()) {
55 // It was invalid, but now its valid again
56 if(invalid) {
57 setBackground(background);
58 invalid = false;
59 }
60 // Otherwise nothings changed so why do anything
61 }
62 else {
63 background = getBackground();
64 setBackground(invalid_background);
65 invalid = true;
66 }
67 m = null;
68 }
69}
Note: See TracBrowser for help on using the repository browser.