Kevin Trometer 7 vuotta sitten
vanhempi
commit
1f9d3a026d

+ 10 - 0
src/ui/controller/Control.java

@@ -390,6 +390,16 @@ public class Control {
 
 	/* Global Operations */
 
+	/**
+	 * Add a SubNetColor.
+	 * 
+	 * @param c
+	 *            the Color
+	 */
+	public void addSubNetColor(Color c) {
+		globalController.addSubNetColor(c);
+	}
+	
 	/**
 	 * Returns SCALE.
 	 * 

+ 12 - 0
src/ui/controller/GlobalController.java

@@ -1,5 +1,7 @@
 package ui.controller;
 
+import java.awt.Color;
+
 import ui.model.Model;
 
 /**
@@ -116,4 +118,14 @@ public class GlobalController {
 	public void setCanvasY(int canvasY) {
 		model.setCanvasY(canvasY);
 	}
+	
+	/**
+	 * Add a SubNetColor.
+	 * 
+	 * @param c
+	 *            the Color
+	 */
+	public void addSubNetColor(Color c) {
+		model.addSubNetColor(c);
+	}
 }

+ 29 - 5
src/ui/model/Model.java

@@ -1,5 +1,6 @@
 package ui.model;
 
+import java.awt.Color;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
@@ -29,6 +30,7 @@ public class Model {
 	private static int sCALEdIV2 = sCALE / 2;
 	private static final int ITERATIONS = 100;
 	private int curIteration = 0;
+	private LinkedList<Color> subNetColors = new LinkedList<>();
 	// ID of the Selected Object
 	private AbstractCpsObject selectedCpsObject = null;
 	private HolonElement selectedHolonElement;
@@ -79,7 +81,7 @@ public class Model {
 	 * Object that runs the Algorithm
 	 */
 	private Object algorithm = null;
-	
+
 	/**
 	 * Constructor for the model. It initializes the categories and
 	 * objectsOnCanvas by default values. Listeners are also initialized by
@@ -537,7 +539,8 @@ public class Model {
 	/**
 	 * Set Canvas X Size.
 	 * 
-	 * @param canvasX the cANVAS_X to set
+	 * @param canvasX
+	 *            the cANVAS_X to set
 	 */
 	public void setCanvasX(int canvasX) {
 		this.canvasX = canvasX;
@@ -555,12 +558,13 @@ public class Model {
 	/**
 	 * Set Canvas Y size.
 	 * 
-	 * @param canvasY the cANVAS_Y to set
+	 * @param canvasY
+	 *            the cANVAS_Y to set
 	 */
 	public void setCanvasY(int canvasY) {
 		this.canvasY = canvasY;
 	}
-	
+
 	/**
 	 * get the Algorithm.
 	 * 
@@ -573,10 +577,30 @@ public class Model {
 	/**
 	 * Set the Algorithm.
 	 * 
-	 * @param obj the Algorithm
+	 * @param obj
+	 *            the Algorithm
 	 */
 	public void setAlgorithm(Object obj) {
 		this.algorithm = null;
 		this.algorithm = obj;
 	}
+
+	/**
+	 * Add a SubNetColor.
+	 * 
+	 * @param c
+	 *            the Color
+	 */
+	public void addSubNetColor(Color c) {
+		this.subNetColors.add(c);
+	}
+
+	/**
+	 * Get the SubNetColors.
+	 * 
+	 * @return SubNetColors
+	 */
+	public LinkedList<Color> getSubNetColors() {
+		return this.subNetColors;
+	}
 }

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

@@ -32,6 +32,7 @@ import classes.AbstractCpsObject;
 import classes.HolonElement;
 import classes.HolonObject;
 import classes.HolonSwitch;
+import classes.SubNet;
 import ui.controller.Control;
 import ui.model.Model;
 
@@ -166,6 +167,20 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);
 
+		// Test SubNet Coloring
+		int i = 0;
+		for (SubNet s : controller.getSimManager().getSubNets()) {
+			
+			if(model.getSubNetColors().size()-1 < i){
+				controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255), (int) (Math.random() * 255)));
+			}
+			
+			for (HolonObject cps : s.getObjects()) {
+				cps.setBorderColor(model.getSubNetColors().get(i));
+			}
+			i++;
+		}
+
 		// drawEdges that is being dragged
 		if (drawEdge) {
 			g2.setColor(Color.BLACK);
@@ -380,14 +395,14 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				}
 			}
 		}
-		
+
 		// Edge Selection
 		if (tempCps == null) {
 			edgeHighlight = mousePositionOnEdge(x, y);
 			controller.setSelecteEdge(edgeHighlight);
 			controller.setSelectedObjectID(0);
 			if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
-				model.	getSelectedCpsObjects().clear();
+				model.getSelectedCpsObjects().clear();
 			}
 		}
 
@@ -397,7 +412,6 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			doMark = true;
 		}
 
-
 		repaint();
 	}
 
@@ -409,7 +423,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 			drawEdge = false;
 			drawDeleteEdge();
 		}
-		
+
 		if (dragged == true) {
 			try {
 				controller.autoSave();
@@ -418,15 +432,14 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				ex.printStackTrace();
 			}
 		}
-		
 
 		if (!e.isControlDown() && dragged == false && tempCps != null && e.BUTTON3 != e.getButton()) {
 			model.getSelectedCpsObjects().clear();
 			controller.addSelectedObject(tempCps);
 		}
-		
+
 		dragged = false;
-		
+
 		// Rightclick List
 		if (e.getButton() == MouseEvent.BUTTON3) {
 			if (e.getButton() == MouseEvent.BUTTON3 && tempCps != null) {