Ver código fonte

graph für switch vorbereitet

Kevin Trometer 8 anos atrás
pai
commit
a572ef5bbb
1 arquivos alterados com 96 adições e 48 exclusões
  1. 96 48
      src/ui/view/UnitGraph.java

+ 96 - 48
src/ui/view/UnitGraph.java

@@ -43,6 +43,9 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private double width = -1;
 	private double height = -1;
 
+	private boolean isElement = true;
+	private boolean isSwitch = true;
+
 	private HolonElement tempElement;
 	private Model model;
 	private Control controller;
@@ -82,61 +85,79 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 		graphCurve.reset();
 
-		// Draw the Vertical Lines
-		g2.setColor(Color.BLACK);
-		for (int i = 0; i <= this.getWidth(); i += 10) {
-			g2.drawLine(i, 0, i, this.getHeight());
-		}
-
-		for (int i = 0; i <= this.getHeight(); i += 5) {
-			g2.drawLine(0, i, this.getWidth(), i);
-		}
-
-		if (arrayOfValue != null) {
-			// array fillen
-			fillArrayofValue();
+		if (isElement) {
 
-			// Draw the Lines
-			g2.setStroke(new BasicStroke(2));
+			// Draw the Vertical Lines
 			g2.setColor(Color.BLACK);
-			for (int i = 0; i < pointList.size() - 1; i++) {
-				c = buildCurve(pointList.get(i), pointList.get(i + 1));
-				graphCurve.append(c, true);
+			for (int i = 0; i <= this.getWidth(); i += 10) {
+				g2.drawLine(i, 0, i, this.getHeight());
+			}
+
+			for (int i = 0; i <= this.getHeight(); i += 5) {
+				g2.drawLine(0, i, this.getWidth(), i);
 			}
-			g2.draw(graphCurve);
 
-			// Draw the Points
+			if (arrayOfValue != null) {
+				// array fillen
+				fillArrayofValue();
+
+				// Draw the Lines
+				g2.setStroke(new BasicStroke(2));
+				g2.setColor(Color.BLACK);
+				for (int i = 0; i < pointList.size() - 1; i++) {
+					c = buildCurve(pointList.get(i), pointList.get(i + 1));
+					graphCurve.append(c, true);
+				}
+				g2.draw(graphCurve);
+
+				// Draw the Points
+				g2.setColor(Color.BLUE);
+				for (int i = 0; i < pointList.size() - 0; i++) {
+					g2.fillOval((int) (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
+							(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
+							(int) recSize.getY());
+				}
+			}
+			// Iteration Line
 			g2.setColor(Color.BLUE);
-			for (int i = 0; i < pointList.size() - 0; i++) {
-				g2.fillOval((int) (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
-						(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
-						(int) recSize.getY());
+			g2.setStroke(new BasicStroke(1));
+			g2.drawLine((model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), 0,
+					(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
+			// Iteration Value
+			if (arrayOfValue != null) {
+				g2.drawString("" + arrayOfValue[model.getCurIteration()],
+						(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
+						this.getHeight() - 10);
 			}
-		}
-		// Iteration Line
-		g2.setColor(Color.BLUE);
-		g2.setStroke(new BasicStroke(1));
-		g2.drawLine((model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), 0,
-				(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
-		// Iteration Value
-		if (arrayOfValue != null) {
-			g2.drawString("" + arrayOfValue[model.getCurIteration()],
-					(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
-					this.getHeight() - 10);
-		}
-		/*
-		 * // Actual Iteration Point Visualization g2.setColor(Color.RED); if
-		 * (arrayOfValue != null) { for (int i = 0; i < arrayOfValue.length;
-		 * i++) { g2.fillOval((int) (i * width / (model.getIterations() - 1) *
-		 * scaleX - recSize.getX() / 2), (int) (convertToCanvasY((int)
-		 * arrayOfValue[i]) * scaleY - recSize.getY() / 2), (int)
-		 * recSize.getX(), (int) recSize.getY()); } }
-		 */
+			/*
+			 * // Actual Iteration Point Visualization g2.setColor(Color.RED);
+			 * if (arrayOfValue != null) { for (int i = 0; i <
+			 * arrayOfValue.length; i++) { g2.fillOval((int) (i * width /
+			 * (model.getIterations() - 1) * scaleX - recSize.getX() / 2), (int)
+			 * (convertToCanvasY((int) arrayOfValue[i]) * scaleY -
+			 * recSize.getY() / 2), (int) recSize.getX(), (int) recSize.getY());
+			 * } }
+			 */
+		} else if (isSwitch) {
 
+		}
 	}
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
+		if (isElement) {
+			elementDragged(e);
+		} else if (isSwitch) {
+			switchDragged(e);
+		}
+	}
+
+	/**
+	 * Wenn ein Punkt bei einem HolonElement gedragged wird
+	 * 
+	 * @param e
+	 */
+	public void elementDragged(MouseEvent e) {
 		if (pointDrag && tempP != null) {
 			// Out of Bounds verhindern
 			int i = pointList.indexOf(tempP);
@@ -156,31 +177,49 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			tempP.setLocation(x, y);
 			repaint();
 		}
+	}
 
+	/**
+	 * Wenn ein Punkt bei einem CpsSwitch gedragged wird
+	 * 
+	 * @param e
+	 */
+	public void switchDragged(MouseEvent e) {
+		// TODO Switch dragged zeugs kommt hier hin
 	}
 
 	@Override
 	public void mouseMoved(MouseEvent e) {
-		// TODO Auto-generated method stub
 	}
 
 	@Override
 	public void mouseClicked(MouseEvent e) {
-		// TODO Auto-generated method stub
 	}
 
 	@Override
 	public void mouseEntered(MouseEvent e) {
-		// TODO Auto-generated method stub
 	}
 
 	@Override
 	public void mouseExited(MouseEvent e) {
-		// TODO Auto-generated method stub
 	}
 
 	@Override
 	public void mousePressed(MouseEvent e) {
+		if (isElement) {
+			elementPressed(e);
+		} else if (isSwitch) {
+			switchPressed(e);
+		}
+
+	}
+
+	/**
+	 * Wenn ein Punkt von einem Element gedrück wird
+	 * 
+	 * @param e
+	 */
+	public void elementPressed(MouseEvent e) {
 		boolean added = false;
 		boolean deletePoint = false;
 
@@ -228,6 +267,15 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		}
 	}
 
+	/**
+	 * Wenn ein Punkt von einem Switch gedrück wird
+	 * 
+	 * @param e
+	 */
+	public void switchPressed(MouseEvent e) {
+		//TODO Siwtch pressed zeugs hier hin 
+	}
+
 	@Override
 	public void mouseReleased(MouseEvent e) {
 		if (pointDrag) {