From 1b5cd063e3b1eee63837f1af2efbefa8d0c41e1f Mon Sep 17 00:00:00 2001 From: nokutu Date: Wed, 12 Aug 2015 10:39:58 +0000 Subject: [PATCH] Fixed tests git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins/mapillary@31492 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4 --- .../mapillary/gui/MapillaryHistoryDialog.java | 24 ++++++-- .../mapillary/history/MapillaryRecord.java | 60 ++++++++----------- .../MapillaryRecordTest.java | 2 +- 3 files changed, 45 insertions(+), 41 deletions(-) rename test/unit/org/openstreetmap/josm/plugins/mapillary/{commands => history}/MapillaryRecordTest.java (98%) diff --git a/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java b/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java index 6cd027354..a3e500124 100644 --- a/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java +++ b/src/org/openstreetmap/josm/plugins/mapillary/gui/MapillaryHistoryDialog.java @@ -16,6 +16,7 @@ import javax.swing.JPanel; import javax.swing.JSeparator; import javax.swing.JTree; +import javax.swing.SwingUtilities; import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.DefaultTreeModel; @@ -79,10 +80,13 @@ private MapillaryHistoryDialog() { JPanel treesPanel = new JPanel(new GridBagLayout()); treesPanel.add(this.spacer, GBC.eol()); this.spacer.setVisible(false); - treesPanel.add(this.undoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); + treesPanel + .add(this.undoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); this.separator.setVisible(false); - treesPanel.add(this.separator, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); - treesPanel.add(this.redoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); + treesPanel.add(this.separator, GBC.eol() + .fill(GridBagConstraints.HORIZONTAL)); + treesPanel + .add(this.redoTree, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); treesPanel.add(Box.createRigidArea(new Dimension(0, 0)), GBC.std().weight(0, 1)); treesPanel.setBackground(this.redoTree.getBackground()); @@ -134,7 +138,8 @@ private void buildTree() { redoRoot.add(new DefaultMutableTreeNode(command.toString())); } - this.separator.setVisible(!undoCommands.isEmpty() || !redoCommands.isEmpty()); + this.separator.setVisible(!undoCommands.isEmpty() + || !redoCommands.isEmpty()); this.spacer.setVisible(undoCommands.isEmpty() && !redoCommands.isEmpty()); this.undoTreeModel.setRoot(undoRoot); @@ -143,7 +148,16 @@ private void buildTree() { @Override public void recordChanged() { - buildTree(); + if (!SwingUtilities.isEventDispatchThread()) { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + recordChanged(); + } + }); + } else { + buildTree(); + } } private class UndoAction extends AbstractAction { diff --git a/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java b/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java index 119d762eb..2828b8ea4 100644 --- a/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java +++ b/src/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecord.java @@ -2,8 +2,6 @@ import java.util.ArrayList; -import javax.swing.SwingUtilities; - import org.openstreetmap.josm.plugins.mapillary.MapillaryAbstractImage; import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryCommand; import org.openstreetmap.josm.plugins.mapillary.history.commands.MapillaryExecutableCommand; @@ -72,41 +70,33 @@ public void removeListener(MapillaryRecordListener lis) { * The command to be added. */ public void addCommand(final MapillaryCommand command) { - if (!SwingUtilities.isEventDispatchThread()) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - addCommand(command); - } - }); - } else { - if (command instanceof MapillaryExecutableCommand) - ((MapillaryExecutableCommand) command).execute(); - // Checks if it is a continuation of last command - if (this.position != -1) { - boolean equalSets = true; - for (MapillaryAbstractImage img : this.commandList.get(this.position).images) - if (!command.images.contains(img)) - equalSets = false; - for (MapillaryAbstractImage img : command.images) - if (!this.commandList.get(this.position).images.contains(img)) - equalSets = false; - if (equalSets - && this.commandList.get(this.position).getClass() == command - .getClass()) { - this.commandList.get(this.position).sum(command); - fireRecordChanged(); - return; - } - } - // Adds the command to the last position of the list. - this.commandList.add(this.position + 1, command); - this.position++; - while (this.commandList.size() > this.position + 1) { - this.commandList.remove(this.position + 1); + + if (command instanceof MapillaryExecutableCommand) + ((MapillaryExecutableCommand) command).execute(); + // Checks if it is a continuation of last command + if (this.position != -1) { + boolean equalSets = true; + for (MapillaryAbstractImage img : this.commandList.get(this.position).images) + if (!command.images.contains(img)) + equalSets = false; + for (MapillaryAbstractImage img : command.images) + if (!this.commandList.get(this.position).images.contains(img)) + equalSets = false; + if (equalSets + && this.commandList.get(this.position).getClass() == command + .getClass()) { + this.commandList.get(this.position).sum(command); + fireRecordChanged(); + return; } - fireRecordChanged(); } + // Adds the command to the last position of the list. + this.commandList.add(this.position + 1, command); + this.position++; + while (this.commandList.size() > this.position + 1) { + this.commandList.remove(this.position + 1); + } + fireRecordChanged(); } /** diff --git a/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java b/test/unit/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecordTest.java similarity index 98% rename from test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java rename to test/unit/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecordTest.java index 41e907868..45f64953e 100644 --- a/test/unit/org/openstreetmap/josm/plugins/mapillary/commands/MapillaryRecordTest.java +++ b/test/unit/org/openstreetmap/josm/plugins/mapillary/history/MapillaryRecordTest.java @@ -1,4 +1,4 @@ -package org.openstreetmap.josm.plugins.mapillary.commands; +package org.openstreetmap.josm.plugins.mapillary.history; import static org.junit.Assert.assertEquals;