|
@@ -1,5 +1,6 @@
|
|
|
package ui.view;
|
|
|
|
|
|
+import java.awt.BasicStroke;
|
|
|
import java.awt.Color;
|
|
|
import java.awt.Graphics;
|
|
|
import java.awt.Graphics2D;
|
|
@@ -7,11 +8,17 @@ import java.awt.RenderingHints;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
import java.awt.event.MouseListener;
|
|
|
import java.awt.event.MouseMotionListener;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.awt.Point;
|
|
|
|
|
|
+import javax.swing.ImageIcon;
|
|
|
import javax.swing.JButton;
|
|
|
import javax.swing.JLabel;
|
|
|
import javax.swing.JPanel;
|
|
|
|
|
|
+import com.sun.xml.internal.bind.v2.runtime.unmarshaller.XsiNilLoader.Array;
|
|
|
+
|
|
|
+import classes.CpsObject;
|
|
|
import ui.controller.Control;
|
|
|
import ui.model.Model;
|
|
|
|
|
@@ -20,7 +27,8 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
private Control controller;
|
|
|
private Model model;
|
|
|
- Graphics2D g2;
|
|
|
+ private Graphics2D g2;
|
|
|
+ private ArrayList<Point> pointList = new ArrayList<>();
|
|
|
|
|
|
public UnitGraph(final Model model, Control control) {
|
|
|
|
|
@@ -29,8 +37,6 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
|
|
|
this.addMouseListener(this);
|
|
|
this.addMouseMotionListener(this);
|
|
|
- repaint();
|
|
|
- this.add(new JButton("rdsfxgbsdugfbadasu"));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -44,50 +50,62 @@ class UnitGraph extends JPanel implements MouseListener, MouseMotionListener {
|
|
|
g2 = (Graphics2D) g;
|
|
|
RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
g2.setRenderingHints(rh);
|
|
|
+ g2.setStroke(new BasicStroke(2));
|
|
|
|
|
|
+ int[] x = new int[10000];
|
|
|
+ int[] y = new int[10000];
|
|
|
+ for (int i = 0; i < pointList.size(); i++) {
|
|
|
+ x[i] = (int)pointList.get(i).getX();
|
|
|
+ y[i] = (int)pointList.get(i).getY();
|
|
|
+ }
|
|
|
+
|
|
|
+ g2.drawPolygon(x, y, pointList.size());
|
|
|
g2.drawLine(0, this.getHeight()/2, this.getWidth(), this.getHeight()/2);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void mouseDragged(MouseEvent arg0) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
+ public void mouseDragged(MouseEvent e) {
|
|
|
+ pointList.add(new Point(e.getX(), e.getY()));
|
|
|
+ repaint();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void mouseMoved(MouseEvent arg0) {
|
|
|
+ public void mouseMoved(MouseEvent e) {
|
|
|
// TODO Auto-generated method stub
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void mouseClicked(MouseEvent arg0) {
|
|
|
+ public void mouseClicked(MouseEvent e) {
|
|
|
// TODO Auto-generated method stub
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void mouseEntered(MouseEvent arg0) {
|
|
|
+ public void mouseEntered(MouseEvent e) {
|
|
|
// TODO Auto-generated method stub
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void mouseExited(MouseEvent arg0) {
|
|
|
+ public void mouseExited(MouseEvent e) {
|
|
|
// TODO Auto-generated method stub
|
|
|
-
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void mousePressed(MouseEvent arg0) {
|
|
|
- // TODO Auto-generated method stub
|
|
|
-
|
|
|
+ public void mousePressed(MouseEvent e) {
|
|
|
+ if(e.getButton() == e.BUTTON1){
|
|
|
+ pointList.add(new Point(e.getX(), e.getY()));
|
|
|
+ } else if(e.getButton() == e.BUTTON3){
|
|
|
+ for (Point p: pointList) {
|
|
|
+ if (p.getX()-2>=e.getX()&& p.getX()+2<=e.getX() && p.getY()-2>=e.getY()&& p.getY()+2<=e.getY()) {
|
|
|
+ pointList.remove(p);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ repaint();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void mouseReleased(MouseEvent arg0) {
|
|
|
+ public void mouseReleased(MouseEvent e) {
|
|
|
// TODO Auto-generated method stub
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|