Changeset 17637 in osm for applications
- Timestamp:
- 2009-09-15T17:13:24+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/tageditor
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/tageditor/build.xml
r17386 r17637 89 89 <attribute name="Plugin-Description" value="Provides a dialog for editing tags in a tabular grid."/> 90 90 <attribute name="Plugin-Link" value="http://wiki.openstreetmap.org/index.php/JOSM/Plugins/TagEditor"/> 91 <attribute name="Plugin-Mainversion" value="2 012"/>91 <attribute name="Plugin-Mainversion" value="2141"/> 92 92 <attribute name="Plugin-Version" value="${version.entry.commit.revision}"/> 93 93 </manifest> -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/Group.java
r14326 r17637 14 14 import org.openstreetmap.josm.plugins.tageditor.util.IndentWriter; 15 15 16 17 16 /** 18 17 * Group represents a named group of preset items. Groups can be nested. 19 18 * 20 * @author Gubaer21 19 * 22 20 */ … … 24 22 25 23 static private Logger logger = Logger.getLogger(Group.class.getName()); 26 27 24 28 25 private String name; … … 101 98 writer.writeLine("</group>"); 102 99 } 103 104 100 } -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/Presets.java
r17386 r17637 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.io.BufferedInputStream;6 import java.io.BufferedReader;7 5 import java.io.IOException; 8 6 import java.io.InputStreamReader; … … 12 10 import java.net.URLConnection; 13 11 import java.util.ArrayList; 12 import java.util.LinkedList; 14 13 import java.util.List; 15 14 import java.util.logging.Level; … … 24 23 import org.openstreetmap.josm.plugins.tageditor.util.IndentWriter; 25 24 26 27 25 public class Presets { 28 26 private static Logger logger = Logger.getLogger(Presets.class.getName()); 29 27 30 28 private static Presets presets = null; 31 32 33 static public void initPresets() { 34 29 30 static public void initPresets() { 31 35 32 presets = new Presets(); 36 33 LinkedList<String> sources = new LinkedList<String>(); 34 37 35 // code copied from org.openstreetmap.josm.gui.tagging.TaggingPreset 38 36 // and slightly modified 39 37 // 40 41 String allTaggingPresets = Main.pref.get("taggingpreset.sources"); 38 if (Main.pref.getBoolean("taggingpreset.enable-defaults", true)) { 39 sources.add("resource://presets/presets.xml"); 40 } 41 sources.addAll(Main.pref.getCollection("taggingpreset.sources", 42 new LinkedList<String>())); 42 43 43 if (Main.pref.getBoolean("taggingpreset.enable-defaults", true)) 44 { 45 allTaggingPresets = "resource://presets/presets.xml" 46 + (allTaggingPresets != null ? ";"+allTaggingPresets : ""); 47 } 44 for (String source : sources) { 45 logger.log(Level.INFO, String.format( 46 "starting to read presets from source '%1$s'", source)); 47 try { 48 MirroredInputStream s = new MirroredInputStream(source); 49 InputStreamReader r; 50 try { 51 r = new InputStreamReader(s, "UTF-8"); 52 } catch (UnsupportedEncodingException e) { 53 r = new InputStreamReader(s); 54 } 55 presets = loadPresets(r, presets); 48 56 49 for(String source : allTaggingPresets.split(";")) 50 { 51 logger.log(Level.INFO, String.format("starting to read presets from source '%1$s'", source)); 52 try { 53 MirroredInputStream s = new MirroredInputStream(source); 54 InputStreamReader r; 55 try 56 { 57 r = new InputStreamReader(s, "UTF-8"); 58 } 59 catch (UnsupportedEncodingException e) 60 { 61 r = new InputStreamReader(s); 62 } 63 presets = loadPresets(r,presets); 64 65 } catch(PresetIOException e) { 66 logger.log(Level.SEVERE, tr("Could not read tagging preset source: {0}", source),e); 67 JOptionPane.showMessageDialog( 68 Main.parent, tr("Could not read tagging preset source: {0}",source), 69 tr("Error"), 70 JOptionPane.ERROR_MESSAGE); 71 } catch (IOException e) { 72 e.printStackTrace(); 73 JOptionPane.showMessageDialog( 74 Main.parent, 75 tr("Could not read tagging preset source: {0}",source), 76 tr("Error"), 77 JOptionPane.ERROR_MESSAGE 78 ); 79 } 80 } 57 } catch (PresetIOException e) { 58 logger 59 .log(Level.SEVERE, tr( 60 "Could not read tagging preset source: {0}", 61 source), e); 62 JOptionPane.showMessageDialog(Main.parent, tr( 63 "Could not read tagging preset source: {0}", source), 64 tr("Error"), JOptionPane.ERROR_MESSAGE); 65 } catch (IOException e) { 66 e.printStackTrace(); 67 JOptionPane.showMessageDialog(Main.parent, tr( 68 "Could not read tagging preset source: {0}", source), 69 tr("Error"), JOptionPane.ERROR_MESSAGE); 70 } 71 } 81 72 } 82 73 83 74 static public Presets loadPresets(URL from) throws PresetIOException { 84 75 try { 85 76 URLConnection con = from.openConnection(); 86 77 con.connect(); 87 Reader reader = new InputStreamReader( 88 con.getInputStream() 89 ); 90 return loadPresets(reader,null); 91 } catch(Exception e) { 92 logger.log(Level.SEVERE, "exception caught while loading preset file",e); 78 Reader reader = new InputStreamReader(con.getInputStream()); 79 return loadPresets(reader, null); 80 } catch (Exception e) { 81 logger.log(Level.SEVERE, 82 "exception caught while loading preset file", e); 93 83 throw new PresetIOException(e); 94 84 } 95 85 96 86 } 97 87 98 88 static public Presets loadPresets(Reader reader, Presets p) throws PresetIOException { 99 try{ 89 try { 100 90 Parser parser = new Parser(); 101 91 parser.setReader(reader); … … 103 93 parser.parse(); 104 94 return parser.getPresets(); 105 } catch(Exception e) { 95 } catch (Exception e) { 106 96 logger.log(Level.SEVERE, "exception caught while loading presets",e); 107 97 throw new PresetIOException(e); 108 98 } 109 99 } 110 111 112 113 100 114 101 static public Presets getPresets() { 115 102 if (presets == null) { 116 103 initPresets(); 117 104 } 118 return presets; 105 return presets; 119 106 } 120 121 107 122 108 private List<Group> groups; 123 109 124 110 public Presets() { 125 111 groups = new ArrayList<Group>(); 126 112 } 127 113 128 114 public void addGroup(Group group) { 129 115 groups.add(group); 130 116 } 131 117 132 118 public void removeGroup(Group group) { 133 119 groups.remove(group); 134 120 } 135 121 136 122 public void dump(IndentWriter writer) throws IOException { 137 123 writer.indent(); 138 124 writer.write("<presets>\n"); 139 125 writer.incLevel(); 140 for(Group group: groups) { 126 for (Group group : groups) { 141 127 group.dump(writer); 142 128 } … … 144 130 writer.indent(); 145 131 writer.write("</presets>"); 146 } 147 132 } 133 148 134 public List<Group> getGroups() { 149 135 return groups; -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/io/Parser.java
r14327 r17637 2 2 3 3 import java.io.Reader; 4 import java.util.Stack; 4 5 import java.util.logging.Level; 5 6 import java.util.logging.Logger; … … 22 23 23 24 static private Logger logger = Logger.getLogger(Parser.class.getName()); 24 25 26 private Presets presets = null; 25 private Presets presets = null; 27 26 private Reader reader; 28 private GroupcurrentGroup;27 private Stack<Group> currentGroup; 29 28 private Item currentItem; 30 29 private boolean inOptionalKeys = false; 31 30 private XMLReader parser; 32 33 31 34 32 public Parser() { 35 currentGroup = n ull;33 currentGroup = new Stack<Group>(); 36 34 currentItem = null; 37 35 } … … 52 50 return reader; 53 51 } 54 55 52 56 53 public Presets getPresets() { … … 135 132 136 133 protected void onStartGroup(String name, String iconName) { 137 currentGroup = new Group(); 138 currentGroup.setName(translatedAttributeValue(name)); 139 currentGroup.setIconName(iconName); 134 Group g = new Group(); 135 g.setName(translatedAttributeValue(name)); 136 g.setIconName(iconName); 137 currentGroup.push(g); 140 138 } 141 139 142 140 protected void onEndGroup() { 143 presets.addGroup(currentGroup);144 currentGroup = null;141 Group g = currentGroup.pop(); 142 presets.addGroup(g); 145 143 } 146 144 … … 156 154 throw new IllegalStateException("illegal state. no current group defined"); 157 155 } 158 currentGroup.addItem(currentItem); 156 currentGroup.peek().addItem(currentItem); 159 157 currentItem = null; 160 158 } … … 190 188 } 191 189 192 193 194 190 /** 195 191 * The SAX handler for reading XML files with tag specifications … … 198 194 */ 199 195 class Handler extends DefaultHandler { 200 201 196 202 197 @Override … … 205 200 } 206 201 207 208 209 202 @Override 210 203 public void error(SAXParseException e) throws SAXException { … … 222 215 } 223 216 224 225 217 protected String getAttribute(Attributes attributes, String qName) { 226 218 for (int i =0; i < attributes.getLength();i++) { … … 231 223 return null; 232 224 } 233 234 225 235 226 @Override 236 227 public void startElement(String namespaceURI, String localName, String qName, 237 228 Attributes atts) throws SAXException { 238 239 229 if ("group".equals(qName)) { 240 230 onStartGroup(getAttribute(atts, "name"), getAttribute(atts, "icon")); … … 263 253 } else if ("optional".equals(qName)) { 264 254 onEndOptionalKeys(); 265 } 266 255 } 267 256 } 268 257 … … 275 264 logger.log(Level.WARNING, "XML parsing warning", e); 276 265 } 277 278 279 280 } 281 282 283 284 285 286 287 266 } 288 267 } -
applications/editors/josm/plugins/tageditor/src/org/openstreetmap/josm/plugins/tageditor/preset/ui/PresetsTableModel.java
r15319 r17637 21 21 private Presets presets = null; 22 22 23 24 23 protected void initModelFromPresets(Presets presets) { 25 24 for(Group group: presets.getGroups()) { … … 30 29 } 31 30 } 32 33 31 34 32 public PresetsTableModel() { … … 44 42 } 45 43 46 47 48 44 public void setPresets(Presets presets) { 49 45 this.presets = presets; … … 51 47 fireTableDataChanged(); 52 48 } 53 54 55 49 56 50 @Override … … 133 127 fireTableStructureChanged(); 134 128 } 135 136 129 } 137 130 }
Note:
See TracChangeset
for help on using the changeset viewer.