Procházet zdrojové kódy

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

dominik.rieder před 7 roky
rodič
revize
3c30b9cf0e

+ 4 - 4
src/ui/controller/SaveController.java

@@ -217,7 +217,8 @@ public class SaveController {
 			file.add(key, new JsonPrimitive(cat.getName()));
 			// forall object in the category store them into the jsontree
 			for (AbstractCpsObject obj : cat.getObjects()) {
-				file.add("CGOBJECT" + getNumerator(NUMTYPE.OBJECT), model.getGson().toJsonTree(obj, AbstractCpsObject.class));
+				file.add("CGOBJECT" + getNumerator(NUMTYPE.OBJECT),
+						model.getGson().toJsonTree(obj, AbstractCpsObject.class));
 				// if its a holonobject add elements too
 				if (obj instanceof HolonObject)
 					elementsToJson(TYPE.CATEGORY, file, obj);
@@ -421,9 +422,8 @@ public class SaveController {
 	private void statisticgraphToJson(JsonObject file) {
 		// TODO Auto-generated method stub
 		JsonObject temp = new JsonObject();
-		
-		List<String> keys = model.getGraphTable().keySet().parallelStream()
-				.collect(Collectors.toCollection(ArrayList::new));
+
+		List<String> keys = model.getGraphTable().keySet().stream().collect(Collectors.toCollection(ArrayList::new));
 
 		for (String k : keys) {
 			JsonObject dataSet = new JsonObject();

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

@@ -960,6 +960,7 @@ public class Model {
 		GsonBuilder builder = new GsonBuilder();
 		builder.serializeNulls();
 		builder.excludeFieldsWithoutExposeAnnotation();
+		builder.setPrettyPrinting();
 		builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter());
 		builder.registerTypeAdapter(Position.class, new PositionAdapter());
 		builder.registerTypeAdapter(Color.class, new ColorAdapter());

+ 26 - 11
src/ui/view/GUI.java

@@ -17,6 +17,7 @@ import java.awt.event.ComponentEvent;
 import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
@@ -384,7 +385,7 @@ public class GUI<E> implements CategoryListener {
 
 		String cntrlADown = "controlA";
 		inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
-		actionMap.put(cntrlADown, new AbstractAction() {
+		AbstractAction controlA = new AbstractAction() {
 
 			private static final long serialVersionUID = 1L;
 
@@ -416,7 +417,8 @@ public class GUI<E> implements CategoryListener {
 				}
 
 			}
-		});
+		};
+		actionMap.put(cntrlADown, controlA);
 
 		String delDown = "delete";
 		inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
@@ -523,7 +525,7 @@ public class GUI<E> implements CategoryListener {
 
 		String cntrlCDown = "controlC";
 		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
-		actionMap.put(cntrlCDown, new AbstractAction() {
+		AbstractAction controlC = new AbstractAction() {
 
 			private static final long serialVersionUID = 1L;
 
@@ -546,11 +548,12 @@ public class GUI<E> implements CategoryListener {
 					}
 				}
 			}
-		});
+		};
+		actionMap.put(cntrlCDown, controlC);
 
 		String cntrlVDown = "controlV";
 		inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
-		actionMap.put(cntrlVDown, new AbstractAction() {
+		AbstractAction controlV = new AbstractAction() {
 
 			private static final long serialVersionUID = 1L;
 
@@ -584,12 +587,12 @@ public class GUI<E> implements CategoryListener {
 				}
 				canvas.repaint();
 			}
-		});
+		};
+		actionMap.put(cntrlVDown, controlV);
 
 		String cntrlXDown = "controlX";
 		inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
-		actionMap.put(cntrlXDown, new AbstractAction() {
-
+		AbstractAction controlX = new AbstractAction() {
 			private static final long serialVersionUID = 1L;
 
 			@Override
@@ -612,7 +615,8 @@ public class GUI<E> implements CategoryListener {
 					canvas.repaint();
 				}
 			}
-		});
+		};
+		actionMap.put(cntrlXDown, controlX);
 
 		frmCyberPhysical.setJMenuBar(menuBar);
 
@@ -1313,7 +1317,17 @@ public class GUI<E> implements CategoryListener {
 		 *****************************/
 
 		frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
-
+		/****************
+		 * Tree Stuff
+		 ****************/
+		
+		//Override Key Actions
+		inputMap = tree.getInputMap();
+		inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
+		inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
+		inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
+		inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
+		
 		TreeCellRenderer customRenderer = new TreeCellRenderer() {
 			@Override
 			public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
@@ -2329,9 +2343,10 @@ public class GUI<E> implements CategoryListener {
 				cps = controller.searchTracked(obj.get("ID").getAsInt());
 				prop = obj.get("PROPERTY").getAsInt();
 				color = model.getGson().fromJson(obj.get("COLOR"), Color.class);
-				stat.getStatGraph().addObject(new TrackedDataSet(cps, prop, color));
+				stat.addObject(new TrackedDataSet(cps, prop, color));
 			}
 			model.getGraphTable().put(json.get("KEY").getAsString(), stat);
+			model.getStatPanel().getGraphPanel().add(stat);
 		}
 	}
 }

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

@@ -152,7 +152,7 @@ public class StatisticGraphPanel extends JPanel {
 	 * 
 	 * @param set
 	 */
-	public void addObjec(TrackedDataSet set) {
+	public void addObject(TrackedDataSet set) {
 		sGraph.addObject(set);
 		String property = "";
 		switch (set.getProperty()) {

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

@@ -613,7 +613,7 @@ public class StatisticPanel extends JSplitPane implements GraphListener {
 							}
 							TrackedDataSet tds = new TrackedDataSet(absCps, propValTable.get(property),
 									currentProperty.getColor());
-							graphHashtable.get(graphNrTxtField.getText()).addObjec(tds);
+							graphHashtable.get(graphNrTxtField.getText()).addObject(tds);
 						}
 					}
 				}

+ 122 - 127
src/ui/view/UpperNodeCanvas.java

@@ -620,147 +620,128 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				}
 			}
 
