Browse Source

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

dominik.rieder 7 years ago
parent
commit
86571e63e2

+ 6 - 0
src/classes/HolonElement.java

@@ -72,6 +72,12 @@ public class HolonElement {
 		setActive(element.getActive());
 		setSign(element.getEnergy());
 		setEnergyAt(element.getEnergy());
+		for (int i = 0; i < energyAt.length; i++) {
+			energyAt[i] = element.getEnergyAt()[i];
+		}
+		for (Point p :element.getGraphPoints()) {
+			this.graphPoints.add(new Point((int)p.getX(), (int)p.getY()));
+		}
 		setSav("CVS");
 		setObj(element.getObj());
 		setId(IdCounterElem.nextId());

+ 8 - 3
src/classes/HolonSwitch.java

@@ -68,10 +68,15 @@ public class HolonSwitch extends AbstractCpsObject {
 	public HolonSwitch(AbstractCpsObject obj) {
 		super(obj);
 		super.setName(obj.getName());
-		setManualState(true);
+		setManualState(((HolonSwitch)obj).getActiveManual());
 		setAutoState(true);
-		setActiveAt(true);
-		setManualMode(false);
+		for (int i = 0; i < activeAt.length; i++) {
+			activeAt[i] = ((HolonSwitch)obj).getActiveAt()[i];
+		}
+		for (Point p :((HolonSwitch)obj).getGraphPoints()) {
+			this.graphPoints.add(new Point((int)p.getX(), (int)p.getY()));
+		}
+		setManualMode(((HolonSwitch)obj).getManualMode());
 	}
 
 	/**

+ 0 - 1
src/tests/PraktikumHolonsTestGlobalController.java

@@ -19,7 +19,6 @@ public class PraktikumHolonsTestGlobalController {
 	protected Model model;
 	protected GlobalController controller;
 
-
 	/**
 	 * Setup.
 	 */

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

@@ -141,7 +141,6 @@ public class CanvasController {
 	 *            the mouse Position
 	 */
 	public void pasteObjects(Point p) {
-		System.out.println("paste");
 		model.getSelectedCpsObjects().clear();
 		AbstractCpsObject tCps = null;
 		int x = Integer.MAX_VALUE, y = Integer.MAX_VALUE;
@@ -176,7 +175,6 @@ public class CanvasController {
 		// Edges
 		boolean newEdge = true;
 		for (AbstractCpsObject cps : model.getClipboradObjects()) {
-			System.out.println("Object edges: " + cps.getConnectedTo().size());
 			for (CpsEdge e : cps.getConnectedTo()) {
 				// A and B of e in the copied Elements?
 				if (model.getClipboradObjects().indexOf(e.getA()) != -1
@@ -187,19 +185,16 @@ public class CanvasController {
 					for (CpsEdge et : tempList.get(model.getClipboradObjects().indexOf(cps)).getConnectedTo()) {
 						for (CpsEdge etA : et.getA().getConnectedTo()) {
 							if (et.getA() == a && et.getB() == b) {
-								System.out.println("false");
 								newEdge = false;
 							}
 						}
 						for (CpsEdge etB : et.getB().getConnectedTo()) {
 							if (et.getA() == a && et.getB() == b) {
-								System.out.println("false");
 								newEdge = false;
 							}
 						}
 					}
 					if (newEdge) {
-						System.out.println("new edge");
 						CpsEdge tempE = new CpsEdge(tempList.get(model.getClipboradObjects().indexOf(e.getA())), // A
 								tempList.get(model.getClipboradObjects().indexOf(e.getB())), /* B */
 								e.getCapacity());

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

@@ -640,4 +640,24 @@ public class Control {
 	public void setIsSimulation(boolean b) {
 		globalController.setIsSimulation(b);
 	}
+	
+	/**
+	 * Set the Canvas X Size.
+	 * 
+	 * @param canvasX the cANVAS_X to set
+	 */
+	public void setCanvasX(int canvasX) {
+		globalController.setCanvasX(canvasX);
+	}
+
+
+	/**
+	 * Set the Canvas Y Size.
+	 * 
+	 * @param canvasY the cANVAS_Y to set
+	 */
+	public void setCanvasY(int canvasY) {
+		globalController.setCanvasY(canvasY);
+	}
+	
 }

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

@@ -98,4 +98,22 @@ public class GlobalController {
 		model.setIsSimulation(b);
 	}
 
+	/**
+	 * Set the Canvas X Size.
+	 * 
+	 * @param canvasX the cANVAS_X to set
+	 */
+	public void setCanvasX(int canvasX) {
+		model.setCanvasX(canvasX);
+	}
+
+
+	/**
+	 * Set the Canvas Y Size.
+	 * 
+	 * @param canvasY the cANVAS_Y to set
+	 */
+	public void setCanvasY(int canvasY) {
+		model.setCanvasY(canvasY);
+	}
 }

+ 2 - 0
src/ui/controller/StoreController.java

@@ -54,6 +54,8 @@ public class StoreController {
 
 		json.put("MODE", "ALL");
 		json.put("ID", IdCounter.getCounter());
+		json.put("SIZEX", model.getCanvasX());
+		json.put("SIZEY", model.getCanvasY());
 		writeCategory(json);
 		writeCategoryObjects(json);
 		writeCanvasObjects(json);

+ 38 - 0
src/ui/model/Model.java

@@ -23,6 +23,8 @@ import ui.view.Console;
 public class Model {
 
 	// Global Variables
+	private int canvasX = 1000;
+	private int canvasY = 1000;
 	private static int sCALE = 50; // Picture Scale
 	private static int sCALEdIV2 = sCALE / 2;
 	private static final int ITERATIONS = 100;
@@ -517,4 +519,40 @@ public class Model {
 	public boolean getIsSimulation() {
 		return this.isSimulation;
 	}
+
+	/**
+	 * Get Canvas X Size.
+	 * 
+	 * @return the cANVAS_X
+	 */
+	public int getCanvasX() {
+		return canvasX;
+	}
+
+	/**
+	 * Set Canvas X Size.
+	 * 
+	 * @param canvasX the cANVAS_X to set
+	 */
+	public void setCanvasX(int canvasX) {
+		this.canvasX = canvasX;
+	}
+
+	/**
+	 * get Canvas Y size.
+	 * 
+	 * @return the cANVAS_Y
+	 */
+	public int getCanvasY() {
+		return canvasY;
+	}
+
+	/**
+	 * Set Canvas Y size.
+	 * 
+	 * @param canvasY the cANVAS_Y to set
+	 */
+	public void setCanvasY(int canvasY) {
+		this.canvasY = canvasY;
+	}
 }

+ 24 - 22
src/ui/view/GUI.java

@@ -100,7 +100,7 @@ public class GUI<E> implements CategoryListener {
 	private final JMenuItem canvasSize = new JMenuItem("View Size");
 	private final JSplitPane splitPane = new JSplitPane();
 	private final JSplitPane splitPane1 = new JSplitPane();
-	private final JSplitPane splitPaneTreeConsole = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
+	private final JSplitPane splitPaneCanvasConsole = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
 
 	private final JScrollPane canvasSP = new JScrollPane();
 	private final JScrollPane scrollPane1 = new JScrollPane();
@@ -303,7 +303,6 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-					controller.addTextToConsole("undo", Color.BLACK, 12, false, false, true);
 				} catch (IOException eex) {
 					// TODO Auto-generated catch block
 					eex.printStackTrace();
@@ -337,7 +336,6 @@ public class GUI<E> implements CategoryListener {
 						}
 					}
 					unitGraph.empty();
-					controller.addTextToConsole("redo", Color.BLACK, 12, false, false, true);
 				} catch (IOException ex) {
 					// TODO Auto-generated catch block
 					ex.printStackTrace();
@@ -525,8 +523,9 @@ public class GUI<E> implements CategoryListener {
 				myPanel.add(field1);
 				myPanel.add(field2);
 				JOptionPane.showMessageDialog(null, myPanel);
-				canvas.setPreferredSize(
-						new Dimension(Integer.parseInt(field1.getText()), Integer.parseInt(field2.getText())));
+				controller.setCanvasX(Integer.parseInt(field1.getText()));
+				controller.setCanvasY(Integer.parseInt(field2.getText()));
+				canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
 				canvas.repaint();
 			}
 		});
@@ -552,7 +551,7 @@ public class GUI<E> implements CategoryListener {
 		mnHelp.add(aboutUs);
 
 		canvas.setBackground(Color.WHITE);
-		canvas.setPreferredSize(new Dimension(1000, 1000));
+		canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
 
 		/********************
 		 * RIGHT CONTAINER (INFORMATION)
@@ -909,7 +908,7 @@ public class GUI<E> implements CategoryListener {
 			@Override
 			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
 					boolean leaf, int row, boolean hasFocus) {
-				JLabel label = new JLabel(); 
+				JLabel label = new JLabel();
 				Image imgR = null;
 				if (leaf) {
 					for (Category cat : model.getCategories()) {
@@ -1477,12 +1476,12 @@ public class GUI<E> implements CategoryListener {
 		splitPane.setRightComponent(splitPane1);
 		splitPane.setDividerLocation(200);
 		splitPane1.setDividerLocation(500);
-		splitPaneTreeConsole.setDividerLocation(500);
+		splitPaneCanvasConsole.setDividerLocation(500);
 
-		splitPane.setLeftComponent(splitPaneTreeConsole);
-		splitPaneTreeConsole.setLeftComponent(scrollPane1);
-		splitPaneTreeConsole.setRightComponent(console);
-		splitPane1.setLeftComponent(canvasSP);
+		splitPane.setLeftComponent(scrollPane1);
+		splitPaneCanvasConsole.setLeftComponent(canvasSP);
+		splitPaneCanvasConsole.setRightComponent(console);
+		splitPane1.setLeftComponent(splitPaneCanvasConsole);
 		splitPane1.setRightComponent(splitHolonElPro);
 
 		splitHolonElPro.setDividerLocation(400);
@@ -1501,7 +1500,7 @@ public class GUI<E> implements CategoryListener {
 		scrollElements.setBorder(null);
 		splitPane.setBorder(null);
 		splitPane1.setBorder(null);
-		splitPaneTreeConsole.setBorder(null);
+		splitPaneCanvasConsole.setBorder(null);
 		splitHolonElPro.setBorder(null);
 		splitGraphHolonEl.setBorder(null);
 		panelHolonEl.setBorder(null);
@@ -1509,16 +1508,17 @@ public class GUI<E> implements CategoryListener {
 		tableHolonElementScrollPane.setBorder(null);
 
 		frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
-		
+
 		String autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
 		File dest = new File(autoPath);
-		if(dest.listFiles().length>1){
+		if (dest.listFiles().length > 1) {
 			int dialogButton = JOptionPane.YES_NO_OPTION;
-			int dialogResult = JOptionPane.showConfirmDialog (null, "Old autosave file was found, should it be loaded?", "Warning",dialogButton);
-			if(dialogResult == JOptionPane.YES_OPTION){
-				model.setAutoSaveNr(dest.listFiles().length-1);
+			int dialogResult = JOptionPane.showConfirmDialog(null, "Old autosave file was found, should it be loaded?",
+					"Warning", dialogButton);
+			if (dialogResult == JOptionPane.YES_OPTION) {
+				model.setAutoSaveNr(dest.listFiles().length - 1);
 				mntmRedo.doClick();
-			}else{
+			} else {
 				controller.deleteDirectory(dest);
 				dest.mkdirs();
 				try {
@@ -1528,7 +1528,7 @@ public class GUI<E> implements CategoryListener {
 					e1.printStackTrace();
 				}
 			}
-			
+
 		}
 	}
 
@@ -1788,8 +1788,10 @@ public class GUI<E> implements CategoryListener {
 	/**
 	 * Adds a Popup.
 	 * 
-	 * @param component Component
-	 * @param popup PopupMenu
+	 * @param component
+	 *            Component
+	 * @param popup
+	 *            PopupMenu
 	 */
 	private static void addPopup(Component component, final JPopupMenu popup) {
 		component.addMouseListener(new MouseAdapter() {