Changeset 255 in josm


Ignore:
Timestamp:
2007-06-13T22:30:51+02:00 (17 years ago)
Author:
imi
Message:
  • fixed AnnotationPreset image loading to load from .jar-ressources as well
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/gui/annotation/AnnotationPreset.java

    r212 r255  
    3535import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3636import org.openstreetmap.josm.tools.GBC;
     37import org.openstreetmap.josm.tools.ImageProvider;
    3738import org.openstreetmap.josm.tools.XmlObjectParser;
    3839import org.xml.sax.SAXException;
     
    5455                boolean requestFocusInWindow() {return false;}
    5556        }
    56        
     57
    5758        public static class Text extends Item {
    5859                public String key;
     
    8182                public String text;
    8283                public boolean default_ = false;
    83                
     84
    8485                private JCheckBox check = new JCheckBox();
    8586
     
    143144
    144145        /**
    145     * The types as preparsed collection.
    146     */
    147     public Collection<Class<?>> types;
     146        * The types as preparsed collection.
     147        */
     148        public Collection<Class<?>> types;
    148149        private List<Item> data = new LinkedList<Item>();
    149150
     
    166167         * Called from the XML parser to set the icon
    167168         */
    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
    172178        /**
    173179         * Called from the XML parser to set the types, this preset affects
     
    186192                }
    187193        }
    188        
     194
    189195        public static List<AnnotationPreset> readAll(InputStream inStream) throws SAXException {
    190196                BufferedReader in = null;
  • src/org/openstreetmap/josm/tools/ImageProvider.java

    r243 r255  
    6969                if (name == null)
    7070                        return null;
    71                 if (subdir == null || subdir != "")
     71                if (subdir == null)
     72                        subdir = "";
     73                else
    7274                        subdir += "/";
    7375                String ext = name.indexOf('.') != -1 ? "" : ".png";
  • test/org/openstreetmap/josm/gui/annotation/AnnotationPresetTest.java

    r193 r255  
    11package org.openstreetmap.josm.gui.annotation;
    22
     3import java.io.ByteArrayInputStream;
    34import java.io.InputStream;
    45import java.lang.reflect.Field;
     
    67
    78import javax.swing.Action;
     9import javax.swing.Icon;
    810
    911import junit.framework.TestCase;
     
    1416import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Label;
    1517import org.openstreetmap.josm.gui.annotation.AnnotationPreset.Text;
     18import org.openstreetmap.josm.tools.ImageProvider;
    1619
    1720public class AnnotationPresetTest extends TestCase {
     
    5558                assertEquals("highway", key.value);
    5659        }
     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    }
    5772}
Note: See TracChangeset for help on using the changeset viewer.