Jelajahi Sumber

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

# Conflicts:
#	src/classes/CpsEdge.java
dominik.rieder 7 tahun lalu
induk
melakukan
6ed4b42653

+ 13 - 37
src/classes/CpsEdge.java

@@ -1,18 +1,14 @@
 package classes;
 
-import java.util.ArrayList;
-
 public class CpsEdge {
 
 	float maxCapacity;
 	float flow;
 	boolean isWorking;
-	//State represents the real status of the edge
-	//If it breaks --> stay ruin no matter the actual scenario
-	//The only way to repair it is through manual change (setStateEdge) 
-	boolean state = true;
-	
-	ArrayList<Integer> tags;
+	// State represents the real status of the edge
+	// If it breaks --> stay ruin no matter the actual scenario
+	// The only way to repair it is through manual change (setStateEdge)
+	// boolean state = true;
 
 	CpsObject A;
 	CpsObject B;
@@ -59,10 +55,6 @@ public class CpsEdge {
 		return flow;
 	}
 
-	public boolean getStateEdge() {
-		return state;
-	}
-
 	/**
 	 * @param flow
 	 *            the flow to set
@@ -70,27 +62,23 @@ public class CpsEdge {
 	public void setFlow(float flow) {
 		this.flow = flow;
 		/**
-		if (flow <= maxCapacity || flow == -1) {
-			isWorking = true;
-		} else {
-			isWorking = false;
-			state = false;
-		}
-		**/
+		 * if (flow <= maxCapacity || flow == -1) { isWorking = true; } else {
+		 * isWorking = false; state = false; }
+		 **/
 	}
