소스 검색

^markieren test

Kevin Trometer 7 년 전
부모
커밋
a702542e02
2개의 변경된 파일51개의 추가작업 그리고 28개의 파일을 삭제
  1. 40 20
      src/ui/view/MyCanvas.java
  2. 11 8
      src/ui/view/UnitGraph.java

+ 40 - 20
src/ui/view/MyCanvas.java

@@ -47,13 +47,14 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 	private Model model;
 	private final Control controller;
 	Graphics2D g2; // For Painting
-	private int cx;
-	private int cy;
+	private int cx, cy, sx, sy;
+
 	ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
 
 	private boolean dragging = false; // for dragging
 	private boolean drawEdge = false; // for drawing edges
 	private boolean click = false; // for double click
+	private boolean doMark = false; // for double click
 	public CpsObject tempCps = null;
 	private Rectangle selectRect = new Rectangle();
 	private CpsEdge edgeHighlight = null;
@@ -166,15 +167,14 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			if (cps.getID() == model.getSelectedObjectID() && controller.searchByID(model.getSelectedObjectID()) != null
 					&& controller.searchByID(model.getSelectedObjectID()) instanceof CpsNode) {
 				img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
-			}
-			else {
+			} else {
 				if (cps instanceof HolonSwitch) {
 					if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
 						((HolonSwitch) cps).setState(true);
 					} else {
 						((HolonSwitch) cps).setState(false);
 					}
-				} 
+				}
 				if (cps == tempCps) {
 					g2.setColor(Color.BLUE);
 					g2.fillRect((int) selectRect.getX(), (int) selectRect.getY(), (int) selectRect.getWidth(),
@@ -183,10 +183,10 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 					if (((HolonObject) cps).getSupplied()) {
 						g2.setColor(Color.GREEN);
 					} else {
-						g2.setColor(Color.RED);
+						g2.setColor(Color.YELLOW);
 					}
 					g2.fillRect(cps.getPosition().x - (controller.getScale() / 20),
-							cps.getPosition().y - (controller.getScale() / 20), 
+							cps.getPosition().y - (controller.getScale() / 20),
 							controller.getScale() + ((controller.getScale() / 20) * 2),
 							controller.getScale() + ((controller.getScale() / 20) * 2));
 				}
@@ -199,8 +199,21 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			}
 			g2.drawImage(img, cps.getPosition().x, cps.getPosition().y, controller.getScale(), controller.getScale(),
 					null);
-
 		}
+		
+		//Dragg Highlighting
+		if (doMark) {
+			if (sx<x && sy<y) {
+				g2.drawRect(sx, sy, x-sx, y-sy);
+			} else if (sx>=x) {
+				g2.drawRect(x, sy, sx-x, y-sy);
+			} else if (sy>=y){
+				g2.drawRect(sx, y, x-sx, sy-y);
+			} else {
+				g2.drawRect(x, y, 30, 30x);
+			}
+		}
+		
 	}
 
 	@Override
@@ -228,13 +241,14 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
 				tempCps = cps;
 				// If drawing an Edge (CTRL down)
-				if (e.isControlDown()) {
-					drawEdge = true;
-					drawEdge = true;
-				}
 				if (tempCps.getClass() == HolonObject.class) {
 					HolonObject tempObj = ((HolonObject) tempCps);
 					dataSelected = tempObj.getElements();
+					dragging = true;
+				}
+				if (e.isControlDown()) {
+					drawEdge = true;
+					dragging = false;
 				}
 			}
 		}
@@ -243,6 +257,12 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			edgeHighlight = mousePositionOnEdge(x, y);
 			controller.setSelecteEdge(edgeHighlight);
 		}
+
+		if (edgeHighlight == null) {
+			sx = e.getX();
+			sy = e.getY();
+			doMark = true;
+		}
 		// Object Selection Highlighting (selectRect)
 		objectSelectionHighlighting();
 
@@ -274,17 +294,16 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			popmenu.show(e.getComponent(), e.getX(), e.getY());
 		}
 
+		doMark = false;
 		repaint();
 	}
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
 		// If Edge is drawn
-		if (drawEdge) {
-			x = e.getX();
-			y = e.getY();
-			repaint();
-		} else {
+		x = e.getX();
+		y = e.getY();
+		if (dragging) {
 			try {
 				// Au�erhalb des Randes gedragged?
 				x = e.getX() - controller.getScaleDiv2();
@@ -309,6 +328,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 
 			}
 		}
+		repaint();
 	}
 
 	@Override
@@ -416,11 +436,11 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 				k = p.getB();
 
 				e = new CpsEdge(n, tempCps);
-				
+
 				e1 = new CpsEdge(n, r);
-				
+
 				e2 = new CpsEdge(n, k);
-				
+
 				p.getA().getConnections().remove(p);
 				p.getB().getConnections().remove(p);
 

+ 11 - 8
src/ui/view/UnitGraph.java

@@ -103,6 +103,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		}
 
 		if (isElement) {
+			// array fillen
+			fillArrayofValue();
 			if (arrayOfFloats != null) {
 				// Draw the Lines
 				g2.setStroke(new BasicStroke(2));
@@ -173,6 +175,9 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		g2.setStroke(new BasicStroke(1));
 		g2.drawLine((model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), 0,
 				(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
+		
+		//algorithmus
+		controller.calculateStateForTimeStep(model.getCurIteration());
 	}
 
 	@Override
@@ -402,10 +407,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			pointDrag = false;
 			tempP = null;
 		}
-		if (isElement) {
-			// array fillen
-			fillArrayofValue();
-		}
 	}
 
 	public void componentResized(ComponentEvent e) {
@@ -583,12 +584,14 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			MAXIMUM = he.getEnergy();
 			he.setGraphPoints((LinkedList<Point>) pointList.clone());
 			for (int i = 0; i < arrayOfFloats.length; i++) {
-				if (he.getEnergy() >=0 ) {
-					he.getEnergyAt()[i] = convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));	
+				if (he.getEnergy() >= 0) {
+					he.getEnergyAt()[i] = convertToValueY(
+							getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
 				} else {
-					he.getEnergyAt()[i] = -convertToValueY(getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
+					he.getEnergyAt()[i] = -convertToValueY(
+							getYValueAt_2((int) (i * width / (model.getIterations() - 1))));
 				}
-				
+
 			}
 			arrayOfFloats = he.getEnergyAt();
 		}