Quellcode durchsuchen

doppelte namen auf der canvas wieder erlaubt

Kevin Trometer vor 8 Jahren
Ursprung
Commit
e0a57119a8
3 geänderte Dateien mit 13 neuen und 19 gelöschten Zeilen
  1. 0 13
      src/ui/controller/CanvasController.java
  2. 0 2
      src/ui/view/GUI.java
  3. 13 4
      src/ui/view/UnitGraph.java

+ 0 - 13
src/ui/controller/CanvasController.java

@@ -25,19 +25,6 @@ public class CanvasController {
 	 *            CpsObject to be added.
 	 */
 	public void addObject(CpsObject object) {
-		// String objName = object.getObjName();
-		// object.setSav("Canvas");
-		// object.setConnections(new ArrayList<>());
-		int i = 0;
-		while (sC.searchHolonObject(object.getName(), MODEL.getObjectsOnCanvas()) != null) {
-			if (object.getObjName().contains("_"))
-				object.setObjName(object.getObjName().substring(0, object.getObjName().indexOf('_')));
-			String name = object.getObjName() + "_" + i;
-			object.setObjName(name);
-			object.setName(name);
-			i++;
-		}
-
 		MODEL.getObjectsOnCanvas().add(object);
 		notifyObjListeners();
 		// System.out.println("Added: " + objName);

+ 0 - 2
src/ui/view/GUI.java

@@ -247,8 +247,6 @@ public class GUI<E> implements CategoryListener {
 
 		splitPane_2.setRightComponent(comboBoxAlgo);
 
-		unitGraph.setBackground(Color.WHITE);
-
 		canvas.setBackground(Color.WHITE);
 		canvas.setPreferredSize(new Dimension(10000, 10000));
 		JScrollPane canvasSP = new JScrollPane(canvas);

+ 13 - 4
src/ui/view/UnitGraph.java

@@ -50,7 +50,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	private boolean pointDrag = false;
 	private boolean init = false;
-	private Point tempP = null, p1 = null, p2 = null;
+	private Point tempP = null;
 	private double x = 0, y = 0;
 	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
 
@@ -60,6 +60,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		this.model = model;
 
 		this.pointList = new LinkedList<>();
+		this.setBackground(Color.WHITE);
 
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
@@ -203,6 +204,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					}
 				}
 			}
+			//New Point
 			if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && e.getX() != 0
 					&& e.getX() != this.getWidth() / scaleX) {
 				for (int i = 0; i < pointList.size(); i++) {
@@ -218,6 +220,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					}
 				}
 			}
+			//Delete a Point
 			if (deletePoint && tempP.getX() != 0
 					&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
 				pointList.remove(tempP);
@@ -236,10 +239,11 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	}
 
 	public void componentResized(ComponentEvent e) {
+		//Wenn ein anderes Element genommen wird
 		if (init) {
 			MAXIMUM = tempElement.getEnergy();
 			init = false;
-			// for scale
+			// for scale on the first initialisation
 			if (width == -1 && height == -1) {
 				width = this.getWidth();
 				height = this.getHeight();
@@ -247,12 +251,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 			scaleX = this.getWidth() / width;
 			scaleY = this.getHeight() / height;
-
+			
+			//First time clicked on the Element
 			if (pointList.isEmpty()) {
 				pointList.addFirst(new Point(0, 0));
 				pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
 			}
 		}
+		
+		//Scale
 		scaleX = this.getWidth() / width;
 		scaleY = this.getHeight() / height;
 		repaint();
@@ -341,6 +348,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		y1 = (int) p1.getY();
 		x2 = (int) p2.getX();
 		y2 = (int) p2.getY();
+		
+		//calculate the controllpoints
 		ctrlx1 = (int) p1.getX() + ((int) p2.getX() - (int) p1.getX()) / 2;
 		ctrlx2 = (int) p2.getX() - ((int) p2.getX() - (int) p1.getX()) / 2;
 		if (y1 < y2) {
@@ -351,6 +360,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			ctrly2 = (int) p2.getY() + ((int) p1.getY() - (int) p2.getY()) / 10;
 		}
 
+		//set the curve
 		c.setCurve(x1 * scaleX, y1 * scaleY, ctrlx1 * scaleX, ctrly1 * scaleY, ctrlx2 * scaleX, ctrly2 * scaleY,
 				x2 * scaleX, y2 * scaleY);
 		return c;
@@ -376,7 +386,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				Line2D l1 = new Line2D.Double(pointList.get(i).getX(), pointList.get(i).getY(),
 						pointList.get(i + 1).getX(), pointList.get(i + 1).getY());
 				Line2D l2 = new Line2D.Double(xVal, 0, xVal, height);
-
 				return (float) getIntersectionPoint(l1, l2).getY();
 			}
 		}