Changeset 31257 in osm for applications/editors/josm/plugins/mapillary/src/org
- Timestamp:
- 2015-06-10T14:21:24+02:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryAbstractImage.java
r31256 r31257 8 8 public final LatLon latLon; 9 9 /** Direction of the picture */ 10 p rotectedfinal double ca;11 p rivateboolean isModified = false;10 public final double ca; 11 public boolean isModified = false; 12 12 /** Temporal position of the picture until it is uplaoded */ 13 13 public LatLon tempLatLon; … … 18 18 public LatLon movingLatLon; 19 19 /** Temporal direction of the picture until it is uplaoded */ 20 p rotecteddouble tempCa;20 public double tempCa; 21 21 /** 22 22 * When the object direction is being moved in the map, the temporal -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryLayer.java
r31256 r31257 6 6 import org.openstreetmap.josm.plugins.mapillary.cache.MapillaryCache; 7 7 import org.openstreetmap.josm.plugins.mapillary.downloads.MapillaryDownloader; 8 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryHistoryDialog; 8 9 import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryToggleDialog; 9 10 import org.openstreetmap.josm.Main; … … 62 63 63 64 private List<Bounds> bounds; 64 private MapillaryToggleDialog tgd; 65 66 private MapillaryToggleDialog mtd; 67 private MapillaryHistoryDialog mhd; 65 68 66 69 private MouseAdapter mouseAdapter; … … 91 94 MapView.addLayerChangeListener(this); 92 95 Main.map.mapView.getEditLayer().data.addDataSetListener(this); 93 if ( tgd == null) {96 if (mtd == null) { 94 97 if (MapillaryToggleDialog.INSTANCE == null) { 95 tgd = MapillaryToggleDialog.getInstance();96 Main.map.addToggleDialog( tgd, false);98 mtd = MapillaryToggleDialog.getInstance(); 99 Main.map.addToggleDialog(mtd, false); 97 100 } else 98 tgd = MapillaryToggleDialog.getInstance(); 101 mtd = MapillaryToggleDialog.getInstance(); 102 } 103 if (mhd == null) { 104 if (MapillaryHistoryDialog.INSTANCE == null) { 105 mhd = MapillaryHistoryDialog.getInstance(); 106 Main.map.addToggleDialog(mhd, false); 107 } else 108 mhd = MapillaryHistoryDialog.getInstance(); 99 109 } 100 110 } … … 109 119 } 110 120 111 112 121 public synchronized static MapillaryLayer getInstance() { 113 122 if (MapillaryLayer.INSTANCE == null) -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandMoveImage.java
r31256 r31257 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.trn; 4 4 5 import java.util.ArrayList; 5 6 import java.util.List; … … 15 16 */ 16 17 public class CommandMoveImage extends MapillaryCommand { 17 private List<MapillaryAbstractImage> images;18 18 private double x; 19 19 private double y; … … 31 31 image.stopMoving(); 32 32 } 33 checkModified(); 33 34 Main.map.repaint(); 34 35 } … … 40 41 image.stopMoving(); 41 42 } 43 checkModified(); 42 44 Main.map.repaint(); 43 45 } … … 46 48 return trn("Moved {0} node", "Moved {0} nodes", images.size(), images.size()); 47 49 } 50 51 @Override 52 public void sum(MapillaryCommand command) { 53 if (command instanceof CommandMoveImage) { 54 this.x += ((CommandMoveImage) command).x; 55 this.y += ((CommandMoveImage) command).y; 56 } 57 } 48 58 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/CommandTurnImage.java
r31256 r31257 16 16 */ 17 17 public class CommandTurnImage extends MapillaryCommand { 18 private List<MapillaryAbstractImage> images;19 18 private double ca; 20 19 … … 30 29 image.stopMoving(); 31 30 } 31 checkModified(); 32 32 Main.map.repaint(); 33 33 } … … 39 39 image.stopMoving(); 40 40 } 41 checkModified(); 41 42 Main.map.repaint(); 42 43 } 43 44 44 45 public String toString() { 45 return trn("Turned {0} node", "Moved {0} nodes", images.size(), images.size()); 46 return trn("Turned {0} node", "Turned {0} nodes", this.images.size(), 47 this.images.size()); 48 } 49 50 @Override 51 public void sum(MapillaryCommand command) { 52 if (command instanceof CommandTurnImage) { 53 this.ca += ((CommandTurnImage) command).ca; 54 } 46 55 } 47 56 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryCommand.java
r31245 r31257 1 1 package org.openstreetmap.josm.plugins.mapillary.commands; 2 3 import java.util.List; 4 5 import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; 2 6 3 7 /** … … 8 12 */ 9 13 public abstract class MapillaryCommand { 14 protected List<MapillaryAbstractImage> images; 10 15 11 16 public abstract void undo(); 12 17 13 18 public abstract void redo(); 19 20 public abstract void sum(MapillaryCommand command); 21 22 public void checkModified() { 23 for (MapillaryAbstractImage image : images) 24 image.isModified = (image.tempLatLon == image.latLon || image.tempCa == image.ca); 25 } 14 26 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecord.java
r31245 r31257 5 5 /** 6 6 * History record system in order to let you undo commands 7 * 7 8 * @author nokutu 8 9 * … … 10 11 public class MapillaryRecord { 11 12 public static MapillaryRecord INSTANCE; 13 14 private ArrayList<MapillaryRecordListener> listeners; 12 15 13 16 public ArrayList<MapillaryCommand> commandList; … … 18 21 commandList = new ArrayList<>(); 19 22 position = -1; 23 listeners = new ArrayList<>(); 20 24 } 21 25 … … 26 30 } 27 31 32 public void addListener(MapillaryRecordListener lis) { 33 this.listeners.add(lis); 34 } 35 36 public void removeListener(MapillaryRecordListener lis) { 37 this.listeners.remove(lis); 38 } 39 28 40 /** 29 41 * Adds a new command to the list. … … 32 44 */ 33 45 public void addCommand(MapillaryCommand command) { 46 // Checks if it is a continuation of last command 47 if (position != -1 48 && commandList.get(position).images.equals(command.images) 49 && commandList.get(position).getClass() == command.getClass()) { 50 commandList.get(position).sum(command); 51 fireRecordChanged(); 52 return; 53 } 34 54 commandList.add(position + 1, command); 35 55 position++; … … 37 57 commandList.remove(position + 1); 38 58 } 59 fireRecordChanged(); 39 60 } 40 61 … … 47 68 commandList.get(position).undo(); 48 69 position--; 70 fireRecordChanged(); 49 71 } 50 72 … … 53 75 */ 54 76 public void redo() { 55 if (position >= commandList.size()) 77 if (position + 1 >= commandList.size()) 56 78 return; 79 position++; 57 80 commandList.get(position).redo(); 58 position++; 81 fireRecordChanged(); 82 } 83 84 private void fireRecordChanged() { 85 for (MapillaryRecordListener lis : listeners) 86 if (lis != null) 87 lis.recordChanged(); 59 88 } 60 89 } -
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java
r31256 r31257 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.awt.Component; 6 import java.awt.Dimension; 7 import java.awt.GridBagLayout; 8 import java.awt.event.ActionEvent; 9 import java.util.ArrayList; 10 import java.util.Arrays; 11 12 import javax.swing.AbstractAction; 13 import javax.swing.Box; 14 import javax.swing.JPanel; 15 import javax.swing.JSeparator; 16 import javax.swing.JTree; 17 import javax.swing.tree.DefaultTreeCellRenderer; 18 import javax.swing.tree.DefaultTreeModel; 19 20 import org.openstreetmap.josm.gui.SideButton; 5 21 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 22 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryCommand; 23 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecord; 24 import org.openstreetmap.josm.plugins.mapillary.commands.MapillaryRecordListener; 25 import org.openstreetmap.josm.tools.GBC; 26 import org.openstreetmap.josm.tools.ImageProvider; 6 27 7 public class MapillaryHistoryDialog extends ToggleDialog { 28 import javax.swing.tree.DefaultMutableTreeNode; 29 30 public class MapillaryHistoryDialog extends ToggleDialog implements 31 MapillaryRecordListener { 32 33 public static MapillaryHistoryDialog INSTANCE; 34 35 private final DefaultTreeModel undoTreeModel = new DefaultTreeModel( 36 new DefaultMutableTreeNode()); 37 private final DefaultTreeModel redoTreeModel = new DefaultTreeModel( 38 new DefaultMutableTreeNode()); 39 private final JTree undoTree = new JTree(undoTreeModel); 40 private final JTree redoTree = new JTree(redoTreeModel); 41 42 private JSeparator separator = new JSeparator(); 43 private Component spacer = Box.createRigidArea(new Dimension(0, 3)); 44 45 private SideButton undoButton; 46 private SideButton redoButton; 8 47 9 48 public MapillaryHistoryDialog() { 10 super(tr("Mapillary history"), "mapillary.png", 49 super(tr("Mapillary history"), "mapillaryhistory.png", 11 50 tr("Open Mapillary history dialog"), null, 200); 51 52 MapillaryRecord.getInstance().addListener(this); 53 54 undoTree.expandRow(0); 55 undoTree.setShowsRootHandles(true); 56 undoTree.setRootVisible(false); 57 undoTree.setCellRenderer(new MapillaryCellRenderer()); 58 redoTree.expandRow(0); 59 redoTree.setCellRenderer(new MapillaryCellRenderer()); 60 redoTree.setShowsRootHandles(true); 61 redoTree.setRootVisible(false); 62 63 JPanel treesPanel = new JPanel(new GridBagLayout()); 64 treesPanel.add(spacer, GBC.eol()); 65 spacer.setVisible(false); 66 treesPanel.add(undoTree, GBC.eol().fill(GBC.HORIZONTAL)); 67 separator.setVisible(false); 68 treesPanel.add(separator, GBC.eol().fill(GBC.HORIZONTAL)); 69 treesPanel.add(redoTree, GBC.eol().fill(GBC.HORIZONTAL)); 70 treesPanel.add(Box.createRigidArea(new Dimension(0, 0)), GBC.std() 71 .weight(0, 1)); 72 treesPanel.setBackground(redoTree.getBackground()); 73 74 undoButton = new SideButton(new UndoAction()); 75 redoButton = new SideButton(new RedoAction()); 76 77 createLayout(treesPanel, true, 78 Arrays.asList(new SideButton[] { undoButton, redoButton })); 79 } 80 81 public static MapillaryHistoryDialog getInstance() { 82 if (INSTANCE == null) 83 INSTANCE = new MapillaryHistoryDialog(); 84 return INSTANCE; 85 } 86 87 private void buildTree() { 88 redoButton.setEnabled(true); 89 undoButton.setEnabled(true); 90 ArrayList<MapillaryCommand> commands = MapillaryRecord.getInstance().commandList; 91 int position = MapillaryRecord.getInstance().position; 92 ArrayList<MapillaryCommand> undoCommands = new ArrayList<>(); 93 if (position >= 0) 94 undoCommands = new ArrayList<>(commands.subList(0, position + 1)); 95 else 96 undoButton.setEnabled(false); 97 ArrayList<MapillaryCommand> redoCommands = new ArrayList<>(); 98 if (commands.size() > 0 && position + 1 < commands.size()) 99 redoCommands = new ArrayList<>(commands.subList(position + 1, 100 commands.size())); 101 else 102 redoButton.setEnabled(false); 103 104 DefaultMutableTreeNode redoRoot = new DefaultMutableTreeNode(); 105 DefaultMutableTreeNode undoRoot = new DefaultMutableTreeNode(); 106 107 for (MapillaryCommand command : undoCommands) { 108 if (command != null) 109 undoRoot.add(new DefaultMutableTreeNode(command.toString())); 110 } 111 for (MapillaryCommand command : redoCommands) { 112 if (command != null) 113 redoRoot.add(new DefaultMutableTreeNode(command.toString())); 114 } 115 116 separator 117 .setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty()); 118 spacer.setVisible(undoCommands.isEmpty() && !redoCommands.isEmpty()); 119 120 undoTreeModel.setRoot(undoRoot); 121 redoTreeModel.setRoot(redoRoot); 122 } 123 124 @Override 125 public void recordChanged() { 126 buildTree(); 127 } 128 129 private class UndoAction extends AbstractAction { 130 131 public UndoAction() { 132 putValue(NAME, tr("Undo")); 133 putValue(SMALL_ICON, ImageProvider.get("undo")); 134 } 135 136 @Override 137 public void actionPerformed(ActionEvent arg0) { 138 MapillaryRecord.getInstance().undo(); 139 } 140 141 } 142 143 private class RedoAction extends AbstractAction { 144 public RedoAction() { 145 putValue(NAME, tr("Redo")); 146 putValue(SMALL_ICON, ImageProvider.get("redo")); 147 } 148 149 @Override 150 public void actionPerformed(ActionEvent arg0) { 151 MapillaryRecord.getInstance().redo(); 152 } 153 154 } 155 156 private static class MapillaryCellRenderer extends DefaultTreeCellRenderer { 157 @Override 158 public Component getTreeCellRendererComponent(JTree tree, Object value, 159 boolean sel, boolean expanded, boolean leaf, int row, 160 boolean hasFocus) { 161 super.getTreeCellRendererComponent(tree, value, sel, expanded, 162 leaf, row, hasFocus); 163 setIcon(ImageProvider.get("data/node.png")); 164 return this; 165 } 12 166 } 13 167 }
Note:
See TracChangeset
for help on using the changeset viewer.