Tom Troppmann 6 years ago
parent
commit
0dd67d0828

+ 3 - 3
src/classes/CpsEdge.java

@@ -277,9 +277,9 @@ public class CpsEdge {
     
     @Override
     public String toString(){
-    	String A = a == null ? "null" : a.getName();
-    	String B = b == null ? "null" : b.getName();
-    	return "CpsEdge: " + a + " to " + b;
+    	String A = (a == null) ? "null" : a.getName();
+    	String B = (b == null) ? "null" : b.getName();
+    	return "CpsEdge: " + A + " to " + B;
     }
 
 }

+ 10 - 11
src/classes/HolonSwitch.java

@@ -88,22 +88,23 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 	 */
 	public HolonSwitch(AbstractCpsObject obj) {
 		super(obj);
-		setLocalPeriod(((HolonSwitch)obj).getLocalPeriod());
-		setStretching(((HolonSwitch)obj).isStretching());
+		HolonSwitch copyObj = (HolonSwitch)obj;
+		setLocalPeriod(copyObj.getLocalPeriod());
+		setStretching(copyObj.isStretching());
 		activeAt=new boolean[UnitGraph.STANDARD_GRAPH_ACCURACY];
 		super.setName(obj.getName());
-		setManualState(((HolonSwitch) obj).getActiveManual());
+		setManualState(copyObj.getActiveManual());
 		setAutoState(true);
 		setLocalPeriod(((IGraphedElement)obj).getLocalPeriod());
 		setActiveAt(true);
 		for (int i = 0; i < activeAt.length; i++) {
-			activeAt[i] = ((HolonSwitch) obj).getState(i);
+			activeAt[i] = copyObj.getState(i);
 		}
 		setGraphPoints(new LinkedList<Point>());
-		for (Point p : ((HolonSwitch) obj).getGraphPoints()) {
+		for (Point p : copyObj.getGraphPoints()) {
 			this.graphPoints.add(new Point((int) p.getX(), (int) p.getY()));
 		}
-		setManualMode(((HolonSwitch) obj).getManualMode());
+		setManualMode(copyObj.getManualMode());
 	}
 
 	/**
@@ -178,13 +179,13 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 	 */
 	private void setImage() {
 		if (manualMode) {
-			if (this.manualActive == false) {
+			if (!this.manualActive) {
 				setImage("/Images/switch-off.png");
 			} else {
 				setImage("/Images/switch-on.png");
 			}
 		} else {
-			if (this.autoActive == false) {
+			if (!this.autoActive) {
 				setImage("/Images/switch-off.png");
 			} else {
 				setImage("/Images/switch-on.png");
@@ -211,9 +212,7 @@ public class HolonSwitch extends AbstractCpsObject implements IGraphedElement {
 		this.graphPoints = points;
 	}
 	
-	public boolean[] getValueArray() {//TODO: Only used in SubNet line 97. I am not entirely sure how important it is there.
-		return activeAt;
-	}
+
 
 	/**
 	 * Returns the ManualState.

+ 1 - 1
src/classes/SubNet.java

@@ -94,7 +94,7 @@ public class SubNet {
         }
         sb.append("\nSwitches:");
         for (HolonSwitch sw : getSwitches()) {
-            sb.append("    " + sw.getName() + "[ID:" + sw.getId()+ "]" + " State:" + sw.getValueArray());//TODO: I don't like this
+            sb.append("    " + sw.getName() + "[ID:" + sw.getId()+ "]");
         }
         sb.append("\nBatteries:");
         for (HolonBattery hB: getBatteries()) {

+ 2 - 7
src/ui/controller/CategoryController.java

@@ -58,12 +58,6 @@ public class CategoryController {
 	 *            the new Category
 	 */
 	public void addCategory(Category category) {
-		// int number = 0;
-		// String name = toAdd.getName();
-		// while (sC.containsInList(MODEL.getCategories(), toAdd)) {
-		// number++;
-		// toAdd.setName(name + "_" + number);
-		// }
 		int i = 0;
 		while (mpC.searchCat(category.getName()) != null) {
 			if (category.getName().contains("_"))
@@ -272,8 +266,9 @@ public class CategoryController {
 	 * notifies all listeners about changes in the Categories.
 	 */
 	public void notifyCatListeners() {
+		ArrayList<Category> categories =  model.getCategories();
 		for (CategoryListener l : model.getCategoryListeners()) {
-			l.onChange(model.getCategories());
+			l.onChange(categories);
 		}
 	}
 

+ 15 - 10
src/ui/controller/HolonCanvasController.java

@@ -39,8 +39,9 @@ public class HolonCanvasController {
 
 		ArrayList<Vector2d> pos = insertionDistSort(sortedDist);
 		for (int i = 0; i < subCount; i++) {
+			int ID = sortedSize.get(subCount - 1 - i).getId();
 			for (j = 0; j < subCount; j++) {
-				if (sortedSize.get(subCount - 1 - i).getId() == bodies.get(j).getId()) {
+				if (ID == bodies.get(j).getId()) {
 					bodies.get(j).position = pos.get(i);
 					break;
 				}
@@ -55,10 +56,12 @@ public class HolonCanvasController {
 		// find correct color for existing HolonBodys
 		ArrayList<HolonBody> newBodies = new ArrayList<>();
 		for (int i = 0; i < subCount; i++) {
+			Color subNetColor = model.getSubNetColors().get(i);			
 			for (int j = 0; j < bodies.size(); j++) {
-				if (model.getSubNetColors().get(i) == bodies.get(j).getColor()) {
-					bodies.get(j).setRadius((subnets.get(i).getObjects().size() * 5 + 10) * HolonBodyScale / 100);
-					bodies.get(j).setMass((float) Math.pow((subnets.get(i).getObjects().size() + 1) * 5, 3));
+				if (subNetColor == bodies.get(j).getColor()) {
+					int objectsSize = subnets.get(i).getObjects().size();
+					bodies.get(j).setRadius((objectsSize * 5 + 10) * HolonBodyScale / 100);
+					bodies.get(j).setMass((float) Math.pow((objectsSize + 1) * 5, 3));
 					newBodies.add(bodies.get(j));
 					newBodies.get(i).setId(i);
 					break;
@@ -228,15 +231,17 @@ public class HolonCanvasController {
 
 		for (int i = 0; i < subCount; i++) {
 			// Ball to Ball collision
+			float radiusI = bodies.get(i).getRadius();
+			float xPlusradius = (bodies.get(i).position.getX() + radiusI);
+			float yPlusradius = (bodies.get(i).position.getY() + radiusI);
+			float yMinusRadius = (bodies.get(i).position.getY()- radiusI);
 			for (int j = i + 1; j < subCount; j++) {
-				if ((bodies.get(i).position.getX() + bodies.get(i).getRadius()) < (bodies.get(j).position.getX()
-						- bodies.get(j).getRadius()))
+				float radiusJ = bodies.get(j).getRadius();
+				if (xPlusradius < (bodies.get(j).position.getX()- radiusJ))
 					break;
 
-				if ((bodies.get(i).position.getY() + bodies.get(i).getRadius()) < (bodies.get(j).position.getY()
-						- bodies.get(j).getRadius())
-						|| (bodies.get(j).position.getY() + bodies.get(j).getRadius()) < (bodies.get(i).position.getY()
-								- bodies.get(i).getRadius()))
+				if (yPlusradius < (bodies.get(j).position.getY()- radiusJ)
+					|| (bodies.get(j).position.getY() + radiusJ) < yMinusRadius)
 					continue;
 
 				bodies.get(i).resolveCollision(bodies.get(j));

+ 1 - 0
src/ui/controller/UpdateController.java

@@ -422,6 +422,7 @@ public class UpdateController {
 		for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
 			if (o.getId() == id) {
 				obj = o;
+				break;
 			}
 		}
 		return obj;

+ 8 - 17
src/ui/view/FlexSubData.java

@@ -22,7 +22,7 @@ public class FlexSubData extends JSplitPane {
 	private JPanel currentObj;
 	private JButton btnShowObjects;
 	private FlexiblePane listener;
-	private boolean shown;
+	private boolean shown; // 0 = Hide, 1= Show
 	public FlexSubData(FlexibleData fD) {
 		setDividerSize(0);
 		setAlignmentY(Component.CENTER_ALIGNMENT);
@@ -34,26 +34,26 @@ public class FlexSubData extends JSplitPane {
 		subnetInfo.setMinimumSize(new Dimension(600, 100));
 		setLeftComponent(subnetInfo);
 		subnetInfo.setLayout(null);
-		
+		shown = true;
 		btnShowObjects = new JButton(SHOW);
 		btnShowObjects.setBounds(135, 13, 99, 23);
 		btnShowObjects.addActionListener(new ActionListener(){
 			public void actionPerformed(ActionEvent e){
-				if(btnShowObjects.getText() == SHOW){
+				if(shown){
 					objectInfo.removeAll();
 					objectInfo.add(currentObj);
 					objectInfo.revalidate();
 					objectInfo.updateUI();
 					listener.revalidate();
 					btnShowObjects.setText(HIDE);
-					shown = true;
-				}else if(btnShowObjects.getText() == HIDE){
+					shown = false;
+				}else{
 					objectInfo.removeAll();
 					objectInfo.revalidate();
 					objectInfo.updateUI();
 					listener.revalidate();
 					btnShowObjects.setText(SHOW);
-					shown = false;
+					shown = true;
 				}
 			}
 		});
@@ -62,7 +62,6 @@ public class FlexSubData extends JSplitPane {
 		objectInfo = new JPanel();
 		setRightComponent(objectInfo);
 		objectInfo.setLayout(new BoxLayout(objectInfo, BoxLayout.X_AXIS));
-		shown = false;
 	}
 	
 	public void setObjects(JPanel obj){
@@ -79,16 +78,6 @@ public class FlexSubData extends JSplitPane {
 	}
 	
 	public void repaint(){
-		/*
-		if(btnShowObjects != null && listener != null && currentObj != null){
-			if(shown){
-				btnShowObjects.setText(SHOW);
-			}else{
-				btnShowObjects.setText(HIDE);
-			}
-			btnShowObjects.doClick();
-		}
-		*/
 		super.repaint();
 	}
 	
@@ -98,6 +87,7 @@ public class FlexSubData extends JSplitPane {
 		objectInfo.revalidate();
 		objectInfo.updateUI();
 		listener.revalidate();
+		shown = false;
 		btnShowObjects.setText(HIDE);
 	}
 	
@@ -106,6 +96,7 @@ public class FlexSubData extends JSplitPane {
 		objectInfo.revalidate();
 		objectInfo.updateUI();
 		listener.revalidate();
+		shown = true;
 		btnShowObjects.setText(SHOW);
 	}
 }

+ 2 - 2
src/ui/view/TimePanel.java

@@ -393,8 +393,8 @@ public class TimePanel extends JPanel implements ActionListener{
 			controller.getModel().setIterations(Integer.parseInt(iterationsField.getText()));
 			timeSlider.setMaximum(controller.getModel().getIterations()-1);
 			timeSlider.setLabelTable(null);//Otherwise the ticks won't update
-			timeSlider.setMajorTickSpacing((int)Math.ceil(((double)controller.getModel().getIterations())/20));
-			timeSlider.setMinorTickSpacing((int)Math.ceil(((double)controller.getModel().getIterations())/100));//Even though the final mark can't actually be reached.
+			timeSlider.setMajorTickSpacing((int)Math.ceil(((double)iterations)/20));
+			timeSlider.setMinorTickSpacing((int)Math.ceil(((double)iterations)/100));//Even though the final mark can't actually be reached.
 			parentGUI.updateIterations();//First one in the chain
 		}catch(NumberFormatException e){}
 	}