Jelajahi Sumber

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

Teh-Hai Julian Zheng 8 tahun lalu
induk
melakukan
d73cfaee2b
51 mengubah file dengan 2749 tambahan dan 436 penghapusan
  1. 3 0
      .classpath
  2. 1 0
      .gitignore
  3. TEMPAT SAMPAH
      res/Images/Dummy_House.png
  4. TEMPAT SAMPAH
      res/Images/Dummy_PowerPlant.png
  5. TEMPAT SAMPAH
      res/Images/Dummy_Switch.png
  6. TEMPAT SAMPAH
      res/Images/Dummy_Transformator.png
  7. TEMPAT SAMPAH
      res/Images/Thumbs.db
  8. TEMPAT SAMPAH
      res/Images/factory-1.png
  9. TEMPAT SAMPAH
      res/Images/factory.png
  10. TEMPAT SAMPAH
      res/Images/folder.png
  11. TEMPAT SAMPAH
      res/Images/home-1.png
  12. TEMPAT SAMPAH
      res/Images/home-2.png
  13. TEMPAT SAMPAH
      res/Images/home.png
  14. TEMPAT SAMPAH
      res/Images/house.png
  15. TEMPAT SAMPAH
      res/Images/power-plant.png
  16. TEMPAT SAMPAH
      res/Images/powerplant-1.png
  17. TEMPAT SAMPAH
      res/Images/switch-1.png
  18. TEMPAT SAMPAH
      res/Images/switch-off.png
  19. TEMPAT SAMPAH
      res/Images/switch-on.png
  20. TEMPAT SAMPAH
      res/Images/transformer-1.png
  21. TEMPAT SAMPAH
      res/Images/transformer.png
  22. 9 0
      src/Interfaces/CategoryListener.java
  23. 6 0
      src/Interfaces/ComparableObject.java
  24. 7 0
      src/Interfaces/ObjectListener.java
  25. 68 0
      src/classes/Category.java
  26. 146 0
      src/classes/CpsObject.java
  27. 141 0
      src/classes/HolonElement.java
  28. 112 0
      src/classes/HolonObject.java
  29. 39 0
      src/classes/HolonSwitch.java
  30. 13 3
      src/classes/HolonTransformer.java
  31. 17 0
      src/classes/Position.java
  32. 7 7
      src/tests/Tests1.java
  33. 20 0
      src/tests/praktikumHolonsTestMinimal.java
  34. 54 0
      src/ui/controller/CanvasController.java
  35. 252 0
      src/ui/controller/CategoryController.java
  36. 129 0
      src/ui/controller/Control.java
  37. 0 98
      src/ui/controller/CpsObject.java
  38. 40 0
      src/ui/controller/GlobalController.java
  39. 0 68
      src/ui/controller/HolonElement.java
  40. 0 49
      src/ui/controller/HolonObject.java
  41. 0 20
      src/ui/controller/HolonSwitch.java
  42. 203 0
      src/ui/controller/ObjectController.java
  43. 159 13
      src/ui/model/Model.java
  44. 3 2
      src/ui/model/idCounter.java
  45. 22 0
      src/ui/model/tests.java
  46. 37 0
      src/ui/view/AboutUsPopUp.java
  47. 152 0
      src/ui/view/AddElementPopUp.java
  48. 307 0
      src/ui/view/AddObjectPopUp.java
  49. 468 136
      src/ui/view/GUI.java
  50. 42 0
      src/ui/view/Main.java
  51. 292 40
      src/ui/view/MyCanvas.java

+ 3 - 0
.classpath

@@ -1,6 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="res"/>
+	<classpathentry excluding="src/|res/" kind="src" path=""/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

+ 1 - 0
.gitignore

@@ -0,0 +1 @@
+bin/

TEMPAT SAMPAH
res/Images/Dummy_House.png


TEMPAT SAMPAH
res/Images/Dummy_PowerPlant.png


TEMPAT SAMPAH
res/Images/Dummy_Switch.png


TEMPAT SAMPAH
res/Images/Dummy_Transformator.png


TEMPAT SAMPAH
res/Images/Thumbs.db


TEMPAT SAMPAH
res/Images/factory-1.png


TEMPAT SAMPAH
res/Images/factory.png


TEMPAT SAMPAH
res/Images/folder.png


TEMPAT SAMPAH
res/Images/home-1.png


TEMPAT SAMPAH
res/Images/home-2.png


TEMPAT SAMPAH
res/Images/home.png


TEMPAT SAMPAH
res/Images/house.png


TEMPAT SAMPAH
res/Images/power-plant.png


TEMPAT SAMPAH
res/Images/powerplant-1.png


TEMPAT SAMPAH
res/Images/switch-1.png


TEMPAT SAMPAH
res/Images/switch-off.png


TEMPAT SAMPAH
res/Images/switch-on.png


TEMPAT SAMPAH
res/Images/transformer-1.png


TEMPAT SAMPAH
res/Images/transformer.png


+ 9 - 0
src/Interfaces/CategoryListener.java

@@ -0,0 +1,9 @@
+package Interfaces;
+
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Locale.Category;
+
+public interface CategoryListener {
+	public void onChange(ArrayList<classes.Category> categories);
+}

+ 6 - 0
src/Interfaces/ComparableObject.java

@@ -0,0 +1,6 @@
+package Interfaces;
+
+public interface ComparableObject {
+	public String getCompareName();
+	public int getID();
+}

+ 7 - 0
src/Interfaces/ObjectListener.java

@@ -0,0 +1,7 @@
+package Interfaces;
+
+import java.util.ArrayList;
+
+public interface ObjectListener {
+	public void onChange(ArrayList<classes.CpsObject> objects);
+}

+ 68 - 0
src/classes/Category.java

@@ -0,0 +1,68 @@
+package classes;
+
+import java.util.ArrayList;
+
+import Interfaces.ComparableObject;
+
+public class Category implements ComparableObject{
+	
+	private int ID;
+	private ArrayList<CpsObject> objects;
+	private String name;
+	
+	public Category(String name){
+		setObjects(new ArrayList<CpsObject>());
+		setName(name);
+		setID(-1);
+	
+	}
+
+	/**
+	 * @return the id
+	 */
+	public int getID() {
+		return ID;
+	}
+
+	/**
+	 * @param id the id to set
+	 */
+	public void setID(int id) {
+		this.ID = id;
+	}
+
+	/**
+	 * @return the objects
+	 */
+	public ArrayList<CpsObject> getObjects() {
+		return objects;
+	}
+
+	/**
+	 * @param objects the objects to set
+	 */
+	public void setObjects(ArrayList<CpsObject> objects) {
+		this.objects = objects;
+	}
+
+	/**
+	 * @return the name
+	 */
+	public String getName() {
+		return name;
+	}
+
+	/**
+	 * @param name the name to set
+	 */
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	@Override
+	public String getCompareName() {
+		return getName();
+	}
+
+	
+}

+ 146 - 0
src/classes/CpsObject.java

@@ -0,0 +1,146 @@
+package classes;
+
+import java.util.ArrayList;
+
+import Interfaces.ComparableObject;
+import ui.model.idCounter;
+
+public abstract class CpsObject implements ComparableObject {
+	/* Type of the Object */
+	String objName;
+	/* Name given by the user */
+	String name;
+	/* ID of the Obj. */
+	int ID;
+	/* Path of the image for the Obj. */
+	String image;
+	/* Array of neighbors */
+	ArrayList<CpsObject> connections;
+	/* Position with a X and Y value */
+	Position position;
+	/* Energy input and output of each object in the grid */
+	float energyIn;
+	float energyOut;
+
+	/**
+	 * Constructor for an CpsObejct with an unique ID
+	 */
+	public CpsObject(String objName) {
+		setObjName(objName);
+		setName(objName);
+		setConnections(new ArrayList<CpsObject>());
+		setPosition(new Position());
+		setImage("/Images/Dummy_House.png");
+	}
+
+	public CpsObject(CpsObject obj) {
+		setObjName(obj.getObjName());
+		setName(obj.getObjName());
+		setConnections(new ArrayList<CpsObject>());
+		setPosition(new Position());
+		setID(idCounter.nextId());
+		setEnergyIn(obj.getEnergyIn());
+		setEnergyOut(obj.getEnergyOut());
+		setImage(obj.getImage());
+	}
+
+	/* Obj type */
+	public String getObjName() {
+		return objName;
+	}
+
+	public void setObjName(String objName) {
+		this.objName = objName;
+	}
+
+	/* User defined Name */
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	/* Unique ID number */
+	public int getID() {
+		return ID;
+	}
+
+	/**
+	 * @param iD
+	 *            the iD to set
+	 */
+	public void setID(int ID) {
+		this.ID = ID;
+	}
+
+	/* Image path */
+	public String getImage() {
+		return image;
+	}
+
+	public void setImage(String image) {
+		this.image = image;
+	}
+
+	/**
+	 * @return the connections
+	 */
+	public ArrayList<CpsObject> getConnections() {
+		return connections;
+	}
+
+	/**
+	 * @param connections
+	 *            the connections to set
+	 */
+	public void setConnections(ArrayList<CpsObject> connections) {
+		this.connections = connections;
+	}
+
+	/* Neighbors array */
+	public ArrayList<CpsObject> getConnectedTo() {
+		return connections;
+	}
+
+	public void AddConnection(CpsObject toConnect) {
+		connections.add(toConnect);
+	}
+
+	public void setPosition(Position pos) {
+		this.position = pos;
+	}
+
+	/* Position (x and Y) */
+	public void setPosition(int x, int y) {
+		setPosition(new Position(x, y));
+	}
+
+	public Position getPosition() {
+		return position;
+	}
+
+	/* Getter and Setters for the energy input and output */
+	public float getEnergyIn() {
+		return energyIn;
+	}
+
+	public void setEnergyIn(float energyIn) {
+		this.energyIn = energyIn;
+	}
+
+	public float getEnergyOut() {
+		return energyOut;
+	}
+
+	public void setEnergyOut(float energyOut) {
+		this.energyOut = energyOut;
+	}
+
+	@Override
+	public String getCompareName() {
+		return objName;
+	}
+
+}

+ 141 - 0
src/classes/HolonElement.java

@@ -0,0 +1,141 @@
+package classes;
+
+public class HolonElement {
+
+	/* Name of the gadget */
+	String eleName;
+	/* Quantity */
+	int amount;
+	/* Energy per gadget */
+	float energy;
+	/* If the gadget is working xor not (true xor false) */
+	boolean active;
+	/* Total Energy */
+	float totalEnergy;
+	/* Path of the image for the Obj. */
+	String image;
+	/* +: for Consumers and -: Producers */
+	char sign;
+
+	public HolonElement(String eleName, float energy, int amount) {
+		setEleName(eleName);
+		setAmount(amount);
+		setEnergy(energy);
+		setActive(true);
+		setSign(energy);
+	}
+	
+	public HolonElement(HolonElement h) {
+		setEleName(h.getEleName());
+		setAmount(h.getAmount());
+		setEnergy(h.getEnergy());
+		setActive(h.getActive());
+		setSign(h.getEnergy());
+	}
+
+	/**
+	 * @return the name
+	 */
+	public String getEleName() {
+		return eleName;
+	}
+
+	/**
+	 * @param name
+	 *            the name to set
+	 */
+	public void setEleName(String name) {
+		this.eleName = name;
+	}
+
+	/**
+	 * @return the amount
+	 */
+	public int getAmount() {
+		return amount;
+	}
+
+	/**
+	 * @param amount
+	 *            the amount to set
+	 */
+	public void setAmount(int amount) {
+		this.amount = amount;
+	}
+
+	/**
+	 * @return the energy
+	 */
+	public float getEnergy() {
+		return energy;
+	}
+
+	/**
+	 * @param energy
+	 *            the energy to set
+	 */
+	public void setEnergy(float energy) {
+		this.energy = energy;
+	}
+
+	/**
+	 * @return the active
+	 */
+	public boolean getActive() {
+		return active;
+	}
+
+	/**
+	 * @param active
+	 *            the active to set
+	 */
+	public void setActive(boolean active) {
+		this.active = active;
+	}
+
+	/**
+	 * @return the image
+	 */
+	public String getImage() {
+		return image;
+	}
+
+	/**
+	 * @param image
+	 *            the image to set
+	 */
+	public void setImage(String image) {
+		this.image = image;
+	}
+
+	/**
+	 * Multiply the amount of gadgets, given by the user, and the
+	 * consumption/production. If the switch isWorking is turned off for on
+	 * gadget, the energy of this gadget have to be subtracted
+	 * 
+	 * @return totalEnergy (actual)
+	 */
+	public float getTotalEnergy() {
+		totalEnergy = ((float) amount) * energy;
+		return totalEnergy;
+	}
+
+	/**
+	 * @return the sign
+	 */
+	public char getSign() {
+		return sign;
+	}
+
+	/**
+	 * @param energy
+	 *            the sign to set
+	 */
+	public void setSign(float energy) {
+		if (energy < 0)
+			this.sign = '-';
+		else
+			this.sign = '+';
+	}
+
+}

