Quellcode durchsuchen

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

dominik.rieder vor 8 Jahren
Ursprung
Commit
d056825cc8
4 geänderte Dateien mit 58 neuen und 25 gelöschten Zeilen
  1. 17 9
      src/classes/CpsObject.java
  2. 6 3
      src/ui/view/MyCanvas.java
  3. 13 5
      src/ui/view/SimulationMenu.java
  4. 22 8
      src/ui/view/UnitGraph.java

+ 17 - 9
src/classes/CpsObject.java

@@ -27,7 +27,6 @@ public abstract class CpsObject {
 	/* a Tag that can be used */
 	ArrayList<Integer> tags;
 
-
 	/**
 	 * Constructor for an CpsObejct with an unique ID
 	 */
@@ -149,6 +148,15 @@ public abstract class CpsObject {
 		return BorderColor;
 	}
 
+	/**
+	 * Set the Border Color of this CpsObject
+	 * 
+	 * @param the BorderColor
+	 */
+	public void setBorderColor(Color c) {
+		this.BorderColor = c;
+	}
+
 	/**
 	 * @param Color
 	 *            the Color to set
@@ -156,20 +164,20 @@ public abstract class CpsObject {
 	public void setConnections(Color color) {
 		this.BorderColor = color;
 	}
-	
-	public void addTag(int tag){
+
+	public void addTag(int tag) {
 		this.tags.add(tag);
 	}
-	
-	public ArrayList<Integer> getTag(){
+
+	public ArrayList<Integer> getTag() {
 		return tags;
 	}
-	
-	public void resetTags(){
+
+	public void resetTags() {
 		this.tags = new ArrayList<Integer>();
 	}
-	
-	public void setTags(ArrayList<Integer> tags){
+
+	public void setTags(ArrayList<Integer> tags) {
 		this.tags = tags;
 	}
 }

+ 6 - 3
src/ui/view/MyCanvas.java

@@ -156,8 +156,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);
 
-		// drawEdges
-		// g2.setColor(Color.BLACK);
+		// drawEdges that is being dragged
 		if (drawEdge) {
 			g2.setColor(Color.BLACK);
 			g2.setStroke(new BasicStroke(2));
@@ -230,7 +229,11 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			}
 		} else if (edgeHighlight != null) {
 			g2.setColor(Color.BLUE);
-			g2.setStroke(new BasicStroke(2));
+			if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
+				g2.setStroke(new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 4), 4)));
+			} else {
+				g2.setStroke(new BasicStroke(2));
+			}
 			g2.drawLine(edgeHighlight.getA().getPosition().x + controller.getScaleDiv2(),
 					edgeHighlight.getA().getPosition().y + controller.getScaleDiv2(),
 					edgeHighlight.getB().getPosition().x + controller.getScaleDiv2(),

+ 13 - 5
src/ui/view/SimulationMenu.java

@@ -51,7 +51,7 @@ public class SimulationMenu extends JMenuBar {
 	private JComboBox algoCombo = new JComboBox<>();
 	private JButton algoFolderButton = new JButton("Algorithm:");
 	private HashMap<String, File> algosHash = new HashMap<>();
-	
+
 	Model model;
 	Control controller;
 
@@ -81,9 +81,16 @@ public class SimulationMenu extends JMenuBar {
 					for (int i = 0; i < files.length; i++) {
 						if (files[i].toString().endsWith(".java") || files[i].toString().endsWith(".class")) {
 							String name = files[i].toString();
-							int tmpA = name.lastIndexOf('/');
+							int tmpS = name.lastIndexOf('/');
+							int tmpBS = name.lastIndexOf('\\');
+							int tmpA;
+							if (tmpS > tmpBS) {
+								tmpA = tmpS;
+							} else {
+								tmpA = tmpBS;
+							}
 							int tmpB = name.lastIndexOf('.');
-							name = name.substring(tmpA+1, tmpB);
+							name = name.substring(tmpA + 1, tmpB);
 							algosHash.put(name, files[i]);
 							algoCombo.addItem(name);
 						}
@@ -107,6 +114,7 @@ public class SimulationMenu extends JMenuBar {
 			@Override
 			public void propertyChange(PropertyChangeEvent evt) {
 				controller.setIsSimulation(simButton.isSelected());
+				controller.calculateStateForCurrentTimeStep();
 			}
 		});
 		GridBagConstraints gbc_simButton = new GridBagConstraints();
@@ -155,8 +163,8 @@ public class SimulationMenu extends JMenuBar {
 		gbc_algoCombo.gridy = 0;
 		menuPanel.add(algoCombo, gbc_algoCombo);
 		algoCombo.addItem("choose folder");
-		
-		//Add Panel to SimulationMenu
+
+		// Add Panel to SimulationMenu
 		this.add(menuPanel);
 	}
 }

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

@@ -19,8 +19,6 @@ import java.awt.Point;
 
 import javax.swing.JPanel;
 
-import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;
-
 import classes.HolonElement;
 import ui.controller.Control;
 import ui.model.Model;
@@ -33,12 +31,17 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private static final long serialVersionUID = 1L;
 	private float MAXIMUM = 0;
 
+	// Information shown when a Point is Dragged
+	private String dragInformation = "";
+
+	// Points
 	private Point recSize = new Point(8, 8); // Point Size
 	private Graphics2D g2;
 	private CubicCurve2D c = new CubicCurve2D.Double();
 	private CubicCurve2D cr = new CubicCurve2D.Double();
 	private CubicCurve2D cl = new CubicCurve2D.Double();
 	private LinkedList<Point> pointList;
+	// Scale for the Graph
 	private double scaleX;
 	private double scaleY;
 
@@ -52,7 +55,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	private boolean isSwitch = false;
 
 	private ArrayList<HolonElement> tempElements = new ArrayList<>();
-	private HolonSwitch tempSwitch;
 	private Model model;
 	private Control controller;
 	private Line2D.Double line = null;
@@ -105,6 +107,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		if (isElement) {
 			// array fillen
 			fillArrayofValue();
+	
 			if (arrayOfFloats != null) {
 				// Draw the Lines
 				g2.setStroke(new BasicStroke(2));
@@ -130,6 +133,12 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 							this.getHeight() - 10);
 				}
 			}
+			//drag Information
+			if (tempP != null) {
+				dragInformation = "" + convertToValueY(getYValueAt((int) tempP.getX()));
+				g2.drawString(dragInformation, (int) (tempP.getX()* scaleX)+10, (int) (tempP.getY()* scaleY)+10);
+			}
+			
 			/*
 			 * // Actual Iteration Point Visualization g2.setColor(Color.RED);
 			 * if (arrayOfValue != null) { for (int i = 0; i <
@@ -169,7 +178,12 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 							this.getHeight() - 10);
 				}
 			}
+			if (tempP != null) {
+				dragInformation = "model.get";
+				g2.drawString(dragInformation, (int) (getMousePosition().getX())+10, (int) (getMousePosition().getY())+10);
+			}
 		}
+		
 		// Iteration Line
 		g2.setColor(Color.BLUE);
 		g2.setStroke(new BasicStroke(1));
@@ -212,6 +226,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				x = tempP.getX();
 			}
 			tempP.setLocation(x, y);
+
 			repaint();
 		}
 	}
@@ -334,7 +349,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		boolean deletePoint = false;
 
 		double x = e.getX() / scaleX;
-		double y = e.getY() / scaleY;
+		e.getY();
 
 		// Halbe Iterations Distanz
 		double dist = (width / (model.getIterations() - 1)) / 2;
@@ -407,6 +422,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 			pointDrag = false;
 			tempP = null;
 		}
+		dragInformation = "";
 	}
 
 	public void componentResized(ComponentEvent e) {
@@ -443,12 +459,11 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	}
 
 	/*
-	 * Emptys the Graph
+	 * Empty the Graph
 	 */
 	public void empty() {
 		pointList = null;
 		tempElements = null;
-		tempSwitch = null;
 		arrayOfFloats = null;
 		arrayOfBooleans = null;
 		isSwitch = false;
@@ -501,7 +516,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		isSwitch = false;
 		isElement = true;
 		MAXIMUM = selectedElement.get(selectedElement.size() - 1).getEnergy();
-  		// First time clicked on the Element
+		// First time clicked on the Element
 		if (pointList.isEmpty()) {
 			pointList.addFirst(new Point(0, 0));
 			pointList.addLast(new Point((int) (this.getWidth() / scaleX), 0));
@@ -517,7 +532,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 */
 	public void repaintWithNewSwitch(HolonSwitch s) {
 		arrayOfBooleans = s.getActiveAt();
-		tempSwitch = s;
 		pointList = s.getGraphPoints();
 		isSwitch = true;
 		isElement = false;