Changed due to Simulation api change.
[debian/openrocket] / android / src / net / sf / openrocket / android / CurrentRocket.java
1 package net.sf.openrocket.android;\r
2 \r
3 import java.io.File;\r
4 import java.io.IOException;\r
5 \r
6 import net.sf.openrocket.aerodynamics.WarningSet;\r
7 import net.sf.openrocket.document.OpenRocketDocument;\r
8 import net.sf.openrocket.document.Simulation;\r
9 import net.sf.openrocket.file.openrocket.OpenRocketSaver;\r
10 import net.sf.openrocket.rocketcomponent.Rocket;\r
11 import android.net.Uri;\r
12 \r
13 public class CurrentRocket {\r
14 \r
15         private Uri fileUri;\r
16 \r
17         private OpenRocketDocument rocketDocument;\r
18         private WarningSet warnings;\r
19 \r
20         private RocketChangedEventHandler handler;\r
21         \r
22         public void setHandler( RocketChangedEventHandler handler ) {\r
23                 this.handler = handler;\r
24         }\r
25         \r
26         /**\r
27          * @return the rocketDocument\r
28          */\r
29         public OpenRocketDocument getRocketDocument() {\r
30                 return rocketDocument;\r
31         }\r
32 \r
33         public void notifySimsChanged() {\r
34                 if ( handler != null ) {\r
35                         handler.simsChangedMessage();\r
36                 }\r
37         }\r
38 \r
39         public void addNewSimulation() {\r
40                 Rocket rocket = rocketDocument.getRocket();\r
41                 // FIXME - hopefully the change to the Simulation object will be reverted soon.\r
42                 Simulation newSim = new Simulation(rocketDocument, rocket);\r
43                 newSim.setName(rocketDocument.getNextSimulationName());\r
44                 rocketDocument.addSimulation(newSim);\r
45                 notifySimsChanged();\r
46         }\r
47         \r
48         public void deleteSimulation( int simulationPos ) {\r
49                 rocketDocument.removeSimulation( simulationPos );\r
50                 notifySimsChanged();\r
51         }\r
52         \r
53         public String addNewMotorConfig() {\r
54                 String configId = rocketDocument.getRocket().newMotorConfigurationID();\r
55                 if ( handler != null ) {\r
56                         handler.configsChangedMessage();\r
57                 }\r
58                 return configId;\r
59         }\r
60         /**\r
61          * @param rocketDocument the rocketDocument to set\r
62          */\r
63         public void setRocketDocument(OpenRocketDocument rocketDocument) {\r
64                 this.rocketDocument = rocketDocument;\r
65         }\r
66 \r
67         public WarningSet getWarnings() {\r
68                 return warnings;\r
69         }\r
70 \r
71         public void setWarnings(WarningSet warnings) {\r
72                 this.warnings = warnings;\r
73         }\r
74 \r
75         public Uri getFileUri() {\r
76                 return fileUri;\r
77         }\r
78 \r
79         public void setFileUri(Uri fileUri) {\r
80                 this.fileUri = fileUri;\r
81         }\r
82 \r
83         public void saveOpenRocketDocument() throws IOException {\r
84                 OpenRocketSaver saver = new OpenRocketSaver();\r
85                 saver.save(new File(fileUri.getPath()),rocketDocument);\r
86 \r
87         }\r
88 \r
89 \r
90 }\r