Package com.eteks.sweethome3d.swing

Examples of com.eteks.sweethome3d.swing.PlanComponent


    // 2. Change default wall thickness and height
    frame.preferences.setNewWallThickness(10);
    frame.preferences.setNewWallHeight(100);
    // Create a home with 5 walls
    PlanController planController = frame.homeController.getPlanController();
    PlanComponent planComponent = (PlanComponent)planController.getView();
    planController.setMode(PlanController.Mode.WALL_CREATION);
    // Click at (50, 50), (200, 50), (250, 100), (250, 150), (50, 150) then double click at (50, 50)
    JComponentTester tester = new JComponentTester();
    tester.actionClick(planComponent, 50, 50);
    tester.actionClick(planComponent, 200, 50);
View Full Code Here


    };
    Home home = new Home();
    final HomeController controller =
        new HomeController(home, preferences, viewFactory, contentManager);
    JComponent homeView = (JComponent)controller.getView();
    PlanComponent planComponent = (PlanComponent)TestUtilities.findComponent(
         homeView, PlanComponent.class);

    // 1. Create a frame that displays a home view
    JFrame frame = new JFrame("Imported Texture Wizard Test");   
    frame.add(homeView);
    frame.pack();

    // Show home plan frame
    showWindow(frame);
    JComponentTester tester = new JComponentTester();
    tester.waitForIdle();
    // Transfer focus to plan view
    planComponent.requestFocusInWindow();
    tester.waitForIdle();
   
    // Check plan view has focus
    assertTrue("Plan component doesn't have the focus", planComponent.isFocusOwner());
   
    // 2. Create two wall between points (50, 50), (150, 50) and (150, 150)
    runAction(controller, HomePane.ActionType.CREATE_WALLS);
    tester.actionClick(planComponent, 50, 50);
    tester.actionClick(planComponent, 150, 50);
