1 package com.hammurapi.jcapture;
2 
3 import java.awt.BorderLayout;
4 import java.awt.Component;
5 import java.awt.GridBagConstraints;
6 import java.awt.GridBagLayout;
7 import java.awt.Insets;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.util.List;
11 
12 import javax.sound.sampled.AudioFormat;
13 import javax.sound.sampled.AudioSystem;
14 import javax.sound.sampled.DataLine;
15 import javax.sound.sampled.Mixer;
16 import javax.sound.sampled.TargetDataLine;
17 import javax.swing.BorderFactory;
18 import javax.swing.ButtonGroup;
19 import javax.swing.ComboBoxModel;
20 import javax.swing.DefaultComboBoxModel;
21 import javax.swing.JButton;
22 import javax.swing.JCheckBox;
23 import javax.swing.JComboBox;
24 import javax.swing.JLabel;
25 import javax.swing.JOptionPane;
26 import javax.swing.JPanel;
27 import javax.swing.JRadioButton;
28 import javax.swing.JTabbedPane;
29 import javax.swing.JTextField;
30 import javax.swing.SwingConstants;
31 
32 public class CaptureOptionsDialog extends javax.swing.JDialog {
33 	private JRadioButton sampleSize16Button;
34 	private JTextField timeLineScaleTextField;
35 	private JCheckBox toobarCheckBox;
36 	private JCheckBox videoBorderCheckBox;
37 	private JTextField screenScaleTextField;
38 	private JLabel timelineScalingLabel;
39 	private JLabel screenScalingLabel;
40 	private JTextField fpsTextField;
41 	private JLabel fpsLabel;
42 	private ButtonGroup sampleSizeButtonGroup;
43 	private JComboBox<String> sampleRateComboBox;
44 	private JRadioButton sampleSize8Button;
45 	private JTextField inactivityIntervalTextField;
46 	private JLabel inactivityIntervalLabel;
47 	private JCheckBox inactivityCheckBox;
48 	private JPanel inactivityPanel;
49 	private JPanel scalingPanel;
50 	private JCheckBox stereoCheckBox;
51 	private JLabel sampleSizeLabel;
52 	private JTabbedPane recordingSettingsPane;
53 	private JCheckBox recordSoundCheckBox;
54 	private JLabel sampleRateLabel;
55 	private JComboBox<String> soundLineComboBox;
56 	private JLabel soundSourceLabel;
57 	private JPanel audioSettingsPanel;
58 	private JPanel videoSettingsPanel;
59 	private JButton cancelButton;
60 	private JButton okButton;
61 	private JPanel recordPanel;
62 	private JComboBox<VideoEncoder> encodersComboBox;
63 	private JTextField mp3Text;
64 
CaptureOptionsDialog(final CaptureFrame owner)65 	public CaptureOptionsDialog(final CaptureFrame owner) {
66 		super(owner);
67 		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
68 		BorderLayout thisLayout = new BorderLayout();
69 		this.setLayout(thisLayout);
70 		this.setPreferredSize(new java.awt.Dimension(333, 186));
71 
72 		recordPanel = new JPanel();
73 		this.add(recordPanel);
74 		GridBagLayout recordPanelLayout = new GridBagLayout();
75 		recordPanelLayout.rowWeights = new double[] { 0.1, 0.0, 0.0, 0.0 };
76 		recordPanelLayout.rowHeights = new int[] { 7, 7, 20, 7 };
77 		recordPanelLayout.columnWeights = new double[] { 0.1, 0.0, 0.0, 0.0, 0.0 };
78 		recordPanelLayout.columnWidths = new int[] { 20, 7, 7, 7, 7 };
79 		recordPanel.setLayout(recordPanelLayout);
80 		recordPanel.setPreferredSize(new java.awt.Dimension(335, 297));
81 
82 		okButton = new JButton();
83 		recordPanel.add(okButton, new GridBagConstraints(1, 2, 1, 1, 0.0,
84 				0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
85 				new Insets(0, 0, 0, 0), 0, 0));
86 		okButton.setText("OK");
87 		okButton.addActionListener(new ActionListener() {
88 			public void actionPerformed(ActionEvent evt) {
89 				try {
90 					if (recordSoundCheckBox.isSelected()) {
91 						owner.getCaptureConfig().setAudioFormat(audioFormat);
92 						owner.getCaptureConfig().setMixerName((String) soundLineComboBox.getSelectedItem());
93 					} else {
94 						owner.getCaptureConfig().setRemoveInactivity(inactivityCheckBox.isSelected());
95 						if (owner.getCaptureConfig().isRemoveInactivity()) {
96 							owner.getCaptureConfig().setInactivityInterval(Double.parseDouble(inactivityIntervalTextField.getText()));
97 						}
98 					}
99 
100 					owner.getCaptureConfig().setLoop(getLoopCheckBox().isSelected());
101 					owner.getCaptureConfig().setPlay(getPlayCheckBox().isSelected());
102 					owner.getCaptureConfig().setMouse(getMouseCheckBox().isSelected());
103 					owner.getCaptureConfig().setSound(recordSoundCheckBox.isSelected());
104 					owner.getCaptureConfig().setImageFormat(getImageFormatTextField().getText().trim());
105 					owner.getCaptureConfig().setBorder(videoBorderCheckBox.isSelected());
106 					owner.getCaptureConfig().setFramesPerSecond(Float.parseFloat(fpsTextField.getText()));
107 					owner.getCaptureConfig().setScreenScale(Double.parseDouble(screenScaleTextField.getText()) / 100.0);
108 					owner.getCaptureConfig().setSpeedScale((float) (Float.parseFloat(timeLineScaleTextField.getText()) / 100.0));
109 					owner.getCaptureConfig().setToolBar(toobarCheckBox.isSelected());
110 					owner.getApplet().storeConfig(owner.getCaptureConfig().store());
111 					owner.getCaptureConfig().setMp3command(mp3Text.getText());
112 					owner.getCaptureConfig().setEncoder((VideoEncoder) encodersComboBox.getSelectedItem());
113 					owner.setRecordButtonState();
114 					CaptureOptionsDialog.this.setVisible(false);
115 				} catch (Exception e) {
116 					e.printStackTrace();
117 					JOptionPane.showMessageDialog(CaptureOptionsDialog.this,
118 							e.toString(), "Error in configuration parameters",
119 							JOptionPane.ERROR_MESSAGE);
120 				}
121 			}
122 		});
123 
124 		cancelButton = new JButton();
125 		recordPanel.add(cancelButton, new GridBagConstraints(3, 2, 1, 1, 0.0,
126 				0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE,
127 				new Insets(0, 0, 0, 0), 0, 0));
128 		cancelButton.setText("Cancel");
129 		cancelButton.addActionListener(new ActionListener() {
130 
131 			@Override
132 			public void actionPerformed(ActionEvent e) {
133 				CaptureOptionsDialog.this.setVisible(false);
134 			}
135 		});
136 
137 		recordingSettingsPane = new JTabbedPane();
138 		recordPanel.add(recordingSettingsPane, new GridBagConstraints(0, 0, 5,
139 				1, 0.0, 0.0, GridBagConstraints.CENTER,
140 				GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
141 
142 		videoSettingsPanel = new JPanel();
143 		GridBagLayout videoSettingsPanelLayout = new GridBagLayout();
144 		recordingSettingsPane.addTab("Video", null, videoSettingsPanel, null);
145 		videoSettingsPanel.setPreferredSize(new java.awt.Dimension(112, 207));
146 		videoSettingsPanelLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1 };
147 		videoSettingsPanelLayout.rowHeights = new int[] { 7, 7, 7, 7, 7, 7, 7, 20 };
148 		videoSettingsPanelLayout.columnWeights = new double[] { 0.0, 0.0, 0.0,
149 				0.0, 0.0, 0.0, 0.0, 0.0, 0.1 };
150 		videoSettingsPanelLayout.columnWidths = new int[] { 115, 7, 40, 7, 20,
151 				7, 20, 7, 20 };
152 		videoSettingsPanel.setLayout(videoSettingsPanelLayout);
153 
154 		scalingPanel = new JPanel();
155 		GridBagLayout scalingPanelLayout = new GridBagLayout();
156 		videoSettingsPanel.add(scalingPanel, new GridBagConstraints(0, 6, 1, 1,
157 				0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
158 				new Insets(0, 0, 0, 0), 0, 0));
159 		scalingPanel.setBorder(BorderFactory.createTitledBorder("Scaling (%)"));
160 		scalingPanelLayout.rowWeights = new double[] { 0.1, 0.0, 0.1 };
161 		scalingPanelLayout.rowHeights = new int[] { 7, 7, 7 };
162 		scalingPanelLayout.columnWeights = new double[] { 0.0, 0.0, 0.1 };
163 		scalingPanelLayout.columnWidths = new int[] { 7, 7, 7 };
164 		scalingPanel.setLayout(scalingPanelLayout);
165 		scalingPanel.add(getScreenScalingLabel(), new GridBagConstraints(0, 0,
166 				1, 1, 0.0, 0.0, GridBagConstraints.EAST,
167 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
168 		scalingPanel.add(getTimelineScalingLabel(), new GridBagConstraints(0,
169 				2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
170 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
171 		scalingPanel.add(getScreenScaleTextField(), new GridBagConstraints(2,
172 				0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
173 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
174 		scalingPanel.add(getTimeLineScaleTextField(), new GridBagConstraints(2,
175 				2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
176 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
177 
178 		inactivityPanel = new JPanel();
179 		GridBagLayout inactivityPanelLayout = new GridBagLayout();
180 		videoSettingsPanel.add(inactivityPanel, new GridBagConstraints(2, 6, 8,
181 				1, 0.0, 0.0, GridBagConstraints.WEST,
182 				GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0));
183 		videoSettingsPanel.add(getFpsLabel(), new GridBagConstraints(0, 0, 1,
184 				1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
185 				new Insets(0, 0, 0, 0), 0, 0));
186 		videoSettingsPanel.add(getFpsTextField(), new GridBagConstraints(2, 0,
187 				1, 1, 0.0, 0.0, GridBagConstraints.WEST,
188 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
189 
190 		videoSettingsPanel.add(getImageFormatLabel(), new GridBagConstraints(0, 2, 1,
191 				1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
192 				new Insets(0, 0, 0, 0), 0, 0));
193 		videoSettingsPanel.add(getImageFormatTextField(), new GridBagConstraints(2, 2,
194 				1, 1, 0.0, 0.0, GridBagConstraints.WEST,
195 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
196 
197 		videoSettingsPanel.add(getEncoderLabel(), new GridBagConstraints(0, 4, 1,
198 				1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
199 				new Insets(0, 0, 0, 0), 0, 0));
200 		videoSettingsPanel.add(getEncoderComboBox(), new GridBagConstraints(2, 4,
201 				6, 1, 0.0, 0.0, GridBagConstraints.WEST,
202 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
203 
204 		videoSettingsPanel.add(getVideoBorderCheckBox(),
205 				new GridBagConstraints(4, 0, 1, 1, 0.0, 0.0,
206 						GridBagConstraints.WEST, GridBagConstraints.NONE,
207 						new Insets(0, 0, 0, 0), 0, 0));
208 		videoSettingsPanel.add(getLoopCheckBox(),
209 				new GridBagConstraints(6, 2, 1, 1, 0.0, 0.0,
210 						GridBagConstraints.WEST, GridBagConstraints.NONE,
211 						new Insets(0, 0, 0, 0), 0, 0));
212 		videoSettingsPanel.add(getPlayCheckBox(),
213 				new GridBagConstraints(8, 2, 1, 1, 0.0, 0.0,
214 						GridBagConstraints.WEST, GridBagConstraints.NONE,
215 						new Insets(0, 0, 0, 0), 0, 0));
216 		videoSettingsPanel.add(getMouseCheckBox(),
217 				new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0,
218 						GridBagConstraints.WEST, GridBagConstraints.NONE,
219 						new Insets(0, 0, 0, 0), 0, 0));
220 		videoSettingsPanel.add(getJToobarCheckBox(), new GridBagConstraints(6,
221 				0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
222 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
223 		inactivityPanel.setBorder(BorderFactory
224 				.createTitledBorder("Inactivity processing"));
225 		inactivityPanel
226 				.setToolTipText("Inactivity handling, enabled if audio is not being recorded.");
227 		inactivityPanelLayout.rowWeights = new double[] { 0.0, 0.0, 0.0 };
228 		inactivityPanelLayout.rowHeights = new int[] { 7, 7, 7 };
229 		inactivityPanelLayout.columnWeights = new double[] { 0.0, 0.0, 0.0,
230 				0.0, 0.1 };
231 		inactivityPanelLayout.columnWidths = new int[] { 7, 7, 7, 47, 7 };
232 		inactivityPanel.setLayout(inactivityPanelLayout);
233 		inactivityPanel.setEnabled(false);
234 
235 		inactivityCheckBox = new JCheckBox();
236 		inactivityPanel.add(inactivityCheckBox, new GridBagConstraints(1, 0, 4,
237 				1, 0.0, 0.0, GridBagConstraints.WEST,
238 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
239 		inactivityCheckBox.setText("Remove inactivity");
240 		inactivityCheckBox.setEnabled(false);
241 
242 		inactivityIntervalLabel = new JLabel();
243 		inactivityPanel.add(inactivityIntervalLabel, new GridBagConstraints(1,
244 				2, 1, 1, 0.0, 0.0, GridBagConstraints.EAST,
245 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
246 		inactivityIntervalLabel.setText("Inactivity interval (sec)");
247 		inactivityIntervalLabel.setEnabled(false);
248 
249 		inactivityIntervalTextField = new JTextField();
250 		inactivityPanel.add(inactivityIntervalTextField,
251 				new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0,
252 						GridBagConstraints.CENTER,
253 						GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
254 						0, 0));
255 		inactivityIntervalTextField.setText("0.7");
256 		inactivityIntervalTextField.setEnabled(false);
257 
258 		audioSettingsPanel = new JPanel();
259 		GridBagLayout audioSettingsPanelLayout = new GridBagLayout();
260 		recordingSettingsPane.addTab("Audio", null, audioSettingsPanel, null);
261 		audioSettingsPanelLayout.rowWeights = new double[] { 0.0, 0.0, 0.0,
262 				0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1 };
263 		audioSettingsPanelLayout.rowHeights = new int[] { 7, 7, 7, 7, 7, 7, 7, 7, 7,
264 				20 };
265 		audioSettingsPanelLayout.columnWeights = new double[] { 0.0, 0.0, 0.0,
266 				0.0, 0.0, 0.0, 0.1 };
267 		audioSettingsPanelLayout.columnWidths = new int[] { 7, 7, 49, 7, 135,
268 				7, 20 };
269 		audioSettingsPanel.setLayout(audioSettingsPanelLayout);
270 
271 		sampleSize16Button = new JRadioButton();
272 		audioSettingsPanel.add(sampleSize16Button, new GridBagConstraints(4, 4,
273 				1, 1, 0.0, 0.0, GridBagConstraints.WEST,
274 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
275 		sampleSize16Button.setText("16");
276 		sampleSize16Button.setSelected(true);
277 		getSampleSizeButtonGroup().add(sampleSize16Button);
278 		sampleSize16Button.addActionListener(new ActionListener() {
279 			public void actionPerformed(ActionEvent evt) {
280 				selectSoundSource();
281 			}
282 		});
283 
284 		recordSoundCheckBox = new JCheckBox();
285 		audioSettingsPanel.add(recordSoundCheckBox, new GridBagConstraints(0,
286 				0, 4, 1, 0.0, 0.0, GridBagConstraints.WEST,
287 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
288 		recordSoundCheckBox.setText("Record sound");
289 		recordSoundCheckBox.setSelected(true);
290 		recordSoundCheckBox.addActionListener(new ActionListener() {
291 			public void actionPerformed(ActionEvent evt) {
292 				onSetSound();
293 			}
294 		});
295 
296 		soundSourceLabel = new JLabel();
297 		audioSettingsPanel.add(soundSourceLabel, new GridBagConstraints(0, 6,
298 				1, 1, 0.0, 0.0, GridBagConstraints.EAST,
299 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
300 		soundSourceLabel.setText("Source");
301 
302 		soundLineComboBox = new JComboBox();
303 		audioSettingsPanel.add(soundLineComboBox, new GridBagConstraints(2, 6,
304 				3, 1, 0.0, 0.0, GridBagConstraints.CENTER,
305 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
306 
307 		audioSettingsPanel.add(new JLabel("WAV2MP3 command"), new GridBagConstraints(0, 8,
308 				1, 1, 0.0, 0.0, GridBagConstraints.EAST,
309 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
310 
311 		mp3Text = new JTextField();
312 		audioSettingsPanel.add(mp3Text, new GridBagConstraints(2, 8,
313 				5, 1, 0.0, 0.0, GridBagConstraints.CENTER,
314 				GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
315 
316 		sampleRateLabel = new JLabel();
317 		audioSettingsPanel.add(sampleRateLabel, new GridBagConstraints(0, 2, 1,
318 				1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
319 				new Insets(0, 0, 0, 0), 0, 0));
320 		sampleRateLabel.setText("Sample rate (khz)");
321 
322 		sampleSizeLabel = new JLabel();
323 		audioSettingsPanel.add(sampleSizeLabel, new GridBagConstraints(0, 4, 1,
324 				1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE,
325 				new Insets(0, 0, 0, 0), 0, 0));
326 		sampleSizeLabel.setText("Sample size (bits)");
327 
328 		stereoCheckBox = new JCheckBox();
329 		audioSettingsPanel.add(stereoCheckBox, new GridBagConstraints(4, 2, 1,
330 				1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
331 				new Insets(0, 0, 0, 0), 0, 0));
332 		stereoCheckBox.setText("Stereo");
333 		stereoCheckBox.addActionListener(new ActionListener() {
334 			public void actionPerformed(ActionEvent evt) {
335 				selectSoundSource();
336 			}
337 		});
338 
339 		sampleSize8Button = new JRadioButton();
340 		audioSettingsPanel.add(sampleSize8Button, new GridBagConstraints(2, 4,
341 				1, 1, 0.0, 0.0, GridBagConstraints.WEST,
342 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
343 		sampleSize8Button.setText("8");
344 		getSampleSizeButtonGroup().add(sampleSize8Button);
345 		sampleSize8Button.addActionListener(new ActionListener() {
346 			public void actionPerformed(ActionEvent evt) {
347 				selectSoundSource();
348 			}
349 		});
350 
351 		ComboBoxModel<String> sampleRateComboBoxModel = new DefaultComboBoxModel<String>(
352 				new String[] { "5.5", "11", "22", "44" });
353 		sampleRateComboBox = new JComboBox<String>();
354 		audioSettingsPanel.add(sampleRateComboBox, new GridBagConstraints(2, 2,
355 				1, 1, 0.0, 0.0, GridBagConstraints.CENTER,
356 				GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
357 		sampleRateComboBox.setModel(sampleRateComboBoxModel);
358 		sampleRateComboBox.setSelectedIndex(2);
359 		sampleRateComboBox.addActionListener(new ActionListener() {
360 			public void actionPerformed(ActionEvent evt) {
361 				selectSoundSource();
362 			}
363 		});
364 
365 		getImageFormatTextField().setText(owner.getCaptureConfig().getImageFormat());
366 
367 		recordSoundCheckBox.setSelected(owner.getCaptureConfig().isSound());
368 		stereoCheckBox.setSelected(owner.getCaptureConfig().getAudioFormat().getChannels()>1);
369 		if (owner.getCaptureConfig().getAudioFormat().getSampleSizeInBits()==8) {
370 			sampleSize8Button.setSelected(true);
371 		} else {
372 			sampleSize16Button.setSelected(true);
373 		}
374 
375 		float sampleRate = owner.getCaptureConfig().getAudioFormat().getSampleRate();
376 		float proximity = Math.abs(sampleRate-sampleRates[0]);
377 		sampleRateComboBox.setSelectedIndex(0);
378 		for (int i=1; i<sampleRates.length; ++i) {
379 			float prx = Math.abs(sampleRate-sampleRates[i]);
380 			if (prx<proximity) {
381 				sampleRateComboBox.setSelectedIndex(i);
382 				proximity = prx;
383 			}
384 		}
385 		inactivityCheckBox.setSelected(owner.getCaptureConfig().isRemoveInactivity());
386 		if (owner.getCaptureConfig().isRemoveInactivity()) {
387 			inactivityIntervalTextField.setText(String.valueOf(owner.getCaptureConfig().getInactivityInterval()));
388 		}
389 		onSetSound();
390 
391 		videoBorderCheckBox.setSelected(owner.getCaptureConfig().isBorder());
392 		getMouseCheckBox().setSelected(owner.getCaptureConfig().isMouse());
393 		getLoopCheckBox().setSelected(owner.getCaptureConfig().isLoop());
394 		getPlayCheckBox().setSelected(owner.getCaptureConfig().isPlay());
395 		fpsTextField.setText(Float.toString(owner.getCaptureConfig().getFramesPerSecond()));
396 		screenScaleTextField.setText(Long.toString(Math.round(owner.getCaptureConfig().getScreenScale()*100.0)));
397 		timeLineScaleTextField.setText(Long.toString(Math.round(owner.getCaptureConfig().getSpeedScale()*100.0)));
398 		toobarCheckBox.setSelected(owner.getCaptureConfig().isToolBar());
399 		mp3Text.setText(owner.getCaptureConfig().getMp3command());
400 
401 		selectSoundSource();
402 		soundLineComboBox.setSelectedItem(owner.getCaptureConfig().getMixerName());
403 
404 		timeLineScaleTextField.setEnabled(!recordSoundCheckBox.isSelected());
405 
406 		getEncoderComboBox().setSelectedItem(owner.getCaptureConfig().getEncoder());
407 
408 		JPanel aboutPanel = new JPanel();
409 		aboutPanel.setLayout(new BorderLayout());
410 		recordingSettingsPane.addTab("About", aboutPanel);
411 		aboutPanel.add(new JLabel("jCapture", SwingConstants.CENTER), BorderLayout.NORTH);
412 		aboutPanel.add(new JLabel("by Hammurapi Group (http://www.hammurapi.com)", SwingConstants.CENTER), BorderLayout.CENTER);
413 		aboutPanel.add(new JLabel("Memory (available/max): "+AbstractCaptureApplet.formatByteSize(Runtime.getRuntime().freeMemory())+"/"+AbstractCaptureApplet.formatByteSize(Runtime.getRuntime().maxMemory()), SwingConstants.CENTER), BorderLayout.SOUTH);
414 
415 		setSize(400, 300);
416 		setLocationRelativeTo(owner);
417 	}
418 
419 	private AudioFormat audioFormat;
420 	private float[] sampleRates = { 5512.0F, 11025.0F, 22050.0F, 44100.0F };
421 	private DefaultComboBoxModel<String> soundLineComboBoxModel;
422 	private JLabel imageFormatLabel;
423 	private JTextField imageFormatTextField;
424 	private JCheckBox mouseCheckBox;
425 	private JCheckBox playCheckBox;
426 	private JCheckBox loopCheckBox;
427 	private JLabel encoderLabel;
428 
selectSoundSource()429 	private void selectSoundSource() {
430 		audioFormat = new AudioFormat(
431 				sampleRates[sampleRateComboBox.getSelectedIndex()],
432 				sampleSize8Button.isSelected() ? 8 : 16,
433 				stereoCheckBox.isSelected() ? 2 : 1, true, false);
434 
435 		String sourceName = (String) soundLineComboBox.getSelectedItem();
436 
437 		if (soundLineComboBoxModel == null) {
438 			soundLineComboBoxModel = new DefaultComboBoxModel<String>();
439 			soundLineComboBox.setModel(soundLineComboBoxModel);
440 		} else {
441 			soundLineComboBoxModel.removeAllElements();
442 		}
443 
444 		DataLine.Info info = new DataLine.Info(TargetDataLine.class, audioFormat);
445 
446 		boolean hasSourceName = false;
447 		for (Mixer.Info mi : AudioSystem.getMixerInfo()) {
448 			Mixer mx = AudioSystem.getMixer(mi);
449 			if (mx.isLineSupported(info)) {
450 				soundLineComboBoxModel.addElement(mi.getName());
451 				if (sourceName!=null && mi.getName().equals(sourceName)) {
452 					hasSourceName = true;
453 				}
454 			}
455 		}
456 
457 		if (hasSourceName) {
458 			soundLineComboBoxModel.setSelectedItem(sourceName);
459 		}
460 	}
461 
getSampleSizeButtonGroup()462 	private ButtonGroup getSampleSizeButtonGroup() {
463 		if (sampleSizeButtonGroup == null) {
464 			sampleSizeButtonGroup = new ButtonGroup();
465 		}
466 		return sampleSizeButtonGroup;
467 	}
468 
getFpsLabel()469 	private JLabel getFpsLabel() {
470 		if (fpsLabel == null) {
471 			fpsLabel = new JLabel();
472 			fpsLabel.setText("Frames Per Second");
473 		}
474 		return fpsLabel;
475 	}
476 
getFpsTextField()477 	private JTextField getFpsTextField() {
478 		if (fpsTextField == null) {
479 			fpsTextField = new JTextField();
480 			fpsTextField.setText("10");
481 			fpsTextField.setSize(30, 23);
482 		}
483 		return fpsTextField;
484 	}
485 
getImageFormatLabel()486 	private JLabel getImageFormatLabel() {
487 		if (imageFormatLabel == null) {
488 			imageFormatLabel = new JLabel();
489 			imageFormatLabel.setText("Image format");
490 		}
491 		return imageFormatLabel;
492 	}
493 
getImageFormatTextField()494 	private JTextField getImageFormatTextField() {
495 		if (imageFormatTextField == null) {
496 			imageFormatTextField = new JTextField();
497 			imageFormatTextField.setText("png");
498 			imageFormatTextField.setSize(30, 23);
499 		}
500 		return imageFormatTextField;
501 	}
502 
getEncoderLabel()503 	private JLabel getEncoderLabel() {
504 		if (encoderLabel == null) {
505 			encoderLabel = new JLabel();
506 			encoderLabel.setText("Video format");
507 		}
508 		return encoderLabel;
509 	}
510 
getEncoderComboBox()511 	private JComboBox<VideoEncoder> getEncoderComboBox() {
512 		if (encodersComboBox == null) {
513 			List<VideoEncoder> el = ((CaptureFrame) getOwner()).getCaptureConfig().getEncoders();
514 			encodersComboBox = new JComboBox<VideoEncoder>(el.toArray(new VideoEncoder[el.size()]));
515 //			encodersComboBox.setSize(30, 23);
516 		}
517 		return encodersComboBox;
518 	}
519 
getScreenScalingLabel()520 	private JLabel getScreenScalingLabel() {
521 		if (screenScalingLabel == null) {
522 			screenScalingLabel = new JLabel();
523 			screenScalingLabel.setText("Graphics");
524 		}
525 		return screenScalingLabel;
526 	}
527 
getTimelineScalingLabel()528 	private JLabel getTimelineScalingLabel() {
529 		if (timelineScalingLabel == null) {
530 			timelineScalingLabel = new JLabel();
531 			timelineScalingLabel.setText("Speed");
532 		}
533 		return timelineScalingLabel;
534 	}
535 
getScreenScaleTextField()536 	private JTextField getScreenScaleTextField() {
537 		if (screenScaleTextField == null) {
538 			screenScaleTextField = new JTextField();
539 			screenScaleTextField.setText("100");
540 		}
541 		return screenScaleTextField;
542 	}
543 
getTimeLineScaleTextField()544 	private JTextField getTimeLineScaleTextField() {
545 		if (timeLineScaleTextField == null) {
546 			timeLineScaleTextField = new JTextField();
547 			timeLineScaleTextField.setText("100");
548 		}
549 		return timeLineScaleTextField;
550 	}
551 
getVideoBorderCheckBox()552 	private JCheckBox getVideoBorderCheckBox() {
553 		if (videoBorderCheckBox == null) {
554 			videoBorderCheckBox = new JCheckBox();
555 			videoBorderCheckBox.setText("Border");
556 		}
557 		return videoBorderCheckBox;
558 	}
559 
getMouseCheckBox()560 	private JCheckBox getMouseCheckBox() {
561 		if (mouseCheckBox == null) {
562 			mouseCheckBox = new JCheckBox();
563 			mouseCheckBox.setText("Mouse");
564 		}
565 		return mouseCheckBox;
566 	}
567 
getLoopCheckBox()568 	private JCheckBox getLoopCheckBox() {
569 		if (loopCheckBox == null) {
570 			loopCheckBox = new JCheckBox();
571 			loopCheckBox.setText("Loop");
572 		}
573 		return loopCheckBox;
574 	}
575 
getPlayCheckBox()576 	private JCheckBox getPlayCheckBox() {
577 		if (playCheckBox == null) {
578 			playCheckBox = new JCheckBox();
579 			playCheckBox.setText("Play");
580 		}
581 		return playCheckBox;
582 	}
583 
getJToobarCheckBox()584 	private JCheckBox getJToobarCheckBox() {
585 		if (toobarCheckBox == null) {
586 			toobarCheckBox = new JCheckBox();
587 			toobarCheckBox.setText("Toolbar");
588 			toobarCheckBox.setSelected(true);
589 		}
590 		return toobarCheckBox;
591 	}
592 
onSetSound()593 	void onSetSound() {
594 		for (Component child : recordSoundCheckBox.getParent().getComponents()) {
595 			if (child != recordSoundCheckBox) {
596 				child.setEnabled(recordSoundCheckBox.isSelected());
597 			}
598 		}
599 		inactivityPanel.setEnabled(!recordSoundCheckBox.isSelected());
600 		timeLineScaleTextField.setEnabled(!recordSoundCheckBox.isSelected());
601 		for (Component child : inactivityPanel.getComponents()) {
602 			child.setEnabled(!recordSoundCheckBox.isSelected());
603 		}
604 	}
605 
606 }
607