Changeset 4721 in josm
- Timestamp:
- 2011-12-27T16:11:03+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r4715 r4721 12 12 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 13 13 import org.openstreetmap.josm.gui.layer.ImageryLayer; 14 import org.openstreetmap.josm.tools.Image Request;14 import org.openstreetmap.josm.tools.ImageProvider; 15 15 16 16 public class AddImageryLayerAction extends JosmAction implements AdaptableAction { … … 28 28 try { 29 29 if (info.getIcon() != null) { 30 ImageIcon i = new Image Request().setOptional(true).setName(info.getIcon()).30 ImageIcon i = new ImageProvider(info.getIcon()).setOptional(true). 31 31 setMaxHeight(MAX_ICON_SIZE).setMaxWidth(MAX_ICON_SIZE).get(); 32 32 if (i != null) { -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r4718 r4721 122 122 if (active != null && active instanceof GpxLayer && (merge || ((GpxLayer)active).data.fromServer)) 123 123 return active; 124 for (Layer l : Main.map.mapView.getAllLayers()) 124 for (Layer l : Main.map.mapView.getAllLayers()) { 125 125 if (l instanceof GpxLayer && (merge || ((GpxLayer)l).data.fromServer)) 126 126 return l; 127 return null; 127 } 128 return null; 128 129 } 129 130 -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r4272 r4721 89 89 public static ImageIcon getIcon(IconReference ref, int width, int height, boolean sanitize) { 90 90 final String namespace = ref.source.getPrefName(); 91 ImageIcon i = ImageProvider.getIfAvailable(getIconSourceDirs(ref.source), "mappaint."+namespace, null, ref.iconName, ref.source.zipIcons, width == -1 && height == -1 ? null : new Dimension(width, height), sanitize); 91 ImageIcon i = new ImageProvider(ref.iconName) 92 .setDirs(getIconSourceDirs(ref.source)) 93 .setId("mappaint."+namespace) 94 .setArchive(ref.source.zipIcons) 95 .setWidth(width) 96 .setHeight(height) 97 .setSanitize(sanitize) 98 .setOptional(true).get(); 92 99 if(i == null) 93 100 { … … 107 114 */ 108 115 public static ImageIcon getNoIcon_Icon(StyleSource source, boolean sanitize) { 109 return ImageProvider.getIfAvailable(getIconSourceDirs(source), "mappaint."+source.getPrefName(), null, "misc/no_icon.png", source.zipIcons, sanitize); 116 return new ImageProvider("misc/no_icon.png") 117 .setDirs(getIconSourceDirs(source)) 118 .setId("mappaint."+source.getPrefName()) 119 .setArchive(source.zipIcons) 120 .setSanitize(sanitize) 121 .setOptional(true).get(); 110 122 } 111 123 -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r4528 r4721 1058 1058 public void setIcon(String iconName) { 1059 1059 Collection<String> s = Main.pref.getCollection("taggingpreset.icon.sources", null); 1060 ImageIcon icon = ImageProvider.getIfAvailable(s, "presets", null, iconName, zipIcons);1060 ImageIcon icon = new ImageProvider(iconName).setDirs(s).setId("presets").setArchive(zipIcons).setOptional(true).get(); 1061 1061 if (icon == null) 1062 1062 { -
trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java
r4688 r4721 45 45 import org.openstreetmap.josm.io.session.SessionWriter.ExportSupport; 46 46 import org.openstreetmap.josm.tools.GBC; 47 import org.openstreetmap.josm.tools.Image Request;47 import org.openstreetmap.josm.tools.ImageProvider; 48 48 49 49 public class OsmDataSessionExporter implements SessionLayerExporter { … … 69 69 private class LayerSaveAction extends AbstractAction { 70 70 public LayerSaveAction() { 71 putValue(SMALL_ICON, new Image Request().setName("save").setWidth(16).get());71 putValue(SMALL_ICON, new ImageProvider("save").setWidth(16).get()); 72 72 putValue(SHORT_DESCRIPTION, tr("Layer contains unsaved data - save to file.")); 73 73 updateEnabledState(); -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r4310 r4721 191 191 if (iconPath != null && file != null) { 192 192 // extract icon from the plugin jar file 193 icon = ImageProvider.getIfAvailable(null, null, null, iconPath, file);193 icon = new ImageProvider(iconPath).setArchive(file).setMaxWidth(24).setMaxHeight(24).setOptional(true).get(); 194 194 } 195 195 if(oldcheck && mainversion > Version.getInstance().getVersion()) -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r4310 r4721 121 121 for (PluginInformation pi : availablePlugins.values()) { 122 122 if (pi.icon == null && pi.iconPath != null) { 123 pi.icon = ImageProvider.getIfAvailable(null, null, null, pi.name+".jar/"+pi.iconPath, f); 123 pi.icon = new ImageProvider(pi.name+".jar/"+pi.iconPath) 124 .setArchive(f) 125 .setMaxWidth(24) 126 .setMaxHeight(24) 127 .setOptional(true).get(); 124 128 } 125 129 } -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r4612 r4721 244 244 for (PluginInformation pi : availablePlugins) { 245 245 if (pi.icon == null && pi.iconPath != null) { 246 pi.icon = ImageProvider.getIfAvailable(null, null, null, pi.name+".jar/"+pi.iconPath, destFile); 246 pi.icon = new ImageProvider(pi.name+".jar/"+pi.iconPath) 247 .setArchive(destFile) 248 .setMaxWidth(24) 249 .setMaxHeight(24) 250 .setOptional(true).get(); 247 251 } 248 252 } -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r4713 r4721 55 55 /** 56 56 * Helper class to support the application with images. 57 * 58 * How to use: 59 * 60 * <code>ImageIcon icon = new ImageProvider(name).setMaxWidth(24).setMaxHeight(24).get();</code> 61 * (there are more options, see below) 62 * 63 * short form: 64 * <code>ImageIcon icon = ImageProvider.get(name);</code> 65 * 57 66 * @author imi 58 67 */ 59 68 public class ImageProvider { 60 69 61 private static SVGUniverse svgUniverse;62 63 70 /** 64 71 * Position of an overlay icon … … 74 81 } 75 82 83 protected Collection<String> dirs; 84 protected String id; 85 protected String subdir; 86 protected String name; 87 protected File archive; 88 protected int width = -1; 89 protected int height = -1; 90 protected int maxWidth = -1; 91 protected int maxHeight = -1; 92 protected boolean sanitize; 93 protected boolean optional; 94 95 private static SVGUniverse svgUniverse; 96 76 97 /** 77 98 * The icon cache 78 99 */ 79 100 private static Map<String, ImageResource> cache = new HashMap<String, ImageResource>(); 101 102 /** 103 * @param subdir Subdirectory the image lies in. 104 * @param name The name of the image. If it does not end with '.png' or '.svg', 105 * both extensions are tried. 106 */ 107 public ImageProvider(String subdir, String name) { 108 this.subdir = subdir; 109 this.name = name; 110 } 111 112 public ImageProvider(String name) { 113 this.name = name; 114 } 115 116 /** 117 * Directories to look for the image. 118 */ 119 public ImageProvider setDirs(Collection<String> dirs) { 120 this.dirs = dirs; 121 return this; 122 } 123 124 /** 125 * An id used for caching. Id is not used for cache if name starts with http://. (URL is unique anyway.) 126 */ 127 public ImageProvider setId(String id) { 128 this.id = id; 129 return this; 130 } 131 132 /** 133 * A zip file where the image is located. 134 */ 135 public ImageProvider setArchive(File archive) { 136 this.archive = archive; 137 return this; 138 } 139 140 /** 141 * The dimensions of the image. 142 * 143 * If not specified, the original size of the image is used. 144 * The width part of the dimension can be -1. Then it will only set the height but 145 * keep the aspect ratio. (And the other way around.) 146 */ 147 public ImageProvider setSize(Dimension size) { 148 this.width = size.width; 149 this.height = size.height; 150 return this; 151 } 152 153 /** 154 * see setSize 155 */ 156 public ImageProvider setWidth(int width) { 157 this.width = width; 158 return this; 159 } 160 161 /** 162 * see setSize 163 */ 164 public ImageProvider setHeight(int height) { 165 this.height = height; 166 return this; 167 } 168 169 /** 170 * The maximum size of the image. 171 * 172 * It will shrink the image if necessary, but keep the aspect ratio. 173 * The given width or height can be -1 which means this direction is not bounded. 174 * 175 * 'size' and 'maxSize' are not compatible, you should set only one of them. 176 */ 177 public ImageProvider setMaxSize(Dimension maxSize) { 178 this.maxWidth = maxSize.width; 179 this.maxHeight = maxSize.height; 180 return this; 181 } 182 183 /** 184 * see setMaxSize 185 */ 186 public ImageProvider setMaxWidth(int maxWidth) { 187 this.maxWidth = maxWidth; 188 return this; 189 } 190 191 /** 192 * see setMaxSize 193 */ 194 public ImageProvider setMaxHeight(int maxHeight) { 195 this.maxHeight = maxHeight; 196 return this; 197 } 198 199 /** 200 * Set true, if the image should be repainted to a new BufferedImage in order to work around certain issues. 201 */ 202 public ImageProvider setSanitize(boolean sanitize) { 203 this.sanitize = sanitize; 204 return this; 205 } 206 207 /** 208 * The image URL comes from user data and the image may be missing. 209 * 210 * Set true, if JOSM should *not* throw a RuntimeException in case the image cannot be located. 211 */ 212 public ImageProvider setOptional(boolean optional) { 213 this.optional = optional; 214 return this; 215 } 216 217 /** 218 * Execute the image request. 219 */ 220 public ImageIcon get() { 221 ImageResource ir = getIfAvailableImpl(); 222 if (ir == null) { 223 if (!optional) { 224 String ext = name.indexOf('.') != -1 ? "" : ".???"; 225 throw new RuntimeException(tr("Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.", name + ext)); 226 } else { 227 System.out.println(tr("Failed to locate image ''{0}''", name)); 228 return null; 229 } 230 } 231 if (maxWidth != -1 || maxHeight != -1) 232 return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight), sanitize); 233 else 234 return ir.getImageIcon(new Dimension(width, height), sanitize); 235 } 80 236 81 237 /** … … 88 244 */ 89 245 public static ImageIcon get(String subdir, String name) { 90 ImageIcon icon = getIfAvailable(subdir, name); 91 if (icon == null) { 92 String ext = name.indexOf('.') != -1 ? "" : ".???"; 93 throw new RuntimeException(tr( 94 "Fatal: failed to locate image ''{0}''. This is a serious configuration problem. JOSM will stop working.", 95 name+ext)); 96 } 97 return icon; 98 } 99 100 /** 101 * Shortcut for get("", name); 102 */ 246 return new ImageProvider(subdir, name).get(); 247 } 248 103 249 public static ImageIcon get(String name) { 104 return get("", name);250 return new ImageProvider(name).get(); 105 251 } 106 252 107 253 public static ImageIcon getIfAvailable(String name) { 108 return getIfAvailable((Collection<String>) null, null, "", name);254 return new ImageProvider(name).setOptional(true).get(); 109 255 } 110 256 111 257 public static ImageIcon getIfAvailable(String subdir, String name) { 112 return getIfAvailable((Collection<String>) null, null, subdir, name); 113 } 114 258 return new ImageProvider(subdir, name).setOptional(true).get(); 259 } 260 261 @Deprecated 115 262 public static ImageIcon getIfAvailable(String[] dirs, String id, String subdir, String name) { 116 263 return getIfAvailable(Arrays.asList(dirs), id, subdir, name); … … 122 269 * be printed on the console if the image could not be found. 123 270 */ 271 @Deprecated 124 272 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name) { 125 273 return getIfAvailable(dirs, id, subdir, name, null); 126 274 } 127 275 276 @Deprecated 128 277 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive) { 129 278 return getIfAvailable(dirs, id, subdir, name, archive, false); 130 279 } 131 280 281 @Deprecated 132 282 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, boolean sanitize) { 133 283 return getIfAvailable(dirs, id, subdir, name, archive, null, sanitize); 134 284 } 135 285 286 @Deprecated 136 287 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, File archive, Dimension dim, boolean sanitize) { 137 288 return getIfAvailable(dirs, id, subdir, name, archive, dim, null, sanitize); … … 159 310 * around certain issues. 160 311 */ 312 @Deprecated 161 313 public static ImageIcon getIfAvailable(Collection<String> dirs, String id, String subdir, String name, 162 314 File archive, Dimension dim, Dimension maxSize, boolean sanitize) { 163 ImageResource ir = getIfAvailableImpl(dirs, id, subdir, name, archive); 164 if (ir == null) 165 return null; 166 if (maxSize != null) 167 return ir.getImageIconBounded(maxSize, sanitize); 168 else 169 return ir.getImageIcon(dim == null ? ImageResource.DEFAULT_DIMENSION : dim, sanitize); 315 ImageProvider p = new ImageProvider(subdir, name).setDirs(dirs).setId(id).setArchive(archive).setSanitize(sanitize).setOptional(true); 316 if (dim != null) { 317 p.setSize(dim); 318 } 319 if (maxSize != null) { 320 p.setMaxSize(maxSize); 321 } 322 return p.get(); 170 323 } 171 324 … … 177 330 "^data:([a-zA-Z]+/[a-zA-Z+]+)?(;base64)?,(.+)$"); 178 331 179 static ImageResource getIfAvailableImpl(Collection<String> dirs, String id, String subdir, String name, File archive) {332 private ImageResource getIfAvailableImpl() { 180 333 if (name == null) 181 334 return null;
Note: See TracChangeset
for help on using the changeset viewer.