Преглед изворни кода

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

dominik.rieder пре 7 година
родитељ
комит
a4a2c646ac

+ 4 - 0
src/classes/HolonBody.java

@@ -16,6 +16,10 @@ public class HolonBody implements Comparable<HolonBody> {
 	public void setId(int id) {
 		this.id = id;
 	}
+	
+	public int getId(){
+		return id;
+	}
 
 	public Color getColor() {
 		return color;

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

@@ -41,7 +41,9 @@ public class UpdateController {
 
 		if (model.getSelectedCpsObjects().size() == 1) {
 			AbstractCpsObject tempCps = model.getSelectedCpsObject();
+			//System.out.println(tempCps.getName());
 			if (tempCps != null && tempCps.getClass() == HolonObject.class) {
+				System.out.println("In here");
 				table.removeRow(2);
 				Object[] tempEnergy = { Languages.getLanguage()[73], ((HolonObject) tempCps).getCurrentEnergy() };
 				table.insertRow(2, tempEnergy);

+ 14 - 12
src/ui/view/GUI.java

@@ -80,6 +80,7 @@ import classes.IdCounter;
 import classes.IdCounterElem;
 import classes.TrackedDataSet;
 import interfaces.CategoryListener;
+import sun.awt.RepaintArea;
 import ui.controller.Control;
 import ui.controller.UpdateController;
 import ui.model.Model;
@@ -665,23 +666,23 @@ public class GUI<E> implements CategoryListener {
 		splitPane3.setRightComponent(sizeSlider);
 
 		splitPane3.setLeftComponent(lblImageSize);
-		
+
 		mnNewMenuView.add(splitPane_1);
 		holonBodySizeSlider.setValue(100);
 		holonBodySizeSlider.setMinimum(1);
-		
+
 		holonBodySizeSlider.addChangeListener(new ChangeListener() {
-			
+
 			@Override
 			public void stateChanged(ChangeEvent e) {
 				controller.setHolonBodyScale(holonBodySizeSlider.getValue());
 				tree.setRowHeight(50);
-				canvas.repaint();				
+				canvas.repaint();
 			}
 		});
-		
+
 		splitPane_1.setRightComponent(holonBodySizeSlider);
-		
+
 		splitPane_1.setLeftComponent(lblHolonBodySize);
 
 		menuBar.add(mnHelp);
@@ -802,8 +803,8 @@ public class GUI<E> implements CategoryListener {
 					selectedElements.clear();
 				}
 				updCon.refreshTableProperties(model.getPropertyTable());
-				elementGraph.setText("None ");
-				holonEleNamesDisplayed = "None ";
+				elementGraph.setText(Languages.getLanguage()[25]);
+				holonEleNamesDisplayed = Languages.getLanguage()[25];
 			}
 		});
 		/*
@@ -830,7 +831,7 @@ public class GUI<E> implements CategoryListener {
 				if (e.isControlDown() && ele != null) {
 					if (!selectedElements.contains(ele)) {
 						selectedElements.add(ele);
-						if (!holonEleNamesDisplayed.equals("None ")) {
+						if (!holonEleNamesDisplayed.equals(Languages.getLanguage()[25])) {
 							holonEleNamesDisplayed = holonEleNamesDisplayed + "; " + ele.getEleName() + " ";
 						} else {
 							holonEleNamesDisplayed = ele.getEleName() + " ";
@@ -1344,7 +1345,7 @@ public class GUI<E> implements CategoryListener {
 					model.getTableHolonElement().setModel(model.getSingleTable());
 				}
 			}
-
+		
 		});
 
 		toolBar.add(btnAdd);
@@ -1830,7 +1831,8 @@ public class GUI<E> implements CategoryListener {
 		aboutUs.setText(tempArray[14]);
 		mntmEditEdges.setText(tempArray[15]);
 		mnLanguage.setText(tempArray[16]);
-
+		canvas.updateLanguages();
+		
 		// Tables
 		for (int i = 0; i < columnNamesMulti.length; i++) {
 			columnNamesMulti[i] = tempArray[i + 17];
@@ -1922,7 +1924,7 @@ public class GUI<E> implements CategoryListener {
 				@Override
 				public void mousePressed(MouseEvent e) {
 					unitGraph.empty();
-					holonEleNamesDisplayed = "None ";
+					holonEleNamesDisplayed = Languages.getLanguage()[25];
 					elementGraph.setText(holonEleNamesDisplayed);
 					temp = ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
 							.getComponent(0)).tempCps;

+ 9 - 7
src/ui/view/HolonCanvas.java

@@ -65,7 +65,7 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 
 	public void paintComponent(Graphics g) {
 		super.paintComponent(g);
-		
+
 		// add new colors if necessary
 		for (int i = 0; i < controller.getSimManager().getSubNets().size(); i++) {
 			if (model.getSubNetColors().size() - 1 < i) {
@@ -111,12 +111,13 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 
 	// updates the bodies according to the changes of subnets
 	private void addNewBodies(int subCount) {
-	
+
 		ArrayList<HolonBody> newBodies = new ArrayList<>();
 		for (int i = 0; i < subCount; i++) {
 			for (int j = 0; j < bodies.size(); j++) {
 				if (model.getSubNetColors().get(i) == bodies.get(j).getColor()) {
-					bodies.get(j).setRadius(subnets.get(i).getObjects().size() * 5 + 10);
+					bodies.get(j).setRadius(
+							(subnets.get(i).getObjects().size() * 5 + 10) * controller.getHolonBodyScale() / 100);
 					bodies.get(j).setMass(subnets.get(i).getObjects().size() * 5 + 10);
 					newBodies.add(bodies.get(j));
 					newBodies.get(i).setId(i);
@@ -128,8 +129,8 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 		bodies = newBodies;
 		for (int i = bodies.size(); i < subCount; i++) {
 			HolonBody temp = new HolonBody((center.width + 1) + (-1 * i), (center.height + 1) + (-1 * i),
-					subnets.get(i).getObjects().size() * 5 + 10, subnets.get(i).getObjects().size() * 5 + 10,
-					model.getSubNetColors().get(i));
+					(subnets.get(i).getObjects().size() * 5 + 10) * controller.getHolonBodyScale() / 100,
+					subnets.get(i).getObjects().size() * 5 + 10, model.getSubNetColors().get(i));
 			temp.setId(i);
 			bodies.add(temp);
 		}
@@ -157,7 +158,8 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 
 		// Render Game Objects
 		for (int i = 0; i < subCount; i++) {
-			bodies.get(i).setRadius(bodies.get(i).getRadius()*controller.getHolonBodyScale()/100);
+			bodies.get(i).setRadius((subnets.get(bodies.get(i).getId()).getObjects().size() * 5 + 10)
+					* controller.getHolonBodyScale() / 100);
 			bodies.get(i).draw(this.g2);
 		}
 	}
@@ -230,7 +232,7 @@ public class HolonCanvas extends JPanel implements MouseWheelListener {
 
 	@Override
 	public void mouseWheelMoved(MouseWheelEvent e) {
-		controller.setHolonBodyScale(model.getHolonBodyScale()+(-e.getScrollAmount()*e.getWheelRotation()));
+		controller.setHolonBodyScale(model.getHolonBodyScale() + (-e.getScrollAmount() * e.getWheelRotation()));
 	}
 
 }

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

@@ -42,7 +42,9 @@ public class Languages {
 			// Simulation ToolTip (89-93)
 			"Play", "Reset", "Forward", "Backward", "Time Slider",
 			// Image Size Slider (94)
-			"Image Size" };
+			"Image Size",
+			// Menu - right click on HolonObjt (95-102)
+			"Cut", "Copy", "Paste", "Delete", "Group", "Ungroup", "Track", "Untrack"};
 
 	static String[] arrayES = {
 			// ToolBar (0-16)
@@ -85,7 +87,9 @@ public class Languages {
 			// Simulation ToolTip (89-93)
 			"Iniciar", "Resetear", "Adelante", "Atrás", "Linea de Tiempo",
 			// Image Size Slider (94)
-			"Tamaño de la Imagen" };
+			"Tamaño de la Imagen",
+			// Menu - right click on HolonObjt (95-102)
+			"Cortar", "Copiar", "Pegar", "Eliminar", "Agrupar", "Desagrupar", "Rastrear", "Dejar de rastrear", };
 
 	static String[] arrayDE = {
 			// ToolBar (0-16)
@@ -129,7 +133,9 @@ public class Languages {
 			// Simulation ToolTip (89-93)
 			"Abspielen", "Zurücksetzen", "Vorwärts", "Rückwärts", "Zeitschieber",
 			// Image Size Slider (94)
-			"Bildgröße" };
+			"Bildgröße",
+			// Menu - right click on HolonObjt (95-102)
+			"Cut", "Copy", "Paste", "Delete", "Group", "Ungroup", "Track", "Untrack", "Categories" };
 
 	static String[] arrayCZ = {
 			// ToolBar (0-16)
@@ -169,39 +175,33 @@ public class Languages {
 			// Simulation ToolTip (89-93)
 			"Play", "Reset", "Forward", "Backward", "Time Slider",
 			// Image Size Slider (94)
-			"Image Size" };
+			"Image Size",
+			// Menu - right click on HolonObjt (95-102)
+			"Cut", "Copy", "Paste", "Delete", "Group", "Ungroup", "Track", "Untrack", "Categories" };
 
 	static String[] arrayZH = {
 			// ToolBar (0-16)
-			"文档", "新", "打开", "保存", "编辑", "撤销", "重做", "查找/替换", "编辑显示的信息", "选项",
-			"复位类别", "视图", "视图尺寸", "帮助", "关于我们", "编辑边缘", "语言",
+			"文档", "新", "打开", "保存", "编辑", "撤销", "重做", "查找/替换", "编辑显示的信息", "选项", "复位类别", "视图", "视图尺寸", "帮助", "关于我们",
+			"编辑边缘", "语言",
 			// Tables (17-24)
 			"对象", "No.", "能源", "电能", "数量", "激活", "字段", "信息",
 			// Graph (25-26)
 			"无", "重置",
 			// Warning PopUps(27-30)
-			"警告", "需要储存现在的数据吗?", "真的想删除类别吗?",
-			"请选择一个类别或对象以便删除。",
+			"警告", "需要储存现在的数据吗?", "真的想删除类别吗?", "请选择一个类别或对象以便删除。",
 			// Edit Edges Pop Up (31-34)
 			"编辑显示的信息", "显示这个对象的总能源", "显示这个对象的总能源", "取消",
 			// Search/Replace Pop Up (35-45)
-			"搜索对象", "寻找", "重置", "方向", "前进", "后退", "范围", "全选", "单一",
-			"重置全部", "关闭",
+			"搜索对象", "寻找", "重置", "方向", "前进", "后退", "范围", "全选", "单一", "重置全部", "关闭",
 			// Edit Edges Pop Up (46-55)
-			"编辑边缘容量", "最大容量:", "更改现有全部编辑",
-			"更改更新内容部分编辑", "更改现有全部以及更新内容部分编辑", "取消",
-			"请选择一个选项",
-			"请输入一个数字大于或等于在字段为最大容量", "编辑边缘容量",
-			"(进入 \"无限\" 无限产能)",
+			"编辑边缘容量", "最大容量:", "更改现有全部编辑", "更改更新内容部分编辑", "更改现有全部以及更新内容部分编辑", "取消", "请选择一个选项", "请输入一个数字大于或等于在字段为最大容量",
+			"编辑边缘容量", "(进入 \"无限\" 无限产能)",
 			// Add PopUp Tree (56-63)
-			"请输入类别名称 ", "请在添加之前选定一个类别 ", "添加对象菜单",
-			"名称:", "浏览图片", "添加元素", "删除元素", "取消",
+			"请输入类别名称 ", "请在添加之前选定一个类别 ", "添加对象菜单", "名称:", "浏览图片", "添加元素", "删除元素", "取消",
 			// Add PopUp Element (64-71)
-			"添加元素至对象", "元素名称:", "提供能源:", "数量:",
-			"请在字段中输入数量以及假设能源数字", "无名", "已给出的名称", "取消",
+			"添加元素至对象", "元素名称:", "提供能源:", "数量:", "请在字段中输入数量以及假设能源数字", "无名", "已给出的名称", "取消",
 			// Info for PropertyTable (72-82)
-			"名称", "总能量", "手册", "主动", " 链接至", " 通过ID: ", "边缘: ", " 至 ",
-			"电流流", "最大容量", "状态",
+			"名称", "总能量", "手册", "主动", " 链接至", " 通过ID: ", "边缘: ", " 至 ", "电流流", "最大容量", "状态",
 			// Info SimulationMenu (83-87)
 			"模拟", "仿真速度:", "计算程序:", "选择“文件夹", "成功",
 			// Exit Pop Up (88)
@@ -209,7 +209,9 @@ public class Languages {
 			// Simulation ToolTip (89-93)
 			"播放", "复位", "前进", "后退", "时间滑块",
 			// Image Size Slider (94)
-			"图片尺寸" };
+			"图片尺寸",
+			// Menu - right click on HolonObjt (95-102)
+			"Cut", "Copy", "Paste", "Delete", "Group", "Ungroup", "Track", "Untrack", "Categories" };
 
 	public static String[] getLanguage() {
 		switch (languageVar) {

+ 60 - 43
src/ui/view/MyCanvas.java

@@ -75,14 +75,14 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 	// PopUpMenu
 	private JPopupMenu popmenu = new JPopupMenu();
-	private JMenuItem itemDelete = new JMenuItem("Delete");
-	private JMenuItem itemCut = new JMenuItem("Cut");
-	private JMenuItem itemCopy = new JMenuItem("Copy");
-	public JMenuItem itemPaste = new JMenuItem("Paste");
-	public JMenuItem itemGroup = new JMenuItem("Group");
-	public JMenuItem itemUngroup = new JMenuItem("Ungroup");
-	public JMenuItem itemTrack = new JMenuItem("Track");
-	public JMenuItem itemUntrack = new JMenuItem("Untrack");
+	private JMenuItem itemDelete = new JMenuItem(Languages.getLanguage()[98]);
+	private JMenuItem itemCut = new JMenuItem(Languages.getLanguage()[95]);
+	private JMenuItem itemCopy = new JMenuItem(Languages.getLanguage()[96]);
+	public JMenuItem itemPaste = new JMenuItem(Languages.getLanguage()[97]);
+	public JMenuItem itemGroup = new JMenuItem(Languages.getLanguage()[99]);
+	public JMenuItem itemUngroup = new JMenuItem(Languages.getLanguage()[100]);
+	public JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
+	public JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
 	private JToolTip objectTT = new JToolTip();
 
 	private Point mousePosition = new Point(); // Mouse Position when
@@ -140,6 +140,8 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		itemTrack.setEnabled(false);
 		itemUntrack.setEnabled(false);
 
+		itemCut.setText(Languages.getLanguage()[95]);
+
 		itemGroup.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
@@ -209,7 +211,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						break;
 					}
 				}
-				
+
 				savePos = new ArrayList<>();
 				animCps = ((CpsUpperNode) tempCps).getNodes();
 				controller.delUpperNode((CpsUpperNode) tempCps, null);
@@ -260,21 +262,21 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				animT.start();
 			}
 		});
-		
-		//adds the selected object(s) to the statistic panel
+
+		// adds the selected object(s) to the statistic panel
 		itemTrack.addActionListener(new ActionListener() {
 			@Override
 			public void actionPerformed(ActionEvent e) {
 				for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
 					boolean found = false;
 					if (controller.getTrackingObj() != null) {
-						if(controller.getTrackingObj().contains(o)){
+						if (controller.getTrackingObj().contains(o)) {
 							found = true;
 						}
 					}
 					if (!found) {
 						controller.addTrackingObj(o);
-						if(o instanceof HolonObject){
+						if (o instanceof HolonObject) {
 							((HolonObject) o).updateTrackingInfo();
 						}
 					}
@@ -295,7 +297,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						boolean found = false;
 						if (controller.getTrackingObj() != null) {
 							for (AbstractCpsObject obj : controller.getTrackingObj()) {
-								if(obj instanceof HolonObject){
+								if (obj instanceof HolonObject) {
 									if (obj.getID() == o.getID()) {
 										found = true;
 									}
@@ -396,10 +398,10 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255),
 						(int) (Math.random() * 255)));
 			}
-			if(showedInformation[3]){
-			for (HolonObject cps : s.getObjects()) {
-				cps.setBorderColor(model.getSubNetColors().get(i));
-			}
+			if (showedInformation[3]) {
+				for (HolonObject cps : s.getObjects()) {
+					cps.setBorderColor(model.getSubNetColors().get(i));
+				}
 			}
 			i++;
 		}
@@ -415,7 +417,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		for (CpsEdge con : model.getEdgesOnCanvas()) {
 			if (con.getA().getID() != model.getSelectedObjectID() && con.getB().getID() != model.getSelectedObjectID()
 					&& con != edgeHighlight) {
-				if(con.getConnected()){
+				if (con.getConnected()) {
 					if (con.getState()) {
 						g2.setColor(Color.GREEN);
 						if (con.getCapacity() != -1) {
@@ -425,7 +427,7 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						g2.setColor(Color.RED);
 						g2.setStroke(new BasicStroke(2));
 					}
-				}else{
+				} else {
 					g2.setColor(Color.DARK_GRAY);
 					g2.setStroke(new BasicStroke(2));
 				}
@@ -440,14 +442,18 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					maxCap = String.valueOf(con.getCapacity());
 				}
 				if (showedInformation[0]) {
-					if(con.getConnected()){
+					if (con.getConnected()) {
 						g2.drawString(con.getFlow() + "/" + maxCap,
-								(con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
-								(con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
-					}else{
-						g2.drawString("not connected", 
-								(con.getA().getPosition().x + con.getB().getPosition().x) / 2 + controller.getScaleDiv2(),
-								(con.getA().getPosition().y + con.getB().getPosition().y) / 2 + controller.getScaleDiv2());
+								(con.getA().getPosition().x + con.getB().getPosition().x) / 2
+										+ controller.getScaleDiv2(),
+								(con.getA().getPosition().y + con.getB().getPosition().y) / 2
+										+ controller.getScaleDiv2());
+					} else {
+						g2.drawString("not connected",
+								(con.getA().getPosition().x + con.getB().getPosition().x) / 2
+										+ controller.getScaleDiv2(),
+								(con.getA().getPosition().y + con.getB().getPosition().y) / 2
+										+ controller.getScaleDiv2());
 					}
 				}
 			}
@@ -478,17 +484,17 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 						maxCap = String.valueOf(con.getCapacity());
 					}
 					if (showedInformation[0]) {
-						if(con.getConnected()){
+						if (con.getConnected()) {
 							g2.drawString(con.getFlow() + "/" + maxCap,
 									(con.getA().getPosition().x + con.getB().getPosition().x) / 2
 											+ controller.getScaleDiv2(),
-											(con.getA().getPosition().y + con.getB().getPosition().y) / 2
+									(con.getA().getPosition().y + con.getB().getPosition().y) / 2
 											+ controller.getScaleDiv2());
-						}else{
+						} else {
 							g2.drawString("not connected",
 									(con.getA().getPosition().x + con.getB().getPosition().x) / 2
 											+ controller.getScaleDiv2(),
-											(con.getA().getPosition().y + con.getB().getPosition().y) / 2
+									(con.getA().getPosition().y + con.getB().getPosition().y) / 2
 											+ controller.getScaleDiv2());
 						}
 					}
@@ -523,10 +529,11 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		// Objects
 		for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
 			// Border Highlighting
-			if(showedInformation[3]){
+			if (showedInformation[3]) {
 				g2.setColor(cps.getBorderColor());
 				if (g2.getColor() != Color.WHITE) {
-					g2.fillRect((int) (cps.getPosition().x - scalediv20 - 3), (int) (cps.getPosition().y - scalediv20 - 3),
+					g2.fillRect((int) (cps.getPosition().x - scalediv20 - 3),
+							(int) (cps.getPosition().y - scalediv20 - 3),
 							(int) (controller.getScale() + ((scalediv20 + 3) * 2)),
 							(int) (controller.getScale() + ((scalediv20 + 3) * 2)));
 				}
@@ -697,16 +704,15 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 				else
 					itemUngroup.setEnabled(false);
 				/*
-				if (!(tempCps instanceof HolonSwitch)) {
-					itemTrack.setEnabled(true);
-					itemUntrack.setEnabled(true);
-				} else {
-				*/
-					itemTrack.setEnabled(true);
-					itemUntrack.setEnabled(true);
-					/*
-				}
-				*/
+				 * if (!(tempCps instanceof HolonSwitch)) {
+				 * itemTrack.setEnabled(true); itemUntrack.setEnabled(true); }
+				 * else {
+				 */
+				itemTrack.setEnabled(true);
+				itemUntrack.setEnabled(true);
+				/*
+				 * }
+				 */
 				if (model.getSelectedCpsObjects().size() == 0) {
 					controller.addSelectedObject(tempCps);
 				}
@@ -988,6 +994,17 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 		return null;
 	}
 
+	public void updateLanguages() {
+		itemCut.setText(Languages.getLanguage()[95]);
+		itemCopy.setText(Languages.getLanguage()[96]);
+		itemPaste.setText(Languages.getLanguage()[97]);
+		itemDelete.setText(Languages.getLanguage()[98]);
+		itemGroup.setText(Languages.getLanguage()[99]);
+		itemUngroup.setText(Languages.getLanguage()[100]);
+		itemTrack.setText(Languages.getLanguage()[101]);
+		itemUntrack.setText(Languages.getLanguage()[102]);
+	}
+
 	/**
 	 * Checks if a double click was made.
 	 *