Changeset 6541 in josm for trunk


Ignore:
Timestamp:
2013-12-27T00:11:47+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #9447 - mappaint: display capacity as a name complement for labels

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/LabelCompositionStrategy.java

    r6070 r6541  
    2929 *   in the JOSM preferences
    3030 *   content of a tag whose name specified in the MapCSS style file, see the preference
    31  *   option <tt>mappaint.nameOrder</tt>.</li>
     31 *   options <tt>mappaint.nameOrder</tt> and <tt>mappaint.nameComplementOrder</tt>.</li>
    3232 * </ul>
    3333 * </p>
     
    163163        };
    164164
    165         private  List<String> nameTags = new ArrayList<String>();
     165        /**
     166         * The list of default name complement tags from which a label candidate is derived.
     167         * @since 6541
     168         */
     169        static public final String[] DEFAULT_NAME_COMPLEMENT_TAGS = {
     170            "capacity"
     171        };
     172
     173        private List<String> nameTags = new ArrayList<String>();
     174        private List<String> nameComplementTags = new ArrayList<String>();
    166175
    167176        /**
     
    177186        }
    178187
    179         /**
    180          * Sets the name tags to be looked up in order to build up the label
    181          *
    182          * @param nameTags the name tags. null values are ignore.
    183          */
    184         public void setNameTags(List<String> nameTags){
     188        private static List<String> buildNameTags(List<String> nameTags) {
    185189            if (nameTags == null) {
    186190                nameTags = Collections.emptyList();
    187191            }
    188             this.nameTags = new ArrayList<String>();
     192            ArrayList<String> result = new ArrayList<String>();
    189193            for(String tag: nameTags) {
    190194                if (tag == null) {
     
    195199                    continue;
    196200                }
    197                 this.nameTags.add(tag);
    198             }
    199         }
    200 
     201                result.add(tag);
     202            }
     203            return result;
     204        }
     205       
     206        /**
     207         * Sets the name tags to be looked up in order to build up the label.
     208         *
     209         * @param nameTags the name tags. null values are ignored.
     210         */
     211        public void setNameTags(List<String> nameTags){
     212            this.nameTags = buildNameTags(nameTags);
     213        }
     214
     215        /**
     216         * Sets the name complement tags to be looked up in order to build up the label.
     217         *
     218         * @param nameComplementTags the name complement tags. null values are ignored.
     219         * @since 6541
     220         */
     221        public void setNameComplementTags(List<String> nameComplementTags){
     222            this.nameComplementTags = buildNameTags(nameComplementTags);
     223        }
     224       
    201225        /**
    202226         * Replies an unmodifiable list of the name tags used to compose the label.
     
    209233
    210234        /**
     235         * Replies an unmodifiable list of the name complement tags used to compose the label.
     236         *
     237         * @return the list of name complement tags
     238         * @since 6541
     239         */
     240        public List<String> getNameComplementTags() {
     241            return Collections.unmodifiableList(nameComplementTags);
     242        }
     243
     244        /**
    211245         * Initializes the name tags to use from a list of default name tags (see
    212          * {@link #DEFAULT_NAME_TAGS}) and from name tags configured in the preferences
    213          * using the preference key <tt>mappaint.nameOrder</tt>.
     246         * {@link #DEFAULT_NAME_TAGS} and {@link #DEFAULT_NAME_COMPLEMENT_TAGS})
     247         * and from name tags configured in the preferences using the keys
     248         * <tt>mappaint.nameOrder</tt> and <tt>mappaint.nameComplementOrder</tt>.
    214249         */
    215250        public void initNameTagsFromPreferences() {
    216251            if (Main.pref == null){
    217252                this.nameTags = new ArrayList<String>(Arrays.asList(DEFAULT_NAME_TAGS));
     253                this.nameComplementTags = new ArrayList<String>(Arrays.asList(DEFAULT_NAME_COMPLEMENT_TAGS));
    218254            } else {
    219255                this.nameTags = new ArrayList<String>(
    220256                        Main.pref.getCollection("mappaint.nameOrder", Arrays.asList(DEFAULT_NAME_TAGS))
     257                );
     258                this.nameComplementTags = new ArrayList<String>(
     259                        Main.pref.getCollection("mappaint.nameComplementOrder", Arrays.asList(DEFAULT_NAME_COMPLEMENT_TAGS))
    221260                );
    222261            }
     
    228267            for (String rn : nameTags) {
    229268                name = n.get(rn);
    230                 if (name != null) return name;
    231             }
    232             return null;
     269                if (name != null) {
     270                    break;
     271                }
     272            }
     273            for (String rn : nameComplementTags) {
     274                String comp = n.get(rn);
     275                if (comp != null) {
     276                    if (name == null) {
     277                        name = comp;
     278                    } else {
     279                        name += " (" + comp + ")";
     280                    }
     281                    break;
     282                }
     283            }
     284            return name;
    233285        }
    234286
  • trunk/src/org/openstreetmap/josm/tools/WindowGeometry.java

    r6530 r6541  
    342342     * @since 6522
    343343     */
    344     public Rectangle getVirtualScreenBounds() {
     344    public static Rectangle getVirtualScreenBounds() {
    345345        Rectangle virtualBounds = new Rectangle();
    346346        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
Note: See TracChangeset for help on using the changeset viewer.