|
@@ -18,8 +18,11 @@ import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.util.ArrayDeque;
|
|
import java.util.ArrayDeque;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
+import java.util.Collection;
|
|
import java.util.LinkedList;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
@@ -51,6 +54,7 @@ import classes.HolonSwitch;
|
|
import classes.IdCounter;
|
|
import classes.IdCounter;
|
|
import classes.IdCounterElem;
|
|
import classes.IdCounterElem;
|
|
import classes.Position;
|
|
import classes.Position;
|
|
|
|
+import sun.reflect.misc.FieldUtil;
|
|
import ui.model.Model;
|
|
import ui.model.Model;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -105,15 +109,16 @@ public class StoreController {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
* exception
|
|
* exception
|
|
*/
|
|
*/
|
|
- public void writeSaveFile(String path) throws IOException, ArchiveException {
|
|
|
|
|
|
+ public void writeSave(String path) throws IOException, ArchiveException {
|
|
|
|
|
|
File dst = new File(path);
|
|
File dst = new File(path);
|
|
File holonFile = File.createTempFile("tmp", ".json");
|
|
File holonFile = File.createTempFile("tmp", ".json");
|
|
|
|
+ holonFile.deleteOnExit();
|
|
dst.delete();
|
|
dst.delete();
|
|
|
|
|
|
- OutputStream out = new FileOutputStream(dst);
|
|
|
|
|
|
+ OutputStream output = new FileOutputStream(dst);
|
|
ArchiveOutputStream stream = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP,
|
|
ArchiveOutputStream stream = new ArchiveStreamFactory().createArchiveOutputStream(ArchiveStreamFactory.ZIP,
|
|
- out);
|
|
|
|
|
|
+ output);
|
|
|
|
|
|
initNumeration();
|
|
initNumeration();
|
|
JsonObject file = new JsonObject();
|
|
JsonObject file = new JsonObject();
|
|
@@ -127,10 +132,10 @@ public class StoreController {
|
|
writer.flush();
|
|
writer.flush();
|
|
writer.close();
|
|
writer.close();
|
|
|
|
|
|
- addFileToSave(holonFile, stream);
|
|
|
|
|
|
+ addFilesToSave(holonFile, stream);
|
|
|
|
|
|
stream.finish();
|
|
stream.finish();
|
|
- out.close();
|
|
|
|
|
|
+ output.close();
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@@ -142,7 +147,7 @@ public class StoreController {
|
|
* @throws IOException
|
|
* @throws IOException
|
|
* Exception
|
|
* Exception
|
|
*/
|
|
*/
|
|
- public void writeAutosaveFile(String path) throws IOException {
|
|
|
|
|
|
+ public void writeAutosave(String path) throws IOException {
|
|
|
|
|
|
initNumeration();
|
|
initNumeration();
|
|
JsonObject file = new JsonObject();
|
|
JsonObject file = new JsonObject();
|
|
@@ -251,6 +256,21 @@ public class StoreController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Save wanted Data
|
|
|
|
+ * @param stream
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ private void storeData(ArchiveOutputStream stream) throws IOException {
|
|
|
|
+ // TODO Auto-generated method stub
|
|
|
|
+
|
|
|
|
+ File images = new File(System.getProperty("user.home") + "/HolonGUI/Images");
|
|
|
|
+ File background = new File(System.getProperty("user.home") + "/HolonGUI/BackgroundImages");
|
|
|
|
+ addFilesToSave(images, stream);
|
|
|
|
+ addFilesToSave(background, stream);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Stores Category or Canvas Elements into Json
|
|
* Stores Category or Canvas Elements into Json
|
|
*
|
|
*
|
|
@@ -367,66 +387,47 @@ public class StoreController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void storeData(ArchiveOutputStream stream) throws IOException {
|
|
|
|
- // TODO Auto-generated method stub
|
|
|
|
- ArrayList<String> images = new ArrayList<>();
|
|
|
|
- Files.newDirectoryStream(Paths.get(System.getProperty("user.home") + "/HolonGUI/Images"),
|
|
|
|
- p -> p.toFile().isFile()).forEach(p -> images.add(p.toString()));
|
|
|
|
- for (String str : images) {
|
|
|
|
- File src = new File(str);
|
|
|
|
- addFileToSave(src, stream);
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Differs Between Single file or whole Directory to Store
|
|
|
|
+ *
|
|
|
|
+ * @param src
|
|
|
|
+ * @param stream
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ private void addFilesToSave(File src, ArchiveOutputStream stream) throws IOException {
|
|
|
|
+ if (!src.exists())
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ if (!src.isDirectory()) {
|
|
|
|
+ addFileToSave(src, stream, false);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ ArrayList<File> files = new ArrayList<>();
|
|
|
|
+ files.addAll(Arrays.asList(src.listFiles()));
|
|
|
|
+ for (File file : files) {
|
|
|
|
+ addFileToSave(file, stream, true);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private void imageToJson(JsonObject file) {
|
|
|
|
- // ArrayList<String> images = new ArrayList<>();
|
|
|
|
- // BufferedImage buffered = null;
|
|
|
|
- // WritableRaster raster = null;
|
|
|
|
- // DataBufferByte data = null;
|
|
|
|
- // String k = null;
|
|
|
|
- // JsonObject temp = new JsonObject();
|
|
|
|
- //
|
|
|
|
- // try {
|
|
|
|
- // Files.newDirectoryStream(Paths.get(System.getProperty("user.home") +
|
|
|
|
- // "/HolonGUI/Images"),
|
|
|
|
- // p -> p.toFile().isFile()).forEach(p -> images.add(p.toString()));
|
|
|
|
- //
|
|
|
|
- // for (String str : images) {
|
|
|
|
- // System.out.println("aaaaa");
|
|
|
|
- // k = "IMAGE" + getNumerator(NUMTYPE.IMAGE);
|
|
|
|
- // buffered = ImageIO.read(new File(str));
|
|
|
|
- // raster = buffered.getRaster();
|
|
|
|
- // data = (DataBufferByte) raster.getDataBuffer();
|
|
|
|
- //
|
|
|
|
- // temp.add("Image", new
|
|
|
|
- // JsonPrimitive(str.substring(str.indexOf("/HolonGUI/Images"),
|
|
|
|
- // str.length())));
|
|
|
|
- // for (int i = 0; i < data.getData().length; i++) {
|
|
|
|
- // temp.add("" + i, new JsonPrimitive(data.getData()[i]));
|
|
|
|
- // System.out.println(i);
|
|
|
|
- // }
|
|
|
|
- //
|
|
|
|
- // file.add(k, gson.toJsonTree(temp));
|
|
|
|
- // }
|
|
|
|
- // } catch (IOException e) {
|
|
|
|
- // // TODO Auto-generated catch block
|
|
|
|
- // e.printStackTrace();
|
|
|
|
- // }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void addFileToSave(File src, ArchiveOutputStream stream) throws IOException {
|
|
|
|
-
|
|
|
|
- String entryName = src.getName();
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Add a File into the Archive
|
|
|
|
+ *
|
|
|
|
+ * @param src
|
|
|
|
+ * @param stream
|
|
|
|
+ * @param dir
|
|
|
|
+ * @throws IOException
|
|
|
|
+ */
|
|
|
|
+ private void addFileToSave(File src, ArchiveOutputStream stream, boolean dir) throws IOException {
|
|
|
|
+ String entryName = (dir == true ? src.getParentFile().getName() + File.separator + src.getName()
|
|
|
|
+ : src.getName());
|
|
ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
|
|
ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
|
|
stream.putArchiveEntry(entry);
|
|
stream.putArchiveEntry(entry);
|
|
-
|
|
|
|
BufferedInputStream input = new BufferedInputStream(new FileInputStream(src));
|
|
BufferedInputStream input = new BufferedInputStream(new FileInputStream(src));
|
|
|
|
|
|
IOUtils.copy(input, stream);
|
|
IOUtils.copy(input, stream);
|
|
input.close();
|
|
input.close();
|
|
stream.closeArchiveEntry();
|
|
stream.closeArchiveEntry();
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|