View Full Code Here

    // a new home at 540 pixels by 400 preferred size, and a tool bar
    // with a mode toggle button, an undo button and a redo button
    final PlanTestFrame frame = new PlanTestFrame();   
    // Show home plan frame
    showWindow(frame);
    PlanComponent planComponent = (PlanComponent)frame.planController.getView();
    assertEquals("Wrong preferred width", 540, planComponent.getWidth());
   
    // Build an ordered list of walls added to home
    final ArrayList<Wall> orderedWalls = new ArrayList<Wall>();
    frame.home.addWallsListener(new CollectionListener<Wall>() {
      public void collectionChanged(CollectionEvent<Wall> ev) {
View Full Code Here

  public void testPlanComponentWithKeyboard() throws InterruptedException {
    // 1. Create a frame that displays a PlanComponent instance
    PlanTestFrame frame = new PlanTestFrame();   
    // Show home plan frame
    showWindow(frame);
    PlanComponent planComponent = (PlanComponent)frame.planController.getView();
 
    // Build an ordered list of walls added to home
    final ArrayList<Wall> orderedWalls = new ArrayList<Wall>();
    frame.home.addWallsListener(new CollectionListener<Wall>() {
      public void collectionChanged(CollectionEvent<Wall> ev) {
        if (ev.getType() == CollectionEvent.Type.ADD) {
          orderedWalls.add(ev.getItem());
        }
      }
    });
   
    // 2. Create walls with keyboard
    frame.planController.setMode(PlanController.Mode.WALL_CREATION);
    assertEquals("Current mode isn't " + PlanController.Mode.WALL_CREATION,
        PlanController.Mode.WALL_CREATION, frame.planController.getMode());
    planComponent.requestFocus();
    JComponentTester tester = new JComponentTester();
    tester.waitForIdle();
    assertTrue("Plan component doesn't have focus", planComponent.hasFocus());
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    // Enter the coordinates of the start point
    tester.actionKeyString("10");
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.actionKeyString("21");
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    // Enter the length of the wall
    tester.actionKeyString("200");
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    // Create a wall with same length
    Thread.sleep(500);
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    // Create a wall with same length, an angle at 270� and a thickness of 7,55 cm
    tester.actionKeyStroke(KeyEvent.VK_DOWN);
    tester.actionKeyStroke(KeyEvent.VK_HOME);
    tester.actionKeyString("27");
    tester.actionKeyStroke(KeyEvent.VK_DELETE); // Remove the 9 digit
    tester.actionKeyStroke(KeyEvent.VK_UP);
    tester.actionKeyStroke(KeyEvent.VK_UP);
    tester.actionKeyStroke(KeyEvent.VK_END);
    tester.actionKeyString("5 ");
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    tester.actionKeyStroke(KeyEvent.VK_ESCAPE);
    // Check created walls
    assertEquals("Wrong walls count", 3, frame.home.getWalls().size());
    Wall wall1 = orderedWalls.get(0);
    assertCoordinatesEqualWallPoints(10, 21, 210, 21, wall1);
    Wall wall2 = orderedWalls.get(1);
    assertCoordinatesEqualWallPoints(210, 21, 210, 221, wall2);
    assertEquals("Wrong wall thickness", wall1.getThickness(), wall2.getThickness());
    Wall wall3 = orderedWalls.get(2);
    assertCoordinatesEqualWallPoints(210, 221, 410, 221, wall3);
    assertEquals("Wrong wall thickness",
        Float.parseFloat(String.valueOf(wall1.getThickness()) + "5"), wall3.getThickness());
    assertWallsAreJoined(wall1, wall2, wall3);
    assertSelectionContains(frame.home, wall1, wall2, wall3);
   
    // 3. Mix mouse and keyboard to create other walls
    tester.actionClick(planComponent, 300, 200);
    tester.actionMouseMove(planComponent,
        new ComponentLocation(new Point(310, 200)));
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    // Enter the length and the angle of the wall
    tester.actionKeyString("100");
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.actionKeyString("315");
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    // Create 3 walls with same length
    Thread.sleep(500);
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    Thread.sleep(500);
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    // Take control with mouse
    tester.actionMouseMove(planComponent,
        new ComponentLocation(new Point(200, 200)));
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    Wall wall7 = orderedWalls.get(7);
    assertCoordinatesEqualWallPoints(wall7.getXStart(), wall7.getYStart(),
        planComponent.convertXPixelToModel(200),
        planComponent.convertYPixelToModel(200), wall7);
    tester.waitForIdle();
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Take control again with keyboard and close the walls square
    tester.actionKeyStroke(KeyEvent.VK_ENTER);
    tester.actionKeyString("100");
View Full Code Here

    Home home = new Home();
    home.getCompass().setVisible(false);
    final HomeController controller =
        new HomeController(home, preferences, new SwingViewFactory());
    JComponent homeView = (JComponent)controller.getView();
    PlanComponent planComponent = (PlanComponent)TestUtilities.findComponent(
        homeView, PlanComponent.class);
    HomeComponent3D component3D = (HomeComponent3D)TestUtilities.findComponent(
        homeView, HomeComponent3D.class);

    // 1. Create a frame that displays a home view
    JFrame frame = new JFrame("Home Camera Test");   
    frame.add(homeView);
    frame.pack();

    // Show home plan frame
    showWindow(frame);
    JComponentTester tester = new JComponentTester();
    tester.waitForIdle();
    // Transfer focus to plan view
    planComponent.requestFocusInWindow();
    tester.waitForIdle();
   
    // Check plan view has focus
    assertTrue("Plan component doesn't have the focus", planComponent.isFocusOwner());
    // Check default camera is the top camera
    assertSame("Default camera isn't top camera",
        home.getTopCamera(), home.getCamera());
    // Check default camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(500, 1500, 1000,
        (float)Math.PI, (float)Math.PI / 4, home.getCamera());
   
    // 2. Create one wall between points (50, 50) and (150, 50) at a bigger scale
    runAction(controller, HomePane.ActionType.CREATE_WALLS, tester);
    runAction(controller, HomePane.ActionType.ZOOM_IN, tester);
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionClick(planComponent, 50, 50);
    tester.actionClick(planComponent, 150, 50, InputEvent.BUTTON1_MASK, 2);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check wall length is 100 * plan scale
    Wall wall = home.getWalls().iterator().next();
    assertTrue("Incorrect wall length " + 100 / planComponent.getScale()
               + " " + (wall.getXEnd() - wall.getXStart()),
        Math.abs(wall.getXEnd() - wall.getXStart() - 100 / planComponent.getScale()) < 1E-3);
    float xWallMiddle = (wall.getXEnd() + wall.getXStart()) / 2;
    float yWallMiddle = (wall.getYEnd() + wall.getYStart()) / 2;
    // Check camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(xWallMiddle, yWallMiddle + 1000, 1000,
        (float)Math.PI, (float)Math.PI / 4, home.getCamera());
   
    // 3. Transfer focus to 3D view with TAB key
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    // Check 3D view has focus
    assertTrue("3D component doesn't have the focus", component3D.isFocusOwner());
    // Add 1� to camera pitch
    tester.actionKeyStroke(KeyEvent.VK_PAGE_UP);
    // Check camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(xWallMiddle, 1000.1468f, 1025.8342f,
        (float)Math.PI, (float)Math.PI / 4 + (float)Math.PI / 120, home.getCamera());
   
    // 4. Remove 10� from camera yaw
    tester.actionKeyStroke(KeyEvent.VK_LEFT);
    // Check camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(144.2812f, 998.8128f, 1025.8342f,
        (float)Math.PI - (float)Math.PI / 60, (float)Math.PI / 4 + (float)Math.PI / 120, home.getCamera());
    // Add 1� to camera yaw
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionKeyStroke(KeyEvent.VK_RIGHT);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(-109.0647f, 978.874f, 1025.8342f,
        (float)Math.PI - (float)Math.PI / 60 + (float)Math.PI / 12, (float)Math.PI / 4 + (float)Math.PI / 120, home.getCamera());
   
    // 5. Move camera 1cm forward
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionKeyStroke(KeyEvent.VK_UP);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(-85.8082f, 869.4608f, 907.961f,
        (float)Math.PI - (float)Math.PI / 60 + (float)Math.PI / 12, (float)Math.PI / 4 + (float)Math.PI / 120, home.getCamera());
    // Move camera 10 backward
    tester.actionKeyStroke(KeyEvent.VK_DOWN);
    // Check camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(-90.4595f, 891.3434f, 931.5356f,
        (float)Math.PI - (float)Math.PI / 60 + (float)Math.PI / 12, (float)Math.PI / 4 + (float)Math.PI / 120, home.getCamera());
   
    // 6. View from observer
    runAction(controller, HomePane.ActionType.VIEW_FROM_OBSERVER, tester);
    tester.waitForIdle();
    ObserverCamera observerCamera = home.getObserverCamera();
    // Check camera is the observer camera
    assertSame("Camera isn't observer camera", observerCamera, home.getCamera());
    // Check default camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(50, 50, 170,
        7 * (float)Math.PI / 4, (float)Math.PI / 16, home.getCamera());
    // Change camera location and angles
    observerCamera.setX(100);
    observerCamera.setY(100);
    observerCamera.setYaw(3 * (float)Math.PI / 4);
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(100, 100, 170,
        3 * (float)Math.PI / 4, (float)Math.PI / 16, home.getCamera());
    // Check observer camera is selected
    assertEquals("Wrong selected items count", 1, home.getSelectedItems().size());
    assertTrue("Camera isn't selected", home.getSelectedItems().contains(home.getCamera()));

    // Try to select wall and observer camera
    runAction(controller, HomePane.ActionType.SELECT, tester);
    tester.actionClick(planComponent, 50, 50);
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionClick(planComponent, (int)(140 * planComponent.getScale()),
        (int)(140 * planComponent.getScale()));
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check selected items contains only wall
    assertEquals("Wrong selected items count", 1, home.getSelectedItems().size());
    assertTrue("Wall isn't selected", home.getSelectedItems().contains(wall));
   
    // Select observer camera
    Thread.sleep(1000); // Wait 1s to avoid double click
    tester.actionClick(planComponent, (int)(140 * planComponent.getScale()),
        (int)(140 * planComponent.getScale()));
    // Check observer camera is selected
    assertEquals("Wrong selected items count", 1, home.getSelectedItems().size());
    assertTrue("Camera isn't selected", home.getSelectedItems().contains(home.getCamera()));
   
    // 7. Move observer camera at right and down
    tester.actionKeyStroke(KeyEvent.VK_RIGHT);
    tester.actionKeyStroke(KeyEvent.VK_DOWN);
    // Check camera location and angles
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(100 + 1 / planComponent.getScale(),
        100 + 1 / planComponent.getScale(), 170,
        3 * (float)Math.PI / 4, (float)Math.PI / 16, home.getCamera());
   
    // 8. Change observer camera yaw by moving its yaw indicator
    float [][] cameraPoints = observerCamera.getPoints();
    int xYawIndicator = (int)(((40 + (cameraPoints[0][0] + cameraPoints[3][0]) / 2)) * planComponent.getScale());
    int yYawIndicator = (int)(((40 + (cameraPoints[0][1] + cameraPoints[3][1]) / 2)) * planComponent.getScale());
    tester.actionMousePress(planComponent, new ComponentLocation(
        new Point(xYawIndicator, yYawIndicator)));
    tester.actionMouseMove(planComponent, new ComponentLocation(
        new Point(xYawIndicator + 2, yYawIndicator + 2)));
    tester.actionMouseRelease();
    // Check camera yaw angle changed
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(100 + 1 / planComponent.getScale(),
        100 + 1 / planComponent.getScale(), 170,
        2.5156f, (float)Math.PI / 16, home.getCamera());

    // Change observer camera pitch by moving its pitch indicator
    cameraPoints = observerCamera.getPoints();
    int xPitchIndicator = (int)(((40 + (cameraPoints[1][0] + cameraPoints[2][0]) / 2)) * planComponent.getScale());
    int yPitchIndicator = (int)(((40 + (cameraPoints[1][1] + cameraPoints[2][1]) / 2)) * planComponent.getScale());
    tester.actionMousePress(planComponent, new ComponentLocation(
        new Point(xPitchIndicator, yPitchIndicator)));
    tester.actionMouseMove(planComponent, new ComponentLocation(
        new Point(xPitchIndicator + 2, yPitchIndicator + 2)));
    tester.actionMouseRelease();
    // Check camera pitch angle changed
    assertCoordinatesAndAnglesEqualCameraLocationAndAngles(100 + 1 / planComponent.getScale(),
        100 + 1 / planComponent.getScale(), 170,
        2.5156f, 0.1639f, home.getCamera());
   
    // 9. Change observer camera location with mouse in 3D view
    tester.actionMousePress(component3D, new ComponentLocation(new Point(10, 10)));
    tester.actionKeyPress(KeyEvent.VK_ALT);
