Package com.eteks.sweethome3d.model

Examples of com.eteks.sweethome3d.model.Content


        int lastSlashIndex = entryName.lastIndexOf('/');
        String entryDirectory = entryName.substring(0, lastSlashIndex + 1);
        // Write in home stream each zipped stream entry that is stored in the same directory 
        for (String zipEntryName : getZipUrlEntries(zipUrl)) {
          if (zipEntryName.startsWith(entryDirectory)) {
            Content siblingContent = new URLContent(new URL("jar:" + zipUrl + "!/"
                + URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20")));
            writeZipEntry(zipOut, entryNameOrDirectory + zipEntryName.substring(lastSlashIndex), siblingContent);
          }
        }
      } else {
View Full Code Here


      URL zipUrl = urlContent.getJAREntryURL();
      String entryDirectory = entryName.substring(0, slashIndex + 1);
      // Write in home stream each zipped stream entry that is stored in the same directory 
      for (String zipEntryName : getZipUrlEntries(zipUrl)) {
        if (zipEntryName.startsWith(entryDirectory)) {
          Content siblingContent = new URLContent(new URL("jar:" + zipUrl + "!/"
              + URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20")));
          writeZipEntry(zipOut, entryNameOrDirectory + zipEntryName.substring(slashIndex), siblingContent);
        }
      }
    } else {
View Full Code Here

      // Open zipped stream that contains urlContent
      zipIn = new ZipInputStream(urlContent.getJAREntryURL().openStream());
      // Write each zipped stream entry in home stream
      for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
        String zipEntryName = entry.getName();
        Content siblingContent = new URLContent(new URL("jar:" + urlContent.getJAREntryURL() + "!/"
            + URLEncoder.encode(zipEntryName, "UTF-8").replace("+", "%20")));
        writeZipEntry(zipOut, directory + "/" + zipEntryName, siblingContent);
      }
    } finally {
      if (zipIn != null) {
View Full Code Here

    // Cancel current model
    this.controller.setModel(null);
    // Read model in modelLoader executor
    this.modelLoader.execute(new Runnable() {
        public void run() {
          Content modelContent = null;
          try {
            modelContent = contentManager.getContent(modelName);
          } catch (RecorderException ex) {
            if (!ignoreException) {
              showModelChoiceError(modelName, preferences);
            }
            return;
          }
         
          BranchGroup model = null;
          Vector3f    modelSize = null;
          try {
            model = readModel(modelContent);
            modelSize = ModelManager.getInstance().getSize(model);
            // Copy model to a temporary OBJ content with materials and textures
            modelContent = copyToTemporaryOBJContent(model, modelName);
          } catch (IOException ex) {
            model = null;
          } catch (IllegalArgumentException ex) {
            // Model is empty
            model = null;
          }
         
          if (model == null) {
            try {
              // Copy model content to a temporary content
              modelContent = TemporaryURLContent.copyToTemporaryURLContent(modelContent);
            } catch (IOException ex2) {
              if (!ignoreException) {
                showModelChoiceError(modelName, preferences);
              }
              return;
            }
           
            // If content couldn't be loaded, try to load model as a zipped file
            ZipInputStream zipIn = null;
            try {
              URLContent urlContent = (URLContent)modelContent;
              // Open zipped stream
              zipIn = new ZipInputStream(urlContent.openStream());
              // Parse entries to see if one is readable
              for (ZipEntry entry; (entry = zipIn.getNextEntry()) != null; ) {
                try {
                  String entryName = entry.getName();
                  // Ignore directory entries and entries starting by a dot
                  if (!entryName.endsWith("/")) {
                    int slashIndex = entryName.lastIndexOf('/');
                    String entryFileName = entryName.substring(++slashIndex);
                    if (!entryFileName.startsWith(".")) {
                      URL entryUrl = new URL("jar:" + urlContent.getURL() + "!/"
                          + URLEncoder.encode(entryName, "UTF-8").replace("+", "%20").replace("%2F", "/"));
                      modelContent = new TemporaryURLContent(entryUrl);
                      model = readModel(modelContent);
                      modelSize = ModelManager.getInstance().getSize(model);
                      break;
                    }
                  }
                } catch (IOException ex3) {
                  // Ignore exception and try next entry
                  model = null;
                } catch (IllegalArgumentException ex3) {
                  // Model is empty
                  model = null;
                }
              }
            } catch (IOException ex2) {
              model = null;
            } finally {
              try {
                if (zipIn != null) {
                  zipIn.close();
                }
              } catch (IOException ex2) {
                // Ignore close exception
              }
            }
          }
         
          final BranchGroup readModel = model;
          final Vector3f    readModelSize = modelSize;
          final Content     readContent = modelContent;
          // Update components in dispatch thread
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                if (readModel != null) {
                  controller.setModel(readContent);
View Full Code Here

                                final UserPreferences preferences,
                                final boolean ignoreException) {
    // Read image in imageLoader executor
    this.imageLoader.execute(new Runnable() {
        public void run() {
          Content imageContent = null;
          try {
            // Copy image to a temporary content to keep a safe access to it until home is saved
            imageContent = TemporaryURLContent.copyToTemporaryURLContent(
                contentManager.getContent(imageName));
          } catch (RecorderException ex) {
            // Error message displayed below
          } catch (IOException ex) {
            // Error message displayed below
          }
          if (imageContent == null) {
            if (!ignoreException) {
              EventQueue.invokeLater(new Runnable() {
                  public void run() {
                    JOptionPane.showMessageDialog(SwingUtilities.getRootPane(ImportedTextureWizardStepsPanel.this),
                        preferences.getLocalizedString(
                            ImportedTextureWizardStepsPanel.class, "imageChoiceError", imageName));
                  }
                });
            }
            return;
          }

          BufferedImage image = null;
          try {
            image = readImage(preferences, imageContent);
          } catch (IOException ex) {
            // image is null
          }
         
          final BufferedImage readImage = image;
          final Content       readContent = imageContent;
          // Update components in dispatch thread
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                if (readImage != null) {
                  controller.setImage(readContent);
View Full Code Here

        // Ignore write requests
      }
    };

    Home home = new Home();
    Content imageContent = new URLContent(UserPreferencesPanelTest.class.getResource("resources/test.png"));
    home.setBackgroundImage(new BackgroundImage(imageContent, 1, 0, 1, 0, 1, 0, 0));

    SwingViewFactory viewFactory = new SwingViewFactory();
    FileContentManager contentManager = new FileContentManager(preferences);
    UndoableEditSupport undoableEditSupport = new UndoableEditSupport();
View Full Code Here

  /**
   * Sets the image content of the background image.
   */
  public void setImage(Content image) {
    if (image != this.image) {
      Content oldImage = this.image;
      this.image = image;
      this.propertyChangeSupport.firePropertyChange(Property.IMAGE.name(), oldImage, image);
    }
  }
View Full Code Here

      setTexturable(true);
      setProportional(false);
    } else {
      // Search the common properties among selected furniture
      HomePieceOfFurniture firstPiece = selectedFurniture.get(0);
      Content icon = firstPiece.getIcon();
      if (icon != null) {
        for (int i = 1; i < selectedFurniture.size(); i++) {
          if (!icon.equals(selectedFurniture.get(i).getIcon())) {
            icon = null;
            break;
          }
        }
      }
View Full Code Here

  /**
   * Sets the edited icon.
   */
  private void setIcon(Content icon) {
    if (icon != this.icon) {
      Content oldIcon = this.icon;
      this.icon = icon;
      this.propertyChangeSupport.firePropertyChange(Property.ICON.name(), oldIcon, icon);
    }
  }
View Full Code Here

  /**
   * Sets the model content of the imported piece.
   */
  public void setModel(Content model) {
    if (model != this.model) {
      Content oldModel = this.model;
      this.model = model;
      this.propertyChangeSupport.firePropertyChange(Property.MODEL.name(), oldModel, model);
    }
  }
View Full Code Here

TOP

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

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.