Browse Source

fix paste ouside boundary, recursive traversing or directories

Teh-Hai Julian Zheng 7 years ago
parent
commit
1ccdacb6e1

+ 5 - 1
.classpath

@@ -6,7 +6,11 @@
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
 	<classpathentry kind="lib" path="jars/CpsAlgorithm.jar"/>
-	<classpathentry kind="lib" path="jars/gson-2.8.0.jar"/>
+	<classpathentry kind="lib" path="jars/gson-2.8.0.jar">
+		<attributes>
+			<attribute name="javadoc_location" value="jar:platform:/resource/praktikum-holons/jars/gson-2.8.0-javadoc.jar!/"/>
+		</attributes>
+	</classpathentry>
 	<classpathentry kind="lib" path="jars/commons-compress-1.13/commons-compress-1.13.jar" sourcepath="jars/commons-compress-1.13/commons-compress-1.13-sources.jar">
 		<attributes>
 			<attribute name="javadoc_location" value="jar:platform:/resource/praktikum-holons/jars/commons-compress-1.13/commons-compress-1.13-javadoc.jar!/"/>

BIN
jars/gson-2.8.0-javadoc.jar


+ 15 - 4
src/ui/controller/ClipboardController.java

@@ -149,9 +149,8 @@ public class ClipboardController {
 				&& !content.isDataFlavorSupported(DataFlavor.allHtmlFlavor)) {
 
 			String str = (String) content.getTransferData(DataFlavor.stringFlavor);
-			
-			
-			if (parser.parse(str).isJsonObject()) 
+
+			if (parser.parse(str).isJsonObject())
 				json = (JsonObject) parser.parse(str);
 			else
 				throw new JsonParseException("Unknown Clipboard Information");
@@ -475,7 +474,19 @@ public class ClipboardController {
 
 	private void updatePosition(AbstractCpsObject temp) {
 		// TODO Auto-generated method stub
-		temp.setPosition(new Position(temp.getPosition().x - point.x, temp.getPosition().y - point.y));
+		int x = temp.getPosition().x - point.x;
+		int y = temp.getPosition().y - point.y;
+		if(x < 0)
+			x = 0;
+		if(x > model.getCanvasX())
+			x = model.getCanvasX();
+		if(y < 0)
+			y = 0;
+		if(y > model.getCanvasX())
+			y = model.getCanvasY();
+		
+		temp.setPosition(new Position(x, y));
+		
 	}
 
 }

+ 14 - 11
src/ui/controller/StoreController.java

@@ -132,7 +132,7 @@ public class StoreController {
 		writer.flush();
 		writer.close();
 
-		addFilesToSave(holonFile, stream);
+		addFileToSave(holonFile, stream, false);
 
 		stream.finish();
 		output.close();
@@ -258,17 +258,19 @@ 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");
+		System.out.println(images.getCanonicalPath());
 		addFilesToSave(images, stream);
 		addFilesToSave(background, stream);
-	
+
 	}
 
 	/**
@@ -397,15 +399,15 @@ public class StoreController {
 	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);
+			if (file.isDirectory())
+				addFilesToSave(file, stream);
+			else
+				addFileToSave(file, stream, true);
 		}
 
 	}
@@ -419,8 +421,9 @@ public class StoreController {
 	 * @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());
+		String entryName = (dir == true ? src.getCanonicalPath() : src.getName());
+		entryName = entryName.replace(System.getProperty("user.home") + "/HolonGUI/", "");
+		
 		ZipArchiveEntry entry = new ZipArchiveEntry(entryName);
 		stream.putArchiveEntry(entry);
 		BufferedInputStream input = new BufferedInputStream(new FileInputStream(src));