KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mc4j > console > swing > html > ClassPathImageView


1 /*
2  * Copyright 2002-2004 Greg Hinkle
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.mc4j.console.swing.html;
18
19 import javax.swing.text.html.ImageView JavaDoc;
20 import javax.swing.text.html.HTML JavaDoc;
21 import javax.swing.text.Element JavaDoc;
22 import java.net.URL JavaDoc;
23
24 /**
25  * @author Greg Hinkle (ghinkle@users.sourceforge.net), Oct 5, 2004
26  * @version $Revision: 492 $($Author: ghinkl $ / $Date: 2004-10-13 01:03:28 -0400 (Wed, 13 Oct 2004) $)
27  */

28 public class ClassPathImageView extends ImageView JavaDoc {
29     public ClassPathImageView(Element JavaDoc elem) {
30         super(elem);
31     }
32     /**
33      * Override the standard url finder to replace classpath
34      * protocols with the actual resource url as found by
35      * our classloader.
36      * @return the url of the image to load
37      */

38     public URL JavaDoc getImageURL() {
39         String JavaDoc src = (String JavaDoc)getElement().getAttributes().
40                      getAttribute(HTML.Attribute.SRC);
41         URL JavaDoc url = null;
42
43         if (src.startsWith("classpath://")) {
44             String JavaDoc location = src;
45             location = location.substring(12,location.length());
46             url = getClass().getClassLoader().getResource(location);
47             return url;
48         } else {
49             return super.getImageURL();
50         }
51     }
52 }
53
Popular Tags