Changeset 255 in josm
- Timestamp:
- 2007-06-13T22:30:51+02:00 (18 years ago)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/gui/annotation/AnnotationPreset.java
r212 r255 35 35 import org.openstreetmap.josm.data.osm.OsmPrimitive; 36 36 import org.openstreetmap.josm.tools.GBC; 37 import org.openstreetmap.josm.tools.ImageProvider; 37 38 import org.openstreetmap.josm.tools.XmlObjectParser; 38 39 import org.xml.sax.SAXException; … … 54 55 boolean requestFocusInWindow() {return false;} 55 56 } 56 57 57 58 public static class Text extends Item { 58 59 public String key; … … 81 82 public String text; 82 83 public boolean default_ = false; 83 84 84 85 private JCheckBox check = new JCheckBox(); 85 86 … … 143 144 144 145 /** 145 146 147 146 * The types as preparsed collection. 147 */ 148 public Collection<Class<?>> types; 148 149 private List<Item> data = new LinkedList<Item>(); 149 150 … … 166 167 * Called from the XML parser to set the icon 167 168 */ 168 public void setIcon(String icon) { 169 putValue(Action.SMALL_ICON, new ImageIcon(new ImageIcon(icon).getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH))); 170 } 171 169 public void setIcon(String iconName) { 170 ImageIcon icon = ImageProvider.getIfAvailable(null, iconName); 171 if (icon == null) 172 icon = new ImageIcon(iconName); 173 if (Math.max(icon.getIconHeight(), icon.getIconWidth()) != 24) 174 icon = new ImageIcon(icon.getImage().getScaledInstance(24, 24, Image.SCALE_SMOOTH)); 175 putValue(Action.SMALL_ICON, icon); 176 } 177 172 178 /** 173 179 * Called from the XML parser to set the types, this preset affects … … 186 192 } 187 193 } 188 194 189 195 public static List<AnnotationPreset> readAll(InputStream inStream) throws SAXException { 190 196 BufferedReader in = null; -
src/org/openstreetmap/josm/tools/ImageProvider.java
r243 r255 69 69 if (name == null) 70 70 return null; 71 if (subdir == null || subdir != "") 71 if (subdir == null) 72 subdir = ""; 73 else 72 74 subdir += "/"; 73 75 String ext = name.indexOf('.') != -1 ? "" : ".png"; -
test/org/openstreetmap/josm/gui/annotation/AnnotationPresetTest.java
r193 r255 1 1 package org.openstreetmap.josm.gui.annotation; 2 2 3 import java.io.ByteArrayInputStream; 3 4 import java.io.InputStream; 4 5 import java.lang.reflect.Field; … … 6 7 7 8 import javax.swing.Action; 9 import javax.swing.Icon; 8 10 9 11 import junit.framework.TestCase; … … 14 16 import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Label; 15 17 import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Text; 18 import org.openstreetmap.josm.tools.ImageProvider; 16 19 17 20 public class AnnotationPresetTest extends TestCase { … … 55 58 assertEquals("highway", key.value); 56 59 } 60 61 public void testIconLoadsFromClasspath() throws Exception { 62 String xml = "<annotations><item icon='logo'></item></annotations>"; 63 List<AnnotationPreset> all = AnnotationPreset.readAll(new ByteArrayInputStream(xml.getBytes())); 64 65 assertEquals(1, all.size()); 66 67 Icon icon = (Icon)all.get(0).getValue(Action.SMALL_ICON); 68 assertNotNull(icon); 69 assertEquals("Icon loaded and of correct size", 70 24, Math.max(icon.getIconHeight(), icon.getIconWidth())); 71 } 57 72 }
Note:
See TracChangeset
for help on using the changeset viewer.