Changeset 1628 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2009-05-30T13:58:30+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UploadAction.java
r1575 r1628 22 22 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 23 23 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 24 import org.openstreetmap.josm.gui.historycombobox.StringUtils;25 24 import org.openstreetmap.josm.gui.historycombobox.SuggestingJHistoryComboBox; 26 25 import org.openstreetmap.josm.io.OsmServerWriter; … … 38 37 */ 39 38 public class UploadAction extends JosmAction { 40 41 public static final String HISTORY_KEY = "upload.comment.history"; 39 40 public static final String HISTORY_KEY = "upload.comment.history"; 42 41 43 42 /** Upload Hook */ … … 103 102 p.add(new JScrollPane(l), GBC.eol().fill()); 104 103 } 105 104 106 105 p.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3)); 107 106 SuggestingJHistoryComboBox cmt = new SuggestingJHistoryComboBox(); 108 List<String> cmtHistory = StringUtils.stringToList(Main.pref.get(HISTORY_KEY), SuggestingJHistoryComboBox.DELIM);107 List<String> cmtHistory = new LinkedList<String>(Main.pref.getCollection(HISTORY_KEY, null)); 109 108 cmt.setHistory(cmtHistory); 110 109 //final JTextField cmt = new JTextField(lastCommitComment); … … 112 111 113 112 while(true) { 114 int result = new ExtendedDialog(Main.parent, 115 tr("Upload these changes?"), 113 int result = new ExtendedDialog(Main.parent, 114 tr("Upload these changes?"), 116 115 p, 117 new String[] {tr("Upload Changes"), tr("Cancel")}, 116 new String[] {tr("Upload Changes"), tr("Cancel")}, 118 117 new String[] {"upload.png", "cancel.png"}).getValue(); 119 118 120 119 // cancel pressed 121 120 if (result != 1) return false; 122 121 123 122 // don't allow empty commit message 124 123 if (cmt.getText().trim().length() < 3) continue; 125 124 126 125 // store the history of comments 127 126 cmt.addCurrentItemToHistory(); 128 Main.pref.put (HISTORY_KEY, StringUtils.listToString(cmt.getHistory(), SuggestingJHistoryComboBox.DELIM));129 127 Main.pref.putCollection(HISTORY_KEY, cmt.getHistory()); 128 130 129 break; 131 130 } -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r1610 r1628 7 7 import java.io.BufferedReader; 8 8 import java.io.File; 9 import java.io.File Reader;10 import java.io.File Writer;9 import java.io.FileInputStream; 10 import java.io.FileOutputStream; 11 11 import java.io.IOException; 12 import java.io.InputStreamReader; 13 import java.io.OutputStreamWriter; 12 14 import java.io.PrintWriter; 13 15 import java.util.ArrayList; … … 279 281 try { 280 282 setSystemProperties(); 281 final PrintWriter out = new PrintWriter(new FileWriter(getPreferencesDir() + "preferences"), false); 283 final PrintWriter out = new PrintWriter(new OutputStreamWriter( 284 new FileOutputStream(getPreferencesDir() + "preferences"), "utf-8"), false); 282 285 for (final Entry<String, String> e : properties.entrySet()) { 283 286 String s = defaults.get(e.getKey()); … … 296 299 public void load() throws IOException { 297 300 properties.clear(); 298 final BufferedReader in = new BufferedReader(new FileReader(getPreferencesDir()+"preferences")); 301 final BufferedReader in = new BufferedReader(new InputStreamReader( 302 new FileInputStream(getPreferencesDir()+"preferences"), "utf-8")); 299 303 int lineNumber = 0; 300 304 ArrayList<Integer> errLines = new ArrayList<Integer>(); … … 362 366 if (!bookmarkFile.exists()) 363 367 bookmarkFile.createNewFile(); 364 BufferedReader in = new BufferedReader(new FileReader(bookmarkFile)); 368 BufferedReader in = new BufferedReader(new InputStreamReader( 369 new FileInputStream(bookmarkFile), "utf-8")); 365 370 366 371 LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>(); 367 // use pattern matches to scan text, as text may contain a "," itself368 372 for (String line = in.readLine(); line != null; line = in.readLine()) { 369 Matcher m = Pattern.compile("^(.+),(-?\\d+.\\d+),(-?\\d+.\\d+),(-?\\d+.\\d+),(-?\\d+.\\d+)$").matcher(line); 373 // FIXME: legacy code using ',' sign, should be \u001e only 374 Matcher m = Pattern.compile("^(.+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)[,\u001e](-?\\d+.\\d+)$").matcher(line); 370 375 if(m.matches()) 371 376 { … … 386 391 if (!bookmarkFile.exists()) 387 392 bookmarkFile.createNewFile(); 388 PrintWriter out = new PrintWriter(new FileWriter(bookmarkFile)); 393 PrintWriter out = new PrintWriter(new OutputStreamWriter( 394 new FileOutputStream(bookmarkFile), "utf-8")); 389 395 for (Bookmark b : bookmarks) { 390 out.print(b.name+" ,");396 out.print(b.name+"\u001e"); 391 397 for (int i = 0; i < b.latlon.length; ++i) 392 out.print(b.latlon[i]+(i<b.latlon.length-1?" ,":""));398 out.print(b.latlon[i]+(i<b.latlon.length-1?"\u001e":"")); 393 399 out.println(); 394 400 } … … 491 497 { 492 498 if(d != null) 493 d += " ;" + a;499 d += "\u001e" + a; 494 500 else 495 501 d = a; … … 498 504 } 499 505 if(s != null && s.length() != 0) 500 return Arrays.asList(s.split(";")); 506 { 507 if(s.indexOf("\u001e") < 0) /* FIXME: legacy code, remove later */ 508 { 509 String r =s; 510 if(r.indexOf("§§§") > 0) /* history dialog */ 511 r = r.replaceAll("§§§","\u001e"); 512 else /* old style ';' separation */ 513 r = r.replace(';','\u001e'); 514 if(!r.equals(s)) /* save the converted string */ 515 { 516 put(key,r); 517 s = r; 518 } 519 } 520 return Arrays.asList(s.split("\u001e")); 521 } 501 522 return def; 502 523 } … … 516 537 { 517 538 if(s != null) 518 s += " ;" + a;539 s += "\u001e" + a; 519 540 else 520 541 s = a; -
trunk/src/org/openstreetmap/josm/gui/historycombobox/JHistoryComboBox.java
r1575 r1628 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 35 35 36 36 /** 37 * Extends the standard JComboBox with a history. Works with Strings only. 37 * Extends the standard JComboBox with a history. Works with Strings only. 38 38 * @author henni 39 39 * … … 41 41 public class JHistoryComboBox extends JComboBox implements ActionListener { 42 42 43 public static String DELIM = "§§§";44 45 43 protected ComboBoxHistory model; 46 44 47 45 /** 48 46 * Default constructor for GUI editors. Don't use this!!! 49 47 */ 50 48 public JHistoryComboBox() {} 51 49 52 50 /** 53 51 * @param history the history as a list of strings … … 60 58 setHistory(history); 61 59 } 62 60 63 61 public void actionPerformed(ActionEvent e) { 64 62 addCurrentItemToHistory(); … … 69 67 model.addElement(regex); 70 68 } 71 69 72 70 public void setText(String text) { 73 71 getEditor().setItem(text); 74 72 } 75 73 76 74 public String getText() { 77 75 return getEditor().getItem().toString(); 78 76 } 79 77 80 78 public void addHistoryChangedListener(HistoryChangedListener l) { 81 79 model.addHistoryChangedListener(l); 82 80 } 83 81 84 82 public void removeHistoryChangedListener(HistoryChangedListener l) { 85 83 model.removeHistoryChangedListener(l); 86 84 } 87 85 88 86 public void setHistory(List<String> history) { 89 87 model.setItems(history); 90 88 } 91 89 92 90 public List<String> getHistory() { 93 91 return model.asList(); -
trunk/src/org/openstreetmap/josm/gui/historycombobox/SuggestingJHistoryComboBox.java
r1585 r1628 1 1 /* Copyright (c) 2008, Henrik Niehaus 2 2 * All rights reserved. 3 * 3 * 4 4 * Redistribution and use in source and binary forms, with or without 5 5 * modification, are permitted provided that the following conditions are met: 6 * 6 * 7 7 * 1. Redistributions of source code must retain the above copyright notice, 8 8 * this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 9 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * this list of conditions and the following disclaimer in the documentation 11 11 * and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 12 * 3. Neither the name of the project nor the names of its 13 * contributors may be used to endorse or promote products derived from this 14 14 * software without specific prior written permission. 15 * 15 * 16 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE … … 43 43 public class SuggestingJHistoryComboBox extends JHistoryComboBox implements KeyListener { 44 44 45 46 45 private EventConsumingPlainDocument doc = new EventConsumingPlainDocument(); 46 47 47 public SuggestingJHistoryComboBox(List<String> history) { 48 48 super(history); … … 50 50 // add keylistener for ctrl + space 51 51 getEditor().getEditorComponent().addKeyListener(this); 52 52 53 53 // add specialized document, which can consume events, which are 54 54 // produced by the suggestion 55 55 ((JTextComponent)getEditor().getEditorComponent()).setDocument(doc); 56 56 57 57 // add DocumentFilter to trigger suggestion 58 58 JTextField editor = (JTextField) getEditor().getEditorComponent(); 59 59 final AbstractDocument doc = (AbstractDocument) editor.getDocument(); 60 60 doc.setDocumentFilter(new DocumentFilter() { 61 62 63 64 65 66 67 68 69 61 @Override 62 public void insertString(FilterBypass fb, int offset, 63 String string, AttributeSet attr) 64 throws BadLocationException { 65 super.insertString(fb, offset, string, attr); 66 if(doc.getLength() > 0) { 67 suggest(); 68 } 69 } 70 70 71 72 73 74 75 76 77 78 79 71 @Override 72 public void replace(FilterBypass fb, int offset, int length, 73 String text, AttributeSet attrs) 74 throws BadLocationException { 75 super.replace(fb, offset, length, text, attrs); 76 if(doc.getLength() > 0) { 77 suggest(); 78 } 79 } 80 80 }); 81 81 } … … 89 89 if(e.getSource() instanceof JTextField) { 90 90 JTextField textField = (JTextField) e.getSource(); 91 91 92 92 // if the ActionCommand equals SUGGEST, the user confirms a suggestion 93 93 if("SUGGEST".equals(e.getActionCommand())) { … … 102 102 103 103 private void suggest() { 104 105 104 JTextField textField = (JTextField) getEditor().getEditorComponent(); 105 String text = textField.getText(); 106 106 107 108 109 110 111 112 // avoid unbound recursion via setText() -> replace() -> 113 114 115 116 117 118 119 120 121 122 123 124 107 // suggest text 108 for (String suggestion : super.model) { 109 if (suggestion.startsWith(text)) { 110 textField.setActionCommand("SUGGEST"); 111 doc.setConsumeEvents(true); 112 // avoid unbound recursion via setText() -> replace() -> 113 // suggest() -> setText() ... in some environments 114 if (! text.equals(suggestion)) { 115 textField.setText(suggestion); 116 } 117 textField.setSelectionStart(text.length()); 118 textField.setSelectionEnd(textField.getText().length()); 119 doc.setConsumeEvents(false); 120 break; 121 } 122 } 123 } 124 125 125 public void keyReleased(KeyEvent e) { 126 127 128 } 126 if(e.getKeyCode() == KeyEvent.VK_SPACE && e.isControlDown()) { 127 suggest(); 128 } 129 129 } 130 130 public void keyPressed(KeyEvent e) {} -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1608 r1628 15 15 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 16 16 import org.openstreetmap.josm.gui.historycombobox.JHistoryComboBox; 17 import org.openstreetmap.josm.gui.historycombobox.StringUtils;18 17 19 18 /** … … 34 33 */ 35 34 public Collection<OsmPrimitive> processed; 36 37 35 38 36 private OsmApi api = new OsmApi(); 39 37 40 38 private static final int MSECS_PER_SECOND = 1000; 41 39 private static final int SECONDS_PER_MINUTE = 60; … … 62 60 63 61 /** 64 * Send the dataset to the server. 62 * Send the dataset to the server. 65 63 * @param the_version version of the data set 66 64 * @param list list of objects to send … … 68 66 public void uploadOsm(String the_version, Collection<OsmPrimitive> list) { 69 67 processed = new LinkedList<OsmPrimitive>(); 70 68 71 69 // initialize API. Abort upload in case of configuration or network 72 70 // errors … … 87 85 return; 88 86 } 89 90 87 91 88 Main.pleaseWaitDlg.progress.setMaximum(list.size()); … … 93 90 94 91 boolean useChangesets = api.hasChangesetSupport(); 95 92 96 93 // controls whether or not we try and upload the whole bunch in one go 97 94 boolean useDiffUploads = Main.pref.getBoolean("osm-server.atomic-upload", … … 103 100 // add the last entered comment to the changeset 104 101 String cmt = ""; 105 List<String> history = StringUtils.stringToList(Main.pref.get(UploadAction.HISTORY_KEY), JHistoryComboBox.DELIM);102 List<String> history = new LinkedList<String>(Main.pref.getCollection(UploadAction.HISTORY_KEY, null)); 106 103 if(history.size() > 0) { 107 104 cmt = history.get(0); … … 161 158 // has successfully cancelled the data upload 162 159 // 163 return; 160 return; 164 161 } 165 166 JOptionPane.showMessageDialog(Main.parent, 162 163 JOptionPane.showMessageDialog(Main.parent, 167 164 /* tr("Error during upload: ") + */ e.getMessage()); 168 165 }
Note:
See TracChangeset
for help on using the changeset viewer.