Ignore:
Timestamp:
2012-09-11T09:55:54+02:00 (13 years ago)
Author:
larry0ua
Message:

'RelToolbox: added warning messages to the warning icon hint'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/reltoolbox/src/relcontext/relationfix/RelationFixer.java

    r28693 r28703  
    11package relcontext.relationfix;
     2
     3import static org.openstreetmap.josm.tools.I18n.tr;
    24
    35import java.util.ArrayList;
    46import java.util.List;
    57
     8import javax.swing.Action;
     9
    610import org.openstreetmap.josm.command.Command;
    711import org.openstreetmap.josm.data.osm.Relation;
    812
     13import relcontext.actions.SortAndFixAction;
     14
    915public abstract class RelationFixer {
    10        
     16
    1117        private List<String> applicableTypes;
    12        
    13         {
    14                 applicableTypes = new ArrayList<String>();
    15         }
     18        private SortAndFixAction sortAndFixAction;
     19
    1620        /**
    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
    2622         * @param types
    2723         */
    28         public RelationFixer(String[] types) {
     24        public RelationFixer(String... types) {
     25            applicableTypes = new ArrayList<String>();
    2926                for(String type: types) {
    3027                        applicableTypes.add(type);
    3128                }
    3229        }
    33        
     30
    3431        /**
    3532         * Check if given relation is of needed type. You may override this method to check first type
    3633         * and then check desired relation properties.
    3734         * 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         *
    4037         * @param rel Relation to check
    4138         * @return true if relation can be verified by current RelationFixer
     
    4643                if (!rel.hasKey("type"))
    4744                        return false;
    48                
     45
    4946                String type = rel.get("type");
    5047                for(String oktype: applicableTypes)
    51                         if (oktype.equals(type)) 
     48                        if (oktype.equals(type))
    5249                                return true;
    53                
     50
    5451                return false;
    5552        }
    56        
     53
    5754        /**
    5855         * Check if given relation is OK. That means if all roles are given properly, all tags exist as expected etc.
    5956         * Should be written in children classes.
    60          * 
     57         *
    6158         * @param rel Relation to verify
    6259         * @return true if given relation is OK
    6360         */
    6461        public abstract boolean isRelationGood(Relation rel);
    65        
     62
    6663        /**
    6764         * Fix relation and return new relation with fixed tags, roles etc.
    6865         * Note that is not obligatory to return true for isRelationGood for new relation
    69          * 
     66         *
    7067         * @param rel Relation to fix
    7168         * @return command that fixes the relation {@code null} if it cannot be fixed or is already OK
    7269         */
    7370        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
    7486}
Note: See TracChangeset for help on using the changeset viewer.