View Full Code Here

    showWindow(frame);
   
    // 2. Use CREATE_WALLS mode
    JComponentTester tester = new JComponentTester();
    tester.click(frame.createWallsButton);
    PlanComponent planComponent = (PlanComponent)
        frame.homeController.getPlanController().getView();
    // Click at (30, 30), (220, 30), (270, 80), (270, 170), (30, 170)
    // then double click at (30, 30) with no magnetism
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionClick(planComponent, 30, 30);
    tester.actionClick(planComponent, 220, 30);
    tester.actionClick(planComponent, 270, 80);
    tester.actionClick(planComponent, 270, 170);
    tester.actionClick(planComponent, 30, 170);
    tester.actionClick(planComponent, 30, 30, InputEvent.BUTTON1_MASK, 2);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check 5 walls were added to home plan
    assertEquals("Wrong walls count", 5, frame.home.getWalls().size());

    // 3. Use SELECTION mode
    tester.click(frame.selectButton);
    // Select the first piece in catalog tree
    JTree catalogTree = (JTree)
        frame.homeController.getFurnitureCatalogController().getView();
    catalogTree.expandRow(0);
    catalogTree.addSelectionInterval(1, 1);
    // Click on Add furniture button
    tester.click(frame.addButton);
    // Check home contains one selected piece
    tester.waitForIdle();
    assertEquals("Wrong piece count",
        1, frame.home.getFurniture().size());
    assertEquals("Wrong selected items count",
        1, frame.home.getSelectedItems().size());
   
    HomePieceOfFurniture piece = frame.home.getFurniture().get(0);
    float pieceWidth = piece.getWidth();
    float pieceDepth = piece.getDepth();
    float pieceHeight = piece.getHeight();
    float pieceX = pieceWidth / 2;
    float pieceY = pieceDepth / 2;
    assertLocationAndOrientationEqualPiece(pieceX, pieceY, 0, piece);
   
    // 4. Press mouse button at piece center
    int widthPixel = Math.round(pieceWidth * planComponent.getScale());
    int depthPixel = Math.round(pieceDepth * planComponent.getScale());
    tester.actionMousePress(planComponent, new ComponentLocation(
        new Point(20 + widthPixel / 2, 20 + depthPixel / 2)));
    // Drag mouse to (100, 100) from piece center
    tester.actionMousePress(planComponent, new ComponentLocation(
        new Point(20 + widthPixel / 2 + 100, 20 + depthPixel / 2 + 100)));
    tester.actionMouseRelease();
    // Check piece moved
    pieceX += 200;
    pieceY += 200;
    assertLocationAndOrientationEqualPiece(pieceX, pieceY, 0, piece);
   
    // 5. Press mouse button at top left point of selected piece
    tester.actionMousePress(planComponent,
        new ComponentLocation(new Point(120, 120)));
    // Drag mouse to (-depthPixel / 2 - 1, widthPixel / 2) pixels from piece center
    tester.actionMouseMove(planComponent, new ComponentLocation(
        new Point(120 + widthPixel / 2 - depthPixel / 2 - 1,
                  120 + depthPixel / 2 + widthPixel / 2)));
    tester.actionMouseRelease();
    // Check piece angle is 3 * PI / 2 (=-90�)
    assertLocationAndOrientationEqualPiece(
        pieceX, pieceY, (float)Math.PI * 3 / 2, piece);

    // 6. Press mouse button at top left point of selected piece
    tester.actionMousePress(planComponent, new ComponentLocation(
        new Point(120 + widthPixel / 2 - depthPixel / 2,
                  120 + depthPixel / 2 + widthPixel / 2)));
    // Drag mouse to the previous position plus 1 pixel along x axis
    tester.actionMouseMove(planComponent, new ComponentLocation(
        new Point(121, 120)));
    // Check piece angle is 0�
    assertLocationAndOrientationEqualPiece(pieceX, pieceY, 0, piece);
    // Press Shift key
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    // Check piece angle is different from 0�
    assertFalse("Piece orientation shouldn't be magnetized",
        Math.abs(piece.getAngle()) < 1E-10);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);   
    tester.actionKeyStroke(planComponent, KeyEvent.VK_ESCAPE);
    tester.actionMouseRelease();
    // Check piece angle is 3 * PI / 2 (=-90�)
    assertLocationAndOrientationEqualPiece(
        pieceX, pieceY, (float)Math.PI * 3 / 2, piece);
   
    // 7. Click at point (30, 160) with Shift key depressed
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionClick(planComponent, 30, 160);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check selected items contains the piece of furniture and the fifth wall
    List<Selectable> selectedItems =
        new ArrayList<Selectable>(frame.home.getSelectedItems());
    assertEquals("Wrong selected items count", 2, selectedItems.size());
    assertTrue("Piece of furniture not selected", selectedItems.contains(piece));
    // Remove piece form list to get the selected wall
    selectedItems.remove(piece);
    Wall fifthWall = (Wall)selectedItems.get(0);
    // Check piece and wall coordinates
    assertLocationAndOrientationEqualPiece(
        pieceX, pieceY, (float)Math.PI * 3 / 2, piece);
    assertCoordinatesEqualWallPoints(20, 300, 20, 20, fifthWall);
   
    // 8. Drag and drop mouse to (40, 160)
    Thread.sleep(1000); // Wait 1s to avoid double click
    tester.actionMousePress(planComponent,
        new ComponentLocation(new Point(30, 160)));
    tester.actionMouseMove(planComponent, 
        new ComponentLocation(new Point(40, 160)));
    tester.actionMouseRelease();
    // Check the piece of furniture moved 20 cm along x axis
    assertLocationAndOrientationEqualPiece(
        pieceX + 20, pieceY, (float)Math.PI * 3 / 2, piece);
    assertCoordinatesEqualWallPoints(40, 300, 40, 20, fifthWall);
   
    // 9. Click twice on undo button
    tester.invokeAndWait(new Runnable() {
         public void run() {
          frame.undoButton.doClick();
          frame.undoButton.doClick();
         }
       });
    // Check piece orientation and location are canceled
    assertLocationAndOrientationEqualPiece(
        pieceX, pieceY, 0f, piece);
    assertCoordinatesEqualWallPoints(20, 300, 20, 20, fifthWall);
   
    // 10. Click twice on redo button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          frame.redoButton.doClick();
          frame.redoButton.doClick();
        }
      });
    // Check piece and wall location was redone
    assertLocationAndOrientationEqualPiece(
        pieceX + 20, pieceY, (float)Math.PI * 3 / 2, piece);
    assertCoordinatesEqualWallPoints(40, 300, 40, 20, fifthWall);
    // Check selected items contains the piece of furniture and the fifth wall
    selectedItems = frame.home.getSelectedItems();
    assertEquals("Wrong selected items count",
        2, selectedItems.size());
    assertTrue("Piece of furniture not selected",
        selectedItems.contains(piece));
    assertTrue("Fifth wall not selected",
        selectedItems.contains(fifthWall));
   
    // 11. Click at point (pieceXPixel + depthPixel / 2, pieceYPixel - widthPixel / 2)
    //     at width and depth resize point of the piece
    int pieceXPixel = Math.round((piece.getX() + 40) * planComponent.getScale());
    int pieceYPixel = Math.round((piece.getY() + 40) * planComponent.getScale());
    tester.actionClick(planComponent, pieceXPixel + depthPixel / 2, pieceYPixel - widthPixel / 2);
   
    // Check selected items contains only the piece of furniture
    selectedItems = frame.home.getSelectedItems();
    assertEquals("Wrong selected items count", 1, selectedItems.size());
    assertTrue("Piece of furniture not selected", selectedItems.contains(piece));
    // Drag mouse (4,4) pixels out of piece box with magnetism disabled
    Thread.sleep(1000); // Wait 1s to avoid double click
    tester.actionMousePress(planComponent, new ComponentLocation(new Point(
        pieceXPixel + depthPixel / 2, pieceYPixel - widthPixel / 2)));
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(
        pieceXPixel + depthPixel / 2 + 4, pieceYPixel - widthPixel / 2 + 4)));
    tester.actionMouseRelease();
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check piece width and depth were resized (caution : piece angle is oriented at 90�)
    assertDimensionEqualPiece(pieceWidth - 4 / planComponent.getScale(),
        pieceDepth + 4 / planComponent.getScale(), pieceHeight, piece);

    // 12. Click at point (pieceXPixel + depthPixel / 2, pieceYPixel + widthPixel / 2)
    //     at height resize point of the piece
    pieceXPixel = Math.round((piece.getX() + 40) * planComponent.getScale());
    pieceYPixel = Math.round((piece.getY() + 40) * planComponent.getScale());
    widthPixel = Math.round((piece.getWidth()) * planComponent.getScale());
    depthPixel = Math.round((piece.getDepth()) * planComponent.getScale());
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(
        pieceXPixel + depthPixel / 2, pieceYPixel + widthPixel / 2)));
    Thread.sleep(1000);
    tester.actionMousePress(planComponent, new ComponentLocation(new Point(
        pieceXPixel + depthPixel / 2, pieceYPixel + widthPixel / 2)));
    // Drag mouse (2,4) pixels
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(
        pieceXPixel + depthPixel / 2 + 2, pieceYPixel + widthPixel / 2 + 4)));
    tester.actionMouseRelease();
    // Check piece height was resized
    assertDimensionEqualPiece(pieceWidth - 4 / planComponent.getScale(),
        pieceDepth + 4 / planComponent.getScale(),
        Math.round((pieceHeight - 4 / planComponent.getScale()) * 2) / 2, piece);

    // 13. Click at point (pieceXPixel - depthPixel / 2, pieceYPixel - widthPixel / 2)
    //     at elevation point of the piece
    float pieceElevation = piece.getElevation();
    tester.actionMousePress(planComponent, new ComponentLocation(new Point(
        pieceXPixel - depthPixel / 2, pieceYPixel - widthPixel / 2)));
    // Drag mouse (2,-4) pixels
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(
        pieceXPixel - depthPixel / 2 + 2, pieceYPixel - widthPixel / 2 - 4)));
    tester.actionMouseRelease();
    // Check piece elevation was updated
    assertElevationEqualPiece(pieceElevation + 4 / planComponent.getScale(), piece);

    // 14. Click three times on undo button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          frame.undoButton.doClick();
          frame.undoButton.doClick();
          frame.undoButton.doClick();
        }
      });
    // Check piece dimension and elevation are canceled
    assertDimensionEqualPiece(pieceWidth, pieceDepth, pieceHeight, piece);
    assertElevationEqualPiece(pieceElevation, piece);
   
    // Build an ordered list of dimensions added to home
    final ArrayList<DimensionLine> orderedDimensionLines = new ArrayList<DimensionLine>();
    frame.home.addDimensionLinesListener(new CollectionListener<DimensionLine>() {
      public void collectionChanged(CollectionEvent<DimensionLine> ev) {
        if (ev.getType() == CollectionEvent.Type.ADD) {
          orderedDimensionLines.add(ev.getItem());
        }
      }
    });
   
    // 15. Use CREATE_DIMENSION_LINES mode
    tester.invokeAndWait(new Runnable() {
        public void run() {
          frame.createDimensionsButton.doClick();
        }
      });
    // Draw a dimension in plan
    tester.actionClick(planComponent, 280, 81);
    tester.actionClick(planComponent, 281, 169, InputEvent.BUTTON1_MASK, 2);
    // Draw a dimension with extension lines
    tester.actionClick(planComponent, 41, 175);
    tester.actionClick(planComponent, 269, 175);
    tester.actionClick(planComponent, 280, 185);
    // Check 2 dimensions were added to home plan
    assertEquals("Wrong dimensions count", 2, frame.home.getDimensionLines().size());
    // Check one dimension is selected
    assertEquals("Wrong selection", 1, frame.home.getSelectedItems().size());
    assertEquals("Selection doesn't contain the second dimension",
        frame.home.getSelectedItems().get(0), orderedDimensionLines.get(1));
    // Check the size of the created dimension lines
    DimensionLine firstDimensionLine = orderedDimensionLines.get(0);
    assertEqualsDimensionLine(520, 122, 520, 298, 0, firstDimensionLine);
    assertEqualsDimensionLine(42, 310, 498, 310, 20, orderedDimensionLines.get(1));
   
    // 16. Select the first dimension line
    tester.click(frame.selectButton);
    tester.actionClick(planComponent, 280, 90);
    assertEquals("Wrong selection", 1, frame.home.getSelectedItems().size());
    assertEquals("Selection doesn't contain the first dimension",
        frame.home.getSelectedItems().get(0), firstDimensionLine);
    // Move its end point to (330, 167)
    tester.actionMousePress(planComponent, new ComponentLocation(new Point(280, 167)));
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(320, 167)));
    // Check its coordinates while Shift key isn't pressed (with magnetism)
    assertEqualsDimensionLine(520, 122, 567.105f, 297.7985f, 0, firstDimensionLine);
    // Check its length with magnetism
    float firstDimensionLineLength = (float)Point2D.distance(
        firstDimensionLine.getXStart(), firstDimensionLine.getYStart(),
        firstDimensionLine.getXEnd(), firstDimensionLine.getYEnd());
    assertTrue("Incorrect length 182 " + firstDimensionLineLength,
        Math.abs(182 - firstDimensionLineLength) < 1E-4);
    // Press Shift key
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    // Check its coordinates while Shift key is pressed (with no magnetism)
    assertEqualsDimensionLine(520, 122, 600, 298, 0, firstDimensionLine);
    // Release Shift key and mouse button
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);   
    tester.actionMouseRelease();
    assertEqualsDimensionLine(520, 122, 567.105f, 297.7985f, 0, firstDimensionLine);
   
    // 17. Click three times on undo button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          frame.undoButton.doClick();
          frame.undoButton.doClick();
          frame.undoButton.doClick();
        }
      });
    // Check home doesn't contain any dimension
    assertEquals("Home dimensions set isn't empty", 0, frame.home.getDimensionLines().size());
   
    // 18. Click twice on redo button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          frame.redoButton.doClick();
          frame.redoButton.doClick();
        }
      });
    // Check the size of the created dimension lines
    assertEqualsDimensionLine(520, 122, 520, 298f, 0, firstDimensionLine);
    assertEqualsDimensionLine(42, 310, 498, 310, 20, orderedDimensionLines.get(1));
    // Click again on redo button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          frame.redoButton.doClick();
        }
      });
    // Check the first dimension is selected
    assertEquals("Wrong selection", 1, frame.home.getSelectedItems().size());
    assertEquals("Selection doesn't contain the first dimension",
        frame.home.getSelectedItems().get(0), firstDimensionLine);
    // Check the coordinates of the first dimension
    assertEqualsDimensionLine(520, 122, 567.105f, 297.7985f, 0, firstDimensionLine);
   
    // 19. Select two walls, the piece and a dimension line
    tester.actionMousePress(planComponent, new ComponentLocation(new Point(20, 100)));
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(200, 200)));
    tester.actionMouseRelease();
    // Check selection
    selectedItems = frame.home.getSelectedItems();
    assertEquals("Selection doesn't contain 4 items", 4, selectedItems.size());   
    int wallsCount = frame.home.getWalls().size();
    int furnitureCount = frame.home.getFurniture().size();
    int dimensionLinesCount = frame.home.getDimensionLines().size();
    HomePieceOfFurniture selectedPiece = Home.getFurnitureSubList(selectedItems).get(0);
    pieceX = selectedPiece.getX();
    pieceY = selectedPiece.getY();
    // Start items duplication
    tester.actionKeyPress(OperatingSystem.isMacOSX() ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL);
    tester.actionMousePress(planComponent, new ComponentLocation(new Point(50, 170)));
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(51, 170)));
    // Check selection changed
    assertFalse("Selection didn't change", selectedItems.equals(frame.home.getSelectedItems()));
    assertEquals("Selection doesn't contain 4 items", 4, frame.home.getSelectedItems().size());   
    assertEquals("No new wall", wallsCount + 2, frame.home.getWalls().size());   
    assertEquals("No new piece", furnitureCount + 1, frame.home.getFurniture().size());   
    assertEquals("No new dimension lines", dimensionLinesCount + 1, frame.home.getDimensionLines().size());
   
    // 20. Duplicate and move items
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(70, 200)));
    // Check the piece moved and the original piece didn't move
    HomePieceOfFurniture movedPiece =
        Home.getFurnitureSubList(frame.home.getSelectedItems()).get(0);
    assertLocationAndOrientationEqualPiece(pieceX + 20 / planComponent.getScale(),
        pieceY + 30 / planComponent.getScale(), selectedPiece.getAngle(), movedPiece);
    assertLocationAndOrientationEqualPiece(pieceX, pieceY, selectedPiece.getAngle(), selectedPiece);
   
    // 21. Release Alt key
    tester.actionKeyRelease(OperatingSystem.isMacOSX() ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL);
    // Check original items replaced duplicated items
    assertTrue("Original items not selected", selectedItems.equals(frame.home.getSelectedItems()));
    assertLocationAndOrientationEqualPiece(pieceX + 20 / planComponent.getScale(),
        pieceY + 30 / planComponent.getScale(), selectedPiece.getAngle(), selectedPiece);
    assertFalse("Duplicated piece still in home", frame.home.getFurniture().contains(movedPiece));
    // Press Alt key again
    tester.actionKeyPress(OperatingSystem.isMacOSX() ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL);
    // Check the duplicated piece moved and the original piece moved back to its original location
    movedPiece = Home.getFurnitureSubList(frame.home.getSelectedItems()).get(0);
    assertLocationAndOrientationEqualPiece(pieceX + 20 / planComponent.getScale(),
        pieceY + 30 / planComponent.getScale(), selectedPiece.getAngle(), movedPiece);
    assertLocationAndOrientationEqualPiece(pieceX, pieceY, selectedPiece.getAngle(), selectedPiece);
    // Press Escape key
    tester.actionKeyStroke(KeyEvent.VK_ESCAPE);
    // Check no items where duplicated
    assertTrue("Original items not selected", selectedItems.equals(frame.home.getSelectedItems()));
    assertLocationAndOrientationEqualPiece(pieceX, pieceY, selectedPiece.getAngle(), selectedPiece);
    assertEquals("New walls created", wallsCount, frame.home.getWalls().size());   
    assertEquals("New pieces created", furnitureCount, frame.home.getFurniture().size());   
    assertEquals("New dimension lines created", dimensionLinesCount, frame.home.getDimensionLines().size());
    tester.actionMouseRelease();
   
    // 22. Duplicate items
    tester.actionMousePress(planComponent, new ComponentLocation(new Point(50, 170)));
    tester.actionMouseMove(planComponent, new ComponentLocation(new Point(50, 190)));
    tester.actionMouseRelease();
    tester.actionKeyRelease(OperatingSystem.isMacOSX() ? KeyEvent.VK_ALT : KeyEvent.VK_CONTROL);
    // Check the duplicated piece moved and the original piece didn't move
    List<Selectable> movedItems = frame.home.getSelectedItems();
    assertEquals("Selection doesn't contain 4 items", 4, movedItems.size());   
    movedPiece = Home.getFurnitureSubList(movedItems).get(0);
    assertLocationAndOrientationEqualPiece(pieceX,
        pieceY + 20 / planComponent.getScale(), selectedPiece.getAngle(), movedPiece);
    assertLocationAndOrientationEqualPiece(pieceX, pieceY, selectedPiece.getAngle(), selectedPiece);
    // Check the duplicated walls are joined to each other
    List<Wall> movedWalls = Home.getWallsSubList(movedItems);
    Wall movedWall1 = movedWalls.get(0);
    Wall movedWall2 = movedWalls.get(1);
