Changeset 32557 in osm for applications/editors/josm


Ignore:
Timestamp:
2016-07-04T18:48:41+02:00 (8 years ago)
Author:
darya
Message:

fix #13104, EDT errors

Location:
applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/gui/PTAssistantPaintVisitor.java

    r32540 r32557  
    291291                        if (parent.getType().equals(OsmPrimitiveType.RELATION)) {
    292292                                Relation relation = (Relation) parent;
    293                                 if (RouteUtils.isTwoDirectionRoute(relation) && relation.get("ref") != null && !relation.get("ref").equals("")) {
     293                                if (RouteUtils.isTwoDirectionRoute(relation) && relation.get("ref") != null
     294                                                && !relation.get("ref").equals("")) {
    294295
    295296                                        boolean stringFound = false;
     
    331332                public int compare(String s1, String s2) {
    332333
    333                         if (s1 == null || s1.equals("")) {
    334                                 if (s2 == null || s2.equals("")) {
    335                                         return 0;
    336                                 } else {
    337                                         return 1;
    338                                 }
    339                         }
    340 
    341                         String firstNumberString1 = s1.split("\\D+")[0];
    342                         String firstNumberString2 = s2.split("\\D+")[0];
    343                        
     334                        if (s1 == null || s1.equals("") || s2 == null || s2.equals("")) {
     335                                // if at least one of the strings is null or empty, there is no
     336                                // point in comparing:
     337                                return 0;
     338                        }
     339
     340                        String[] splitString1 = s1.split("\\D");
     341                        String[] splitString2 = s2.split("\\D");
     342
     343                        if (splitString1.length == 0 && splitString2.length != 0) {
     344                                // if the first ref does not start a digit and the second ref
     345                                // starts with a digit:
     346                                return 1;
     347                        }
     348
     349                        if (splitString1.length != 0 && splitString2.length == 0) {
     350                                // if the first ref starts a digit and the second ref does not
     351                                // start with a digit:
     352                                return -1;
     353                        }
     354
     355                        if (splitString1.length == 0 && splitString2.length == 0) {
     356                                // if both ref values do not start with a digit:
     357                                return s1.compareTo(s2);
     358                        }
     359
     360                        String firstNumberString1 = splitString1[0];
     361                        String firstNumberString2 = splitString2[0];
     362
    344363                        try {
    345364                                int firstNumber1 = Integer.valueOf(firstNumberString1);
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/PTAssitantValidatorTest.java

    r32554 r32557  
    9898                        if (SwingUtilities.isEventDispatchThread()) {
    9999
    100                                 userSelection[0] = realDownloadIncompleteMembers();
     100                                userSelection[0] = showIncompleteMembersDownloadDialog();
    101101
    102102                        } else {
     
    106106                                        public void run() {
    107107                                                try {
    108                                                         userSelection[0] = realDownloadIncompleteMembers();
     108                                                        userSelection[0] = showIncompleteMembersDownloadDialog();
    109109                                                } catch (InterruptedException e) {
    110110                                                        e.printStackTrace();
     
    144144         * @throws InterruptedException
    145145         */
    146         private int realDownloadIncompleteMembers() throws InterruptedException {
     146        private int showIncompleteMembersDownloadDialog() throws InterruptedException {
    147147
    148148                IncompleteMembersDownloadDialog incompleteMembersDownloadDialog = new IncompleteMembersDownloadDialog();
     
    169169                }
    170170
    171                 ProceedDialog proceedDialog = new ProceedDialog(r.getId(), numberOfDirectionErrors, numberOfRoadTypeErrors);
    172                 int userInput = proceedDialog.getUserSelection();
    173 
    174                 if (userInput == 0) {
     171                final int[] userInput = { 0 };
     172                final long idParameter = r.getId();
     173                final int directionErrorParameter = numberOfDirectionErrors;
     174                final int roadTypeErrorParameter = numberOfRoadTypeErrors;
     175
     176                if (SwingUtilities.isEventDispatchThread()) {
     177
     178                        userInput[0] = showProceedDialog(idParameter, directionErrorParameter, roadTypeErrorParameter);
     179
     180                } else {
     181
     182                        try {
     183                                SwingUtilities.invokeAndWait(new Runnable() {
     184                                        @Override
     185                                        public void run() {
     186                                                userInput[0] = showProceedDialog(idParameter, roadTypeErrorParameter, roadTypeErrorParameter);
     187
     188                                        }
     189                                });
     190                        } catch (InvocationTargetException | InterruptedException e1) {
     191                                // TODO Auto-generated catch block
     192                                e1.printStackTrace();
     193                        }
     194
     195                }
     196
     197                if (userInput[0] == 0) {
    175198                        this.fixErrorFromPlugin(this.errors);
    176199                        proceedWithSorting(r);
     
    178201                }
    179202
    180                 if (userInput == 1) {
     203                if (userInput[0] == 1) {
    181204                        // TODO
    182205                        JOptionPane.showMessageDialog(null, "This is not implemented yet!");
     
    184207                }
    185208
    186                 if (userInput == 2) {
     209                if (userInput[0] == 2) {
    187210                        // TODO: should the errors be removed from the error list?
    188211                        proceedWithSorting(r);
     
    191214                // if userInput==-1 (i.e. no input), do nothing and stop testing of the
    192215                // route.
     216
     217        }
     218
     219        private int showProceedDialog(long id, int numberOfDirectionErrors, int numberOfRoadTypeErrors) {
     220
     221                ProceedDialog proceedDialog = new ProceedDialog(id, numberOfDirectionErrors, numberOfRoadTypeErrors);
     222                return proceedDialog.getUserSelection();
    193223
    194224        }
  • applications/editors/josm/plugins/pt_assistant/src/org/openstreetmap/josm/plugins/pt_assistant/validation/WayChecker.java

    r32554 r32557  
    66import java.util.Collection;
    77import java.util.List;
     8
     9import javax.swing.SwingUtilities;
    810
    911import org.openstreetmap.josm.Main;
     
    1214import org.openstreetmap.josm.command.Command;
    1315import org.openstreetmap.josm.command.SelectCommand;
     16import org.openstreetmap.josm.command.SequenceCommand;
    1417import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1518import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    2932
    3033/**
    31  * Performs tests of a route at the level of single ways: DirectionTest and RoadTypeTest
     34 * Performs tests of a route at the level of single ways: DirectionTest and
     35 * RoadTypeTest
    3236 *
    3337 * @author darya
     
    3539 */
    3640public class WayChecker extends Checker {
    37 
     41       
    3842        public WayChecker(Relation relation, Test test) {
    3943
     
    4347
    4448        protected void performRoadTypeTest() {
    45                
     49
    4650                if (!relation.hasTag("route", "bus") && !relation.hasTag("route", "trolleybus")
    4751                                && !relation.hasTag("route", "share_taxi")) {
     
    121125
    122126                                }
    123                                
     127
    124128                                if (isUnderConstruction) {
    125129                                        List<Relation> primitives = new ArrayList<>(1);
     
    127131                                        List<Way> highlighted = new ArrayList<>(1);
    128132                                        highlighted.add(way);
    129                                         TestError e = new TestError(this.test, Severity.WARNING,
    130                                                         tr("PT: Road is under construction"),
     133                                        TestError e = new TestError(this.test, Severity.WARNING, tr("PT: Road is under construction"),
    131134                                                        PTAssitantValidatorTest.ERROR_CODE_CONSTRUCTION, primitives, highlighted);
    132135                                        errors.add(e);
     
    215218                return false;
    216219        }
    217        
     220
    218221        protected static Command fixErrorByRemovingWay(TestError testError) {
    219222
    220                 if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_ROAD_TYPE && testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_DIRECTION) {
     223                if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_ROAD_TYPE
     224                                && testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_DIRECTION) {
    221225                        return null;
    222226                }
     
    272276                return changeCommand;
    273277        }
    274        
    275278
    276279        protected static Command fixErrorByZooming(TestError testError) {
    277                
     280
    278281                if (testError.getCode() != PTAssitantValidatorTest.ERROR_CODE_DIRECTION) {
    279282                        return null;
    280283                }
    281284               
    282                  long startTime = System.currentTimeMillis();
    283                
     285                ArrayList<Command> commands = new ArrayList<>();
     286
    284287                Collection<? extends OsmPrimitive> primitives = testError.getPrimitives();
    285288                Relation originalRelation = (Relation) primitives.iterator().next();
     289                ArrayList<OsmPrimitive> primitivesToSelect = new ArrayList<>(1);
     290                primitivesToSelect.add(originalRelation);
    286291                Collection<?> highlighted = testError.getHighlighted();
    287292                Way wayToHighlight = (Way) highlighted.iterator().next();
    288                 ArrayList<OsmPrimitive> primitivesToHighlight = new ArrayList<>(1);
    289                 primitivesToHighlight.add(wayToHighlight);
     293                ArrayList<OsmPrimitive> primitivesToZoom = new ArrayList<>(1);
     294                primitivesToZoom.add(wayToHighlight);
     295
     296                SelectCommand command1 = new SelectCommand(primitivesToSelect);
     297                commands.add(command1);
     298                SelectCommand command2 = new SelectCommand(primitivesToZoom);
     299                commands.add(command2);
     300
     301                List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class);
     302                for (OsmDataLayer osmDataLayer : listOfLayers) {
     303                        if (osmDataLayer.data == originalRelation.getDataSet()) {
     304
     305                                final OsmDataLayer layerParameter = osmDataLayer;
     306                                final Relation relationParameter = originalRelation;
     307                                final Collection<OsmPrimitive> zoomParameter = primitivesToZoom;
     308
     309                                if (SwingUtilities.isEventDispatchThread()) {
     310
     311                                        showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter);
     312
     313                                } else {
     314
     315                                        SwingUtilities.invokeLater(new Runnable() {
     316                                                @Override
     317                                                public void run() {
     318
     319                                                        showRelationEditorAndZoom(layerParameter, relationParameter, zoomParameter);
     320
     321                                                }
     322                                        });
     323
     324                                }
     325
     326                                return new SequenceCommand(null, commands);
     327                        }
     328                }
     329
     330                return null;
     331
     332        }
     333
     334        private static void showRelationEditorAndZoom(OsmDataLayer layer, Relation r, Collection<OsmPrimitive> primitives) {
     335
     336                AutoScaleAction.zoomTo(primitives);
     337                GenericRelationEditor editor = new GenericRelationEditor(layer, r, r.getMembersFor(primitives));
     338                RelationDialogManager.getRelationDialogManager().register(layer, r, editor);
    290339               
    291                 long endTime = System.currentTimeMillis();
    292                 System.out.println("obtaining primitives: " + (endTime - startTime));
    293                 startTime = endTime;
    294340               
    295                 SelectCommand command = new SelectCommand(primitivesToHighlight);
     341                editor.setVisible(true);
     342//              editor.requestFocus();
     343//              editor.requestFocusInWindow();
    296344               
    297                 endTime = System.currentTimeMillis();
    298                 System.out.println("constructing command: " + (endTime - startTime));
    299                 startTime = endTime;
    300                
    301                 AutoScaleAction.zoomTo(primitivesToHighlight);
    302                
    303                 endTime = System.currentTimeMillis();
    304                 System.out.println("AutoScaleAction done: " + (endTime - startTime));
    305                 startTime = endTime;
    306                
    307                 List<OsmDataLayer> listOfLayers = Main.getLayerManager().getLayersOfType(OsmDataLayer.class);
    308                 for (OsmDataLayer osmDataLayer: listOfLayers) {
    309                         if (osmDataLayer.data == originalRelation.getDataSet()) {
    310                                 endTime = System.currentTimeMillis();
    311                                 System.out.println("getting to the necessary layer: " + (endTime - startTime));
    312                                 startTime = endTime;
    313                                
    314                                 GenericRelationEditor editor = new GenericRelationEditor(osmDataLayer, originalRelation, originalRelation.getMembersFor(primitivesToHighlight));
    315                                 endTime = System.currentTimeMillis();
    316                                 System.out.println("creating relation editor: " + (endTime - startTime));
    317                                 startTime = endTime;
    318                                
    319                                 RelationDialogManager.getRelationDialogManager().register(osmDataLayer, originalRelation, editor);
    320                                
    321                                 endTime = System.currentTimeMillis();
    322                                 System.out.println("registering relation editor: " + (endTime - startTime));
    323                                 startTime = endTime;
    324                                
    325                                 editor.setVisible(true);
    326                                
    327                                 endTime = System.currentTimeMillis();
    328                                 System.out.println("setting editor visible: " + (endTime - startTime));
    329                                 startTime = endTime;
    330                                
    331                                 break;
    332                         }
    333                 }
    334                
    335                 endTime = System.currentTimeMillis();
    336                 System.out.println("whatever else: " + (endTime - startTime));
    337                 startTime = endTime;
    338                                                
    339                 return command;
    340                
    341         }
    342        
     345//              editor.firePropertyChange("focusedWindow", editor, editor);
     346//              editor.setRelation(r);
     347
     348        }
     349
    343350}
Note: See TracChangeset for help on using the changeset viewer.