001/* ---------------------------------------------------------------------------- 002 The Kiwi Toolkit - A Java Class Library 003 Copyright (C) 1998-2004 Mark A. Lindner 004 005 This library is free software; you can redistribute it and/or 006 modify it under the terms of the GNU General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This library is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 General Public License for more details. 014 015 You should have received a copy of the GNU General Public License 016 along with this library; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 018 02111-1307, USA. 019 020 The author may be contacted at: mark_a_lindner@yahoo.com 021 ---------------------------------------------------------------------------- 022 $Log: URLField.java,v $ 023 Revision 1.2 2004/05/12 18:50:04 markl 024 comment block updates 025 026 Revision 1.1 2004/03/15 08:29:38 markl 027 New class. 028 ---------------------------------------------------------------------------- 029*/ 030 031package kiwi.ui; 032 033import java.net.URL; 034import java.net.MalformedURLException; 035 036import kiwi.text.*; 037import kiwi.util.*; 038 039/** A subclass of <code>DataField</code> for the input and display of URLs. 040 * 041 * @author Mark Lindner 042 * @since Kiwi 2.0 043 */ 044 045public class URLField extends DataField 046 { 047 private URL _url = null; 048 049 /** Construct a new <code>NumericField</code> of the specified width and 050 * a default type of <code>DECIMAL_FORMAT</code>. 051 * 052 * @param width The width of the field. 053 */ 054 055 public URLField(int width) 056 { 057 super(width); 058 059 setFont(KiwiUtils.boldFont); 060 } 061 062 /** Set the URL to be displayed by this field. 063 * 064 * @param url The URL. 065 */ 066 067 public void setURL(URL url) 068 { 069 _url = url; 070 071 setText(url.toString()); 072 } 073 074 /** Get the URL that is currently displayed by this field. 075 * 076 * @return The URL, or <code>null</code> if there is no text in the field. 077 */ 078 079 public URL getURL() 080 { 081 return(_url); 082 } 083 084 /** Validate the input in this field. 085 * 086 * @return <code>true</code> if the field contains a valid URL, and 087 * <code>false</code> otherwise. 088 */ 089 090 protected boolean checkInput() 091 { 092 invalid = false; 093 094 if(getText().trim().equals("")) 095 _url = null; 096 else 097 { 098 try 099 { 100 _url = new URL(getText()); 101 } 102 catch(MalformedURLException ex) 103 { 104 invalid = true; 105 } 106 } 107 108 paintInvalid(invalid); 109 110 return(!invalid); 111 } 112 113 } 114 115/* end of source file */