Changeset 12378 in josm


Ignore:
Timestamp:
2017-06-09T22:13:45+02:00 (2 years ago)
Author:
michael2402
Message:

Document the gui.mappaint package

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
10 edited

Legend:

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

    r11388 r12378  
    4242    }
    4343
     44    /**
     45     * Gets the value for a given key with the given type
     46     * @param <T> the expected type
     47     * @param key the key
     48     * @param def default value, can be null
     49     * @param klass the same as T
     50     * @return if a value that can be converted to class klass has been mapped to key, returns this
     51     *      value, def otherwise
     52     */
    4453    public <T> T get(String key, T def, Class<T> klass) {
    4554        return get(key, def, klass, false);
     
    5463     * @param suppressWarnings show or don't show a warning when some value is
    5564     *      found, but cannot be converted to the requested type
    56      * @return if a value with class klass has been mapped to key, returns this
     65     * @return if a value that can be converted to class klass has been mapped to key, returns this
    5766     *      value, def otherwise
    5867     */
     
    7382    }
    7483
     84    /**
     85     * Gets a property for the given key (like stroke, ...)
     86     * @param key The key of the property
     87     * @return The value or <code>null</code> if it is not set. May be of any type
     88     */
    7589    public Object get(String key) {
    7690        return prop.get(key);
    7791    }
    7892
     93    /**
     94     * Sets the property for the given key
     95     * @param key The key
     96     * @param val The value
     97     */
    7998    public void put(String key, Object val) {
    8099        prop.put(key, val);
    81100    }
    82101
     102    /**
     103     * Sets the property for the given key, removes it if the value is <code>null</code>
     104     * @param key The key
     105     * @param val The value, may be <code>null</code>
     106     */
    83107    public void putOrClear(String key, Object val) {
    84108        if (val != null) {
     
    89113    }
    90114
     115    /**
     116     * Removes the property with the given key
     117     * @param key The key
     118     */
    91119    public void remove(String key) {
    92120        prop.remove(key);
    93121    }
    94122
     123    /**
     124     * Converts an object to a given other class.
     125     *
     126     * Only conversions that are useful for MapCSS are supported
     127     * @param <T> The class type
     128     * @param o The object to convert
     129     * @param klass The class
     130     * @return The converted object or <code>null</code> if the conversion failed
     131     */
    95132    @SuppressWarnings("unchecked")
    96133    public static <T> T convertTo(Object o, Class<T> klass) {
     
    235272    }
    236273
     274    /**
     275     * Checks if this cascade has a value for given key
     276     * @param key The key to check
     277     * @return <code>true</code> if there is a value
     278     */
    237279    public boolean containsKey(String key) {
    238280        return prop.containsKey(key);
    239281    }
    240282
     283    /**
     284     * Get if the default selection drawing should be used for the object this cascade applies to
     285     * @return <code>true</code> to use the default selection drawing
     286     */
    241287    public boolean isDefaultSelectedHandling() {
    242288        return defaultSelectedHandling;
    243289    }
    244290
     291    /**
     292     * Set that the default selection drawing should be used for the object this cascade applies to
     293     * @param defaultSelectedHandling <code>true</code> to use the default selection drawing
     294     */
    245295    public void setDefaultSelectedHandling(boolean defaultSelectedHandling) {
    246296        this.defaultSelectedHandling = defaultSelectedHandling;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Environment.java

    r9239 r12378  
    1515public class Environment {
    1616
     17    /**
     18     * The primitive that is currently evaluated
     19     */
    1720    public OsmPrimitive osm;
    1821
     22    /**
     23     * The cascades that are currently evaluated
     24     */
    1925    public MultiCascade mc;
     26    /**
     27     * The current MapCSS layer
     28     */
    2029    public String layer;
     30    /**
     31     * The style source that is evaluated
     32     */
    2133    public StyleSource source;
    2234    private Context context = Context.PRIMITIVE;
     35
     36    /**
     37     * The name of the default layer. It is used if no layer is specified in the MapCSS rule
     38     */
    2339    public static final String DEFAULT_LAYER = "default";
    2440
     
    228244    }
    229245
     246    /**
     247     * Gets the role of the matching primitive in the relation
     248     * @return The role
     249     */
    230250    public String getRole() {
    231251        if (getContext().equals(Context.PRIMITIVE))
     
    239259    }
    240260
     261    /**
     262     * Clears all matching context information
     263     */
    241264    public void clearSelectorMatchingInformation() {
    242265        parent = null;
     
    246269    }
    247270
     271    /**
     272     * Gets the current cascade for a given layer
     273     * @param layer The layer to use, <code>null</code> to use the layer of the {@link Environment}
     274     * @return The cascade
     275     */
    248276    public Cascade getCascade(String layer) {
    249277        return mc == null ? null : mc.getCascade(layer == null ? this.layer : layer);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Keyword.java

    r11137 r12378  
    1414 */
    1515public class Keyword {
     16    /**
     17     * The string value for this keyword
     18     */
    1619    public final String val;
    1720
     21    /**
     22     * Create a new Keyword
     23     * @param val The string value that is written in the MapCSS file
     24     */
    1825    public Keyword(String val) {
    1926        this.val = val.toLowerCase(Locale.ENGLISH);
     
    3845    }
    3946
     47    /**
     48     * Automated text positioning
     49     */
    4050    public static final Keyword AUTO = new Keyword("auto");
     51    /**
     52     * Align text at the bottom
     53     */
    4154    public static final Keyword BOTTOM = new Keyword("bottom");
     55    /**
     56     * Align text at the center
     57     */
    4258    public static final Keyword CENTER = new Keyword("center");
     59    /**
     60     * Use default line width
     61     */
    4362    public static final Keyword DEFAULT = new Keyword("default");
     63    /**
     64     * Align to the right
     65     */
    4466    public static final Keyword RIGHT = new Keyword("right");
     67    /**
     68     * Thinnest line width
     69     */
    4570    public static final Keyword THINNEST = new Keyword("thinnest");
    4671}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r12342 r12378  
    7777     */
    7878    public static class TagKeyReference {
     79        /**
     80         * The tag name
     81         */
    7982        public final String key;
    8083
     84        /**
     85         * Create a new {@link TagKeyReference}
     86         * @param key The tag name
     87         */
    8188        public TagKeyReference(String key) {
    8289            this.key = key;
     
    96103    public static class IconReference {
    97104
     105        /**
     106         * The name of the icon
     107         */
    98108        public final String iconName;
     109        /**
     110         * The style source this reference occurred in
     111         */
    99112        public final StyleSource source;
    100113
     114        /**
     115         * Create a new {@link IconReference}
     116         * @param iconName The icon name
     117         * @param source The current style source
     118         */
    101119        public IconReference(String iconName, StyleSource source) {
    102120            this.iconName = iconName;
     
    182200    }
    183201
     202    /**
     203     * Returns the node icon that would be displayed for the given tag.
     204     * @param tag The tag to look an icon for
     205     * @return {@code null} if no icon found
     206     */
    184207    public static ImageIcon getNodeIcon(Tag tag) {
    185208        return getNodeIcon(tag, true);
     
    225248    }
    226249
     250    /**
     251     * Gets the directories that should be searched for icons
     252     * @param source The style source the icon is from
     253     * @return A list of directory names
     254     */
    227255    public static List<String> getIconSourceDirs(StyleSource source) {
    228256        List<String> dirs = new LinkedList<>();
     
    323351    }
    324352
     353    /**
     354     * This class loads the map paint styles
     355     */
    325356    public static class MapPaintStyleLoader extends PleaseWaitRunnable {
    326357        private boolean canceled;
    327358        private final Collection<StyleSource> sources;
    328359
     360        /**
     361         * Create a new {@link MapPaintStyleLoader}
     362         * @param sources The styles to load
     363         */
    329364        public MapPaintStyleLoader(Collection<StyleSource> sources) {
    330365            super(tr("Reloading style sources"));
     
    396431    }
    397432
     433    /**
     434     * Check if the styles can be moved
     435     * @param sel The indexes of the selected styles
     436     * @param i The number of places to move the styles
     437     * @return <code>true</code> if that movement is possible
     438     */
    398439    public static boolean canMoveStyles(int[] sel, int i) {
    399440        if (sel.length == 0)
     
    410451    }
    411452
     453    /**
     454     * Toggles the active state of several styles
     455     * @param sel The style indexes
     456     */
    412457    public static void toggleStyleActive(int... sel) {
    413458        List<StyleSource> data = styles.getStyleSources();
     
    491536    }
    492537
     538    /**
     539     * Notifies all listeners that there was any update to the map paint styles
     540     */
    493541    public static void fireMapPaintSylesUpdated() {
    494542        listeners.fireEvent(MapPaintSylesUpdateListener::mapPaintStylesUpdated);
    495543    }
    496544
     545    /**
     546     * Notifies all listeners that there was an update to a specific map paint style
     547     * @param index The style index
     548     */
    497549    public static void fireMapPaintStyleEntryUpdated(int index) {
    498550        listeners.fireEvent(l -> l.mapPaintStyleEntryUpdated(index));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MultiCascade.java

    r11388 r12378  
    1717
    1818    private final Map<String, Cascade> layers;
     19    /**
     20     * The scale range this cascade is valid for
     21     */
    1922    public Range range;
    2023
     
    7477    }
    7578
     79    /**
     80     * Gets all cascades for the known layers
     81     * @return The cascades for the layers
     82     */
    7683    public Collection<Entry<String, Cascade>> getLayers() {
    7784        return layers.entrySet();
    7885    }
    7986
     87    /**
     88     * Check whether this cascade has a given layer
     89     * @param layer The layer to check for
     90     * @return <code>true</code> if it has that layer
     91     */
    8092    public boolean hasLayer(String layer) {
    8193        return layers.containsKey(layer);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/Range.java

    r11370 r12378  
    1313    private final double upper;
    1414
     15    /**
     16     * The full scale range from zero to infinity
     17     */
    1518    public static final Range ZERO_TO_INFINITY = new Range(0.0, Double.POSITIVE_INFINITY);
    1619
     
    2831    }
    2932
     33    /**
     34     * Check if a number is contained in this range
     35     * @param x The number to test
     36     * @return <code>true</code> if it is in this range
     37     */
    3038    public boolean contains(double x) {
    3139        return lower < x && x <= upper;
     
    7684    }
    7785
     86    /**
     87     * Gets the lower bound
     88     * @return The lower, exclusive, bound
     89     */
    7890    public double getLower() {
    7991        return lower;
    8092    }
    8193
     94    /**
     95     * Gets the upper bound
     96     * @return The upper, inclusive, bound
     97     */
    8298    public double getUpper() {
    8399        return upper;
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java

    r11781 r12378  
    1818    private static final Storage<StyleCache> internPool = new Storage<>();
    1919
     20    /**
     21     * An empty style cache entry
     22     */
    2023    public static final StyleCache EMPTY_STYLECACHE = (new StyleCache()).intern();
    2124
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleElementList.java

    r9669 r12378  
    2424    }
    2525
     26    /**
     27     * Create a new List of style elements
     28     * @param init The list
     29     */
    2630    public StyleElementList(StyleElement... init) {
    2731        lst = new ArrayList<>(Arrays.asList(init));
    2832    }
    2933
     34    /**
     35     * Create a new List of style elements
     36     * @param sl The list
     37     */
    3038    public StyleElementList(Collection<StyleElement> sl) {
    3139        lst = new ArrayList<>(sl);
    3240    }
    3341
     42    /**
     43     * Create a new List of style elements
     44     * @param sl The list
     45     * @param s An item to merge to the list
     46     */
    3447    public StyleElementList(StyleElementList sl, StyleElement s) {
    3548        lst = new ArrayList<>(sl.lst);
     
    4255    }
    4356
     57    /**
     58     * Check if the list is empty
     59     * @return <code>true</code> if it is empty
     60     */
    4461    public boolean isEmpty() {
    4562        return lst.isEmpty();
    4663    }
    4764
     65    /**
     66     * Get the list size
     67     * @return The list size
     68     */
    4869    public int size() {
    4970        return lst.size();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSetting.java

    r9966 r12378  
    3434public interface StyleSetting {
    3535
     36    /**
     37     * Adds the menu entry for this style setting to the menu
     38     * @param menu The menu to add the setting to
     39     */
    3640    void addMenuEntry(JMenu menu);
    3741
     42    /**
     43     * gets the value for this setting
     44     * @return The value the user selected
     45     */
    3846    Object getValue();
    3947
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r9334 r12378  
    3838    private final List<Throwable> errors = new CopyOnWriteArrayList<>();
    3939    private final Set<String> warnings = new CopyOnWriteArraySet<>();
     40    /**
     41     * The zip file containing the icons for this style
     42     */
    4043    public File zipIcons;
    4144
     
    245248    }
    246249
     250    /**
     251     * Gets the background color that was set in this style
     252     * @return The color or <code>null</code> if it was not set
     253     */
    247254    public Color getBackgroundColorOverride() {
    248255        return null;
Note: See TracChangeset for help on using the changeset viewer.