Forráskód Böngészése

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 8 éve
szülő
commit
afc4079274

+ 36 - 29
src/classes/Category.java

@@ -3,37 +3,33 @@ package classes;
 import java.util.ArrayList;
 import java.util.HashMap;
 
+/**
+ * Class "Category" performs the functionality of listing elements into groups.
+ * Each Category contains an ArrayList of CpsObjects, a name and a HashMap of
+ * ObjIdx.
+ * 
+ * @author Gruppe14
+ *
+ */
 
-public class Category{
-	
-	private int ID;
+public class Category {
+	// objects: is a ArrayList of all Objects that belongs to the Category
 	private ArrayList<CpsObject> objects;
+	// name: is a String chosen by the User
 	private String name;
-	private HashMap<String, Integer> ObjIdx;
-	
-	public Category(String name){
+	// ObjIdx: Index of each Category that corresponds to the order in the tree
+	private HashMap<String, Integer> objIdx;
+
+	public Category(String name) {
 		setObjects(new ArrayList<CpsObject>());
 		setName(name);
-		setID(-1);
-		setObjIdx(new HashMap<String,Integer>());
-	
-	}
+		setObjIdx(new HashMap<String, Integer>());
 
-	/**
-	 * @return the id
-	 */
-	public int getID() {
-		return ID;
-	}
-
-	/**
-	 * @param id the id to set
-	 */
-	public void setID(int id) {
-		this.ID = id;
 	}
 
 	/**
+	 * Getter for all CpsObjects
+	 * 
 	 * @return the objects
 	 */
 	public ArrayList<CpsObject> getObjects() {
@@ -41,13 +37,18 @@ public class Category{
 	}
 
 	/**
-	 * @param objects the objects to set
+	 * Set a new ArrayList of CpsObjects
+	 * 
+	 * @param objects
+	 *            the objects to set
 	 */
 	public void setObjects(ArrayList<CpsObject> objects) {
 		this.objects = objects;
 	}
 
 	/**
+	 * Getter the name of the Category
+	 * 
 	 * @return the name
 	 */
 	public String getName() {
@@ -55,26 +56,32 @@ public class Category{
 	}
 
 	/**
-	 * @param name the name to set
+	 * Set the name of the Category to a new one
+	 * 
+	 * @param name
+	 *            the name to set
 	 */
 	public void setName(String name) {
 		this.name = name;
 	}
 
 	/**
+	 * Getter of the Objects in the Tree with their respective order
+	 * 
 	 * @return the objIdx
 	 */
 	public HashMap<String, Integer> getObjIdx() {
-		return ObjIdx;
+		return objIdx;
 	}
 
 	/**
-	 * @param objIdx the objIdx to set
+	 * Set a new sequence of Objects in the tree
+	 * 
+	 * @param objIdx
+	 *            the objIdx to set
 	 */
 	public void setObjIdx(HashMap<String, Integer> objIdx) {
-		ObjIdx = objIdx;
+		this.objIdx = objIdx;
 	}
 
-
-	
 }

+ 96 - 26
src/classes/CpsEdge.java

@@ -2,20 +2,43 @@ package classes;
 
 import java.util.ArrayList;
 
+/**
+ * The class "CpsEdge" represents the connections on the GUI. Each connection
+ * contains a max. capacity, a flow, a status (isWorking), tags (for internal
+ * use of electricity flow), source and destination
+ * 
+ * @author Gruppe14
+ *
+ */
 public class CpsEdge {
 
+	// Max. capacity of the Edge, if flow is greater than the status --> is
+	// Working would be false
 	float maxCapacity;
+	// Current flow of electricity (through the edge)
 	float flow;
+	/*
+	 * Represents the actual status of the Edge (true = flows electricity; false
+	 * = no flow of electricity) State represents the real status of the edge If
+	 * it breaks --> stay ruin no matter the actual scenario The only way to
+	 * repair it is through manual change (setStateEdge)
+	 */
 	boolean isWorking;
-	//State represents the real status of the edge
-	//If it breaks --> stay ruin no matter the actual scenario
-	//The only way to repair it is through manual change (setStateEdge) 
-	
+	// for internal use --> flow of electricity (simulation state)
 	ArrayList<Integer> tags;
-
+	// Source
 	CpsObject A;
+	// Destination
 	CpsObject B;
 
+	/**
+	 * Constructor without max. capacity (by default as 100)
+	 * 
+	 * @param A
+	 *            Source
+	 * @param B
+	 *            Destination
+	 */
 	public CpsEdge(CpsObject A, CpsObject B) {
 		setA(A);
 		setB(B);
@@ -26,6 +49,14 @@ public class CpsEdge {
 		isWorking = true;
 	}
 
+	/**
+	 * Constructor with a user-defined max. capacity
+	 * 
+	 * @param A
+	 *            Source
+	 * @param B
+	 *            Destination
+	 */
 	public CpsEdge(CpsObject A, CpsObject B, float maxCap) {
 		setA(A);
 		setB(B);
@@ -37,6 +68,8 @@ public class CpsEdge {
 	}
 
 	/**
+	 * Getter for the max. capacity
+	 * 
 	 * @return the capacity
 	 */
 	public float getCapacity() {
@@ -44,6 +77,8 @@ public class CpsEdge {
 	}
 
 	/**
+	 * Setter for the max. capacity
+	 * 
 	 * @param cap
 	 *            the Capacity to set
 	 */
@@ -52,6 +87,8 @@ public class CpsEdge {
 	}
 
 	/**
+	 * Getter fot the current flow
+	 * 
 	 * @return the flow
 	 */
 	public float getFlow() {
@@ -59,36 +96,38 @@ public class CpsEdge {
 	}
 
 	/**
+	 * Set the flow into a new one
+	 * 
 	 * @param flow
 	 *            the flow to set
 	 */
 	public void setFlow(float flow) {
 		this.flow = flow;
 		/**
-		if (flow <= maxCapacity || flow == -1) {
-			isWorking = true;
-		} else {
-			isWorking = false;
-			state = false;
-		}
-		**/
+		 * if (flow <= maxCapacity || flow == -1) { isWorking = true; } else {
+		 * isWorking = false; state = false; }
+		 **/
 	}
-	
+
 	/**
-	 * calculates wether isWorking or not
+	 * Calculates the state of the edge (see description of isWorking)
+	 * 
 	 * @param simMode
 	 */
-	public void calculateState(boolean simMode){
-		if(flow > maxCapacity && maxCapacity != -1){
+
+	public void calculateState(boolean simMode) {
+		if (flow > maxCapacity && maxCapacity != -1) {
 			isWorking = false;
-		}else {
-			if(!simMode && flow <= maxCapacity){
+		} else {
+			if (!simMode && flow <= maxCapacity) {
 				isWorking = true;
 			}
 		}
 	}
 
 	/**
+	 * Getter for the Source
+	 * 
 	 * @return the a
 	 */
 	public CpsObject getA() {
@@ -96,6 +135,8 @@ public class CpsEdge {
 	}
 
 	/**
+	 * Set the Source to a new one
+	 * 
 	 * @param a
 	 *            the a to set
 	 */
@@ -104,6 +145,8 @@ public class CpsEdge {
 	}
 
 	/**
+	 * Getter for the destination
+	 * 
 	 * @return the b
 	 */
 	public CpsObject getB() {
@@ -111,30 +154,57 @@ public class CpsEdge {
 	}
 
 	/**
+	 * Set the Destination to a new one
+	 * 
 	 * @param b
 	 *            the b to set
 	 */
 	public void setB(CpsObject b) {
 		B = b;
 	}
-	
-	public void setState(boolean state){
+
+	/**
+	 * Set the state manually to a new one
+	 * 
+	 * @param state
+	 */
+	public void setState(boolean state) {
 		isWorking = state;
 	}
 
+	/**
+	 * Getter for the status
+	 * 
+	 * @return
+	 */
 	public boolean getState() {
 		return isWorking;
 	}
-	
-	public void setTags(ArrayList<Integer> tags){
+
+	/**
+	 * set the tags into a new set of tags
+	 * 
+	 * @param tags
+	 */
+	public void setTags(ArrayList<Integer> tags) {
 		this.tags = tags;
 	}
-	
-	public ArrayList<Integer> getTags(){
+
+	/**
+	 * Getter for the ArrayList of tags
+	 * 
+	 * @return
+	 */
+	public ArrayList<Integer> getTags() {
 		return tags;
 	}
-	
-	public void addTag(int tag){
+
+	/**
+	 * Add a new tag to the ArrayList
+	 * 
+	 * @param tag
+	 */
+	public void addTag(int tag) {
 		tags.add(tag);
 	}
 

+ 13 - 1
src/classes/CpsNode.java

@@ -4,8 +4,21 @@ import java.util.ArrayList;
 
 import ui.model.idCounter;
 
+/**
+ * The class "CpsNode" represents empty Objects in the system. They are just
+ * nodes between Objects
+ * 
+ * @author Gruppe14
+ *
+ */
 public class CpsNode extends CpsObject {
 
+	/**
+	 * Create a new node in the system with an user-defined name
+	 * 
+	 * @param objName
+	 *            String
+	 */
 	public CpsNode(String objName) {
 		super(objName);
 		this.setConnections(new ArrayList<CpsEdge>());
@@ -13,5 +26,4 @@ public class CpsNode extends CpsObject {
 		this.setSav("CVS");
 		this.setID(idCounter.nextId());
 	}
-
 }

+ 111 - 11
src/classes/CpsObject.java

@@ -6,6 +6,14 @@ import java.util.HashMap;
 
 import ui.model.idCounter;
 
+/**
+ * The abstract class "CpsObject" represents any possible object in the system
+ * (except Edges). The representation of any object contains following
+ * variables: see description of variables
+ * 
+ * @author Gruppe14
+ *
+ */
 public abstract class CpsObject {
 	/* Type of the Object */
 	String objName;
@@ -19,8 +27,10 @@ public abstract class CpsObject {
 	ArrayList<CpsEdge> connections;
 	/* Position with a X and Y value */
 	Position position;
-	/* Energy input and output of each object in the grid */
-	/* Where the Object is Stored */
+	/*
+	 * Energy input and output of each object in the grid Where the Object is
+	 * Stored
+	 */
 	String sav;
 	/* BorderColor the user sets */
 	Color BorderColor = Color.WHITE;
@@ -28,7 +38,7 @@ public abstract class CpsObject {
 	ArrayList<Integer> tags;
 
 	/**
-	 * Constructor for an CpsObejct with an unique ID
+	 * Constructor for a CpsObejct with an unique ID
 	 */
 	public CpsObject(String objName) {
 		setObjName(objName);
@@ -36,6 +46,14 @@ public abstract class CpsObject {
 		setImage("/Images/Dummy_House.png");
 	}
 
+	/**
+	 * Constructor for a new CpsObject with an unique ID (This constructor
+	 * correspond to the interaction between the Categories and Canvas)-->
+	 * actually the "new" Object is a copy.
+	 * 
+	 * @param obj
+	 *            Object to be copied
+	 */
 	public CpsObject(CpsObject obj) {
 		setObjName(obj.getObjName());
 		setName(obj.getObjName());
@@ -45,30 +63,56 @@ public abstract class CpsObject {
 		setImage(obj.getImage());
 	}
 
-	/* Obj type */
+	/**
+	 * Getter for the type of the Object
+	 * 
+	 * @return String
+	 */
 	public String getObjName() {
 		return objName;
 	}
 
+	/**
+	 * Set the type of Object
+	 * 
+	 * @param objName
+	 *            String
+	 */
 	public void setObjName(String objName) {
 		this.objName = objName;
 	}
 
-	/* User defined Name */
+	/**
+	 * Getter for the user-defined name (no unique)
+	 * 
+	 * @return String
+	 */
 	public String getName() {
 		return name;
 	}
 
+	/**
+	 * Set the name
+	 * 
+	 * @param name
+	 *            String
+	 */
 	public void setName(String name) {
 		this.name = name;
 	}
 
-	/* Unique ID number */
+	/**
+	 * Getter of the unique ID
+	 * 
+	 * @return int
+	 */
 	public int getID() {
 		return ID;
 	}
 
 	/**
+	 * Set the ID to a new one
+	 * 
 	 * @param iD
 	 *            the iD to set
 	 */
@@ -76,12 +120,18 @@ public abstract class CpsObject {
 		this.ID = ID;
 	}
 
-	/* Image path */
+	/**
+	 * Get the path of the image for the selected Object
+	 * 
+	 * @return String
+	 */
 	public String getImage() {
 		return image;
 	}
 
 	/**
+	 * Set the path of the image
+	 * 
 	 * @param image
 	 *            the Image to set
 	 */
@@ -90,13 +140,17 @@ public abstract class CpsObject {
 	}
 
 	/**
-	 * @return the connections
+	 * List of all existing connections
+	 * 
+	 * @return the connections ArrayList
 	 */
 	public ArrayList<CpsEdge> getConnections() {
 		return connections;
 	}
 
 	/**
+	 * Set a new ArrayList of connections (Update)
+	 * 
 	 * @param arrayList
 	 *            the connections to set
 	 */
@@ -104,24 +158,52 @@ public abstract class CpsObject {
 		this.connections = arrayList;
 	}
 
-	/* Neighbors array */
+	/**
+	 * List of all existing connections
+	 * 
+	 * @return the connections ArrayList
+	 */
 	public ArrayList<CpsEdge> getConnectedTo() {
 		return connections;
 	}
 
+	/**
+	 * Add a new connection to the selected Object
+	 * 
+	 * @param toConnect
+	 *            Edge
+	 */
 	public void AddConnection(CpsEdge toConnect) {
 		connections.add(toConnect);
 	}
 
+	/**
+	 * Set the position of the Object in the canvas
+	 * 
+	 * @param pos
+	 *            Coordinates
+	 */
 	public void setPosition(Position pos) {
 		this.position = pos;
 	}
 
-	/* Position (x and Y) */
+	/**
+	 * Set the position of the Object in the canvas
+	 * 
+	 * @param x
+	 *            X-Coord
+	 * @param y
+	 *            Y-Coord
+	 */
 	public void setPosition(int x, int y) {
 		setPosition(new Position(x, y));
 	}
 
+	/**
+	 * Get the actual position of the Object
+	 * 
+	 * @return
+	 */
 	public Position getPosition() {
 		return position;
 	}
@@ -142,6 +224,8 @@ public abstract class CpsObject {
 	}
 
 	/**
+	 * Get the color of the border
+	 * 
 	 * @return the BorderColor
 	 */
 	public Color getBorderColor() {
@@ -151,13 +235,16 @@ public abstract class CpsObject {
 	/**
 	 * Set the Border Color of this CpsObject
 	 * 
-	 * @param the BorderColor
+	 * @param the
+	 *            BorderColor
 	 */
 	public void setBorderColor(Color c) {
 		this.BorderColor = c;
 	}
 
 	/**
+	 * Set the Color of the edges
+	 * 
 	 * @param Color
 	 *            the Color to set
 	 */
@@ -165,14 +252,27 @@ public abstract class CpsObject {
 		this.BorderColor = color;
 	}
 
+	/**
+	 * For internal purpose (energy flow)
+	 * 
+	 * @param tag
+	 */
 	public void addTag(int tag) {
 		this.tags.add(tag);
 	}
 
+	/**
+	 * Get the actual tags
+	 * 
+	 * @return ArrayList
+	 */
 	public ArrayList<Integer> getTag() {
 		return tags;
 	}
 
+	/**
+	 * Rest the tags to Null
+	 */
 	public void resetTags() {
 		this.tags = new ArrayList<Integer>();
 	}

+ 100 - 15
src/classes/HolonElement.java

@@ -4,35 +4,54 @@ import java.awt.Point;
 import java.util.LinkedList;
 import ui.model.idCounterElem;
 
+/**
+ * The class "HolonElement" represents any possible element that can be added to
+ * a CpsObject (such as TV (consumer) or any energy source/producer)
+ * 
+ * @author Gruppe14
+ *
+ */
 public class HolonElement {
 
 	/* Name of the gadget */
-	String eleName;
+	private String eleName;
 	/* Quantity */
-	int amount;
+	private int amount;
 	/* Energy per gadget */
-	float energy;
+	private float energy;
 	/* If the gadget is working xor not (true xor false) */
-	boolean active;
+	private boolean active;
 	/* Total Energy */
-	float totalEnergy;
+	private float totalEnergy;
 	/* Path of the image for the Obj. */
-	String image;
+	private String image;
 	/* +: for Consumers and -: Producers */
-	char sign;
+	private char sign;
 	/* Place where the Object is Stored */
-	String sav;
+	private String sav;
 	/* Object where the Element is Stored */
-	String obj;
-	int id;
+	private String obj;
+	/* Unique Id of the Element */
+	private int id;
 	/*
 	 * Energy at each point of the graph with 100 predefined points. At the
 	 * beginning, it starts with all values at energy
 	 */
-	float[] energyAt = new float[100];
+	private float[] energyAt = new float[100];
 	// Points on the UnitGraph
 	LinkedList<Point> graphPoints = new LinkedList<>();
 
+	/**
+	 * Create a new HolonElement with a user-defined name, amount of the same
+	 * element and energy per element
+	 * 
+	 * @param eleName
+	 *            String
+	 * @param amount
+	 *            int
+	 * @param energy
+	 *            float
+	 */
 	public HolonElement(String eleName, int amount, float energy) {
 		setEleName(eleName);
 		setAmount(amount);
@@ -40,9 +59,14 @@ public class HolonElement {
 		setActive(true);
 		setSign(energy);
 		setEnergyAt(energy);
-		setId(idCounterElem.nextId());
+		// setId(idCounterElem.nextId());
 	}
 
+	/**
+	 * Create a copy of the HolonElement given each one a new ID
+	 * 
+	 * @param element
+	 */
 	public HolonElement(HolonElement element) {
 		setEleName(element.getEleName());
 		setAmount(element.getAmount());
@@ -56,13 +80,17 @@ public class HolonElement {
 	}
 
 	/**
-	 * get the EnergyAt Array
+	 * Get the Array of energy (100 values)
+	 * 
+	 * @return Array of floats
 	 */
 	public float[] getEnergyAt() {
 		return energyAt;
 	}
 
 	/**
+	 * Set energy to any value to the whole array
+	 * 
 	 * @param energy,
 	 *            the value
 	 */
@@ -72,18 +100,30 @@ public class HolonElement {
 		}
 	}
 
+	/**
+	 * Set energy to any value at a given position
+	 * 
+	 * @param pos
+	 *            int
+	 * @param energy
+	 *            float
+	 */
 	public void setEnergyAt(int pos, float energy) {
 		this.energyAt[pos] = energy;
 	}
 
 	/**
-	 * @return the name
+	 * Get the user-defined Name
+	 * 
+	 * @return the name String
 	 */
 	public String getEleName() {
 		return eleName;
 	}
 
 	/**
+	 * Set the name to any new name
+	 * 
 	 * @param name
 	 *            the name to set
 	 */
@@ -92,13 +132,17 @@ public class HolonElement {
 	}
 
 	/**
-	 * @return the amount
+	 * Get the actual amount of Elements in the selected Object
+	 * 
+	 * @return the amount int
 	 */
 	public int getAmount() {
 		return amount;
 	}
 
 	/**
+	 * Set the amount of the Element in the selected Object
+	 * 
 	 * @param amount
 	 *            the amount to set
 	 */
@@ -107,6 +151,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Get the energy value of the selected Element
+	 * 
 	 * @return the energy
 	 */
 	public float getEnergy() {
@@ -114,6 +160,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Set the energy value of the selected Element
+	 * 
 	 * @param energy
 	 *            the energy to set
 	 */
@@ -122,6 +170,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Get the Status of the Element (see description of variables)
+	 * 
 	 * @return the active
 	 */
 	public boolean getActive() {
@@ -129,6 +179,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Set the Status of the Element (see description of variables)
+	 * 
 	 * @param active
 	 *            the active to set
 	 */
@@ -137,6 +189,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Get Image path
+	 * 
 	 * @return the image
 	 */
 	public String getImage() {
@@ -144,6 +198,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Set Image path
+	 * 
 	 * @param image
 	 *            the image to set
 	 */
@@ -163,12 +219,21 @@ public class HolonElement {
 		return totalEnergy;
 	}
 
+	/**
+	 * Get the energy value at a selected time x
+	 * 
+	 * @param x
+	 *            int
+	 * @return energy value
+	 */
 	public float getTotalEnergyAtTimeStep(int x) {
 		float result = ((float) amount) * energyAt[x];
 		return result;
 	}
 
 	/**
+	 * Get the symbol of the value (see variable description)
+	 * 
 	 * @return the sign
 	 */
 	public char getSign() {
@@ -176,6 +241,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Set symbol of the value
+	 * 
 	 * @param energy
 	 *            the sign to set
 	 */
@@ -202,6 +269,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Get the actual object
+	 * 
 	 * @return the obj
 	 */
 	public String getObj() {
@@ -209,6 +278,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Set the object to a new one
+	 * 
 	 * @param obj
 	 *            the obj to set
 	 */
@@ -217,6 +288,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Get the points (values) in the graph
+	 * 
 	 * @return the Graph Points
 	 */
 	public LinkedList<Point> getGraphPoints() {
@@ -224,6 +297,8 @@ public class HolonElement {
 	}
 
 	/**
+	 * Set the points (values) in the graph
+	 * 
 	 * @param points,
 	 *            the Graph points
 	 */
@@ -231,10 +306,20 @@ public class HolonElement {
 		this.graphPoints = points;
 	}
 
+	/**
+	 * Set the ID of the HolonElement (one time only)
+	 * 
+	 * @param id
+	 */
 	private void setId(int id) {
 		this.id = id;
 	}
 
+	/**
+	 * Get the Id of the selected HolonElement
+	 * 
+	 * @return
+	 */
 	public int getId() {
 		return id;
 	}