浏览代码

some fixes for boundaries and using median for scarediv2

Teh-Hai Julian Zheng 7 年之前
父节点
当前提交
c29a2a7fba
共有 3 个文件被更改,包括 30 次插入22 次删除
  1. 9 7
      src/ui/controller/ClipboardController.java
  2. 8 6
      src/ui/controller/NodeController.java
  3. 13 9
      src/ui/model/Model.java

+ 9 - 7
src/ui/controller/ClipboardController.java

@@ -446,21 +446,23 @@ public class ClipboardController {
 		eleIDMap.put(id, temp.getId());
 
 	}
-	
+
 	private void updatePosition(AbstractCpsObject temp, CpsUpperNode upperNode) {
 		// TODO Auto-generated method stub
 		int x = temp.getPosition().x - point.x;
 		int y = temp.getPosition().y - point.y;
 
 		if (y < 0)
-			y = 0;
-		if (upperNode != null)
-			if (x < upperNode.getLeftBorder())
-				x = upperNode.getLeftBorder();
+			y = 0 + model.getScaleDiv2() + 1;
+		if (upperNode != null) {
+			if (x < upperNode.getLeftBorder() + model.getScaleDiv2() + 1)
+				x = upperNode.getLeftBorder() + model.getScaleDiv2() + 1;
+		} else if (x < 0)
+			x = 0 + model.getScaleDiv2() + 1;
 		if (x > model.getCanvasX())
-			x = model.getCanvasX();
+			x = model.getCanvasX() - model.getScaleDiv2() - 1;
 		if (y > model.getCanvasX())
-			y = model.getCanvasY();
+			y = model.getCanvasY() - model.getScaleDiv2() - 1;
 
 		temp.setPosition(new Position(x, y));
 

+ 8 - 6
src/ui/controller/NodeController.java

@@ -568,14 +568,16 @@ public class NodeController {
 		int y = temp.getPosition().y - point.y;
 
 		if (y < 0)
-			y = 0;
-		if (upperNode != null)
-			if (x < upperNode.getLeftBorder())
-				x = upperNode.getLeftBorder();
+			y = 0 + model.getScaleDiv2() + 1;
+		if (upperNode != null) {
+			if (x < upperNode.getLeftBorder() + model.getScaleDiv2() + 1)
+				x = upperNode.getLeftBorder() + model.getScaleDiv2() + 1;
+		} else if (x < 0)
+			x = 0 + model.getScaleDiv2() + 1;
 		if (x > model.getCanvasX())
-			x = model.getCanvasX();
+			x = model.getCanvasX() - model.getScaleDiv2() - 1;
 		if (y > model.getCanvasX())
-			y = model.getCanvasY();
+			y = model.getCanvasY() - model.getScaleDiv2() - 1;
 
 		temp.setPosition(new Position(x, y));
 

+ 13 - 9
src/ui/model/Model.java

@@ -132,9 +132,9 @@ public class Model {
 	// Statistic Graph Data
 	private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<String, StatisticGraphPanel>();
 	private ArrayList<JsonObject> statisticData = new ArrayList<>();
-	
+
 	private Gson gson;
-	
+
 	private StatisticPanel statPanel;
 
 	/**
@@ -396,7 +396,10 @@ public class Model {
 	 */
 	public void setScale(int scale) {
 		sCALE = scale;
-		sCALEdIV2 = sCALE / 2;
+		if ((sCALE & 1) == 0)
+			sCALEdIV2 = sCALE / 2;
+		else
+			sCALEdIV2 = (sCALE + 1) / 2;
 	}
 
 	/**
@@ -953,7 +956,7 @@ public class Model {
 		this.showConsoleLog = showConsoleLog;
 
 	}
-	
+
 	/**
 	 * Initialize the Gson with wanted parameters
 	 */
@@ -980,17 +983,18 @@ public class Model {
 	}
 
 	/**
-	 * @param gson the gson to set
+	 * @param gson
+	 *            the gson to set
 	 */
 	public void setGson(Gson gson) {
 		this.gson = gson;
 	}
-	
-	public void setStatPanel(StatisticPanel sP){
+
+	public void setStatPanel(StatisticPanel sP) {
 		statPanel = sP;
 	}
-	
-	public StatisticPanel getStatPanel(){
+
+	public StatisticPanel getStatPanel() {
 		return statPanel;
 	}
 }