|
@@ -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();
|
|
|
}
|