View Full Code Here

    JComponent homeView = (JComponent)controller.getView();
    final FurnitureCatalogTree catalogTree = (FurnitureCatalogTree)TestUtilities.findComponent(
         homeView, FurnitureCatalogTree.class);
    FurnitureTable furnitureTable = (FurnitureTable)TestUtilities.findComponent(
        homeView, FurnitureTable.class);
    final PlanComponent planComponent = (PlanComponent)TestUtilities.findComponent(
         homeView, PlanComponent.class);

    // 1. Create a frame that displays a home view
    JFrame frame = new JFrame("Home TransferHandler Test");   
    frame.add(homeView);
    frame.pack();
    // Ensure clipboard is empty
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(""), null);

    // Show home plan frame
    showWindow(frame);
    final JComponentTester tester = new JComponentTester();
    tester.waitForIdle();
    // Check catalog tree has default focus
    assertTrue("Tree doesn't have the focus", catalogTree.isFocusOwner());
    // Check Cut, Copy, Paste and Delete actions are disable
    assertActionsEnabled(controller, false, false, false, false);
   
    // 2. Select the first piece of furniture in catalog
    tester.invokeAndWait(new Runnable() {
      public void run() {
        catalogTree.expandRow(0);
        catalogTree.addSelectionInterval(1, 1);
      }
    });
    // Check only Copy action is enabled
    assertActionsEnabled(controller, false, true, false, false);
   
    // 3. Drag and drop selected piece in tree to point (120, 120) in plan component
    Rectangle selectedRowBounds = catalogTree.getRowBounds(1);
    tester.actionDrag(catalogTree, new ComponentLocation(
        new Point(selectedRowBounds.x, selectedRowBounds.y)));
    tester.actionDrop(planComponent, new ComponentLocation(
        new Point(120, 120)));
    tester.waitForIdle();
    // Check a piece was added to home
    assertEquals("Wrong piece count in home", 1, home.getFurniture().size());
    // Check top left corner of the piece is at (200, 200)
    HomePieceOfFurniture piece = home.getFurniture().get(0);
    assertTrue("Incorrect X " + piece.getX(),
        Math.abs(200 - piece.getX() + piece.getWidth() / 2) < 1E-5);
    assertTrue("Incorrect Y " + piece.getY(),
        Math.abs(200 - piece.getY() + piece.getDepth() / 2) < 1E-5);

    // 4.  Transfer focus to plan view with TAB keys
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    tester.actionKeyStroke(KeyEvent.VK_TAB);
    // Check plan component has focus
    assertTrue("Plan doesn't have the focus", planComponent.isFocusOwner());
    // Check Cut, Copy and Delete actions are enabled in plan view
    assertActionsEnabled(controller, true, true, false, true);

    // 5. Use Wall creation mode
    tester.invokeAndWait(new Runnable() {
View Full Code Here

TOP

Related Classes of com.eteks.sweethome3d.swing.PlanComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.