Package com.eteks.sweethome3d.model

Examples of com.eteks.sweethome3d.model.Home


   
    // Read home in a threaded task
    Callable<Void> openTask = new Callable<Void>() {
          public Void call() throws RecorderException {
            // Read home with application recorder
            Home openedHome = application.getHomeRecorder().readHome(homeName);
            openedHome.setName(homeName);
            addHomeToApplication(openedHome);
            return null;
          }
        };
    ThreadedTaskController.ExceptionHandler exceptionHandler =
View Full Code Here


      connection = new URL(readHomeURL).openConnection();
      connection.setRequestProperty("Content-Type", "charset=UTF-8");
      connection.setUseCaches(false);
      in = new DefaultHomeInputStream(connection.getInputStream());
      // Read home with HomeInputStream
      Home home = in.readHome();
      return home;
    } catch (InterruptedIOException ex) {
      throw new InterruptedRecorderException("Read " + name + " interrupted");
    } catch (IOException ex) {
      throw new RecorderException("Can't read home from " + name, ex);
View Full Code Here

    private final JButton        undoButton;
    private final JButton        redoButton;

    public TestFrame() {
      super("Home Plan Component Test");
      this.home = new Home();
      this.home.getCompass().setVisible(false);
      UserPreferences preferences = new DefaultUserPreferences();     
      ViewFactory viewFactory = new SwingViewFactory();
      this.homeController = new HomeController(home, preferences, viewFactory);
      JComponent homeView = (JComponent)this.homeController.getView();
View Full Code Here

  public void testTransferHandler() throws ComponentSearchException, UnsupportedFlavorException,
                                           IOException, InterruptedException, InvocationTargetException {
    UserPreferences preferences = new DefaultUserPreferences();
    preferences.setFurnitureCatalogViewedInTree(true);
    ViewFactory viewFactory = new SwingViewFactory();
    Home home = new Home();
    home.getCompass().setVisible(false);
    final HomeController controller = new HomeController(home, preferences, viewFactory);
    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() {
      public void run() {
        controller.getPlanController().setMode(PlanController.Mode.WALL_CREATION);
      }
    });
    // Check Cut, Copy, Paste actions are enabled
    assertActionsEnabled(controller, true, true, false, true);   
    // Create a wall between points (25, 25) and (100, 25)
    tester.actionClick(planComponent, 25, 25);
    // Check Cut, Copy, Paste actions are disabled during wall drawing
    assertActionsEnabled(controller, false, false, false, false);   
    tester.actionClick(planComponent, 100, 25, InputEvent.BUTTON1_MASK, 2);

    // 6. Use Dimension creation mode
    tester.invokeAndWait(new Runnable() {
      public void run() {
        controller.getPlanController().setMode(PlanController.Mode.DIMENSION_LINE_CREATION);
      }
    });
    // Check Cut, Copy, Paste actions are enabled
    assertActionsEnabled(controller, true, true, false, true);
    // 7. Create a dimension line between points (25, 35) and (100, 35)
    tester.actionClick(planComponent, 25, 35);
    // Check Cut, Copy, Paste actions are disabled during dimension line drawing
    assertActionsEnabled(controller, false, false, false, false);   
    tester.actionClick(planComponent, 100, 35, InputEvent.BUTTON1_MASK, 2);
    // Use Selection mode
    tester.invokeAndWait(new Runnable() {
        public void run() {
          controller.getPlanController().setMode(PlanController.Mode.SELECTION);
        }
      });
    // Check Cut, Copy and Delete actions are enabled
    assertActionsEnabled(controller, true, true, false, true);
   
    // 7. Select the dimension, the wall and the piece
    tester.actionKeyPress(KeyEvent.VK_SHIFT);
    tester.actionClick(planComponent, 30, 25);
    tester.actionClick(planComponent, 120, 120);
    tester.actionKeyRelease(KeyEvent.VK_SHIFT);
    // Check home selection contains 3 items
    assertEquals("Selected items wrong count", 3, home.getSelectedItems().size());
    // Cut selected items in plan component
    runAction(tester, controller, HomePane.ActionType.CUT);
    // Check home is empty
    assertEquals("Wrong piece count in home", 0, home.getFurniture().size());
    assertEquals("Wrong wall count in home", 0, home.getWalls().size());
    assertEquals("Wrong dimension count in home", 0, home.getDimensionLines().size());
    // Check only Paste action is enabled
    assertActionsEnabled(controller, false, false, true, false);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    // Check clipboard contains two different data flavors (HomeTransferableList and Image)
    assertTrue("Missing home data flavor", clipboard.isDataFlavorAvailable(HomeTransferableList.HOME_FLAVOR));
    assertTrue("Missing String flavor", clipboard.isDataFlavorAvailable(DataFlavor.imageFlavor));

    // 8. Paste selected items in plan component
    runAction(tester, controller, HomePane.ActionType.PASTE);
    tester.waitForIdle();
    // Check home contains one piece, one wall and one dimension
    assertEquals("Wrong piece count in home", 1, home.getFurniture().size());
    assertEquals("Wrong wall count in home", 1, home.getWalls().size());
    assertEquals("Wrong dimension count in home", 1, home.getDimensionLines().size());

    // 9. Transfer focus to furniture table
    tester.actionKeyStroke(KeyEvent.VK_TAB, InputEvent.SHIFT_MASK);
    // Check furniture table has focus
    assertTrue("Table doesn't have the focus", furnitureTable.isFocusOwner());
    // Delete selection
    runAction(tester, controller, HomePane.ActionType.DELETE);
    // Check home contains no piece, one wall and one dimension
    assertEquals("Wrong piece count in home", 0, home.getFurniture().size());
    assertEquals("Wrong wall count in home", 1, home.getWalls().size());
    assertEquals("Wrong dimension count in home", 1, home.getDimensionLines().size());
    // Check only Paste action is enabled
    assertActionsEnabled(controller, false, false, true, false);

    // 10. Paste selected items in furniture table
    runAction(tester, controller, HomePane.ActionType.PASTE);
    // Check home contains one piece, one wall and one dimension
    assertEquals("Wrong piece count in home", 1, home.getFurniture().size());
    assertEquals("Wrong wall count in home", 1, home.getWalls().size());
    assertEquals("Wrong dimension count in home", 1, home.getDimensionLines().size());
    // Check Cut, Copy and Paste actions are enabled
    assertActionsEnabled(controller, true, true, true, true);
   
    // 11. Copy selected furniture in clipboard while furniture table has focus
    runAction(tester, controller, HomePane.ActionType.COPY);   
View Full Code Here

    Locale.setDefault(Locale.FRANCE);
    UserPreferences preferences = new DefaultUserPreferences();
    SwingViewFactory viewFactory = new SwingViewFactory();
    ContentManager contentManager = new FileContentManager(preferences);
    // Create a home and add a selected piece of furniture to it
    Home home = new Home();
    PieceOfFurniture firstPiece = preferences.getFurnitureCatalog().
        getCategories().get(0).getFurniture().get(0);
    HomePieceOfFurniture piece1 = new HomePieceOfFurniture(firstPiece);
    home.addPieceOfFurniture(piece1);
    home.setSelectedItems(Arrays.asList(new HomePieceOfFurniture [] {piece1}));

    // 2. Create a home piece of furniture panel to edit piece
    HomeFurnitureController controller = new HomeFurnitureController(home, preferences, viewFactory, contentManager, null);
    // Check values stored by furniture panel components are equal to the ones set
    assertFurnitureControllerEquals(piece1.getName(), piece1.getX(),
        piece1.getY(), piece1.getElevation(), (int)Math.toDegrees(piece1.getAngle()), piece1.getWidth(),
        piece1.getDepth(), piece1.getHeight(), piece1.getColor(),
        piece1.isVisible(), piece1.isModelMirrored(), controller);

    // 3. Add a second selected piece to home
    HomePieceOfFurniture piece2 = new HomePieceOfFurniture(firstPiece);
    home.addPieceOfFurniture(piece2);
    piece2.setX(piece1.getX());
    piece2.setY(piece1.getY() + 10);
    piece2.setElevation(piece1.getElevation() + 10);
    piece2.setWidth(piece1.getWidth());
    piece2.setDepth(piece1.getDepth() + 10);
    piece2.setHeight(piece1.getHeight() + 10);
    piece2.setColor(0xFF00FF);
    piece2.setVisible(!piece1.isVisible());
    piece2.setModelMirrored(!piece1.isModelMirrored());
    home.setSelectedItems(Arrays.asList(new HomePieceOfFurniture [] {piece1, piece2}));
    // Check if furniture panel edits null values
    // if some furniture properties are the same
    controller = new HomeFurnitureController(home, preferences, viewFactory, contentManager, null);
    // Check values stored by furniture panel components are equal to the ones set
    assertFurnitureControllerEquals(piece1.getName(), piece1.getX(), null, null, (int)Math.toDegrees(piece1.getAngle()),
View Full Code Here

  }

  public static void main(String [] args) {
    // Create a selected piece of furniture in a home and display it in a furniture panel
    UserPreferences preferences = new DefaultUserPreferences();
    Home home = new Home();
    PieceOfFurniture firstPiece = preferences.getFurnitureCatalog().
        getCategories().get(0).getFurniture().get(0);
    HomePieceOfFurniture piece1 = new HomePieceOfFurniture(firstPiece);
    home.addPieceOfFurniture(piece1);
    home.setSelectedItems(Arrays.asList(new HomePieceOfFurniture [] {piece1}));
   
    HomeFurnitureController controller = new HomeFurnitureController(home, preferences,
        new SwingViewFactory(), new FileContentManager(preferences), null);
    HomeFurniturePanel furniturePanel =
        new HomeFurniturePanel(preferences, controller);
View Full Code Here

public class PrintTest extends ComponentTestFixture {
  public void testPageSetupAndPrintPreview() throws ComponentSearchException, InterruptedException,
      NoSuchFieldException, IllegalAccessException, InvocationTargetException, IOException {
    UserPreferences preferences = new DefaultUserPreferences();
    ViewFactory viewFactory = new SwingViewFactory();
    Home home = new Home();
    ContentManager contentManager = new FileContentManager(preferences) {
        @Override
        public String showSaveDialog(View parentView, String dialogTitle, ContentType contentType, String name) {
          String os = System.getProperty("os.name");
          if (OperatingSystem.isMacOSX()) {
            // Let's pretend the OS isn't Mac OS X to get a JFileChooser instance that works better in test
            System.setProperty("os.name", "dummy");
          }
          try {
            return super.showSaveDialog(parentView, dialogTitle, contentType, name);
          } finally {
            System.setProperty("os.name", os);
          }
        }
      };
    final HomeController controller =
        new HomeController(home, preferences, viewFactory, contentManager);

    // 1. Create a frame that displays a home view
    JFrame frame = new JFrame("Home Print Test");   
    frame.add((JComponent)controller.getView());
    frame.pack();

    // Show home frame
    showWindow(frame);
    JComponentTester tester = new JComponentTester();
    tester.waitForIdle();
    // Add a piece of furniture to home
    List<CatalogPieceOfFurniture> selectedPieces = Arrays.asList(
        new CatalogPieceOfFurniture [] {preferences.getFurnitureCatalog().getCategories().get(0).getFurniture().get(0)});
    controller.getFurnitureCatalogController().setSelectedFurniture(selectedPieces);
    tester.invokeAndWait(new Runnable() {
      public void run() {
        runAction(controller, HomePane.ActionType.ADD_HOME_FURNITURE);
      }
    });
    // Check home contains one piece
    assertEquals("Home doesn't contain any furniture", 1, home.getFurniture().size());
   
    // 2. Edit page setup dialog box
    tester.invokeLater(new Runnable() {
        public void run() {
          // Display dialog box later in Event Dispatch Thread to avoid blocking test thread
          runAction(controller, HomePane.ActionType.PAGE_SETUP);
        }
      });
    // Wait for page setup to be shown
    tester.waitForFrameShowing(new AWTHierarchy(), preferences.getLocalizedString(
        PageSetupPanel.class, "pageSetup.title"));
    // Check dialog box is displayed
    JDialog pageSetupDialog = (JDialog)TestUtilities.findComponent(
        frame, JDialog.class);
    assertTrue("Page setup dialog not showing", pageSetupDialog.isShowing());
    // Retrieve PageSetupPanel components
    PageSetupPanel pageSetupPanel = (PageSetupPanel)TestUtilities.findComponent(
        frame, PageSetupPanel.class);
    JCheckBox furniturePrintedCheckBox =
        (JCheckBox)TestUtilities.getField(pageSetupPanel, "furniturePrintedCheckBox");
    JCheckBox planPrintedCheckBox =
        (JCheckBox)TestUtilities.getField(pageSetupPanel, "planPrintedCheckBox");;
    JCheckBox view3DPrintedCheckBox =
        (JCheckBox)TestUtilities.getField(pageSetupPanel, "view3DPrintedCheckBox");
    // Check default edited values
    assertTrue("Furniture printed not checked", furniturePrintedCheckBox.isSelected());
    assertTrue("Plan printed not checked", planPrintedCheckBox.isSelected());
    assertTrue("View 3D printed not checked", view3DPrintedCheckBox.isSelected());
   
    // 3. Change dialog box values
    planPrintedCheckBox.setSelected(false);
    // Click on Ok in dialog box
    final JOptionPane pageSetupOptionPane = (JOptionPane)TestUtilities.findComponent(
        pageSetupDialog, JOptionPane.class);
    tester.invokeAndWait(new Runnable() {
        public void run() {
          // Select Ok option to hide dialog box in Event Dispatch Thread
          pageSetupOptionPane.setValue(JOptionPane.OK_OPTION);
        }
      });
    assertFalse("Page setup dialog still showing", pageSetupDialog.isShowing());
    PageFormat pageFormat = PrinterJob.getPrinterJob().defaultPage();
    // Check home print attributes are modified accordingly
    assertHomePrintEqualPrintAttributes(pageFormat, true, false, true, home);
   
    // 4. Undo changes
    runAction(controller, HomePane.ActionType.UNDO);
    // Check home attributes have previous values
    assertEquals("Home print set", null, home.getPrint());
    // Redo
    runAction(controller, HomePane.ActionType.REDO);
    // Check home attributes are modified accordingly
    assertHomePrintEqualPrintAttributes(pageFormat, true, false, true, home);
   
View Full Code Here

      public String showSaveDialog(View parentView, String dialogTitle, ContentType contentType, String name) {
        return null;
      }     
    };
    Home home = new Home();
    final HomeController controller =
        new HomeController(home, preferences, viewFactory, contentManager);
    final JComponent homeView = (JComponent)controller.getView();
    final List<CatalogPieceOfFurniture> addedCatalogFurniture = new ArrayList<CatalogPieceOfFurniture>();
    preferences.getFurnitureCatalog().addFurnitureListener(new CollectionListener<CatalogPieceOfFurniture>() {
        public void collectionChanged(CollectionEvent<CatalogPieceOfFurniture> ev) {
          addedCatalogFurniture.add(ev.getItem());
        }
      });

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

    // Show home plan frame
    showWindow(frame);
    JComponentTester tester = new JComponentTester();
    tester.waitForIdle();   

    // 2. Transfer focus to plan view
    ((JComponent)controller.getPlanController().getView()).requestFocusInWindow();     
    tester.waitForIdle();   

    // Check plan view has focus
    assertTrue("Plan component doesn't have the focus",
        ((JComponent)controller.getPlanController().getView()).isFocusOwner());
    // Open wizard to import a test object (1 width x 2 depth x 3 height) in plan
    tester.invokeLater(new Runnable() {
        public void run() {
          // Display dialog box later in Event Dispatch Thread to avoid blocking test thread
          homeView.getActionMap().get(HomePane.ActionType.IMPORT_FURNITURE).actionPerformed(null);
        }
      });
    // Wait for import furniture view to be shown
    tester.waitForFrameShowing(new AWTHierarchy(), preferences.getLocalizedString(
        ImportedFurnitureWizardController.class, "importFurnitureWizard.title"));
    // Check dialog box is displayed
    JDialog wizardDialog = (JDialog)TestUtilities.findComponent(frame, JDialog.class);
    assertTrue("Wizard view dialog not showing", wizardDialog.isShowing());

    // Retrieve ImportedFurnitureWizardStepsPanel components
    ImportedFurnitureWizardStepsPanel panel = (ImportedFurnitureWizardStepsPanel)TestUtilities.findComponent(
        frame, ImportedFurnitureWizardStepsPanel.class);
    final JButton modelChoiceOrChangeButton = (JButton)TestUtilities.getField(panel, "modelChoiceOrChangeButton");
    final JButton turnLeftButton = (JButton)TestUtilities.getField(panel, "turnLeftButton");
    final JButton turnDownButton = (JButton)TestUtilities.getField(panel, "turnDownButton");
    JCheckBox backFaceShownCheckBox = (JCheckBox)TestUtilities.getField(panel, "backFaceShownCheckBox");
    final JTextField nameTextField = (JTextField)TestUtilities.getField(panel, "nameTextField");
    final JCheckBox addToCatalogCheckBox = (JCheckBox)TestUtilities.getField(panel, "addToCatalogCheckBox");
    final JComboBox categoryComboBox = (JComboBox)TestUtilities.getField(panel, "categoryComboBox");
    final JSpinner widthSpinner = (JSpinner)TestUtilities.getField(panel, "widthSpinner");
    JSpinner heightSpinner = (JSpinner)TestUtilities.getField(panel, "heightSpinner");
    JSpinner depthSpinner = (JSpinner)TestUtilities.getField(panel, "depthSpinner");
    final JCheckBox keepProportionsCheckBox = (JCheckBox)TestUtilities.getField(panel, "keepProportionsCheckBox");
    JSpinner elevationSpinner = (JSpinner)TestUtilities.getField(panel, "elevationSpinner");
    JCheckBox movableCheckBox = (JCheckBox)TestUtilities.getField(panel, "movableCheckBox");
    JCheckBox doorOrWindowCheckBox = (JCheckBox)TestUtilities.getField(panel, "doorOrWindowCheckBox");
    ColorButton colorButton = (ColorButton)TestUtilities.getField(panel, "colorButton");
    final JButton clearColorButton = (JButton)TestUtilities.getField(panel, "clearColorButton");
   
    // Check current step is model
    tester.waitForIdle();
    assertStepShowing(panel, true, false, false, false);   
   
    // 3. Choose tested model
    String modelChoiceOrChangeButtonText = modelChoiceOrChangeButton.getText();
    tester.invokeAndWait(new Runnable() {
        public void run() {
          modelChoiceOrChangeButton.doClick();
        }
      });
    // Wait 1 s to let time to Java 3D to load the model
    Thread.sleep(1000);
    // Check choice button text changed
    assertFalse("Choice button text didn't change",
        modelChoiceOrChangeButtonText.equals(modelChoiceOrChangeButton.getText()));
    // Click on next button
    WizardPane view = (WizardPane)TestUtilities.findComponent(frame, WizardPane.class);
    // Retrieve wizard view next button
    final JButton nextFinishOptionButton = (JButton)TestUtilities.getField(view, "nextFinishOptionButton");
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());   
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton.doClick();
        }
      });
    // Check current step is rotation
    assertStepShowing(panel, false, true, false, false);   
    // Check back face shown check box isn't selected by default
    assertFalse("Back face shown check box is selected", backFaceShownCheckBox.isSelected());
   
    // 4. Click on left button
    float width = (Float)widthSpinner.getValue();
    float depth = (Float)depthSpinner.getValue();
    float height = (Float)heightSpinner.getValue();
    tester.invokeAndWait(new Runnable() {
        public void run() {
          turnLeftButton.doClick();
        }
      });
    // Check depth and width values were swapped
    float newWidth = (Float)widthSpinner.getValue();
    float newDepth = (Float)depthSpinner.getValue();
    float newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", depth, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", width, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", height, newHeight, 1E-3f);
    // Click on down button
    width = newWidth;
    depth = newDepth;
    height = newHeight;
    tester.invokeAndWait(new Runnable() {
        public void run() {
          turnDownButton.doClick();
        }
      });
    // Check height and depth values were swapped
    newWidth = (Float)widthSpinner.getValue();
    newDepth = (Float)depthSpinner.getValue();
    newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", width, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", height, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", depth, newHeight, 1E-3f);
   
    // 5. Click on next button
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton.doClick();
        }
      });
    // Check current step is attributes
    assertStepShowing(panel, false, false, true, false);   
       
    // 6. Check default furniture name is the presentation name proposed by content manager
    assertEquals("Wrong default name"
        contentManager.getPresentationName(testedModelName.toString(), ContentManager.ContentType.MODEL),
        nameTextField.getText());
    // Check Add to catalog check box isn't selected and category combo box
    // is disabled when furniture is imported in home
    assertFalse("Add to catalog check box is selected", addToCatalogCheckBox.isSelected());
    assertFalse("Category combo box isn't disabled", categoryComboBox.isEnabled());
    // Check default category is first category 
    final FurnitureCategory firstCategory = preferences.getFurnitureCatalog().getCategories().get(0);
    assertEquals("Wrong default category", firstCategory, categoryComboBox.getSelectedItem());
    // Rename furniture with the name of the catalog first piece
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nameTextField.setText(firstCategory.getFurniture().get(0).getName());
        }
      });
    // Check next button is enabled
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
    // Select Add to catalog check box
    tester.invokeAndWait(new Runnable() {
        public void run() {
          addToCatalogCheckBox.setSelected(true);
        }
      });
    // Check next button is disabled because imported furniture has a wrong name
    assertFalse("Next button isn't disabled", nextFinishOptionButton.isEnabled());
    // Rename furniture and its category
    final String pieceTestName = "#@" + System.currentTimeMillis() + "@#";
    final String categoryTestName = "sdfghjkl";
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nameTextField.setText(pieceTestName);
          categoryComboBox.getEditor().selectAll();
        }
      });
    tester.actionKeyString(categoryComboBox.getEditor().getEditorComponent(), categoryTestName);   
    // Check next button is enabled again
    assertTrue("Next button isn't enabled", nextFinishOptionButton.isEnabled());
   
    // 7. Check keep proportions check box is selected by default
    assertTrue("Keep proportions check box isn't selected", keepProportionsCheckBox.isSelected());
    // Change width with a value 10 times greater
    width = newWidth;
    depth = newDepth;
    height = newHeight;
    final float enteredWidth = newWidth * 10;
    tester.invokeAndWait(new Runnable() {
        public void run() {
          widthSpinner.setValue(enteredWidth);
        }
      });
    // Check height and depth values are 10 times greater
    newWidth = (Float)widthSpinner.getValue();
    newDepth = (Float)depthSpinner.getValue();
    newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", 10 * width, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", 10 * depth, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", 10 * height, newHeight, 1E-3f);
    // Deselect keep proportions check box
    tester.invokeAndWait(new Runnable() {
        public void run() {
          keepProportionsCheckBox.setSelected(false);
        }
      });      
    // Change width with a value 2 times greater
    width = newWidth;
    depth = newDepth;
    height = newHeight;
    final float twiceValue = newWidth * 2;
    tester.invokeAndWait(new Runnable() {
        public void run() {
          widthSpinner.setValue(twiceValue);
        }
      });
    // Check height and depth values didn't change
    newWidth = (Float)widthSpinner.getValue();
    newDepth = (Float)depthSpinner.getValue();
    newHeight = (Float)heightSpinner.getValue();
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", 2 * width, newWidth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", depth, newDepth, 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", height, newHeight, 1E-3f);

    // 8. Change elevation, movable, door or window, color default values
    assertEquals("Wrong default elevation", 0f, (Float)elevationSpinner.getValue());
    elevationSpinner.setValue(10);
    assertTrue("Movable check box isn't selected", movableCheckBox.isSelected());
    movableCheckBox.setSelected(false);
    assertFalse("Door or window check box is selected", doorOrWindowCheckBox.isSelected());
    doorOrWindowCheckBox.setSelected(true);
    assertEquals("Wrong default color", null, colorButton.getColor());
    assertFalse("Clear color button isn't disabled", clearColorButton.isEnabled());
    // Change color
    colorButton.setColor(0x000000);
    // Check clear color button is enabled
    assertTrue("Clear color button isn't enabled", clearColorButton.isEnabled());
    // Click on clear color button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          clearColorButton.doClick();
        }
      });
    // Check color is null and clear color button is disabled
    assertEquals("Wrong color", null, colorButton.getColor());
    assertFalse("Clear color button isn't disabled", clearColorButton.isEnabled());
    // 9. Click on next button
    tester.invokeAndWait(new Runnable() {
        public void run() {
          nextFinishOptionButton.doClick();
        }
      });
    // Check current step is icon
    assertStepShowing(panel, false, false, false, true);   
    tester.invokeAndWait(new Runnable() {
        public void run() {
          // Click on Finish to hide dialog box in Event Dispatch Thread
          nextFinishOptionButton.doClick();
        }
      });
   
    // 10. Check the matching new catalog piece of furniture was created
    List<CatalogPieceOfFurniture> selectedCatalogFurniture =
        controller.getFurnitureCatalogController().getSelectedFurniture();
    assertEquals("Wrong selected furniture count in catalog", 0, selectedCatalogFurniture.size());
    assertEquals("Incorrect count of created catalog piece", 1, addedCatalogFurniture.size());   
    CatalogPieceOfFurniture catalogPiece = addedCatalogFurniture.get(0);
    assertEquals("Wrong catalog piece name", pieceTestName, catalogPiece.getName());
    assertEquals("Wrong catalog piece category name", categoryTestName, catalogPiece.getCategory().getName());
    assertTrue("Catalog doesn't contain new piece",
        preferences.getFurnitureCatalog().getCategories().contains(catalogPiece.getCategory()));
    TestUtilities.assertEqualsWithinEpsilon("Incorrect width", newWidth, catalogPiece.getWidth(), 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect depth", newDepth, catalogPiece.getDepth(), 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect height", newHeight, catalogPiece.getHeight(), 1E-3f);
    TestUtilities.assertEqualsWithinEpsilon("Incorrect elevation", 10, catalogPiece.getElevation(), 1E-3f);
    assertFalse("Catalog piece is movable", catalogPiece.isMovable());
    assertTrue("Catalog piece isn't a door or window", catalogPiece.isDoorOrWindow());
    assertEquals("Wrong catalog piece color", null, catalogPiece.getColor());
    assertTrue("Catalog piece isn't modifiable", catalogPiece.isModifiable());
   
    // Check a new home piece of furniture was created and it's the selected piece in home
    List<Selectable> homeSelectedItems = home.getSelectedItems();
    assertEquals("Wrong selected furniture count in home", 1, homeSelectedItems.size());
    HomePieceOfFurniture homePiece = (HomePieceOfFurniture)homeSelectedItems.get(0);
    assertEquals("Wrong home piece name", pieceTestName, homePiece.getName());
   
    // 11. Transfer focus to tree
    JComponent catalogView = (JComponent)controller.getFurnitureCatalogController().getView();
    tester.focus(catalogView);       
    // Check plan view has focus
    assertTrue("Catalog tree doesn't have the focus", catalogView.isFocusOwner());
    // Select the piece added to catalog
    controller.getFurnitureCatalogController().setSelectedFurniture(addedCatalogFurniture);
    // Delete new catalog piece of furniture
    final Action deleteAction = homeView.getActionMap().get(HomePane.ActionType.DELETE);
    assertTrue("Delete action isn't enable", deleteAction.isEnabled());
    tester.invokeLater(new Runnable() {
        public void run() {
          deleteAction.actionPerformed(null);
        }
      });
    // Wait for confirm dialog to be shown
    tester.waitForFrameShowing(new AWTHierarchy(), preferences.getLocalizedString(
        HomePane.class, "confirmDeleteCatalogSelection.title"));
    // Find displayed dialog box
    JDialog confirmDeleteCatalogSelectionDialog = (JDialog)new BasicFinder().find(frame,
        new ClassMatcher (JDialog.class, true));
    // Click on Ok in dialog box
    final JOptionPane optionPane = (JOptionPane)TestUtilities.findComponent(
        confirmDeleteCatalogSelectionDialog, JOptionPane.class);
    tester.invokeAndWait(new Runnable() {
        public void run() {
          // Select delete option to hide dialog box in Event Dispatch Thread
          optionPane.setValue(preferences.getLocalizedString(
              HomePane.class, "confirmDeleteCatalogSelection.delete"));
        }
      });
    // Check selection is empty
    selectedCatalogFurniture = controller.getFurnitureCatalogController().getSelectedFurniture();
    assertTrue("Catalog selected furniture isn't empty", selectedCatalogFurniture.isEmpty());
    // Check catalog doesn't contain the new piece
    assertFalse("Piece is still in catalog",
        preferences.getFurnitureCatalog().getCategories().contains(catalogPiece.getCategory()));
    // Check home piece of furniture is still in home and selected
    assertTrue("Home piece isn't in home", home.getFurniture().contains(homePiece));
    assertTrue("Home piece isn't selected", home.getSelectedItems().contains(homePiece));
   
    // 12. Undo furniture creation in home
    tester.invokeAndWait(new Runnable() {
        public void run() {
          homeView.getActionMap().get(HomePane.ActionType.UNDO).actionPerformed(null);
        }
      });
    // Check home is empty
    assertTrue("Home isn't empty", home.getFurniture().isEmpty());
    // Redo
    tester.invokeAndWait(new Runnable() {
        public void run() {
          homeView.getActionMap().get(HomePane.ActionType.REDO).actionPerformed(null);
        }
      });
    // Check home piece of furniture is in home and selected
    assertTrue("Home piece isn't in home", home.getFurniture().contains(homePiece));
    assertTrue("Home piece isn't selecteed", home.getSelectedItems().contains(homePiece));
  }
View Full Code Here

      });
  }
 
  private void runPlanContollerTest() {
    // 1. Create a frame that displays a PlanComponent at its preferred size,
    Home home = new Home();
    Locale.setDefault(Locale.FRANCE);
    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());
        }
      }
View Full Code Here

    }
   
    public void selectionChanged(SelectionEvent ev) {
      // If piece 3D was garbage collected, remove this listener from home
      HomePieceOfFurniture3D piece3D = this.piece.get();
      Home home = (Home)ev.getSource();
      if (piece3D == null) {
        home.removeSelectionListener(this);
      } else {
        piece3D.updatePieceOfFurnitureVisibility();
      }
    }
View Full Code Here

TOP

Related Classes of com.eteks.sweethome3d.model.Home

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.