Преглед на файлове

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

Jessey Widhalm преди 8 години
родител
ревизия
7214b8e195
променени са 3 файла, в които са добавени 53 реда и са изтрити 15 реда
  1. 25 9
      src/ui/view/GUI.java
  2. 27 5
      src/ui/view/MyCanvas.java
  3. 1 1
      src/ui/view/PropertyTable.java

+ 25 - 9
src/ui/view/GUI.java

@@ -330,7 +330,7 @@ public class GUI<E> implements CategoryListener {
 		 * RIGHT CONTAINER (INFORMATION)
 		 **********************/
 		// Set up of the HolonElements section
-		Object[] columnNames = { "Device", "Energy", "Quantity", "Activated" };
+		Object[] columnNames = { "Object", "Device", "Energy", "Quantity", "Activated" };
 		tableModelHolonElement.setColumnIdentifiers(columnNames);
 		tableHolonElement.setBorder(null);
 		tableHolonElement.setModel(tableModelHolonElement);
@@ -775,6 +775,7 @@ public class GUI<E> implements CategoryListener {
 		 * the clicked HolonObject
 		 */
 		canvas.addMouseListener(new MouseAdapter() {
+
 			@Override
 			public void mousePressed(MouseEvent e) {
 				if (temp == null || temp.getID() != model.getSelectedObjectID()) {
@@ -789,6 +790,7 @@ public class GUI<E> implements CategoryListener {
 				// Update of the Information about the Properties - only for
 				// CpsObjects
 				// Erase old data
+				System.out.println(model.getSelectedCpsObjects());
 				if (tableModelProperties.getRowCount() > 0) {
 					for (int i = tableModelProperties.getRowCount() - 1; i > -1; i--) {
 						tableModelProperties.removeRow(i);
@@ -800,6 +802,9 @@ public class GUI<E> implements CategoryListener {
 					} else {
 						controller.addSelectedObject(temp);
 					}
+				} else if (temp != null) {
+					model.getSelectedCpsObjects().clear();
+					controller.addSelectedObject(temp);
 				}
 				// } else if (e.isShiftDown() && model.getSelectedEdge() !=
 				// null) {
@@ -808,10 +813,10 @@ public class GUI<E> implements CategoryListener {
 				boolean nothingImportant = true;
 				for (CpsObject c : model.getSelectedCpsObjects()) {
 					if (nothingImportant) {
-						System.out.println("Elements: " + c.getName());
+						System.out.println("Elements: " + c.getName() + " and ID: " + c.getID());
 						nothingImportant = false;
 					} else {
-						System.out.println(c.getName());
+						System.out.println(c.getName() + " and ID: " + c.getID());
 					}
 				}
 				// Write new data
@@ -881,6 +886,12 @@ public class GUI<E> implements CategoryListener {
 					deleteRows();
 				}
 			}
+
+			@Override
+			public void mouseReleased(MouseEvent e) {
+				refreshTableHolonElement();
+				refreshTableProperties();
+			}
 		});
 
 		toolBar.add(btnAdd);
@@ -1236,8 +1247,9 @@ public class GUI<E> implements CategoryListener {
 		// HolonObjects
 
 		deleteRows();
-		if (getActualCps() != null) {
-			fillElementTable(((HolonObject) getActualCps()).getElements());
+		System.out.println(model.getSelectedCpsObjects());
+		if (model.getSelectedCpsObjects() != null) {
+			fillElementTable(model.getSelectedCpsObjects());
 		}
 		tableModelHolonElement.fireTableDataChanged();
 	}
@@ -1260,10 +1272,14 @@ public class GUI<E> implements CategoryListener {
 	 * @param elements
 	 *            ArrayList to be displayed
 	 */
-	public void fillElementTable(ArrayList<HolonElement> elements) {
-		for (HolonElement he : elements) {
-			Object[] temp = { he.getEleName(), he.getEnergy(), he.getAmount(), he.getActive() };
-			tableModelHolonElement.addRow(temp);
+	public void fillElementTable(ArrayList<CpsObject> objects) {
+		for (CpsObject o : objects) {
+			if (o instanceof HolonObject) {
+				for (HolonElement he : ((HolonObject) o).getElements()) {
+					Object[] temp = { o.getName(), he.getEleName(), he.getEnergy(), he.getAmount(), he.getActive() };
+					tableModelHolonElement.addRow(temp);
+				}
+			}
 		}
 	}
 

+ 27 - 5
src/ui/view/MyCanvas.java

@@ -345,9 +345,12 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 
 		if (dragging) {
 			try {
+				float xDist, yDist; //Distance
+				
 				x = e.getX() - controller.getScaleDiv2();
 				y = e.getY() - controller.getScaleDiv2();
 
+				//Make sure its in bounds
 				if (e.getX() < controller.getScaleDiv2())
 					x = 0;
 				else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
@@ -356,16 +359,35 @@ public class MyCanvas extends JPanel implements MouseListener, MouseMotionListen
 					y = 0;
 				else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
 					y = this.getHeight() - controller.getScale();
-				// Drag Position
-				tempCps.setPosition(x, y);
-				// Highlighting Position
-				selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20));
+
+				//Distance
+				xDist = x-tempCps.getPosition().x;
+				yDist = y-tempCps.getPosition().y;
+				
+				tempCps.setPosition(x, y); // Drag Position
+				selectRect.setLocation(x - (controller.getScale() / 20), y - (controller.getScale() / 20)); // Highlighting-Position
+				
 				// TipText Position and name
 				objectTT.setTipText(tempCps.getName());
 				objectTT.setLocation(x, y + controller.getScale());
+				
+				//All Selected Objects
 				for (CpsObject cps : model.getSelectedCpsObjects()) {
 					if (cps != tempCps) {
-
+						x = (int) (cps.getPosition().x+xDist);
+						y = (int) (cps.getPosition().y+yDist);
+
+						//Make sure its in bounds
+						if (x < 0)
+							x = 0;
+						else if (x > this.getWidth())
+							x = this.getWidth() - controller.getScale();
+						if (y < controller.getScaleDiv2())
+							y = 0;
+						else if (y > this.getHeight())
+							y = this.getHeight() - controller.getScale();
+						
+						cps.setPosition(x, y);
 					}
 				}
 				repaint();

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

@@ -10,7 +10,7 @@ public class PropertyTable extends DefaultTableModel {
 	public Class<?> getColumnClass(int columnIndex) {
 		Class clazz = String.class;
 			switch (columnIndex) {
-			case 3:
+			case 4:
 				clazz = Boolean.class;
 				break;
 			}