24
|
1 package myVncProxy;
|
0
|
2 //
|
|
3 // Copyright (C) 2002 Constantin Kaplinsky. All Rights Reserved.
|
|
4 //
|
|
5 // This is free software; you can redistribute it and/or modify
|
|
6 // it under the terms of the GNU General Public License as published by
|
|
7 // the Free Software Foundation; either version 2 of the License, or
|
|
8 // (at your option) any later version.
|
|
9 //
|
|
10 // This software is distributed in the hope that it will be useful,
|
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 // GNU General Public License for more details.
|
|
14 //
|
|
15 // You should have received a copy of the GNU General Public License
|
|
16 // along with this software; if not, write to the Free Software
|
|
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
|
18 // USA.
|
|
19 //
|
|
20
|
|
21 //
|
|
22 // Recording frame. It allows to control recording RFB sessions into
|
|
23 // FBS (FrameBuffer Stream) files.
|
|
24 //
|
|
25
|
|
26 import java.io.*;
|
|
27 import java.awt.*;
|
|
28 import java.awt.event.*;
|
|
29
|
|
30 class RecordingFrame extends Frame
|
|
31 implements WindowListener, ActionListener {
|
|
32
|
|
33 boolean recording;
|
|
34
|
|
35 TextField fnameField;
|
|
36 Button browseButton;
|
|
37
|
|
38 Label statusLabel;
|
|
39
|
|
40 Button recordButton, nextButton, closeButton;
|
|
41 VncViewer viewer;
|
|
42
|
|
43 //
|
|
44 // Check if current security manager allows to create a
|
|
45 // RecordingFrame object.
|
|
46 //
|
|
47
|
|
48 public static boolean checkSecurity() {
|
|
49 SecurityManager security = System.getSecurityManager();
|
|
50 if (security != null) {
|
|
51 try {
|
|
52 security.checkPropertyAccess("user.dir");
|
|
53 security.checkPropertyAccess("file.separator");
|
|
54 // Work around (rare) checkPropertyAccess bug
|
|
55 System.getProperty("user.dir");
|
|
56 } catch (SecurityException e) {
|
|
57 System.out.println("SecurityManager restricts session recording.");
|
|
58 return false;
|
|
59 }
|
|
60 }
|
|
61 return true;
|
|
62 }
|
|
63
|
|
64 //
|
|
65 // Constructor.
|
|
66 //
|
|
67
|
|
68 RecordingFrame(VncViewer v) {
|
|
69 super("TightVNC Session Recording");
|
|
70
|
|
71 viewer = v;
|
|
72
|
|
73 // Determine initial filename for next saved session.
|
|
74 // FIXME: Check SecurityManager.
|
|
75
|
|
76 String fname = nextNewFilename(System.getProperty("user.dir") +
|
|
77 System.getProperty("file.separator") +
|
|
78 "vncsession.fbs");
|
|
79
|
|
80 // Construct new panel with file name field and "Browse" button.
|
|
81
|
|
82 Panel fnamePanel = new Panel();
|
|
83 GridBagLayout fnameGridbag = new GridBagLayout();
|
|
84 fnamePanel.setLayout(fnameGridbag);
|
|
85
|
|
86 GridBagConstraints fnameConstraints = new GridBagConstraints();
|
|
87 fnameConstraints.gridwidth = GridBagConstraints.RELATIVE;
|
|
88 fnameConstraints.fill = GridBagConstraints.BOTH;
|
|
89 fnameConstraints.weightx = 4.0;
|
|
90
|
|
91 fnameField = new TextField(fname, 64);
|
|
92 fnameGridbag.setConstraints(fnameField, fnameConstraints);
|
|
93 fnamePanel.add(fnameField);
|
|
94 fnameField.addActionListener(this);
|
|
95
|
|
96 fnameConstraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
97 fnameConstraints.weightx = 1.0;
|
|
98
|
|
99 browseButton = new Button("Browse");
|
|
100 fnameGridbag.setConstraints(browseButton, fnameConstraints);
|
|
101 fnamePanel.add(browseButton);
|
|
102 browseButton.addActionListener(this);
|
|
103
|
|
104 // Construct the frame.
|
|
105
|
|
106 GridBagLayout gridbag = new GridBagLayout();
|
|
107 setLayout(gridbag);
|
|
108
|
|
109 GridBagConstraints gbc = new GridBagConstraints();
|
|
110 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
111 gbc.fill = GridBagConstraints.BOTH;
|
|
112 gbc.weighty = 1.0;
|
|
113 gbc.insets = new Insets(10, 0, 0, 0);
|
|
114
|
|
115 Label helpLabel =
|
|
116 new Label("File name to save next recorded session in:", Label.CENTER);
|
|
117 gridbag.setConstraints(helpLabel, gbc);
|
|
118 add(helpLabel);
|
|
119
|
|
120 gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
121 gbc.weighty = 0.0;
|
|
122 gbc.insets = new Insets(0, 0, 0, 0);
|
|
123
|
|
124 gridbag.setConstraints(fnamePanel, gbc);
|
|
125 add(fnamePanel);
|
|
126
|
|
127 gbc.fill = GridBagConstraints.BOTH;
|
|
128 gbc.weighty = 1.0;
|
|
129 gbc.insets = new Insets(10, 0, 10, 0);
|
|
130
|
|
131 statusLabel = new Label("", Label.CENTER);
|
|
132 gridbag.setConstraints(statusLabel, gbc);
|
|
133 add(statusLabel);
|
|
134
|
|
135 gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
136 gbc.weightx = 1.0;
|
|
137 gbc.weighty = 0.0;
|
|
138 gbc.gridwidth = 1;
|
|
139 gbc.insets = new Insets(0, 0, 0, 0);
|
|
140
|
|
141 recordButton = new Button("Record");
|
|
142 gridbag.setConstraints(recordButton, gbc);
|
|
143 add(recordButton);
|
|
144 recordButton.addActionListener(this);
|
|
145
|
|
146 nextButton = new Button("Next file");
|
|
147 gridbag.setConstraints(nextButton, gbc);
|
|
148 add(nextButton);
|
|
149 nextButton.addActionListener(this);
|
|
150
|
|
151 closeButton = new Button("Close");
|
|
152 gridbag.setConstraints(closeButton, gbc);
|
|
153 add(closeButton);
|
|
154 closeButton.addActionListener(this);
|
|
155
|
|
156 // Set correct text, font and color for the statusLabel.
|
|
157 stopRecording();
|
|
158
|
|
159 pack();
|
|
160
|
|
161 addWindowListener(this);
|
|
162 }
|
|
163
|
|
164 //
|
|
165 // If the given string ends with ".NNN" where NNN is a decimal
|
|
166 // number, increase this number by one. Otherwise, append ".001"
|
|
167 // to the given string.
|
|
168 //
|
|
169
|
|
170 protected String nextFilename(String fname) {
|
|
171 int len = fname.length();
|
|
172 int suffixPos = len;
|
|
173 int suffixNum = 1;
|
|
174
|
|
175 if (len > 4 && fname.charAt(len - 4) == '.') {
|
|
176 try {
|
|
177 suffixNum = Integer.parseInt(fname.substring(len - 3, len)) + 1;
|
|
178 suffixPos = len - 4;
|
|
179 } catch (NumberFormatException e) { }
|
|
180 }
|
|
181
|
|
182 char[] zeroes = {'0', '0', '0'};
|
|
183 String suffix = String.valueOf(suffixNum);
|
|
184 if (suffix.length() < 3) {
|
|
185 suffix = new String(zeroes, 0, 3 - suffix.length()) + suffix;
|
|
186 }
|
|
187
|
|
188 return fname.substring(0, suffixPos) + '.' + suffix;
|
|
189 }
|
|
190
|
|
191 //
|
|
192 // Find next name of a file which does not exist yet.
|
|
193 //
|
|
194
|
|
195 protected String nextNewFilename(String fname) {
|
|
196 String newName = fname;
|
|
197 File f;
|
|
198 try {
|
|
199 do {
|
|
200 newName = nextFilename(newName);
|
|
201 f = new File(newName);
|
|
202 } while (f.exists());
|
|
203 } catch (SecurityException e) { }
|
|
204
|
|
205 return newName;
|
|
206 }
|
|
207
|
|
208 //
|
|
209 // Let the user choose a file name showing a FileDialog.
|
|
210 //
|
|
211
|
|
212 protected boolean browseFile() {
|
|
213 File currentFile = new File(fnameField.getText());
|
|
214
|
|
215 FileDialog fd =
|
|
216 new FileDialog(this, "Save next session as...", FileDialog.SAVE);
|
|
217 fd.setDirectory(currentFile.getParent());
|
|
218 fd.setVisible(true);
|
|
219 if (fd.getFile() != null) {
|
|
220 String newDir = fd.getDirectory();
|
|
221 String sep = System.getProperty("file.separator");
|
|
222 if (newDir.length() > 0) {
|
|
223 if (!sep.equals(newDir.substring(newDir.length() - sep.length())))
|
|
224 newDir += sep;
|
|
225 }
|
|
226 String newFname = newDir + fd.getFile();
|
|
227 if (newFname.equals(fnameField.getText())) {
|
|
228 fnameField.setText(newFname);
|
|
229 return true;
|
|
230 }
|
|
231 }
|
|
232 return false;
|
|
233 }
|
|
234
|
|
235 //
|
|
236 // Start recording.
|
|
237 //
|
|
238
|
|
239 public void startRecording() {
|
|
240 statusLabel.setText("Status: Recording...");
|
|
241 statusLabel.setFont(new Font("Helvetica", Font.BOLD, 12));
|
|
242 statusLabel.setForeground(Color.red);
|
|
243 recordButton.setLabel("Stop recording");
|
|
244
|
|
245 recording = true;
|
|
246
|
|
247 viewer.setRecordingStatus(fnameField.getText());
|
|
248 }
|
|
249
|
|
250 //
|
|
251 // Stop recording.
|
|
252 //
|
|
253
|
|
254 public void stopRecording() {
|
|
255 statusLabel.setText("Status: Not recording.");
|
|
256 statusLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
|
257 statusLabel.setForeground(Color.black);
|
|
258 recordButton.setLabel("Record");
|
|
259
|
|
260 recording = false;
|
|
261
|
|
262 viewer.setRecordingStatus(null);
|
|
263 }
|
|
264
|
|
265 //
|
|
266 // Close our window properly.
|
|
267 //
|
|
268
|
|
269 public void windowClosing(WindowEvent evt) {
|
|
270 setVisible(false);
|
|
271 }
|
|
272
|
|
273 //
|
|
274 // Ignore window events we're not interested in.
|
|
275 //
|
|
276
|
|
277 public void windowActivated(WindowEvent evt) {}
|
|
278 public void windowDeactivated (WindowEvent evt) {}
|
|
279 public void windowOpened(WindowEvent evt) {}
|
|
280 public void windowClosed(WindowEvent evt) {}
|
|
281 public void windowIconified(WindowEvent evt) {}
|
|
282 public void windowDeiconified(WindowEvent evt) {}
|
|
283
|
|
284
|
|
285 //
|
|
286 // Respond to button presses
|
|
287 //
|
|
288
|
|
289 public void actionPerformed(ActionEvent evt) {
|
|
290 if (evt.getSource() == browseButton) {
|
|
291 if (browseFile() && recording)
|
|
292 startRecording();
|
|
293
|
|
294 } else if (evt.getSource() == recordButton) {
|
|
295 if (!recording) {
|
|
296 startRecording();
|
|
297 } else {
|
|
298 stopRecording();
|
|
299 fnameField.setText(nextNewFilename(fnameField.getText()));
|
|
300 }
|
|
301
|
|
302 } else if (evt.getSource() == nextButton) {
|
|
303 fnameField.setText(nextNewFilename(fnameField.getText()));
|
|
304 if (recording)
|
|
305 startRecording();
|
|
306
|
|
307 } else if (evt.getSource() == closeButton) {
|
|
308 setVisible(false);
|
|
309
|
|
310 }
|
|
311 }
|
|
312 }
|