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.action;
21
22
23
24 import camera3d.J3DBase;
25 import camera3d.VcObject;
26 import java.io.FileWriter;
27 import java.util.Vector;
28 import java.util.Iterator;
29
30 /***
31 * Action that creates a text file with description of objects currently present in
32 * the scene graph.
33 *
34 * @author Fábio Roberto de Miranda
35 * @version 1.0
36 */
37 public class TXTSaveAction extends GUIAction {
38
39 private String filename;
40 private VcObject obj;
41 private String desc;
42
43 /***
44 * Creates action.
45 * @param filename Name of file to be saved.
46 */
47 public TXTSaveAction( String filename) {
48 if(!filename.endsWith(".txt"))
49 this.filename = filename+".txt";
50 else this.filename = filename;
51 }
52
53 /***
54 * Creates text file. Descriptions of objects are retrieved by calling the VcObject.getInfo()
55 * method.
56 */
57 public void doAction(ActionExecutor executor) {
58 Vector objVec = executor.getJ3DBase().getObjectList();
59 Iterator iter = objVec.iterator();
60 FileWriter file;
61 try{
62 file = new FileWriter(filename);
63 while(iter.hasNext()){
64 obj = (VcObject) iter.next();
65 desc = obj.getInfo();
66 file.write(desc,0,desc.length());
67 }
68 file.flush();
69 file.close();
70 } catch(Exception e){
71 e.printStackTrace();
72 }
73 }
74 }
This page was automatically generated by Maven