20 package net.sf.gridarta.model.io;
22 import java.io.BufferedReader;
24 import java.io.FileInputStream;
25 import java.io.IOException;
26 import java.io.InputStreamReader;
27 import java.io.Reader;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
69 try (FileInputStream fileInputStream =
new FileInputStream(animFile)) {
70 try (Reader inputStreamReader =
new InputStreamReader(fileInputStream,
IOUtils.
MAP_ENCODING)) {
71 loadAnimations(animationObjects, errorViewCollector, inputStreamReader, startKey, ignoreOtherText, path, null);
98 if (path == null && animations == null) {
99 throw new IllegalArgumentException();
101 if (path != null && animations != null) {
102 throw new IllegalArgumentException();
104 try (BufferedReader in =
new BufferedReader(reader)) {
107 final String line2 = in.readLine();
111 final String line = line2.trim();
112 if (line.startsWith(
"#") || line.isEmpty()) {
114 }
else if (line.startsWith(startKey)) {
115 lineNumber +=
processAnimation(line.substring(startKey.length()), lineNumber, in, startKey, animationObjects, errorViewCollector, path, animations);
116 }
else if (line.equals(
"mina") || !ignoreOtherText) {
117 throw new AnimationParseException(startKey +
"...", line2, lineNumber);
143 private static int processAnimation(@NotNull
final String animName,
final int startLineNumber, @NotNull
final BufferedReader in, @NotNull
final String startKey, @NotNull
final AnimationObjects animationObjects, @NotNull
final ErrorViewCollector errorViewCollector, @Nullable
final String path, @Nullable
final Map<String, String> animations)
throws AnimationParseException, IOException {
144 int lineNumber = startLineNumber;
145 final StringBuilder animText =
new StringBuilder();
148 final String line3 = in.readLine();
150 throw new AnimationParseException(
"mina",
"<end of file>", lineNumber);
152 final String line4 = line3.trim();
153 if (line4.startsWith(
"#") || line4.isEmpty()) {
155 }
else if (line4.startsWith(startKey)) {
156 throw new AnimationParseException(
"mina", line4, lineNumber);
157 }
else if (line4.equals(
"mina")) {
158 processAnimationLine(animationObjects, errorViewCollector, path, animations, animName, animText.toString());
161 animText.append(line4).append(
'\n');
164 return lineNumber - startLineNumber;
179 private static void processAnimationLine(@NotNull
final AnimationObjects animationObjects, @NotNull
final ErrorViewCollector errorViewCollector, @Nullable
final String path, @Nullable
final Map<String, String> animations, @NotNull
final String animName, @NotNull
final String animText) {
180 if (path == null && animations == null) {
181 throw new IllegalArgumentException();
184 final String animPath;
188 final String tmp = animations.get(animName);
191 animPath =
"/" + animName;
197 animationObjects.addAnimationObject(animName, animText, animPath);
This exception is thrown when parsing an animation definition file (.
Convenience class for adding messages to a ErrorView instance using a fixed category name...
Utility class for reading AnimationObjects from files.
static final String MAP_ENCODING
Encoding to use for maps and other data.
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
static void loadAnimations(@NotNull final AnimationObjects animationObjects, @NotNull final ErrorViewCollector errorViewCollector, final Reader reader, @NotNull final String startKey, final boolean ignoreOtherText, @Nullable final String path, @Nullable final Map< String, String > animations)
Loads any number of animations from a reader.
Exception thrown to indicate that an animation object is not acceptable.
Defines possible error categories for ErrorView instances.
static void loadAnimations(@NotNull final AnimationObjects animationObjects, @NotNull final ErrorViewCollector errorViewCollector, @NotNull final String path, @NotNull final File animFile, @NotNull final String startKey, final boolean ignoreOtherText)
Loads animations from a file.
Base package of all Gridarta classes.
Utility-class for Gridarta's I/O.
AnimationObjects is a container for AnimationObjects.
static void processAnimationLine(@NotNull final AnimationObjects animationObjects, @NotNull final ErrorViewCollector errorViewCollector, @Nullable final String path, @Nullable final Map< String, String > animations, @NotNull final String animName, @NotNull final String animText)
Processes a complete anim..mina block.
String getPath()
Get the path of this AbstractNamedObject.
NamedObject getAnimationObject()
Returns the illegal animation object.
static int processAnimation(@NotNull final String animName, final int startLineNumber, @NotNull final BufferedReader in, @NotNull final String startKey, @NotNull final AnimationObjects animationObjects, @NotNull final ErrorViewCollector errorViewCollector, @Nullable final String path, @Nullable final Map< String, String > animations)
Processes an anim..mina block.
Exception that's thrown in case an animation name was not unique.
AnimationObjectsReader()
Private constructor to prevent instantiation.