+ 112 - 0
src/classes/HolonObject.java

@@ -0,0 +1,112 @@
+package classes;
+
+import java.util.ArrayList;
+
+public class HolonObject extends CpsObject {
+
+	/* Array of all consumers */
+	private ArrayList<HolonElement> elements;
+	/* Total of consumption */
+	private float currentEnergy;
+	/**
+	 * State of the building: 0 = fully supplied (currentEnergy == 0) 1 = not
+	 * enough energy (currentEnergy > 0) 2 = oversupplied (currentEnergy < 0)
+	 */
+	int state;
+
+	/**
+	 * Constructor Set by default the name of the object equals to the category
+	 * name, until the user changes it.
+	 */
+	public HolonObject(String ObjName) {
+		super(ObjName);
+		setElements(new ArrayList<HolonElement>());
+	}
+
+	public HolonObject(String ObjName, String obj) {
+		super(ObjName);
+		super.setName(obj);
+		setElements(new ArrayList<HolonElement>());
+	}
+
+	public HolonObject(CpsObject obj) {
+		super(obj);
+		setElements(((HolonObject) obj).getCopyofElements());
+	}
+
+	/**
+	 * @return the elements
+	 */
+	public ArrayList<HolonElement> getElements() {
+		return elements;
+	}
+
+	/**
+	 * @param elements
+	 *            the elements to set
+	 */
+	public void setElements(ArrayList<HolonElement> elements) {
+		this.elements = elements;
+	}
+
+	/**
+	 * @return the currentEnergy
+	 */
+	public float getCurrentEnergy() {
+		return currentEnergy;
+	}
+
+	/**
+	 * @param currentEnergy
+	 *            the currentEnergy to set
+	 */
+	public void setCurrentEnergy(float currentEnergy) {
+		this.currentEnergy = currentEnergy;
+	}
+
+	/**
+	 * deletes Element
+	 * 
+	 * @param idx
+	 */
+	public void deleteElement(int idx) {
+		elements.remove(idx);
+	}
+
+	public float calculateCurrentEnergy() {
+		return currentEnergy;
+	}
+
+	/**
+	 * String of all consumers in this HolonObject
+	 * 
+	 * @return all the names of this HolonObject separated by "," each object
+	 */
+	public String toStringElements() {
+		String objString = "Empty";
+		for (HolonElement e : elements) {
+			if (objString == "Empty") {
+				objString = e.getEleName();
+			} else {
+				objString = objString + ", " + e.getEleName();
+			}
+		}
+		return objString;
+	}
+	
+	/**
+	 * Copys the ArrayList
+	 * 
+	 * @param the ArrayList to Copy
+	 * 
+	 * @return the currentEnergy
+	 */
+	public ArrayList<HolonElement> getCopyofElements() {
+		ArrayList<HolonElement> temp = new ArrayList<>();
+		for (HolonElement h : elements) {
+			HolonElement he = new HolonElement(h);
+			temp.add(he);
+		}
+		return temp;
+	}
+}

+ 39 - 0
src/classes/HolonSwitch.java

@@ -0,0 +1,39 @@
+package classes;
+
+public class HolonSwitch extends CpsObject {
+	/*
+	 * True, if this wire is working (capable of carrying electricity), else
+	 * false
+	 */
+	
+	
+	boolean active;
+
+	public HolonSwitch(String ObjName) {
+		super(ObjName);
+		setState(false);
+	}
+
+	public HolonSwitch(String ObjName, String obj) {
+		super(ObjName);
+		super.setName(obj);
+		setState(false);
+	}
+
+	public HolonSwitch(CpsObject obj) {
+		super(obj);
+		setState(((HolonSwitch)obj).getState());
+	}
+
+	public void switchState() {
+		this.active = !active;
+	}
+
+	public boolean getState() {
+		return this.active;
+	}
+	
+	public void setState(boolean state){
+		this.active = state;
+	}
+}

+ 13 - 3
src/ui/controller/HolonTransformer.java → src/classes/HolonTransformer.java

