summaryrefslogtreecommitdiff
path: root/java/gjt/test/ImageDissolverTest.java
blob: c157408d2af725cf1af71e24ba2083b39c3e9036 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package gjt.test;

import java.applet.Applet;
import java.awt.*;
import java.awt.image.FilteredImageSource;

import gjt.Util;
import gjt.image.ImageDissolver;

/**
 * Initially displays an image.  Subsequent mouse clicks in the 
 * canvas containing the image cause the image to fade in or 
 * fade out, depending upon it's current state.<p>
 *
 * @version 1.0, Apr 1 1996
 * @author  David Geary
 * @see     gjt.test.UnitTest
 * @see     gjt.image.DissolveFilter
 * @see     gjt.image.ImageDissolver
 */
public class ImageDissolverTest extends UnitTest {
    public String title() { 
        return "ImageDissolver Test " + 
               "(Click Below to Fade Picture In/Out)";     
    }
    public Panel centerPanel() { 
        return new ImageDissolverTestPanel(this); 
    }
}

class ImageDissolverTestPanel extends Panel {
    ImageDissolverTestCanvas canvas;

    public ImageDissolverTestPanel(Applet applet) {
        add(canvas = new ImageDissolverTestCanvas(applet));
    }
    public boolean mouseDown(Event event, int x, int y) {
        canvas.doFade();
        return true;
    }
}

class ImageDissolverTestCanvas extends Canvas {
    private boolean         isFaded = false;
    private Image           image;
    private ImageDissolver  dissolver;

    public ImageDissolverTestCanvas(Applet applet) {
        image = 
        applet.getImage(applet.getCodeBase(),"gifs/saint.gif");

        Util.waitForImage(this, image);
        dissolver = new ImageDissolver(this, image);
    }
    public void paint(Graphics g) {
        if( ! isFaded)
            g.drawImage(image, 0, 0, this);
    }
    public Dimension preferredSize() {
        return new Dimension(image.getWidth(this), 
                             image.getHeight(this));
    }
    public void doFade() {
        if(isFaded) dissolver.fadeIn (0,0);
        else        dissolver.fadeOut(0,0);

        isFaded = isFaded ? false : true;
    }
}