Changeset 31500 in osm for applications/editors
- Timestamp:
- 2015-08-15T12:30:24+02:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/mapillary
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java
r31490 r31500 67 67 68 68 /** 69 * Removes an image from the database. 70 * 71 * @param image 69 * Removes an image from the database. From the ArrayList in this object and 70 * from its {@link MapillarySequence}. 71 * 72 * @param image 73 * The {@link MapillaryAbstractImage} that is going to be deleted. 72 74 */ 73 75 public synchronized void remove(MapillaryAbstractImage image) { 74 if (MapillaryMainDialog.getInstance().getImage() != null) { 76 if (Main.main != null 77 && MapillaryMainDialog.getInstance().getImage() != null) { 75 78 MapillaryMainDialog.getInstance().setImage(null); 76 79 MapillaryMainDialog.getInstance().updateImage(); … … 88 91 * 89 92 * @param images 93 * The set of {@link MapillaryAbstractImage} objects that are going 94 * to be removed. 90 95 */ 91 96 public synchronized void remove(List<MapillaryAbstractImage> images) { -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandDelete.java
r31490 r31500 10 10 11 11 /** 12 * Command used to delete a set of images. 13 * 12 14 * @author nokutu 13 15 * … … 18 20 19 21 /** 22 * Main constructor. 23 * 20 24 * @param images 25 * The set of images that are going to be deleted. 21 26 */ 22 27 public CommandDelete(List<MapillaryAbstractImage> images) { … … 27 32 @Override 28 33 public void sum(MapillaryCommand command) { 29 // Ignored30 34 } 31 35 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandImport.java
r31491 r31500 22 22 * 23 23 * @param images 24 * The set of images that are going to be added. Might be in the same 25 * sequence or not. 24 26 */ 25 27 public CommandImport(List<MapillaryAbstractImage> images) { … … 47 49 @Override 48 50 public void sum(MapillaryCommand command) { 49 // IGNORE50 51 } 51 52 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandJoin.java
r31490 r31500 6 6 7 7 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 8 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;9 8 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils; 10 9 … … 21 20 * 22 21 * @param images 22 * The two images that are going to be joined. Must be of exactly 23 * size 2. The first one joins to the second one. 24 * @throws IllegalArgumentException 25 * if the List size is different from 2. 23 26 */ 24 27 public CommandJoin(List<MapillaryAbstractImage> images) { 25 28 super(images); 29 if (images.size() != 2) 30 throw new IllegalArgumentException(); 26 31 } 27 32 … … 33 38 @Override 34 39 public void undo() { 35 MapillaryUtils.unjoin((MapillaryImportedImage) this.images.get(0), 36 (MapillaryImportedImage) this.images.get(1)); 40 MapillaryUtils.unjoin(this.images.get(0), this.images.get(1)); 37 41 } 38 42 39 43 @Override 40 44 public void redo() { 41 MapillaryUtils.join((MapillaryImportedImage) this.images.get(0), 42 (MapillaryImportedImage) this.images.get(1)); 45 MapillaryUtils.join(this.images.get(0), this.images.get(1)); 43 46 } 44 47 45 48 @Override 46 49 public void sum(MapillaryCommand command) { 47 // TODO Auto-generated method stub48 49 50 } 50 51 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/CommandUnjoin.java
r31490 r31500 6 6 7 7 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 8 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;9 8 import org.openstreetmap.josm.plugins.mapillary.utils.MapillaryUtils; 10 9 … … 21 20 * 22 21 * @param images 22 * The two images that are going to be unjoined. Must be of exactly 23 * size 2. 24 * @throws IllegalArgumentException 25 * if the List size is different from 2. 23 26 */ 24 27 public CommandUnjoin(List<MapillaryAbstractImage> images) { 25 28 super(images); 29 if (images.size() != 2) 30 throw new IllegalArgumentException(); 26 31 } 27 32 … … 33 38 @Override 34 39 public void undo() { 35 MapillaryUtils.join((MapillaryImportedImage) this.images.get(0), 36 (MapillaryImportedImage) this.images.get(1)); 40 MapillaryUtils.join(this.images.get(0), this.images.get(1)); 37 41 } 38 42 39 43 @Override 40 44 public void redo() { 41 MapillaryUtils.unjoin((MapillaryImportedImage) this.images.get(0), 42 (MapillaryImportedImage) this.images.get(1)); 45 MapillaryUtils.unjoin(this.images.get(0), this.images.get(1)); 43 46 } 44 47 45 48 @Override 46 49 public void sum(MapillaryCommand command) { 47 // IGNORE48 50 } 49 51 -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/history/commands/MapillaryExecutableCommand.java
r31490 r31500 17 17 * 18 18 * @param images 19 * The set of images affected by the command. 19 20 */ 20 21 public MapillaryExecutableCommand(List<MapillaryAbstractImage> images) { … … 23 24 24 25 /** 25 * Executes the command. 26 * Executes the command. It is run when the command is added to the history 27 * record. 26 28 */ 27 29 public abstract void execute(); -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java
r31495 r31500 19 19 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 20 20 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 21 import org.openstreetmap.josm.plugins.mapillary.MapillaryImportedImage;22 21 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 23 22 import org.openstreetmap.josm.plugins.mapillary.MapillarySequence; … … 137 136 * Joins two images into the same sequence. 138 137 * 139 * @param img1140 * @param img2141 */ 142 public synchronized static void join(Mapillary ImportedImage img1,143 Mapillary ImportedImage img2) {144 Mapillary ImportedImage firstImage =img1;145 Mapillary ImportedImage secondImage =img2;146 147 if ( img1.next() != null) {148 firstImage = img2;149 secondImage = img1;138 * @param mapillaryAbstractImage 139 * @param mapillaryAbstractImage2 140 */ 141 public synchronized static void join(MapillaryAbstractImage mapillaryAbstractImage, 142 MapillaryAbstractImage mapillaryAbstractImage2) { 143 MapillaryAbstractImage firstImage = mapillaryAbstractImage; 144 MapillaryAbstractImage secondImage = mapillaryAbstractImage2; 145 146 if (mapillaryAbstractImage.next() != null) { 147 firstImage = mapillaryAbstractImage2; 148 secondImage = mapillaryAbstractImage; 150 149 } 151 150 if (firstImage.getSequence() == null) { … … 157 156 MapillarySequence seq = new MapillarySequence(); 158 157 seq.add(secondImage); 159 img2.setSequence(seq);158 mapillaryAbstractImage2.setSequence(seq); 160 159 } 161 160 … … 171 170 * Separates two images belonging to the same sequence. 172 171 * 173 * @param img1174 * @param img2175 */ 176 public synchronized static void unjoin(Mapillary ImportedImage img1,177 Mapillary ImportedImage img2) {178 Mapillary ImportedImage firstImage =img1;179 Mapillary ImportedImage secondImage =img2;180 181 if ( img1.next() !=img2) {182 firstImage = img2;183 secondImage = img1;172 * @param mapillaryAbstractImage 173 * @param mapillaryAbstractImage2 174 */ 175 public synchronized static void unjoin(MapillaryAbstractImage mapillaryAbstractImage, 176 MapillaryAbstractImage mapillaryAbstractImage2) { 177 MapillaryAbstractImage firstImage = mapillaryAbstractImage; 178 MapillaryAbstractImage secondImage = mapillaryAbstractImage2; 179 180 if (mapillaryAbstractImage.next() != mapillaryAbstractImage2) { 181 firstImage = mapillaryAbstractImage2; 182 secondImage = mapillaryAbstractImage; 184 183 } 185 184 -
applications/editors/josm/plugins/mapillary/test/unit/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecordTest.java
r31492 r31500 2 2 3 3 import static org.junit.Assert.assertEquals; 4 import static org.junit.Assert.fail; 4 5 5 6 import java.util.Arrays; … … 9 10 import org.openstreetmap.josm.plugins.mapillary.AbstractTest; 10 11 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 12 import org.openstreetmap.josm.plugins.mapillary.MapillaryData; 11 13 import org.openstreetmap.josm.plugins.mapillary.MapillaryImage; 14 import org.openstreetmap.josm.plugins.mapillary.MapillaryLayer; 12 15 import org.openstreetmap.josm.plugins.mapillary.history.MapillaryRecord; 16 import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandDelete; 17 import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandImport; 18 import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandJoin; 13 19 import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandMove; 14 20 import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandTurn; 21 import org.openstreetmap.josm.plugins.mapillary.history.commands.CommandUnjoin; 15 22 import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryCommand; 16 23 … … 38 45 this.img2 = new MapillaryImage("key2", 0.2, 0.2, 0.2); 39 46 this.img3 = new MapillaryImage("key3", 0.3, 0.3, 0.3); 47 MapillaryLayer.getInstance().getData().getImages().clear(); 40 48 } 41 49 … … 55 63 0.1, 0.1); 56 64 MapillaryCommand cmd1 = new CommandMove( 57 Arrays.asList(new MapillaryAbstractImage[] { this.img1 }), 58 0.1, 0.1); 65 Arrays.asList(new MapillaryAbstractImage[] { this.img1 }), 0.1, 0.1); 59 66 MapillaryCommand cmd31 = new CommandMove( 60 67 Arrays.asList(new MapillaryAbstractImage[] { this.img3, this.img1 }), … … 98 105 99 106 /** 100 * Tests CommandMove Imageclass.107 * Tests {@link CommandMove} class. 101 108 */ 102 109 @Test … … 132 139 133 140 /** 134 * Tests CommandTurn Imageclass.141 * Tests {@link CommandTurn} class. 135 142 */ 136 143 @Test … … 161 168 assertEquals(0.1, this.img1.getCa(), 0.01); 162 169 } 170 171 /** 172 * Tests {@link CommandJoin} class. 173 */ 174 @Test 175 public void commandJoinClass() { 176 CommandJoin cmd1 = new CommandJoin( 177 Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 })); 178 CommandJoin cmd2 = new CommandJoin( 179 Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 })); 180 181 this.record.addCommand(cmd1); 182 assertEquals(2, this.img1.getSequence().getImages().size()); 183 assertEquals(this.img2, this.img1.next()); 184 this.record.undo(); 185 assertEquals(1, this.img1.getSequence().getImages().size()); 186 this.record.redo(); 187 this.record.addCommand(cmd2); 188 assertEquals(3, this.img1.getSequence().getImages().size()); 189 assertEquals(this.img3, this.img1.next().next()); 190 191 try { 192 this.record.addCommand(new CommandJoin(Arrays 193 .asList(new MapillaryAbstractImage[] { this.img1, this.img2, 194 this.img3 }))); 195 fail(); 196 } catch (IllegalArgumentException e) { 197 // Expected output. 198 } catch (Exception e) { 199 fail(); 200 } 201 } 202 203 /** 204 * Tests {@link CommandUnjoin} class. 205 */ 206 @Test 207 public void commandUnjoinClass() { 208 CommandJoin join1 = new CommandJoin( 209 Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 })); 210 CommandJoin join2 = new CommandJoin( 211 Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 })); 212 213 CommandUnjoin cmd1 = new CommandUnjoin( 214 Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 })); 215 CommandUnjoin cmd2 = new CommandUnjoin( 216 Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 })); 217 218 this.record.addCommand(join1); 219 this.record.addCommand(join2); 220 221 this.record.addCommand(cmd1); 222 assertEquals(1, this.img1.getSequence().getImages().size()); 223 this.record.undo(); 224 assertEquals(3, this.img1.getSequence().getImages().size()); 225 this.record.redo(); 226 this.record.addCommand(cmd2); 227 assertEquals(1, this.img1.getSequence().getImages().size()); 228 assertEquals(1, this.img2.getSequence().getImages().size()); 229 230 try { 231 this.record.addCommand(new CommandUnjoin(Arrays 232 .asList(new MapillaryAbstractImage[] { this.img1, this.img2, 233 this.img3 }))); 234 fail(); 235 } catch (IllegalArgumentException e) { 236 // Expected output. 237 } catch (Exception e) { 238 fail(); 239 } 240 } 241 242 /** 243 * Test {@link CommandDelete} class. 244 */ 245 @Test 246 public void commandDeleteTest() { 247 CommandJoin join1 = new CommandJoin( 248 Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2 })); 249 CommandJoin join2 = new CommandJoin( 250 Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 })); 251 252 CommandDelete cmd1 = new CommandDelete( 253 Arrays.asList(new MapillaryAbstractImage[] { this.img1 })); 254 CommandDelete cmd2 = new CommandDelete( 255 Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 })); 256 257 this.record.addCommand(join1); 258 this.record.addCommand(join2); 259 260 MapillaryLayer 261 .getInstance() 262 .getData() 263 .add( 264 Arrays.asList(new MapillaryAbstractImage[] { this.img1, this.img2, 265 this.img3 })); 266 267 this.record.addCommand(cmd1); 268 assertEquals(false, MapillaryLayer.getInstance().getData().getImages() 269 .contains(this.img1)); 270 assertEquals(null, this.img2.previous()); 271 this.record.undo(); 272 assertEquals(true, MapillaryLayer.getInstance().getData().getImages() 273 .contains(this.img1)); 274 this.record.redo(); 275 this.record.addCommand(cmd2); 276 assertEquals(0, MapillaryLayer.getInstance().getData().size()); 277 } 278 279 /** 280 * Test {@link CommandImport} class. 281 */ 282 @Test 283 public void commandImportTest() { 284 MapillaryData data = MapillaryLayer.getInstance().getData(); 285 data.remove(data.getImages()); 286 287 CommandImport cmd1 = new CommandImport( 288 Arrays.asList(new MapillaryAbstractImage[] { this.img1 })); 289 CommandImport cmd2 = new CommandImport( 290 Arrays.asList(new MapillaryAbstractImage[] { this.img2, this.img3 })); 291 292 this.record.addCommand(cmd1); 293 assertEquals(1, data.size()); 294 this.record.undo(); 295 assertEquals(0, data.size()); 296 this.record.redo(); 297 this.record.addCommand(cmd2); 298 assertEquals(3, data.size()); 299 } 163 300 }
Note:
See TracChangeset
for help on using the changeset viewer.