Kevin Trometer 8 years ago
parent
commit
1c1413527c
2 changed files with 16 additions and 23 deletions
  1. 5 15
      src/ui/view/MyCanvas.java
  2. 11 8
      src/ui/view/UnitGraph.java

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

@@ -110,11 +110,9 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 					g2.drawLine(cps.getPosition().x + controller.getScaleDiv2(),
 							cps.getPosition().y + controller.getScaleDiv2(),
 							con.getPosition().x + controller.getScaleDiv2(),
-							con.getPosition().y + controller.getScaleDiv2());
-				g2.drawString("Capacity", (cps.getPosition().x + con.getPosition().x) / 2 + model.getScaleDiv2(),
-						(cps.getPosition().y + con.getPosition().y) / 2 + model.getScaleDiv2());
+							con.getPosition().y + controller.getScaleDiv2());
 				g2.drawString("100", (cps.getPosition().x + con.getPosition().x) / 2 + model.getScaleDiv2(),
-						(cps.getPosition().y + con.getPosition().y) / 2 + model.getScaleDiv2());
+						(cps.getPosition().y + con.getPosition().y) / 2 + model.getScaleDiv2());
 			}
 		}
 
@@ -177,17 +175,9 @@ class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
 			if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
 				tempCps = cps;
 				// If drawing an Edge (CTRL down)
-				if (e.isControlDown()) {
-					drawEdge = true;
-					controller.deleteElementCanvas(1, "Rehab");
-					System.out.println(((HolonObject) model.getCategories().get(0).getObjects().get(0)).getElements()
-							.get(2).getAmount());
-					/*
-					 * controller.deleteElementCanvas(1, "Rehab");
-					 * System.out.println(((HolonObject)
-					 * model.getCategories().get(0).getObjects().get(0)).
-					 * getElements() .get(2).getAmount());
-					 */
+				if (e.isControlDown()) {
+					drawEdge = true;
+					drawEdge = true;
 				}
 				if (tempCps.getClass() == HolonObject.class) {
 					HolonObject tempObj = ((HolonObject) tempCps);

+ 11 - 8
src/ui/view/UnitGraph.java

@@ -38,7 +38,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 
 	public UnitGraph(final Model model, Control control) {
 		
-		
 		this.controller = control;
 		this.model = model;
 		for (int i = 0; i < pointList.length; i++) {
@@ -61,19 +60,23 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
 		g2.setRenderingHints(rh);
 		g2.setStroke(new BasicStroke(1));
-
+		
+		g2.setColor(Color.LIGHT_GRAY);
+		for (int i = 0; i < pointList.length; i++) {
+			g2.drawLine((int)pointList[i].getX(), 0, (int)pointList[i].getX(), this.getHeight());
+		}
+		
+		g2.setColor(Color.BLACK);
+		g2.setStroke(new BasicStroke(2));
 		for (int i = 0; i < pointList.length-1; i++) {
 			g2.drawLine((int)pointList[i].getX(), (int)pointList[i].getY(), (int)pointList[i+1].getX(), (int)pointList[i+1].getY());
 		}
-		g2.drawLine((int)pointList[NUMBER-1].getX(), (int)pointList[NUMBER-1].getY(), this.getWidth(), this.getHeight()/2);
 	}
 
 	@Override
 	public void mouseDragged(MouseEvent e) {
-		if (pointDrag) {
+		if (pointDrag && e.getY()>= this.getHeight()/3) {
 			pointList[tempP].setLocation(pointList[tempP].getX(), e.getY());
-			pointList[tempP-1].setLocation(pointList[tempP-1].getX(), pointList[tempP-1].getY()+(e.getY()-pointList[tempP-1].getY())/10);
-			pointList[tempP+1].setLocation(pointList[tempP+1].getX(), pointList[tempP-1].getY()+(e.getY()-pointList[tempP-1].getY())/10);
 		}
 		repaint();
 	}
@@ -101,7 +104,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 	@Override
 	public void mousePressed(MouseEvent e){
 		for (int i = 0; i < pointList.length; i++) {
-			if(e.getX()-this.getWidth()/NUMBER<pointList[i].getX() && e.getX()+this.getWidth()/NUMBER>pointList[i].getX() && e.getY()-10<pointList[i].getY() && e.getY()+10>pointList[i].getY()){
+			if(e.getX()-this.getWidth()/NUMBER/2<=pointList[i].getX() && e.getX()+this.getWidth()/NUMBER/2>=pointList[i].getX() && e.getY()-10<pointList[i].getY() && e.getY()+10>pointList[i].getY()){
 				pointDrag = true;
 				tempP = i;
 			}
@@ -119,7 +122,7 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener, Co
 		// resize listener
 		System.out.println("resize");
 		for (int i = 0; i < pointList.length; i++) {
-			pointList[i] = new Point((i)*this.getWidth()/NUMBER,this.getHeight()/2);
+			pointList[i] = new Point((i)*this.getWidth()/(NUMBER-1),this.getHeight()/3);
 		}
 		repaint();
 	}