Changeset 28703 in osm for applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/RelationFixer.java
- Timestamp:
- 2012-09-11T09:55:54+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/RelationFixer.java
r28693 r28703 1 1 package relcontext.relationfix; 2 3 import static org.openstreetmap.josm.tools.I18n.tr; 2 4 3 5 import java.util.ArrayList; 4 6 import java.util.List; 5 7 8 import javax.swing.Action; 9 6 10 import org.openstreetmap.josm.command.Command; 7 11 import org.openstreetmap.josm.data.osm.Relation; 8 12 13 import relcontext.actions.SortAndFixAction; 14 9 15 public abstract class RelationFixer { 10 16 11 17 private List<String> applicableTypes; 12 13 { 14 applicableTypes = new ArrayList<String>(); 15 } 18 private SortAndFixAction sortAndFixAction; 19 16 20 /** 17 * Construct new RelationFixer by only one applicable relation type 18 * @param type 19 */ 20 public RelationFixer(String type) { 21 applicableTypes.add(type); 22 } 23 24 /** 25 * Construct new RelationFixer by an array of applicable types 21 * Construct new RelationFixer by a list of applicable types 26 22 * @param types 27 23 */ 28 public RelationFixer(String[] types) { 24 public RelationFixer(String... types) { 25 applicableTypes = new ArrayList<String>(); 29 26 for(String type: types) { 30 27 applicableTypes.add(type); 31 28 } 32 29 } 33 30 34 31 /** 35 32 * Check if given relation is of needed type. You may override this method to check first type 36 33 * and then check desired relation properties. 37 34 * Note that this only verifies if current RelationFixer can be used to check and fix given relation 38 * Deeper relation checking is at {@link isRelationGood} 39 * 35 * Deeper relation checking is at {@link isRelationGood} 36 * 40 37 * @param rel Relation to check 41 38 * @return true if relation can be verified by current RelationFixer … … 46 43 if (!rel.hasKey("type")) 47 44 return false; 48 45 49 46 String type = rel.get("type"); 50 47 for(String oktype: applicableTypes) 51 if (oktype.equals(type)) 48 if (oktype.equals(type)) 52 49 return true; 53 50 54 51 return false; 55 52 } 56 53 57 54 /** 58 55 * Check if given relation is OK. That means if all roles are given properly, all tags exist as expected etc. 59 56 * Should be written in children classes. 60 * 57 * 61 58 * @param rel Relation to verify 62 59 * @return true if given relation is OK 63 60 */ 64 61 public abstract boolean isRelationGood(Relation rel); 65 62 66 63 /** 67 64 * Fix relation and return new relation with fixed tags, roles etc. 68 65 * Note that is not obligatory to return true for isRelationGood for new relation 69 * 66 * 70 67 * @param rel Relation to fix 71 68 * @return command that fixes the relation {@code null} if it cannot be fixed or is already OK 72 69 */ 73 70 public abstract Command fixRelation(Relation rel); 71 72 public void setFixAction(SortAndFixAction sortAndFixAction) { 73 this.sortAndFixAction = sortAndFixAction; 74 } 75 protected void setWarningMessage(String text) { 76 if (text == null) { 77 clearWarningMessage(); 78 } else { 79 sortAndFixAction.putValue(Action.SHORT_DESCRIPTION, text); 80 } 81 } 82 protected void clearWarningMessage() { 83 sortAndFixAction.putValue(Action.SHORT_DESCRIPTION, tr("Fix roles of the chosen relation members")); 84 } 85 74 86 }
Note:
See TracChangeset
for help on using the changeset viewer.