4 * Created on 15 November 2001, 12:52
\r
5 * $Header: /VisTA/CID/Components/TitledURLItem.java 1 15/11/01 15:34 Tj $
\r
7 * $History: TitledURLItem.java $
\r
9 * ***************** Version 1 *****************
\r
10 * User: Tj Date: 15/11/01 Time: 15:34
\r
11 * Created in $/VisTA/CID/Components
\r
15 package org.tjworld.components;
\r
17 import java.net.URL;
\r
18 import java.net.MalformedURLException;
\r
20 /** Maintains a separate record of the filename.extension part of the URL's path, such
\r
21 * that calling getFilename() will return ONLY the simple filename, with no path
\r
24 * If the URL were: http://host.domain.tld:8080/root/path/filename.extension
\r
25 * getFilename() will return: filename.extension
\r
27 * Overrides toString() in order to return a value that allows an instance of
\r
28 * this Class to be used in Lists and ComboBoxes. Calling toString() is functionally
\r
29 * the same as using the accessor method getTitle().
\r
38 public class TitledURLItem {
\r
39 /** URL associated with the Title */
\r
40 protected URL url = null;
\r
42 /** The descriptive Title (usually displayed in list items rather than the raw URL) */
\r
43 protected String title = null;
\r
45 /** The simple filename.ext without any path components */
\r
46 protected String filename = null;
\r
48 /** Creates new TitledURLItem */
\r
49 public TitledURLItem() {
\r
50 this((String)null, (URL)null);
\r
53 /** Creates new TitledURLItem.
\r
54 * Parses the URL to identify the Filename component
\r
55 * @param title The Title associated with the URL
\r
56 * @param url The URL
\r
58 TitledURLItem(String title, URL url) {
\r
61 this.filename = parseFilename(url);
\r
64 /** Return the Title associated to the underlying URL.
\r
65 * Applications may want to determine this dynamically by getting the title of the
\r
66 * document addressed by the URL.
\r
69 * @return Title associated with the URL
\r
71 public String getTitle() {
\r
75 /** Sets the Title associated with the underlying URL.
\r
76 * Applications may want to determine this dynamically by using the title of the
\r
77 * document addressed by the URL.
\r
80 public void setTitle() {
\r
84 /** Gets the simple filename.extension part of the URL
\r
85 * This is useful for applications that use paths to differentiate, for example,
\r
86 * multiple language versions of the same file by path.
\r
89 * @return The simple filename
\r
91 public String getFilename() {
\r
95 /** Get the underlying URL
\r
96 * @return The URL associated with the Title
\r
98 public URL getURL() {
\r
102 /** Set the URL associated with this Title and updates the underlying filename returned by getFilename
\r
103 * @param url the new URL
\r
107 public void setURL(URL url) throws MalformedURLException {
\r
108 this.url = new URL(url, "");
\r
109 filename = parseFilename(this.url);
\r
112 /** Extract the Filename part of a URL
\r
114 * @return Everything to the right of the last path separator returned by URL.getFile(), or null if url is null
\r
115 * @see #setFilename
\r
116 * @see #getFilename
\r
119 public static String parseFilename(URL u) {
\r
120 String result = null;
\r
121 if(u != null) { // only work with proper URL
\r
122 String file = u.getFile(); // the /path/file component
\r
123 int start = file.lastIndexOf('/');
\r
124 if(start == -1) // when the path separator isn't found, treat the url as relative
\r
126 result = file.substring(start+1);
\r
131 /** Gets the Title (functionally identical to getTitle()).
\r
132 * Used by listCellRender objects to determine the text to display
\r
133 * @return the Title
\r
135 public String toString() {
\r