Пример #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
  /**
   * 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;
  }
Пример #3
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);
            }
          }
        }
      }
    }
  }