1 | /** | | 1 | /** |
2 | * Look up the external file type registered with this name, if any. | | 2 | * Reset the List of external file types after user customization. |
3 | * @param name The file type name. | | 3 | * @param types The new List of external file types. This is the complete list, not |
4 | * @return The ExternalFileType registered, or null if none. | | 4 | * just new entries. |
5 | */ | | 5 | */ |
6 | public ExternalFileType getExternalFileTypeByName(String name) { | | 6 | public void setExternalFileTypes(List<ExternalFileType> types) { |
7 | for (Iterator<ExternalFileType> iterator = externalFileTypes.iterator(); iterator.hasNext();) { | | 7 | |
8 | ExternalFileType type = iterator.next(); | | 8 | // First find a list of the default types: |
9 | if (type.getName().equals(name)) | | 9 | List<ExternalFileType> defTypes = getDefaultExternalFileTypes(); |
10 | return type; | | 10 | // Make a list of types that are unchanged: |
11 | } | | 11 | List<ExternalFileType> unchanged = new ArrayList<ExternalFileType>(); |
12 | // Return an instance that signifies an unknown file type: | | 12 | |
13 | return new UnknownExternalFileType(name); | | 13 | externalFileTypes.clear(); |
14 | } | | 14 | for (Iterator<ExternalFileType> iterator = types.iterator(); iterator.hasNext();) { |
| | | 15 | ExternalFileType type = iterator.next(); |
| | | 16 | externalFileTypes.add(type); |
| | | 17 | |
| | | 18 | // See if we can find a type with matching name in the default type list: |
| | | 19 | ExternalFileType found = null; |
| | | 20 | for (ExternalFileType defType : defTypes) { |
| | | 21 | if (defType.getName().equals(type.getName())) { |
| | | 22 | found = defType; |
| | | 23 | break; |
| | | 24 | } |
| | | 25 | } |
| | | 26 | if (found != null) { |
| | | 27 | // Found it! Check if it is an exact match, or if it has been customized: |
| | | 28 | if (found.equals(type)) |
| | | 29 | unchanged.add(type); |
| | | 30 | else { |
| | | 31 | // It was modified. Remove its entry from the defaults list, since |
| | | 32 | // the type hasn't been removed: |
| | | 33 | defTypes.remove(found); |
| | | 34 | } |
| | | 35 | } |
| | | 36 | } |
| | | 37 | |
| | | 38 | // Go through unchanged types. Remove them from the ones that should be stored, |
| | | 39 | // and from the list of defaults, since we don't need to mention these in prefs: |
| | | 40 | for (ExternalFileType type : unchanged) { |
| | | 41 | defTypes.remove(type); |
| | | 42 | types.remove(type); |
| | | 43 | } |
| | | 44 | |
| | | 45 | // Now set up the array to write to prefs, containing all new types, all modified |
| | | 46 | // types, and a flag denoting each default type that has been removed: |
| | | 47 | String[][] array = new String[types.size()+defTypes.size()][]; |
| | | 48 | int i=0; |
| | | 49 | for (ExternalFileType type : types) { |
| | | 50 | array[i] = type.getStringArrayRepresentation(); |
| | | 51 | i++; |
| | | 52 | } |
| | | 53 | for (ExternalFileType type : defTypes) { |
| | | 54 | array[i] = new String[] {type.getName(), FILE_TYPE_REMOVED_FLAG}; |
| | | 55 | i++; |
| | | 56 | } |
| | | 57 | //System.out.println("Encoded: '"+Util.encodeStringArray(array)+"'"); |
| | | 58 | put("externalFileTypes", Util.encodeStringArray(array)); |
| | | 59 | } |