Math2mat
|
00001 00020 package m2m.backend.project; 00021 00022 import java.io.File; 00023 00024 00025 public class ProjectProperties { 00026 00030 private File file; 00034 private String path; 00035 00039 private String relativeSourceFileName; 00040 00044 private OptimisationProperties optimisationProperties; 00048 private SimulationProperties simulationProperties; 00049 00050 00051 public void setProjectFile(File file) { 00052 this.file = file; 00053 this.path = file.getAbsolutePath().replace("\\", "/").substring(0, file.getAbsolutePath().replace("\\", "/").lastIndexOf("/") + 1); 00054 } 00055 00056 public File getProjectFile() { 00057 return file; 00058 } 00059 00060 public String getProjectPath() { 00061 return path; 00062 } 00063 00064 public String getFunctionName() { 00065 return file.getName().substring(0, file.getName().length()-4); 00066 } 00067 00068 00069 00074 /* 00075 public void setPath(File file) { 00076 String sourceFile = new String(); 00077 try { 00078 sourceFile= this.getSourceFile().getCanonicalPath(); 00079 } catch (IOException e) { 00080 e.printStackTrace(); 00081 } 00082 this.path = file.getAbsolutePath().replace("\\", "/").substring(0, file.getAbsolutePath().replace("\\", "/").lastIndexOf("/") + 1); 00083 setSourceFile(new File(sourceFile)); 00084 } 00085 */ 00086 00091 /* 00092 public void setPath(String path) { 00093 String sourceFile = new String(); 00094 try { 00095 sourceFile= this.getSourceFile().getCanonicalPath(); 00096 } catch (IOException e) { 00097 e.printStackTrace(); 00098 } 00099 this.path = path; 00100 setSourceFile(new File(sourceFile)); 00101 } 00102 */ 00103 00104 00105 00111 public void setSourceFile(File file) { 00112 setSourceFilePath(getRelativePath(file.getAbsolutePath().replace("\\", "/"))); 00113 } 00114 00120 private String getRelativePath(String absolutePath) { 00121 String relativePath = new String(); 00122 String commonPath = new String(); 00123 String subPath = new String(); 00124 int index = 0; 00125 int subFolders = 0; 00126 00127 for (int i = 0; i < path.length(); i++) { 00128 if (path.charAt(i) == absolutePath.charAt(i)) { 00129 index++; 00130 commonPath += path.charAt(i); 00131 } 00132 else 00133 break; 00134 } 00135 00136 subPath = path.substring(index); 00137 00138 //count the number of sub-folders we have to go back 00139 while (subPath.indexOf("/") != -1) { 00140 subFolders++; 00141 subPath = subPath.substring(subPath.indexOf("/")+1); 00142 } 00143 00144 for (int i = 0; i < subFolders; i++) { 00145 relativePath += "../"; 00146 } 00147 00148 subPath = absolutePath.substring(index); 00149 relativePath += subPath; 00150 00151 return relativePath; 00152 } 00153 00157 public ProjectProperties() { 00158 relativeSourceFileName = null; 00159 optimisationProperties = new OptimisationProperties(); 00160 simulationProperties = new SimulationProperties(); 00161 } 00162 00170 public ProjectProperties(String sourceFilePath, OptimisationProperties optimProp, SimulationProperties simProp) { 00171 this.relativeSourceFileName = sourceFilePath; 00172 optimisationProperties = optimProp; 00173 simulationProperties = simProp; 00174 } 00175 00176 //Getters 00182 public OptimisationProperties getOptimisationProperties() { 00183 return optimisationProperties; 00184 } 00190 public SimulationProperties getSimulationProperties() { 00191 return simulationProperties; 00192 } 00197 public String getRelativeSourceFilename() { 00198 return relativeSourceFileName; 00199 } 00200 00205 public String getAbsoluteSourceFilename() { 00206 return path+relativeSourceFileName; 00207 } 00208 00209 public String getProjectShortFilename() { 00210 return file.getName(); 00211 } 00212 00213 public String getProjectFullFilename() { 00214 return file.getAbsolutePath(); 00215 } 00216 00217 //Setters 00223 public void setOptimisationProperties(OptimisationProperties optimProp) { 00224 optimisationProperties = optimProp; 00225 } 00231 public void setSimulationProperties(SimulationProperties simProp) { 00232 simulationProperties = simProp; 00233 } 00238 public void setSourceFilePath(String path) { 00239 relativeSourceFileName = path; 00240 } 00241 }