Explorar el Código

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 hace 8 años
padre
commit
f7a874a303
Se han modificado 2 ficheros con 125 adiciones y 26 borrados
  1. 29 9
      src/ui/view/GUI.java
  2. 96 17
      src/ui/view/UnitGraph.java

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

@@ -91,6 +91,7 @@ public class GUI<E> implements CategoryListener {
 	private final JLabel minGraph = new JLabel("0%");
 	private final JLabel elementGraph = new JLabel("None ");
 	private final ArrayList<HolonElement> selectedElements = new ArrayList<HolonElement>();
+	private String holonEleNamesDisplayed = "";
 
 	private final JTree tree = new JTree();
 	private final JEditorPane dtrpnHereWillBe = new JEditorPane();
@@ -377,8 +378,20 @@ public class GUI<E> implements CategoryListener {
 				HolonObject obj = (HolonObject) getActualCps();
 				yValueElements = e.getY();
 				HolonElement ele = getActualHolonElement(obj, yValueElements);
-				if (ele != null) {
-					elementGraph.setText(ele.getEleName() + " ");
+				if (e.isControlDown() && ele != null) {
+					if (!selectedElements.contains(ele)) {
+						selectedElements.add(ele);
+						if (!holonEleNamesDisplayed.equals("None ")) {
+							holonEleNamesDisplayed = holonEleNamesDisplayed + "; " + ele.getEleName() + " ";
+						} else {
+							holonEleNamesDisplayed = ele.getEleName() + " ";
+						}
+
+					}
+				} else if (ele != null) {
+					selectedElements.clear();
+					selectedElements.add(ele);
+					holonEleNamesDisplayed = ele.getEleName() + " ";
 					unitGraph.repaintWithNewElement(ele);
 				} else {
 					elementGraph.setText("None ");
@@ -390,17 +403,18 @@ public class GUI<E> implements CategoryListener {
 					yTHIS = e.getY();
 					xTHIS = e.getX();
 				}
-				if (e.isControlDown() && ele != null) {
-					if (!selectedElements.contains(ele)) {
-						selectedElements.add(ele);
-					}
-				}
 				if (e.getClickCount() == 1 && ele == null) {
 					selectedElements.clear();
+					holonEleNamesDisplayed = "None ";
 				}
 				for (int i = 0; i < selectedElements.size(); i++) {
-					System.out.println(selectedElements.get(i).getEleName());
+					if (i == 0) {
+						System.out.println("Selected Items: " + selectedElements.get(i).getEleName());
+					} else {
+						System.out.println(selectedElements.get(i).getEleName());
+					}
 				}
+				elementGraph.setText(holonEleNamesDisplayed);
 				yBTHIS = e.getY();
 				xBTHIS = e.getX();
 
@@ -729,6 +743,12 @@ public class GUI<E> implements CategoryListener {
 						deleteRows();
 						Object[] tempRatioPerc = { "Ratio Type", true };
 						tableModelProperties.addRow(tempRatioPerc);
+					} else if (temp instanceof HolonSwitch) {
+						deleteRows();
+						Object[] tempActive = { "Active", ((HolonSwitch) temp).getActiveAt()[model.getCurIteration()]};
+						tableModelProperties.addRow(tempActive);
+						unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
+						elementGraph.setText(temp.getName());
 					} else {
 						deleteRows();
 					}
@@ -849,7 +869,7 @@ public class GUI<E> implements CategoryListener {
 				JFrame test = new JFrame();
 				FileNameExtensionFilter jsonFilter = new FileNameExtensionFilter("*.json", "json");
 				fileChooser.setFileFilter(jsonFilter);
-				
+
 				if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
 					File file = fileChooser.getSelectedFile();
 

+ 96 - 17
src/ui/view/UnitGraph.java

@@ -120,7 +120,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 							(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
 							(int) recSize.getY());
 				}
-				
+
 				// Iteration Value
 				if (arrayOfFloats != null) {
 					g2.drawString("" + arrayOfFloats[model.getCurIteration()],
@@ -146,22 +146,23 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 				g2.setStroke(new BasicStroke(2));
 				g2.setColor(Color.BLACK);
 				for (int i = 0; i < pointList.size() - 1; i++) {
-					line = new Line2D.Double(pointList.get(i).getX()*scaleX, pointList.get(i).getY()*scaleY, pointList.get(i+1).getX()*scaleX,pointList.get(i+1).getY()*scaleY);
+					line = new Line2D.Double(pointList.get(i).getX() * scaleX, pointList.get(i).getY() * scaleY,
+							pointList.get(i + 1).getX() * scaleX, pointList.get(i + 1).getY() * scaleY);
 					graphCurve.append(line, true);
 				}
 				g2.draw(graphCurve);
 
-				// Draw the Points
-				g2.setColor(Color.BLUE);
-				for (int i = 0; i < pointList.size() - 0; i++) {
-					g2.fillOval((int) (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
-							(int) (pointList.get(i).getY() * scaleY - recSize.getY() / 2), (int) recSize.getX(),
-							(int) recSize.getY());
-				}
-				
+				/*
+				 * // Draw the Points g2.setColor(Color.BLUE); for (int i = 0; i
+				 * < pointList.size() - 0; i++) { g2.fillOval((int)
+				 * (pointList.get(i).getX() * scaleX - recSize.getX() / 2),
+				 * (int) (pointList.get(i).getY() * scaleY - recSize.getY() /
+				 * 2), (int) recSize.getX(), (int) recSize.getY()); }
+				 */
+
 				// Iteration Value
-				if (arrayOfFloats != null) {
-					g2.drawString("" + arrayOfFloats[model.getCurIteration()],
+				if (arrayOfBooleans != null) {
+					g2.drawString("" + arrayOfBooleans[model.getCurIteration()],
 							(model.getCurIteration()) * this.getWidth() / (model.getIterations() - 1) + 2,
 							this.getHeight() - 10);
 				}
@@ -216,7 +217,26 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 * @param e
 	 */
 	public void switchDragged(MouseEvent e) {
-		// TODO Switch dragged zeugs kommt hier hin
+		if (pointDrag && tempP != null && tempP != pointList.getFirst() && tempP != pointList.getLast()) {
+			int i = pointList.indexOf(tempP);
+			x = e.getX() / scaleX;
+
+			if (pointList.get(i + 1).getY() == tempP.getY()) {
+				// x
+				if (pointList.get(i + 1).getX() <= x+1 || pointList.get(i - 2).getX() >= x-1) {
+					x = tempP.getX();
+				}
+				pointList.get(i - 1).setLocation(x, pointList.get(i - 1).getY());
+			} else {
+				// x
+				if (pointList.get(i + 2).getX() <= x+1 || pointList.get(i - 1).getX() >= x-1) {
+					x = tempP.getX();
+				}
+				pointList.get(i + 1).setLocation(x, pointList.get(i + 1).getY());
+			}
+			tempP.setLocation(x, tempP.getY());
+			repaint();
+		}
 	}
 
 	@Override
@@ -260,6 +280,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		// Click on Point
 		tempP = null;
 		if (pointList != null) {
+			// look if a point was clicked
 			for (Point p : pointList) {
 				if (x >= p.getX() - recSize.getX() / 2 && y >= p.getY() - recSize.getY() / 2
 						&& x <= p.getX() + recSize.getX() / 2 && y <= p.getY() * scaleY + recSize.getY() / 2) {
@@ -304,6 +325,58 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 * @param e
 	 */
 	public void switchPressed(MouseEvent e) {
+		boolean added = false;
+		boolean deletePoint = false;
+
+		double x = e.getX() / scaleX;
+		double y = e.getY() / scaleY;
+
+		// Halbe Iterations Distanz
+		double dist = (width / (model.getIterations() - 1)) / 2;
+
+		// Click on Point
+		tempP = null;
+		if (pointList != null) {
+			for (Point p : pointList) {
+				if (x >= p.getX() - dist && x <= p.getX() + dist) {
+					if (e.getButton() == MouseEvent.BUTTON3) {
+						tempP = p;
+						deletePoint = true;
+					} else {
+						pointDrag = true;
+						tempP = p;
+					}
+				}
+			}
+			// New Point
+			if (!pointDrag && e.getButton() != MouseEvent.BUTTON3 && x != 0 && x != width) {
+				for (int i = 0; i < pointList.size() && !added; i++) {
+					if (x < pointList.get(i).getX() - dist) {
+						// Punkt hinzufügen, je nachdem ob es oberhalb oder
+						// unterhalb der hälfte ist
+						if (y < height / 2 && (pointList.get(i - 1).getY() == height - 1
+								&& pointList.get(i).getY() == height - 1)) {
+							pointList.add(i, new Point((int) (x + dist), (int) height - 1));
+							pointList.add(i, new Point((int) (x + dist), 0));
+							pointList.add(i, new Point((int) (x - dist), 0));
+							pointList.add(i, new Point((int) (x - dist), (int) height - 1));
+							added = true;
+						} else if (y >= height / 2 && (pointList.get(i - 1).getY() != height - 1
+								&& pointList.get(i).getY() != height - 1)) {
+							pointList.add(i, new Point((int) (x + dist), 0));
+							pointList.add(i, new Point((int) (x + dist), (int) height - 1));
+							pointList.add(i, new Point((int) (x - dist), (int) height - 1));
+							pointList.add(i, new Point((int) (x - dist), 0));
+							added = true;
+						}
+					}
+				}
+			}
+			for (int i = 0; i < pointList.size(); i++) {
+				System.out.println(pointList.get(i).getX()+", "+pointList.get(i).getY());
+			}
+			repaint();
+		}
 		// TODO Siwtch pressed zeugs hier hin
 	}
 
@@ -429,8 +502,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		isElement = false;
 		// First time clicked on the Element
 		if (pointList.isEmpty()) {
-			pointList.addFirst(new Point(0, (int) (this.getHeight()/scaleY)));
-			pointList.addLast(new Point((int) (this.getWidth() / scaleX), (int) (this.getHeight()/scaleY)));
+			pointList.addFirst(new Point(0, 0));
+			pointList.addLast(new Point((int) (width), 0));
 		}
 		repaint();
 	}
@@ -471,10 +544,16 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	 */
 	public void fillArrayofBooleans() {
 		for (int i = 0; i < arrayOfBooleans.length; i++) {
-			arrayOfBooleans[i] = true;
+			int t = (int) getYValueAt_2((int) (i * width / (model.getIterations() - 1)));
+			if (t == 0) {
+				arrayOfBooleans[i] = true;
+			} else {
+				arrayOfBooleans[i] = false;
+			}
+
 		}
 	}
-	
+
 	/**
 	 * Fills the Arrays of each HolonElement
 	 */