Parcourir la source

category changes etc

Teh-Hai Julian Zheng il y a 8 ans
Parent
commit
8d1301c501

BIN
bin/ui/model/Model.class


BIN
bin/ui/view/GUI$1.class


BIN
bin/ui/view/GUI$2.class


BIN
bin/ui/view/GUI.class


+ 70 - 24
src/ui/controller/CategoryControl.java

@@ -4,27 +4,28 @@ import java.util.ArrayList;
 
 import com.sun.glass.ui.View;
 
+import sun.lwawt.macosx.CPrinterSurfaceData;
 import ui.model.*;
 import ui.view.*;
 
 public class CategoryControl{
 
-	private IdCounter id;
-	private Model model;
-	private GUI view;
+	private IdCounter ID;
+	private Model M;
+	private GUI V;
 	
 	
 	public CategoryControl(Model model, GUI view, IdCounter id){
-		this.id = id;
-		this.model = model;
-		this.view = view;
+		this.ID = id;
+		this.M = model;
+		this.V = view;
 		initCategories();
 	}
 	
 	
 	
 	/**
-	 * initialisiert alle Standart Kategorien und Objekte
+	 * init default category and objects
 	 */
 	public void initCategories(){
 		Category energy = new Category("Energy");
@@ -33,35 +34,80 @@ public class CategoryControl{
 		
 		HolonObject powerp = new HolonObject("Power Plant");
 		HolonObject house = new HolonObject("House");
-		HolonObject transformer = new HolonObject("Transformer");
-		HolonObject sw = new HolonObject("Switch");
+		HolonTransformer transformer = new HolonTransformer("Transformer");
+		HolonSwitch sw = new HolonSwitch("Switch");
 		
-		energy.addObject(powerp);
-		building.addObject(house);
-		component.addObject(transformer);
-		component.addObject(sw);
-		
-		model.addCategory(energy);
-		model.addCategory(building);
-		model.addCategory(component);
+		addObject(energy, powerp);
+		addObject(building, house);
+		addObject(component, transformer);
+		addObject(component, sw);
 		
+		addCategory(energy);
+		addCategory(building);
+		addCategory(component);
 		
 	}
 	
 	
 	/**
-	 * läd die Kategorien und Objekte in die View
+	 * Adds Category into Model
+	 * @param toAdd neue Kategorie
 	 */
-	public void loadCategories(){
-		//ArrayList<Category> category = m.getCategories();
+	public void addCategory(Category toAdd){
+	M.getCategories().add(toAdd);
+	}
+	
+	/**
+	 * Adds New Category into Model
+	 * @param name Bezeichnung der neuen Kategorie
+	 */
+	public void addNewCategory(String name){
 		
-
-//		for (Category c : category) {
-//			
-//		}
+		addCategory(new Category(name));
 	}
 	
+	/**
+	 * Add Object into a Category
+	 * @param cat Category
+	 * @param obj Object
+	 */
+	public void addObject(Category cat,CpsObject obj){
+		cat.getObjects().add(obj);
+	}
+	
+	/**
+	 * Add new Holon Object
+	 * @param cat Category
+	 * @param obj New Object Name
+	 */
+	public void addNewHolonObject(Category cat, String obj){
+		addObject(cat, new HolonObject(obj));
+	}
 	
+	/**
+	 * Add new Holon Transformer
+	 * @param cat Category
+	 * @param obj New Object Name
+	 */
+	public void addNewHolonTransformer(Category cat, String obj){
+		addObject(cat, new HolonTransformer(obj));
+	}
+	
+	/**
+	 * Add new Holon Switch
+	 * @param cat Category
+	 * @param obj New Object Name
+	 */
+	public void addNewHolonSwitch(Category cat, String obj){
+		addObject(cat, new HolonSwitch(obj));
+	}
+
+
+	public void deleteCategory(int idx){
+	M.getCategories().remove(idx);
+	}
+
+
 	
 	
 }

+ 5 - 0
src/ui/controller/ObjectControl.java

@@ -0,0 +1,5 @@
+package ui.controller;
+
+public class ObjectControl {
+
+}

+ 46 - 17
src/ui/model/Category.java

@@ -3,31 +3,60 @@ package ui.model;
 import java.util.ArrayList;
 
 public class Category {
-	private ArrayList<HolonObject> objects;
+	
+	private ArrayList<CpsObject> objects;
 	private String name;
 	
 	public Category(String name){
-		this.objects = new ArrayList<>();
-		this.name = name;
+		this.setObjects(new ArrayList<>());
+		this.setName(name);
 	}
-	
-	public void addObject(HolonObject toAdd){
-		objects.add(toAdd);
+
+	/**
+	 * @return the objects
+	 */
+	public ArrayList<CpsObject> getObjects() {
+		return objects;
 	}
-	
-	public void deleteObject(int idx){
-		objects.remove(idx);
+
+	/**
+	 * @param objects the objects to set
+	 */
+	public void setObjects(ArrayList<CpsObject> objects) {
+		this.objects = objects;
 	}
-	
-	public ArrayList<HolonObject> getObjects(){
-		return objects;
+
+	/**
+	 * @return the name
+	 */
+	public String getName() {
+		return name;
 	}
-	
-	public void changeName(String name){
+
+	/**
+	 * @param name the name to set
+	 */
+	public void setName(String name) {
 		this.name = name;
 	}
 	
-	public String getName(){
-		return name;
-	}
+//	public void addObject(HolonObject toAdd){
+//		objects.add(toAdd);
+//	}
+//	
+//	public void deleteObject(int idx){
+//		objects.remove(idx);
+//	}
+//	
+//	public ArrayList<HolonObject> getObjects(){
+//		return objects;
+//	}
+//	
+//	public void changeName(String name){
+//		this.name = name;
+//	}
+//	
+//	public String getName(){
+//		return name;
+//	}
 }

+ 1 - 1
src/ui/model/CpsObject.java

@@ -2,7 +2,7 @@ package ui.model;
 
 import java.util.ArrayList;
 
-abstract class CpsObject {
+public class CpsObject {
 	/* Type of the Object */
 	String objName;
 	/* Name given by the user */

+ 37 - 20
src/ui/model/Model.java

@@ -5,38 +5,55 @@ import java.util.ArrayList;
 import ui.controller.*;
 
 public class Model {
-	private ArrayList<Category> Categories;
-	private ArrayList<HolonObject> ObjectsOnCanvas;
-	
-	
-	public Model(){
-		Categories = new ArrayList<Category>();
-		ObjectsOnCanvas = new ArrayList<HolonObject>();
-	}
 	
-	public void addCategory(Category toAdd){
-		Categories.add(toAdd);
-	}
+	//eventuell wenn Canvasgröße gewählt werden kann
+	private int HEIGHT;
+	private int WIDTH;
 	
-	public void deleteCategory(int idx){
-		Categories.remove(idx);
-	}
+	private ArrayList<Category> Categories;
+	private ArrayList<CpsObject> ObjectsOnCanvas;
 	
-	public void addObject(HolonObject toAdd){
-		ObjectsOnCanvas.add(toAdd);
-	}
 	
-	public void deleteObject(int idx){
-		ObjectsOnCanvas.remove(idx);
+	public Model(){
+		setCategories(new ArrayList<Category>());
+		setObjectsOnCanvas(new ArrayList<CpsObject>());
 	}
-	
+
+
+	/**
+	 * @return the categories
+	 */
 	public ArrayList<Category> getCategories() {
 		return Categories;
 	}
 
+
+	/**
+	 * @param categories the categories to set
+	 */
 	public void setCategories(ArrayList<Category> categories) {
 		Categories = categories;
 	}
+
+
+	/**
+	 * @return the objectsOnCanvas
+	 */
+	public ArrayList<CpsObject> getObjectsOnCanvas() {
+		return ObjectsOnCanvas;
+	}
+
+
+	/**
+	 * @param objectsOnCanvas the objectsOnCanvas to set
+	 */
+	public void setObjectsOnCanvas(ArrayList<CpsObject> objectsOnCanvas) {
+		ObjectsOnCanvas = objectsOnCanvas;
+	}
+
 	
 	
+	
+
+	
 }

+ 7 - 4
src/ui/view/GUI.java

@@ -18,9 +18,8 @@ import javax.swing.JTabbedPane;
 import javax.swing.JTable;
 import javax.swing.tree.DefaultTreeModel;
 
-import ui.model.Category;
-import ui.model.HolonObject;
-import ui.model.Model;
+
+import ui.model.*;
 
 import javax.swing.tree.DefaultMutableTreeNode;
 import javax.swing.JEditorPane;
@@ -180,6 +179,9 @@ public class GUI {
 		
 	}
 	
+	/**
+	 * reloads the Categories from Model
+	 */
 	public void refreshCategories(){
 		tree.setModel(new DefaultTreeModel(
 				new DefaultMutableTreeNode("Categories") {
@@ -188,7 +190,8 @@ public class GUI {
 						for (Category c : model.getCategories()) {
 							node_1 = new DefaultMutableTreeNode(c.getName());
 							
-							for (HolonObject hol : c.getObjects()) {
+							//kann eventuell umgeändert werden
+							for (CpsObject hol : c.getObjects()) {
 								node_1.add(new DefaultMutableTreeNode(hol.getObjName()));
 							}
 							add(node_1);

+ 13 - 12
src/ui/view/Main.java

@@ -1,4 +1,5 @@
 package ui.view;
+
 import java.awt.EventQueue;
 
 import javax.swing.UIManager;
@@ -9,9 +10,9 @@ import ui.model.*;
 
 public class Main {
 
-public static void main(String[] args) {
-		
-		//*Design
+	public static void main(String[] args) {
+
+		// *Design
 		try {
 			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
 		} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
@@ -19,18 +20,18 @@ public static void main(String[] args) {
 			// TODO Auto-generated catch block
 			e1.printStackTrace();
 		}
-		
+
 		EventQueue.invokeLater(new Runnable() {
 			public void run() {
 				try {
-					IdCounter id = new IdCounter();
-					Model model = new Model();
-					GUI window = new GUI(model);
-					Control control = new Control(model,window, id);
-					window.refreshCategories();
-					
-					window.getFrmCyberPhysical().setVisible(true);
-					
+					IdCounter 	ID = new IdCounter();
+					Model 		M = new Model();
+					GUI 		V = new GUI(M);
+					Control 	C = new Control(M, V, ID);
+
+					V.refreshCategories();
+					V.getFrmCyberPhysical().setVisible(true);
+
 				} catch (Exception e) {
 					e.printStackTrace();
 				}