KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > graphics > Images


1 /*
2  * Copyright (c) 1998-2000 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  *
28  * $Id: Images.java,v 1.6 2005/01/10 23:25:42 cvs Exp $
29  */

30
31 package com.caucho.graphics;
32
33 import java.awt.*;
34 import java.awt.image.ColorModel JavaDoc;
35 import java.awt.image.ImageConsumer JavaDoc;
36 import java.util.Hashtable JavaDoc;
37
38 public class Images implements ImageConsumer JavaDoc {
39   private static Toolkit toolkit;
40   private int width;
41   private int height;
42
43   public static Images getImage(String JavaDoc filename)
44   {
45     try {
46       if (toolkit == null)
47         toolkit = Toolkit.getDefaultToolkit();
48       
49       Image img = toolkit.getImage(filename);
50
51       if (img == null)
52     return null;
53
54       Images image = new Images();
55
56       img.getSource().startProduction(image);
57
58       synchronized (image) {
59     image.wait(100);
60       }
61
62       if (image.width > 0 && image.height > 0)
63     return image;
64       else
65     return null;
66     } catch (Throwable JavaDoc e) {
67       return null;
68     }
69   }
70
71   public int getWidth()
72   {
73     return width;
74   }
75
76   public int getHeight()
77   {
78     return height;
79   }
80
81   public void imageComplete(int status)
82   {
83     synchronized (this) {
84       this.notifyAll();
85     }
86   }
87   public void setColorModel(ColorModel JavaDoc model) {}
88
89   public void setDimensions(int width, int height)
90   {
91     this.width = width;
92     this.height = height;
93   }
94
95   public void setHints(int hintflags) {}
96   public void setPixels(int x, int y, int w, int h, ColorModel JavaDoc mode,
97     byte []pixels, int off, int scansize) {}
98   public void setPixels(int x, int y, int w, int h, ColorModel JavaDoc mode,
99       int []pixels, int off, int scansize) {}
100
101   public void setProperties(Hashtable JavaDoc<?,?> props) {}
102 }
103
104
105
Popular Tags