예제 #1
0
public class Images {
  private static final Image[] images = new Image[ImageType.values().length];

  public static void loadImageResources() throws IOException {
    final ClassLoader cl = Images.class.getClassLoader();
    for (ImageType imageType : ImageType.values()) {
      images[imageType.ordinal()] = readFromImageDir(imageType.getFileName());
    }
  }

  public static Image get(ImageType imageType) {
    assertNotNull(imageType, "iamgeType");
    final Image image = images[imageType.ordinal()];
    assertNotNull(image, imageType.toString());

    return image;
  }

  private static void assertNotNull(Object o, String msg) {
    if (o == null) {
      throw new AssertionError("object was null: " + msg);
    }
  }

  private static Image readFromImageDir(String fileName) {
    final String relativePath = "image/" + fileName;
    try {
      InputStream imageStream = ResourceFinder.getResourceStream(relativePath);
      final Image img = ImageIO.read(imageStream);
      return img;
    } catch (Exception e) {
      throw new IllegalStateException("couldn't find image: " + relativePath);
    }
  }
}
예제 #2
0
 private Map<Album, Map<ImageType, Resource>> collectAlbumTargets(
     Library library, final ResourceLocator resourceLocator, Collection<Album> changedAlbums) {
   Map<Album, Map<ImageType, Resource>> result = new HashMap<>();
   for (Album album : library.getAlbums()) {
     Resource artworkAssetResource = album.artworkAssetResource();
     if (artworkAssetResource != null) {
       Map<ImageType, Resource> targets = new HashMap<ImageType, Resource>();
       for (ImageType type : ImageType.values()) {
         String imagePath = resourceLocator.getAlbumImagePath(album, type);
         if (imagePath != null) {
           Resource resource = resourceLocator.getResource(imagePath);
           try {
             if (changedAlbums.contains(album) || !resource.exists()) {
               resource.getParent().mkdirs();
               targets.put(type, resource);
             }
           } catch (IOException e) {
             LOGGER.warning("Could not write image file: " + resource.getPath().toAbsolutePath());
           }
         }
       }
       if (!targets.isEmpty()) {
         result.put(album, targets);
       }
     }
   }
   return result;
 }
예제 #3
0
 public static ImageType getTypeFromString(String val) {
   for (ImageType t : ImageType.values()) {
     if (t.getTypeId().equals(val)) {
       return t;
     }
   }
   return null;
 }
예제 #4
0
파일: Media.java 프로젝트: hhutch/jclouds
  @XmlType
  @XmlEnum(String.class)
  public static enum ImageType {
    @XmlEnumValue("iso")
    ISO("iso"),
    @XmlEnumValue("floppy")
    FLOPPY("floppy"),
    UNRECOGNIZED("unrecognized");

    public static final List<ImageType> ALL = ImmutableList.of(ISO, FLOPPY);

    protected final String stringValue;

    ImageType(String stringValue) {
      this.stringValue = stringValue;
    }

    public String value() {
      return stringValue;
    }

    protected static final Map<String, ImageType> STATUS_BY_ID =
        Maps.uniqueIndex(
            ImmutableSet.copyOf(ImageType.values()),
            new Function<ImageType, String>() {
              @Override
              public String apply(ImageType input) {
                return input.stringValue;
              }
            });

    public static ImageType fromValue(String value) {
      ImageType type = STATUS_BY_ID.get(checkNotNull(value, "stringValue"));
      return type == null ? UNRECOGNIZED : type;
    }
  }
예제 #5
0
 public static void loadImageResources() throws IOException {
   final ClassLoader cl = Images.class.getClassLoader();
   for (ImageType imageType : ImageType.values()) {
     images[imageType.ordinal()] = readFromImageDir(imageType.getFileName());
   }
 }