Ver código fonte

switch unitgraph fix and delete points

Kevin Trometer 8 anos atrás
pai
commit
516a4cc940
1 arquivos alterados com 21 adições e 17 exclusões
  1. 21 17
      src/ui/view/UnitGraph.java

+ 21 - 17
src/ui/view/UnitGraph.java

@@ -314,7 +314,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
 				pointList.remove(tempP);
 			}
-			
+
 			repaint();
 		}
 	}
@@ -352,17 +352,14 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && x != 0 && x != width) {
 				for (int i = 0; i < pointList.size() && !added; i++) {
 					if (x < pointList.get(i).getX() - dist) {
-						// Punkt hinzufügen, je nachdem ob es oberhalb oder
-						// unterhalb der hälfte ist
-						if (y < height / 2 && (pointList.get(i - 1).getY() == height - 1
-								&& pointList.get(i).getY() == height - 1)) {
+						// Punkte hinzufügen, je nachdem ob true oder false
+						if (pointList.get(i - 1).getY() != 0 && pointList.get(i).getY() != 0) {
 							pointList.add(i, new Point((int) (x + dist), (int) height - 1));
 							pointList.add(i, new Point((int) (x + dist), 0));
 							pointList.add(i, new Point((int) (x - dist), 0));
 							pointList.add(i, new Point((int) (x - dist), (int) height - 1));
 							added = true;
-						} else if (y >= height / 2 && (pointList.get(i - 1).getY() != height - 1
-								&& pointList.get(i).getY() != height - 1)) {
+						} else if (pointList.get(i - 1).getY() == 0 && pointList.get(i).getY() == 0) {
 							pointList.add(i, new Point((int) (x + dist), 0));
 							pointList.add(i, new Point((int) (x + dist), (int) height - 1));
 							pointList.add(i, new Point((int) (x - dist), (int) height - 1));
@@ -376,15 +373,20 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			// Delete a Point
 			if (deletePoint && tempP.getX() != 0
 					&& (tempP.getX() != this.getWidth() / scaleX || tempP != pointList.getLast())) {
-				System.out.println("y: " + tempP.getY());
-				// pointList.remove(tempP);
+				int i = pointList.indexOf(tempP);
+				if (tempP.getY() == 0) {
+					pointList.remove(i);
+					pointList.remove(i-1);
+					pointList.remove(i-2);
+					pointList.remove(i-3);
+				}
+				if (tempP.getY() == height-1) {
+					pointList.remove(i+2);
+					pointList.remove(i+1);
+					pointList.remove(i);
+					pointList.remove(i-1);
+				}
 			}
-			// Delete This for
-			/*
-			 * for (int i = 0; i < pointList.size(); i++) {
-			 * System.out.println(pointList.get(i).getX() + ", " +
-			 * pointList.get(i).getY()); }
-			 */
 
 			repaint();
 		}
@@ -397,8 +399,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			pointDrag = false;
 			tempP = null;
 		}
-		// array fillen
-		fillArrayofValue();
+		if (isElement) {
+			// array fillen
+			fillArrayofValue();
+		}
 	}
 
 	public void componentResized(ComponentEvent e) {