Ignore:
Timestamp:
2013-08-14T13:12:50+02:00 (11 years ago)
Author:
bastiK
Message:

fixed #8686 - Allow ZIP files whose paths are relative to the ZIP root in JOSM's map styling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java

    r6070 r6148  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.gui.preferences;
     3
     4import static org.openstreetmap.josm.tools.Utils.equal;
    35
    46import java.io.File;
    57import java.util.regex.Matcher;
    68import java.util.regex.Pattern;
    7 
    8 import static org.openstreetmap.josm.tools.Utils.equal;
    99
    1010/**
     
    1919     */
    2020    public String url;
     21
     22    /**
     23     * Indicates, that {@link #url} is a zip file and the resource is
     24     * inside the zip file.
     25     */
     26    public boolean isZip;
     27
     28    /**
     29     * If {@link #isZip} is true, denotes the path inside the zip file.
     30     */
     31    public String zipEntryPath;
    2132
    2233    /**
     
    4253    public boolean active;
    4354
    44     public SourceEntry(String url, String name, String title, Boolean active) {
     55    public SourceEntry(String url, boolean isZip, String zipEntryPath, String name, String title, boolean active) {
    4556        this.url = url;
     57        this.isZip = isZip;
     58        this.zipEntryPath = equal(zipEntryPath, "") ? null : zipEntryPath;
    4659        this.name = equal(name, "") ? null : name;
    4760        this.title = equal(title, "") ? null : title;
     
    4962    }
    5063
     64    public SourceEntry(String url, String name, String title, Boolean active) {
     65        this(url, false, null, name, title, active);
     66    }
     67
    5168    public SourceEntry(SourceEntry e) {
    5269        this.url = e.url;
     70        this.isZip = e.isZip;
     71        this.zipEntryPath = e.zipEntryPath;
    5372        this.name = e.name;
    5473        this.title = e.title;
     
    6281        final SourceEntry other = (SourceEntry) obj;
    6382        return equal(other.url, url) &&
     83                other.isZip == isZip &&
     84                equal(other.zipEntryPath, zipEntryPath) &&
    6485                equal(other.name, name) &&
    6586                equal(other.title, title) &&
     
    7192        int hash = 5;
    7293        hash = 89 * hash + (this.url != null ? this.url.hashCode() : 0);
     94        hash = 89 * hash + (this.isZip ? 1 : 0);
     95        hash = 89 * hash + (this.zipEntryPath != null ? this.zipEntryPath.hashCode() : 0);
    7396        hash = 89 * hash + (this.name != null ? this.name.hashCode() : 0);
    7497        hash = 89 * hash + (this.title != null ? this.title.hashCode() : 0);
     
    133156        return dir.getPath();
    134157    }
     158
     159    /**
     160     * Returns the parent directory of the resource inside the zip file.
     161     * @return null, if zipEntryPath is null, otherwise the parent directory of
     162     * the resource inside the zip file
     163     */
     164    public String getZipEntryDirName() {
     165        if (zipEntryPath == null) return null;
     166        return new File(zipEntryPath).getParent().toString();
     167    }
    135168}
Note: See TracChangeset for help on using the changeset viewer.