/Users/lyon/j4p/src/j2d/animation/AnimationDialog.java

1    /* 
2     * Created by DocJava, Inc. 
3     * User: lyon 
4     * Date: Apr 26, 2003 
5     * Time: 7:25:34 AM 
6     */ 
7    package j2d.animation; 
8     
9    import gui.run.RunButton; 
10   import gui.run.RunSlider; 
11   import j2d.ImageProcessorFactory; 
12    
13   import javax.swing.*; 
14   import java.awt.*; 
15    
16    
17   public class AnimationDialog { 
18       private ImageProcessorFactory ipf; 
19       private Image orgImg; 
20       private int numberOfFrames = 10; 
21       private int fps = 10; 
22    
23    
24       JDialog jd = new JDialog(new JFrame(), 
25               "A dialog", true); 
26    
27       public AnimationDialog(Image orgImg, 
28                              ImageProcessorFactory ipf) { 
29           this.ipf = ipf; 
30           this.orgImg = orgImg; 
31           getDialog(); 
32       } 
33    
34    
35       public void getDialog() { 
36    
37           Container c = jd.getContentPane(); 
38           c.setLayout(new BorderLayout()); 
39           JPanel jp = new JPanel(); 
40           jp.setLayout(new FlowLayout()); 
41    
42           jp.add(getFpsPanel()); 
43           jp.add(getNumberOfFramesPanel()); 
44           jp.add(getOkCancelPanel()); 
45    
46           c.add(jp); 
47           jd.setSize(200, 200); 
48           jd.show(); 
49    
50       } 
51    
52       private void cancel() { 
53           jd.dispose(); 
54       } 
55    
56       private JPanel getOkCancelPanel() { 
57           JPanel jp = new JPanel(); 
58           jp.setLayout(new FlowLayout()); 
59           jp.add(new RunButton("ok") { 
60               public void run() { 
61                   GifUtils.writeGifs( 
62                           orgImg, 
63                           ipf, numberOfFrames, fps); 
64               } 
65           }); 
66           jp.add(new RunButton("cancel") { 
67               public void run() { 
68                   cancel(); 
69               } 
70           }); 
71           return jp; 
72       } 
73    
74       private JPanel getNumberOfFramesPanel() { 
75           JPanel jp = new JPanel(); 
76           jp.setLayout(new BorderLayout()); 
77           JLabel jl = new JLabel("number of Frames"); 
78           jp.add(jl, BorderLayout.NORTH); 
79    
80           jp.add(new RunSlider(1, 300, 10) { 
81               public void run() { 
82                   numberOfFrames = getValue(); 
83               } 
84           }, BorderLayout.CENTER); 
85           return jp; 
86       } 
87    
88       private JPanel getFpsPanel() { 
89           JPanel jp = new JPanel(); 
90           jp.setLayout(new BorderLayout()); 
91           jp.add(new RunSlider(1, 30, 10) { 
92               public void run() { 
93                   fps = getValue(); 
94               } 
95           }, BorderLayout.CENTER); 
96           jp.add(new JLabel("fps"), BorderLayout.NORTH); 
97           return jp; 
98       } 
99    
100  } 
101