source: trunk/gli/src/org/greenstone/gatherer/gui/URLField.java@ 12608

Last change on this file since 12608 was 10575, checked in by mdewsnip, 19 years ago

Made URLField far simpler and more accurate. Removed the crazy regular expressions and now just attempts to create a URL object to validate the string.

  • Property svn:keywords set to Author Date Id Revision
File size: 652 bytes
Line 
1package org.greenstone.gatherer.gui;
2
3import java.awt.*;
4import java.net.*;
5import javax.swing.*;
6
7
8public class URLField
9 extends JTextField
10{
11 public URLField(Color foreground, Color background)
12 {
13 super();
14 setBackground(background);
15 setForeground(foreground);
16 }
17
18
19 public boolean validateURL()
20 {
21 String url_string = getText();
22 if (!url_string.equals("")) {
23 // Check the URL string is valid by trying to create a URL object from it
24 try {
25 new URL(url_string);
26 }
27 catch (MalformedURLException exception) {
28 // URL string is invalid
29 return false;
30 }
31 }
32
33 // URL string is valid
34 return true;
35 }
36}
Note: See TracBrowser for help on using the repository browser.