1 /* sane - Scanner Access Now Easy.
2    Copyright (C) 1997 Jeffrey S. Freedman
3    This file is part of the SANE package.
4 
5    This program is free software; you can redistribute it and/or
6    modify it under the terms of the GNU General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
9 
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    General Public License for more details.
14 
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 
18    As a special exception, the authors of SANE give permission for
19    additional uses of the libraries contained in this release of SANE.
20 
21    The exception is that, if you link a SANE library with other files
22    to produce an executable, this does not by itself cause the
23    resulting executable to be covered by the GNU General Public
24    License.  Your use of that executable is in no way restricted on
25    account of linking the SANE library code into it.
26 
27    This exception does not, however, invalidate any other reasons why
28    the executable file might be covered by the GNU General Public
29    License.
30 
31    If you submit changes to SANE to the maintainers to be included in
32    a subsequent release, you agree by submitting the changes that
33    those changes may be distributed with this exception intact.
34 
35    If you write modifications of your own for SANE, it is your choice
36    whether to permit this exception to apply to your modifications.
37    If you do not wish that, delete this exception notice.  */
38 
39 /**
40  **	ImageCanvas.java - A canvas that displays an image.
41  **
42  **	Written: 11/4/97 - JSF
43  **/
44 
45 import java.awt.Canvas;
46 import java.awt.Dimension;
47 import java.awt.Graphics;
48 import java.awt.Image;
49 import java.awt.image.ImageProducer;
50 
51 /*
52  *	Here's a canvas that just shows an image.
53  */
54 
55 public class ImageCanvas extends Canvas
56     {
57     Image image = null;			// The image to display.
58     ImageCanvasClient client = null;	// 1 client for now.
59 
60 	/*
61 	 *	Create with empty image.
62 	 */
ImageCanvas()63     ImageCanvas()
64 	{
65 	}
66 
67 	/*
68 	 *	Create image from an image producer.
69 	 */
setImage(ImageProducer iprod, ImageCanvasClient c)70     void setImage(ImageProducer iprod, ImageCanvasClient c)
71 	{
72 	client = c;
73 	image = createImage(iprod);
74 	repaint();
75 	}
76 
77 	/*
78 	 *	Paint.
79 	 */
paint(Graphics g)80     public void paint(Graphics g)
81 	{
82 	System.out.println("In ImageCanvas.paint()");
83 	Dimension dim = getSize();
84 	g.drawRect(0, 0, dim.width - 1, dim.height - 1);
85 	if (image != null)
86 		{
87 		g.drawImage(image, 1, 1, dim.width - 2, dim.height - 2, this);
88 		}
89 	}
90 
91 	/*
92 	 *	Image has been updated.
93 	 */
imageUpdate(Image theimg, int infoflags, int x, int y, int w, int h)94     public boolean imageUpdate(Image theimg, int infoflags,
95 				int x, int y, int w, int h)
96 	{
97 	System.out.println("In imageUpdate()");
98 	boolean done = ((infoflags & (ERROR | FRAMEBITS | ALLBITS)) != 0);
99 //	repaint();
100 	paint(getGraphics());
101 	if (done && client != null)	// Tell client when done.
102 		{
103 		client.imageDone((infoflags & ERROR) != 0);
104 		client = null;
105 		}
106 	return (!done);
107 	}
108     }
109