Changeset 32637 in osm for applications/editors/josm/plugins/indoorhelper/src/org
- Timestamp:
- 2016-07-11T22:48:15+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/indoorhelper/src/org/openstreetmap/josm/plugins/indoorhelper/IndoorHelperPlugin.java
r32122 r32637 37 37 * 38 38 */ 39 public class IndoorHelperPlugin extends Plugin{ 39 public class IndoorHelperPlugin extends Plugin { 40 40 41 41 42 43 44 42 @SuppressWarnings("unused") 43 private IndoorHelperController controller; 44 String sep = System.getProperty("file.separator"); 45 45 46 /** 47 * Constructor for the plug-in. 48 * 49 * Exports the needed files and adds them to the settings. 50 * 51 * @param info general information about the plug-in 52 * @throws Exception 53 */ 54 public IndoorHelperPlugin(PluginInformation info) throws Exception { 55 super(info); 46 /** 47 * Constructor for the plug-in. 48 * 49 * Exports the needed files and adds them to the settings. 50 * 51 * @param info general information about the plug-in 52 */ 53 public IndoorHelperPlugin(PluginInformation info) throws Exception { 54 super(info); 56 55 57 this.exportValidator("/data/indoorhelper.validator.mapcss"); 58 this.exportStyleFile("indoor.mapcss"); 59 this.exportStyleFile("entrance_door_icon.png"); 60 this.exportStyleFile("entrance_icon.png"); 61 // this.setIndoorValidator(); 62 63 } 56 this.exportValidator("/data/indoorhelper.validator.mapcss"); 57 this.exportStyleFile("indoor.mapcss"); 58 this.exportStyleFile("entrance_door_icon.png"); 59 this.exportStyleFile("entrance_icon.png"); 60 // this.setIndoorValidator(); 61 } 62 63 /** 64 * Secures that the plug-in is only loaded, if a new MapFrame is created. 65 */ 66 @Override 67 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 68 super.mapFrameInitialized(oldFrame, newFrame); 69 70 if (oldFrame == null && newFrame != null) { 71 controller = new IndoorHelperController(); 72 } 73 } 74 75 /** 76 * Exports the mapcss validator file to the preferences directory. 77 */ 78 private void exportValidator(String resourceName) throws Exception { 79 InputStream stream = null; 80 OutputStream resStreamOut = null; 64 81 65 82 66 /** 67 * Secures that the plug-in is only loaded, if a new MapFrame is created. 68 */ 69 @Override 70 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 71 super.mapFrameInitialized(oldFrame, newFrame); 83 try { 84 stream = IndoorHelperPlugin.class.getResourceAsStream(resourceName); 85 if (stream == null) { 86 System.out.println("Validator: stream is null"); 87 throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); 88 } 72 89 73 if( oldFrame == null && newFrame != null ) { 74 controller = new IndoorHelperController();75 } 90 String outPath; 91 int readBytes; 92 byte[] buffer = new byte[4096]; 76 93 77 } 94 String valDirPath = Main.pref.getUserDataDirectory() + sep + "validator"; 95 File valDir = new File(valDirPath); 96 valDir.mkdirs(); 97 outPath = valDir.getAbsolutePath() +sep+ "indoorhelper.validator.mapcss"; 98 System.out.println("Validator:"+outPath); 78 99 79 80 /** 81 * Exports the mapcss validator file to the preferences directory. 82 * 83 * @param resourceName 84 * @throws Exception 85 */ 86 private void exportValidator(String resourceName) throws Exception { 87 InputStream stream = null; 88 OutputStream resStreamOut = null; 100 resStreamOut = new FileOutputStream(outPath); 101 while ((readBytes = stream.read(buffer)) > 0) { 102 resStreamOut.write(buffer, 0, readBytes); 103 } 104 resStreamOut.close(); 105 } catch (Exception ex) { 106 throw ex; 107 } finally { 108 stream.close(); 109 } 110 } 89 111 112 /** 113 * Exports the mapCSS file to the preferences directory. 114 */ 115 private void exportStyleFile(String resourceName) throws Exception { 116 InputStream stream = null; 117 OutputStream resStreamOut = null; 90 118 91 92 93 if(stream == null) {94 Validator: stream is null");95 96 119 try { 120 stream = IndoorHelperPlugin.class.getResourceAsStream("/data/" + resourceName); 121 if (stream == null) { 122 System.out.println("MapPaint: stream is null"); 123 throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); 124 } 97 125 98 99 100 126 String outPath; 127 int readBytes; 128 byte[] buffer = new byte[4096]; 101 129 102 validator";103 104 105 "indoorhelper.validator.mapcss";106 Validator:"+outPath);130 String valDirPath = Main.pref.getUserDataDirectory() + sep + "styles"; 131 File valDir = new File(valDirPath); 132 valDir.mkdirs(); 133 outPath = valDir.getAbsolutePath() +sep+ resourceName; 134 System.out.println("MapPaint"+outPath); 107 135 108 resStreamOut = new FileOutputStream(outPath); 109 while ((readBytes = stream.read(buffer)) > 0) { 110 resStreamOut.write(buffer, 0, readBytes); 111 } 112 resStreamOut.close(); 113 } catch (Exception ex) { 114 throw ex; 115 } finally { 116 stream.close(); 117 } 118 } 119 120 /** 121 * Exports the mapCSS file to the preferences directory. 122 * 123 * @param resourceName 124 * @throws Exception 125 */ 126 private void exportStyleFile(String resourceName) throws Exception { 127 InputStream stream = null; 128 OutputStream resStreamOut = null; 129 130 131 try { 132 stream = IndoorHelperPlugin.class.getResourceAsStream("/data/" + resourceName); 133 if(stream == null) { 134 System.out.println("MapPaint: stream is null"); 135 throw new Exception("Cannot get resource \"" + resourceName + "\" from Jar file."); 136 } 137 138 String outPath; 139 int readBytes; 140 byte[] buffer = new byte[4096]; 141 142 String valDirPath = Main.pref.getUserDataDirectory() + sep + "styles"; 143 File valDir = new File(valDirPath); 144 valDir.mkdirs(); 145 outPath = valDir.getAbsolutePath() +sep+ resourceName; 146 System.out.println("MapPaint"+outPath); 147 148 resStreamOut = new FileOutputStream(outPath); 149 while ((readBytes = stream.read(buffer)) > 0) { 150 resStreamOut.write(buffer, 0, readBytes); 151 } 152 resStreamOut.close(); 153 } catch (Exception ex) { 154 throw ex; 155 } finally { 156 stream.close(); 157 } 158 } 159 160 /** 161 * Writes the indoor validator file in the user preferences if it isn't there 162 * and activates it. 163 */ 164 // private void setIndoorValidator(){ 165 // //get the current validator settings 166 // Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 167 // MapListSetting mapListSetting = (MapListSetting) settings. 168 // get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 169 // List<Map<String, String>> validatorMaps; 170 // if(mapListSetting!=null){ 171 // validatorMaps = mapListSetting.getValue(); 172 // } else{ 173 // validatorMaps = new ArrayList<>(); 174 // } 175 // boolean validatorExists = false; 136 resStreamOut = new FileOutputStream(outPath); 137 while ((readBytes = stream.read(buffer)) > 0) { 138 resStreamOut.write(buffer, 0, readBytes); 139 } 140 resStreamOut.close(); 141 } catch (Exception ex) { 142 throw ex; 143 } finally { 144 stream.close(); 145 } 146 } 147 148 /** 149 * Writes the indoor validator file in the user preferences if it isn't there 150 * and activates it. 151 */ 152 // private void setIndoorValidator() { 153 // //get the current validator settings 154 // Map<String, Setting<?>> settings = Main.pref.getAllSettings(); 155 // MapListSetting mapListSetting = (MapListSetting) settings. 156 // get("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries"); 157 // List<Map<String, String>> validatorMaps; 158 // if (mapListSetting != null) { 159 // validatorMaps = mapListSetting.getValue(); 160 // } else { 161 // validatorMaps = new ArrayList<>(); 162 // } 163 // boolean validatorExists = false; 176 164 // 177 // 178 // for(Map<String, String> map : validatorMaps){179 // if(map.containsValue("Indoor")){180 // 181 // 182 // 165 // //check if indoor validator is already set 166 // for (Map<String, String> map : validatorMaps) { 167 // if (map.containsValue("Indoor")) { 168 // validatorExists = true; 169 // } 170 // } 183 171 // 184 // 185 // if(!validatorExists){186 // 187 // if(!validatorMaps.isEmpty()){188 // 189 // 190 // 191 // 192 // 193 // 194 // 172 // //put it in the settings if not 173 // if (!validatorExists) { 174 // List<Map<String, String>> validatorMapsNew = new ArrayList<>(); 175 // if (!validatorMaps.isEmpty()) { 176 // validatorMapsNew.addAll(validatorMaps); 177 // } 178 // Map<String, String> indoorValidator = new HashMap<>(); 179 // indoorValidator.put("title", "Indoor"); 180 // indoorValidator.put("active", "true"); 181 // indoorValidator.put("url", Main.pref.getUserDataDirectory()+ sep +"validator" + 182 // sep + "indoorhelper.validator.mapcss"); 195 183 // 196 // validatorMapsNew.add(indoorValidator); 197 // Main.pref.putListOfStructs 198 // ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 199 // validatorMapsNew); 200 // } 201 // } 202 203 184 // validatorMapsNew.add(indoorValidator); 185 // Main.pref.putListOfStructs 186 // ("validator.org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.entries", 187 // validatorMapsNew); 188 // } 189 // } 204 190 }
Note:
See TracChangeset
for help on using the changeset viewer.