Changeset 6690 in josm for trunk/src


Ignore:
Timestamp:
2014-01-15T15:47:45+01:00 (10 years ago)
Author:
Don-vip
Message:

code/javadoc cleanup in imagery code

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r6364 r6690  
    3131public class ImageryInfo implements Comparable<ImageryInfo>, Attributed {
    3232
     33    /**
     34     * Type of imagery entry.
     35     */
    3336    public enum ImageryType {
     37        /** A WMS (Web Map Service) entry. **/
    3438        WMS("wms"),
     39        /** A TMS (Tile Map Service) entry. **/
    3540        TMS("tms"),
     41        /** An HTML proxy (previously used for Yahoo imagery) entry. **/
    3642        HTML("html"),
     43        /** TMS entry for Microsoft Bing. */
    3744        BING("bing"),
     45        /** TMS entry for Russian company <a href="https://wiki.openstreetmap.org/wiki/WikiProject_Russia/kosmosnimki">ScanEx</a>. **/
    3846        SCANEX("scanex"),
     47        /** A WMS endpoint entry only stores the WMS server info, without layer, which are chosen later by the user. **/
    3948        WMS_ENDPOINT("wms_endpoint");
    4049
    41         private String urlString;
    42 
    43         ImageryType(String urlString) {
    44             this.urlString = urlString;
    45         }
    46 
    47         public String getUrlString() {
    48             return urlString;
    49         }
    50 
    51         public static ImageryType fromUrlString(String s) {
     50        private final String typeString;
     51
     52        private ImageryType(String urlString) {
     53            this.typeString = urlString;
     54        }
     55
     56        /**
     57         * Returns the unique string identifying this type.
     58         * @return the unique string identifying this type
     59         * @since 6690
     60         */
     61        public final String getTypeString() {
     62            return typeString;
     63        }
     64
     65        /**
     66         * Returns the imagery type from the given type string.
     67         * @param s The type string
     68         * @return the imagery type matching the given type string
     69         */
     70        public static ImageryType fromString(String s) {
    5271            for (ImageryType type : ImageryType.values()) {
    53                 if (type.getUrlString().equals(s)) {
     72                if (type.getTypeString().equals(s)) {
    5473                    return type;
    5574                }
     
    5978    }
    6079
     80    /**
     81     * Multi-polygon bounds for imagery backgrounds.
     82     * Used to display imagery coverage in preferences and to determine relevant imagery entries based on edit location.
     83     */
    6184    public static class ImageryBounds extends Bounds {
     85       
     86        /**
     87         * Constructs a new {@code ImageryBounds} from string.
     88         * @param asString The string containing the list of shapes defining this bounds
     89         * @param separator The shape separator in the given string, usually a comma
     90         */
    6291        public ImageryBounds(String asString, String separator) {
    6392            super(asString, separator);
     
    6695        private List<Shape> shapes = new ArrayList<Shape>();
    6796
    68         public void addShape(Shape shape) {
     97        /**
     98         * Adds a new shape to this bounds.
     99         * @param shape The shape to add
     100         */
     101        public final void addShape(Shape shape) {
    69102            this.shapes.add(shape);
    70103        }
    71104
    72         public void setShapes(List<Shape> shapes) {
     105        /**
     106         * Sets the list of shapes defining this bounds.
     107         * @param shapes The list of shapes defining this bounds.
     108         */
     109        public final void setShapes(List<Shape> shapes) {
    73110            this.shapes = shapes;
    74111        }
    75112
    76         public List<Shape> getShapes() {
     113        /**
     114         * Returns the list of shapes defining this bounds.
     115         * @return The list of shapes defining this bounds
     116         */
     117        public final List<Shape> getShapes() {
    77118            return shapes;
    78119        }
     
    125166    // when adding a field, also adapt the ImageryInfo(ImageryInfo) constructor
    126167
    127     /** auxiliary class to save an ImageryInfo object in the preferences */
     168    /**
     169     * Auxiliary class to save an {@link ImageryInfo} object in the preferences.
     170     */
    128171    public static class ImageryPreferenceEntry {
    129172        @pref String name;
     
    148191
    149192        /**
    150          * Constructs a new {@code ImageryPreferenceEntry}.
     193         * Constructs a new empty WMS {@code ImageryPreferenceEntry}.
    151194         */
    152195        public ImageryPreferenceEntry() {
    153196        }
    154197
     198        /**
     199         * Constructs a new {@code ImageryPreferenceEntry} from a given {@code ImageryInfo}.
     200         * @param i The corresponding imagery info
     201         */
    155202        public ImageryPreferenceEntry(ImageryInfo i) {
    156203            name = i.name;
    157             type = i.imageryType.getUrlString();
     204            type = i.imageryType.getTypeString();
    158205            url = i.url;
    159206            pixel_per_eastnorth = i.pixelPerDegree;
     
    202249
    203250    /**
    204      * Constructs a new {@code ImageryInfo}.
     251     * Constructs a new WMS {@code ImageryInfo}.
    205252     */
    206253    public ImageryInfo() {
    207254    }
    208255
     256    /**
     257     * Constructs a new WMS {@code ImageryInfo} with a given name.
     258     * @param name The entry name
     259     */
    209260    public ImageryInfo(String name) {
    210261        this.name=name;
    211262    }
    212263
     264    /**
     265     * Constructs a new WMS {@code ImageryInfo} with given name and extended URL.
     266     * @param name The entry name
     267     * @param url The entry extended URL
     268     */
    213269    public ImageryInfo(String name, String url) {
    214270        this.name=name;
     
    216272    }
    217273
     274    /**
     275     * Constructs a new WMS {@code ImageryInfo} with given name, extended and EULA URLs.
     276     * @param name The entry name
     277     * @param url The entry URL
     278     * @param eulaAcceptanceRequired The EULA URL
     279     */
    218280    public ImageryInfo(String name, String url, String eulaAcceptanceRequired) {
    219281        this.name=name;
     
    222284    }
    223285
    224     public ImageryInfo(String name, String url, String eulaAcceptanceRequired, String cookies) {
    225         this.name=name;
    226         setExtendedUrl(url);
    227         this.cookies=cookies;
    228         this.eulaAcceptanceRequired = eulaAcceptanceRequired;
    229     }
    230 
    231286    public ImageryInfo(String name, String url, String type, String eulaAcceptanceRequired, String cookies) {
    232287        this.name=name;
    233288        setExtendedUrl(url);
    234         ImageryType t = ImageryType.fromUrlString(type);
     289        ImageryType t = ImageryType.fromString(type);
    235290        this.cookies=cookies;
    236291        this.eulaAcceptanceRequired = eulaAcceptanceRequired;
     
    240295    }
    241296
    242     public ImageryInfo(String name, String url, String cookies, double pixelPerDegree) {
    243         this.name=name;
    244         setExtendedUrl(url);
    245         this.cookies=cookies;
    246         this.pixelPerDegree=pixelPerDegree;
    247     }
    248 
     297    /**
     298     * Constructs a new {@code ImageryInfo} from an imagery preference entry.
     299     * @param e The imagery preference entry
     300     */
    249301    public ImageryInfo(ImageryPreferenceEntry e) {
    250302        CheckParameterUtil.ensureParameterNotNull(e.name, "name");
     
    254306        cookies = e.cookies;
    255307        eulaAcceptanceRequired = e.eula;
    256         imageryType = ImageryType.fromUrlString(e.type);
     308        imageryType = ImageryType.fromString(e.type);
    257309        if (imageryType == null) throw new IllegalArgumentException("unknown type");
    258310        pixelPerDegree = e.pixel_per_eastnorth;
     
    284336    }
    285337
     338    /**
     339     * Constructs a new {@code ImageryInfo} from an existing one.
     340     * @param i The other imagery info
     341     */
    286342    public ImageryInfo(ImageryInfo i) {
    287343        this.name = i.name;
     
    338394
    339395    @Override
    340     public int compareTo(ImageryInfo in)
    341     {
     396    public int compareTo(ImageryInfo in) {
    342397        int i = countryCode.compareTo(in.countryCode);
    343398        if (i == 0) {
     
    353408    }
    354409
    355     public boolean equalsBaseValues(ImageryInfo in)
    356     {
     410    public boolean equalsBaseValues(ImageryInfo in) {
    357411        return url.equals(in.url);
    358412    }
     
    362416    }
    363417
     418    /**
     419     * Sets the maximum zoom level.
     420     * @param defaultMaxZoom The maximum zoom level
     421     */
    364422    public void setDefaultMaxZoom(int defaultMaxZoom) {
    365423        this.defaultMaxZoom = defaultMaxZoom;
    366424    }
    367425
     426    /**
     427     * Sets the minimum zoom level.
     428     * @param defaultMinZoom The minimum zoom level
     429     */
    368430    public void setDefaultMinZoom(int defaultMinZoom) {
    369431        this.defaultMinZoom = defaultMinZoom;
    370432    }
    371433
     434    /**
     435     * Sets the imagery polygonial bounds.
     436     * @param b The imagery bounds (non-rectangular)
     437     */
    372438    public void setBounds(ImageryBounds b) {
    373439        this.bounds = b;
    374440    }
    375441
     442    /**
     443     * Returns the imagery polygonial bounds.
     444     * @return The imagery bounds (non-rectangular)
     445     */
    376446    public ImageryBounds getBounds() {
    377447        return bounds;
     
    441511    }
    442512
     513    /**
     514     * Sets the extended URL of this entry.
     515     * @param url Entry extended URL containing in addition of service URL, its type and min/max zoom info
     516     */
    443517    public void setExtendedUrl(String url) {
    444518        CheckParameterUtil.ensureParameterNotNull(url);
     
    451525        defaultMinZoom = 0;
    452526        for (ImageryType type : ImageryType.values()) {
    453             Matcher m = Pattern.compile(type.getUrlString()+"(?:\\[(?:(\\d+),)?(\\d+)\\])?:(.*)").matcher(url);
     527            Matcher m = Pattern.compile(type.getTypeString()+"(?:\\[(?:(\\d+),)?(\\d+)\\])?:(.*)").matcher(url);
    454528            if (m.matches()) {
    455529                this.url = m.group(3);
     
    479553    }
    480554
     555    /**
     556     * Returns the entry name.
     557     * @return The entry name
     558     */
    481559    public String getName() {
    482560        return this.name;
    483561    }
    484562
     563    /**
     564     * Sets the entry name.
     565     * @param name The entry name
     566     */
    485567    public void setName(String name) {
    486568        this.name = name;
    487569    }
    488570
     571    /**
     572     * Returns the entry URL.
     573     * @return The entry URL
     574     */
    489575    public String getUrl() {
    490576        return this.url;
    491577    }
    492578
     579    /**
     580     * Sets the entry URL.
     581     * @param url The entry URL
     582     */
    493583    public void setUrl(String url) {
    494584        this.url = url;
    495585    }
    496586
     587    /**
     588     * Determines if this entry is enabled by default.
     589     * @return {@code true} if this entry is enabled by default, {@code false} otherwise
     590     */
    497591    public boolean isDefaultEntry() {
    498592        return defaultEntry;
    499593    }
    500594
     595    /**
     596     * Sets the default state of this entry.
     597     * @param defaultEntry {@code true} if this entry has to be enabled by default, {@code false} otherwise
     598     */
    501599    public void setDefaultEntry(boolean defaultEntry) {
    502600        this.defaultEntry = defaultEntry;
     
    511609    }
    512610
     611    /**
     612     * Returns the maximum zoom level.
     613     * @return The maximum zoom level
     614     */
    513615    public int getMaxZoom() {
    514616        return this.defaultMaxZoom;
    515617    }
    516618
     619    /**
     620     * Returns the minimum zoom level.
     621     * @return The minimum zoom level
     622     */
    517623    public int getMinZoom() {
    518624        return this.defaultMinZoom;
    519625    }
    520626
     627    /**
     628     * Returns the EULA acceptance URL, if any.
     629     * @return The URL to an EULA text that has to be accepted before use, or {@code null}
     630     */
    521631    public String getEulaAcceptanceRequired() {
    522632        return eulaAcceptanceRequired;
    523633    }
    524634
     635    /**
     636     * Sets the EULA acceptance URL.
     637     * @param eulaAcceptanceRequired The URL to an EULA text that has to be accepted before use
     638     */
    525639    public void setEulaAcceptanceRequired(String eulaAcceptanceRequired) {
    526640        this.eulaAcceptanceRequired = eulaAcceptanceRequired;
    527641    }
    528642
     643    /**
     644     * Returns the ISO 3166-1-alpha-2 country code.
     645     * @return The country code (2 letters)
     646     */
    529647    public String getCountryCode() {
    530648        return countryCode;
    531649    }
    532650
     651    /**
     652     * Sets the ISO 3166-1-alpha-2 country code.
     653     * @param countryCode The country code (2 letters)
     654     */
    533655    public void setCountryCode(String countryCode) {
    534656        this.countryCode = countryCode;
    535657    }
    536658
     659    /**
     660     * Returns the entry icon.
     661     * @return The entry icon
     662     */
    537663    public String getIcon() {
    538664        return icon;
    539665    }
    540666
     667    /**
     668     * Sets the entry icon.
     669     * @param icon The entry icon
     670     */
    541671    public void setIcon(String icon) {
    542672        this.icon = icon;
     
    559689    }
    560690
     691    /**
     692     * Returns the extended URL, containing in addition of service URL, its type and min/max zoom info.
     693     * @return The extended URL
     694     */
    561695    public String getExtendedUrl() {
    562         return imageryType.getUrlString() + (defaultMaxZoom != 0
     696        return imageryType.getTypeString() + (defaultMaxZoom != 0
    563697            ? "["+(defaultMinZoom != 0 ? defaultMinZoom+",":"")+defaultMaxZoom+"]" : "") + ":" + url;
    564698    }
    565699
    566     public String getToolbarName()
    567     {
     700    public String getToolbarName() {
    568701        String res = name;
    569702        if(pixelPerDegree != 0.0) {
     
    573706    }
    574707
    575     public String getMenuName()
    576     {
     708    public String getMenuName() {
    577709        String res = name;
    578710        if(pixelPerDegree != 0.0) {
     
    582714    }
    583715
    584     public boolean hasAttribution()
    585     {
     716    /**
     717     * Determines if this entry requires attribution.
     718     * @return {@code true} if some attribution text has to be displayed, {@code false} otherwise
     719     */
     720    public boolean hasAttribution() {
    586721        return attributionText != null;
    587722    }
    588723
    589     public void copyAttribution(ImageryInfo i)
    590     {
     724    /**
     725     * Copies attribution from another {@code ImageryInfo}.
     726     * @param i The other imagery info to get attribution from
     727     */
     728    public void copyAttribution(ImageryInfo i) {
    591729        this.attributionImage = i.attributionImage;
    592730        this.attributionImageURL = i.attributionImageURL;
     
    598736
    599737    /**
    600      * Applies the attribution from this object to a TMSTileSource.
     738     * Applies the attribution from this object to a tile source.
     739     * @param s The tile source
    601740     */
    602741    public void setAttribution(AbstractTileSource s) {
     
    636775    }
    637776
     777    /**
     778     * Returns the imagery type.
     779     * @return The imagery type
     780     */
    638781    public ImageryType getImageryType() {
    639782        return imageryType;
    640783    }
    641784
     785    /**
     786     * Sets the imagery type.
     787     * @param imageryType The imagery type
     788     */
    642789    public void setImageryType(ImageryType imageryType) {
    643790        this.imageryType = imageryType;
     
    647794     * Returns true if this layer's URL is matched by one of the regular
    648795     * expressions kept by the current OsmApi instance.
     796     * @return {@code true} is this entry is blacklisted, {@code false} otherwise
    649797     */
    650798    public boolean isBlacklisted() {
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java

    r6529 r6690  
    525525                    ImageryInfo info = defaultModel.getRow(line);
    526526
    527                     // Check if an entry with exactly the same values already
    528                     // exists
     527                    // Check if an entry with exactly the same values already exists
    529528                    for (int j = 0; j < activeModel.getRowCount(); j++) {
    530529                        if (info.equalsBaseValues(activeModel.getRow(j))) {
     
    572571         */
    573572        public class ImageryLayerTableModel extends DefaultTableModel {
     573            /**
     574             * Constructs a new {@code ImageryLayerTableModel}.
     575             */
    574576            public ImageryLayerTableModel() {
    575577                setColumnIdentifiers(new String[] { tr("Menu Name"), tr("Imagery URL")});
    576578            }
    577579
     580            /**
     581             * Returns the imagery info at the given row number.
     582             * @param row The row number
     583             * @return The imagery info at the given row number
     584             */
    578585            public ImageryInfo getRow(int row) {
    579586                return layerInfo.getLayers().get(row);
    580587            }
    581588
     589            /**
     590             * Adds a new imagery info as the last row.
     591             * @param i The imagery info to add
     592             */
    582593            public void addRow(ImageryInfo i) {
    583594                layerInfo.add(i);
     
    636647         */
    637648        public class ImageryDefaultLayerTableModel extends DefaultTableModel {
     649            /**
     650             * Constructs a new {@code ImageryDefaultLayerTableModel}.
     651             */
    638652            public ImageryDefaultLayerTableModel() {
    639653                setColumnIdentifiers(new String[]{"", tr("Menu Name (Default)"), tr("Imagery URL (Default)")});
    640654            }
    641655
     656            /**
     657             * Returns the imagery info at the given row number.
     658             * @param row The row number
     659             * @return The imagery info at the given row number
     660             */
    642661            public ImageryInfo getRow(int row) {
    643662                return layerInfo.getDefaultLayers().get(row);
     
    834853    }
    835854
     855    /**
     856     * Initializes imagery preferences.
     857     */
    836858    public static void initialize() {
    837859        ImageryLayerInfo.instance.clear();
  • trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java

    r6650 r6690  
    206206                    boolean found = false;
    207207                    for (ImageryType type : ImageryType.values()) {
    208                         if (equal(accumulator.toString(), type.getUrlString())) {
     208                        if (equal(accumulator.toString(), type.getTypeString())) {
    209209                            entry.setImageryType(type);
    210210                            found = true;
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java

    r6536 r6690  
    123123            @Override
    124124            public String apply(ImageryInfo.ImageryType x) {
    125                 return x.getUrlString();
     125                return x.getTypeString();
    126126            }
    127127        }));
Note: See TracChangeset for help on using the changeset viewer.