Changeset 1628 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-05-30T13:58:30+02:00 (15 years ago)
Author:
stoecker
Message:

cleanup group settings in preferences

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  
    2222import org.openstreetmap.josm.gui.OsmPrimitivRenderer;
    2323import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    24 import org.openstreetmap.josm.gui.historycombobox.StringUtils;
    2524import org.openstreetmap.josm.gui.historycombobox.SuggestingJHistoryComboBox;
    2625import org.openstreetmap.josm.io.OsmServerWriter;
     
    3837 */
    3938public 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";
    4241
    4342    /** Upload Hook */
     
    103102                    p.add(new JScrollPane(l), GBC.eol().fill());
    104103                }
    105                
     104
    106105                p.add(new JLabel(tr("Provide a brief comment for the changes you are uploading:")), GBC.eol().insets(0, 5, 10, 3));
    107106                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));
    109108                cmt.setHistory(cmtHistory);
    110109                //final JTextField cmt = new JTextField(lastCommitComment);
     
    112111
    113112                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?"),
    116115                        p,
    117                         new String[] {tr("Upload Changes"), tr("Cancel")}, 
     116                        new String[] {tr("Upload Changes"), tr("Cancel")},
    118117                        new String[] {"upload.png", "cancel.png"}).getValue();
    119                    
     118
    120119                    // cancel pressed
    121120                    if (result != 1) return false;
    122                    
     121
    123122                    // don't allow empty commit message
    124123                    if (cmt.getText().trim().length() < 3) continue;
    125                    
     124
    126125                    // store the history of comments
    127126                    cmt.addCurrentItemToHistory();
    128                     Main.pref.put(HISTORY_KEY, StringUtils.listToString(cmt.getHistory(), SuggestingJHistoryComboBox.DELIM));
    129                    
     127                    Main.pref.putCollection(HISTORY_KEY, cmt.getHistory());
     128
    130129                    break;
    131130                }
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r1610 r1628  
    77import java.io.BufferedReader;
    88import java.io.File;
    9 import java.io.FileReader;
    10 import java.io.FileWriter;
     9import java.io.FileInputStream;
     10import java.io.FileOutputStream;
    1111import java.io.IOException;
     12import java.io.InputStreamReader;
     13import java.io.OutputStreamWriter;
    1214import java.io.PrintWriter;
    1315import java.util.ArrayList;
     
    279281        try {
    280282            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);
    282285            for (final Entry<String, String> e : properties.entrySet()) {
    283286                String s = defaults.get(e.getKey());
     
    296299    public void load() throws IOException {
    297300        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"));
    299303        int lineNumber = 0;
    300304        ArrayList<Integer> errLines = new ArrayList<Integer>();
     
    362366        if (!bookmarkFile.exists())
    363367            bookmarkFile.createNewFile();
    364         BufferedReader in = new BufferedReader(new FileReader(bookmarkFile));
     368        BufferedReader in = new BufferedReader(new InputStreamReader(
     369        new FileInputStream(bookmarkFile), "utf-8"));
    365370
    366371        LinkedList<Bookmark> bookmarks = new LinkedList<Bookmark>();
    367         // use pattern matches to scan text, as text may contain a "," itself
    368372        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);
    370375            if(m.matches())
    371376            {
     
    386391        if (!bookmarkFile.exists())
    387392            bookmarkFile.createNewFile();
    388         PrintWriter out = new PrintWriter(new FileWriter(bookmarkFile));
     393        PrintWriter out = new PrintWriter(new OutputStreamWriter(
     394        new FileOutputStream(bookmarkFile), "utf-8"));
    389395        for (Bookmark b : bookmarks) {
    390             out.print(b.name+",");
     396            out.print(b.name+"\u001e");
    391397            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":""));
    393399            out.println();
    394400        }
     
    491497            {
    492498                if(d != null)
    493                     d += ";" + a;
     499                    d += "\u001e" + a;
    494500                else
    495501                    d = a;
     
    498504        }
    499505        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        }
    501522        return def;
    502523    }
     
    516537            {
    517538                if(s != null)
    518                     s += ";" + a;
     539                    s += "\u001e" + a;
    519540                else
    520541                    s = a;
  • trunk/src/org/openstreetmap/josm/gui/historycombobox/JHistoryComboBox.java

    r1575 r1628  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    3535
    3636/**
    37  * Extends the standard JComboBox with a history. Works with Strings only. 
     37 * Extends the standard JComboBox with a history. Works with Strings only.
    3838 * @author henni
    3939 *
     
    4141public class JHistoryComboBox extends JComboBox implements ActionListener {
    4242
    43     public static String DELIM = "§§§";
    44    
    4543    protected ComboBoxHistory model;
    46    
     44
    4745    /**
    4846     * Default constructor for GUI editors. Don't use this!!!
    4947     */
    5048    public JHistoryComboBox() {}
    51    
     49
    5250    /**
    5351     * @param history the history as a list of strings
     
    6058        setHistory(history);
    6159    }
    62    
     60
    6361    public void actionPerformed(ActionEvent e) {
    6462        addCurrentItemToHistory();
     
    6967        model.addElement(regex);
    7068    }
    71    
     69
    7270    public void setText(String text) {
    73         getEditor().setItem(text);
     71        getEditor().setItem(text);
    7472    }
    75    
     73
    7674    public String getText() {
    77         return getEditor().getItem().toString();
     75        return getEditor().getItem().toString();
    7876    }
    79    
     77
    8078    public void addHistoryChangedListener(HistoryChangedListener l) {
    8179        model.addHistoryChangedListener(l);
    8280    }
    83    
     81
    8482    public void removeHistoryChangedListener(HistoryChangedListener l) {
    8583        model.removeHistoryChangedListener(l);
    8684    }
    87    
     85
    8886    public void setHistory(List<String> history) {
    8987        model.setItems(history);
    9088    }
    91    
     89
    9290    public List<String> getHistory() {
    9391        return model.asList();
  • trunk/src/org/openstreetmap/josm/gui/historycombobox/SuggestingJHistoryComboBox.java

    r1585 r1628  
    11/* Copyright (c) 2008, Henrik Niehaus
    22 * All rights reserved.
    3  * 
     3 *
    44 * Redistribution and use in source and binary forms, with or without
    55 * modification, are permitted provided that the following conditions are met:
    6  * 
     6 *
    77 * 1. Redistributions of source code must retain the above copyright notice,
    88 *    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
    1111 *    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
    1414 *    software without specific prior written permission.
    15  * 
     15 *
    1616 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1717 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     
    4343public class SuggestingJHistoryComboBox extends JHistoryComboBox implements KeyListener {
    4444
    45         private EventConsumingPlainDocument doc = new EventConsumingPlainDocument();
    46        
     45    private EventConsumingPlainDocument doc = new EventConsumingPlainDocument();
     46
    4747    public SuggestingJHistoryComboBox(List<String> history) {
    4848        super(history);
     
    5050        // add keylistener for ctrl + space
    5151        getEditor().getEditorComponent().addKeyListener(this);
    52        
     52
    5353        // add specialized document, which can consume events, which are
    5454        // produced by the suggestion
    5555        ((JTextComponent)getEditor().getEditorComponent()).setDocument(doc);
    56        
     56
    5757        // add DocumentFilter to trigger suggestion
    5858        JTextField editor = (JTextField) getEditor().getEditorComponent();
    5959        final AbstractDocument doc = (AbstractDocument) editor.getDocument();
    6060        doc.setDocumentFilter(new DocumentFilter() {
    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                         }
     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            }
    7070
    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                         }
     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            }
    8080        });
    8181    }
     
    8989        if(e.getSource() instanceof JTextField) {
    9090            JTextField textField = (JTextField) e.getSource();
    91    
     91
    9292            // if the ActionCommand equals SUGGEST, the user confirms a suggestion
    9393            if("SUGGEST".equals(e.getActionCommand())) {
     
    102102
    103103    private void suggest() {
    104                 JTextField textField = (JTextField) getEditor().getEditorComponent();
    105                 String text = textField.getText();
     104        JTextField textField = (JTextField) getEditor().getEditorComponent();
     105        String text = textField.getText();
    106106
    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    
     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
    125125    public void keyReleased(KeyEvent e) {
    126         if(e.getKeyCode() == KeyEvent.VK_SPACE && e.isControlDown()) {
    127                 suggest();
    128         } 
     126        if(e.getKeyCode() == KeyEvent.VK_SPACE && e.isControlDown()) {
     127            suggest();
     128        }
    129129    }
    130130    public void keyPressed(KeyEvent e) {}
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r1608 r1628  
    1515import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
    1616import org.openstreetmap.josm.gui.historycombobox.JHistoryComboBox;
    17 import org.openstreetmap.josm.gui.historycombobox.StringUtils;
    1817
    1918/**
     
    3433     */
    3534    public Collection<OsmPrimitive> processed;
    36    
    3735
    3836    private OsmApi api = new OsmApi();
    39    
     37
    4038    private static final int MSECS_PER_SECOND = 1000;
    4139    private static final int SECONDS_PER_MINUTE = 60;
     
    6260
    6361    /**
    64      * Send the dataset to the server. 
     62     * Send the dataset to the server.
    6563     * @param the_version version of the data set
    6664     * @param list list of objects to send
     
    6866    public void uploadOsm(String the_version, Collection<OsmPrimitive> list) {
    6967        processed = new LinkedList<OsmPrimitive>();
    70        
     68
    7169        // initialize API. Abort upload in case of configuration or network
    7270        // errors
     
    8785            return;
    8886        }
    89        
    9087
    9188        Main.pleaseWaitDlg.progress.setMaximum(list.size());
     
    9390
    9491        boolean useChangesets = api.hasChangesetSupport();
    95        
     92
    9693        // controls whether or not we try and upload the whole bunch in one go
    9794        boolean useDiffUploads = Main.pref.getBoolean("osm-server.atomic-upload",
     
    103100                // add the last entered comment to the changeset
    104101                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));
    106103                if(history.size() > 0) {
    107104                    cmt = history.get(0);
     
    161158            // has successfully cancelled the data upload
    162159            //
    163             return; 
     160            return;
    164161        }
    165        
    166         JOptionPane.showMessageDialog(Main.parent, 
     162
     163        JOptionPane.showMessageDialog(Main.parent,
    167164            /* tr("Error during upload: ") + */ e.getMessage());
    168165    }
Note: See TracChangeset for help on using the changeset viewer.