Adds JavaDoc to every method.
@@ -15,10 +15,46 @@ import java.util.List;
import java.util.Scanner;
public class FontLoader {
+ /**
+ * Loads a font from the file system.
+ *
+ * @param spriteSheetPath
+ * The path to the sprite sheet.
+ *
+ * @param characterDataPath
+ * The path to the character data.
+ *
+ * @return
+ * The font.
+ *
+ * @throws IOException
+ * If an IOException occurs while loading the font.
+ *
+ * @throws URISyntaxException
+ * If a URISyntaxException occurs while loading the font.
+ */
public static Font loadFont(final String spriteSheetPath, final String characterDataPath) throws IOException {
return loadFont(new FileInputStream(spriteSheetPath), Paths.get(characterDataPath));
}
+ /**
+ * Loads a font from the file system.
+ *
+ * @param spriteSheet
+ * The input stream to the sprite sheet.
+ *
+ * @param characterData
+ * The path to the character data.
+ *
+ * @return
+ * The font.
+ *
+ * @throws IOException
+ * If an IOException occurs while loading the font.
+ *
+ * @throws URISyntaxException
+ * If a URISyntaxException occurs while loading the font.
+ */
public static Font loadFont(final InputStream spriteSheet, final Path characterData) throws IOException {
final BufferedImage image = loadSpriteSheet(spriteSheet);
final List<String> data = loadCharacterData(characterData);
@@ -26,6 +62,24 @@ public class FontLoader {
return new Font(processFontData(image, data));
}
+ /**
+ * Loads a font from within the Jar.
+ *
+ * @param spriteSheetPath
+ * The path to the sprite sheet.
+ *
+ * @param characterDataPath
+ * The path to the character data.
+ *
+ * @return
+ * The font.
+ *
+ * @throws IOException
+ * If an IOException occurs while loading the font.
+ *
+ * @throws URISyntaxException
+ * If a URISyntaxException occurs while loading the font.
+ */
public static Font loadFontFromJar(final String spriteSheetPath, final String characterDataPath) throws IOException, URISyntaxException {
final ClassLoader classLoader = FontLoader.class.getClassLoader();
@@ -35,6 +89,18 @@ public class FontLoader {
return loadFont(spriteSheetURI.toURL().openStream(), Paths.get(characterDataURI));
}
+ /**
+ * Processes a font sprite sheet and character data into a usable HashMap of character sprites.
+ *
+ * @param spriteSheet
+ * The sprite sheet.
+ *
+ * @param characterData
+ * The character data.
+ *
+ * @return
+ * The HashMap of character sprites.
+ */
private static HashMap<Character, BufferedImage> processFontData(final BufferedImage spriteSheet, final List<String> characterData) {
final HashMap<Character, BufferedImage> hashMap = new HashMap<>(characterData.size());
@@ -56,10 +122,34 @@ public class FontLoader {
return hashMap;
}
+ /**
+ * Loads sprite sheet from an input stream.
+ *
+ * @param inputStream
+ * The input stream.
+ *
+ * @return
+ * The sprite sheet.
+ *
+ * @throws IOException
+ * If an IOException occurs while loading the sprite sheet.
+ */
private static BufferedImage loadSpriteSheet(final InputStream inputStream) throws IOException {
return ImageIO.read(inputStream);
}
+ /**
+ * Loads character data from a path.
+ *
+ * @param path
+ * The path.
+ *
+ * @return
+ * The character data.
+ *
+ * @throws IOException
+ * If an IOException occurs while loading the character data.
+ */
private static List<String> loadCharacterData(final Path path) throws IOException {
return Files.readAllLines(path);
}
