UserPreferences preferences = new DefaultUserPreferences();
ViewFactory viewFactory = new SwingViewFactory();
UndoableEditSupport undoSupport = new UndoableEditSupport();
UndoManager undoManager = new UndoManager();
undoSupport.addUndoableEditListener(undoManager);
PlanController planController =
new PlanController(home, preferences, viewFactory, null, undoSupport);
// Build an ordered list of walls added to home
final ArrayList<Wall> orderedWalls = new ArrayList<Wall>();
home.addWallsListener(new CollectionListener<Wall> () {
public void collectionChanged(CollectionEvent<Wall> ev) {
if (ev.getType() == CollectionEvent.Type.ADD) {
orderedWalls.add(ev.getItem());
}
}
});
// 2. Use WALL_CREATION mode
planController.setMode(PlanController.Mode.WALL_CREATION);
// Click at (20, 20), (500, 22), (498, 300), then double click at (20, 302) in home coordinates space
planController.moveMouse(20, 20);
planController.pressMouse(20, 20, 1, false, false);
planController.toggleMagnetism(false);
planController.releaseMouse(20, 20);
planController.moveMouse(500, 22);
planController.pressMouse(500, 22, 1, false, false);
planController.releaseMouse(500, 22);
planController.moveMouse(498, 300);
planController.pressMouse(498, 300, 1, false, false);
planController.releaseMouse(498, 300);
planController.moveMouse(20, 302);
planController.pressMouse(20, 302, 1, false, false);
planController.releaseMouse(20, 302);
planController.pressMouse(20, 302, 2, false, false);
planController.releaseMouse(20, 302);
// Check 3 walls were created at (20, 20), (500, 20), (500, 300) and (20, 300) coordinates
Wall wall1 = orderedWalls.get(0);
assertCoordinatesEqualWallPoints(20, 20, 500, 20, wall1);
Wall wall2 = orderedWalls.get(1);
assertCoordinatesEqualWallPoints(500, 20, 500, 300, wall2);
Wall wall3 = orderedWalls.get(2);
assertCoordinatesEqualWallPoints(500, 300, 20, 300, wall3);
// Check they are joined to each other end point
assertWallsAreJoined(null, wall1, wall2);
assertWallsAreJoined(wall1, wall2, wall3);
assertWallsAreJoined(wall2, wall3, null);
// Check they are selected
assertSelectionContains(home, wall1, wall2, wall3);
// 3. Click at (20, 300), then double click at (60, 60) with Alt key depressed
planController.moveMouse(20, 300);
planController.pressMouse(20, 300, 1, false, false);
planController.releaseMouse(20, 300);
planController.toggleMagnetism(true);
planController.moveMouse(60, 60);
planController.pressMouse(60, 60, 1, false, false);
planController.releaseMouse(60, 60);
planController.pressMouse(60, 60, 2, false, false);
planController.releaseMouse(60, 60);
planController.toggleMagnetism(false);
// Check a forth wall was created at (20, 300), (60, 60) coordinates
Wall wall4 = orderedWalls.get(orderedWalls.size() - 1);
assertCoordinatesEqualWallPoints(20, 300, 60, 60, wall4);
assertSelectionContains(home, wall4);
assertWallsAreJoined(wall3, wall4, null);
// 4. Use SELECTION mode
planController.setMode(PlanController.Mode.SELECTION);
// Check current mode is SELECTION
assertEquals("Current mode isn't " + PlanController.Mode.SELECTION,
PlanController.Mode.SELECTION, planController.getMode());
// Press the delete key
planController.deleteSelection();
// Check plan contains only the first three walls
assertHomeContains(home, wall1, wall2, wall3);
// 5. Use WALL_CREATION mode
planController.setMode(PlanController.Mode.WALL_CREATION);
// Click at (22, 18), then double click at (20, 300)
planController.moveMouse(22, 18);
planController.pressMouse(22, 18, 1, false, false);
planController.releaseMouse(22, 18);
planController.moveMouse(20, 300);
planController.pressMouse(20, 300, 1, false, false);
planController.releaseMouse(20, 300);
planController.pressMouse(20, 300, 2, false, false);
planController.releaseMouse(20, 300);
// Check a new forth wall was created at (20, 20), (20, 300) coordinates
wall4 = orderedWalls.get(orderedWalls.size() - 1);
assertCoordinatesEqualWallPoints(20, 20, 20, 300, wall4);
// Check its end points are joined to the first and third wall
assertWallsAreJoined(wall1, wall4, wall3);
// 6. Use SELECTION mode
planController.setMode(PlanController.Mode.SELECTION);
// Drag and drop cursor from (360, 160) to (560, 320)
planController.moveMouse(360, 160);
planController.pressMouse(360, 160, 1, false, false);
planController.moveMouse(560, 320);
planController.releaseMouse(560, 320);
// Check the selected walls are the second and third ones
assertSelectionContains(home, wall2, wall3);
// 7. Press twice right arrow key
planController.moveSelection(2, 0);
planController.moveSelection(2, 0);
// Check the 4 walls coordinates are (20, 20), (504, 20), (504, 300), (24, 300)
assertCoordinatesEqualWallPoints(20, 20, 504, 20, wall1);
assertCoordinatesEqualWallPoints(504, 20, 504, 300, wall2);
assertCoordinatesEqualWallPoints(504, 300, 24, 300, wall3);
assertCoordinatesEqualWallPoints(20, 20, 24, 300, wall4);
// 8. Click at (504, 40) with Shift key depressed
planController.moveMouse(504, 40);
planController.pressMouse(504, 40, 1, true, false);
planController.releaseMouse(504, 40);
// Check the second wall was removed from selection
assertSelectionContains(home, wall3);
// 9. Drag cursor from (60, 20) to (60, 60)
planController.moveMouse(60, 20);
planController.pressMouse(60, 20, 1, false, false);
planController.moveMouse(60, 60);
// Check first wall is selected and that it moved
assertSelectionContains(home, wall1);
assertCoordinatesEqualWallPoints(20, 60, 504, 60, wall1);
// Lose focus
planController.escape();
// Check the wall didn't move at end
assertCoordinatesEqualWallPoints(20, 20, 504, 20, wall1);
// 10. Undo 8 times
for (int i = 0; i < 6; i++) {