Changeset 30738 in osm for applications/editors/josm/plugins/tracer2/src/org
- Timestamp:
- 2014-10-19T01:27:04+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tracer2/src/org/openstreetmap/josm/plugins/tracer2/preferences/ServerParamList.java
r30737 r30738 1 1 /** 2 2 * Tracer2 - plug-in for JOSM to capture contours 3 * 3 * 4 4 * This program is free software; you can redistribute it and/or modify 5 5 * it under the terms of the GNU General Public License as published by 6 6 * the Free Software Foundation; either version 2 of the License, or 7 7 * (at your option) any later version. 8 * 8 * 9 9 * This program is distributed in the hope that it will be useful, 10 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 12 * GNU General Public License for more details. 13 * 13 * 14 14 * You should have received a copy of the GNU General Public License along 15 15 * with this program; if not, write to the Free Software Foundation, Inc., … … 28 28 import java.util.List; 29 29 30 import org.openstreetmap.josm.Main; 31 30 32 public class ServerParamList { 31 33 ArrayList<ServerParam> m_listServerParam = new ArrayList<>(); 32 34 ServerParam m_oActivParam = null; 33 35 String m_strFilename; 34 36 35 37 public ServerParamList(String filename) { 36 38 this.m_strFilename = filename; … … 41 43 } 42 44 } 43 45 44 46 public void load() { 45 try { 46 BufferedReader oReader = new BufferedReader(new InputStreamReader(new FileInputStream(m_strFilename), "UTF-8")); 47 try (BufferedReader oReader = new BufferedReader(new InputStreamReader(new FileInputStream(m_strFilename), "UTF-8"))) { 47 48 StringBuilder oBuilder = new StringBuilder(); 48 49 String strLine; … … 54 55 } 55 56 } 56 oReader.close();57 57 } catch (Exception e) { 58 58 loadDefault(); 59 59 } 60 60 } 61 61 62 62 public void loadDefault() { 63 try {63 try ( 64 64 InputStream oIP = getClass().getResourceAsStream("/resources/serverParam.cfg"); 65 65 BufferedReader oReader = new BufferedReader(new InputStreamReader(oIP)); 66 ) { 66 67 StringBuilder oBuilder = new StringBuilder(); 67 68 String strLine; … … 73 74 } 74 75 } 75 oReader.close();76 76 } catch (Exception e) { 77 System.err.println("Tracer2 warning: can't load file " + m_strFilename); 78 //e.printStackTrace(); 77 Main.warn("Tracer2 warning: can't load file " + m_strFilename); 79 78 } 80 79 } 81 80 82 81 public void save() { 83 try { 84 OutputStreamWriter oWriter = new OutputStreamWriter(new FileOutputStream(m_strFilename), "UTF-8"); 82 try (OutputStreamWriter oWriter = new OutputStreamWriter(new FileOutputStream(m_strFilename), "UTF-8")) { 85 83 for (ServerParam param : m_listServerParam) { 86 84 oWriter.write(param.serialize()); 87 85 } 88 oWriter.close();89 86 } catch (Exception e) { 90 System.err.println("Tracer2 warning: can't save file " + m_strFilename); 91 //e.printStackTrace(); 87 Main.warn("Tracer2 warning: can't save file " + m_strFilename); 92 88 } 93 89 } 94 90 95 91 public List<ServerParam> getParamList() { 96 92 return m_listServerParam; 97 93 } 98 94 99 95 public ServerParam getActivParam() { 100 96 return m_oActivParam; … … 105 101 } 106 102 } 107 103 108 104 public List<ServerParam> getEnableParamList() { 109 105 List<ServerParam> listParam = new ArrayList<>(); … … 115 111 return listParam; 116 112 } 117 113 118 114 public void addParam(ServerParam param) { 119 115 m_listServerParam.add(param); 120 116 } 121 117 122 118 public void removeParam(ServerParam param) { 123 119 param.setEnabled(false); 124 120 m_listServerParam.remove(param); 125 121 } 126 127 122 }
Note:
See TracChangeset
for help on using the changeset viewer.