/Users/lyon/j4p/src/video/NequantDialog.java

1    package video; 
2     
3    import futils.Futil; 
4    import gui.In; 
5    import gui.dialogs.LabelledItemPanel; 
6    import gui.dialogs.ModalJDialog; 
7    import gui.run.RunButton; 
8    import gui.run.RunCheckBox; 
9    import gui.run.RunSlider; 
10   import gui.run.RunTextField; 
11    
12   import javax.swing.BorderFactory; 
13   import java.io.File; 
14    
15   /** 
16    * This class demonstrates the usage of the StandardDialog class. 
17    */ 
18   public class NequantDialog extends ModalJDialog { 
19       NeuquantCaptureBean ncb; 
20    
21    
22       public NequantDialog() { 
23           init(); 
24       } 
25    
26       private void init() { 
27           setTitle("NeQuantDialog"); 
28           ncb = NeuquantCaptureBean.restore(); 
29           final RunTextField outputFileTextField = getOutputFileTextField(); 
30           LabelledItemPanel c = new LabelledItemPanel(); 
31           c.addItem("localFile", outputFileTextField); 
32           c.addItem("setLocalFile", new RunButton("browse") { 
33               public void run() { 
34                   File f = Futil.getReadFile("select local file"); 
35                   outputFileTextField.setText(f.getAbsolutePath()); 
36                   ncb.setOutputFile(f.getAbsolutePath()); 
37               } 
38           }); 
39           c.addItem("is Looped", new RunCheckBox("", ncb.isLooped()) { 
40               public void run() { 
41                   ncb.setLooped(isSelected()); 
42               } 
43           }); 
44           c.addItem("sec/frame", new RunSlider(0, 10, (int) ncb.getSecondsPerFrame()) { 
45               public void run() { 
46                   ncb.setSecondsPerFrame(getValue()); 
47               } 
48           }); 
49           c.setBorder(BorderFactory.createEtchedBorder()); 
50           setContentPane(c); 
51       } 
52    
53       private RunTextField getOutputFileTextField() { 
54           return new RunTextField(ncb.getOutputFile(), 20) { 
55               public void run() { 
56                   ncb.setOutputFile(getText()); 
57               } 
58           }; 
59       } 
60    
61       /** 
62        * This method gets the values of the panel entry fields. 
63        * 
64        * @return an object containing the Customer data 
65        */ 
66       public NeuquantCaptureBean getData() { 
67           return ncb; 
68       } 
69    
70       public void okPressed() { 
71           if (isValidData()) { 
72               processOk(); 
73           } else 
74               debugData(); 
75       } 
76    
77       private void processOk() { 
78           System.out.println("OK process!"); 
79           ncb.save(); 
80           System.out.println("Validate the data and capture..."); 
81           //super.okPressed(); 
82       } 
83    
84       public void debugData() { 
85           In.message("data not valid! Model=" + ncb); 
86       } 
87    
88       /** 
89        * This method checks that the data entered is valid. 
90        * 
91        * @return <code>true</code> if the data is valid, otherwise 
92        *         <code>false</code> 
93        */ 
94       protected boolean isValidData() { 
95           return ncb.isValidData(); 
96       } 
97    
98       public static void main(String[] args) { 
99           NequantDialog dialog = new NequantDialog(); 
100          dialog.pack(); 
101          dialog.show(); 
102          System.exit(0); 
103      } 
104  }