Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
157 kaklik 1
/*
2
    AVRcamVIEW: A PC application to test out the functionallity of the
3
     AVRcam real-time image processing engine.
4
    Copyright (C) 2004    Brent A. Taylor
5
 
6
    This program is free software; you can redistribute it and/or
7
    modify it under the terms of the GNU General Public
8
    License as published by the Free Software Foundation; either
9
    version 2 of the License, or (at your option) any later version.
10
 
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
    General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public
17
    License along with this program; if not, write to the Free Software
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
20
   For more information on the AVRcamVIEW, please contact:
21
 
22
   taylorba@comcast.net
23
 
24
   or go to www.jrobot.net for more details regarding the system.
25
*/
26
 
27
package avr.swing;
28
 
29
import java.awt.*;
30
import java.util.*;
31
import javax.swing.*;
32
import javax.swing.border.*;
33
 
34
public class JRegisterPanel extends JPanel {
35
 
36
   public static void main(String[] args) throws Exception {
37
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
38
      int option = new JRegisterPanel().showDialog(null);
39
      System.out.println(option);
40
   }
41
 
42
   private static final String WARNING_TEXT = "WARNING!!! Changing the registers may cause the AVRcam to no longer respond.  If this happens, simply power cycle the AVRcam.";
43
   private static final int UNKNOWN_OPTION = 0x00;
44
   public static final int OK_OPTION = 0x01;
45
   public static final int CANCEL_OPTION = 0x02;
46
 
47
   private JDialog dialog;
48
   private JRegister[] registers;
49
   private int option;
50
 
51
   private JTabbedPane tabs;
52
 
53
   private JRadioButton enableAutoWhiteBalanceRB;
54
   private JRadioButton disableAutoWhiteBalanceRB;
55
   private JRadioButton enableAutoAdjustModeRB;
56
   private JRadioButton disableAutoAdjustModeRB;
57
   private JRadioButton enableFlourescentLightFilterRB;
58
   private JRadioButton disableFlourescentLightFilterRB;
59
 
60
   public JRegisterPanel() {
61
      super(new BorderLayout());
62
 
63
      tabs = new JTabbedPane();
64
 
65
      enableAutoWhiteBalanceRB = new JRadioButton("Enable", true);
66
      disableAutoWhiteBalanceRB = new JRadioButton("Disable");
67
      enableAutoAdjustModeRB = new JRadioButton("Enable");
68
      disableAutoAdjustModeRB = new JRadioButton("Disable", true);
69
      enableFlourescentLightFilterRB = new JRadioButton("Enable");
70
      disableFlourescentLightFilterRB = new JRadioButton("Disable", true);
71
 
72
      ButtonGroup autoWhiteBalanceBG = new ButtonGroup();
73
      autoWhiteBalanceBG.add(enableAutoWhiteBalanceRB);
74
      autoWhiteBalanceBG.add(disableAutoWhiteBalanceRB);
75
 
76
      ButtonGroup autoAdjustModeBG = new ButtonGroup();
77
      autoAdjustModeBG.add(enableAutoAdjustModeRB);
78
      autoAdjustModeBG.add(disableAutoAdjustModeRB);
79
 
80
      ButtonGroup flourescentLightFilterBG = new ButtonGroup();
81
      flourescentLightFilterBG.add(enableFlourescentLightFilterRB);
82
      flourescentLightFilterBG.add(disableFlourescentLightFilterRB);
83
 
84
//      Box generalP = new Box(BoxLayout.Y_AXIS);
85
      JPanel generalP = new JPanel();
86
      generalP.setLayout(new BoxLayout(generalP, BoxLayout.Y_AXIS));
87
 
88
      Border emptyBorder = new EmptyBorder(5, 5, 5, 5);
89
 
90
      Box autoWhiteBalanceBox = new Box(BoxLayout.X_AXIS);
91
      autoWhiteBalanceBox.setBorder(emptyBorder);
92
      autoWhiteBalanceBox.add(new JLabel("Auto White Balance:"));
93
      autoWhiteBalanceBox.add(Box.createHorizontalGlue());
94
      autoWhiteBalanceBox.add(enableAutoWhiteBalanceRB);
95
      autoWhiteBalanceBox.add(disableAutoWhiteBalanceRB);
96
 
97
      Box autoAdjustModeBox = new Box(BoxLayout.X_AXIS);
98
      autoAdjustModeBox.setBorder(emptyBorder);
99
      autoAdjustModeBox.add(new JLabel("Auto Adjust Mode:"));
100
      autoAdjustModeBox.add(Box.createHorizontalGlue());
101
      autoAdjustModeBox.add(enableAutoAdjustModeRB);
102
      autoAdjustModeBox.add(disableAutoAdjustModeRB);
103
 
104
      Box flourescentLightFilterBox = new Box(BoxLayout.X_AXIS);
105
      flourescentLightFilterBox.setBorder(emptyBorder);
106
      flourescentLightFilterBox.add(new JLabel("Flourescent Light Filter:"));
107
      flourescentLightFilterBox.add(Box.createHorizontalGlue());
108
      flourescentLightFilterBox.add(enableFlourescentLightFilterRB);
109
      flourescentLightFilterBox.add(disableFlourescentLightFilterRB);
110
 
111
      generalP.add(autoWhiteBalanceBox);
112
      generalP.add(autoAdjustModeBox);
113
      generalP.add(flourescentLightFilterBox);
114
 
115
      JPanel advancedP = new JPanel();
116
      advancedP.setLayout(new BoxLayout(advancedP, BoxLayout.Y_AXIS));
117
 
118
      JTextArea warningTA = new JTextArea(WARNING_TEXT);
119
      warningTA.setEditable(false);
120
      warningTA.setWrapStyleWord(true);
121
      warningTA.setLineWrap(true);
122
      warningTA.setForeground(Color.RED);
123
      warningTA.setRows(4);
124
      warningTA.setFont(warningTA.getFont().deriveFont(16F));
125
      warningTA.setBackground(advancedP.getBackground());
126
      warningTA.setBorder(new EmptyBorder(0, 10, 0, 10));
127
 
128
      registers = new JRegister[8];
129
 
130
      for(int i = 0; i < registers.length; i++) {
131
         registers[i] = new JRegister();
132
         advancedP.add(registers[i]);
133
         advancedP.add(Box.createVerticalStrut(5));
134
      }
135
      advancedP.add(warningTA);
136
 
137
      tabs.addTab("General", generalP);
138
      tabs.addTab("Advanced", advancedP);
139
 
140
      add(tabs, BorderLayout.CENTER);
141
 
142
   }
143
 
144
   public int showDialog(Frame owner) {
145
      reset();
146
 
147
      option = UNKNOWN_OPTION;
148
      if(dialog == null) {
149
         dialog = new JDialog(owner, "AVRcamVIEW - Set Registers", true);
150
 
151
         dialog.getContentPane().add(this, BorderLayout.CENTER);
152
         dialog.getContentPane().add(createButtonPanel(), BorderLayout.SOUTH);
153
         dialog.pack();
154
         dialog.setResizable(false);
155
      }
156
 
157
      dialog.setLocationRelativeTo(owner);
158
      dialog.setVisible(true);
159
 
160
      return option;
161
 
162
   }
163
 
164
   public void reset() {
165
      for(int i = 0; i < registers.length; i++) {
166
         registers[i].reset();
167
      }
168
   }
169
 
170
   public Map getRegisters() {
171
      Map info = new HashMap();
172
 
173
      if(tabs.getSelectedIndex() == 0) {
174
 
175
         if(enableAutoWhiteBalanceRB.isSelected()) {
176
            info.put(new Integer(0x12), new Integer(0x2C));
177
         } else {
178
            info.put(new Integer(0x12), new Integer(0x28));
179
         }
180
 
181
         if(enableAutoAdjustModeRB.isSelected()) {
182
            info.put(new Integer(0x13), new Integer(0x01));
183
         } else {
184
            info.put(new Integer(0x13), new Integer(0x00));
185
         }
186
 
187
         if(enableFlourescentLightFilterRB.isSelected()) {
188
            info.put(new Integer(0x2D), new Integer(0x07));
189
         } else {
190
            info.put(new Integer(0x2D), new Integer(0x03));
191
         }
192
 
193
      } else {
194
         for(int i = 0; i < registers.length; i++) {
195
         JRegister r = registers[i];
196
            if(r.isChecked()) {
197
               info.put(r.getRegister(), r.getValue());
198
            }
199
         }
200
      }
201
 
202
      return Collections.unmodifiableMap(info);
203
   }
204
 
205
   public void ok() {
206
      option = OK_OPTION;
207
      dialog.setVisible(false);
208
   }
209
 
210
   public void cancel() {
211
      option = CANCEL_OPTION;
212
      dialog.setVisible(false);
213
   }
214
 
215
   private JComponent createButtonPanel() {
216
 
217
      JPanel buttonP = new JPanel(new FlowLayout(FlowLayout.RIGHT));
218
 
219
      buttonP.setBorder(new EtchedBorder());
220
 
221
      buttonP.add(new JButton(new ProxyAction(this, "ok", "OK", 'o')));
222
      buttonP.add(new JButton(new ProxyAction(this, "cancel", "Cancel", 'c')));
223
 
224
      return buttonP;
225
   }
226
 
227
   private static final class JRegister extends JPanel {
228
 
229
      private JCheckBox enableCB;
230
      private JSpinner registerS;
231
      private JSpinner valueS;
232
 
233
      public JRegister() {
234
         super(new FlowLayout(FlowLayout.CENTER));
235
 
236
         // remove the default insets of the JPanel
237
         setBorder(new EmptyBorder(-5, -5, -5, -5));
238
 
239
         enableCB = new JCheckBox(new ProxyAction(this, "setEnabled", "Register"));
240
 
241
         registerS = new JSpinner(new SpinnerNumberModel(0, 0, 0x90, 1));
242
         valueS = new JSpinner(new SpinnerNumberModel(0, 0, 0xFF, 1));
243
 
244
         reset();
245
 
246
         add(enableCB);
247
         add(registerS);
248
         add(new JLabel(" = "));
249
         add(valueS);
250
      }
251
 
252
      public void reset() {
253
         enableCB.setSelected(false);
254
         registerS.setEnabled(false);
255
         valueS.setEnabled(false);
256
         registerS.setValue(new Integer(0));
257
         valueS.setValue(new Integer(0));
258
      }
259
 
260
      public boolean isChecked() {
261
         return enableCB.isSelected();
262
      }
263
 
264
      public String getRegister() {
265
         return registerS.getValue().toString();
266
      }
267
 
268
      public String getValue() {
269
         return valueS.getValue().toString();
270
      }
271
 
272
      public void setEnabled() {
273
         boolean enabled = enableCB.isSelected();
274
         registerS.setEnabled(enabled);
275
         valueS.setEnabled(enabled);
276
      }
277
 
278
   }
279
 
280
 
281
}