01: /*
02: * Copyright (C) 2004 TiongHiang Lee
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * Email: thlee@onemindsoft.org
19: */
20:
21: package org.onemind.swingweb.image;
22:
23: import java.awt.Graphics;
24: import java.awt.image.BufferedImage;
25: import java.io.IOException;
26: import java.net.URL;
27: import java.util.logging.Logger;
28: import javax.imageio.ImageIO;
29:
30: /**
31: * An image from a URL
32: * @author TiongHiang Lee (thlee@onemindsoft.org)
33: *
34: */
35: public class URLImage extends AbstractImage {
36:
37: /** the logger **/
38: private static final Logger _logger = Logger
39: .getLogger(URLImage.class.getName());
40:
41: /** the url **/
42: private URL _url;
43:
44: /**
45: * Constructor
46: * @param g the graphics
47: * @param url the url
48: */
49: public URLImage(Graphics g, URL url) {
50: super (g);
51: _url = url;
52: BufferedImage bufferedImage;
53: try {
54: bufferedImage = ImageIO.read(_url.openStream());
55: setWidth(bufferedImage.getWidth());
56: setHeight(bufferedImage.getHeight());
57: } catch (IOException e) {
58: _logger.throwing(getClass().getName(), "constructor", e);
59: }
60: }
61:
62: /**
63: * Return the url
64: * @return the url
65: */
66: public URL getURL() {
67: return _url;
68: }
69: }
|