Package com.eteks.sweethome3d.model

Examples of com.eteks.sweethome3d.model.FurnitureCategory


          name = name.trim();
          // If category is empty, replace it by the last selected item
          if (name.length() == 0) {
            setItem(nullableComboBox ? null : categoryComboBox.getSelectedItem());
          }
          FurnitureCategory category = new FurnitureCategory(name);
          // Search an existing category
          int categoryIndex = Collections.binarySearch(categories, category);
          if (categoryIndex >= 0) {
            return categories.get(categoryIndex);
          }
          // If no existing category was found, return a new one         
          return category;
        }
     
        public void setItem(Object value) {
          if (value != null) {
            FurnitureCategory category = (FurnitureCategory)value;
            defaultEditor.setItem(category.getName());
          }
        }

        public void addActionListener(ActionListener l) {
          defaultEditor.addActionListener(l);
        }

        public Component getEditorComponent() {
          return defaultEditor.getEditorComponent();
        }

        public void removeActionListener(ActionListener l) {
          defaultEditor.removeActionListener(l);
        }

        public void selectAll() {
          defaultEditor.selectAll();
        }
      });
    this.categoryComboBox.setRenderer(new DefaultListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index,
                                                      boolean isSelected, boolean cellHasFocus) {
          if (value == null) {
            value = " ";
          } else {
           value = ((FurnitureCategory)value).getName();
          }
          return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        }
      });
    this.categoryComboBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent ev) {
          controller.setCategory((FurnitureCategory)ev.getItem());
        }
      });
    controller.addPropertyChangeListener(FurnitureController.Property.CATEGORY,
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent ev) {
            // If category changes update category combo box
            FurnitureCategory category = controller.getCategory();
            if (category != null) {
              categoryComboBox.setSelectedItem(category);
            }
          }
        });
View Full Code Here


          }
        }
      }
      setDescription(description);
     
      FurnitureCategory category = firstPiece.getCategory();
      String categoryName = (String)this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
          firstPiece, furnitureLanguage, FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY, category.getName());
      if (category != null) {
        for (int i = 1; i < this.modifiedFurniture.size(); i++) {
          CatalogPieceOfFurniture piece = this.modifiedFurniture.get(i);
          if (!categoryName.equals(this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
              piece, furnitureLanguage, FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY, piece.getCategory().getName()))) {
            category = null;
            break;
          }
        }
      }
      setCategory(new FurnitureCategory(categoryName));

      Float width = firstPiece.getWidth();
      for (int i = 1; i < this.modifiedFurniture.size(); i++) {
        if (width.floatValue() != this.modifiedFurniture.get(i).getWidth()) {
          width = null;
View Full Code Here

  /**
   * Sets the edited category.
   */
  public void setCategory(FurnitureCategory category) {
    if (category != this.category) {
      FurnitureCategory oldCategory = this.category;
      this.category = category;
      this.propertyChangeSupport.firePropertyChange(Property.CATEGORY.name(), oldCategory, category);
    }
  }
View Full Code Here

    String furnitureLanguage = this.furnitureLanguageController.getFurnitureLangauge();
    Set<FurnitureCategory> categories = new TreeSet<FurnitureCategory>(getDefaultCategories(furnitureLanguage));
    for (CatalogPieceOfFurniture piece : this.furnitureLibrary.getFurniture()) {
      String categoryName = (String)this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
          piece, furnitureLanguage, FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY, piece.getCategory().getName());
      categories.add(new FurnitureCategory(categoryName));
    }
    return new ArrayList<FurnitureCategory>(categories);
  }
View Full Code Here

        "com.eteks.furniturelibraryeditor.viewcontroller.DefaultCategories", locale);
    List<FurnitureCategory> categories = new ArrayList<FurnitureCategory>();
    int i = 1;
    try {
      while (true) {
        categories.add(new FurnitureCategory(resource.getString("defaultFurnitureCategory#" + i++)));
      }
    } catch (MissingResourceException ex) {
      // Stop searching for next category
    }
    return categories;
