Changeset 4960 in josm


Ignore:
Timestamp:
2012-02-16T20:58:54+01:00 (8 years ago)
Author:
stoecker
Message:

mv jump to action from G to key J

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/JumpToAction.java

    r4139 r4960  
    3030    public JumpToAction() {
    3131        super(tr("Jump To Position"), null, tr("Opens a dialog that allows to jump to a specific location"), Shortcut.registerShortcut("tools:jumpto", tr("Tool: {0}", tr("Jump To Position")),
    32         KeyEvent.VK_G, Shortcut.GROUP_HOTKEY), false);
     32        KeyEvent.VK_J, Shortcut.GROUP_HOTKEY), false);
    3333        putValue("toolbar", "action/jumpto");
    3434        Main.toolbar.register(this);
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r4937 r4960  
    332332        locations.add("/usr/lib/josm/");
    333333        return locations;
    334     }
    335 
    336     @Deprecated
    337     synchronized public boolean hasKey(final String key) {
    338         return properties.containsKey(key);
    339334    }
    340335
  • trunk/src/org/openstreetmap/josm/gui/mappaint/AreaElemStyle.java

    r4822 r4960  
    1818import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    1919import org.openstreetmap.josm.tools.CheckParameterUtil;
    20 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;
    2120import org.openstreetmap.josm.tools.Utils;
    2221
     
    4544        IconReference iconRef = c.get("fill-image", null, IconReference.class);
    4645        if (iconRef != null) {
    47             ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1, SanitizeMode.MAKE_BUFFEREDIMAGE);
     46            ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1);
    4847            if (icon != null) {
    4948                if (!(icon.getImage() instanceof BufferedImage))
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r4936 r4960  
    2727import org.openstreetmap.josm.io.MirroredInputStream;
    2828import org.openstreetmap.josm.tools.ImageProvider;
    29 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;
    3029
    3130/**
     
    8988
    9089    public static ImageIcon getIcon(IconReference ref, int width, int height) {
    91         return getIcon(ref, width, height, SanitizeMode.OFF);
    92     }
    93 
    94     public static ImageIcon getIcon(IconReference ref, int width, int height, SanitizeMode sanitize) {
    9590        final String namespace = ref.source.getPrefName();
    9691        ImageIcon i = new ImageProvider(ref.iconName)
     
    10095                .setWidth(width)
    10196                .setHeight(height)
    102                 .setSanitize(sanitize)
    10397                .setOptional(true).get();
    10498        if(i == null)
     
    108102        }
    109103        return i;
    110     }
    111 
    112     public static ImageIcon getNoIcon_Icon(StyleSource source) {
    113         return getNoIcon_Icon(source, SanitizeMode.OFF);
    114104    }
    115105
     
    122112     *  can be null if the defaults are turned off by user
    123113     */
    124     public static ImageIcon getNoIcon_Icon(StyleSource source, SanitizeMode sanitize) {
     114    public static ImageIcon getNoIcon_Icon(StyleSource source) {
    125115        return new ImageProvider("misc/no_icon.png")
    126116                .setDirs(getIconSourceDirs(source))
    127117                .setId("mappaint."+source.getPrefName())
    128118                .setArchive(source.zipIcons)
    129                 .setSanitize(sanitize)
    130119                .setOptional(true).get();
    131120    }
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r4938 r4960  
    8585    }
    8686
    87     public static enum SanitizeMode {
    88         OFF,                // never sanitize the image
    89         ALWAYS,             // always copy to a new BufferedImage
    90         MAKE_BUFFEREDIMAGE  // make sure the returned image is instance of BufferedImage
    91     }
    92 
    9387    protected Collection<String> dirs;
    9488    protected String id;
     
    10094    protected int maxWidth = -1;
    10195    protected int maxHeight = -1;
    102     protected SanitizeMode sanitize;
    10396    protected boolean optional;
    10497
     
    204197    public ImageProvider setMaxHeight(int maxHeight) {
    205198        this.maxHeight = maxHeight;
    206         return this;
    207     }
    208 
    209     /**
    210      * Set true, if the image should be repainted to a new BufferedImage in order to work around certain issues.
    211      */
    212     public ImageProvider setSanitize(SanitizeMode sanitize) {
    213         this.sanitize = sanitize;
    214199        return this;
    215200    }
     
    240225        }
    241226        if (maxWidth != -1 || maxHeight != -1)
    242             return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight), sanitize);
     227            return ir.getImageIconBounded(new Dimension(maxWidth, maxHeight));
    243228        else
    244             return ir.getImageIcon(new Dimension(width, height), sanitize);
     229            return ir.getImageIcon(new Dimension(width, height));
    245230    }
    246231
     
    292277                    if (mediatype != null && mediatype.contains("image/svg+xml")) {
    293278                        URI uri = getSvgUniverse().loadSVG(new StringReader(new String(bytes)), name);
    294                         SVGDiagram svg = getSvgUniverse().getDiagram(uri);
    295                         return new ImageResource(svg);
     279                        return new ImageResource(getSvgUniverse().getDiagram(uri));
    296280                    } else {
    297                         return new ImageResource(new ImageIcon(bytes).getImage(), true);
     281                        return new ImageResource(new ImageIcon(bytes).getImage());
    298282                    }
    299283                }
     
    406390                        img = ImageIO.read(is.getFile().toURI().toURL());
    407391                    } catch (IOException e) {}
    408                     return img == null ? null : new ImageResource(img, true);
     392                    return img == null ? null : new ImageResource(img);
    409393                default:
    410394                    throw new AssertionError();
     
    475459                                img = ImageIO.read(new ByteArrayInputStream(buf));
    476460                            } catch (IOException e) {}
    477                             return img == null ? null : new ImageResource(img, false);
     461                            return img == null ? null : new ImageResource(img);
    478462                        default:
    479463                            throw new AssertionError();
     
    509493                    img = ImageIO.read(path);
    510494                } catch (IOException e) {}
    511                 return img == null ? null : new ImageResource(img, true);
     495                return img == null ? null : new ImageResource(img);
    512496            default:
    513497                throw new AssertionError();
     
    767751    }
    768752
    769     public static BufferedImage sanitize(Image img) {
    770         (new ImageIcon(img)).getImage(); // load competely
    771         int width = img.getWidth(null);
    772         int height = img.getHeight(null);
    773         BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    774         result.getGraphics().drawImage(img, 0, 0, null);
    775         return result;
    776     }
    777 
    778753    public static Image createImageFromSvg(SVGDiagram svg, Dimension dim) {
    779754        float realWidth = svg.getWidth();
  • trunk/src/org/openstreetmap/josm/tools/ImageResource.java

    r4824 r4960  
    99import java.util.HashMap;
    1010import javax.swing.ImageIcon;
    11 
    12 import org.openstreetmap.josm.tools.ImageProvider.SanitizeMode;
    1311
    1412/**
     
    2422     * Caches the image data for resized versions of the same image.
    2523     */
    26     private HashMap<Dimension, ImageWrapper> imgCache = new HashMap<Dimension, ImageWrapper>();
     24    private HashMap<Dimension, Image> imgCache = new HashMap<Dimension, Image>();
    2725    private SVGDiagram svg;
    2826    public static final Dimension DEFAULT_DIMENSION = new Dimension(-1, -1);
    2927 
    30     /**
    31      * remember whether the image has been sanitized
    32      */
    33     private static class ImageWrapper {
    34         Image img;
    35         boolean sanitized;
    36 
    37         public ImageWrapper(Image img, boolean sanitized) {
    38             CheckParameterUtil.ensureParameterNotNull(img);
    39             this.img = img;
    40             this.sanitized = sanitized;
    41         }
    42     }
    43    
    44     public ImageResource(Image img, boolean sanitized) {
     28    public ImageResource(Image img) {
    4529        CheckParameterUtil.ensureParameterNotNull(img);
    46         imgCache.put(DEFAULT_DIMENSION, new ImageWrapper(img, sanitized));
     30        imgCache.put(DEFAULT_DIMENSION, img);
    4731    }
    4832
     
    5337
    5438    public ImageIcon getImageIcon() {
    55         return getImageIcon(DEFAULT_DIMENSION, SanitizeMode.OFF);
     39        return getImageIcon(DEFAULT_DIMENSION);
    5640    }
    5741
     
    6145     *          and (width, -1) to set the width, but otherwise scale the image
    6246     *          proportionally.
    63      * @param sanitize Whether the returned image should be copied to a BufferedImage
    64      *          to avoid certain problem with native image formats.
    6547     */
    66     public ImageIcon getImageIcon(Dimension dim, SanitizeMode sanitize) {
     48    public ImageIcon getImageIcon(Dimension dim) {
    6749        if (dim.width < -1 || dim.width == 0 || dim.height < -1 || dim.height == 0)
    6850            throw new IllegalArgumentException();
    69         ImageWrapper iw = imgCache.get(dim);
    70         if (iw != null) {
    71             if (!iw.sanitized) {
    72                 if (sanitize == SanitizeMode.ALWAYS || (sanitize == SanitizeMode.MAKE_BUFFEREDIMAGE && !(iw.img instanceof BufferedImage))) {
    73                     iw.img = ImageProvider.sanitize(iw.img);
    74                     iw.sanitized = true;
    75                 }
    76             }
    77             return new ImageIcon(iw.img);
     51        Image img = imgCache.get(dim);
     52        if (img != null) {
     53            return new ImageIcon(img);
    7854        }
    7955        if (svg != null) {
    80             Image img = ImageProvider.createImageFromSvg(svg, dim);
    81             imgCache.put(dim, new ImageWrapper(img, true));
     56            img = ImageProvider.createImageFromSvg(svg, dim);
     57            imgCache.put(dim, img);
    8258            return new ImageIcon(img);
    8359        } else {
    84             ImageWrapper base = imgCache.get(DEFAULT_DIMENSION);
     60            Image base = imgCache.get(DEFAULT_DIMENSION);
    8561            if (base == null) throw new AssertionError();
    8662           
    8763            int width = dim.width;
    8864            int height = dim.height;
    89             ImageIcon icon = new ImageIcon(base.img);
     65            ImageIcon icon = new ImageIcon(base);
    9066            if (width == -1) {
    9167                width = icon.getIconWidth() * height / icon.getIconHeight();
     
    9369                height = icon.getIconHeight() * width / icon.getIconWidth();
    9470            }
    95             Image img;
    9671            img = icon.getImage().getScaledInstance(width, height, Image.SCALE_SMOOTH);
    97             boolean sanitized = false;
    98             if (sanitize == SanitizeMode.ALWAYS || (sanitize == SanitizeMode.MAKE_BUFFEREDIMAGE && !(img instanceof BufferedImage))) {
    99                 img = ImageProvider.sanitize(img);
    100                 sanitized = true;
    101             }
    102             imgCache.put(dim, new ImageWrapper(img, sanitized));
     72            imgCache.put(dim, img);
    10373            return new ImageIcon(img);
    10474        }
     
    11282     * which means it is not bounded.
    11383     */
    114     public ImageIcon getImageIconBounded(Dimension maxSize, SanitizeMode sanitize) {
     84    public ImageIcon getImageIconBounded(Dimension maxSize) {
    11585        if (maxSize.width < -1 || maxSize.width == 0 || maxSize.height < -1 || maxSize.height == 0)
    11686            throw new IllegalArgumentException();
     
    12191            realHeight = svg.getHeight();
    12292        } else {
    123             ImageWrapper base = imgCache.get(DEFAULT_DIMENSION);
     93            Image base = imgCache.get(DEFAULT_DIMENSION);
    12494            if (base == null) throw new AssertionError();
    125             ImageIcon icon = new ImageIcon(base.img);
     95            ImageIcon icon = new ImageIcon(base);
    12696            realWidth = icon.getIconWidth();
    12797            realHeight = icon.getIconHeight();
     
    138108
    139109        if (maxWidth == -1 && maxHeight == -1)
    140             return getImageIcon(DEFAULT_DIMENSION, sanitize);
     110            return getImageIcon(DEFAULT_DIMENSION);
    141111        else if (maxWidth == -1)
    142             return getImageIcon(new Dimension(-1, maxHeight), sanitize);
     112            return getImageIcon(new Dimension(-1, maxHeight));
    143113        else if (maxHeight == -1)
    144             return getImageIcon(new Dimension(maxWidth, -1), sanitize);
     114            return getImageIcon(new Dimension(maxWidth, -1));
    145115        else
    146116            if (realWidth / maxWidth > realHeight / maxHeight)
    147                 return getImageIcon(new Dimension(maxWidth, -1), sanitize);
     117                return getImageIcon(new Dimension(maxWidth, -1));
    148118            else
    149                 return getImageIcon(new Dimension(-1, maxHeight), sanitize);
     119                return getImageIcon(new Dimension(-1, maxHeight));
    150120   }
    151121}
Note: See TracChangeset for help on using the changeset viewer.