Преглед на файлове

Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

Edgardo Palza преди 8 години
родител
ревизия
07225c64d2
променени са 4 файла, в които са добавени 89 реда и са изтрити 37 реда
  1. 7 8
      src/ui/controller/Control.java
  2. 31 0
      src/ui/controller/LoadStoreController.java
  3. 5 15
      src/ui/view/MyCanvas.java
  4. 46 14
      src/ui/view/UnitGraph.java

+ 7 - 8
src/ui/controller/Control.java

@@ -15,10 +15,6 @@ import ui.view.GUI;
 
 public class Control {
 
-	public enum command {
-		CATEGORY, OBJECT
-	}
-
 	private Model MODEL;
 
 	private ActionListener actionListener;
@@ -27,13 +23,16 @@ public class Control {
 	private final ObjectController objectController;
 	private final CanvasController canvasController;
 	private final GlobalController globalController;
+	private final LoadStoreController loadStoreController;
 
 	public Control(Model model) {
 		this.MODEL = model;
-		this.categoryController = new CategoryController(model);
-		this.objectController = new ObjectController(model);
-		this.canvasController = new CanvasController(model);
-		this.globalController = new GlobalController(model);
+		this.categoryController = new CategoryController(MODEL);
+		this.objectController = new ObjectController(MODEL);
+		this.canvasController = new CanvasController(MODEL);
+		this.globalController = new GlobalController(MODEL);
+		this.loadStoreController = new LoadStoreController(MODEL);
+		
 	}
 
 	/* Operations for Categories and Objects */

+ 31 - 0
src/ui/controller/LoadStoreController.java

@@ -0,0 +1,31 @@
+package ui.controller;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+import ui.model.Model;
+
+public class LoadStoreController {
+
+	private Model MODEL;
+
+	public LoadStoreController(Model model) {
+		this.MODEL = model;
+	}
+
+	public void readFromTextFile(File textFile) throws IOException {
+
+		String line;
+		BufferedReader reader = new BufferedReader(new FileReader("textfile"));
+		while ((line = reader.readLine()) != null) {
+			// mach hier irgendwas mit der Gelesenen Zeile
+		}
+	}
+
+	public void unZip(File zipFile) throws IOException {
+
+	}
+}

+ 5 - 15
src/ui/view/MyCanvas.java

@@ -111,11 +111,9 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 					g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
 							cps.getPosition().y + controller.getScaleDiv2(),
 							con.getPosition().x + controller.getScaleDiv2(),
-							con.getPosition().y + controller.getScaleDiv2());
-				g2.drawString("Capacity", (cps.getPosition().x + con.getPosition().x) / 2 + model.getScaleDiv2(),
-						(cps.getPosition().y + con.getPosition().y) / 2 + model.getScaleDiv2());
+							con.getPosition().y + controller.getScaleDiv2());
 				g2.drawString("100", (cps.getPosition().x + con.getPosition().x) / 2 + model.getScaleDiv2(),
-						(cps.getPosition().y + con.getPosition().y) / 2 + model.getScaleDiv2());
+						(cps.getPosition().y + con.getPosition().y) / 2 + model.getScaleDiv2());
 			}
 		}
 
