Procházet zdrojové kódy

controller dies das Merge branch 'Ohne_Drag_and_Drop' of https://git.tk.informatik.tu-darmstadt.de/carlos.garcia/praktikum-holons into Ohne_Drag_and_Drop

# Conflicts:
#	bin/ui/controller/Control.class
#	src/ui/controller/Control.java
Teh-Hai Julian Zheng před 8 roky
rodič
revize
f1012e85cd

binární
bin/Images/Thumbs.db


binární
bin/classes/CpsObject.class


binární
bin/ui/controller/CategoryController.class


binární
bin/ui/model/tests.class


binární
bin/ui/view/GUI$1.class


binární
bin/ui/view/GUI$2.class


binární
bin/ui/view/GUI$3.class


binární
bin/ui/view/GUI$4.class


binární
bin/ui/view/GUI$5.class


binární
bin/ui/view/GUI$6.class


binární
bin/ui/view/GUI.class


binární
bin/ui/view/Main$1.class


binární
bin/ui/view/MyCanvas.class


binární
res/Images/Thumbs.db


binární
res/Images/folder.png


+ 1 - 0
src/classes/CpsObject.java

@@ -32,6 +32,7 @@ public abstract class CpsObject implements ComparableObject {
 		position = new Position();
 		id = iDCounter.nextId();
 		image = "/Images/Dummy_House.png";
+//		System.out.println("ID: " + id + " of " + objName);
 	}
 
 	public CpsObject(CpsObject obj) {

+ 3 - 3
src/ui/controller/CanvasController.java

@@ -7,11 +7,11 @@ import ui.model.Model;
 
 public class CanvasController {
 
-	private iDCounter ID;
+//	private iDCounter ID;
 	private Model MODEL;
 
-	public CanvasController(Model model, iDCounter id) {
-		this.ID = id;
+	public CanvasController(Model model) {
+//		this.ID = id;
 		this.MODEL = model;
 	}
 

+ 3 - 3
src/ui/controller/CategoryController.java

@@ -18,11 +18,11 @@ import ui.view.*;
 
 public class CategoryController {
 
-	private iDCounter ID;
+//	private iDCounter ID;
 	private Model MODEL;
 
-	public CategoryController(Model model, iDCounter id) {
-		this.ID = id;
+	public CategoryController(Model model) {
+//		this.ID = id;
 		this.MODEL = model;
 		initCategories();
 	}

+ 11 - 5
src/ui/controller/Control.java

@@ -19,7 +19,7 @@ public class Control {
 		CATEGORY, OBJECT
 	}
 
-	private iDCounter ID;
+//	private iDCounter ID;
 	private Model MODEL;
 	
 	private ActionListener actionListener;
@@ -28,12 +28,12 @@ public class Control {
 	private final ObjectController objectController;
 	private final CanvasController canvasController;
 
-	public Control(Model model, iDCounter id) {
+	public Control(Model model) {
 		this.MODEL = model;
-		this.ID = id;
-		this.categoryController = new CategoryController(model, id);
+//		this.ID = id;
+		this.categoryController = new CategoryController(model);
 		this.objectController = new ObjectController(model);
-		this.canvasController = new CanvasController(model, id);
+		this.canvasController = new CanvasController(model);
 	}
 
 	/* Operations for Categories and Objects */
@@ -93,6 +93,12 @@ public class Control {
 		objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
 	}
 	
+<<<<<<< HEAD
+=======
+	public void deleteElement(){
+		
+	}
+>>>>>>> ea5ce1090a75c104d2cca9f0aa9dfc5b0bc08d01
 
 	////////// etc
 	/**

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

@@ -18,11 +18,11 @@ public class ObjectController {
 	}
 
 	private Model MODEL;
-	private int ID;
+//	private int ID;
 
 	public ObjectController(Model model) {
 		this.MODEL = model;
-		this.ID = iDCounter.nextId();
+//		this.ID = iDCounter.nextId();
 		initHolonElements();
 	}
 	

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

@@ -8,7 +8,7 @@ import ui.controller.CategoryController;
 public class tests {
 	
 	public static void main(String[] args){
-		CategoryController cc = new CategoryController(new Model(), new iDCounter());
+		CategoryController cc = new CategoryController(new Model());
 		ArrayList<Category> cats = new ArrayList<Category>();
 		cats.add(new Category("sup"));
 		boolean value;

+ 36 - 21
src/ui/view/GUI.java

@@ -28,6 +28,7 @@ import java.awt.Color;
 import java.awt.Component;
 import java.awt.Cursor;
 import java.awt.Dimension;
+import java.awt.Font;
 import java.awt.Image;
 import java.awt.Point;
 import java.awt.Toolkit;
@@ -151,17 +152,18 @@ public class GUI implements CategoryListener {
 		splitPane.setRightComponent(splitPane_1);
 		splitPane.setDividerLocation(200);
 		splitPane_1.setDividerLocation(500);
-		
+
 		canvas.setBackground(Color.WHITE);
 		canvas.setPreferredSize(new Dimension(10000, 10000));
 		JScrollPane canvasSP = new JScrollPane(canvas);
-		canvasSP.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
-		canvasSP.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
 
-		tabbedPane.addTab("Modeling", null, canvasSP, null);
+		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", null, scrollPane_2, null);
+		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);
@@ -202,13 +204,13 @@ public class GUI implements CategoryListener {
 					boolean leaf, int row, boolean hasFocus) {
 				JLabel label = new JLabel();
 				Image imgR = null;
-				
-				if(leaf){
+				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(GlobalVariables.SCALE, GlobalVariables.SCALE, java.awt.Image.SCALE_SMOOTH);
+										.getScaledInstance(GlobalVariables.SCALE, GlobalVariables.SCALE,
+												java.awt.Image.SCALE_SMOOTH);
 								if (imgR != null) {
 									label.setIcon(new ImageIcon(imgR));
 								}
@@ -217,11 +219,18 @@ public class GUI implements CategoryListener {
 						}
 					}
 				}
-				
-				if(hasFocus) label.setForeground(new Color(0, 0, 255));
 				tree.setRowHeight(GlobalVariables.SCALE);
-				if(label.getText().length() == 0) label.setText(value.toString());
-				
+				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;
 
 			}
@@ -234,11 +243,16 @@ public class GUI implements CategoryListener {
 				try {
 					if (dragging) {
 						CpsObject h = null;
-						System.out.println(tempCps.getClass().toString());
-						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);}
-						
+						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.setPos((int) canvas.getMousePosition().getX(), (int) canvas.getMousePosition().getY());
 						controller.addObject(h);
 						for (int i = 0; i < model.getObjectsOnCanvas().size(); i++) {
@@ -258,12 +272,13 @@ public class GUI implements CategoryListener {
 			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(GlobalVariables.SCALE, GlobalVariables.SCALE, java.awt.Image.SCALE_SMOOTH);
+										.getScaledInstance(GlobalVariables.SCALE, GlobalVariables.SCALE,
+												java.awt.Image.SCALE_SMOOTH);
 								tempCps = cps;
 								dragging = true;
 								Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
@@ -302,7 +317,7 @@ public class GUI implements CategoryListener {
 						controller.addNewCategory(catName);
 					}
 					break;
-				
+
 				case "Object":
 					if (selectedNode == null) {
 						JOptionPane.showMessageDialog(new JFrame(),

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

@@ -27,7 +27,7 @@ public class Main {
 				try {
 					iDCounter ID = new iDCounter();
 					Model MODEL = new Model();
-					Control CONTROL = new Control(MODEL, ID);
+					Control CONTROL = new Control(MODEL);
 					GUI VIEW = new GUI(CONTROL);
 
 					VIEW.getFrmCyberPhysical().setVisible(true);

+ 2 - 8
src/ui/view/MyCanvas.java

@@ -90,13 +90,11 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
 		g2 = (Graphics2D) g;
-		g2.setStroke(new BasicStroke(GlobalVariables.SCALE/15));
 		RenderingHints rh = new RenderingHints(
 	             RenderingHints.KEY_ANTIALIASING,
 	             RenderingHints.VALUE_ANTIALIAS_ON);
 	    g2.setRenderingHints(rh);
 	    
-		
 		//Selection
 		if(selectRect != null){
 			g2.setColor(Color.GREEN);
@@ -114,6 +112,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			}
 		}
 		
+		//Highlighted Edge
 		g2.setColor(Color.GREEN);		
 		for (CpsObject cps : model.getObjectsOnCanvas()) {
 			for (CpsObject con : cps.getConnectedTo()) {
@@ -184,12 +183,7 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			tempCps.setPos(e.getX() - GlobalVariables.SCALE_DIVIDED2, e.getY() - GlobalVariables.SCALE_DIVIDED2);
 			tempCps = null;
 		}
-		if(y+GlobalVariables.SCALE>this.getHeight()){
-			this.setPreferredSize(new Dimension(this.getWidth(), y+GlobalVariables.SCALE));
-		}
-		if(x+GlobalVariables.SCALE>this.getHeight()){
-			this.setPreferredSize(new Dimension(x+GlobalVariables.SCALE,this.getHeight() ));
-		}
+		
 		// Rechtsklick Liste
 		if (e.getButton() == e.BUTTON3) {
 			if (e.getButton() == e.BUTTON3 && tempCps != null) {