bibliothek.notes.util.ResourceSet Maven / Gradle / Ivy
package bibliothek.notes.util;
import java.awt.Image;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Scanner;
import javax.imageio.ImageIO;
import javax.swing.Icon;
import javax.swing.ImageIcon;
/**
* A set of properties used in the application "Notes".
* @author Benjamin Sigg
*/
public class ResourceSet {
/** The Icons which might be used as images for {@link bibliothek.notes.model.Note}s */
public static final List NOTE_ICONS;
/** The Icons which are used in the application itself */
public static final Map APPLICATION_ICONS;
static{
NOTE_ICONS = readNoteIcons();
APPLICATION_ICONS = readApplicationIcons();
}
/**
* Reads the set of icons which might be used as images for Notes.
* @return the set of icons
*/
private static List readNoteIcons(){
List icons = new ArrayList();
try{
Scanner list = new Scanner( openStream( "/data/bibliothek/notes/icons/choices/list.txt" ));
while( list.hasNext() ){
InputStream in = openStream( "/data/bibliothek/notes/icons/choices/" + list.next() );
icons.add( new ImageIcon( ImageIO.read( in )));
in.close();
}
list.close();
}
catch( IOException ex ){
ex.printStackTrace();
}
return Collections.unmodifiableList( icons );
}
/**
* Reads the set of icons which are used in the application.
* @return the set of icons
*/
private static Map readApplicationIcons(){
Map icons = new HashMap();
try{
Properties properties = new Properties();
InputStream in = openStream( "/data/bibliothek/notes/icons/icons.ini" );
properties.load( in );
in.close();
for( Map.Entry