Ignore:
Timestamp:
2016-01-03T15:50:53+01:00 (8 years ago)
Author:
bastiK
Message:

move ElemStyle classes to new package, rename to (Style)Element

File:
1 edited

Legend:

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

    r9239 r9278  
    2323import org.openstreetmap.josm.gui.mappaint.StyleCache.StyleList;
    2424import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
     25import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement;
     26import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement;
     27import org.openstreetmap.josm.gui.mappaint.styleelement.LineElement;
     28import org.openstreetmap.josm.gui.mappaint.styleelement.LineTextElement;
     29import org.openstreetmap.josm.gui.mappaint.styleelement.NodeElement;
     30import org.openstreetmap.josm.gui.mappaint.styleelement.RepeatImageElement;
     31import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
     32import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel;
    2533import org.openstreetmap.josm.gui.util.GuiHelper;
    2634import org.openstreetmap.josm.tools.Pair;
     
    97105        if (osm instanceof Node && isDefaultNodes()) {
    98106            if (p.a.isEmpty()) {
    99                 if (TextElement.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {
    100                     p.a = NodeElemStyle.DEFAULT_NODE_STYLELIST_TEXT;
     107                if (TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {
     108                    p.a = NodeElement.DEFAULT_NODE_STYLELIST_TEXT;
    101109                } else {
    102                     p.a = NodeElemStyle.DEFAULT_NODE_STYLELIST;
     110                    p.a = NodeElement.DEFAULT_NODE_STYLELIST;
    103111                }
    104112            } else {
    105113                boolean hasNonModifier = false;
    106114                boolean hasText = false;
    107                 for (ElemStyle s : p.a) {
    108                     if (s instanceof BoxTextElemStyle) {
     115                for (StyleElement s : p.a) {
     116                    if (s instanceof BoxTextElement) {
    109117                        hasText = true;
    110118                    } else {
     
    115123                }
    116124                if (!hasNonModifier) {
    117                     p.a = new StyleList(p.a, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE);
     125                    p.a = new StyleList(p.a, NodeElement.SIMPLE_NODE_ELEMSTYLE);
    118126                    if (!hasText) {
    119                         if (TextElement.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {
    120                             p.a = new StyleList(p.a, BoxTextElemStyle.SIMPLE_NODE_TEXT_ELEMSTYLE);
     127                        if (TextLabel.AUTO_LABEL_COMPOSITION_STRATEGY.compose(osm) != null) {
     128                            p.a = new StyleList(p.a, BoxTextElement.SIMPLE_NODE_TEXT_ELEMSTYLE);
    121129                        }
    122130                    }
     
    125133        } else if (osm instanceof Way && isDefaultLines()) {
    126134            boolean hasProperLineStyle = false;
    127             for (ElemStyle s : p.a) {
     135            for (StyleElement s : p.a) {
    128136                if (s.isProperLineStyle()) {
    129137                    hasProperLineStyle = true;
     
    132140            }
    133141            if (!hasProperLineStyle) {
    134                 AreaElemStyle area = Utils.find(p.a, AreaElemStyle.class);
    135                 LineElemStyle line = area == null ? LineElemStyle.UNTAGGED_WAY : LineElemStyle.createSimpleLineStyle(area.color, true);
     142                AreaElement area = Utils.find(p.a, AreaElement.class);
     143                LineElement line = area == null ? LineElement.UNTAGGED_WAY : LineElement.createSimpleLineStyle(area.color, true);
    136144                p.a = new StyleList(p.a, line);
    137145            }
     
    197205                    boolean hasIndependentLineStyle = false;
    198206                    if (!isOuterWayOfSomeMP) { // do this only one time
    199                         List<ElemStyle> tmp = new ArrayList<>(p.a.size());
    200                         for (ElemStyle s : p.a) {
    201                             if (s instanceof AreaElemStyle) {
    202                                 wayColor = ((AreaElemStyle) s).color;
     207                        List<StyleElement> tmp = new ArrayList<>(p.a.size());
     208                        for (StyleElement s : p.a) {
     209                            if (s instanceof AreaElement) {
     210                                wayColor = ((AreaElement) s).color;
    203211                            } else {
    204212                                tmp.add(s);
     
    217225                            mpElemStyles = getStyleCacheWithRange(r, scale, nc);
    218226                        }
    219                         ElemStyle mpLine = null;
    220                         for (ElemStyle s : mpElemStyles.a) {
     227                        StyleElement mpLine = null;
     228                        for (StyleElement s : mpElemStyles.a) {
    221229                            if (s.isProperLineStyle()) {
    222230                                mpLine = s;
     
    229237                            break;
    230238                        } else if (wayColor == null && isDefaultLines()) {
    231                             AreaElemStyle mpArea = Utils.find(mpElemStyles.a, AreaElemStyle.class);
     239                            AreaElement mpArea = Utils.find(mpElemStyles.a, AreaElement.class);
    232240                            if (mpArea != null) {
    233241                                wayColor = mpArea.color;
     
    240248                if (isDefaultLines()) {
    241249                    boolean hasLineStyle = false;
    242                     for (ElemStyle s : p.a) {
     250                    for (StyleElement s : p.a) {
    243251                        if (s.isProperLineStyle()) {
    244252                            hasLineStyle = true;
     
    247255                    }
    248256                    if (!hasLineStyle) {
    249                         p.a = new StyleList(p.a, LineElemStyle.createSimpleLineStyle(wayColor, true));
     257                        p.a = new StyleList(p.a, LineElement.createSimpleLineStyle(wayColor, true));
    250258                    }
    251259                }
     
    265273                    p = generateStyles(osm, scale, false);
    266274                    boolean hasIndependentElemStyle = false;
    267                     for (ElemStyle s : p.a) {
    268                         if (s.isProperLineStyle() || s instanceof AreaElemStyle) {
     275                    for (StyleElement s : p.a) {
     276                        if (s.isProperLineStyle() || s instanceof AreaElement) {
    269277                            hasIndependentElemStyle = true;
    270278                            break;
     
    277285                            mpElemStyles = get(ref, scale, nc);
    278286                        }
    279                         for (ElemStyle mpS : mpElemStyles) {
    280                             if (mpS instanceof AreaElemStyle) {
    281                                 mpColor = ((AreaElemStyle) mpS).color;
     287                        for (StyleElement mpS : mpElemStyles) {
     288                            if (mpS instanceof AreaElement) {
     289                                mpColor = ((AreaElement) mpS).color;
    282290                                break;
    283291                            }
    284292                        }
    285                         p.a = new StyleList(p.a, LineElemStyle.createSimpleLineStyle(mpColor, true));
     293                        p.a = new StyleList(p.a, LineElement.createSimpleLineStyle(mpColor, true));
    286294                    }
    287295                    return p;
     
    292300            Pair<StyleList, Range> p = generateStyles(osm, scale, true);
    293301            if (drawMultipolygon && ((Relation) osm).isMultipolygon()) {
    294                 if (!Utils.exists(p.a, AreaElemStyle.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) {
     302                if (!Utils.exists(p.a, AreaElement.class) && Main.pref.getBoolean("multipolygon.deprecated.outerstyle", true)) {
    295303                    // look at outer ways to find area style
    296304                    Multipolygon multipolygon = MultipolygonCache.getInstance().get(nc, (Relation) osm);
     
    298306                        Pair<StyleList, Range> wayStyles = generateStyles(w, scale, false);
    299307                        p.b = Range.cut(p.b, wayStyles.b);
    300                         ElemStyle area = Utils.find(wayStyles.a, AreaElemStyle.class);
     308                        StyleElement area = Utils.find(wayStyles.a, AreaElement.class);
    301309                        if (area != null) {
    302310                            p.a = new StyleList(p.a, area);
     
    326334    public Pair<StyleList, Range> generateStyles(OsmPrimitive osm, double scale, boolean pretendWayIsClosed) {
    327335
    328         List<ElemStyle> sl = new ArrayList<>();
     336        List<StyleElement> sl = new ArrayList<>();
    329337        MultiCascade mc = new MultiCascade();
    330338        Environment env = new Environment(osm, mc, null, null);
     
    342350            env.layer = e.getKey();
    343351            if (osm instanceof Way) {
    344                 addIfNotNull(sl, AreaElemStyle.create(env));
    345                 addIfNotNull(sl, RepeatImageElemStyle.create(env));
    346                 addIfNotNull(sl, LineElemStyle.createLine(env));
    347                 addIfNotNull(sl, LineElemStyle.createLeftCasing(env));
    348                 addIfNotNull(sl, LineElemStyle.createRightCasing(env));
    349                 addIfNotNull(sl, LineElemStyle.createCasing(env));
    350                 addIfNotNull(sl, LineTextElemStyle.create(env));
     352                addIfNotNull(sl, AreaElement.create(env));
     353                addIfNotNull(sl, RepeatImageElement.create(env));
     354                addIfNotNull(sl, LineElement.createLine(env));
     355                addIfNotNull(sl, LineElement.createLeftCasing(env));
     356                addIfNotNull(sl, LineElement.createRightCasing(env));
     357                addIfNotNull(sl, LineElement.createCasing(env));
     358                addIfNotNull(sl, LineTextElement.create(env));
    351359            } else if (osm instanceof Node) {
    352                 NodeElemStyle nodeStyle = NodeElemStyle.create(env);
     360                NodeElement nodeStyle = NodeElement.create(env);
    353361                if (nodeStyle != null) {
    354362                    sl.add(nodeStyle);
    355                     addIfNotNull(sl, BoxTextElemStyle.create(env, nodeStyle.getBoxProvider()));
     363                    addIfNotNull(sl, BoxTextElement.create(env, nodeStyle.getBoxProvider()));
    356364                } else {
    357                     addIfNotNull(sl, BoxTextElemStyle.create(env, NodeElemStyle.SIMPLE_NODE_ELEMSTYLE_BOXPROVIDER));
     365                    addIfNotNull(sl, BoxTextElement.create(env, NodeElement.SIMPLE_NODE_ELEMSTYLE_BOXPROVIDER));
    358366                }
    359367            } else if (osm instanceof Relation) {
    360368                if (((Relation) osm).isMultipolygon()) {
    361                     addIfNotNull(sl, AreaElemStyle.create(env));
    362                     addIfNotNull(sl, RepeatImageElemStyle.create(env));
    363                     addIfNotNull(sl, LineElemStyle.createLine(env));
    364                     addIfNotNull(sl, LineElemStyle.createCasing(env));
    365                     addIfNotNull(sl, LineTextElemStyle.create(env));
     369                    addIfNotNull(sl, AreaElement.create(env));
     370                    addIfNotNull(sl, RepeatImageElement.create(env));
     371                    addIfNotNull(sl, LineElement.createLine(env));
     372                    addIfNotNull(sl, LineElement.createCasing(env));
     373                    addIfNotNull(sl, LineTextElement.create(env));
    366374                } else if ("restriction".equals(osm.get("type"))) {
    367                     addIfNotNull(sl, NodeElemStyle.create(env));
     375                    addIfNotNull(sl, NodeElement.create(env));
    368376                }
    369377            }
     
    448456
    449457    /**
    450      * Returns the first AreaElemStyle for a given primitive.
     458     * Returns the first AreaElement for a given primitive.
    451459     * @param p the OSM primitive
    452460     * @param pretendWayIsClosed For styles that require the way to be closed,
    453461     * we pretend it is. This is useful for generating area styles from the (segmented)
    454462     * outer ways of a multipolygon.
    455      * @return first AreaElemStyle found or {@code null}.
    456      */
    457     public static AreaElemStyle getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) {
     463     * @return first AreaElement found or {@code null}.
     464     */
     465    public static AreaElement getAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) {
    458466        MapCSSStyleSource.STYLE_SOURCE_LOCK.readLock().lock();
    459467        try {
    460468            if (MapPaintStyles.getStyles() == null)
    461469                return null;
    462             for (ElemStyle s : MapPaintStyles.getStyles().generateStyles(p, 1.0, pretendWayIsClosed).a) {
    463                 if (s instanceof AreaElemStyle)
    464                     return (AreaElemStyle) s;
     470            for (StyleElement s : MapPaintStyles.getStyles().generateStyles(p, 1.0, pretendWayIsClosed).a) {
     471                if (s instanceof AreaElement)
     472                    return (AreaElement) s;
    465473            }
    466474            return null;
     
    471479
    472480    /**
    473      * Determines whether primitive has an AreaElemStyle.
     481     * Determines whether primitive has an AreaElement.
    474482     * @param p the OSM primitive
    475483     * @param pretendWayIsClosed For styles that require the way to be closed,
    476484     * we pretend it is. This is useful for generating area styles from the (segmented)
    477485     * outer ways of a multipolygon.
    478      * @return {@code true} if primitive has an AreaElemStyle
     486     * @return {@code true} if primitive has an AreaElement
    479487     */
    480488    public static boolean hasAreaElemStyle(OsmPrimitive p, boolean pretendWayIsClosed) {
     
    483491
    484492    /**
    485      * Determines whether primitive has <b>only</b> an AreaElemStyle.
     493     * Determines whether primitive has <b>only</b> an AreaElement.
    486494     * @param p the OSM primitive
    487      * @return {@code true} if primitive has only an AreaElemStyle
     495     * @return {@code true} if primitive has only an AreaElement
    488496     * @since 7486
    489497     */
     
    497505                return false;
    498506            }
    499             for (ElemStyle s : styles) {
    500                 if (!(s instanceof AreaElemStyle)) {
     507            for (StyleElement s : styles) {
     508                if (!(s instanceof AreaElement)) {
    501509                    return false;
    502510                }
Note: See TracChangeset for help on using the changeset viewer.