@@ -178,17 +176,9 @@ 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;
-					controller.deleteElementCanvas(1, "Rehab");
-					System.out.println(((HolonObject) model.getCategories().get(0).getObjects().get(0)).getElements()
-							.get(2).getAmount());
-					/*
-					 * controller.deleteElementCanvas(1, "Rehab");
-					 * System.out.println(((HolonObject)
-					 * model.getCategories().get(0).getObjects().get(0)).
-					 * getElements() .get(2).getAmount());
-					 */
+				if (e.isControlDown()) {
+					drawEdge = true;
+					drawEdge = true;
 				}
 				if (tempCps.getClass() == HolonObject.class) {
 					HolonObject tempObj = ((HolonObject) tempCps);

+ 46 - 14
src/ui/view/UnitGraph.java

@@ -10,6 +10,8 @@ import java.awt.event.ComponentListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
+import java.awt.geom.CubicCurve2D;
+import java.awt.geom.QuadCurve2D;
 import java.util.ArrayList;
 import java.awt.Point;
 
@@ -31,18 +33,19 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private Control controller;
 	private Model model;
 	private Graphics2D g2;
+	private CubicCurve2D c = new CubicCurve2D.Double();
 	Point[] pointList = new Point[NUMBER];
 
 	private boolean pointDrag = false;
 	private int tempP;
+	private int x1, x2, y1, y2, ctrlx1, ctrly1, ctrlx2, ctrly2;
 
 	public UnitGraph(final Model model, Control control) {
-		
-		
+
 		this.controller = control;
 		this.model = model;
 		for (int i = 0; i < pointList.length; i++) {
-			pointList[i] = new Point(0,0);
+			pointList[i] = new Point(0, 0);
 		}
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
@@ -62,18 +65,46 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		g2.setRenderingHints(rh);
 		g2.setStroke(new BasicStroke(1));
 
-		for (int i = 0; i < pointList.length-1; i++) {
-			g2.drawLine((int)pointList[i].getX(), (int)pointList[i].getY(), (int)pointList[i+1].getX(), (int)pointList[i+1].getY());
+		g2.setColor(Color.LIGHT_GRAY);
+		for (int i = 0; i < pointList.length; i++) {
+			g2.drawLine((int) pointList[i].getX(), 0, (int) pointList[i].getX(), this.getHeight());
+		}
+
+		g2.setColor(Color.BLACK);
+		g2.setStroke(new BasicStroke(2));
+		for (int i = 0; i < pointList.length - 1; i++) {
+			// g2.drawLine((int)pointList[i].getX(), (int)pointList[i].getY(),
+			// (int)pointList[i+1].getX(), (int)pointList[i+1].getY());
+			
+			//Set up the Curve
+			x1 = (int) pointList[i].getX();
+			y1 = (int) pointList[i].getY();
+			x2 = (int) pointList[i + 1].getX();
+			y2 = (int) pointList[i + 1].getY();
+			ctrlx1 = (int) pointList[i].getX()+((int) pointList[i+1].getX()-(int) pointList[i].getX())/2;
+			ctrlx2 = (int) pointList[i+1].getX()-((int) pointList[i+1].getX()-(int) pointList[i].getX())/2;
+			if(y1<y2){
+				ctrly1 = (int) pointList[i].getY()+((int) pointList[i+1].getY()-(int) pointList[i].getY())/10;
+				ctrly2 = (int) pointList[i+1].getY()-((int) pointList[i+1].getY()-(int) pointList[i].getY())/10;
+			} else{
+				ctrly1 = (int) pointList[i].getY()-((int) pointList[i].getY()-(int) pointList[i+1].getY())/10;
+				ctrly2 = (int) pointList[i+1].getY()+((int) pointList[i].getY()-(int) pointList[i+1].getY())/10;
+			}
+			
+			c.setCurve(x1, y1, ctrlx1, ctrly1, ctrlx2, ctrly2, x2, y2);
+			
+			
+			//draw the curve
+			g2.draw(c);
 		}
-		g2.drawLine((int)pointList[NUMBER-1].getX(), (int)pointList[NUMBER-1].getY(), this.getWidth(), this.getHeight()/2);
 	}
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
-		if (pointDrag) {
+		if (pointDrag && e.getY() >= this.getHeight() / 3) {
 			pointList[tempP].setLocation(pointList[tempP].getX(), e.getY());
-			pointList[tempP-1].setLocation(pointList[tempP-1].getX(), pointList[tempP-1].getY()+(e.getY()-pointList[tempP-1].getY())/10);
-			pointList[tempP+1].setLocation(pointList[tempP+1].getX(), pointList[tempP-1].getY()+(e.getY()-pointList[tempP-1].getY())/10);
+		} else {
+			pointList[tempP].setLocation(pointList[tempP].getX(), this.getHeight()/3);
 		}
 		repaint();
 	}
@@ -99,9 +130,11 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	}
 
 	@Override
-	public void mousePressed(MouseEvent e){
+	public void mousePressed(MouseEvent e) {
 		for (int i = 0; i < pointList.length; i++) {
-			if(e.getX()-this.getWidth()/NUMBER<pointList[i].getX() && e.getX()+this.getWidth()/NUMBER>pointList[i].getX() && e.getY()-10<pointList[i].getY() && e.getY()+10>pointList[i].getY()){
+			if (e.getX() - this.getWidth() / NUMBER / 2 <= pointList[i].getX()
+					&& e.getX() + this.getWidth() / NUMBER / 2 >= pointList[i].getX()
+					&& e.getY() - 10 < pointList[i].getY() && e.getY() + 10 > pointList[i].getY()) {
 				pointDrag = true;
 				tempP = i;
 			}
@@ -117,9 +150,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	public void componentResized(ComponentEvent e) {
 		// resize listener
-		System.out.println("resize");
 		for (int i = 0; i < pointList.length; i++) {
-			pointList[i] = new Point((i)*this.getWidth()/NUMBER,this.getHeight()/2);
+			pointList[i] = new Point((i) * this.getWidth() / (NUMBER - 1), this.getHeight() / 3);
 		}
 		repaint();
 	}
@@ -130,7 +162,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	@Override
 	public void componentMoved(ComponentEvent e) {
-		
+
 	}
 
 	@Override