summaryrefslogtreecommitdiff
path: root/java/gjt/test/BleachImageFilterTest.java
blob: 08fda725a0826aa6ebc36a2037369c47236c2a02 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package gjt.test;

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

import gjt.Util;
import gjt.image.BleachImageFilter;

/**
 * Initially displays an unbleached image.  Subsequent mouse
 * clicks in the canvas containing the image toggle between
 * a bleached version of the image and an unbleached version.<p>
 *
 * @version 1.0, Apr 1 1996
 * @author  David Geary
 * @see     gjt.test.UnitTest
 * @see     gjt.image.BleachImageFilter
 */
public class BleachImageFilterTest extends UnitTest {
    public String title() { 
        return "BleachImageFilter Test " + 
               "(Click below to Bleach/Unbleach Picture)";
    }
    public Panel centerPanel() { 
        return new BleachImageFilterTestPanel(this); 
    }
}

class BleachImageFilterTestPanel extends Panel {
    BleachImageFilterTestCanvas canvas;

    public BleachImageFilterTestPanel(Applet applet) {
        add(canvas = new BleachImageFilterTestCanvas(applet));
    }
    public boolean mouseDown(Event event, int x, int y) {
        canvas.toggleBleaching();
        canvas.repaint();
        return true;
    }
}

class BleachImageFilterTestCanvas extends Canvas {
    private Image   im;
    private Image   bleached;
    private boolean showingBleached = false;

    public BleachImageFilterTestCanvas(Applet applet) {
        int    bp;
        String bleachPercent = 
                applet.getParameter("bleachPercent");

        if(bleachPercent != null) 
            bp = new Integer(bleachPercent).intValue();
        else                      
            bp = 50;
        
        im = applet.getImage(applet.getCodeBase(), 
                             "gifs/saint.gif");
        Util.waitForImage(this, im);

        FilteredImageSource source = 
            new FilteredImageSource(im.getSource(), 
                                    new BleachImageFilter(bp));

        bleached = createImage(source);
        Util.waitForImage(this, bleached);
        
        showImageSize();
    }
    public Dimension preferredSize() {
        return new Dimension(im.getWidth(this), 
                             im.getHeight(this));
    }
    public void paint(Graphics g) {
        if(showingBleached) g.drawImage(bleached,0,0,this);
        else                g.drawImage(im,      0,0,this);
    }
    public void toggleBleaching() {
        showingBleached = showingBleached ? false : true;
    }
    private void showImageSize() {
        System.out.print  ("Image width=" + im.getWidth(this));
        System.out.println(" height=" + im.getHeight(this));
    }
}