1 | /** | | 1 | /** |
2 | * Look up the external file type registered with this name, if any. | | 2 | * Set up the list of external file types, either from default values, or from values |
3 | * @param name The file type name. | | 3 | * recorded in Preferences. |
4 | * @return The ExternalFileType registered, or null if none. | | 4 | */ |
5 | */ | | 5 | public void updateExternalFileTypes() { |
6 | public ExternalFileType getExternalFileTypeByName(String name) { | | 6 | // First get a list of the default file types as a starting point: |
7 | for (Iterator<ExternalFileType> iterator = externalFileTypes.iterator(); iterator.hasNext();) { | | 7 | List<ExternalFileType> types = getDefaultExternalFileTypes(); |
8 | ExternalFileType type = iterator.next(); | | 8 | // If no changes have been stored, simply use the defaults: |
9 | if (type.getName().equals(name)) | | 9 | if (prefs.get("externalFileTypes", null) == null) { |
10 | return type; | | 10 | externalFileTypes.clear(); |
11 | } | | 11 | externalFileTypes.addAll(types); |
12 | // Return an instance that signifies an unknown file type: | | 12 | return; |
13 | return new UnknownExternalFileType(name); | | 13 | } |
14 | } | | 14 | // Read the prefs information for file types: |
| | | 15 | String[][] vals = Util.decodeStringDoubleArray(prefs.get("externalFileTypes", "")); |
| | | 16 | for (int i = 0; i < vals.length; i++) { |
| | | 17 | if ((vals[i].length == 2) && (vals[i][1].equals(FILE_TYPE_REMOVED_FLAG))) { |
| | | 18 | // This entry indicates that a default entry type should be removed: |
| | | 19 | ExternalFileType toRemove = null; |
| | | 20 | for (ExternalFileType type : types) { |
| | | 21 | if (type.getName().equals(vals[i][0])) { |
| | | 22 | toRemove = type; |
| | | 23 | break; |
| | | 24 | } |
| | | 25 | } |
| | | 26 | // If we found it, remove it from the type list: |
| | | 27 | if (toRemove != null) |
| | | 28 | types.remove(toRemove); |
| | | 29 | } |
| | | 30 | else { |
| | | 31 | // A new or modified entry type. Construct it from the string array: |
| | | 32 | ExternalFileType type = new ExternalFileType(vals[i]); |
| | | 33 | // Check if there is a default type with the same name. If so, this is a |
| | | 34 | // modification of that type, so remove the default one: |
| | | 35 | ExternalFileType toRemove = null; |
| | | 36 | for (ExternalFileType defType : types) { |
| | | 37 | if (type.getName().equals(defType.getName())) { |
| | | 38 | toRemove = defType; |
| | | 39 | break; |
| | | 40 | } |
| | | 41 | } |
| | | 42 | // If we found it, remove it from the type list: |
| | | 43 | if (toRemove != null) { |
| | | 44 | types.remove(toRemove); |
| | | 45 | } |
| | | 46 | |
| | | 47 | // Then add the new one: |
| | | 48 | types.add(type); |
| | | 49 | } |
| | | 50 | } |
| | | 51 | |
| | | 52 | // Finally, build the list of types based on the modified defaults list: |
| | | 53 | for (ExternalFileType type : types) { |
| | | 54 | externalFileTypes.add(type); |
| | | 55 | } |
| | | 56 | } |