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;
67 try (FileInputStream fileInputStream =
new FileInputStream(animFile)) {
68 try (Reader inputStreamReader =
new InputStreamReader(fileInputStream,
IOUtils.
MAP_ENCODING)) {
69 loadAnimations(animationObjects, errorViewCollector, inputStreamReader, startKey, path,
null);
94 if (path ==
null && animations ==
null) {
95 throw new IllegalArgumentException(
"neither path nor animations is set");
97 if (path !=
null && animations !=
null) {
98 throw new IllegalArgumentException(
"both path and animations are set");
100 try (BufferedReader in =
new BufferedReader(reader)) {
103 final String line2 = in.readLine();
107 final String line = line2.trim();
108 if (line.startsWith(
"#") || line.isEmpty()) {
110 }
else if (line.startsWith(startKey)) {
111 lineNumber +=
processAnimation(line.substring(startKey.length()), lineNumber, in, startKey, animationObjects, errorViewCollector, path, animations);
113 final int lineNumbers =
parseLine(line, lineNumber, in, errorViewCollector);
114 if (lineNumbers >= 0) {
115 lineNumber += lineNumbers;
158 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 {
159 int lineNumber = startLineNumber;
160 final StringBuilder animText =
new StringBuilder();
163 final String line3 = in.readLine();
167 final String line4 = line3.trim();
168 if (line4.startsWith(
"#") || line4.isEmpty()) {
170 }
else if (line4.startsWith(startKey)) {
172 }
else if (line4.equals(
"mina")) {
173 processAnimationLine(animationObjects, errorViewCollector, path, animations, animName, animText.toString());
176 animText.append(line4).append(
'\n');
179 return lineNumber - startLineNumber;
194 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) {
195 if (path ==
null && animations ==
null) {
196 throw new IllegalArgumentException(
"neither path not animations is set");
199 final String animPath;
201 final String tmp = animations.get(animName);
204 animPath =
"/" + animName;
212 animationObjects.addAnimationObject(animName, animText, animPath);