Пример #1
0
  /**
   * getting the image representing a resource given the id of a resource
   *
   * @param svgHandle a svg handle
   * @param resourceId the id of the resource from which the image has been created
   * @param useSmallImage whether the returned image should be small or large
   * @return the image representing the resource
   */
  public Image getImage(SVGHandle svgHandle, String resourceId, boolean useSmallImage) {

    Image image = null;

    if (svgHandle != null && resourceId != null && !resourceId.equals("")) {

      Map<String, ImageRepresentation> idToImageMap = null;

      if (handleToIdToImages.containsKey(svgHandle)) {

        idToImageMap = handleToIdToImages.get(svgHandle);

        if (idToImageMap.containsKey(resourceId)) {

          ImageRepresentation imageRepresentation = idToImageMap.get(resourceId);

          if (imageRepresentation != null) {

            if (useSmallImage) {

              image = imageRepresentation.getSmallImage();

            } else {

              image = imageRepresentation.getLargeImage();
            }
          }
        }
      }
    }

    return image;
  }
Пример #2
0
  /**
   * invalidates the representation of a resource
   *
   * @param svgHandle a svg handle
   * @param resourceId the id of a resource node
   */
  public void invalidateResourceRepresentation(SVGHandle svgHandle, String resourceId) {

    if (resourceId != null && svgHandle != null) {

      Map<String, ImageRepresentation> idToImageMap = null;

      if (handleToIdToImages.containsKey(svgHandle)) {

        idToImageMap = handleToIdToImages.get(svgHandle);

        if (idToImageMap != null) {

          // removes the id in the map
          synchronized (this) {
            idToImageMap.remove(resourceId);
          }
        }
      }
    }
  }
Пример #3
0
  /**
   * getting the image representing a resource given the id of a resource
   *
   * @param svgHandle a svg handle
   * @param resourceId the id of the resource from which the image has been created
   * @return the image representation object representing the resource
   */
  public ImageRepresentation getResourceImage(SVGHandle svgHandle, String resourceId) {

    ImageRepresentation imageRepresentation = null;

    if (svgHandle != null && resourceId != null && !resourceId.equals("")) {

      Map<String, ImageRepresentation> idToImageMap = null;

      if (handleToIdToImages.containsKey(svgHandle)) {

        idToImageMap = handleToIdToImages.get(svgHandle);

        if (idToImageMap.containsKey(resourceId)) {

          imageRepresentation = idToImageMap.get(resourceId);
        }
      }
    }

    return imageRepresentation;
  }
Пример #4
0
  /**
   * creates a new image
   *
   * @param svgHandle a svg handle
   * @param resourceId the id of the resource from which the image has been created
   * @param image the image representing the resource
   */
  protected void setImage(SVGHandle svgHandle, String resourceId, Image image) {

    if (svgHandle != null && resourceId != null && image != null) {

      Map<String, ImageRepresentation> idToImageMap = null;

      if (handleToIdToImages.containsKey(svgHandle)) {

        idToImageMap = handleToIdToImages.get(svgHandle);

      } else {

        idToImageMap = new HashMap<String, ImageRepresentation>();
        handleToIdToImages.put(svgHandle, idToImageMap);
      }

      synchronized (this) {
        idToImageMap.put(resourceId, new ImageRepresentation(image));
      }
    }
  }
Пример #5
0
  /**
   * checks if the map associating an id to an image is consistent
   *
   * @param svgHandle a svg handle
   */
  protected void checkResourceRepresentationsConsistency(SVGHandle svgHandle) {

    if (svgHandle != null) {

      Map<String, ImageRepresentation> idToImageMap = null;

      if (handleToIdToImages.containsKey(svgHandle)) {

        idToImageMap = handleToIdToImages.get(svgHandle);

        if (idToImageMap != null) {

          // getting the map associating the id of a resource to the
          // resource node
          LinkedList<String> resourceNames = new LinkedList<String>();
          resourceNames.add("linearGradient");
          resourceNames.add("radialGradient");
          resourceNames.add("pattern");
          resourceNames.add("marker");

          Map<String, Element> resources =
              svgHandle
                  .getSvgResourcesManager()
                  .getResourcesFromDefs(svgHandle.getCanvas().getDocument(), resourceNames);

          for (String id : new LinkedList<String>(idToImageMap.keySet())) {

            if (id != null && !id.equals("") && !resources.containsKey(id)) {

              idToImageMap.remove(id);
            }
          }
        }
      }
    }
  }