Changeset 3839 in josm for trunk/src


Ignore:
Timestamp:
2011-02-01T08:28:03+01:00 (13 years ago)
Author:
jttt
Message:

Fix #5893 Null Pointer Exception while loding custom presets at start - JOSM hangs on splash screen

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/AutosaveTask.java

    r3720 r3839  
    77import java.io.IOException;
    88import java.util.ArrayList;
    9 import java.util.Arrays;
    109import java.util.Date;
    1110import java.util.Deque;
     
    274273                    moveToDeletedLayersFolder(f);
    275274                }
    276             }         
     275            }
    277276        });
    278277    }
  • trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java

    r3796 r3839  
    1111import java.awt.Image;
    1212import java.awt.Insets;
    13 import java.awt.Color;
    1413import java.awt.event.ActionEvent;
    1514import java.io.BufferedReader;
     
    182181    }
    183182
    184         protected static class PresetListEntry {
    185             String value;
    186             String display_value;
    187             String short_description;
    188 
    189             public String getListDisplay() {
    190                 if (value.equals(DIFFERENT))
    191                     return "<b>"+DIFFERENT.replaceAll("<", "&lt;").replaceAll(">", "&gt;")+"</b>";
    192 
    193                 if (value.equals(""))
    194                     return "&nbsp;";
    195 
    196                 StringBuilder res = new StringBuilder("<b>");
    197                 if (display_value != null) {
    198                     res.append(display_value);
    199                 } else {
    200                     res.append(value);
    201                 }
    202                 res.append("</b>");
    203                 if (short_description != null) {
    204                     // wrap in table to restrict the text width
    205                     res.append("<br><table><td width='232'>(").append(short_description).append(")</td></table>");
    206                 }
    207                 return res.toString();
    208             }
    209 
    210             public PresetListEntry(String value) {
    211                 this.value = value;
    212                 this.display_value = value;
    213             }
    214 
    215             public PresetListEntry(String value, String display_value) {
    216                 this.value = value;
    217                 this.display_value = display_value;
    218             }
    219 
    220             // toString is mainly used to initialize the Editor
    221             @Override
    222             public String toString() {
    223                 if (value.equals(DIFFERENT))
    224                     return DIFFERENT;
    225                 return display_value.replaceAll("<.*>", ""); // remove additional markup, e.g. <br>
    226             }
    227         }
     183    protected static class PresetListEntry {
     184        String value;
     185        String display_value;
     186        String short_description;
     187
     188        public String getListDisplay() {
     189            if (value.equals(DIFFERENT))
     190                return "<b>"+DIFFERENT.replaceAll("<", "&lt;").replaceAll(">", "&gt;")+"</b>";
     191
     192            if (value.equals(""))
     193                return "&nbsp;";
     194
     195            StringBuilder res = new StringBuilder("<b>");
     196            if (display_value != null) {
     197                res.append(display_value);
     198            } else {
     199                res.append(value);
     200            }
     201            res.append("</b>");
     202            if (short_description != null) {
     203                // wrap in table to restrict the text width
     204                res.append("<br><table><td width='232'>(").append(short_description).append(")</td></table>");
     205            }
     206            return res.toString();
     207        }
     208
     209        public PresetListEntry(String value) {
     210            this.value = value;
     211            this.display_value = value;
     212        }
     213
     214        public PresetListEntry(String value, String display_value) {
     215            this.value = value;
     216            this.display_value = display_value;
     217        }
     218
     219        // toString is mainly used to initialize the Editor
     220        @Override
     221        public String toString() {
     222            if (value.equals(DIFFERENT))
     223                return DIFFERENT;
     224            return display_value.replaceAll("<.*>", ""); // remove additional markup, e.g. <br>
     225        }
     226    }
    228227
    229228    public static class Text extends Item {
     
    460459                PresetListEntry e = new PresetListEntry(value_array[i]);
    461460                e.display_value = (locale_display_values == null)
    462                         ? (values_context == null ? tr(display_array[i])
    463                                 : trc(values_context, display_array[i])) : display_array[i];
     461                ? (values_context == null ? tr(display_array[i])
     462                        : trc(values_context, display_array[i])) : display_array[i];
    464463                if (short_descriptions_array != null) {
    465464                    e.short_description = locale_short_descriptions == null ? tr(short_descriptions_array[i])
     
    633632                int j = 0;
    634633                for (int i = 0; i < lm.getSize(); i++) {
    635                     if (parts.contains((((PresetListEntry)lm.getElementAt(i)).value)))
     634                    if (parts.contains((((PresetListEntry)lm.getElementAt(i)).value))) {
    636635                        intParts[j++]=i;
     636                    }
    637637                }
    638638                setSelectedIndices(Arrays.copyOf(intParts, j));
    639                 // check if we have acutally managed to represent the full 
     639                // check if we have acutally managed to represent the full
    640640                // value with our presets. if not, cop out; we will not offer
    641641                // a selection list that threatens to ruin the value.
     
    647647            int[] si = getSelectedIndices();
    648648            StringBuilder builder = new StringBuilder();
    649             for (int i=0; i<si.length; i++) {
    650                 if (i>0) builder.append(delimiter);
     649            for (int i=0; i<si.length; i++) {
     650                if (i>0) {
     651                    builder.append(delimiter);
     652                }
    651653                builder.append(((PresetListEntry)lm.getElementAt(si[i])).value);
    652654            }
     
    726728                PresetListEntry e = new PresetListEntry(value_array[i]);
    727729                e.display_value = (locale_display_values == null)
    728                         ? (values_context == null ? tr(display_array[i])
    729                                 : trc(values_context, display_array[i])) : display_array[i];
     730                ? (values_context == null ? tr(display_array[i])
     731                        : trc(values_context, display_array[i])) : display_array[i];
    730732                if (short_descriptions_array != null) {
    731733                    e.short_description = locale_short_descriptions == null ? tr(short_descriptions_array[i])
  • trunk/src/org/openstreetmap/josm/tools/PresetTextComparator.java

    r3719 r3839  
    77import javax.swing.JMenuItem;
    88
     9import org.openstreetmap.josm.Main;
     10
    911public class PresetTextComparator implements Comparator<JMenuItem>, Serializable {
    10     //TODO add error checking and stuff
    1112    public int compare(JMenuItem arg0, JMenuItem arg1) {
    12         return arg0.getText().compareTo(arg1.getText());
     13        if (Main.main.menu.presetSearchAction.equals(arg0.getAction()))
     14            return -1;
     15        else if (Main.main.menu.presetSearchAction.equals(arg0.getAction()))
     16            return 1;
     17        else if (arg0.getText() == arg1.getText())
     18            return 0;
     19        else if (arg0.getText() == null)
     20            return -1;
     21        else if (arg1.getText() == null)
     22            return 1;
     23        else
     24            return arg0.getText().compareTo(arg1.getText());
    1325    }
    1426
Note: See TracChangeset for help on using the changeset viewer.