@@ -1,4 +1,4 @@
-package ui.controller;
+package classes;
 
 public class HolonTransformer extends CpsObject {
 
@@ -9,8 +9,18 @@ public class HolonTransformer extends CpsObject {
 	 * Constructor Set type of object (Transformer), its transform ratio and the
 	 * default name ("Transformer");
 	 */
-	public HolonTransformer() {
-		super();
+	public HolonTransformer(String ObjName) {
+		super(ObjName);
+	}
+
+	public HolonTransformer(String ObjName, String obj) {
+		super(ObjName);
+		super.setName(obj);
+	}
+
+	public HolonTransformer(CpsObject obj) {
+		super(obj);
+		this.setTransformRatio(((HolonTransformer) obj).getTransformRatio());
 	}
 
 	/**

+ 17 - 0
src/classes/Position.java

@@ -0,0 +1,17 @@
+package classes;
+
+public class Position {
+	public int x;
+	public int y;
+	
+	public Position(int x, int y){
+		this.x = x;
+		this.y = y;
+	}
+	
+	//default Constructor
+	public Position(){
+		this.x = -1;
+		this.y = -1;
+	}
+}

+ 7 - 7
src/tests/Tests1.java

@@ -12,12 +12,12 @@ public class Tests1 {
 	 * Create some CPS object and Gadgets
 	 */
 	public static void main(String[] args) {
-		HolonObject b1 = new HolonObject();
-		HolonObject b2 = new HolonObject();
-		HolonSwitch s1 = new HolonSwitch();
-		HolonTransformer t1 = new HolonTransformer();
-		b1.setPos(20, 30);
-		Position p = b1.getPos();
-		System.out.println(p.x + "," + p.y);
+		// HolonObject b1 = new HolonObject();
+		// HolonObject b2 = new HolonObject();
+		// HolonSwitch s1 = new HolonSwitch();
+		// HolonTransformer t1 = new HolonTransformer();
+		// b1.setPos(20, 30);
+		// Position p = b1.getPos();
+		// System.out.println(p.x + "," + p.y);
 	}
 }

+ 20 - 0
src/tests/praktikumHolonsTestMinimal.java

@@ -0,0 +1,20 @@
+package tests;
+
+import static org.junit.Assert.*;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class praktikumHolonsTestMinimal {
+
+	
+	@Before
+	public void setup(){
+		
+	}
+	
+	//@Test
+	
+
+
+}

+ 54 - 0
src/ui/controller/CanvasController.java

@@ -0,0 +1,54 @@
+package ui.controller;
+
+import Interfaces.CategoryListener;
+import Interfaces.ObjectListener;
+import classes.CpsObject;
+import ui.model.Model;
+
+public class CanvasController {
+
+	private Model MODEL;
+
+	public CanvasController(Model model) {
+		this.MODEL = model;
+	}
+
+	/**
+	 * Add an CpsObject to the model and notify the ObjectListener for update.
+	 * 
+	 * @param object
+	 *            CpsObject to be added.
+	 */
+	public void addObjectIntoCanvas(CpsObject object) {
+		String objName = object.getObjName();
+		MODEL.getObjectsOnCanvas().add(object);
+		notifyObjListeners();
+		System.out.println("Added: " + objName);
+	}
+	
+	public void addObjectListener(ObjectListener objLis) {
+		MODEL.getObjectListeners().add(objLis);
+	}
+
+	/**
+	 * notifies all listeners about changes in the Canvas
+	 */
+	public void notifyObjListeners() {
+		for (ObjectListener l : MODEL.getObjectListeners()) {
+			l.onChange(MODEL.getObjectsOnCanvas());
+		}
+	}
+	
+	/**
+	 * Deletes an CpsObject on the Canvas and its connections
+	 * 
+	 * @param CpsObject
+	 */
+	public void deleteObjectOnCanvas(CpsObject obj) {
+		for (CpsObject cps : MODEL.getObjectsOnCanvas()) {
+			cps.getConnectedTo().remove(obj);
+		}
+		MODEL.getObjectsOnCanvas().remove(obj);
+	}
+
+}

+ 252 - 0
src/ui/controller/CategoryController.java

@@ -0,0 +1,252 @@
+package ui.controller;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+
+import classes.Category;
+import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
+import classes.HolonSwitch;
+import classes.HolonTransformer;
+
+import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
+
+import Interfaces.CategoryListener;
+import Interfaces.ComparableObject;
+import ui.model.*;
+import ui.view.*;
+
+public class CategoryController {
+	private Model MODEL;
+
+	public CategoryController(Model model) {
+		this.MODEL = model;
+		initCategories();
+	}
+
+	/**
+	 * init default category and objects
+	 */
+	public void initCategories() {
+		Category energy = new Category("Energy");
+		Category building = new Category("Building");
+		Category component = new Category("Component");
+
+		HolonObject powerp = new HolonObject("Power Plant");
+		powerp.setImage("/Images/power-plant.png");
+		HolonObject house = new HolonObject("House");
+		house.setImage("/Images/home.png");
+
+		System.out.println(house.toString());
+		HolonTransformer transformer = new HolonTransformer("Transformer");
+		transformer.setImage("/Images/transformer.png");
+		HolonSwitch sw = new HolonSwitch("Switch");
+		sw.setImage("/Images/switch-on.png");
+
+		addObject(energy, powerp);
+		addObject(building, house);
+		addObject(component, transformer);
+		addObject(component, sw);
+
+		addCategory(energy);
+		addCategory(building);
+		addCategory(component);
+	}
+
+	/**
+	 * Adds Category into Model if a Category with the same name already exists
+	 * Add Category_+1
+	 * 
+	 * @param toAdd
+	 *            neue Kategorie
+	 */
+	public void addCategory(Category toAdd) {
+		int number = 0;
+		String name = toAdd.getName();
+		while (containsInList(MODEL.getCategories(), toAdd)) {
+			number++;
+			toAdd.setName(name + "_" + number);
+		}
+		;
+		MODEL.getCategories().add(toAdd);
+		notifyCatListeners();
+	}
+
+	/**
+	 * Adds New Category into Model
+	 * 
+	 * @param name
+	 *            Bezeichnung der neuen Kategorie
+	 */
+	public void addNewCategory(String name) {
+
+		addCategory(new Category(name));
+	}
+
+	/**
+	 * deletes category with given name
+	 * 
+	 * @param catName
+	 * @return true if successfull, otherwise false
+	 */
+	public boolean deleteCategory(String catName) {
+		int position = getPositionInList(MODEL.getCategories(), searchCatNode(catName));
+		if (position != -1) {
+			deleteCategoryAt(position);
+			return true;
+		} else
+			return false;
+
+	}
+
+	/**
+	 * deletes a Category at given position
+	 */
+	public void deleteCategoryAt(int idx) {
+		MODEL.getCategories().remove(idx);
+		notifyCatListeners();
+	}
+
+	/**
+	 * Add Object into a Category
+	 * 
+	 * @param cat
+	 *            Category
+	 * @param obj
+	 *            Object
+	 */
+	public void addObject(Category cat, CpsObject obj) {
+		cat.getObjects().add(obj);
+		notifyCatListeners();
+	}
+
+	/**
+	 * Add new Holon Object
+	 * 
+	 * @param cat
+	 *            Category
+	 * @param obj
+	 *            New Object Name
+	 */
+	public void addNewHolonObject(Category cat, String objName, ArrayList<HolonElement> elements, String image) {
+		HolonObject object = new HolonObject(objName);
+		object.setImage(image);
+		object.setElements(elements);
+		addObject(cat, object);
+	}
+
+	/**
+	 * Add new Holon Transformer
+	 * 
+	 * @param cat
+	 *            Category
+	 * @param obj
+	 *            New Object Name
+	 */
+	public void addNewHolonTransformer(Category cat, String objName, String image) {
+		HolonTransformer transformer = new HolonTransformer(objName);
+		transformer.setImage(image);
+		addObject(cat, transformer);
+	}
+
+	/**
+	 * Add new Holon Switch
+	 * 
+	 * @param cat
+	 *            Category
+	 * @param obj
+	 *            New Object Name
+	 */
+	public void addNewHolonSwitch(Category cat, String objName, String image) {
+		HolonSwitch holonSwitch = new HolonSwitch(objName);
+		holonSwitch.setImage(image);
+		addObject(cat, holonSwitch);
+	}
+
+	/**
+	 * deletes given Object in given Category
+	 * 
+	 * @param toDelete
+	 * @param deleteIn
+	 */
+	public void deleteObjectInCat(String toDelete, String deleteIn) {
+		Category cat = searchCatNode(deleteIn);
+		print(cat.getObjects());
+		for (int i = 0; i < cat.getObjects().size(); i++) {
+			if (cat.getObjects().get(i).getCompareName().equals(toDelete)) {
+				cat.getObjects().remove(i);
+				cat.getObjects();
+				notifyCatListeners();
+			}
+		}
+
+	}
+
+	public void print(ArrayList<CpsObject> iterate) {
+		for (CpsObject cps : iterate) {
+			System.out.println(cps.getCompareName());
+		}
+	}
+
+	/**
+	 * 
+	 * @param catLis
+	 */
+	public void addCategoryListener(CategoryListener catLis) {
+		MODEL.getCategoryListeners().add(catLis);
+	}
+
+	/**
+	 * notifies all listeners about changes in the Categories
+	 */
+	public void notifyCatListeners() {
+		for (CategoryListener l : MODEL.getCategoryListeners()) {
+			l.onChange(MODEL.getCategories());
+		}
+	}
+
+	/**
+	 * search for category
+	 * 
+	 * @param name
+	 * @return
+	 */
+	public Category searchCatNode(String name) {
+		Category query = null;
+
+		for (Category cat : MODEL.getCategories()) {
+			if (cat.getName().equals(name)) {
+				query = cat;
+				break;
+			}
+		}
+		return query;
+	}
+
+	/**
+	 * gets the position of an object in the array
+	 * 
+	 * @param arrayList
+	 * @param toSearch
+	 * @return -1 if object is not in the array, otherwise the index
+	 */
+	public int getPositionInList(ArrayList<? extends ComparableObject> arrayList, ComparableObject toSearch) {
+		for (int i = 0; i < arrayList.size(); i++) {
+			if (arrayList.get(i).getCompareName() == toSearch.getCompareName()) {
+				return i;
+			}
+		}
+		return -1;
+	}
+
+	public boolean containsInList(ArrayList<? extends ComparableObject> arrayList, ComparableObject toSearch) {
+		for (ComparableObject obj : arrayList) {
+			if (obj.getCompareName().equals(toSearch.getCompareName())) {
+				return true;
+			}
+		}
+		return false;
+	}
+
+}

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

@@ -0,0 +1,129 @@
+package ui.controller;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.LinkedList;
+
+import classes.Category;
+import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
+import Interfaces.CategoryListener;
+import ui.model.Model;
+import ui.view.GUI;
+
+public class Control {
+
+	public enum command {
+		CATEGORY, OBJECT
+	}
+
+	private Model MODEL;
+
+	private ActionListener actionListener;
+
+	private final CategoryController categoryController;
+	private final ObjectController objectController;
+	private final CanvasController canvasController;
+	private final GlobalController globalController;
+
+	public Control(Model model) {
+		this.MODEL = model;
+		this.categoryController = new CategoryController(model);
+		this.objectController = new ObjectController(model);
+		this.canvasController = new CanvasController(model);
+		this.globalController = new GlobalController(model);
+	}
+
+	/* Operations for Categories and Objects */
+	public void addCategory(String catName) {
+		categoryController.addNewCategory(catName);
+	}
+
+	public void addObject(Category cat, String objType, ArrayList<HolonElement> elements, String image) {
+		categoryController.addNewHolonObject(cat, objType, elements, image);
+	}
+
+	// public void addObjectCategory(Category cat, HolonObject object) {
+	// categoryController.addObject(cat, object);
+	// }
+
+	public void addTransformer(Category cat, String objName, String image) {
+		categoryController.addNewHolonTransformer(cat, objName, image);
+	}
+
+	public void addSwitch(Category cat, String objName, String image) {
+		categoryController.addNewHolonSwitch(cat, objName, image);
+	}
+
+	public Category searchCategory(String name) {
+		return categoryController.searchCatNode(name);
+	}
+
+	public void deleteCategory(String catName) {
+		categoryController.deleteCategory(catName);
+	}
+
+	public void delObjectCategory(String toDelete, String deleteIn) {
+		categoryController.deleteObjectInCat(toDelete, deleteIn);
+	}
+
+	/* Operations for Canvas */
+	public void addObjectCanvas(CpsObject object) {
+		canvasController.addObjectIntoCanvas(object);
+	}
+
+	public void setSelectedObjectID(int id) {
+		objectController.setSelectedObjectID(id);
+	}
+
+	public void deleteObjectOnCanvas(CpsObject obj) {
+		canvasController.deleteObjectOnCanvas(obj);
+	}
+
+	/* Operations for Objects and Elements */
+	public void addElementCanvasObject(String objName, String eleName, int amount, float energy) {
+		objectController.addNewElementIntoCanvasObject(objName, eleName, amount, energy);
+	}
+
+	public void addElementCategoryObject(String catName, String objName, String eleName, int amount, float energy) {
+		objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
+	}
+
+	public void deleteElementCanvas(int id, String element) {
+		objectController.deleteElementInCanvas(id, element);
+	}
+
+	public CpsObject searchByID(int ID){
+		return objectController.searchByID(ID);
+	}
+
+	/* Global Operations */
+	public int getScale() {
+		return globalController.getScale();
+	}
+
+	public int getScaleDiv2() {
+		return globalController.getScaleDiv2();
+	}
+
+	public void setScale(int s) {
+		globalController.setScale(s);
+	}
+
+	////////// etc
+	public void initListener(CategoryListener catLis) {
+		categoryController.addCategoryListener(catLis);
+	}
+
+	/**
+	 * Getter for Model
+	 * 
+	 * @return
+	 */
+	public Model getModel() {
+		return MODEL;
+	}
+
+}

+ 0 - 98
src/ui/controller/CpsObject.java

@@ -1,98 +0,0 @@
-package ui.controller;
-
-import java.util.ArrayList;
-
-abstract class CpsObject {
-	/* Type of the Object */
-	String objName;
-	/* Name given by the user */
-	String name;
-	/* ID of the Obj. */
-	int id;
-	/* Path of the image for the Obj. */
-	String image;
-	/* Array of neighbors */
-	ArrayList<CpsObject> connectedTo;
-	/* Position with a X and Y value */
-	Position position;
-	/*Energy input and output of each object in the grid*/
-	float energyIn;
-	float energyOut;
-	
-	/**
-	 * Constructor for an CpsObejct with an unique ID
-	 */
-	public CpsObject() {
-		connectedTo = new ArrayList<CpsObject>();
-		position = new Position();
-	}
-	
-	/* Obj type */
-	public String getObjName() {
-		return objName;
-	}
-
-	public void setObjName(String objName) {
-		this.objName = objName;
-	}
-
-	/* User defined Name */
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	/* Unique ID number */
-	public int getID() {
-		return id;
-	}
-
-	/* Image path */
-	public String getImage() {
-		return image;
-	}
-
-	public void setImage(String image) {
-		this.image = image;
-	}
-
-	/* Neighbors array */
-	public ArrayList<CpsObject> getConnectedTo() {
-		return connectedTo;
-	}
-
-	public void AddConnection(CpsObject toConnect) {
-		connectedTo.add(toConnect);
-	}
-
-	/* Position (x and Y) */
-	public void setPos(int x, int y){
-		position.x = x;
-		position.y = y;
-	}
-
-	public Position getPos(){
-		return position;
-	}
-	
-	/*Getter and Setters for the energy input and output*/
-	public float getEnergyIn() {
-		return energyIn;
-	}
-
-	public void setEnergyIn(float energyIn) {
-		this.energyIn = energyIn;
-	}
-
-	public float getEnergyOut() {
-		return energyOut;
-	}
-
-	public void setEnergyOut(float energyOut) {
-		this.energyOut = energyOut;
-	}
-
-}

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

@@ -0,0 +1,40 @@
+package ui.controller;
+
+import ui.model.Model;
+
+public class GlobalController {
+
+	private Model MODEL;
+
+	public GlobalController(Model model) {
+		this.MODEL = model;
+	}
+
+	/**
+	 * Returns SCALE
+	 * 
+	 * @return SCALE
+	 */
+	public int getScale(){
+		return MODEL.getScale();
+	}
+	
+	/**
+	 * Returns SCALE Divided by 2
+	 * 
+	 * @return SCALE Divided by 2
+	 */
+	public int getScaleDiv2(){
+		return MODEL.getScaleDiv2();
+	}
+	
+	/**
+	 * Changes the value of SCALE and SCALEDIV2
+	 * 
+	 * @param int Scale
+	 */
+	public void setScale(int s){
+		MODEL.setScale(s);
+	}
+
+}

+ 0 - 68
src/ui/controller/HolonElement.java

@@ -1,68 +0,0 @@
-package ui.controller;
-
-public class HolonElement {
-
-	/* Name of the gadget */
-	String name;
-	/* Quantity */
-	int amount;
-	/* Energy per gadget */
-	float energy;
-	/* If the gadget is working xor not (true xor false) */
-	boolean isWorking;
-	/* Total Energy */
-	float totalEnergy;
-
-	public HolonElement(String name, int amount, float energy) {
-		this.name = name;
-		this.amount = amount;
-		this.energy = energy;
-		this.isWorking = true;
-		System.out.println("You create some " + name + "'s. The amount is:" + amount);
-		System.out.println("It's actual status is: " + isWorking);
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public int getAmount() {
-		return amount;
-	}
-
-	public void setAmount(int amount) {
-		this.amount = amount;
-	}
-
-	public float getEnergy() {
-		return energy;
-	}
-
-	public void setEnergy(float energy) {
-		this.energy = energy;
-	}
-
-	public void switchGadget(boolean bool) {
-		this.isWorking = bool;
-	}
-
-	public boolean getState() {
-		return isWorking;
-	}
-
-	/**
-	 * Multiply the amount of gadgets, given by the user, and the
-	 * consumption/production. If the switch isWorking is turned off for on
-	 * gadget, the energy of this gadget have to be subtracted
-	 * 
-	 * @return totalEnergy (actual)
-	 */
-	public float getTotalEnergy() {
-		totalEnergy = ((float)amount)*energy;
-		return totalEnergy;
-	}
-}

+ 0 - 49
src/ui/controller/HolonObject.java

@@ -1,49 +0,0 @@
-package ui.controller;
-
-import java.util.ArrayList;
-
-public class HolonObject extends CpsObject {
-	
-	/*Array of all consumers*/
-	private ArrayList<HolonElement> consumers;
-	/*Array of all producers*/
-	private ArrayList<HolonElement> producers;
-	/*Total of consumption*/
-	private float currentEnergy;
-	/**
-	 * State of the building: 
-	 * 0 = fully supplied (currentEnergy == 0)
-	 * 1 = not enough energy (currentEnergy > 0)
-	 * 2 = oversupplied (currentEnergy < 0)
-	 */
-	int state;
-	
-	/**
-	 * Constructor
-	 * Set by default the name of the object equals to the category name, until the user changes it.
-	 */
-	public HolonObject() {
-		super();
-	}
-	
-	public void addConsumer(HolonElement consumer){
-		consumers.add(consumer);
-	}
-	
-	public void addProducer(HolonElement producer){
-		producers.add(producer);
-	}
-	
-	public void deleteConsumer(int idx){
-		consumers.remove(idx);
-	}
-	
-	public void deleteProducer(int idx){
-		producers.remove(idx);
-	}
-	
-	public float calculateCurrentEnergy(){
-		return currentEnergy;
-	}
-	
-}

+ 0 - 20
src/ui/controller/HolonSwitch.java

@@ -1,20 +0,0 @@
-package ui.controller;
-
-public class HolonSwitch extends CpsObject {
-	/*True, if this wire is working (capable of carrying electricity), else false*/
-	boolean isWorking;
-
-	public HolonSwitch() {
-		super();
-		isWorking = false;
-	}
-	
-	public void switchState() {
-		this.isWorking = !isWorking;
-	}
-	
-	
-	public boolean getStates() {
-		return this.isWorking;
-	}
-}

+ 203 - 0
src/ui/controller/ObjectController.java

@@ -0,0 +1,203 @@
+package ui.controller;
+
+import classes.Category;
+import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
+import ui.model.Model;
+
+import java.util.ArrayList;
+
+import Interfaces.ObjectListener;
+
+public class ObjectController {
+
+
+	private Model MODEL;
+
+	public ObjectController(Model model) {
+		this.MODEL = model;
+		initHolonElements();
+	}
+
+	/**
+	 * init default Power supply of the Power Plant
+	 */
+	public void initHolonElements() {
+		addNewElementIntoCategoryObject("Energy", "Power Plant", "Power", 1, 100);
+		addNewElementIntoCategoryObject("Energy", "Power Plant", "Zero", 10, 100);
+		addNewElementIntoCategoryObject("Energy", "Power Plant", "Rehab", 10, 100);
+		addNewElementIntoCategoryObject("Energy", "Power Plant", "The Doctor", 40, 100);
+		addNewElementIntoCategoryObject("Energy", "Power Plant", "Original", 1, 100);
+	}
+
+	/**
+	 * Adds Element into a Object
+	 */
+	public void addElement(HolonObject object, HolonElement element) {
+		object.getElements().add(element);
+	}
+
+	/**
+	 * Adds Element into a Object on the Canvas
+	 * 
+	 * @param object
+	 * @param element
+	 * @param type
+	 */
+	public void addElementIntoCanvasObject(String object, HolonElement element) {
+		addElement(searchHolonObject(object, MODEL.getObjectsOnCanvas()), element);
+	}
+
+	/**
+	 * Add a new Element into a Object on the Canvas
+	 * 
+	 * @param object
+	 * @param eleName
+	 * @param amount
+	 * @param energy
+	 * @param type
+	 */
+	public void addNewElementIntoCanvasObject(String object, String eleName, int amount, float energy) {
+		addElementIntoCanvasObject(object, new HolonElement(eleName, energy, amount));
+	}
+
+	/**
+	 * Add Element into a Object in Category
+	 * 
+	 * @param object
+	 * @param element
+	 * @param type
+	 */
+	public void addElementIntoCategoryObject(String category, String object, HolonElement element) {
+		Category cat = null;
+
+		for (Category cats : MODEL.getCategories()) {
+			if (cats.getName().equals(category)) {
+				cat = cats;
+				break;
+			}
+		}
+		addElement(searchHolonObject(object, cat.getObjects()), element);
+	}
+
+	/**
+	 * Add a new Element into a Object in Category
+	 * 
+	 * @param category
+	 * @param object
+	 * @param eleName
+	 * @param amount
+	 * @param energy
+	 * @param type
+	 */
+	public void addNewElementIntoCategoryObject(String category, String object, String eleName, int amount,
+			float energy) {
+		addElementIntoCategoryObject(category, object, new HolonElement(eleName, energy, amount));
+	}
+
+	/**
+	 * deletes a Element from a given Object
+	 * 
+	 * @param obj
+	 * @param ele
+	 */
+	public void deleteElement(HolonObject obj, HolonElement ele) {
+		obj.getElements().remove(ele);
+	}
+
+	/**
+	 * deletes a Element from a given Canvas Object
+	 * @param ID
+	 * @param ele
+	 * @param amount
+	 */
+	public void deleteElementInCanvas(int ID, String ele) {
+		HolonObject object = (HolonObject) searchByID(ID);
+		HolonElement element = searchHolonElement(object, ele);
+
+//		element.setAmount(element.getAmount() - amount);
+//
+//		if (element.getAmount() <= 0)
+			deleteElement(object, element);
+
+	}
+	
+	/**
+	 * deletes a Element from a given Category Object
+	 * @param cat
+	 * @param obj
+	 * @param ele
+	 * @param amount
+	 */
+	public void deleteElementInCategory(String cat, String obj, String ele, int amount) {
+		Category category = searchCategory(cat, MODEL.getCategories());
+		HolonObject object = searchHolonObject(obj, category.getObjects());
+		HolonElement element = searchHolonElement(object, ele);
+		
+		deleteElement(object, element);
+	}
+
+	public Category searchCategory(String category, ArrayList<Category> list) {
+		for (Category cats : list) {
+			if (cats.getName().equals(category))
+				return cats;
+		}
+		return null;
+	}
+	
+	/**
+	 * Search for Object
+	 * 
+	 * @param object
+	 * @param list
+	 * @return
+	 */
+	public HolonObject searchHolonObject(String object, ArrayList<CpsObject> list) {
+		for (CpsObject objects : list) {
+			if (objects.getObjName().equals(object))
+				return (HolonObject) objects;
+		}
+		return null;
+	}
+	
+	/**
+	 * Search for Object by ID
+	 * @param ID
+	 * @param list
+	 * @return
+	 */
+	public CpsObject searchByID(int ID){
+		for (CpsObject objects : MODEL.getObjectsOnCanvas()) {
+			if(objects.getID() == ID)
+				return objects;
+		}
+		return null;
+	}
+
+	/**
+	 * Search for Element
+	 * @param object
+	 * @param element
+	 * @return
+	 */
+	public HolonElement searchHolonElement(HolonObject object, String element) {
+
+		for (HolonElement elements : object.getElements()) {
+			if (elements.getEleName().equals(element))
+				return elements;
+		}
+		return null;
+	}
+	
+
+
+	/**
+	 * Returns the ID of the selected Object 0 = no Object is selected
+	 * 
+	 * @return ID
+	 */
+	public void setSelectedObjectID(int id) {
+		MODEL.setSelectedObjectID(id);
+	}
+}

+ 159 - 13
src/ui/model/Model.java

@@ -1,31 +1,177 @@
 package ui.model;
 
+import Interfaces.CategoryListener;
+import Interfaces.ObjectListener;
+
 import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
 
+import classes.Category;
+import classes.CpsObject;
 import ui.controller.*;
 
 public class Model {
-	private ArrayList<Category> Categories;
-	private ArrayList<HolonObject> ObjectsOnCanvas;
+
+	//Global Variables
+	public static int SCALE = 50;	//Picture Scale
+	public static int SCALE_DIV2 = SCALE/2;
+	
+	// ID of the Selected Object
+	private int selectedID = 0;
+	// eventuell wenn Canvasgröße gewählt werden kann
+	private int HEIGHT;
+	private int WIDTH;
+	/*
+	 * Array of all categories in the model. It is set by default with the
+	 * categories ENERGY, BUILDINGS and COMPONENTS
+	 */
+	private ArrayList<Category> categories;
+	/*
+	 * Array of all CpsObjects in our canvas. It is set by default as an empty
+	 * list.
+	 */
+	private ArrayList<CpsObject> objectsOnCanvas;
+
+	/*
+	 * Array for all Listeners
+	 */
+	private List<CategoryListener> categoryListeners;
+	private List<ObjectListener> objectListeners;
+	
+
+	/*
+	 * Constructor for the model. It initializes the categories and
+	 * objectsOnCanvas by default values. Listeners are also initialized by
+	 * default values.
+	 */
+	public Model() {
+		setCategories(new ArrayList<Category>());
+		setObjectsOnCanvas(new ArrayList<CpsObject>());
+		setCategoryListeners(new LinkedList<CategoryListener>());
+		setObjectListeners(new LinkedList<ObjectListener>());
+	}
+
+	/**
+	 * @return the categories
+	 */
+	public ArrayList<Category> getCategories() {
+		return categories;
+	}
+
+	/**
+	 * @param categories
+	 *            the categories to set
+	 */
+	public void setCategories(ArrayList<Category> categories) {
+		this.categories = categories;
+	}
+
+	/**
+	 * Transform the Arraylist of categories into a string of all objectName
+	 * with a separation (',') between each name
+	 * 
+	 * @return String of all names separeted by ','
+	 */
+	public String toStringCat() {
+		String text = "";
+		for (int i = 0; i < categories.size(); i++) {
+			if (text == "") {
+				text = categories.get(i).getName();
+			} else {
+				text = text + ", " + categories.get(i).getName();
+			}
+		}
+		return text;
+	}
+
+	/**
+	 * @return the objectsOnCanvas
+	 */
+	public ArrayList<CpsObject> getObjectsOnCanvas() {
+		return objectsOnCanvas;
+	}
+
+	/**
+	 * @param objectsOnCanvas
+	 *            the objectsOnCanvas to set
+	 */
+	public void setObjectsOnCanvas(ArrayList<CpsObject> objectsOnCanvas) {
+		this.objectsOnCanvas = objectsOnCanvas;
+	}
+
+	/**
+	 * @return the objectListeners
+	 */
+	public List<ObjectListener> getObjectListeners() {
+		return objectListeners;
+	}
+
+	/**
+	 * @param linkedList
+	 *            the objectListeners to set
+	 */
+	public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
+		this.objectListeners = linkedList;
+	}
+
+	/**
+	 * @return the categoryListeners
+	 */
+	public List<CategoryListener> getCategoryListeners() {
+		return categoryListeners;
+	}
+
+	/**
+	 * @param linkedList
+	 *            the categoryListeners to set
+	 */
+	public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
+		this.categoryListeners = linkedList;
+	}
 	
-	public Model(){
-		Categories = new ArrayList<Category>();
-		ObjectsOnCanvas = new ArrayList<HolonObject>();
+	/**
+	 * Set the ID of the selected Object
+	 * 0 = no Object is selected
+	 * 
+	 * @param ID
+	 * 
+	 */
+	public void setSelectedObjectID(int id){
+		this.selectedID = id;
 	}
 	
-	public void addCategory(Category toAdd){
-		Categories.add(toAdd);
+	/**
+	 * Returns the ID of the selected Object
+	 * 0 = no Object is selected
+	 * 
+	 * @return ID
+	 */
+	public int getSelectedObjectID(){
+		return selectedID;
 	}
 	
-	public void deleteCategory(int idx){
-		Categories.remove(idx);
+	/**
+	 * Returns SCALE
+	 * 
+	 * @return SCALE
+	 */
+	public int getScale(){
+		return SCALE;
 	}
 	
-	public void addObject(HolonObject toAdd){
-		ObjectsOnCanvas.add(toAdd);
+	/**
+	 * Returns SCALE_DIV2
+	 * 
+	 * @return SCALE_DIV2
+	 */
+	public int getScaleDiv2(){
+		return SCALE_DIV2;
 	}
 	
-	public void deleteObject(int idx){
-		ObjectsOnCanvas.remove(idx);
+	public void setScale(int s){
+		SCALE = s;
+		SCALE_DIV2 = SCALE/2;
 	}
+
 }

+ 3 - 2
src/ui/controller/IdCounter.java → src/ui/model/idCounter.java

@@ -1,9 +1,10 @@
-package ui.controller;
+package ui.model;
 
-public class IdCounter {
+public class idCounter {
 	private static int counter = 0;
 
 	public static synchronized int nextId() {
 		return ++counter;
+		
 	}
 }

+ 22 - 0
src/ui/model/tests.java

@@ -0,0 +1,22 @@
+package ui.model;
+
+import java.util.ArrayList;
+
+import classes.Category;
+import ui.controller.CategoryController;
+
+public class tests {
+	
+	public static void main(String[] args){
+		CategoryController cc = new CategoryController(new Model());
+		ArrayList<Category> cats = new ArrayList<Category>();
+		cats.add(new Category("sup"));
+		boolean value;
+		value = cc.containsInList(cats, new Category("sup"));
+		if(value){
+			System.out.println("true");
+		}else{
+			System.out.println("false");
+		}
+	}
+}

+ 37 - 0
src/ui/view/AboutUsPopUp.java

@@ -0,0 +1,37 @@
+package ui.view;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+public class AboutUsPopUp extends JFrame {
+	private final JPanel contentPanel = new JPanel();
+	private final JPanel contentPanel2 = new JPanel();
+	private final JPanel contentPanel3 = new JPanel();
+	private JLabel titel = new JLabel("Cyber Physical Systems");
+	private JLabel text = new JLabel("Something nice for the user :D");
+	private JLabel names_developers = new JLabel("K. Trometer, D. Rieder, T. Zheng, J. Widhalm and E. Palza");
+	private JLabel names_client = new JLabel("");
+	private JLabel name_leader = new JLabel("");
+	private JLabel credits = new JLabel();
+
+	public AboutUsPopUp() {
+		super("About Us");
+		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+		setBounds(100, 100, 500, 800);
+		getContentPane().setLayout(new BorderLayout());
+		titel.setBounds(150, 30, 100, 20);
+		Font fontTitle = new Font("Titel", 2, 35);
+		titel.setFont(fontTitle);
+		contentPanel.add(titel);
+		getContentPane().add(contentPanel, BorderLayout.NORTH);
+		contentPanel2.add(text);
+		contentPanel2.add(credits);
+		getContentPane().add(contentPanel2, BorderLayout.CENTER);
+		contentPanel3.add(names_developers);
+		getContentPane().add(contentPanel3, BorderLayout.SOUTH);
+	}
+}

+ 152 - 0
src/ui/view/AddElementPopUp.java

@@ -0,0 +1,152 @@
+package ui.view;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.FlowLayout;
+import java.util.ArrayList;
+
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JTextField;
+import javax.swing.JComboBox;
+import javax.swing.DefaultComboBoxModel;
+
+import classes.HolonElement;
+
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
+import java.awt.event.ActionEvent;
+
+public class AddElementPopUp extends JDialog {
+
+	private final JPanel contentPanel = new JPanel();
+	private JTextField elementName;
+	private JTextField providedEnergy;
+	private JTextField amount;
+	private HolonElement hl;
+
+	/**
+	 * Launch the application.
+	 */
+	public static void main(String[] args) {
+		try {
+			AddElementPopUp dialog = new AddElementPopUp();
+			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+			dialog.setVisible(true);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * Create the dialog.
+	 */
+	public AddElementPopUp() {
+		super((java.awt.Frame) null, true);
+		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
+		setBounds(100, 100, 300, 190);
+		getContentPane().setLayout(new BorderLayout());
+		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
+		getContentPane().add(contentPanel, BorderLayout.CENTER);
+		contentPanel.setLayout(null);
+		this.setTitle("Add default Element to Object");
+		
+		JLabel lblElementName = new JLabel("Element Name:");
+		lblElementName.setBounds(10, 11, 79, 14);
+		contentPanel.add(lblElementName);
+		
+		JLabel lblProvidedEnergy = new JLabel("Provided Energy:");
+		lblProvidedEnergy.setBounds(10, 49, 90, 14);
+		contentPanel.add(lblProvidedEnergy);
+		
+		JLabel lblAmount = new JLabel("Amount:");
+		lblAmount.setBounds(10, 84, 46, 14);
+		contentPanel.add(lblAmount);
+		
+		elementName = new JTextField();
+		elementName.addKeyListener(new KeyListener() {
+			@Override
+			public void keyPressed(KeyEvent arg0) {
+				// TODO Auto-generated method stub
+
+			}
+
+			@Override
+			public void keyReleased(KeyEvent e) {
+				// TODO Auto-generated method stub
+
+			}
+
+			@Override
+			public void keyTyped(KeyEvent e) {
+				elementName.setBackground(Color.WHITE);
+			}
+		});
+		elementName.setBounds(140, 8, 110, 20);
+		contentPanel.add(elementName);
+		elementName.setColumns(10);
+		
+		final JComboBox sign = new JComboBox();
+		sign.setModel(new DefaultComboBoxModel(new String[] {"+", "-"}));
+		sign.setBounds(100, 46, 33, 20);
+		contentPanel.add(sign);
+		
+		providedEnergy = new JTextField();
+		providedEnergy.setBounds(140, 46, 110, 20);
+		contentPanel.add(providedEnergy);
+		providedEnergy.setColumns(10);
+		providedEnergy.setText("0");
+		
+		amount = new JTextField();
+		amount.setBounds(140, 81, 110, 20);
+		contentPanel.add(amount);
+		amount.setColumns(10);
+		amount.setText("0");
+		{
+			JPanel buttonPane = new JPanel();
+			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
+			getContentPane().add(buttonPane, BorderLayout.SOUTH);
+			{
+				JButton okButton = new JButton("OK");
+				okButton.addActionListener(new ActionListener() {
+					public void actionPerformed(ActionEvent arg0) {
+						if(elementName.getText().length() != 0){
+							try{
+								float energy = Float.parseFloat(providedEnergy.getText().toString());
+								int elementAmount = Integer.parseInt(amount.getText().toString());
+								if(sign.getSelectedItem().toString().equals("-")){
+									energy = energy * -1;
+								}
+								hl = new HolonElement(elementName.getText().toString(), energy, elementAmount);
+								dispose();
+							} catch(NumberFormatException e){
+								JOptionPane.showMessageDialog(new JFrame(),"Please enter numbers in the Fields amount and providedEnergy");
+							}
+						}else{
+							//JOptionPane.showMessageDialog(new JFrame(), "Please enter a Name");
+							elementName.setBackground(new Color(255, 50, 50));
+						}
+					}
+				});
+				okButton.setActionCommand("OK");
+				buttonPane.add(okButton);
+				getRootPane().setDefaultButton(okButton);
+			}
+			{
+				JButton cancelButton = new JButton("Cancel");
+				cancelButton.setActionCommand("Cancel");
+				buttonPane.add(cancelButton);
+			}
+		}
+	}
+	
+	public HolonElement getElement(){
+		return hl;
+	}
+}

+ 307 - 0
src/ui/view/AddObjectPopUp.java

@@ -0,0 +1,307 @@
+package ui.view;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.FlowLayout;
+import java.awt.Image;
+import java.awt.event.*;
+import java.awt.image.ImageProducer;
+import java.io.*;
+import java.util.ArrayList;
+
+import javax.swing.DefaultListModel;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JFileChooser;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.ListModel;
+import javax.swing.ListSelectionModel;
+import javax.swing.border.EmptyBorder;
+import javax.swing.filechooser.FileNameExtensionFilter;
+import javax.swing.JLabel;
+import javax.swing.JTextField;
+import javax.swing.JList;
+import javax.swing.JOptionPane;
+import javax.swing.SwingConstants;
+
+import classes.Category;
+import classes.HolonElement;
+import classes.HolonObject;
+
+import javax.swing.JScrollBar;
+import javax.swing.ScrollPaneConstants;
+
+import ui.controller.Control;
+
+public class AddObjectPopUp extends JDialog {
+
+	private final JPanel contentPanel = new JPanel();
+	private AddElementPopUp addElement;
+	private JTextField objectName;
+	private JTextField sourcePath;
+	private ArrayList<HolonElement> hElements;
+	private DefaultListModel listModel;
+	private JList list;
+	private String imagePath;
+	private HolonObject theObject;
+	private Control controller;
+	private File selectedFile = null;
+	private String filePath = " ";
+	private String givenCategory;
+	private JLabel lblImagePreview;
+
+	/**
+	 * Launch the application.
+	 */
+	public static void main(String[] args) {
+		try {
+			AddObjectPopUp dialog = new AddObjectPopUp();
+			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+			dialog.setVisible(true);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	/**
+	 * Create the dialog.
+	 */
+	public AddObjectPopUp() {
+		setBounds(100, 100, 450, 342);
+		getContentPane().setLayout(new BorderLayout());
+		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
+		getContentPane().add(contentPanel, BorderLayout.CENTER);
+		contentPanel.setLayout(null);
+		hElements = new ArrayList<HolonElement>();
+		this.setTitle("Add Object Menu");
+		{
+			JLabel lblName = new JLabel("Name:");
+			lblName.setHorizontalAlignment(SwingConstants.CENTER);
+			lblName.setBounds(28, 21, 76, 14);
+			contentPanel.add(lblName);
+		}
+		{
+			objectName = new JTextField();
+			objectName.addKeyListener(new KeyListener() {
+				@Override
+				public void keyPressed(KeyEvent arg0) {
+					// TODO Auto-generated method stub
+
+				}
+
+				@Override
+				public void keyReleased(KeyEvent e) {
+					// TODO Auto-generated method stub
+
+				}
+
+				@Override
+				public void keyTyped(KeyEvent e) {
+					objectName.setBackground(Color.WHITE);
+				}
+			});
+			objectName.setBounds(98, 18, 172, 20);
+			contentPanel.add(objectName);
+			objectName.setColumns(10);
+		}
+		{
+			JButton btnBrowseImage = new JButton("Browse Image");
+			btnBrowseImage.setBounds(10, 75, 134, 23);
+			contentPanel.add(btnBrowseImage);
+			btnBrowseImage.addMouseListener(new MouseAdapter() {
+				public void mouseClicked(MouseEvent e) {
+					fileChooser();
+				}
+			});
+
+		}
+		{
+			sourcePath = new JTextField();
+			sourcePath.addKeyListener(new KeyListener() {
+				@Override
+				public void keyPressed(KeyEvent arg0) {
+					// TODO Auto-generated method stub
+
+				}
+
+				@Override
+				public void keyReleased(KeyEvent e) {
+					// TODO Auto-generated method stub
+
+				}
+
+				@Override
+				public void keyTyped(KeyEvent e) {
+					sourcePath.setBackground(Color.WHITE);
+				}
+			});
+			sourcePath.setBounds(148, 77, 271, 20);
+			contentPanel.add(sourcePath);
+			sourcePath.setColumns(10);
+		}
+		{
+			JButton btnAddDefaultElement = new JButton("Add Element");
+			btnAddDefaultElement.addActionListener(new ActionListener() {
+				public void actionPerformed(ActionEvent arg0) {
+					addElement = new AddElementPopUp();
+					addElement.setVisible(true);
+					HolonElement hl = addElement.getElement();
+					addElement(hl);
+				}
+			});
+
+			btnAddDefaultElement.setBounds(270, 144, 142, 23);
+			contentPanel.add(btnAddDefaultElement);
+		}
+		{
+			JScrollPane scrollPane = new JScrollPane();
+			scrollPane.setBounds(10, 114, 236, 150);
+			contentPanel.add(scrollPane);
+			{
+
+				listModel = new DefaultListModel();
+				HolonElement hel = new HolonElement("Test", 100, 5);
+				String name = hel.getEleName();
+				/*
+				 * for (int i = 0; i < 11; i++) { hel.setEleName(name + i);
+				 * addElement(hel); }
+				 */
+				list = new JList(listModel);
+				scrollPane.setViewportView(list);
+			}
+		}
+		{
+			JButton btnNewButton = new JButton("Delete Element");
+			btnNewButton.addActionListener(new ActionListener() {
+				public void actionPerformed(ActionEvent e) {
+					int selectedIndex = list.getSelectedIndex();
+					if (selectedIndex != -1) {
+						listModel.remove(selectedIndex);
+						hElements.remove(selectedIndex);
+					}
+				}
+			});
+			btnNewButton.setBounds(270, 182, 142, 27);
+			contentPanel.add(btnNewButton);
+		}
+		{
+			lblImagePreview = new JLabel("");
+			lblImagePreview.setBounds(295, 3, 50, 50);
+			contentPanel.add(lblImagePreview);
+		}
+
+		{
+			JPanel buttonPane = new JPanel();
+			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
+			getContentPane().add(buttonPane, BorderLayout.SOUTH);
+			{
+				JButton okButton = new JButton("OK");
+				okButton.addMouseListener(new MouseAdapter() {
+					public void mouseClicked(MouseEvent e) {
+						Component frame = null;
+						if (objectName.getText().length() > 0) {
+							if (sourcePath.getText().equals(filePath)) {
+								copieFile();
+								// theObject = new
+								// HolonObject(objectName.getText());
+								// theObject.setElements(hElements);
+								// theObject.setImage(imagePath);
+								controller.addObject(controller.searchCategory(givenCategory), objectName.getText(), hElements, imagePath);
+//								controller.addObjectCategory(controller.searchCategory(givenCategory), theObject);
+//								
+//								System.out.println(theObject.getImage());
+								System.out.println(givenCategory);
+								dispose();
+							} else
+								sourcePath.setBackground(new Color(255, 50, 50));
+						} else {
+							objectName.setBackground(new Color(255, 50, 50));
+							if (!sourcePath.getText().equals(filePath))
+								sourcePath.setBackground(new Color(255, 50, 50));
+
+						}
+					}
+				});
+				okButton.setActionCommand("OK");
+				buttonPane.add(okButton);
+				getRootPane().setDefaultButton(okButton);
+			}
+			{
+				JButton cancelButton = new JButton("Cancel");
+				cancelButton.setActionCommand("Cancel");
+				buttonPane.add(cancelButton);
+				cancelButton.addActionListener(new ActionListener() {
+					public void actionPerformed(ActionEvent e) {
+						dispose();
+					}
+				});
+			}
+		}
+	}
+
+	public void addElement(HolonElement hl) {
+		hElements.add(hl);
+		listModel.addElement(hl.getAmount() + "x: " + hl.getEleName() + " " + hl.getEnergy() + "U");
+	}
+
+	protected void fileChooser() {
+		// TODO Auto-generated method stub
+		JFileChooser FileChooser = new JFileChooser();
+		FileNameExtensionFilter filter = new FileNameExtensionFilter("png, jpg or jpeg", "png", "jpg", "jpeg");
+		FileChooser.setFileFilter(filter);
+		int returnValue = FileChooser.showOpenDialog(null);
+		if (returnValue == JFileChooser.APPROVE_OPTION) {
+			selectedFile = FileChooser.getSelectedFile();
+			filePath = selectedFile.getAbsolutePath();
+			sourcePath.setText(filePath);
+			// Image image = createImage((ImageProducer) selectedFile);
+			ImageIcon icon = new ImageIcon(
+					new ImageIcon(filePath).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH));
+			lblImagePreview.setIcon(icon);
+		} else {
+			System.out.println("Failed to Load");
+		}
+
+	}
+
+	protected void copieFile() {
+		InputStream inStream = null;
+		OutputStream outStream = null;
+		try {
+			File source = new File(filePath);
+			File dest = new File(System.getProperty("user.dir") + "/bin/Images/", selectedFile.getName());
+			imagePath = "/Images/" + selectedFile.getName();
+			inStream = new FileInputStream(source);
+			outStream = new FileOutputStream(dest);
+			byte[] buffer = new byte[1024];
+
+			int length;
+			while ((length = inStream.read(buffer)) > 0) {
+				outStream.write(buffer, 0, length);
+			}
+
+			if (inStream != null)
+				inStream.close();
+			if (outStream != null)
+				outStream.close();
+			System.out.println("File Copied..");
+		} catch (IOException e1) {
+			e1.printStackTrace();
+		}
+	}
+
+	public HolonObject getObject() {
+		return theObject;
+	}
+
+	public void setController(Control controller) {
+		this.controller = controller;
+	}
+
+	public void setCategory(String cat) {
+		givenCategory = cat;
+	}
+}

+ 468 - 136
src/ui/view/GUI.java

@@ -1,38 +1,76 @@
 package ui.view;
 
-import java.awt.EventQueue;
 import java.io.File;
-
+import java.text.AttributedCharacterIterator;
+import java.util.ArrayList;
 import javax.swing.JFrame;
+import javax.swing.JLabel;
 import javax.swing.JMenuBar;
 import javax.swing.JMenu;
 import javax.swing.JMenuItem;
-import javax.swing.UIManager;
-import javax.swing.UnsupportedLookAndFeelException;
+import javax.swing.JOptionPane;
 import javax.swing.JTree;
-
 import javax.swing.BoxLayout;
 import javax.swing.JSplitPane;
 import javax.swing.JScrollPane;
 import javax.swing.JTabbedPane;
 import javax.swing.JTable;
 import javax.swing.tree.DefaultTreeModel;
-
+import javax.swing.tree.TreeCellRenderer;
+import ui.controller.Control;
+import ui.model.*;
 
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.JEditorPane;
 import javax.swing.JFileChooser;
 import javax.swing.table.DefaultTableModel;
+import javax.swing.table.TableModel;
+
 import java.awt.Color;
 import java.awt.Component;
-import java.awt.Window.Type;
-import javax.swing.JInternalFrame;
+import java.awt.Cursor;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.Point;
+import java.awt.Rectangle;
+import java.awt.Shape;
+import java.awt.Toolkit;
 import java.awt.BorderLayout;
+
 import javax.swing.JPanel;
+import javax.swing.JToolBar;
+import javax.swing.JButton;
+import javax.swing.JComboBox;
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.ImageIcon;
 
-public class GUI {
+import classes.Category;
+import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
+import classes.HolonSwitch;
+import classes.HolonTransformer;
+import Interfaces.CategoryListener;
+
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.image.ImageObserver;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.awt.event.ActionEvent;
+import javax.swing.JSlider;
+import javax.swing.event.ChangeListener;
+import javax.swing.event.ChangeEvent;
+import javax.swing.SwingConstants;
+
+public class GUI implements CategoryListener {
 
 	private JFrame frmCyberPhysical;
+
 	private final JMenuBar menuBar = new JMenuBar();
 	private final JMenu mnNewMenu = new JMenu("File");
 	private final JMenu mnNewMenu_1 = new JMenu("Edit");
@@ -40,183 +78,477 @@ public class GUI {
 	private final JMenu mnNewMenu_3 = new JMenu("View");
 	private final JMenu mnHelp = new JMenu("Help");
 	private final JMenuItem mntmOpen = new JMenuItem("Open");
-	private JMenuItem mntmNew = new JMenuItem("New");
+	private final JMenuItem mntmNew = new JMenuItem("New");
 	private final JMenuItem mntmSave = new JMenuItem("Save");
+	private final JMenuItem aboutUs = new JMenuItem("About Us");
 	private final JSplitPane splitPane = new JSplitPane();
 	private final JSplitPane splitPane_1 = new JSplitPane();
 	private final JScrollPane scrollPane_1 = new JScrollPane();
 	private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
 	private final JScrollPane scrollPane_2 = new JScrollPane();
-	private final MyCanvas canvas = new MyCanvas();
+
 	private final JTree tree = new JTree();
 	private final JEditorPane dtrpnHereWillBe = new JEditorPane();
 	private final JSplitPane splitPane_2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
-	private JTable table;
-	private final JTable table_2 = new JTable();
-	
-	/**
-	 * Launch the application.
-	 */
-	public static void main(String[] args) {
-		
-		//*Design
-		try {
-			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
-				| UnsupportedLookAndFeelException e1) {
-			// TODO Auto-generated catch block
-			e1.printStackTrace();
-		}
-		
-		EventQueue.invokeLater(new Runnable() {
-			public void run() {
-				try {
-					GUI window = new GUI();
-					window.frmCyberPhysical.setVisible(true);
-				} catch (Exception e) {
-					e.printStackTrace();
-				}
-			}
-		});
-	}
+
+	private JTable table = new JTable();
+	private DefaultTableModel tableModel = new DefaultTableModel();
+	private final Model model;
+	private final Control controller;
+	private AddObjectPopUp addObjectPopUP;
+	private AboutUsPopUp aboutUsPopUp;
+
+	private final JPanel panel = new JPanel();
+	private final JComboBox comboBox = new JComboBox();
+
+	// Buttons
+	private final JButton btnAdd = new JButton("+");
+	private final JButton btnDel = new JButton("-");
+
+	private final JToolBar toolBar = new JToolBar();
+
+	// variables
+	private boolean dragging = false;
+	private String actualObjectClicked;
+	private Image img = null;
+	private CpsObject tempCps = null;
+
+	private MyCanvas canvas;
+	private final JSplitPane splitPane_3 = new JSplitPane();
+	private final JSlider slider = new JSlider();
+	private final JLabel lblImageSize = new JLabel("Image Size");
 
 	/**
 	 * Create the application.
 	 */
-	public GUI() {
+	public GUI(Control control) {
+		this.controller = control;
+		this.model = control.getModel();
+		this.canvas = new MyCanvas(model, control);
+		control.initListener(this);
 		initialize();
+		updateCategories(model.getCategories());
 	}
 
 	/**
 	 * Initialize the contents of the frame.
 	 */
-	@SuppressWarnings("serial")
+	@SuppressWarnings({ "serial", "unchecked" })
 	private void initialize() {
 		frmCyberPhysical = new JFrame();
 		frmCyberPhysical.setTitle("Cyber Physical Systems Model");
-		frmCyberPhysical.setBounds(100, 100, 891, 467);
+		frmCyberPhysical.setBounds(100, 100, 1000, 800);
 		frmCyberPhysical.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-		
+
 		frmCyberPhysical.setJMenuBar(menuBar);
-		
+
 		menuBar.add(mnNewMenu);
-		
+
 		mnNewMenu.add(mntmNew);
-		
+
 		mnNewMenu.add(mntmOpen);
-		
+
 		mnNewMenu.add(mntmSave);
-		
+
 		menuBar.add(mnNewMenu_1);
-		
+
 		menuBar.add(mnNewMenu_2);
-		
+
 		menuBar.add(mnNewMenu_3);
-		
+
+		mnNewMenu_3.add(splitPane_3);
+
+		slider.setMinimum(15);
+		slider.setMaximum(115);
+		slider.addChangeListener(new ChangeListener() {
+			@Override
+			public void stateChanged(ChangeEvent e) {
+				controller.setScale(slider.getValue());
+				tree.setRowHeight(model.getScale());
+				canvas.objectSelectionHighlighting();
+				canvas.repaint();
+			}
+		});
+		splitPane_3.setRightComponent(slider);
+
+		splitPane_3.setLeftComponent(lblImageSize);
+
 		menuBar.add(mnHelp);
-		frmCyberPhysical.getContentPane().setLayout(new BoxLayout(frmCyberPhysical.getContentPane(), BoxLayout.X_AXIS));
-		
-		frmCyberPhysical.getContentPane().add(splitPane);
-		
-		//Table
-		String[] columnNames = {"Consumer",
-                "Units",
-                "Number"};
-
-		Object[][] data = {
-				{"TV", "20", "1"},
-				{"PC", "30", "2"},
-				{"Fridge", "40","1"}
-		};
-		
-		splitPane.setRightComponent(splitPane_1);
-		splitPane.setDividerLocation(200);
-		splitPane_1.setDividerLocation(500);
+
+		mnHelp.add(aboutUs);
+
 		canvas.setBackground(Color.WHITE);
-		
-		tabbedPane.addTab("Modeling", null, canvas, null);
-		tabbedPane.addTab("Simulation", null, scrollPane_2, null);
+		canvas.setPreferredSize(new Dimension(10000, 10000));
+		JScrollPane canvasSP = new JScrollPane(canvas);
+
+		tabbedPane.addTab("Modeling", new ImageIcon(new ImageIcon(this.getClass().getResource("/Images/home.png"))
+				.getImage().getScaledInstance(30, 30, Image.SCALE_SMOOTH)), canvasSP, "Model a CPS");
+
+		tabbedPane.addTab("Simulation",
+				new ImageIcon(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
+						.getScaledInstance(30, 30, Image.SCALE_SMOOTH)),
+				scrollPane_2, "Simulate the CPS");
 		dtrpnHereWillBe.setText("Here will be the Simulation");
-		
+
 		scrollPane_2.setViewportView(dtrpnHereWillBe);
-		
-		splitPane_1.setLeftComponent(tabbedPane);
-		
+
 		JScrollPane scrollPane = new JScrollPane();
-		splitPane_1.setRightComponent(splitPane_2);
-		splitPane_2.setLeftComponent(scrollPane);
-		table = new JTable(data, columnNames);
+		// Table Set up
+		Object[] columnNames = { "Device", "Type", "Energy", "Quantity" };
+		tableModel.setColumnIdentifiers(columnNames);
+		table.setModel(tableModel);
 		scrollPane.setViewportView(table);
-		
 		table.setFillsViewportHeight(true);
-		table.setModel(new DefaultTableModel(
-			data,
-			columnNames
-		));
 		table.setCellSelectionEnabled(true);
 		table.setColumnSelectionAllowed(true);
-		JScrollPane scrollPane_3 = new JScrollPane();
-		splitPane_2.setRightComponent(scrollPane_3);
-		scrollPane_3.setViewportView(table_2);
-		
-		table_2.setFillsViewportHeight(true);
-		table_2.setModel(new DefaultTableModel(
-			new Object[][] {
-				{"Solar", "23", "10"},
-				{"Generator", "24", "1"},
-				{"Something Else", "25", "3"},
-			},
-			new String[] {
-				"Producer", "Units", "Number"
+
+		frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
+
+		TreeCellRenderer customRenderer = new TreeCellRenderer() {
+			@Override
+			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
+					boolean leaf, int row, boolean hasFocus) {
+				JLabel label = new JLabel();
+				Image imgR = null;
+				if (leaf) {
+					for (Category cat : model.getCategories()) {
+						for (CpsObject cps : cat.getObjects()) {
+							if (value.toString().compareTo(cps.getCompareName()) == 0) {
+								imgR = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
+										.getScaledInstance(controller.getScale(), controller.getScale(),
+												java.awt.Image.SCALE_SMOOTH);
+								if (imgR != null) {
+									label.setIcon(new ImageIcon(imgR));
+								}
+								label.setText(cps.getName());
+							}
+						}
+					}
+				}
+				tree.setRowHeight(controller.getScale());
+				if (hasFocus) {
+					label.setForeground(new Color(0, 0, 255));
+					label.setOpaque(true);
+				}
+				if (label.getText().length() == 0) {
+					label.setText(value.toString());
+					if (value.toString().compareTo("Categories") != 0) {
+						label.setIcon(new ImageIcon(this.getClass().getResource("/Images/folder.png")));
+					}
+				}
+
+				return label;
+
 			}
-		));
-		table_2.getColumnModel().getColumn(0).setPreferredWidth(103);
-		table_2.getColumnModel().getColumn(1).setPreferredWidth(107);
-		table_2.getColumnModel().getColumn(2).setPreferredWidth(125);
-		splitPane_2.setDividerLocation(200);
-		
-		splitPane.setLeftComponent(scrollPane_1);
-		tree.setEditable(true);
-		tree.setModel(new DefaultTreeModel(
-			new DefaultMutableTreeNode("Components") {
-				{
-					DefaultMutableTreeNode node_1;
-					node_1 = new DefaultMutableTreeNode("PowerPlant");
-						node_1.add(new DefaultMutableTreeNode("Standart P.P"));
-						node_1.add(new DefaultMutableTreeNode("Power PowerPlant"));
-					add(node_1);
-					node_1 = new DefaultMutableTreeNode("Houses");
-						node_1.add(new DefaultMutableTreeNode("Hospital"));
-						node_1.add(new DefaultMutableTreeNode("Standart House"));
-						node_1.add(new DefaultMutableTreeNode("Castle"));
-						node_1.add(new DefaultMutableTreeNode("Arena"));
-					add(node_1);
-					node_1 = new DefaultMutableTreeNode("Cars");
-						node_1.add(new DefaultMutableTreeNode("Small Car"));
-						node_1.add(new DefaultMutableTreeNode("Medium  Car"));
-						node_1.add(new DefaultMutableTreeNode("Big Car"));
-						node_1.add(new DefaultMutableTreeNode("Invisible Car"));
-					add(node_1);
+		};
+
+		tree.setCellRenderer(customRenderer);
+
+		tree.addMouseListener(new MouseAdapter() {
+			public void mouseReleased(MouseEvent e) {
+				try {
+					if (dragging) {
+						int x = (int) canvas.getMousePosition().getX();
+						int y = (int) canvas.getMousePosition().getY();
+						CpsObject h = null;
+						if (tempCps.getClass() == HolonObject.class) {
+							h = new HolonObject(tempCps);
+						}
+						if (tempCps.getClass() == HolonSwitch.class) {
+							h = new HolonSwitch(tempCps);
+						}
+						if (tempCps.getClass() == HolonTransformer.class) {
+							h = new HolonTransformer(tempCps);
+						}
+
+						h.setPosition(x, y);
+						controller.addObjectCanvas(h);
+						for (int i = 0; i < model.getObjectsOnCanvas().size(); i++) {
+							CpsObject temp = model.getObjectsOnCanvas().get(i);
+							String output = "Element: " + temp.getObjName() + " with ID: " + temp.getID();
+
+							if (temp.getClass() == HolonObject.class) {
+								output = output + " and Elements: " + ((HolonObject) temp).toStringElements();
+							}
+							System.out.println(output);
+						}
+						canvas.repaint();
+						dragging = false;
+					}
+				} catch (Exception e2) {
 				}
+				frmCyberPhysical.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
 			}
-		));
-		
+		});
+
+		tree.addMouseListener(new MouseAdapter() {
+			public void mousePressed(MouseEvent e) {
+				try {
+					actualObjectClicked = tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent().toString();
+					for (Category cat : model.getCategories()) {
+						for (CpsObject cps : cat.getObjects()) {
+							if (actualObjectClicked.compareTo(cps.getCompareName()) == 0) {
+								img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
+										.getScaledInstance(controller.getScale(), controller.getScale(),
+												java.awt.Image.SCALE_SMOOTH);
+								tempCps = cps;
+								dragging = true;
+								Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
+										"Image");
+								frmCyberPhysical.setCursor(cursor);
+							}
+						}
+					}
+				} catch (Exception e2) {
+				}
+			}
+		});
+
 		scrollPane_1.setViewportView(tree);
-		
+
+		scrollPane_1.setColumnHeaderView(panel);
+		panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
+		toolBar.setFloatable(false);
+
+		panel.add(toolBar);
+		toolBar.add(comboBox);
+		comboBox.setModel(new DefaultComboBoxModel(new String[] { "Category", "Object", "Transformer", "Switch" }));
+		// Add Button
+		btnAdd.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+
+				Object nodeInfo = tree.getLastSelectedPathComponent();
+				String selectedOption = comboBox.getSelectedItem().toString();
+				DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
+
+				switch (selectedOption) {
+
+				case "Category":
+					String catName = JOptionPane.showInputDialog("Please enter a Name for Category ");
+					if (catName.length() != 0) {
+						controller.addCategory(catName);
+					}
+					break;
+
+				case "Object":
+					if (selectedNode == null) {
+						JOptionPane.showMessageDialog(new JFrame(),
+								"Please select a Category first before adding " + selectedOption + ".");
+					}
+					if (selectedNode.getLevel() == 1) {
+						addObjectPopUP = new AddObjectPopUp();
+						addObjectPopUP.setVisible(true);
+						addObjectPopUP.setController(controller);
+						addObjectPopUP.setCategory(selectedNode.toString());
+					}
+					break;
+
+				default:
+					addObjectAction(selectedOption, selectedNode);
+					break;
+				}
+			}
+		});
+		aboutUs.addMouseListener(new MouseAdapter() {
+			@Override
+			public void mousePressed(MouseEvent e) {
+				aboutUsPopUp = new AboutUsPopUp();
+				aboutUsPopUp.setVisible(true);
+			}
+		});
+		canvas.addMouseListener(new MouseAdapter() {
+			@Override
+			public void mousePressed(MouseEvent e) {
+				if (tableModel.getRowCount() > 0) {
+					for (int i = tableModel.getRowCount() - 1; i > -1; i--) {
+						tableModel.removeRow(i);
+					}
+				}
+				if (canvas.dataSelected != null) {
+					for (HolonElement he : canvas.dataSelected) {
+						Object[] temp = { he.getEleName(), he.getSign(), he.getEnergy(), he.getAmount() };
+						tableModel.addRow(temp);
+					}
+				}
+			}
+		});
+
+		table.addPropertyChangeListener(new PropertyChangeListener() {
+			@Override
+			public void propertyChange(PropertyChangeEvent evt) {
+				try {
+
+					tempCps = controller.searchByID(model.getSelectedObjectID());
+					if (tempCps != null) {
+						System.out.println("change: " + tempCps.toString());
+						for (int r = 0; r < tableModel.getRowCount(); r++) {
+							ArrayList<Object> temp = new ArrayList<>();
+							for (int c = 0; c < tableModel.getColumnCount(); c++) {
+								temp.add(table.getValueAt(r, c));
+							}
+							float ch;
+							if(temp.get(1).toString().compareTo("-")==0) {ch = -1;} else {ch = 1;}
+							float fa = Float.parseFloat(temp.get(2).toString());
+							int i = Integer.parseInt(temp.get(3).toString());
+							((HolonObject) tempCps).getElements().get(r).setEleName((String) temp.get(0));
+							((HolonObject) tempCps).getElements().get(r).setSign(ch);
+							((HolonObject) tempCps).getElements().get(r).setEnergy(fa);
+							((HolonObject) tempCps).getElements().get(r).setAmount(i);
+							System.out.println(table.getRowCount() + " " + temp.get(0) + " " + ch + " "
+									+ fa + " " + i);
+						}
+						if (tableModel.getRowCount() > 0) {
+							for (int i = tableModel.getRowCount() - 1; i > -1; i--) {
+								tableModel.removeRow(i);
+							}
+						}
+						for (HolonElement he : canvas.dataSelected) {
+							Object[] temp = { he.getEleName(), he.getSign(), he.getEnergy(), he.getAmount() };
+							tableModel.addRow(temp);
+						}
+					}
+				} catch (Exception e) {
+					
+				}
+			}
+		});
+
+		toolBar.add(btnAdd);
+
+		// Del Button
+		btnDel.addActionListener(new ActionListener() {
+			public void actionPerformed(ActionEvent arg0) {
+
+				Object nodeInfo = tree.getLastSelectedPathComponent();
+				if (nodeInfo != null) {
+					DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
+					String nodeName = selectedNode.getUserObject().toString();
+					int depthOfNode = selectedNode.getLevel();
+
+					switch (depthOfNode) {
+					case 1:
+						int dialogResult = JOptionPane.showConfirmDialog(null,
+								"Do you realy want to delete the Category " + nodeName + "?", "Warning",
+								JOptionPane.YES_NO_OPTION);
+						if (dialogResult == JOptionPane.YES_OPTION) {
+							controller.deleteCategory(nodeName);
+							break;
+						} else {
+							break;
+						}
+					case 2:
+						DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
+						controller.delObjectCategory(nodeName, parent.getUserObject().toString());
+						break;
+
+					default:
+						JOptionPane.showMessageDialog(new JFrame(),
+								"Please select a Category or an Object in order to delete something.");
+					}
+				} else {
+					JOptionPane.showMessageDialog(new JFrame(),
+							"Please select a Category or an Object in order to delete something.");
+				}
+
+			}
+		});
+		toolBar.add(btnDel);
+		frmCyberPhysical.getContentPane().add(splitPane);
+
 		mntmOpen.addActionListener(new java.awt.event.ActionListener() {
-	        @Override
-	        public void actionPerformed(java.awt.event.ActionEvent evt) {
-	            menuFileExitActionPerformed(evt);
-	        }
+			@Override
+			public void actionPerformed(java.awt.event.ActionEvent evt) {
+				menuFileExitActionPerformed(evt);
+			}
+
 			private void menuFileExitActionPerformed(java.awt.event.ActionEvent evt) {
 				JFileChooser fileChooser = new JFileChooser();
 				JFrame test = new JFrame();
 				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
-				  File file = fileChooser.getSelectedFile();
-				  System.out.println("File Path is: "+file.toString());
+					File file = fileChooser.getSelectedFile();
+					System.out.println("File Path is: " + file.toString());
+				}
+			}
+		});
+
+		splitPane.setRightComponent(splitPane_1);
+		splitPane.setDividerLocation(200);
+		splitPane_1.setDividerLocation(500);
+		splitPane.setLeftComponent(scrollPane_1);
+		splitPane_1.setLeftComponent(tabbedPane);
+		splitPane_1.setRightComponent(scrollPane);
+	}
+
+	/*
+	 * adds a specific object type to selected Category also handles input
+	 * windows and illegal inputs
+	 */
+	public void addObjectAction(String objType, DefaultMutableTreeNode selectedNode) {
+		if (selectedNode == null) {
+			JOptionPane.showMessageDialog(new JFrame(),
+					"Please select a Category first before adding " + objType + ".");
+		}
+		// if selected node is a directory for Categories
+		else {
+			if (selectedNode.getLevel() == 1) {
+				String objname = JOptionPane.showInputDialog("Please enter a Name for the " + objType);
+				Category cat = controller.searchCategory(selectedNode.getUserObject().toString());
+
+				if (objname.length() != 0) {
+					switch (objType) {
+
+					case "Switch":
+						controller.addSwitch(cat, objname, objType);
+						break;
+
+					case "Transformer":
+						controller.addTransformer(cat, objname, objType);
+						break;
+					}
+				}
+			} else {
+				JOptionPane.showMessageDialog(new JFrame(),
+						"Objects can not be added to Objects. Please select a Category.");
+			}
+		}
+	}
+
+	/**
+	 * reloads the Categories from Model
+	 */
+	public void updateCategories(final ArrayList<Category> categories) {
+		tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
+			{
+				DefaultMutableTreeNode node_1;
+				for (Category c : categories) {
+					node_1 = new DefaultMutableTreeNode(c.getName());
+
+					// kann eventuell umgeändert werden
+					for (CpsObject obj : c.getObjects()) {
+						node_1.add(new DefaultMutableTreeNode(obj.getObjName()));
+					}
+					add(node_1);
 				}
+
 			}
-	    });
-		
+		}));
 	}
+
+	/**
+	 * 
+	 */
+	public void onChange(ArrayList<Category> categories) {
+		DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
+		updateCategories(categories);
+		model.reload();
+	}
+
+	/**
+	 * 
+	 * @return
+	 */
+	public JFrame getFrmCyberPhysical() {
+		return frmCyberPhysical;
+	}
+
 }

+ 42 - 0
src/ui/view/Main.java

@@ -0,0 +1,42 @@
+package ui.view;
+
+import java.awt.EventQueue;
+import java.util.ArrayList;
+
+import javax.swing.UIManager;
+import javax.swing.UnsupportedLookAndFeelException;
+
+import ui.controller.*;
+import ui.model.*;
+
+public class Main {
+
+	public static void main(String[] args) {
+
+		// *Design
+		try {
+			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
+		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
+				| UnsupportedLookAndFeelException e1) {
+			// TODO Auto-generated catch block
+			e1.printStackTrace();
+		}
+
+		EventQueue.invokeLater(new Runnable() {
+			public void run() {
+				try {
+					idCounter ID = new idCounter();
+					Model MODEL = new Model();
+					Control CONTROL = new Control(MODEL);
+					GUI VIEW = new GUI(CONTROL);
+
+					VIEW.getFrmCyberPhysical().setVisible(true);
+
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
+			}
+		});
+	}
+
+}

+ 292 - 40
src/ui/view/MyCanvas.java

@@ -1,76 +1,328 @@
 package ui.view;
 
+import java.awt.Color;
 import java.awt.Graphics;
+import java.awt.Graphics2D;
 import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.RenderingHints;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
-import java.awt.image.BufferedImage;
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
+import java.awt.event.MouseMotionListener;
+import java.util.ArrayList;
+import java.util.Timer;
+import java.util.TimerTask;
 
-import javax.imageio.ImageIO;
+import javax.swing.ImageIcon;
+import javax.swing.JMenuItem;
 import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.event.MenuDragMouseEvent;
+import javax.swing.JPopupMenu;
+import javax.swing.JToolTip;
 
-class MyCanvas extends JPanel implements MouseListener
-{
-	private Image img;      // Contains the image to draw on MyCanvas
+import classes.CpsObject;
+import classes.HolonElement;
+import classes.HolonObject;
+import classes.HolonSwitch;
+import ui.controller.Control;
+import ui.model.*;
+
+class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
+	private Image img = null; // Contains the image to draw on MyCanvas
 	private int x = 0;
 	private int y = 0;
-	
-    public MyCanvas()
-    {
-    	img = null;
-    	try {
-    		URL url = new URL("https://cdn4.iconfinder.com/data/icons/buildings-filled-1/60/house-home-building-construction-32.png");
-          
-    		img = ImageIO.read(url);
-    	} catch (IOException e) {
-    		System.out.println("Failed to load the Image!");
-    	}
-    	
-        this.addMouseListener(this);
-    }
-
-    public void paintComponent(Graphics g)
-    {
-        // Draws the image to the canvas
-    	super.paintComponent(g);
-        g.drawImage(img, x, y, null);
-    }
+	// edge Object Start Point
+	private Model model;
+	private final Control controller;
+	Graphics2D g2; // For Painting
+	private int cx;
+	private int cy;
+	ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
+
+	private boolean dragging = false; // for dragging
+	private boolean drawEdge = false; // for drawing edges
+	private boolean click = false; // for double click
+	private CpsObject tempCps = null;
+	private Rectangle selectRect = new Rectangle();
+
+	// PopUpMenu
+	private JPopupMenu popmenu = new JPopupMenu();
+	private JMenuItem itemDelete = new JMenuItem("Delete Object");
+	private JToolTip objectTT = new JToolTip();
+
+	public MyCanvas(final Model model, Control control) {
+		this.add(objectTT);
+		this.controller = control;
+		this.model = model;
+		popmenu.add(itemDelete);
+		itemDelete.setEnabled(false);
+		itemDelete.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				// Remove the selected Object object
+				controller.deleteObjectOnCanvas(tempCps);
+				tempCps = null;
+				selectRect.setRect(0, 0, 0, 0);
+				repaint();
+			}
+		});
+
+		this.addMouseListener(this);
+		this.addMouseMotionListener(this);
+	}
+
+	/**
+	 * Paints all Components on the Canvas
+	 * 
+	 * @param Graphics
+	 * 
+	 */
+	public void paintComponent(Graphics g) {
+		super.paintComponent(g);
+		// Rendering
+		g2 = (Graphics2D) g;
+		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+		g2.setRenderingHints(rh);
+
+		// Selection
+		if (selectRect != null) {
+			g2.setColor(Color.GREEN);
+			g2.fillRect((int) selectRect.getX(), (int) selectRect.getY(), (int) selectRect.getWidth(),
+					(int) selectRect.getHeight());
+
+		}
+
+		// drawEdges
+		g2.setColor(Color.BLACK);
+		if (drawEdge)
+			g2.drawLine(tempCps.getPosition().x + controller.getScaleDiv2(),
+					tempCps.getPosition().y + controller.getScaleDiv2(), x, y);
+
+		for (CpsObject cps : model.getObjectsOnCanvas()) {
+			for (CpsObject con : cps.getConnectedTo()) {
+				if (con.getID() != model.getSelectedObjectID() && cps.getID() != model.getSelectedObjectID())
+					g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
+							cps.getPosition().y + controller.getScaleDiv2(),
+							con.getPosition().x + controller.getScaleDiv2(),
+							con.getPosition().y + controller.getScaleDiv2());
+			}
+		}
+
+		// Highlighted Edge
+		g2.setColor(Color.GREEN);
+		for (CpsObject cps : model.getObjectsOnCanvas()) {
+			for (CpsObject con : cps.getConnectedTo()) {
+				if (con.getID() == model.getSelectedObjectID())
+					g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
+							cps.getPosition().y + controller.getScaleDiv2(),
+							con.getPosition().x + controller.getScaleDiv2(),
+							con.getPosition().y + controller.getScaleDiv2());
+			}
+		}
+
+		// Objects
+		for (CpsObject cps : model.getObjectsOnCanvas()) {
+			img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
+
+			g2.drawImage(img, cps.getPosition().x, cps.getPosition().y, controller.getScale(), controller.getScale(),
+					null);
+
+		}
+	}
 
 	@Override
 	public void mouseClicked(MouseEvent e) {
-		// TODO Auto-generated method stub
+		// If double clicked on a Switch change the Image to on/off
+		if (doubleClick() && tempCps != null && tempCps.getClass() == HolonSwitch.class) {
+			System.out.println("trans double click");
+			if (tempCps.getImage().compareTo("/Images/switch-on.png") == 0) {
+				tempCps.setImage("/Images/switch-off.png");
+			} else {
+				tempCps.setImage("/Images/switch-on.png");
+			}
+		}
+		repaint();
 	}
 
 	@Override
 	public void mouseEntered(MouseEvent e) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void mouseExited(MouseEvent e) {
 		// TODO Auto-generated method stub
-		
+
 	}
 
 	@Override
 	public void mousePressed(MouseEvent e) {
-		// TODO Auto-generated method stub
-		
+		tempCps = null;
+		dataSelected = null;
+		// Object Selection
+		for (CpsObject cps : model.getObjectsOnCanvas()) {
+			cx = cps.getPosition().x;
+			cy = cps.getPosition().y;
+			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
+				tempCps = cps;
+				// If drawing an Edge (CTRL down)
+				if (e.isControlDown()){
+					drawEdge = true;
+					controller.deleteElementCanvas(1, "Rehab");
+					System.out.println(((HolonObject)model.getCategories().get(0).getObjects().get(0)).getElements().get(2).getAmount());
+				}
+				if (tempCps.getClass() == HolonObject.class) {
+					HolonObject tempObj = ((HolonObject) tempCps);
+					dataSelected = tempObj.getElements();
+				}
+			}
+		}
+		// Object Selection Highlighting (selectRect)
+		objectSelectionHighlighting();
+
+		repaint();
 	}
 
 	@Override
 	public void mouseReleased(MouseEvent e) {
-		x = e.getX();
-        y = e.getY();
+		if (drawEdge) {
+			drawEdge = false;
+			drawDeleteEdge();
+		}
+
+		// if Dragged reposition the Object
+		if (dragging) {
+			x = e.getX();
+			y = e.getY();
+			dragging = false;
+			tempCps.setPosition(e.getX() - controller.getScaleDiv2(), e.getY() - controller.getScaleDiv2());
+		}
+
+		// Rightclick List
+		if (e.getButton() == e.BUTTON3) {
+			if (e.getButton() == e.BUTTON3 && tempCps != null) {
+				itemDelete.setEnabled(true);
+			} else {
+				itemDelete.setEnabled(false);
+			}
+			popmenu.show(e.getComponent(), e.getX(), e.getY());
+		}
 
-        Graphics g = img.getGraphics();
-        System.out.println("Draw!");
 		repaint();
 	}
+
+	@Override
+	public void mouseDragged(MouseEvent e) {
+		//If Edge is drawn
+		if (drawEdge) {
+			x = e.getX();
+			y = e.getY();
+			repaint();
+		} else {
+			try {
+				//Au�erhalb des Randes gedragged?
+				x = e.getX()-controller.getScaleDiv2();
+				y = e.getY()-controller.getScaleDiv2();
+				if(e.getX()<controller.getScaleDiv2())x = 0;
+				else if(e.getX()>this.getWidth()-controller.getScaleDiv2())x = this.getWidth()-controller.getScale();
+				if(e.getY()<controller.getScaleDiv2())y = 0;
+				else if(e.getY()>this.getHeight()-controller.getScaleDiv2())y = this.getHeight()-controller.getScale();
+				//Drag Position
+				tempCps.setPosition(x, y);
+				//Highlighting Position
+				selectRect.setLocation(x - (controller.getScale() / 20),y - (controller.getScale() / 20)); 
+				//TipText Position and name
+				objectTT.setTipText(tempCps.getName());
+				objectTT.setLocation(x, y+controller.getScale());
+				repaint();
+				}
+			catch (Exception e2) {
+			
+			}
+		}
+	}
+
+	@Override
+	public void mouseMoved(MouseEvent e) {
+		x = e.getX();
+		y = e.getY();
+		// Everytghing for the tooltip :)
+		boolean on = false;
+		for (CpsObject cps : model.getObjectsOnCanvas()) {
+
+			cx = cps.getPosition().x;
+			cy = cps.getPosition().y;
+			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
+
+				objectTT.setTipText(cps.getName());
+				objectTT.setLocation(cx, cy + controller.getScale());
+				on = true;
+			}
+		}
+		if (!on) {
+			objectTT.setLocation(-200, -200);
+			objectTT.setTipText("");
+		}
+	}
+
+	/**
+	 * Sets the Highlighting of the Selected Object
+	 */
+	public void objectSelectionHighlighting() {
+		if (tempCps != null) {
+			selectRect.setBounds(tempCps.getPosition().x - (controller.getScale() / 20),
+					tempCps.getPosition().y - (controller.getScale() / 20),
+					controller.getScale() + controller.getScale() / 10,
+					controller.getScale() + controller.getScale() / 10);
+
+			controller.setSelectedObjectID(tempCps.getID());
+		} else {
+			controller.setSelectedObjectID(0);
+			selectRect.setRect(0, 0, 0, 0);
+		}
+	}
+
+	/**
+	 * Draws or Deletes an Edge
+	 */
+	private void drawDeleteEdge() {
+		for (CpsObject cps : model.getObjectsOnCanvas()) {
+			cx = cps.getPosition().x;
+			cy = cps.getPosition().y;
+			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
+
+				if (!cps.getConnectedTo().contains(tempCps)) {
+					cps.AddConnection(tempCps);
+					tempCps.AddConnection(cps);
+				} else {
+					cps.getConnectedTo().remove(tempCps);
+					tempCps.getConnectedTo().remove(cps);
+				}
+			}
+		}
+	}
+
+	/**
+	 * Checks if a double click was made
+	 * 
+	 * @return true if doublecklick, false if not
+	 */
+	private boolean doubleClick() {
+		if (click) {
+			click = false;
+			return true;
+		} else {
+			click = true;
+			Timer t = new Timer("doubleclickTimer", false);
+			t.schedule(new TimerTask() {
+				@Override
+				public void run() {
+					click = false;
+				}
+			}, 500);
+		}
+		return false;
+	}
 }