Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nokutu committed Aug 12, 2015
1 parent 21f35e9 commit 1b5cd06
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.openstreetmap.josm.plugins.mapillary.commands;
package org.openstreetmap.josm.plugins.mapillary.history;

import static org.junit.Assert.assertEquals;

Expand Down

0 comments on commit 1b5cd06

Please sign in to comment.