1 /*****************************************************************************
2 * Virtual Mockup for Machine Vision
3 * Copyright (C) 2001-2003 Fabio R. de Miranda, João E. Kogler Jr.,
4 * Carlos S. Santos.
5 * Virtual Mockup for Machine Vision Project funded by SENAC-SP
6 *
7 * Permission is granted to redistribute and/or modify this
8 * software under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License (http://www.gnu.org/copyleft/lesser.html)
16 * for more details.
17 *
18 *****************************************************************************/
19
20 package camera3d;
21
22 import camera3d.test.NodeTester;
23 import java.io.*;
24 import javax.swing.*;
25 import java.awt.*;
26
27 /***
28 * This class is a Bean that can be exported as an ActiveX control
29 * @author Fábio de Miranda
30 * @version 1.0
31 */
32 public class VirtualCamera extends JPanel implements Serializable {
33
34 transient camera3d.VcApplication vcApplication;
35 transient camera3d.GUIControl guiControl;
36
37 private boolean initialized = false;
38
39 //for testing only
40 //transient camera3d.test.NodeTester tester;
41
42 JLabel jLabel1 = new JLabel();
43 BorderLayout borderLayout1 = new BorderLayout();
44 //PrintWriter printWriter;
45
46 /* For debugging*/
47 //JFrame frame = new JFrame();
48 //JTextArea logText = new JTextArea();
49
50 public VirtualCamera() {
51 /*
52 try{
53 File logFile = new File("D:/Users/csantos/VClogfile.txt");
54 FileOutputStream fos = new FileOutputStream(logFile);
55 printWriter = new PrintWriter(fos,true);
56 printWriter.print("Log of execution as ActiveX control: "+System.currentTimeMillis()+"\n");
57 }catch(IOException ioe){
58 ioe.printStackTrace();
59 System.exit(0);
60 }*/
61 try {
62 jbInit();
63 }
64 catch(Exception e) {
65 e.printStackTrace();
66 }
67 }
68
69 /*
70 public void runTester(){
71 tester = new NodeTester();
72 }*/
73
74 public int initialize1(int lookAndFeel, int internalFrames){
75 //printWriter.print("initialize1\n");
76 //logText.append("initialize1: "+lookAndFeel+" "+internalFrames);
77 System.out.println("initialize: "+lookAndFeel+" "+internalFrames);
78 if (internalFrames ==0){
79 GUIControl.viewportsInJInternalFrames = false;
80 } else {
81 GUIControl.viewportsInJInternalFrames = true;
82 }
83 initialize(lookAndFeel);
84 return 0;
85 }
86
87 public void initialize0(){
88 this.initialize1(1,1);
89 }
90
91 public void initialize(int lookAndFeel){
92 if(!initialized){
93 initialized = true;
94 switch (lookAndFeel){
95 case 0:
96 try {
97 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
98 }
99 catch(Exception e) {
100 e.printStackTrace();
101 }
102 break;
103 case 1:
104 try {
105 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
106 }
107 catch(Exception e) {
108 e.printStackTrace();
109 }
110 break;
111 default:
112 try {
113 UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
114 }
115 catch(Exception e) {
116 e.printStackTrace();
117 }
118 break;
119 }
120 jLabel1.setText("Please wait");
121 try{
122 /*
123 printWriter.println("Trying to create VcApplication");
124 printWriter.flush();
125 logText.append("Trying to create VcApplication\n");
126 */
127 vcApplication = new VcApplication();
128 if(vcApplication!=null){
129 vcApplication.setBeanMode(true);
130 this.guiControl = vcApplication.getGUIControl();
131 jLabel1.setText("Virtual Camera");
132 }
133 }catch(Exception e){
134 e.printStackTrace();
135 jLabel1.setText(e.getCause()+"[...]"+e.getStackTrace()+"[...]Could not initialize VcApplication");
136 //printWriter.println("Initialization failed");
137 //logText.append("Initialization failed\n");
138 //e.printStackTrace(printWriter);
139 //printWriter.flush();
140 }
141 }
142 }
143
144 private void jbInit() throws Exception {
145 jLabel1.setText("Virtual Camera");
146 this.setLayout(borderLayout1);
147 this.setBorder(BorderFactory.createEtchedBorder());
148 this.setMaximumSize(new Dimension(100, 20));
149 this.setMinimumSize(new Dimension(100, 20));
150 this.setPreferredSize(new Dimension(100, 20));
151 this.add(jLabel1, BorderLayout.CENTER);
152
153 /*for debugging */
154 /*
155 logText.append("creating Virtual Camera\n");
156 frame.getContentPane().add(logText);
157 frame.setTitle("Virtual Camera log");
158 frame.setSize(256,300);
159 frame.setVisible(true);
160 */
161 }
162
163 public void close(){
164 if(vcApplication!=null){
165 vcApplication.close();
166 }
167 //printWriter.flush();
168 //printWriter.close();
169 //guiControl = null;
170 //vcApplication = null;
171 //System.exit(0);
172 }
173
174 public void loadFile(String s){
175 guiControl.loadFile(s);
176 }
177
178 public void addViewport(){
179 guiControl.addViewport();
180 }
181
182 /*
183 * Adds a view with specified name
184 */
185 public void addView(String s){
186 guiControl.addView(s);
187 }
188
189
190
191 /*
192 * Adds a viewport representing the specified view
193 */
194 public void addViewport1(String view){
195 guiControl.addViewport(view);
196 }
197
198 /*
199 * Finds the viewport called viewportName and sets it to display the view called
200 * view
201 */
202 public void changeViewInViewport(String viewportName, String view){
203 guiControl.changeViewInViewport(viewportName, view);
204 }
205
206 public void renameVcObject(String oldName, String newName){
207 guiControl.renameVcObject(oldName, newName);
208 }
209
210 public void toggleHelpingGrid(){
211 guiControl.toggleHelpingGrid();
212 }
213
214 public void translateX(String mode, String object, double value){
215 guiControl.translateX(mode, object, value);
216 }
217
218 public void translateY(String mode, String object, double value){
219 guiControl.translateY(mode, object, value);
220 }
221
222 public void translateZ(String mode, String object, double value){
223 guiControl.translateZ(mode, object, value);
224 }
225
226 public void rotateX(String mode, String object, double value){
227 guiControl.rotateX(mode, object, value);
228 }
229
230 public void rotateY(String mode, String object, double value){
231 guiControl.rotateY(mode, object, value);
232 }
233
234 public void rotateZ(String mode, String object, double value){
235 guiControl.rotateZ(mode, object, value);
236 }
237
238 public void scaleX(String mode, String object, double value){
239 guiControl.scaleX(mode, object, value);
240 }
241
242 public void scaleY(String mode, String object, double value){
243 guiControl.scaleY(mode, object, value);
244 }
245
246 public void scaleZ(String mode, String object, double value){
247 guiControl.scaleZ(mode, object, value);
248 }
249
250 public void scale(String mode, String object, double value){
251 guiControl.scale(mode, object, value);
252 }
253
254 public void changeProjectionPolicy(String strView, String strPolicy){
255 guiControl.changeProjectionPolicy(strView, strPolicy);
256 }
257
258 public void changeMovementPolicy(String strView, String strPolicy){
259 guiControl.changeMovementPolicy(strView, strPolicy);
260 }
261
262 public void changeResizePolicy(String strView, String strPolicy){
263 guiControl.changeResizePolicy(strView, strPolicy);
264 }
265
266 public void setFieldOfView(String strView, double d){
267 guiControl.setFieldOfView(strView, d);
268 }
269
270 public void addLight(String type, String name){
271 guiControl.addLight(type, name);
272 //return 0;
273 }
274
275 public void changeLightColor(String light, int red, int green, int blue){
276 guiControl.changeLightColor(light, red, green, blue);
277 }
278
279 public void changeLightState(String light, int state){
280 guiControl.changeLightState(light, state);
281 }
282
283 public void changeSpotSpreadAngle(String spotName, double angle){
284 guiControl.changeSpotSpreadAngle(spotName, angle);
285 }
286
287 public void changeSpotConcentration(String spotName, double angle){
288 guiControl.changeSpotConcentration(spotName, angle);
289 }
290
291 public void takeJPGSnapshot1(String viewname, String filename){
292 guiControl.saveJPGFileSync(viewname, filename);
293 //guiControl.saveJPGFile(viewname, filename);
294 }
295
296
297 public void takeJPGSnapshot(String filename){
298 guiControl.saveJPGFileSync(filename);
299 //guiControl.saveJPGFile(filename);
300 }
301
302 public void frameObjectsInView(String view){
303 guiControl.frameObjectsInView(view);
304 }
305
306 public void lookAt(String camera, String object){
307 guiControl.lookAt(camera, object);
308 }
309
310 public void addMeasurer(){
311 guiControl.addDistanceMeasurer();
312 }
313
314 public void setMeasurerDirection(String name, int direction, String axis){
315 guiControl.setMeasurerDirection(name, direction, axis);
316 }
317
318 /* public void wait(int milliseconds){
319 guiControl.wait();
320 }
321 */
322
323 public double getMeasuredDistance(String measurer){
324 double dist = guiControl.getMeasuredDistance(measurer);
325 return dist;
326 }
327 }
This page was automatically generated by Maven