- Timestamp:
- 2015-02-22T14:19:20+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintMenu.java
r7937 r8097 34 34 35 35 public MapPaintAction(StyleSource style) { 36 super(style.getDisplayString(), style.getIcon (),36 super(style.getDisplayString(), style.getIconProvider(), 37 37 tr("Select the map painting styles"), null, true, "mappaint/" + style.getDisplayString(), true); 38 38 this.button = new StayOpenCheckBoxMenuItem(this); -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r8085 r8097 102 102 } 103 103 104 public static ImageIcon getIcon(IconReference ref, int width, int height) { 104 /** 105 * Image provider for icon. Note that this is a provider only. A @link{ImageProvider#get()} call may still 106 * fail! 107 * 108 * @param ref reference to the requested icon 109 * @param test if <code>true</code> than the icon is request is tested 110 * @return image provider for icon (can be <code>null</code> when <code>test</code> is <code>true</code>). 111 * @since 8097 112 * @see #getIcon(IconReference, int,int) 113 */ 114 public static ImageProvider getIconProvider(IconReference ref, boolean test) { 105 115 final String namespace = ref.source.getPrefName(); 106 Image Iconi = new ImageProvider(ref.iconName)116 ImageProvider i = new ImageProvider(ref.iconName) 107 117 .setDirs(getIconSourceDirs(ref.source)) 108 118 .setId("mappaint."+namespace) 109 119 .setArchive(ref.source.zipIcons) 110 120 .setInArchiveDir(ref.source.getZipEntryDirName()) 111 .setWidth(width) 112 .setHeight(height) 113 .setOptional(true).get(); 121 .setOptional(true); 122 if (test && i.get() == null) { 123 Main.warn("Mappaint style \""+namespace+"\" ("+ref.source.getDisplayString()+") icon \"" + ref.iconName + "\" not found."); 124 return null; 125 } 126 return i; 127 } 128 129 /** 130 * Return scaled icon. 131 * 132 * @param ref reference to the requested icon 133 * @param width icon width or -1 for autoscale 134 * @param height icon height or -1 for autoscale 135 * @return image icon or <code>null</code>. 136 * @see #getIconProvider(IconReference, boolean) 137 */ 138 public static ImageIcon getIcon(IconReference ref, int width, int height) { 139 final String namespace = ref.source.getPrefName(); 140 ImageIcon i = getIconProvider(ref, false).setWidth(width).setHeight(height).get(); 114 141 if (i == null) { 115 142 Main.warn("Mappaint style \""+namespace+"\" ("+ref.source.getDisplayString()+") icon \"" + ref.iconName + "\" not found."); -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r7592 r8097 21 21 import org.openstreetmap.josm.gui.preferences.SourceEntry; 22 22 import org.openstreetmap.josm.io.CachedFile; 23 import org.openstreetmap.josm.tools.ImageOverlay; 23 24 import org.openstreetmap.josm.tools.ImageProvider; 24 25 import org.openstreetmap.josm.tools.Utils; … … 35 36 public File zipIcons; 36 37 37 private ImageIcon imageIcon; 38 /** image provider returning the icon for this style */ 39 private ImageProvider imageIconProvider; 40 41 /** image provider returning the default icon */ 42 private static ImageProvider defaultIconProvider; 38 43 39 44 /****** … … 41 46 * of the source file. 42 47 */ 43 44 48 public String icon; 45 49 … … 115 119 } 116 120 121 /** 122 * Initialize the class. 123 */ 117 124 protected void init() { 118 125 errors.clear(); 119 imageIcon = null;126 imageIconProvider = null; 120 127 icon = null; 121 128 } 122 129 123 private static ImageIcon defaultIcon; 124 125 private static ImageIcon getDefaultIcon() { 126 if (defaultIcon == null) { 127 defaultIcon = ImageProvider.get("dialogs/mappaint", "pencil"); 130 /** 131 * Image provider for default icon. 132 * 133 * @return image provider for default styles icon 134 * @since 8097 135 * @see #getIconProvider() 136 */ 137 private static ImageProvider getDefaultIconProvider() { 138 if (defaultIconProvider == null) { 139 defaultIconProvider = new ImageProvider("dialogs/mappaint", "pencil"); 128 140 } 129 return defaultIcon; 130 } 131 132 protected ImageIcon getSourceIcon() { 133 if (imageIcon == null) { 141 return defaultIconProvider; 142 } 143 144 /** 145 * Image provider for source icon. Uses default icon, when not else available. 146 * 147 * @return image provider for styles icon 148 * @since 8097 149 * @see #getIconProvider() 150 */ 151 protected ImageProvider getSourceIconProvider() { 152 if (imageIconProvider == null) { 134 153 if (icon != null) { 135 imageIcon = MapPaintStyles.getIcon(new IconReference(icon, this), -1, -1);154 imageIconProvider = MapPaintStyles.getIconProvider(new IconReference(icon, this), true); 136 155 } 137 if (imageIcon == null) {138 imageIcon = getDefaultIcon();156 if (imageIconProvider == null) { 157 imageIconProvider = getDefaultIconProvider(); 139 158 } 140 159 } 141 return imageIcon; 142 } 143 160 return imageIconProvider; 161 } 162 163 /** 164 * Image provider for source icon. 165 * 166 * @return image provider for styles icon 167 * @since 8097 168 */ 169 public final ImageProvider getIconProvider() { 170 ImageProvider i = getSourceIconProvider(); 171 if (!getErrors().isEmpty()) { 172 i = new ImageProvider(i).addOverlay(new ImageOverlay(new ImageProvider("dialogs/mappaint/error_small"))); 173 } 174 return i; 175 } 176 177 /** 178 * Image for source icon. 179 * 180 * @return styles icon for display 181 */ 144 182 public final ImageIcon getIcon() { 145 if (getErrors().isEmpty())146 return getSourceIcon();147 else 148 return ImageProvider.overlay(getSourceIcon(),149 ImageProvider.get("dialogs/mappaint/error_small"),150 ImageProvider.OverlayPosition.SOUTHEAST);151 }152 183 return getIconProvider().setMaxSize(ImageProvider.ImageSizes.MENU).get(); 184 } 185 186 /** 187 * Return text to display as ToolTip. 188 * 189 * @return tooltip text containing error status 190 */ 153 191 public String getToolTipText() { 154 192 if (errors.isEmpty()) -
trunk/src/org/openstreetmap/josm/tools/ImageOverlay.java
r8095 r8097 81 81 ImageIcon overlay; 82 82 if(width != -1 || height != -1) { 83 /* Don't modify ImageProvider, but apply maximum size, probably cloning the ImageProvider 84 would be a better approach. */ 85 overlay = image.getResource().getImageIconBounded(new Dimension(width, height)); 86 } else { 87 overlay = image.get(); 83 image = new ImageProvider(image).resetMaxSize(new Dimension(width, height)); 88 84 } 85 overlay = image.get(); 89 86 int x, y; 90 87 if (width == -1 && offsetLeft < 0) { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r8096 r8097 240 240 241 241 /** 242 * Constructs a new {@code ImageProvider} from an existing one. 243 * @param image the existing image provider to be copied 244 * @since 8095 245 */ 246 public ImageProvider(ImageProvider image) { 247 this.dirs = image.dirs; 248 this.id = image.id; 249 this.subdir = image.subdir; 250 this.name = image.name; 251 this.archive = image.archive; 252 this.inArchiveDir = image.inArchiveDir; 253 this.width = image.width; 254 this.height = image.height; 255 this.maxWidth = image.maxWidth; 256 this.maxHeight = image.maxHeight; 257 this.optional = image.optional; 258 this.suppressWarnings = image.suppressWarnings; 259 this.additionalClassLoaders = image.additionalClassLoaders; 260 this.overlayInfo = image.overlayInfo; 261 } 262 263 /** 242 264 * Directories to look for the image. 243 265 * @param dirs The directories to look for. … … 384 406 this.maxWidth = maxSize.width; 385 407 this.maxHeight = maxSize.height; 408 return this; 409 } 410 411 /** 412 * Limit the maximum size of the image. 413 * 414 * It will shrink the image if necessary, but keep the aspect ratio. 415 * The given width or height can be -1 which means this direction is not bounded. 416 * 417 * This function sets value using the most restrictive of the new or existing set of 418 * values. 419 * 420 * @param maxSize maximum image size 421 * @return the current object, for convenience 422 * @see #setMaxSize(Dimension) 423 */ 424 public ImageProvider resetMaxSize(Dimension maxSize) { 425 if (this.maxWidth == -1 || maxSize.width < this.maxWidth) { 426 this.maxWidth = maxSize.width; 427 } 428 if (this.maxHeight == -1 || maxSize.height < this.maxHeight) { 429 this.maxHeight = maxSize.height; 430 } 386 431 return this; 387 432 }
Note:
See TracChangeset
for help on using the changeset viewer.