source: osm/applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java@ 31245

Last change on this file since 31245 was 31245, checked in by nokutu, 10 years ago

New link to image's url at mapillary website

File size: 1.2 KB
Line 
1package org.openstreetmap.josm.plugins.mapillary.commands;
2
3import java.util.ArrayList;
4
5/**
6 * History record system in order to let you undo commands
7 * @author nokutu
8 *
9 */
10public class MapillaryRecord {
11 public static MapillaryRecord INSTANCE;
12
13 public ArrayList<MapillaryCommand> commandList;
14 /** Last written command */
15 public int position;
16
17 public MapillaryRecord() {
18 commandList = new ArrayList<>();
19 position = -1;
20 }
21
22 public static synchronized MapillaryRecord getInstance() {
23 if (MapillaryRecord.INSTANCE == null)
24 MapillaryRecord.INSTANCE = new MapillaryRecord();
25 return MapillaryRecord.INSTANCE;
26 }
27
28 /**
29 * Adds a new command to the list.
30 *
31 * @param command
32 */
33 public void addCommand(MapillaryCommand command) {
34 commandList.add(position + 1, command);
35 position++;
36 while (commandList.size() > position + 1) {
37 commandList.remove(position + 1);
38 }
39 }
40
41 /**
42 * Undo latest command.
43 */
44 public void undo() {
45 if (position == -1)
46 return;
47 commandList.get(position).undo();
48 position--;
49 }
50
51 /**
52 * Redo latest undoed action.
53 */
54 public void redo() {
55 if (position >= commandList.size())
56 return;
57 commandList.get(position).redo();
58 position++;
59 }
60}
Note: See TracBrowser for help on using the repository browser.