/Users/lyon/j4p/src/j2d/color/ColorSpacePanel.java

1    /* 
2     * Created by DocJava, Inc. 
3     * User: lyon 
4     * Date: Mar 2, 2003 
5     * Time: 5:12:56 PM 
6     */ 
7    package j2d.color; 
8     
9    import gui.run.RunButton; 
10   import gui.run.RunSlider; 
11   import j2d.ImageProcessListener; 
12    
13   import javax.swing.*; 
14   import java.awt.*; 
15    
16    
17   public class ColorSpacePanel 
18           extends JPanel { 
19    
20       private ImageProcessListener ipl = null; 
21    
22       private RunSlider rsa[][] = new RunSlider[3][3]; 
23       private float colorMatrix[][] = new float[3][3]; 
24    
25    
26       public ColorSpacePanel(ImageProcessListener _ipl) { 
27           ipl = _ipl; 
28    
29           setLayout(new GridLayout(0, 3)); 
30           for (int x = 0; x < rsa.length; x++) 
31               for (int y = 0; y < rsa[0].length; y++) 
32                   add(new FloatMatrixSlider(x, y)); 
33           add(getButtonPanel()); 
34       } 
35    
36       private JPanel getButtonPanel() { 
37           JPanel jp = new JPanel(); 
38           jp.setLayout(new FlowLayout()); 
39           jp.add(new RunButton("apply") { 
40               public void run() { 
41                   updateImage(); 
42               } 
43           }); 
44           jp.add(new RunButton("Reset") { 
45               public void run() { 
46                   ipl.update(null); 
47               } 
48           }); 
49           return jp; 
50       } 
51    
52       private void updateImage() { 
53           ipl.update(new ColorSpaceProcessor(colorMatrix)); 
54    
55       } 
56    
57       public static float scaleSlider(int t) { 
58           return (float) (t / 100.0); 
59       } 
60    
61       private class FloatMatrixSlider extends RunSlider { 
62           private final int x; 
63           private final int y; 
64    
65           public FloatMatrixSlider(int x, int y) { 
66               this.x = x; 
67               this.y = y; 
68           } 
69    
70           public void run() { 
71               colorMatrix[x][y] = 
72                       scaleSlider(getValue()); 
73           } 
74       } 
75   } 
76