View Full Code Here

  public void modifyFurniture() {
    if (!this.modifiedFurniture.isEmpty()) {
      String id = getId();
      String name = getName();
      String description = getDescription();
      FurnitureCategory category = getCategory();
      Content model = getModel();
      Content icon = getIcon();
      Float width = getWidth();
      Float depth = getDepth();
      Float height = getHeight();
      Float elevation = getElevation();
      Boolean movable = getMovable();
      Boolean resizable = getResizable();
      Boolean deformable = getDeformable();
      Boolean doorOrWindow = getDoorOrWindow();
      float [][] modelRotation = getModelRotation();
      String creator = getCreator();
      BigDecimal price = getPrice();
      BigDecimal valueAddedTaxPercentage = getValueAddedTaxPercentage();
      boolean defaultFurnitureLanguage = FurnitureLibrary.DEFAULT_LANGUAGE.equals(this.furnitureLanguageController.getFurnitureLangauge());
     
      // Apply modification
      int piecesCount = this.modifiedFurniture.size();
      for (CatalogPieceOfFurniture piece : this.modifiedFurniture) {
        int index = this.furnitureLibrary.getPieceOfFurnitureIndex(piece);
        // Retrieve localized data
        Map<String, Object> localizedNames = new HashMap<String, Object>();
        Map<String, Object> localizedDescriptions = new HashMap<String, Object>();
        Map<String, Object> localizedCategories = new HashMap<String, Object>();
        for (String language : this.furnitureLibrary.getSupportedLanguages()) {
          Object pieceName = this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
              piece, language, FurnitureLibrary.FURNITURE_NAME_PROPERTY);
          if (pieceName != null) {
            localizedNames.put(language, pieceName);
          }
          Object pieceDescription = this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
              piece, language, FurnitureLibrary.FURNITURE_DESCRIPTION_PROPERTY);
          if (pieceDescription != null) {
            localizedDescriptions.put(language, pieceDescription);
          }
          Object categoryName = this.furnitureLibrary.getPieceOfFurnitureLocalizedData(
              piece, language, FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY);
          if (categoryName != null) {
            localizedCategories.put(language, categoryName);
          }
        }
        this.furnitureLibrary.deletePieceOfFurniture(piece);
       
        String pieceId = id != null || piecesCount == 1 ? id : piece.getId();
        String pieceName = name != null && defaultFurnitureLanguage ? name : piece.getName();
        String pieceDescription = description != null && defaultFurnitureLanguage ? description : piece.getDescription();
        FurnitureCategory pieceCategory = category != null && defaultFurnitureLanguage ? category : piece.getCategory();
        Content pieceModel = model != null ? model : piece.getModel();
        Content pieceIcon = icon != null ? icon : piece.getIcon();
        float pieceWidth = width != null ? width : piece.getWidth();
        float pieceDepth = depth != null ? depth : piece.getDepth();
        float pieceHeight = height != null ? height : piece.getHeight();
View Full Code Here

            categories = furnitureController.getDefaultCategories(language);
            translatedCategories = furnitureController.getDefaultCategories(translationLanguage);
          }
          String categoryName = (String)this.furnitureLibrary.getPieceOfFurnitureLocalizedData(piece, language,
              FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY, piece.getCategory().getName());
          int i = categories.indexOf(new FurnitureCategory(categoryName));
          if (i >= 0) {
            furnitureController.setCategory(translatedCategories.get(i));
            // Retrieve the new modified piece that replaces the old one to add it to selection
            this.furnitureLibrary.addListener(new CollectionListener<CatalogPieceOfFurniture>() {
                public void collectionChanged(CollectionEvent<CatalogPieceOfFurniture> ev) {
View Full Code Here

    }
    modelName = Character.toUpperCase(modelName.charAt(0)) + modelName.substring(1);
    CatalogPieceOfFurniture piece = new CatalogPieceOfFurniture(key,
        modelName, null, iconContent, null, modelContent,
        size.x, size.z, size.y, 0f, true, null, this.preferences.getDefaultCreator(), true, null, null);
    FurnitureCategory defaultCategory = new FurnitureCategory(
        this.preferences.getLocalizedString(ImportFurnitureTaskPanel.class, "defaultCategory"));
    new FurnitureCatalog() { }.add(defaultCategory , piece);
    return piece;
  }
View Full Code Here

              furnitureLibrary.setProvider(getOptionalString(resource, PROVIDER));
            }
            CatalogPieceOfFurniture piece = super.readPieceOfFurniture(resource, index, furnitureCatalogUrl, furnitureResourcesUrlBase);
            if (piece != null) {
              // Set furniture category through dummy catalog
              FurnitureCategory category = super.readFurnitureCategory(resource, index);
              new FurnitureCatalog() { }.add(category, piece);
              furniture.add(piece);
            }
            return piece;
          }
         
          private String getOptionalString(ResourceBundle resource, String propertyKey) {
            try {
              return resource.getString(propertyKey);
            } catch (MissingResourceException ex) {
              return null;
            }
          }
        };
     
      // Search which locales are supported
      List<ZipEntry> zipEntries = getZipEntries(furnitureLibraryUrl);
      Set<Locale>    supportedLocales = new HashSet<Locale>();
      for (ZipEntry zipEntry : zipEntries) {
        String entryName = zipEntry.getName();
        if (entryName.startsWith(DefaultFurnitureCatalog.PLUGIN_FURNITURE_CATALOG_FAMILY)
            && entryName.endsWith(".properties")) {
          supportedLocales.add(getLocale(entryName));
        }
      }

      // Replace furniture by the one read
      for (CatalogPieceOfFurniture piece : furnitureLibrary.getFurniture()) {
        furnitureLibrary.deletePieceOfFurniture(piece);
      }
      for (CatalogPieceOfFurniture piece : furniture) {
        furnitureLibrary.addPieceOfFurniture(piece);
      }

      // Get furniture name and category name in each supported locale
      for (Locale locale : supportedLocales) {
        if (!FurnitureLibrary.DEFAULT_LANGUAGE.equals(locale.toString())) {         
          Locale.setDefault(locale);
          final String language = locale.toString();
          new DefaultFurnitureCatalog(new URL [] {furnitureLibraryUrl}, furnitureResourcesUrlBase) {
              @Override
              protected CatalogPieceOfFurniture readPieceOfFurniture(ResourceBundle resource,
                                                                     int index,
                                                                     URL furnitureCatalogUrl,
                                                                     URL furnitureResourcesUrlBase) {
                CatalogPieceOfFurniture piece = super.readPieceOfFurniture(resource, index, furnitureCatalogUrl, furnitureResourcesUrlBase);
                if (piece != null) {
                  FurnitureCategory category = super.readFurnitureCategory(resource, index);
                  CatalogPieceOfFurniture furnitureLibraryPiece = furniture.get(index - 1);
                  furnitureLibrary.setPieceOfFurnitureLocalizedData(furnitureLibraryPiece, language,
                      FurnitureLibrary.FURNITURE_NAME_PROPERTY, piece.getName());
                  furnitureLibrary.setPieceOfFurnitureLocalizedData(furnitureLibraryPiece, language,
                      FurnitureLibrary.FURNITURE_DESCRIPTION_PROPERTY, piece.getDescription());
                  furnitureLibrary.setPieceOfFurnitureLocalizedData(furnitureLibraryPiece, language,
                      FurnitureLibrary.FURNITURE_CATEGORY_PROPERTY, category.getName());
                }
                return piece;
              }
            };
        }
View Full Code Here

  /**
   * Tests zoom and alignment tools.
   */
  public void testZoomAndAligment() {
    // Add the first two pieces of catalog first category to home
    FurnitureCategory firstCategory = this.preferences.getFurnitureCatalog().getCategories().get(0);
    HomePieceOfFurniture firstPiece = new HomePieceOfFurniture(firstCategory.getFurniture().get(0));
    this.home.addPieceOfFurniture(firstPiece);
    HomePieceOfFurniture secondPiece = new HomePieceOfFurniture(firstCategory.getFurniture().get(1));
    secondPiece.setAngle(15);
    this.home.addPieceOfFurniture(secondPiece);
    // Add a wall to home
    this.home.addWall(new Wall(0, 0, 100, 0, 7));
   
View Full Code Here

TOP

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

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.