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
|
Rev | Line | |
---|
[5167] | 1 | package org.greenstone.gatherer.gui;
|
---|
| 2 |
|
---|
| 3 | import java.awt.*;
|
---|
[10575] | 4 | import java.net.*;
|
---|
[5167] | 5 | import javax.swing.*;
|
---|
| 6 |
|
---|
[8236] | 7 |
|
---|
[5167] | 8 | public class URLField
|
---|
[10575] | 9 | extends JTextField
|
---|
| 10 | {
|
---|
| 11 | public URLField(Color foreground, Color background)
|
---|
| 12 | {
|
---|
[5167] | 13 | super();
|
---|
| 14 | setBackground(background);
|
---|
| 15 | setForeground(foreground);
|
---|
| 16 | }
|
---|
| 17 |
|
---|
| 18 |
|
---|
[10575] | 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 | }
|
---|
[6622] | 32 |
|
---|
[10575] | 33 | // URL string is valid
|
---|
| 34 | return true;
|
---|
[6622] | 35 | }
|
---|
[5167] | 36 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.