Browse Source

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

Teh-Hai Julian Zheng 8 years ago
parent
commit
4b4ed16f77
2 changed files with 55 additions and 42 deletions
  1. 11 5
      src/ui/view/GUI.java
  2. 44 37
      src/ui/view/UnitGraph.java

+ 11 - 5
src/ui/view/GUI.java

@@ -51,6 +51,7 @@ import javax.swing.tree.TreeCellRenderer;
 import Interfaces.CategoryListener;
 import classes.Category;
 import classes.CpsEdge;
+import classes.CpsNode;
 import classes.CpsObject;
 import classes.HolonElement;
 import classes.HolonObject;
@@ -366,13 +367,18 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void propertyChange(PropertyChangeEvent evt) {
 				try {
+					Object temp;
 					if (getActualCps() != null) {
-						String newName = tableModelProperties.getValueAt(0, 1).toString();
-						getActualCps().setName(newName);
+						temp = tableModelProperties.getValueAt(0, 1);
+						getActualCps().setName(temp.toString());
 					} else {
-						float newCap = (float) tableModelProperties.getValueAt(2, 1);
-						System.out.println(newCap);
-						model.getSelectedEdge().setCapacity(newCap);
+						temp = tableModelProperties.getValueAt(2, 1);
+						Float ftemp = Float.parseFloat(temp.toString());
+						System.out.println(ftemp);
+						model.getSelectedEdge().setCapacity(ftemp);
+					}
+					for (CpsEdge c : getActualCps().getConnections()) {
+						System.out.println(c.getA().getName() + " conected to " + c.getB().getName());
 					}
 				} catch (Exception e) {
 

+ 44 - 37
src/ui/view/UnitGraph.java

@@ -27,7 +27,6 @@ import java.awt.Cursor;
 class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, ComponentListener {
 
 	private static final long serialVersionUID = 1L;
-	private int ITERATIONS = 50;
 	private float MAXIMUM = 0;
 
 	private Point recSize = new Point(8, 8); // Point Size
@@ -45,7 +44,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private HolonElement tempElement;
 	private Model model;
 	private Control controller;
-	GeneralPath graphCurve = new GeneralPath();  
+	GeneralPath graphCurve = new GeneralPath();
 
 	private boolean pointDrag = false;
 	private boolean init = false;
@@ -57,10 +56,9 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
 		this.controller = control;
 		this.model = model;
-		this.ITERATIONS = model.getIterations();
-		
+
 		this.pointList = new LinkedList<>();
-		
+
 		this.addMouseListener(this);
 		this.addMouseMotionListener(this);
 		this.addComponentListener(this);
@@ -78,27 +76,27 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);
 		g2.setStroke(new BasicStroke(1));
-		
+
 		graphCurve.reset();
-		
+
 		if (arrayOfValue != null) {
 			for (int i = 0; i < arrayOfValue.length; i++) {
-				arrayOfValue[i] = convertToValueY(getYValueAt((int) (i * width / (ITERATIONS - 1))));
+				arrayOfValue[i] = convertToValueY(getYValueAt((int) (i * width / (model.getIterations() - 1))));
 			}
 		}
-		
+
 		// Draw the Vertical Lines
 		g2.setColor(new Color(240, 240, 240));
-		for (int i = 0; i < ITERATIONS; i++) {
-			g2.drawLine((i) * this.getWidth() / (ITERATIONS - 1), 0, (i) * this.getWidth() / (ITERATIONS - 1),
-					this.getHeight());
+		for (int i = 0; i < model.getIterations(); i++) {
+			g2.drawLine((i) * this.getWidth() / (model.getIterations() - 1), 0,
+					(i) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
 		}
 
-		for (int i = 0; i < ITERATIONS; i++) {
-			g2.drawLine(0, (i) * this.getHeight() / (ITERATIONS - 1), this.getWidth(),
-					(i) * this.getHeight() / (ITERATIONS - 1));
+		for (int i = 0; i < model.getIterations(); i++) {
+			g2.drawLine(0, (i) * this.getHeight() / (model.getIterations() - 1), this.getWidth(),
+					(i) * this.getHeight() / (model.getIterations() - 1));
 		}
-		
+
 		// Draw the Lines
 		g2.setColor(Color.BLACK);
 		for (int i = 0; i < pointList.size() - 1; i++) {
@@ -106,7 +104,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			graphCurve.append(c, true);
 		}
 		g2.draw(graphCurve);
-		
+
 		// Draw the Points
 		g2.setColor(Color.BLUE);
 		for (int i = 0; i < pointList.size() - 0; i++) {
@@ -114,21 +112,30 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 					(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
 					(int) recSize.getY());
 		}
-		g2.drawLine((model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1), 0,
-				(model.getCurIteration()) * this.getWidth() / (ITERATIONS - 1), this.getHeight());
-
-		//Actual Iteration Point Visualization
-		/*
-		g2.setColor(Color.RED);
+		// Iteration Line
+		g2.drawLine((model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), 0,
+				(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1), this.getHeight());
+		// Iteration Value
 		if (arrayOfValue != null) {
-			for (int i = 0; i < arrayOfValue.length; i++) {
-				g2.fillOval((int) (i * width / (ITERATIONS - 1) * scaleX - recSize.getX() / 2),
-						(int) (convertToCanvasY((int) arrayOfValue[i]) * scaleY - recSize.getY() / 2), (int) recSize.getX(),
-						(int) recSize.getY());
+			if (model.getCurIteration() > model.getIterations() / 2) {
+				g2.drawString("" + arrayOfValue[model.getCurIteration()],
+						(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) - 30,
+						this.getHeight() / 2);
+			} else {
+				g2.drawString("" + arrayOfValue[model.getCurIteration()],
+						(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
+						this.getHeight() / 2);
 			}
 		}
-		*/
-		
+		// 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()); } }
+		 */
+
 	}
 
 	@Override
@@ -269,7 +276,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 */
 	public void reset() {
 		pointList.removeAll(pointList);
-		pointList.addFirst(new Point(0,0));
+		pointList.addFirst(new Point(0, 0));
 		pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
 		repaint();
 	}
@@ -282,10 +289,10 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 * @return the converted number
 	 */
 	public double convertToCanvasY(float d) {
-		System.out.println(""+(height + (d*(height/MAXIMUM))));
-		return (height -(d*(height/MAXIMUM)));
+		System.out.println("" + (height + (d * (height / MAXIMUM))));
+		return (height - (d * (height / MAXIMUM)));
 	}
-	
+
 	/**
 	 * converts the number to fit the value
 	 * 
@@ -293,8 +300,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 *            d, the number to convert
 	 * @return the converted number
 	 */
-	public float convertToValueY(double d){
-		return (float)((height - ( height * (d/height)))/(height/MAXIMUM));
+	public float convertToValueY(double d) {
+		return Math.round(((float) ((height - (height * (d / height))) / (height / MAXIMUM)) * 10)) / 10;
 	}
 
 	/**
@@ -354,7 +361,7 @@ 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 (int) getIntersectionPoint(l1, l2).getY();
 			}
 		}
@@ -373,7 +380,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		} else {
 			double z = (sx * (qy - py) + sy * (px - qx)) / det;
 			if (z < 0 || z > 1)
-				return new Point(0,0); // intersection at end point!
+				return new Point(0, 0); // intersection at end point!
 			return new Point((int) (px + z * rx), (int) (py + z * ry));
 		}
 	} // end intersection line-line