source: osm/applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/RelationFixer.java

Last change on this file was 36483, checked in by stoecker, 13 days ago

set eol-style, fix checkstyle issues, add ignores

  • Property svn:eol-style set to native
File size: 2.7 KB
RevLine 
[32395]1// License: GPL. For details, see LICENSE file.
[28693]2package relcontext.relationfix;
3
[28703]4import static org.openstreetmap.josm.tools.I18n.tr;
5
[34551]6import java.util.ArrayList;
7import java.util.Arrays;
8import java.util.List;
[28693]9
[28703]10import javax.swing.Action;
11
[28693]12import org.openstreetmap.josm.command.Command;
13import org.openstreetmap.josm.data.osm.Relation;
14
[28703]15import relcontext.actions.SortAndFixAction;
16
[28693]17public abstract class RelationFixer {
[28703]18
[36102]19 private final List<String> applicableTypes;
[30738]20 private SortAndFixAction sortAndFixAction;
[28703]21
[30738]22 /**
23 * Construct new RelationFixer by a list of applicable types
[32395]24 * @param types types
[30738]25 */
26 public RelationFixer(String... types) {
27 applicableTypes = new ArrayList<>();
[33311]28 applicableTypes.addAll(Arrays.asList(types));
[30738]29 }
[28703]30
[30738]31 /**
32 * Check if given relation is of needed type. You may override this method to check first type
33 * and then check desired relation properties.
34 * Note that this only verifies if current RelationFixer can be used to check and fix given relation
[32395]35 * Deeper relation checking is at {@link #isRelationGood}
[30738]36 *
37 * @param rel Relation to check
38 * @return true if relation can be verified by current RelationFixer
39 */
40 public boolean isFixerApplicable(Relation rel) {
41 if (rel == null)
42 return false;
43 if (!rel.hasKey("type"))
44 return false;
[28703]45
[30738]46 String type = rel.get("type");
[32395]47 for (String oktype: applicableTypes) {
[30738]48 if (oktype.equals(type))
49 return true;
[32395]50 }
[28703]51
[30738]52 return false;
53 }
[28703]54
[30738]55 /**
56 * Check if given relation is OK. That means if all roles are given properly, all tags exist as expected etc.
57 * Should be written in children classes.
58 *
59 * @param rel Relation to verify
60 * @return true if given relation is OK
61 */
62 public abstract boolean isRelationGood(Relation rel);
[28703]63
[30738]64 /**
65 * Fix relation and return new relation with fixed tags, roles etc.
66 * Note that is not obligatory to return true for isRelationGood for new relation
67 *
68 * @param rel Relation to fix
69 * @return command that fixes the relation {@code null} if it cannot be fixed or is already OK
70 */
71 public abstract Command fixRelation(Relation rel);
[28703]72
73 public void setFixAction(SortAndFixAction sortAndFixAction) {
74 this.sortAndFixAction = sortAndFixAction;
75 }
[32395]76
[28703]77 protected void setWarningMessage(String text) {
78 if (text == null) {
79 clearWarningMessage();
80 } else {
81 sortAndFixAction.putValue(Action.SHORT_DESCRIPTION, text);
82 }
83 }
[32395]84
[28703]85 protected void clearWarningMessage() {
86 sortAndFixAction.putValue(Action.SHORT_DESCRIPTION, tr("Fix roles of the chosen relation members"));
87 }
[28693]88}
Note: See TracBrowser for help on using the repository browser.