If the filename doesn't end in .ork, append .ork to indicate the saved file is ork...
[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.document.StorageOptions;\r
10 import net.sf.openrocket.file.openrocket.OpenRocketSaver;\r
11 import net.sf.openrocket.rocketcomponent.Rocket;\r
12 import android.net.Uri;\r
13 \r
14 public class CurrentRocket {\r
15 \r
16         private Uri fileUri;\r
17 \r
18         private OpenRocketDocument rocketDocument;\r
19         private WarningSet warnings;\r
20 \r
21         private RocketChangedEventHandler handler;\r
22         \r
23         private boolean isModified = false;\r
24         \r
25         public void setHandler( RocketChangedEventHandler handler ) {\r
26                 this.handler = handler;\r
27         }\r
28         \r
29         /**\r
30          * @return the rocketDocument\r
31          */\r
32         public OpenRocketDocument getRocketDocument() {\r
33                 return rocketDocument;\r
34         }\r
35 \r
36         public void notifySimsChanged() {\r
37                 isModified = true;\r
38                 if ( handler != null ) {\r
39                         handler.simsChangedMessage();\r
40                 }\r
41         }\r
42 \r
43         public void addNewSimulation() {\r
44                 Rocket rocket = rocketDocument.getRocket();\r
45                 // FIXME - hopefully the change to the Simulation object will be reverted soon.\r
46                 Simulation newSim = new Simulation(rocketDocument, rocket);\r
47                 newSim.setName(rocketDocument.getNextSimulationName());\r
48                 rocketDocument.addSimulation(newSim);\r
49                 notifySimsChanged();\r
50         }\r
51         \r
52         public void deleteSimulation( int simulationPos ) {\r
53                 rocketDocument.removeSimulation( simulationPos );\r
54                 notifySimsChanged();\r
55         }\r
56         \r
57         public String addNewMotorConfig() {\r
58                 isModified = true;\r
59                 String configId = rocketDocument.getRocket().newMotorConfigurationID();\r
60                 if ( handler != null ) {\r
61                         handler.configsChangedMessage();\r
62                 }\r
63                 return configId;\r
64         }\r
65         /**\r
66          * @param rocketDocument the rocketDocument to set\r
67          */\r
68         public void setRocketDocument(OpenRocketDocument rocketDocument) {\r
69                 this.rocketDocument = rocketDocument;\r
70                 isModified = false;\r
71         }\r
72 \r
73         public WarningSet getWarnings() {\r
74                 return warnings;\r
75         }\r
76 \r
77         public void setWarnings(WarningSet warnings) {\r
78                 this.warnings = warnings;\r
79         }\r
80 \r
81         public Uri getFileUri() {\r
82                 return fileUri;\r
83         }\r
84 \r
85         public void setFileUri(Uri fileUri) {\r
86                 this.fileUri = fileUri;\r
87         }\r
88 \r
89         public boolean isModified() {\r
90                 return this.isModified;\r
91         }\r
92         \r
93         public void saveOpenRocketDocument() throws IOException {\r
94                 \r
95                 // Translate the fileUri if it happens to be a .rkt file.\r
96 \r
97                 String filename = fileUri.getPath();\r
98                 \r
99                 if ( ! filename.endsWith(".ork") ) {\r
100                         filename = filename.concat(".ork");\r
101                 }\r
102                 \r
103                 OpenRocketSaver saver = new OpenRocketSaver();\r
104                 StorageOptions options = new StorageOptions();\r
105                 options.setCompressionEnabled(true);\r
106                 options.setSimulationTimeSkip(StorageOptions.SIMULATION_DATA_ALL);\r
107                 saver.save(new File(filename),rocketDocument,options);\r
108                 isModified = false;\r
109         }\r
110 \r
111 }\r