Browse Source

cleaning classes

Teh-Hai Julian Zheng 8 years ago
parent
commit
a747978b59

BIN
bin/classes/Category.class


BIN
bin/classes/CpsObject.class


BIN
bin/classes/HolonObject.class


BIN
bin/classes/HolonSwitch.class


BIN
bin/classes/HolonTransformer.class


BIN
bin/ui/controller/Control.class


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


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


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


BIN
bin/ui/view/GUI.class


BIN
bin/ui/view/MyCanvas.class


+ 17 - 6
src/classes/Category.java

@@ -6,14 +6,29 @@ import Interfaces.ComparableObject;
 
 public class Category implements ComparableObject{
 	
-	private int id;
+	private int ID;
 	private ArrayList<CpsObject> objects;
 	private String name;
 	
 	public Category(String name){
 		setObjects(new ArrayList<CpsObject>());
 		setName(name);
-		id = -1;
+		setID(-1);
+	
+	}
+
+	/**
+	 * @return the id
+	 */
+	public int getID() {
+		return ID;
+	}
+
+	/**
+	 * @param id the id to set
+	 */
+	public void setID(int id) {
+		this.ID = id;
 	}
 
 	/**
@@ -49,9 +64,5 @@ public class Category implements ComparableObject{
 		return getName();
 	}
 
-	@Override
-	public int getID() {
-		return id;
-	}
 	
 }

+ 49 - 24
src/classes/CpsObject.java

@@ -11,11 +11,11 @@ public abstract class CpsObject implements ComparableObject {
 	/* Name given by the user */
 	String name;
 	/* ID of the Obj. */
-	int id;
+	int ID;
 	/* Path of the image for the Obj. */
 	String image;
 	/* Array of neighbors */
-	ArrayList<CpsObject> connectedTo;
+	ArrayList<CpsObject> connections;
 	/* Position with a X and Y value */
 	Position position;
 	/* Energy input and output of each object in the grid */
@@ -26,24 +26,23 @@ public abstract class CpsObject implements ComparableObject {
 	 * Constructor for an CpsObejct with an unique ID
 	 */
 	public CpsObject(String objName) {
-		this.objName = objName;
-		this.name = objName;
-		connectedTo = new ArrayList<CpsObject>();
-		position = new Position();
-		// id = idCounter.nextId();
-		image = "/Images/Dummy_House.png";
-		System.out.println("ID: " + id + " of " + objName);
+		setObjName(objName);
+		setName(objName);
+		setConnections(new ArrayList<CpsObject>());
+		setPosition(new Position());
+		setImage("/Images/Dummy_House.png");
+		System.out.println("ID: " + ID + " of " + objName);
 	}
 
 	public CpsObject(CpsObject obj) {
-		this.objName = obj.getObjName();
-		connectedTo = new ArrayList<CpsObject>();
-		position = new Position();
-		id = idCounter.nextId();
-		this.name = obj.getName();
-		this.energyIn = obj.getEnergyIn();
-		this.energyOut = obj.getEnergyOut();
-		this.image = obj.getImage();
+		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 */
@@ -66,7 +65,15 @@ public abstract class CpsObject implements ComparableObject {
 
 	/* Unique ID number */
 	public int getID() {
-		return id;
+		return ID;
+	}
+
+	/**
+	 * @param iD
+	 *            the iD to set
+	 */
+	public void setID(int ID) {
+		this.ID = ID;
 	}
 
 	/* Image path */
@@ -78,22 +85,40 @@ public abstract class CpsObject implements ComparableObject {
 		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 connectedTo;
+		return connections;
 	}
 
 	public void AddConnection(CpsObject toConnect) {
-		connectedTo.add(toConnect);
+		connections.add(toConnect);
+	}
+
+	public void setPosition(Position pos) {
+		this.position = pos;
 	}
 
 	/* Position (x and Y) */
-	public void setPos(int x, int y) {
-		position.x = x;
-		position.y = y;
+	public void setPosition(int x, int y) {
+		setPosition(new Position(x, y));
 	}
 
-	public Position getPos() {
+	public Position getPosition() {
 		return position;
 	}
 

+ 4 - 6
src/classes/HolonObject.java

@@ -20,19 +20,18 @@ public class HolonObject extends CpsObject {
 	 */
 	public HolonObject(String ObjName) {
 		super(ObjName);
-		elements = new ArrayList<HolonElement>();
+		setElements(new ArrayList<HolonElement>());
 	}
 
 	public HolonObject(String ObjName, String obj) {
 		super(ObjName);
-		super.name = obj;
-		elements = new ArrayList<HolonElement>();
+		super.setName(obj);
+		setElements(new ArrayList<HolonElement>());
 	}
 
 	public HolonObject(CpsObject obj) {
 		super(obj);
-		elements = new ArrayList<HolonElement>();
-		this.elements = ((HolonObject) obj).getElements();
+		setElements(((HolonObject) obj).getElements());
 
 	}
 
@@ -92,7 +91,6 @@ public class HolonObject extends CpsObject {
 			} else {
 				objString = objString + ", " + e.getEleName();
 			}
-
 		}
 		return objString;
 	}

+ 12 - 8
src/classes/HolonSwitch.java

@@ -5,29 +5,33 @@ public class HolonSwitch extends CpsObject {
 	 * True, if this wire is working (capable of carrying electricity), else
 	 * false
 	 */
-	boolean isWorking;
+	boolean isActive;
 
 	public HolonSwitch(String ObjName) {
 		super(ObjName);
-		isWorking = false;
+		setState(false);
 	}
 
 	public HolonSwitch(String ObjName, String obj) {
 		super(ObjName);
-		super.name = obj;
-		isWorking = false;
+		super.setName(obj);
+		setState(false);
 	}
 
 	public HolonSwitch(CpsObject obj) {
 		super(obj);
-		this.isWorking = ((HolonSwitch)obj).getStates();
+		setState(((HolonSwitch)obj).getState());
 	}
 
 	public void switchState() {
-		this.isWorking = !isWorking;
+		this.isActive = !isActive;
 	}
 
-	public boolean getStates() {
-		return this.isWorking;
+	public boolean getState() {
+		return this.isActive;
+	}
+	
+	public void setState(boolean state){
+		this.isActive = state;
 	}
 }

+ 2 - 2
src/classes/HolonTransformer.java

@@ -15,12 +15,12 @@ public class HolonTransformer extends CpsObject {
 
 	public HolonTransformer(String ObjName, String obj) {
 		super(ObjName);
-		super.name = obj;
+		super.setName(obj);
 	}
 
 	public HolonTransformer(CpsObject obj) {
 		super(obj);
-		this.transformRatio = ((HolonTransformer)obj).getTransformRatio();
+		this.setTransformRatio(((HolonTransformer) obj).getTransformRatio());
 	}
 
 	/**

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

@@ -35,28 +35,27 @@ public class Control {
 	}
 
 	/* Operations for Categories and Objects */
-	public void addNewCategory(String catName) {
+	public void addCategory(String catName) {
 		categoryController.addNewCategory(catName);
 	}
 
-	public void addNewObject(Category cat, String name, String objType) {
+	public void addObject(Category cat, String name, String objType) {
 		categoryController.addNewHolonObject(cat, name, objType);
 	}
 
-	public void addNewObject(Category cat, HolonObject object) {
+	public void addObjectCategory(Category cat, HolonObject object) {
 		categoryController.addObject(cat, object);
 	}
 
-	public void addNewTransformer(Category cat, String name, String objType) {
+	public void addTransformer(Category cat, String name, String objType) {
 		categoryController.addNewHolonTransformer(cat, name, objType);
 	}
 
-	public void addNewSwitch(Category cat, String name, String objType) {
+	public void addSwitch(Category cat, String name, String objType) {
 		categoryController.addNewHolonSwitch(cat, name, objType);
 	}
 
 	public Category searchCategory(String name) {
-
 		return categoryController.searchCatNode(name);
 	}
 
@@ -68,12 +67,12 @@ public class Control {
 		categoryController.deleteCategory(catName);
 	}
 
-	public void deleteObjectInCat(String toDelete, String deleteIn) {
+	public void delObjectCategory(String toDelete, String deleteIn) {
 		categoryController.deleteObjectInCat(toDelete, deleteIn);
 	}
 
 	/* Operations for Canvas */
-	public void addObject(CpsObject object) {
+	public void addObjectCanvas(CpsObject object) {
 		canvasController.addObjectIntoCanvas(object);
 	}
 
@@ -82,11 +81,11 @@ public class Control {
 	}
 
 	/* Operations for Objects and Elements */
-	public void addNewElementIntoCanvasObjects(String objName, String eleName, int amount, float energy) {
+	public void addElementCanvasObject(String objName, String eleName, int amount, float energy) {
 		objectController.addNewElementIntoCanvasObject(objName, eleName, amount, energy);
 	}
 
-	public void addNewElementIntoCategoryObject(String catName, String objName, String eleName, int amount,
+	public void addElementCategoryObject(String catName, String objName, String eleName, int amount,
 			float energy) {
 		objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
 	}

+ 3 - 2
src/ui/controller/ObjectController.java

@@ -105,8 +105,9 @@ public class ObjectController {
 		obj.getElements().remove(ele);
 	}
 
-	public void deleteElementInCategory(Category cat, HolonObject obj, HolonElement ele) {
-
+	public void deleteElementInCanvas(String obj, String ele) {
+		HolonElement element;
+		//searchHolonObject(obj, MODEL.getObjectsOnCanvas()).;
 	}
 
 	/**

+ 1 - 1
src/ui/view/AddObjectPopUp.java

@@ -167,7 +167,7 @@ public class AddObjectPopUp extends JDialog {
 							theObject = new HolonObject(objectName.getText());
 							theObject.setElements(hElements);
 							theObject.setImage(imagePath);
-							controller.addNewObject(controller.searchCategory(givenCategory), theObject);
+							controller.addObjectCategory(controller.searchCategory(givenCategory), theObject);
 							System.out.println(theObject.getImage());
 							System.out.println(givenCategory);
 							dispose();

+ 6 - 6
src/ui/view/GUI.java

@@ -253,8 +253,8 @@ public class GUI implements CategoryListener {
 							h = new HolonTransformer(tempCps);
 						}
 
-						h.setPos((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
-						controller.addObject(h);
+						h.setPosition((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
+						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();
@@ -315,7 +315,7 @@ public class GUI implements CategoryListener {
 				case "Category":
 					String catName = JOptionPane.showInputDialog("Please enter a Name for Category ");
 					if (catName.length() != 0) {
-						controller.addNewCategory(catName);
+						controller.addCategory(catName);
 					}
 					break;
 
@@ -364,7 +364,7 @@ public class GUI implements CategoryListener {
 						}
 					case 2:
 						DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
-						controller.deleteObjectInCat(nodeName, parent.getUserObject().toString());
+						controller.delObjectCategory(nodeName, parent.getUserObject().toString());
 						break;
 
 					default:
@@ -418,11 +418,11 @@ public class GUI implements CategoryListener {
 					switch (objType) {
 
 					case "Switch":
-						controller.addNewSwitch(cat, objname, objType);
+						controller.addSwitch(cat, objname, objType);
 						break;
 
 					case "Transformer":
-						controller.addNewTransformer(cat, objname, objType);
+						controller.addTransformer(cat, objname, objType);
 						break;
 					}
 				}

+ 24 - 24
src/ui/view/MyCanvas.java

@@ -103,16 +103,16 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		// drawEdges
 		g2.setColor(Color.BLACK);
 		if (drawEdge)
-			g2.drawLine(tempCps.getPos().x + GlobalVariables.SCALE_DIVIDED2,
-					tempCps.getPos().y + GlobalVariables.SCALE_DIVIDED2, x, y);
+			g2.drawLine(tempCps.getPosition().x + GlobalVariables.SCALE_DIVIDED2,
+					tempCps.getPosition().y + GlobalVariables.SCALE_DIVIDED2, x, y);
 
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			for (CpsObject con : cps.getConnectedTo()) {
 				if (con.getID() != model.getSelectedObjectID() && cps.getID() != model.getSelectedObjectID())
-					g2.drawLine(cps.getPos().x + GlobalVariables.SCALE_DIVIDED2,
-							cps.getPos().y + GlobalVariables.SCALE_DIVIDED2,
-							con.getPos().x + GlobalVariables.SCALE_DIVIDED2,
-							con.getPos().y + GlobalVariables.SCALE_DIVIDED2);
+					g2.drawLine(cps.getPosition().x + GlobalVariables.SCALE_DIVIDED2,
+							cps.getPosition().y + GlobalVariables.SCALE_DIVIDED2,
+							con.getPosition().x + GlobalVariables.SCALE_DIVIDED2,
+							con.getPosition().y + GlobalVariables.SCALE_DIVIDED2);
 			}
 		}
 
@@ -121,17 +121,17 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			for (CpsObject con : cps.getConnectedTo()) {
 				if (con.getID() == model.getSelectedObjectID())
-					g2.drawLine(cps.getPos().x + GlobalVariables.SCALE_DIVIDED2,
-							cps.getPos().y + GlobalVariables.SCALE_DIVIDED2,
-							con.getPos().x + GlobalVariables.SCALE_DIVIDED2,
-							con.getPos().y + GlobalVariables.SCALE_DIVIDED2);
+					g2.drawLine(cps.getPosition().x + GlobalVariables.SCALE_DIVIDED2,
+							cps.getPosition().y + GlobalVariables.SCALE_DIVIDED2,
+							con.getPosition().x + GlobalVariables.SCALE_DIVIDED2,
+							con.getPosition().y + GlobalVariables.SCALE_DIVIDED2);
 			}
 		}
 
 		// Objects
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
-			g2.drawImage(img, cps.getPos().x, cps.getPos().y, GlobalVariables.SCALE, GlobalVariables.SCALE, null);
+			g2.drawImage(img, cps.getPosition().x, cps.getPosition().y, GlobalVariables.SCALE, GlobalVariables.SCALE, null);
 		}
 	}
 
@@ -161,8 +161,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 		tempCps = null;
 		// Object Selection
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
-			cx = cps.getPos().x;
-			cy = cps.getPos().y;
+			cx = cps.getPosition().x;
+			cy = cps.getPosition().y;
 			if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
 				tempCps = cps;
 				if (e.isControlDown())
@@ -188,7 +188,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			y = e.getY();
 
 			dragging = false;
-			tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
+			tempCps.setPosition(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
 			tempCps = null;
 		}
 
@@ -214,12 +214,12 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			repaint();
 		} else {
 			try {
-				tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
+				tempCps.setPosition(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
 				dragging = true;
-				selectRect.setLocation(tempCps.getPos().x - (GlobalVariables.SCALE / 20),
-						tempCps.getPos().y - (GlobalVariables.SCALE / 20));
+				selectRect.setLocation(tempCps.getPosition().x - (GlobalVariables.SCALE / 20),
+						tempCps.getPosition().y - (GlobalVariables.SCALE / 20));
 				objectTT.setTipText(tempCps.getName());
-				objectTT.setLocation(tempCps.getPos().x, tempCps.getPos().y);
+				objectTT.setLocation(tempCps.getPosition().x, tempCps.getPosition().y);
 				repaint();
 			} catch (Exception e2) {
 				// TODO: handle exception
@@ -234,8 +234,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 
 		boolean on = false;
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
-			cx = cps.getPos().x;
-			cy = cps.getPos().y;
+			cx = cps.getPosition().x;
+			cy = cps.getPosition().y;
 			if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
 				objectTT.setTipText(cps.getName());
 				objectTT.setLocation(cx, cy);
@@ -253,8 +253,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 	 */
 	private void objectSelectionHighlighting() {
 		if (tempCps != null) {
-			selectRect.setBounds(tempCps.getPos().x - (GlobalVariables.SCALE / 20),
-					tempCps.getPos().y - (GlobalVariables.SCALE / 20),
+			selectRect.setBounds(tempCps.getPosition().x - (GlobalVariables.SCALE / 20),
+					tempCps.getPosition().y - (GlobalVariables.SCALE / 20),
 					GlobalVariables.SCALE + GlobalVariables.SCALE / 10,
 					GlobalVariables.SCALE + GlobalVariables.SCALE / 10);
 			controller.setSelectedObjectID(tempCps.getID());
@@ -269,8 +269,8 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 	 */
 	private void drawDeleteEdge() {
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
-			cx = cps.getPos().x;
-			cy = cps.getPos().y;
+			cx = cps.getPosition().x;
+			cy = cps.getPosition().y;
 			if (x - GlobalVariables.SCALE <= cx && y - GlobalVariables.SCALE <= cy && x >= cx && y >= cy) {
 				if (!cps.getConnectedTo().contains(tempCps)) {
 					cps.AddConnection(tempCps);