-			// Highlighted Edge
-			if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty()
-					|| !tempSelected.isEmpty()) {
-				g2.setColor(Color.BLUE);
-				for (CpsEdge con : upperNode.getNodeEdges()) {
-					if (con.getFlow() <= con.getCapacity()) {
-						g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
+			// Border Highlighting
+			if (showedInformation[3]) {
+				g2.setColor(cps.getBorderColor());
+				if (g2.getColor() != Color.WHITE) {
+					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20) - 3,
+							(int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
+							(int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
+				}
+			}
+
+			// node image
+			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).setAutoState(true);
 					} else {
-						g2.setStroke(new BasicStroke(2));
-					}
-					if (con.getA().getId() == model.getSelectedObjectID()
-							|| 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, con.getA().getPosition().y, con.getB().getPosition().x,
-								con.getB().getPosition().y);
-
-						if (con.getCapacity() == -1) {
-							maxCap = Character.toString('\u221e');
-						} else if (con.getCapacity() == -2) {
-							maxCap = "???";
-						} else {
-							maxCap = String.valueOf(con.getCapacity());
-						}
-						if (showedInformation[0]) {
-							if (con.getConnected() == 0 || con.getConnected() == 1) {
-								g2.drawString(con.getFlow() + "/" + maxCap,
-										(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-										(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-							} else {
-								g2.drawString("not connected",
-										(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
-										(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
-							}
-						}
+						((HolonSwitch) cps).setAutoState(false);
 					}
 				}
-			} else if (edgeHighlight != null) {
-				g2.setColor(Color.BLUE);
-				if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
-					g2.setStroke(new BasicStroke(
-							Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
+				// Highlighting
+				if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
+						|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
+					g2.setColor(Color.BLUE);
+					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
+							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
+							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+				} else if (cps instanceof HolonObject) {
+					g2.setColor(((HolonObject) cps).getColor());
+
+					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
+							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
+							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+				}
+				// draw image
+				File checkPath = new File(cps.getImage());
+				if (checkPath.exists()) {
+					img = new ImageIcon(cps.getImage()).getImage();
+				} else {
+					img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
+				}
+			}
+			g2.drawImage(img, (upperNode.getLeftBorder() >> 1) - 25,
+					(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
+			count++;
+		}
+		// Highlighted Edge
+		if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty()) {
+			g2.setColor(Color.BLUE);
+			for (CpsEdge con : upperNode.getNodeEdges()) {
+				if (con.getFlow() <= con.getCapacity()) {
+					g2.setStroke(new BasicStroke(Math.min((con.getFlow() / con.getCapacity() * 3) + 1, 4)));
 				} else {
 					g2.setStroke(new BasicStroke(2));
 				}
-				if (upperNode.getNodeEdges().contains(edgeHighlight)) {
-					g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
-							edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
-
-					if (edgeHighlight.getCapacity() == -1) {
+				if (con.getA().getId() == model.getSelectedObjectID()
+						|| 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, con.getA().getPosition().y, con.getB().getPosition().x,
+							con.getB().getPosition().y);
+
+					if (con.getCapacity() == -1) {
 						maxCap = Character.toString('\u221e');
-					} else if (edgeHighlight.getCapacity() == -2) {
+					} else if (con.getCapacity() == -2) {
 						maxCap = "???";
 					} else {
-						maxCap = String.valueOf(edgeHighlight.getCapacity());
+						maxCap = String.valueOf(con.getCapacity());
 					}
 					if (showedInformation[0]) {
-						g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
-								(edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
-								(edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
+						if (con.getConnected() == 0 || con.getConnected() == 1) {
+							g2.drawString(con.getFlow() + "/" + maxCap,
+									(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+									(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
+						} else {
+							g2.drawString("not connected",
+									(con.getA().getPosition().x + con.getB().getPosition().x) / 2,
+									(con.getA().getPosition().y + con.getB().getPosition().y) / 2);
+						}
 					}
 				}
 			}
+		} else if (edgeHighlight != null) {
+			g2.setColor(Color.BLUE);
+			if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
+				g2.setStroke(
+						new BasicStroke(Math.min((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1, 4)));
+			} else {
+				g2.setStroke(new BasicStroke(2));
+			}
+			if (upperNode.getNodeEdges().contains(edgeHighlight)) {
+				g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
+						edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
 
-			// Objects in upper node
-			for (AbstractCpsObject cps1 : upperNode.getNodes()) {
-				// Border Highlighting
-				if (showedInformation[3]) {
-					g2.setColor(cps1.getBorderColor());
-					if (g2.getColor() != Color.WHITE) {
-						g2.fillRect((int) (cps1.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
-								(int) (cps1.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
-								(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
-								(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
-					}
-				}
-
-				// node image
-				if (cps1 instanceof CpsNode && (cps1 == tempCps || model.getSelectedCpsObject() == cps1
-						|| model.getSelectedCpsObjects().contains(cps1) || tempSelected.contains(cps1))) {
-					img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
+				if (edgeHighlight.getCapacity() == -1) {
+					maxCap = Character.toString('\u221e');
+				} else if (edgeHighlight.getCapacity() == -2) {
+					maxCap = "???";
 				} else {
-					if (cps1 instanceof HolonSwitch) {
-						if (((HolonSwitch) cps1).getActiveAt()[model.getCurIteration()]) {
-							((HolonSwitch) cps1).setAutoState(true);
-						} else {
-							((HolonSwitch) cps1).setAutoState(false);
-						}
-					}
-					// Highlighting
-					if ((cps1 == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
-							|| model.getSelectedCpsObjects().contains(cps1) || tempSelected.contains(cps1)) {
-						g2.setColor(Color.BLUE);
-						g2.fillRect((int) (cps1.getPosition().x - model.getScaleDiv2() - scalediv20),
-								(int) (cps1.getPosition().y - model.getScaleDiv2() - scalediv20),
-								(int) (controller.getScale() + (scalediv20 * 2)),
-								(int) (controller.getScale() + (scalediv20 * 2)));
-						if (showedInformation[1] && cps1 instanceof HolonObject) {
-							g2.setColor(Color.BLACK);
-							float totalEnergy = ((HolonObject) cps1)
-									.getCurrentEnergyAtTimeStep(model.getCurIteration());
-							g2.drawString(Float.toString(totalEnergy), cps1.getPosition().x - model.getScaleDiv2(),
-									cps1.getPosition().y - model.getScaleDiv2() - 10);
-						}
-					} else if (cps1 instanceof HolonObject) {
-						g2.setColor(((HolonObject) cps1).getColor());
-
-						g2.fillRect((int) (cps1.getPosition().x - model.getScaleDiv2() - scalediv20),
-								(int) (cps1.getPosition().y - model.getScaleDiv2() - scalediv20),
-								(int) (controller.getScale() + (scalediv20 * 2)),
-								(int) (controller.getScale() + (scalediv20 * 2)));
-
-						if (showedInformation[1]) {
-							g2.setColor(Color.BLACK);
-							float totalEnergy = ((HolonObject) cps1)
-									.getCurrentEnergyAtTimeStep(model.getCurIteration());
-							g2.drawString(Float.toString(totalEnergy), cps1.getPosition().x - model.getScaleDiv2(),
-									cps1.getPosition().y - model.getScaleDiv2() - 10);
-						}
-					}
-					// draw image
-					File checkPath = new File(cps1.getImage());
-					if (checkPath.exists()) {
-						img = new ImageIcon(cps1.getImage()).getImage();
-					} else {
-						img = new ImageIcon(this.getClass().getResource(cps1.getImage())).getImage();
-					}
+					maxCap = String.valueOf(edgeHighlight.getCapacity());
+				}
+				if (showedInformation[0]) {
+					g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
+							(edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
+							(edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
 				}
-				g2.drawImage(img, cps1.getPosition().x - model.getScaleDiv2(),
-						cps1.getPosition().y - model.getScaleDiv2(), controller.getScale(), controller.getScale(),
-						null);
 			}
+		}
 
+		// Objects in upper node
+		for (AbstractCpsObject cps : upperNode.getNodes()) {
 			// Border Highlighting
 			if (showedInformation[3]) {
 				g2.setColor(cps.getBorderColor());
 				if (g2.getColor() != Color.WHITE) {
-					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20) - 3,
-							(int) (scalediv20 + 5 + (25 + scalediv20 + 10) * count - scalediv20) - 3,
-							(int) (50 + ((scalediv20 + 3) * 2)), (int) (50 + ((scalediv20 + 3) * 2)));
+					g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
+							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20 - 3),
+							(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
+							(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
 				}
 			}
 
@@ -780,15 +761,30 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 				if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
 						|| model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
 					g2.setColor(Color.BLUE);
-					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
-							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+					g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
+							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
+							(int) (controller.getScale() + (scalediv20 * 2)),
+							(int) (controller.getScale() + (scalediv20 * 2)));
+					if (showedInformation[1] && cps instanceof HolonObject) {
+						g2.setColor(Color.BLACK);
+						float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
+						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
+								cps.getPosition().y - model.getScaleDiv2() - 10);
+					}
 				} else if (cps instanceof HolonObject) {
 					g2.setColor(((HolonObject) cps).getColor());
 
-					g2.fillRect((int) ((upperNode.getLeftBorder() >> 1) - 25 - scalediv20),
-							(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count - scalediv20),
-							(int) (50 + (scalediv20 * 2)), (int) (50 + (scalediv20 * 2)));
+					g2.fillRect((int) (cps.getPosition().x - model.getScaleDiv2() - scalediv20),
+							(int) (cps.getPosition().y - model.getScaleDiv2() - scalediv20),
+							(int) (controller.getScale() + (scalediv20 * 2)),
+							(int) (controller.getScale() + (scalediv20 * 2)));
+
+					if (showedInformation[1]) {
+						g2.setColor(Color.BLACK);
+						float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
+						g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - model.getScaleDiv2(),
+								cps.getPosition().y - model.getScaleDiv2() - 10);
+					}
 				}
 				// draw image
 				File checkPath = new File(cps.getImage());
@@ -798,9 +794,8 @@ public class UpperNodeCanvas extends JPanel implements MouseListener, MouseMotio
 					img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
 				}
 			}
-			g2.drawImage(img, (upperNode.getLeftBorder() >> 1) - 25,
-					(int) (scalediv20 + 5 + (50 + scalediv20 + 10) * count), 50, 50, null);
-			count++;
+			g2.drawImage(img, cps.getPosition().x - model.getScaleDiv2(), cps.getPosition().y - model.getScaleDiv2(),
+					controller.getScale(), controller.getScale(), null);
 		}
 
 		// Dragg Highlighting