Package com.eteks.sweethome3d.model

Examples of com.eteks.sweethome3d.model.Home


   
    // Remove auto saved files when a home is closed
    application.addHomesListener(new CollectionListener<Home>() {
        public void collectionChanged(CollectionEvent<Home> ev) {
          if (ev.getType() == CollectionEvent.Type.DELETE) {
            final Home home = ev.getItem();
            autoSaveForRecoveryExecutor.submit(new Runnable() {
                public void run() {
                  try {
                    final File homeFile = autoSavedFiles.get(home);
                    if (homeFile != null) {
View Full Code Here


          }
        });
      for (final File file : recoveredFiles) {
        if (!isFileLocked(file)) {
          try {
            final Home home = this.application.getHomeRecorder().readHome(file.getPath());
            // Recovered homes are the ones with a name different from the file path
            if (home.getName() == null
                || !file.equals(new File(home.getName()))) {
              home.setRecovered(true);
              // Delete recovered file once home isn't recovered anymore
              home.addPropertyChangeListener(Home.Property.RECOVERED, new PropertyChangeListener() {
                  public void propertyChange(PropertyChangeEvent evt) {
                    if (!home.isRecovered()) {
                      file.delete();
                    }
                  }
                });
              this.recoveredHomes.add(home);
View Full Code Here

    try {
      EventQueue.invokeAndWait(new Runnable() {
          public void run() {
            // Handle and clone application homes in Event Dispatch Thread
            for (final Home home : application.getHomes()) {
              final Home autoSavedHome = home.clone();
              final HomeRecorder homeRecorder = application.getHomeRecorder();
              autoSaveForRecoveryExecutor.submit(new Runnable() {
                public void run() {
                  try {
                    // Save home clone in an other thread
View Full Code Here

* @author Emmanuel Puybaret
*/
public class HomeFileRecorderTest extends TestCase {
  public void testWriteReadHome() throws RecorderException {
    // 1. Create an empty home
    Home home1 = new Home();
    // Add to home a wall and a piece of furniture
    Wall wall = new Wall(0, 10, 100, 80, 10);
    home1.addWall(wall);
    FurnitureCatalog catalog = new DefaultFurnitureCatalog();
    HomePieceOfFurniture piece = new HomePieceOfFurniture(
        catalog.getCategories().get(0).getFurniture().get(0));
    home1.addPieceOfFurniture(piece);
   
    // 2. Record home in a file named test.sh3d in current directory
    HomeRecorder recorder = new HomeFileRecorder();
    String testFile = new File("test.sh3d").getAbsolutePath();
    recorder.writeHome(home1, testFile);
    // Check test.sh3d file exists
    assertTrue("File test.sh3d doesn't exist", recorder.exists(testFile));
   
    // 3. Read test.sh3d file in a new home
    Home home2 = recorder.readHome(testFile);
    // Compare home content
    assertNotSame("Home not loaded", home1, home2);
    assertEquals("Home wall height",
        home1.getWallHeight(), home2.getWallHeight());
    assertEquals("Home walls wrong count",
        home1.getWalls().size(), home2.getWalls().size());
    assertEquals(wall, home2.getWalls().iterator().next());
    assertEquals("Home furniture wrong count",
        home1.getFurniture().size(), home2.getFurniture().size());
    assertEquals(piece, home2.getFurniture().get(0));

    // Delete file
    if (!new File(testFile).delete()) {
      fail("Couldn't delete file " + testFile);
    }
View Full Code Here

    // Get furniture catalog
    FurnitureCatalog catalog = preferences.getFurnitureCatalog();
   
    // 2. Create a home that contains furniture matching catalog furniture
    List<HomePieceOfFurniture> homeFurniture = createHomeFurnitureFromCatalog(catalog);
    Home home = new Home(homeFurniture);
    // Check catalog furniture count equals home furniture count
    assertEquals("Different furniture count in list and home",
        homeFurniture.size(), home.getFurniture().size());

    // 3. Create a table that displays home furniture
    JTable table = new FurnitureTable(home, preferences);
    // Check home furniture count equals table row count
    assertEquals("Different furniture count in home and table",
        home.getFurniture().size(), table.getRowCount());
   
    // 4. Check the displayed depth in table are different in French and US version
    for (int row = 0, n = table.getRowCount(); row < n; row++) {
      preferences.setUnit(LengthUnit.INCH);
      String widthInInch = getRenderedDepth(table, row);
View Full Code Here

  public void testFurnitureTableSort() {
    // 1.  Create a home that contains furniture matching catalog furniture
    UserPreferences preferences = new DefaultUserPreferences();
    List<HomePieceOfFurniture> homeFurniture =
      createHomeFurnitureFromCatalog(preferences.getFurnitureCatalog());
    Home home = new Home(homeFurniture);
    // Check home furniture isn't empty
    assertTrue("Home furniture is empty", homeFurniture.size() > 0);

    // 2. Create a table that displays home furniture with its controller 
    FurnitureController furnitureController =
        new FurnitureController(home, preferences, new SwingViewFactory());
    FurnitureTable table = (FurnitureTable)furnitureController.getView();
   
    // 3. Sort furniture table in alphabetical order of furniture name
    furnitureController.sortFurniture(HomePieceOfFurniture.SortableProperty.NAME);
    // Check the alphabetical order of table data
    assertFurnitureIsSortedByName(table, true);
   
    // 4. Sort in descending order and check order
    furnitureController.sortFurniture(HomePieceOfFurniture.SortableProperty.NAME);
    // Check table data is sorted in alphabetical descending order
    assertFurnitureIsSortedByName(table, false);
   
    // 5. Change first furniture name
    HomePieceOfFurniture firstPiece = home.getFurniture().get(0);
    firstPiece.setName("Aaaa");
    // Check table data is sorted in alphabetical descending order
    assertFurnitureIsSortedByName(table, false);
  }
View Full Code Here

  public void testFurnitureTableFilter() {
    // 1.  Create a home that contains furniture matching catalog furniture
    UserPreferences preferences = new DefaultUserPreferences();
    List<HomePieceOfFurniture> homeFurniture =
      createHomeFurnitureFromCatalog(preferences.getFurnitureCatalog());
    Home home = new Home(homeFurniture);
    // Check home furniture isn't empty
    assertTrue("Home furniture is empty", homeFurniture.size() > 0);

    // 2. Create a table that displays home furniture with its controller 
    FurnitureController furnitureController =
        new FurnitureController(home, preferences, new SwingViewFactory());
    FurnitureTable table = (FurnitureTable)furnitureController.getView();
    assertEquals("Home furniture count and row count different", homeFurniture.size(), table.getRowCount());
    // Apply a filter on furniture that refuses pieces that are windows
    table.setFurnitureFilter(new FurnitureFilter() {
        public boolean include(Home home, HomePieceOfFurniture piece) {         
          return !piece.isDoorOrWindow();
        }
      });
    // Count how many doors and windows are in home
    int doorsAndWindowsCount = 0;
    HomePieceOfFurniture doorOrWindowPiece = null;
    HomePieceOfFurniture otherPiece = null;
    for (HomePieceOfFurniture piece : home.getFurniture()) {
      if (piece.isDoorOrWindow()) {
        doorsAndWindowsCount++;
        doorOrWindowPiece = piece;
      } else {
        otherPiece = piece;
      }
    }
    // Check there's no door or window in table
    int homeFurnitureCount = homeFurniture.size();
    int tableFilterRowCount = table.getRowCount();
    assertEquals("Home furniture count and row count same",
        homeFurnitureCount - doorsAndWindowsCount, tableFilterRowCount);
   
    // 3. Add a door or window to home
    home.addPieceOfFurniture(new HomePieceOfFurniture(doorOrWindowPiece));
    // Check no row were added in table
    assertEquals("Wrong furniture count in home", homeFurnitureCount + 1, home.getFurniture().size());
    assertEquals("Wrong row count in table", tableFilterRowCount, table.getRowCount());
   
    // 4. Add an other kind of piece to home
    home.addPieceOfFurniture(new HomePieceOfFurniture(otherPiece));
    // Check one row was added in table
    assertEquals("Wrong furniture count in home", homeFurnitureCount + 2, home.getFurniture().size());
    assertEquals("Wrong row count in table", tableFilterRowCount + 1, table.getRowCount());
   
    // 5. Test sort and filter internal buffer of the table
    furnitureController.sortFurniture(HomePieceOfFurniture.SortableProperty.NAME);
    // Check the alphabetical order of table data
    assertFurnitureIsSortedByName(table, true);
    // Add a door or window and an other kind of piece to home
    home.addPieceOfFurniture(new HomePieceOfFurniture(doorOrWindowPiece));
    home.addPieceOfFurniture(new HomePieceOfFurniture(otherPiece));
    // Check one row was added in sorted table
    assertEquals("Wrong furniture count in home", homeFurnitureCount + 4, home.getFurniture().size());
    assertEquals("Wrong row count in table", tableFilterRowCount + 2, table.getRowCount());
    assertFurnitureIsSortedByName(table, true);
   
    // 6. Remove filter
    table.setFurnitureFilter(null);
    // Check missing rows are back
    assertEquals("Home furniture count and row count different",
        home.getFurniture().size(), table.getRowCount());
    assertFurnitureIsSortedByName(table, true);
  }
View Full Code Here

  public static void main(String [] args) {
    UserPreferences preferences = new DefaultUserPreferences();
    List<HomePieceOfFurniture> homeFurniture =
      createHomeFurnitureFromCatalog(preferences.getFurnitureCatalog());
    Home home = new Home(homeFurniture);
   
    // Create a furniture table
    JTable table = new FurnitureTable(home, preferences);
    JFrame frame = new JFrame("Furniture table Test");
    frame.add(new JScrollPane(table));
View Full Code Here

  @Override
  protected void setUp() {
    this.viewFactory = new SwingViewFactory();
    this.preferences = new DefaultUserPreferences();
    this.preferences.setFurnitureCatalogViewedInTree(true);
    this.home = new Home();
    this.homeController =
        new HomeController(this.home, this.preferences, viewFactory);
    FurnitureCatalogController catalogController =
        homeController.getFurnitureCatalogController();
    this.catalogTree = (FurnitureCatalogTree)catalogController.getView();
View Full Code Here

  }
 
  public static void main(String [] args) {
    ViewFactory viewFactory = new SwingViewFactory();
    UserPreferences preferences = new DefaultUserPreferences();
    Home home = new Home();
    new ControllerTest(home, preferences, viewFactory);
  }
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.