-	
-	public void calculateState(boolean simMode){
-		if(flow > maxCapacity && maxCapacity != -1){
+
+	public void calculateState(boolean simMode) {
+		if (flow > maxCapacity && maxCapacity != -1) {
 			isWorking = false;
-		}else {
-			if(!simMode && flow <= maxCapacity){
+		} else {
+			if (!simMode && flow <= maxCapacity) {
 				isWorking = true;
 			}
 		}
 	}
 
 	public void setState(boolean isActive) {
-		state = isActive;
+		isWorking = isActive;
 	}
 
 	/**
@@ -126,17 +114,5 @@ public class CpsEdge {
 	public boolean getState() {
 		return isWorking;
 	}
-	
-	public void setTags(ArrayList<Integer> tags){
-		this.tags = tags;
-	}
-	
-	public ArrayList<Integer> getTags(){
-		return tags;
-	}
-	
-	public void addTag(int tag){
-		tags.add(tag);
-	}
 
 }

+ 61 - 16
src/classes/HolonSwitch.java

@@ -5,10 +5,16 @@ import java.util.LinkedList;
 
 public class HolonSwitch extends CpsObject {
 	/*
-	 * True, if this wire is working (capable of carrying electricity), else
-	 * false
+	 * manual state True, if this wire is working (capable of carrying
+	 * electricity), else false
 	 */
-	boolean active;
+	boolean manualActive;
+
+	/*
+	 * active state True, if this wire is working (capable of carrying
+	 * electricity), else false
+	 */
+	boolean autoActive;
 
 	/*
 	 * true if switch has to be used manually
@@ -25,7 +31,8 @@ public class HolonSwitch extends CpsObject {
 
 	public HolonSwitch(String ObjName) {
 		super(ObjName);
-		setState(true);
+		setManualState(true);
+		setAutoState(true);
 		setActiveAt(true);
 		setManualMode(false);
 	}
@@ -33,7 +40,8 @@ public class HolonSwitch extends CpsObject {
 	public HolonSwitch(String ObjName, String obj) {
 		super(ObjName);
 		super.setName(obj);
-		setState(true);
+		setManualState(true);
+		setAutoState(true);
 		setActiveAt(true);
 		setManualMode(false);
 	}
@@ -41,30 +49,63 @@ public class HolonSwitch extends CpsObject {
 	public HolonSwitch(CpsObject obj) {
 		super(obj);
 		super.setName(obj.getName());
-		setState(true);
+		setManualState(true);
+		setAutoState(true);
 		setActiveAt(true);
 		setManualMode(false);
 	}
 
 	public void switchState() {
-		if (this.active == true) {
-			setImage("/Images/switch-off.png");
+		if (manualMode) {
+			if (this.manualActive == true) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
+			this.manualActive = !manualActive;
 		} else {
-			setImage("/Images/switch-on.png");
+			if (this.autoActive == true) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
+			this.autoActive = !autoActive;
 		}
-		this.active = !active;
+
 	}
 
 	public boolean getState() {
-		return this.active;
+		if (manualMode) {
+			return this.manualActive;
+		} else {
+			return this.autoActive;
+		}
+
 	}
 
-	public void setState(boolean state) {
-		this.active = state;
-		if (this.active == true) {
-			setImage("/Images/switch-on.png");
+	public void setManualState(boolean state) {
+		this.manualActive = state;
+		setImage();
+	}
+
+	public void setAutoState(boolean state) {
+		this.autoActive = state;
+		setImage();
+	}
+
+	private void setImage() {
+		if (manualMode) {
+			if (this.manualActive == false) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
 		} else {
-			setImage("/Images/switch-off.png");
+			if (this.autoActive == false) {
+				setImage("/Images/switch-off.png");
+			} else {
+				setImage("/Images/switch-on.png");
+			}
 		}
 	}
 
@@ -90,6 +131,10 @@ public class HolonSwitch extends CpsObject {
 		return activeAt;
 	}
 
+	public boolean getActiveManual() {
+		return this.manualActive;
+	}
+
 	/**
 	 * @param active,
 	 *            the default value

+ 5 - 0
src/tests/praktikumHolonsTestAutoSaveController.java

@@ -0,0 +1,5 @@
+package tests;
+
+public class praktikumHolonsTestAutoSaveController {
+
+}

+ 5 - 0
src/tests/praktikumHolonsTestGlobalController.java

@@ -0,0 +1,5 @@
+package tests;
+
+public class praktikumHolonsTestGlobalController {
+
+}

+ 5 - 0
src/tests/praktikumHolonsTestLoadController.java

@@ -0,0 +1,5 @@
+package tests;
+
+public class praktikumHolonsTestLoadController {
+
+}

+ 5 - 0
src/tests/praktikumHolonsTestMultiPurposeController.java

@@ -0,0 +1,5 @@
+package tests;
+
+public class praktikumHolonsTestMultiPurposeController {
+
+}

+ 53 - 16
src/tests/praktikumHolonsTestObjectController.java

@@ -7,7 +7,9 @@ import static org.junit.Assert.assertTrue;
 import org.junit.Before;
 import org.junit.Test;
 
+import classes.CpsObject;
 import classes.HolonObject;
+import ui.controller.CanvasController;
 import ui.controller.CategoryController;
 import ui.controller.MultiPurposeController;
 import ui.controller.ObjectController;
@@ -19,6 +21,7 @@ public class praktikumHolonsTestObjectController {
 	protected Model model;
 	protected MultiPurposeController mp;
 	protected CategoryController cg;
+	protected CanvasController cvs;
 	protected ObjectController controller;
 
 	@Before
@@ -27,6 +30,7 @@ public class praktikumHolonsTestObjectController {
 		model = new Model();
 		mp = new MultiPurposeController(model);
 		cg = new CategoryController(model, mp);
+		cvs = new CanvasController(model, mp);
 		controller = new ObjectController(model, mp);
 	}
 
@@ -46,17 +50,19 @@ public class praktikumHolonsTestObjectController {
 		assertTrue("Non-Existant Element is Found",
 				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "") == null);
 	}
-	
+
 	@Test
 	public void testAddingAndDeletingInCategory() {
 		controller.addNewElementIntoCategoryObject("Building", "House", "A", 1, -10);
 		for (int i = 2; i < 27; i++) {
 			controller.addNewElementIntoCategoryObject("Building", "House", adapter.generate(i), i, -10);
-			// n(n+1) / 2 
-			assertTrue("Total Energy does not match",((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House")).getCurrentEnergy() == -1800 + ((i* (i+1)) / 2) * -10);
-			assertTrue("Number of Elements does not Match", ((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House")).getElements().size() == 6+i);
+			// n(n+1) / 2
+			assertTrue("Total Energy does not match", ((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"))
+					.getCurrentEnergy() == -1800 + ((i * (i + 1)) / 2) * -10);
+			assertTrue("Number of Elements does not Match",
+					((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House")).getElements().size() == 6 + i);
 		}
-		
+
 		controller.deleteElementInCategory("Building", "House", "B");
 		controller.deleteElementInCategory("Building", "House", "D");
 		controller.deleteElementInCategory("Building", "House", "F");
@@ -65,19 +71,50 @@ public class praktikumHolonsTestObjectController {
 		controller.deleteElementInCategory("Building", "House", "I");
 		controller.deleteElementInCategory("Building", "House", "Z");
 		controller.deleteElementInCategory("Building", "House", "TV");
-		assertTrue("Element:B was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "B") == null);
-		assertTrue("Element:D was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "D") == null);
-		assertTrue("Element:F was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "F") == null);
-		assertTrue("Element:G was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "G") == null);
-		assertTrue("Element:H was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "H") == null);
-		assertTrue("Element:I was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "I") == null);
-		assertTrue("Element:Z was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "Z") == null);
-		assertTrue("Element:TV was not Found", mp.searchEle((HolonObject)mp.searchCatObj(mp.searchCat("Building"), "House"), "TV") == null);
+		assertTrue("Element:B was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "B") == null);
+		assertTrue("Element:D was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "D") == null);
+		assertTrue("Element:F was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "F") == null);
+		assertTrue("Element:G was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "G") == null);
+		assertTrue("Element:H was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "H") == null);
+		assertTrue("Element:I was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "I") == null);
+		assertTrue("Element:Z was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "Z") == null);
+		assertTrue("Element:TV was Found",
+				mp.searchEle((HolonObject) mp.searchCatObj(mp.searchCat("Building"), "House"), "TV") == null);
 	}
-	
+
 	@Test
 	public void testAddingAndDeletingInCanvas() {
-		
+		for (int i = 0; i < 100; i++) {
+			cvs.addNewObject(new HolonObject(mp.searchCatObj(mp.searchCat("Building"), "House")));
+		}
+		for (CpsObject cps : model.getObjectsOnCanvas()) {
+			for (int i = 0; i < 27; i++) {
+				controller.addNewElementIntoCanvasObject(cps.getID(), adapter.generate(i), 1, -100);
+				assertTrue("Element:" + adapter.generate(i) + " was not Created", mp
+						.searchEle((HolonObject) mp.searchByID(cps.getID()), adapter.generate(i)) != null);
+			}
+			assertTrue("Element:B was not Found", mp
+					.searchEle((HolonObject) mp.searchByID(cps.getID()), "B") != null);
+			assertTrue("Element:D was not Found", mp
+					.searchEle((HolonObject) mp.searchByID(cps.getID()), "D") != null);
+			assertTrue("Element:F was not Found", mp
+					.searchEle((HolonObject) mp.searchByID(cps.getID()), "F") != null);
+			assertTrue("Element:G was not Found", mp
+					.searchEle((HolonObject) mp.searchByID(cps.getID()), "G") != null);
+			assertTrue("Element:H was not Found", mp
+					.searchEle((HolonObject) mp.searchByID(cps.getID()), "H") != null);
+			assertTrue("Element:I was not Found", mp
+					.searchEle((HolonObject) mp.searchByID(cps.getID()), "I") != null);
+			assertTrue("Element:B was not Found", mp
+					.searchEle((HolonObject) mp.searchByID(cps.getID()), "B") != null);	
+		}
 	}
-	
+
 }

+ 5 - 0
src/tests/praktikumHolonsTestStoreController.java

@@ -0,0 +1,5 @@
+package tests;
+
+public class praktikumHolonsTestStoreController {
+
+}

+ 14 - 1
src/ui/controller/ConsoleController.java

@@ -2,6 +2,9 @@ package ui.controller;
 
 import java.awt.Color;
 
+import javax.swing.text.BadLocationException;
+import javax.swing.text.StyleConstants;
+
 import ui.model.Model;
 import ui.view.Console;
 
@@ -14,7 +17,7 @@ public class ConsoleController {
 	}
 
 	/**
-	 * Getter for selected CpsObject
+	 * Print Text on the console
 	 *
 	 * @param text
 	 *            String the Text
@@ -34,6 +37,16 @@ public class ConsoleController {
 	public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
 		MODEL.getConsole().addText(text, color, p, bold, italic, nl);
 	}
+	
+	/**
+	 * Print Text on the console in black and font size 12
+	 *
+	 * @param text
+	 *            String the Text
+	 */
+	public void addTextToConsole(String text) {
+		MODEL.getConsole().addText(text);
+	}
 
 	/**
 	 * Clears the console

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

@@ -313,6 +313,16 @@ public class Control {
 	public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
 		consoleController.addTextToConsole(text, color, p, bold, italic, nl);
 	}
+	
+	/**
+	 * Print Text on the console in black and font size 12
+	 *
+	 * @param text
+	 *            String the Text
+	 */
+	public void addTextToConsole(String text) {
+		consoleController.addTextToConsole(text);
+	}
 
 	/**
 	 * Clears the console

+ 63 - 2
src/ui/view/Console.java

@@ -1,7 +1,12 @@
 package ui.view;
 
 import java.awt.Color;
-
+import java.awt.Toolkit;
+import java.awt.datatransfer.StringSelection;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import javax.swing.JScrollPane;
 
 import java.awt.BorderLayout;
@@ -10,7 +15,9 @@ import javax.swing.text.BadLocationException;
 import javax.swing.text.Style;
 import javax.swing.text.StyleConstants;
 import javax.swing.text.StyledDocument;
+import javax.swing.JMenuItem;
 import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
 
 public class Console extends JScrollPane {
 
@@ -23,6 +30,11 @@ public class Console extends JScrollPane {
 	private Style style;
 	private StyledDocument doc;
 
+	// PopUpMenu
+	private JPopupMenu popmenu = new JPopupMenu();
+	private JMenuItem itemCopy = new JMenuItem("Copy");
+	private JMenuItem itemClear = new JMenuItem("Clear Console");
+
 	public Console() {
 		super();
 		this.setBackground(Color.WHITE);
@@ -37,11 +49,42 @@ public class Console extends JScrollPane {
 		panel.setLayout(new BorderLayout(0, 0));
 		panel.setBackground(Color.WHITE);
 		panel.add(consoleText);
+
 		setViewportView(panel);
+
+		// PopUpMenu
+		popmenu.add(itemCopy);
+		popmenu.add(itemClear);
+
+		itemCopy.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				Toolkit.getDefaultToolkit().getSystemClipboard()
+						.setContents(new StringSelection(consoleText.getSelectedText()), null);
+			}
+		});
+
+		itemClear.addActionListener(new ActionListener() {
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				clearConsole();
+			}
+		});
+
+		// MouseListener
+		consoleText.addMouseListener(new MouseAdapter() {
+			@Override
+			public void mouseReleased(MouseEvent e) {
+				if (e.getButton() == e.BUTTON3) {
+					itemClear.setEnabled(!consoleText.getText().isEmpty());
+					popmenu.show(e.getComponent(), e.getX(), e.getY());
+				}
+			}
+		});
 	}
 
 	/**
-	 * Getter for selected CpsObject
+	 * Print Text on the console
 	 *
 	 * @param text
 	 *            String the Text
@@ -73,6 +116,24 @@ public class Console extends JScrollPane {
 		}
 	}
 
+	/**
+	 * Print Text on the console in black and font size 12
+	 *
+	 * @param text
+	 *            String the Text
+	 */
+	public void addText(String text) {
+		StyleConstants.setForeground(style, Color.BLACK);
+		StyleConstants.setFontSize(style, 12);
+		StyleConstants.setBold(style, false);
+		StyleConstants.setItalic(style, false);
+
+		try {
+			doc.insertString(doc.getLength(), text + "\n", style);
+		} catch (BadLocationException e) {
+		}
+	}
+
 	/**
 	 * Clears the console
 	 */

+ 48 - 75
src/ui/view/GUI.java

@@ -202,9 +202,6 @@ public class GUI<E> implements CategoryListener {
 	private final JLabel lblImageSize = new JLabel("Image Size");
 	// Time Stuff
 	private TimePanel timePanel;
-	private final JMenu mnAlgorithm = new JMenu("Algorithm");
-	private final JCheckBoxMenuItem chckbxmntmUseAlgorithm = new JCheckBoxMenuItem("Use Algorithm");
-	private final JComboBox comboBoxAlgo = new JComboBox();
 	// Coord for all Cells with text
 	private int yTHIS;
 	private int xTHIS;
@@ -219,10 +216,6 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
 	private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
 	private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
-	private final JMenuItem mntmSetFolder = new JMenuItem("Set Folder");
-	private final JMenu mnSimulationSpeed = new JMenu("Simulation Speed");
-	private final JTextField simulationSpeedField = new JTextField();
-	private final JButton btnApply = new JButton("Apply");
 
 	/**
 	 * Create the application.
@@ -245,7 +238,6 @@ public class GUI<E> implements CategoryListener {
 	 */
 	@SuppressWarnings({ "serial", "unchecked" })
 	private void initialize() {
-		simulationSpeedField.setColumns(10);
 		frmCyberPhysical = new JFrame();
 		frmCyberPhysical.setTitle("Cyber Physical Systems Model");
 		frmCyberPhysical.setBounds(100, 100, 1000, 800);
@@ -381,6 +373,21 @@ public class GUI<E> implements CategoryListener {
 				unitGraph.empty();
 			}
 		});
+		
+		String cntrlFDown = "controlF";
+		inputMap.put(KeyStroke.getKeyStroke("control F"), cntrlFDown);
+		actionMap.put(cntrlFDown, new AbstractAction() {
+
+			@Override
+			public void actionPerformed(ActionEvent e) {
+				searchPopUp dialog = new searchPopUp(controller, canvas);
+				dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+				dialog.setVisible(true);
+			}
+		});
+
+		
+		
 
 		String cntrlCDown = "controlC";
 		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
@@ -483,10 +490,6 @@ public class GUI<E> implements CategoryListener {
 		mnNewMenu_2.add(mntmEditEdges);
 
 		mnNewMenu_2.add(mntmResetCategory);
-
-		mnNewMenu_2.add(mnSimulationSpeed);
-
-		mnSimulationSpeed.add(simulationSpeedField);
 		mntmResetCategory.addActionListener(new ActionListener() {
 
 			@Override
@@ -527,7 +530,7 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public void stateChanged(ChangeEvent e) {
 				controller.setScale(sizeSlider.getValue());
-				tree.setRowHeight(model.getScale());
+				tree.setRowHeight(50);
 				canvas.objectSelectionHighlighting();
 				canvas.repaint();
 			}
@@ -540,12 +543,6 @@ public class GUI<E> implements CategoryListener {
 
 		mnHelp.add(aboutUs);
 
-		menuBar.add(mnAlgorithm);
-
-		mnAlgorithm.add(mntmSetFolder);
-
-		mnAlgorithm.add(chckbxmntmUseAlgorithm);
-
 		canvas.setBackground(Color.WHITE);
 		canvas.setPreferredSize(new Dimension(1000, 1000));
 
@@ -641,6 +638,7 @@ public class GUI<E> implements CategoryListener {
 							controller.calculateStateForTimeStep(model.getCurIteration());
 							// Names displayed in graph are not updated
 						}
+						eleToDelete.clear();
 						selectedElements.clear();
 					}
 					// For MultiSelection of CpsObject
@@ -652,7 +650,11 @@ public class GUI<E> implements CategoryListener {
 					}
 					refreshTableHolonElement();
 					refreshTableProperties();
+					eleToDelete.clear();
+					selectedElements.clear();
 				}
+				elementGraph.setText("None ");
+				holonEleNamesDisplayed = "None ";
 			}
 		});
 		/*
@@ -819,9 +821,17 @@ public class GUI<E> implements CategoryListener {
 							if (mousePos.y / tableProperties.getRowHeight() == 2) {
 								Boolean bTemp = Boolean.parseBoolean(temp.toString());
 								((HolonSwitch) getActualCps()).setManualMode(bTemp);
+								if (bTemp) {
+									tableModelProperties.setCellEditable(3, 1, true);
+								} else {
+									tableModelProperties.setCellEditable(3, 1, false);
+								}
 							} else if (mousePos.y / tableProperties.getRowHeight() == 3) {
-								Boolean bTemp = Boolean.parseBoolean(temp.toString());
-								((HolonSwitch) getActualCps()).setActiveAt(bTemp);
+								if (((HolonSwitch) getActualCps()).getManualMode()) {
+									tableModelProperties.setCellEditable(3, 1, true);
+									Boolean bTemp = Boolean.parseBoolean(temp.toString());
+									((HolonSwitch) getActualCps()).setManualState(bTemp);
+								}
 							}
 						}
 					} else {
@@ -879,10 +889,10 @@ public class GUI<E> implements CategoryListener {
 								File checkPath = new File(cps.getImage());
 								if (checkPath.exists()) {
 									imgR = new ImageIcon(cps.getImage()).getImage().getScaledInstance(
-											controller.getScale(), controller.getScale(), java.awt.Image.SCALE_SMOOTH);
+											50, 50, java.awt.Image.SCALE_SMOOTH);
 								} else {
 									imgR = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
-											.getScaledInstance(controller.getScale(), controller.getScale(),
+											.getScaledInstance(50, 50,
 													java.awt.Image.SCALE_SMOOTH);
 								}
 								if (imgR != null) {
@@ -893,7 +903,7 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 				}
-				tree.setRowHeight(model.getScale());
+				tree.setRowHeight(50);
 				if (hasFocus) {
 					label.setForeground(new Color(0, 0, 255));
 					label.setOpaque(true);
@@ -986,11 +996,11 @@ public class GUI<E> implements CategoryListener {
 									File checkPath = new File(cps.getImage());
 									if (checkPath.exists()) {
 										img = new ImageIcon(cps.getImage()).getImage().getScaledInstance(
-												controller.getScale(), controller.getScale(),
+												50, 50,
 												java.awt.Image.SCALE_SMOOTH);
 									} else {
 										img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
-												.getScaledInstance(controller.getScale(), controller.getScale(),
+												.getScaledInstance(50, 50,
 														java.awt.Image.SCALE_SMOOTH);
 									}
 									tempCps = cps;
@@ -1127,15 +1137,22 @@ public class GUI<E> implements CategoryListener {
 					else if (temp instanceof HolonSwitch) {
 						deleteRows(tableModelHolonElementSingle);
 						deleteRows(tableModelHolonElementMulti);
-						Object[] tempMode = { "Mode", ((HolonSwitch) temp).getManualMode() };
+						Object[] tempMode = { "Manual", ((HolonSwitch) temp).getManualMode() };
 						tableModelProperties.addRow(tempMode);
-						Object[] tempActive = { "Active", ((HolonSwitch) temp).getActiveAt()[model.getCurIteration()] };
-						tableModelProperties.addRow(tempActive);
+						if (((HolonSwitch) temp).getManualMode()) {
+							Object[] tempActive = { "Active", ((HolonSwitch) temp).getActiveManual() };
+							tableModelProperties.addRow(tempActive);
+							tableModelProperties.setCellEditable(3, 1, true);
+						} else {
+							Object[] tempActive = { "Active",
+									((HolonSwitch) temp).getActiveAt()[model.getCurIteration()] };
+							tableModelProperties.addRow(tempActive);
+							tableModelProperties.setCellEditable(3, 1, false);
+						}
 						unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
 						elementGraph.setText(temp.getName());
 						tableModelProperties.setCellEditable(0, 1, true);
 						tableModelProperties.setCellEditable(2, 1, true);
-						tableModelProperties.setCellEditable(3, 1, true);
 					} else {
 						deleteRows(tableModelHolonElementSingle);
 						deleteRows(tableModelHolonElementMulti);
@@ -1183,7 +1200,7 @@ public class GUI<E> implements CategoryListener {
 					Object[] tempCapacity = { "Max. Capacity", model.getSelectedEdge().getCapacity() };
 					tableModelProperties.addRow(tempCapacity);
 					// Status displayed
-					Object[] tempStatus = { "Status", model.getSelectedEdge().getStateEdge() };
+					Object[] tempStatus = { "Status", model.getSelectedEdge().getState() };
 					tableModelProperties.addRow(tempStatus);
 					// For edges, the only possible editable cell is the max
 					// flow
@@ -1416,34 +1433,6 @@ public class GUI<E> implements CategoryListener {
 
 		});
 
-		mntmSetFolder.addActionListener(new java.awt.event.ActionListener() {
-
-			@Override
-			public void actionPerformed(java.awt.event.ActionEvent evt) {
-
-				menuSetFolderActionPerformed(evt);
-
-			}
-
-			private void menuSetFolderActionPerformed(java.awt.event.ActionEvent evt) {
-				JFileChooser fileChooser = new JFileChooser();
-				JFrame test = new JFrame();
-				fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
-				fileChooser.setAcceptAllFileFilterUsed(false);
-
-				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
-					comboBoxAlgo.removeAllItems();
-					File[] files = fileChooser.getSelectedFile().listFiles();
-					for (int i = 0; i < files.length; i++) {
-						if (files[i].toString().endsWith(".java") || files[i].toString().endsWith(".class")) {
-							comboBoxAlgo.addItem(files[i]);
-						}
-					}
-				}
-			}
-
-		});
-
 		timePanel = new TimePanel(model, controller);
 		timePanel.setBorder(null);
 		((JSlider) (timePanel.getComponent(1))).addChangeListener(new ChangeListener() {
@@ -1490,22 +1479,6 @@ public class GUI<E> implements CategoryListener {
 		tableHolonElementScrollPane.setBorder(null);
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
-
-		simulationSpeedField.setText(Integer.toString(model.getTimerSpeed()));
-		btnApply.addActionListener(new ActionListener() {
-			public void actionPerformed(ActionEvent e) {
-				int speed = Integer.parseInt(simulationSpeedField.getText());
-				controller.setTimerSpeed(speed);
-				mnSimulationSpeed.setPopupMenuVisible(false);
-			}
-		});
-
-		mnSimulationSpeed.add(btnApply);
-		menuBar.add(comboBoxAlgo);
-
-		Dimension height = comboBoxAlgo.getPreferredSize();
-		comboBoxAlgo.setPreferredSize(new Dimension(200, (int) height.getHeight()));
-		comboBoxAlgo.setMaximumSize(comboBoxAlgo.getPreferredSize());
 	}
 
 	/*

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

@@ -196,7 +196,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		}
 
 		// Highlighted Edge
-		if (model.getSelectedObjectID() > 0) {
+		if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !TempSelected.isEmpty()) {
 			g2.setColor(Color.BLUE);
 			for (CpsEdge con : model.getEdgesOnCanvas()) {
 				if (con.getFlow() <= con.getCapacity()) {
@@ -205,7 +205,10 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					g2.setStroke(new BasicStroke(2));
 				}
 				if (con.getA().getID() == model.getSelectedObjectID()
-						|| con.getB().getID() == model.getSelectedObjectID() && con != edgeHighlight) {
+						|| model.getSelectedCpsObjects().contains(con.getA()) || TempSelected.contains(con.getA())
+						|| con.getB().getID() == model.getSelectedObjectID()
+						|| model.getSelectedCpsObjects().contains(con.getB())
+						|| TempSelected.contains(con.getB()) && con != edgeHighlight) {
 					g2.drawLine(con.getA().getPosition().x + controller.getScaleDiv2(),
 							con.getA().getPosition().y + controller.getScaleDiv2(),
 							con.getB().getPosition().x + controller.getScaleDiv2(),
@@ -256,17 +259,17 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
 						(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
 			}
-			
 
 			// node image
-			if (cps instanceof CpsNode && (model.getSelectedCpsObjects().contains(cps) || TempSelected.contains(cps))) {
+			if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
+					|| model.getSelectedCpsObjects().contains(cps) || TempSelected.contains(cps))) {
 				img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
 			} else {
 				if (cps instanceof HolonSwitch) {
 					if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
-						((HolonSwitch) cps).setState(true);
+						((HolonSwitch) cps).setAutoState(true);
 					} else {
-						((HolonSwitch) cps).setState(false);
+						((HolonSwitch) cps).setAutoState(false);
 					}
 				}
 				// Highlighting
@@ -510,8 +513,9 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					y1 = y;
 					y2 = sy;
 				}
-				if (x1 <= cps.getPosition().x+model.getScaleDiv2() && y1 <= cps.getPosition().y+model.getScaleDiv2() && x2 >= cps.getPosition().x+model.getScaleDiv2()
-						&& y2 >= cps.getPosition().y+model.getScaleDiv2()) {
+				if (x1 <= cps.getPosition().x + model.getScaleDiv2() && y1 <= cps.getPosition().y + model.getScaleDiv2()
+						&& x2 >= cps.getPosition().x + model.getScaleDiv2()
+						&& y2 >= cps.getPosition().y + model.getScaleDiv2()) {
 					TempSelected.add(cps);
 
 				}

+ 86 - 44
src/ui/view/SimulationMenu.java

@@ -1,6 +1,9 @@
 package ui.view;
 
+import javax.swing.JButton;
 import javax.swing.JComboBox;
+import javax.swing.JFileChooser;
+import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenuBar;
 import javax.swing.JPanel;
@@ -11,17 +14,29 @@ import javax.swing.event.CaretListener;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
+import com.sun.crypto.provider.JceKeyStore;
+
+import classes.CpsObject;
+import classes.HolonObject;
+import classes.HolonSwitch;
+import classes.HolonTransformer;
 import ui.controller.Control;
 import ui.model.Model;
 import java.util.ArrayList;
-
+import java.util.HashMap;
 import java.awt.GridBagLayout;
 import java.awt.Color;
+import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.Insets;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
+import java.io.File;
+import java.awt.FlowLayout;
 
 public class SimulationMenu extends JMenuBar {
 	/**
@@ -29,61 +44,71 @@ public class SimulationMenu extends JMenuBar {
 	 */
 	private static final long serialVersionUID = 1L;
 
-	// Components
-	private JPanel simMenuPanel = new JPanel();
+	private JPanel menuPanel = new JPanel();
 	private JRadioButton simButton = new JRadioButton("Simulate");
 	private JLabel simSpeedLabel = new JLabel("Simulation Speed:");
 	private JTextField simSpeedText = new JTextField("1000");
-	private JLabel algoLabel = new JLabel("Algorithm:");
-	private JComboBox algoCombo;
-	private ArrayList<String> algos = new ArrayList<>();
-
+	private JComboBox algoCombo = new JComboBox<>();
+	private JButton algoFolderButton = new JButton("Algorithm:");
+	private HashMap<String, File> algosHash = new HashMap<>();
+	
 	Model model;
 	Control controller;
-	
+
 	public SimulationMenu(Model mod, Control cont) {
 		super();
 		// Init Stuff
 		this.model = mod;
 		this.controller = cont;
-		
-		//AlgoCombobox Items
-		algos.add("algorithm1");
-		algos.add("algorithm2");
-		algos.add("algorithm3");
-		
-		//timerSpeed
-		simSpeedText.setMaximumSize(new Dimension(300, 300));
-		simSpeedText.addCaretListener(new CaretListener() {
+
+		// algoFolderButton Action
+		algoFolderButton.addActionListener(new ActionListener() {
+
 			@Override
-			public void caretUpdate(CaretEvent e) {
-				try {
-					controller.setTimerSpeed(Integer.parseInt(simSpeedText.getText()));
-				} catch (Exception e2) {
-					// TODO: handle exception
+			public void actionPerformed(java.awt.event.ActionEvent evt) {
+				menuSetFolderActionPerformed(evt);
+			}
+
+			private void menuSetFolderActionPerformed(java.awt.event.ActionEvent evt) {
+				JFileChooser fileChooser = new JFileChooser();
+				JFrame test = new JFrame();
+				fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
+				fileChooser.setAcceptAllFileFilterUsed(false);
+
+				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
+					algoCombo.removeAllItems();
+					File[] files = fileChooser.getSelectedFile().listFiles();
+					for (int i = 0; i < files.length; i++) {
+						if (files[i].toString().endsWith(".java") || files[i].toString().endsWith(".class")) {
+							String name = files[i].toString();
+							int tmpA = name.lastIndexOf('/');
+							int tmpB = name.lastIndexOf('.');
+							name = name.substring(tmpA+1, tmpB);
+							algosHash.put(name, files[i]);
+							algoCombo.addItem(name);
+						}
+					}
 				}
-				
 			}
+
 		});
-		
-		//isSimulation
+
+		// Add to Panel
+		GridBagLayout gbl_menuPanel = new GridBagLayout();
+		gbl_menuPanel.columnWidths = new int[] { 79, 105, 34, 60, 31, 151, 0 };
+		gbl_menuPanel.rowHeights = new int[] { 25, 0 };
+		gbl_menuPanel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
+		gbl_menuPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
+		menuPanel.setLayout(gbl_menuPanel);
+
+		// isSimulation
 		simButton.addPropertyChangeListener(new PropertyChangeListener() {
-			
+
 			@Override
 			public void propertyChange(PropertyChangeEvent evt) {
 				controller.setIsSimulation(simButton.isSelected());
 			}
 		});
-		
-		// Add to Panel
-		JPanel menuPanel = new JPanel();
-		GridBagLayout gbl_t = new GridBagLayout();
-		gbl_t.columnWidths = new int[] { 79, 109, 46, 64, 31, 0 };
-		gbl_t.rowHeights = new int[] { 25, 0 };
-		gbl_t.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
-		gbl_t.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
-		menuPanel.setLayout(gbl_t);
-
 		GridBagConstraints gbc_simButton = new GridBagConstraints();
 		gbc_simButton.anchor = GridBagConstraints.NORTHWEST;
 		gbc_simButton.insets = new Insets(0, 0, 0, 5);
@@ -96,25 +121,42 @@ public class SimulationMenu extends JMenuBar {
 		gbc_simSpeedLabel.gridx = 1;
 		gbc_simSpeedLabel.gridy = 0;
 		menuPanel.add(simSpeedLabel, gbc_simSpeedLabel);
+
+		// timerSpeed
+		simSpeedText.setMaximumSize(new Dimension(300, 300));
+		simSpeedText.addCaretListener(new CaretListener() {
+			@Override
+			public void caretUpdate(CaretEvent e) {
+				try {
+					controller.setTimerSpeed(Integer.parseInt(simSpeedText.getText()));
+				} catch (Exception e2) {
+					// TODO: handle exception
+				}
+
+			}
+		});
 		GridBagConstraints gbc_simSpeedText = new GridBagConstraints();
 		gbc_simSpeedText.anchor = GridBagConstraints.WEST;
 		gbc_simSpeedText.insets = new Insets(0, 0, 0, 5);
 		gbc_simSpeedText.gridx = 2;
 		gbc_simSpeedText.gridy = 0;
 		menuPanel.add(simSpeedText, gbc_simSpeedText);
-		GridBagConstraints gbc_algoLabel = new GridBagConstraints();
-		gbc_algoLabel.anchor = GridBagConstraints.WEST;
-		gbc_algoLabel.insets = new Insets(0, 0, 0, 5);
-		gbc_algoLabel.gridx = 3;
-		gbc_algoLabel.gridy = 0;
-		menuPanel.add(algoLabel, gbc_algoLabel);
-
-		algoCombo = new JComboBox<Object>(algos.toArray());
+		GridBagConstraints gbc_algoFolderButton = new GridBagConstraints();
+		gbc_algoFolderButton.anchor = GridBagConstraints.WEST;
+		gbc_algoFolderButton.insets = new Insets(0, 0, 0, 5);
+		gbc_algoFolderButton.gridx = 3;
+		gbc_algoFolderButton.gridy = 0;
+		menuPanel.add(algoFolderButton, gbc_algoFolderButton);
+
 		GridBagConstraints gbc_algoCombo = new GridBagConstraints();
 		gbc_algoCombo.anchor = GridBagConstraints.WEST;
+		gbc_algoCombo.insets = new Insets(0, 0, 0, 5);
 		gbc_algoCombo.gridx = 4;
 		gbc_algoCombo.gridy = 0;
 		menuPanel.add(algoCombo, gbc_algoCombo);
+		algoCombo.addItem("choose folder");
+		
+		//Add Panel to SimulationMenu
 		this.add(menuPanel);
 	}
 }

+ 75 - 13
src/ui/view/searchPopUp.java

@@ -34,9 +34,11 @@ public class searchPopUp extends JDialog {
 	private JRadioButton rdbtnBackward;
 	private JRadioButton rdbtnAll;
 	private JRadioButton rdbtnSingle;
+	private int idx;
 
 	searchPopUp(Control contr, MyCanvas can) {
 		super((java.awt.Frame) null, true);
+		idx = -1;
 		setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
 		this.setTitle("Search for Objects");
 		setBounds(100, 100, 238, 360);
@@ -115,17 +117,25 @@ public class searchPopUp extends JDialog {
 						}
 
 					}
-					canvas.repaint();
+
 				}
 				if (rdbtnSingle.isSelected()) {
+					controller.getModel().getSelectedCpsObjects().clear();
 
-					if (rdbtnForward.isSelected()) {
+					if (!controller.getModel().getObjectsOnCanvas().isEmpty() && !findTextField.getText().isEmpty()) {
 
+						if (rdbtnForward.isSelected()) {
+							if ((idx = getNext(++idx)) != -1)
+								controller.getModel().getSelectedCpsObjects().add(getObj(idx));
+						} else if (rdbtnBackward.isSelected()) {
+							if ((idx = getPrev(--idx)) != -1)
+								controller.getModel().getSelectedCpsObjects().add(getObj(idx));
+						}
 					}
-					if (rdbtnBackward.isSelected()) {
 
-					}
 				}
+
+				canvas.repaint();
 			}
 		});
 		btnFind.setFont(new Font("Tahoma", Font.PLAIN, 13));
@@ -136,12 +146,10 @@ public class searchPopUp extends JDialog {
 		JButton btnReplace = new JButton("Replace");
 		btnReplace.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent e) {
-				System.out.println("ID:" + controller.getModel().getSelectedObjectID());
-				System.out.println("SIZE:" + controller.getModel().getSelectedCpsObjects().size());
-				System.out.println(controller.searchByID(controller.getModel().getSelectedObjectID()).getName());
-				System.out.println(controller.getModel().getObjectsOnCanvas().get(0).getName());
-				
-				// controller.searchByID(controller.getModel().getSelectedObjectID()).setName(replaceTextField.getText());
+
+				if (controller.getModel().getSelectedCpsObjects().size() == 1 && controller.getModel()
+						.getSelectedCpsObjects().get(0).getName().equals(findTextField.getText()))
+					controller.getModel().getSelectedCpsObjects().get(0).setName(replaceTextField.getText());
 				canvas.repaint();
 			}
 		});
@@ -156,7 +164,7 @@ public class searchPopUp extends JDialog {
 				canvas.tempCps = null;
 				canvas.TempSelected = new ArrayList<>();
 				controller.getModel().getSelectedCpsObjects().clear();
-				
+
 				for (CpsObject cps : controller.getModel().getObjectsOnCanvas()) {
 					if (cps.getName().equals(findTextField.getText())
 							&& !controller.getModel().getSelectedCpsObjects().contains(cps))
@@ -178,8 +186,6 @@ public class searchPopUp extends JDialog {
 		JButton btnClose = new JButton("Close");
 		btnClose.addActionListener(new ActionListener() {
 			public void actionPerformed(ActionEvent arg0) {
-
-
 				dispose();
 			}
 		});
@@ -197,11 +203,67 @@ public class searchPopUp extends JDialog {
 
 	}
 
+	/**
+	 * 
+	 * @param obj
+	 */
 	public void selectObj(CpsObject obj) {
 		controller.getModel().getSelectedCpsObjects().add(obj);
 	}
 
+	/**
+	 * 
+	 * @param obj
+	 * @param name
+	 */
 	public void renameObj(CpsObject obj, String name) {
 		obj.setName(name);
 	}
+
+	/**
+	 * 
+	 * @param idx
+	 * @return
+	 */
+	public CpsObject getObj(int idx) {
+		return controller.getModel().getObjectsOnCanvas().get(idx);
+	}
+
+	/**
+	 * 
+	 * @param idx
+	 * @return
+	 */
+	public int getNext(int idx) {
+		for (int i = idx; i < controller.getModel().getObjectsOnCanvas().size(); i++) {
+			if (getObj(i).getName().equals(findTextField.getText())
+					&& !controller.getModel().getSelectedCpsObjects().contains(getObj(i)))
+				return i;
+		}
+		for (int i = 0; i < idx; i++) {
+			if (getObj(i).getName().equals(findTextField.getText())
+					&& !controller.getModel().getSelectedCpsObjects().contains(getObj(i)))
+				return i;
+		}
+		return -1;
+	}
+
+	/**
+	 * 
+	 * @param idx
+	 * @return
+	 */
+	public int getPrev(int idx) {
+		for (int i = idx; i >= 0; i--) {
+			if (getObj(i).getName().equals(findTextField.getText())
+					&& !controller.getModel().getSelectedCpsObjects().contains(getObj(i)))
+				return i;
+		}
+		for (int i = controller.getModel().getObjectsOnCanvas().size() - 1; i > idx; i--) {
+			if (getObj(i).getName().equals(findTextField.getText())
+					&& !controller.getModel().getSelectedCpsObjects().contains(getObj(i)))
+				return i;
+		}
+		return -1;
+	}
 }