Changeset 3999 in josm
- Timestamp:
- 2011-03-22T13:33:04+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/NodeElemStyle.java
r3992 r3999 6 6 import java.awt.BasicStroke; 7 7 import java.awt.Color; 8 import java.awt.Image; 8 9 import java.awt.Stroke; 9 10 … … 20 21 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference; 21 22 import org.openstreetmap.josm.tools.CheckParameterUtil; 23 import org.openstreetmap.josm.tools.Pair; 22 24 import org.openstreetmap.josm.tools.Utils; 23 25 … … 130 132 } 131 133 132 protected NodeElemStyle(Cascade c, ImageIcon icon, inticonAlpha, Symbol symbol, NodeTextElement text) {134 protected NodeElemStyle(Cascade c, ImageIcon icon, Integer iconAlpha, Symbol symbol, NodeTextElement text) { 133 135 super(c); 134 136 this.icon = icon; 135 this.iconAlpha = iconAlpha ;137 this.iconAlpha = iconAlpha == null ? 0 : iconAlpha; 136 138 this.symbol = symbol; 137 139 this.text = text; … … 158 160 Cascade c = env.mc.getCascade(env.layer); 159 161 160 IconReference iconRef = c.get("icon-image", null, IconReference.class); 161 ImageIcon icon = null; 162 int iconAlpha = 0; 162 Pair<ImageIcon, Integer> icon = createIcon(env); 163 163 Symbol symbol = null; 164 165 if (iconRef != null) { 166 icon = MapPaintStyles.getIcon(iconRef, false); 167 if (icon == null) { 168 icon = MapPaintStyles.getNoIcon_Icon(iconRef.source, false); 169 } 170 iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255)))); 171 Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class)); 172 if (pAlpha != null) { 173 iconAlpha = pAlpha; 174 } 175 } else { 164 if (icon == null) { 176 165 symbol = createSymbol(env); 177 166 } … … 210 199 } 211 200 212 return new NodeElemStyle(c, icon, iconAlpha, symbol, text); 201 return new NodeElemStyle(c, 202 icon == null ? null : icon.a, 203 icon == null ? null : icon.b, 204 symbol, 205 text); 206 } 207 208 private static Pair<ImageIcon, Integer> createIcon(Environment env) { 209 Cascade c = env.mc.getCascade(env.layer); 210 Cascade c_def = env.mc.getCascade("default"); 211 212 IconReference iconRef = c.get("icon-image", null, IconReference.class); 213 if (iconRef == null) 214 return null; 215 216 ImageIcon icon = null; 217 int iconAlpha = 0; 218 219 icon = MapPaintStyles.getIcon(iconRef, false); 220 if (icon == null) 221 return new Pair<ImageIcon, Integer>(MapPaintStyles.getNoIcon_Icon(iconRef.source, false), 255); 222 else { 223 Float sizeOnDefault = c_def.get("icon-size", null, Float.class); 224 if (sizeOnDefault != null && sizeOnDefault <= 0) { 225 sizeOnDefault = null; 226 } 227 Float sizeF = getWidth(c, "icon-size", sizeOnDefault); 228 229 if (sizeF != null) { 230 if (sizeF <= 0) 231 return null; 232 int size = Math.round(sizeF); 233 int width = icon.getIconWidth(); 234 int height = icon.getIconHeight(); 235 if (Math.max(width, height) != size) { 236 if (width >= height) { 237 width = size; 238 height = -1; 239 } else { 240 width = -1; 241 height = size; 242 } 243 icon.setImage(icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH)); 244 } 245 } 246 iconAlpha = Math.min(255, Math.max(0, Integer.valueOf(Main.pref.getInteger("mappaint.icon-image-alpha", 255)))); 247 Integer pAlpha = Utils.color_float2int(c.get("icon-opacity", null, float.class)); 248 if (pAlpha != null) { 249 iconAlpha = pAlpha; 250 } 251 252 return new Pair<ImageIcon, Integer>(icon, iconAlpha); 253 } 213 254 } 214 255
Note:
See TracChangeset
for help on using the changeset viewer.