Changeset 20622 in osm for applications/editors


Ignore:
Timestamp:
2010-03-23T13:35:14+01:00 (14 years ago)
Author:
guggis
Message:

Additional tests for error cases (missing vias, ways to split, etc.)

Location:
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionEditor.java

    r20586 r20622  
    4848import org.openstreetmap.josm.gui.dialogs.relation.RelationEditor;
    4949import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction;
     50import org.openstreetmap.josm.gui.help.HelpUtil;
    5051import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    5152import org.openstreetmap.josm.plugins.turnrestrictions.qa.IssuesView;
     
    380381     * to the dataset.
    381382     */
    382     abstract class SavingAction extends AbstractAction {
     383    abstract class SavingAction extends AbstractAction {       
     384        protected boolean confirmSaveDespiteOfErrorsAndWarnings(){
     385                int numErrors = editorModel.getIssuesModel().getNumErrors();
     386                int numWarnings = editorModel.getIssuesModel().getNumWarnings();
     387                if (numErrors + numWarnings == 0) return true;
     388               
     389                StringBuffer sb = new StringBuffer();
     390                sb.append("<html>");
     391                sb.append(trn(
     392                                "There is still an unresolved error or warning identified for this turn restriction. "
     393                                + "You are recommended to resolve this issue first.",
     394                                  "There are still {0} errors and/or warnings identified for this turn restriction. "
     395                                + "You are recommended to resolve these issues first.",
     396                                  numErrors + numWarnings,
     397                                  numErrors + numWarnings
     398                ));
     399                sb.append("<br>");
     400                sb.append(tr("Do you want to save anyway?"));
     401                ButtonSpec[] options = new ButtonSpec[] {
     402                                new ButtonSpec(
     403                                                tr("Yes, save anyway"),
     404                                                ImageProvider.get("ok"),
     405                                                tr("Save the turn restriction despite of errors and/or warnings"),
     406                                                null // no specific help topic
     407                                ),
     408                                new ButtonSpec(
     409                                                tr("No, resolve issues first"),
     410                                                ImageProvider.get("cancel"),
     411                                                tr("Cancel saving and start resolving pending issues first"),
     412                                                null // no specific help topic
     413                                )
     414                };
     415               
     416                int ret = HelpAwareOptionPane.showOptionDialog(
     417                                JOptionPane.getFrameForComponent(TurnRestrictionEditor.this),
     418                                sb.toString(),
     419                                tr("Pending errors and warnings"),
     420                                JOptionPane.WARNING_MESSAGE,
     421                                null, // no special icon
     422                                options,
     423                                options[1], // cancel is default operation
     424                                HelpUtil.ht("/Plugins/turnrestrictions#PendingErrorsAndWarnings")
     425                );
     426                return ret == 0 /* OK */;               
     427        }
    383428       
    384429        /**
     
    595640
    596641        public void run() {
     642                if (!confirmSaveDespiteOfErrorsAndWarnings()){
     643                        tpEditors.setSelectedIndex(2); // show the errors and warnings
     644                        return;
     645                }
    597646            if (getTurnRestriction() == null) {
    598647                applyNewTurnRestriction();
     
    634683
    635684        public void run() {
     685                if (!confirmSaveDespiteOfErrorsAndWarnings()){
     686                        tpEditors.setSelectedIndex(2); // show the errors and warnings
     687                        return;
     688                }
    636689            if (getTurnRestriction() == null) {
    637690                // it's a new turn restriction. Try to save it and close the dialog
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/TurnRestrictionLegRole.java

    r20489 r20622  
    55 */
    66public enum TurnRestrictionLegRole {   
    7         FROM,
    8         TO
     7        FROM("from"),
     8        TO("to");
     9       
     10        private String osmRoleName;
     11       
     12        private TurnRestrictionLegRole(String osmRoleName) {
     13                this.osmRoleName = osmRoleName;
     14        }
     15       
     16        public String getOsmRole() {
     17                return osmRoleName;
     18        }
    919}
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IdenticalTurnRestrictionLegsError.java

    r20586 r20622  
    1515 */
    1616public class IdenticalTurnRestrictionLegsError extends Issue{
    17         private String value;
    1817        private OsmPrimitive leg;
    1918       
     
    2827        @Override
    2928        public String getText() {               
    30                 return tr("This turn restriction uses the OSM way <em>{0}</em> with role ''from'' <strong>and</strong> with role ''to''. "
     29                return tr("This turn restriction uses the OSM way <span class=\"object-name\">{0}</span> with role ''from'' <strong>and</strong> with role ''to''. "
    3130                                + "In a turn restriction, the way with role ''from'' should be different from the way with role ''to'', though.",
    3231                                leg.getDisplayName(DefaultNameFormatter.getInstance())
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IllegalRestrictionTypeError.java

    r20586 r20622  
    2525        @Override
    2626        public String getText() {               
    27                 return tr("This turn restriction uses a non-standard restriction type <tt>{0}</tt> for the tag key <tt>restriction<tt>. "
     27                return tr("This turn restriction uses a non-standard restriction type <tt>{0}</tt> for the tag key <tt>restriction</tt>. "
    2828                                + "It is recommended to use standard values only. Please select one in the Basic editor.",
    2929                                value
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/Issue.java

    r20586 r20622  
    1919abstract public class Issue {
    2020        /** the parent model for this issue */
    21         private IssuesModel parent;
    22         private Severity severity;
     21        protected IssuesModel parent;
     22        protected Severity severity;
    2323        protected final ArrayList<Action> actions = new ArrayList<Action>();
    2424       
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssueView.java

    r20586 r20622  
    1414import javax.swing.JPanel;
    1515import javax.swing.SwingConstants;
     16import javax.swing.text.html.HTMLEditorKit;
     17import javax.swing.text.html.StyleSheet;
    1618
    1719import org.openstreetmap.josm.gui.widgets.HtmlPanel;
     
    2830        private Issue issue;
    2931        private JLabel lblIcon;
     32        private StyleSheet styleSheet;
     33       
     34         /**
     35     * Builds the style sheet used in the internal help browser
     36     *
     37     * @return the style sheet
     38     */
     39    protected void initStyleSheet(HtmlPanel view) {
     40        StyleSheet ss = ((HTMLEditorKit)view.getEditorPane().getEditorKit()).getStyleSheet();
     41        ss.addRule("em {font-style: italic}");
     42        ss.addRule("tt {font-family: Courier New}");
     43        ss.addRule(".object-name {background-color:rgb(240,240,240); color: blue;}");
     44    }
    3045       
    3146        protected void build() {
     
    5974                gc.weighty = 1.0;
    6075                add(pnlMessage = new HtmlPanel(), gc);
     76                initStyleSheet(pnlMessage);
    6177                pnlMessage.setBackground(Color.white);
    6278                pnlMessage.setText("<html><body>" + issue.getText() + "</html></bod>");
     79
    6380               
    6481                // if there are any actions available to resolve the issue, add a panel with action buttons
     
    98115                CheckParameterUtil.ensureParameterNotNull(issue, "issue");
    99116                this.issue = issue;
    100                 build();
     117                build();               
    101118        }
    102119
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/IssuesModel.java

    r20606 r20622  
    33import java.util.ArrayList;
    44import java.util.Collections;
     5import java.util.HashSet;
    56import java.util.List;
    67import java.util.Observable;
     
    89import java.util.Set;
    910
     11import org.openstreetmap.josm.data.osm.Node;
    1012import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1113import org.openstreetmap.josm.data.osm.Way;
     
    9597                        checkToLeg(editorModel);
    9698                        checkFromAndToEquals(editorModel);
     99                        checkVias(editorModel);
    97100                }
    98101                setChanged();
     
    188191        }
    189192       
     193        protected Node getNodeAtIntersection(Way from, Way to){
     194                Set<Node> fromNodes = new HashSet<Node>(from.getNodes());
     195                fromNodes.retainAll(to.getNodes());
     196                if (fromNodes.size() == 1){
     197                        return fromNodes.iterator().next();
     198                } else {
     199                        return null;
     200                }
     201        }
     202       
     203        /**
     204         * Checks the 'via' members in the turn restriction
     205         *
     206         * @param editorModel the editor model
     207         */
     208        protected void checkVias(TurnRestrictionEditorModel editorModel){
     209                Set<OsmPrimitive> toLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.TO);
     210                Set<OsmPrimitive> fromLegs = editorModel.getTurnRestrictionLeg(TurnRestrictionLegRole.FROM);
     211                // we only check vias if 'to' and 'from' are already OK
     212                if (toLegs.size() != 1 || fromLegs.size() != 1) return;
     213                if (! (toLegs.iterator().next() instanceof Way)) return;
     214                if (! (fromLegs.iterator().next() instanceof Way)) return;
     215               
     216                Way from = (Way)fromLegs.iterator().next();
     217                Way to = (Way)toLegs.iterator().next();
     218                Node intersect = getNodeAtIntersection(from, to);
     219                if (intersect != null){
     220                        if (!editorModel.getVias().contains(intersect)) {
     221                                issues.add(new IntersectionMissingAsViaError(this, from, to, intersect));
     222                        }
     223                }
     224               
     225                // 'from' intersects with 'to' - should be split 
     226                if (intersect != null && from.getNode(0) != intersect && from.getNode(from.getNodesCount()-1) != intersect){
     227                        issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.FROM, from, to, intersect));
     228                }
     229                // 'to' intersects with 'from' - should be split
     230                if (intersect != null && to.getNode(0) != intersect && to.getNode(to.getNodesCount()-1) != intersect){
     231                        issues.add(new TurnRestrictionLegSplitRequiredError(this, TurnRestrictionLegRole.TO, from, to, intersect));
     232                }               
     233        }
     234       
    190235        public NavigationControler getNavigationControler() {
    191236                return editorModel.getNavigationControler();
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MissingTurnRestrictionLegError.java

    r20586 r20622  
    3434                switch(role){
    3535                case FROM:
    36                         msg = tr("An OSM way with role <em>from</em> is required in a turn restriction.");
     36                        msg = tr("An OSM way with role <tt>from</t> is required in a turn restriction.");
    3737                        break;
    3838                case TO:
    39                         msg = tr("An OSM way with role <em>to</em> is required in a turn restriction.");
     39                        msg = tr("An OSM way with role <tt>to</tt> is required in a turn restriction.");
    4040                        break;
    4141                }
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/MultipleTurnRestrictionLegError.java

    r20586 r20622  
    3535                switch(role){
    3636                case FROM: return
    37                         tr("A turn restriction requires exactly one way with role <em>from</em>. "
     37                        tr("A turn restriction requires exactly one way with role <tt>from</tt>. "
    3838                                + "This turn restriction has {0} ways in this role. Please remove "
    3939                                + "{1} of them.",
     
    4242                        );
    4343                case TO:
    44                         tr("A turn restriction requires exactly one way with role <em>from</em>. "
     44                        tr("A turn restriction requires exactly one way with role <tt>from</tt>. "
    4545                                        + "This turn restriction has {0} ways in this role. Please remove "
    4646                                        + "{1} of them.",
  • applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/qa/WrongTurnRestrictionLegTypeError.java

    r20586 r20622  
    4343                case NODE:
    4444                        msg = tr(
    45                                 "This turn restriction uses the OSM node ''{0}'' as member with role ''{1}''.",
     45                                "This turn restriction uses the OSM node <span class=\"object-name\">{0}</span> as member with role <tt>{1}</tt>.",
    4646                                leg.getDisplayName(DefaultNameFormatter.getInstance()),
    4747                                role.toString()
     
    4949                        break;
    5050                case RELATION:
    51                         msg = tr("This turn restriction uses the OSM relation ''{0}'' as member with role ''{1}''.",
     51                        msg = tr("This turn restriction uses the OSM relation <span class=\"object-name\">{0}</span> as member with role <tt>{1}</tt>.",
    5252                                        leg.getDisplayName(DefaultNameFormatter.getInstance()),
    5353                                        role.toString()
Note: See TracChangeset for help on using the changeset viewer.