changed drawbox config

This commit is contained in:
Maggistrator
2021-08-15 10:10:07 +03:00
parent 7688de83b2
commit 27eb5e89d8

View File

@ -68,7 +68,7 @@ public class GUI extends JFrame {
@Override
public void mouseMoved(MouseEvent e) {
if(radioButtonDrawBox.isSelected()) {
if(labelDrawing.listPoints.size()<4) {
if(labelDrawing.listPoints.size() < 2) {
labelDrawing.x = e.getX();
labelDrawing.y = e.getY();
labelDrawing.repaint();
@ -98,22 +98,36 @@ public class GUI extends JFrame {
@Override
public void mousePressed(MouseEvent e) {
if(radioButtonDrawBox.isSelected()) {
if(labelDrawing.listPoints.size()<4) {
if(labelDrawing.listPoints.size() < 2) {
labelDrawing.listPoints.add(new PointLine(e.getX(), e.getY()));
if(labelDrawing.listPoints.size() > 1 && labelDrawing.listPoints.size() <=4) {
PointLine p1 = labelDrawing.listPoints.get(labelDrawing.listPoints.size()-2);
PointLine p2 = labelDrawing.listPoints.get(labelDrawing.listPoints.size()-1);
labelDrawing.listLines.add(new Line2D.Float(p1.x,p1.y,p2.x,p2.y));
}
if(labelDrawing.listPoints.size() ==4){
PointLine p1 = labelDrawing.listPoints.get(0);
PointLine p2 = labelDrawing.listPoints.get(labelDrawing.listPoints.size()-1);
labelDrawing.listLines.add(new Line2D.Float(p1.x,p1.y,p2.x,p2.y));
labelDrawing.sortPoint();
labelDrawing.listLines.add(new Line2D.Float(saveListPoints.get(2).x,saveListPoints.get(2).y+3,saveListPoints.get(3).x,saveListPoints.get(3).y+3));
}
}
if(labelDrawing.listPoints.size() == 2) {
PointLine p1 = labelDrawing.listPoints.get(0);
PointLine p2 = labelDrawing.listPoints.get(1);
labelDrawing.listLines.add(new Line2D.Float(p1.x,p1.y,p2.x,p2.y));
//��������� ����� ������������ �������������� �������������
PointLine p3;
if (p1.y > p2.y) p3 = new PointLine(p1.x, p2.y);
else if(p1.y < p2.y) p3 = new PointLine(p2.x, p1.y);
else p3 = new PointLine(p1.x + Math.abs(p1.x - p2.x)/2, p2.y);
labelDrawing.listPoints.add(p3);
labelDrawing.listLines.add(new Line2D.Float(p1.x, p1.y, p3.x, p3.y));
labelDrawing.listLines.add(new Line2D.Float(p2.x, p2.y, p3.x, p3.y));
labelDrawing.sortPoint();
labelDrawing.repaint();
System.out.println("__list for save___");
System.out.print("without rect:");
for(PointLine l: saveListPoints) System.out.print("["+l.x+";"+l.y+"] ");
System.out.println();
saveListPoints.add(0, new PointLine(0, labelDrawing.heigth));
saveListPoints.add(1, new PointLine(0, 0));
saveListPoints.add(2, new PointLine(labelDrawing.width, 0));
saveListPoints.add(3, new PointLine(labelDrawing.width, labelDrawing.heigth));
System.out.print("with rect:");
for(PointLine l: saveListPoints) System.out.print("["+l.x+";"+l.y+"] ");
System.out.println();
System.out.println("_____");
}
}
@ -205,23 +219,19 @@ public class GUI extends JFrame {
public void paint(Graphics g) {
Graphics2D graphic2d = (Graphics2D) g;
if(radioButtonDrawBox.isSelected()) {
graphic2d.setColor(Color.BLUE);
g.drawRect(1, 1, width-3, heigth-3);
graphic2d.setColor(Color.MAGENTA);
//��� ������� ��� ����� ������� ��������� �� ������
if(listPoints.size() >= 1) {
if(listPoints.size() >= 1 && listPoints.size() < 3) {
PointLine a = listPoints.get(listPoints.size()-1);
graphic2d.setColor(Color.BLUE);
graphic2d.draw(new Line2D.Float(a.x,a.y,x,y));
}
//��������� ���� �����
if(listLines.size() >= 1) {
for(int i = 0;i<listLines.size();i++) {
graphic2d.draw(listLines.get(i));
}
if(listLines.size() == 5) {
graphic2d.setColor(Color.MAGENTA);
graphic2d.draw(listLines.get(4));
}
}
}
@ -268,25 +278,17 @@ public class GUI extends JFrame {
public void sortPoint() {
copyPointList();
for(int i = 0;i<listPoints.size()-1;i++) {
for(int j = i+1;j<listPoints.size();j++) {
if(saveListPoints.get(i).y>saveListPoints.get(j).y) {
for (int i = 0; i < saveListPoints.size() - 1; i++) {
for (int j = i + 1; j < saveListPoints.size(); j++) {
if (saveListPoints.get(i).y > saveListPoints.get(j).y) {
Collections.swap(saveListPoints, i, j);
}
}
}
if(listPoints.size()>2) {
if(saveListPoints.get(0).x>saveListPoints.get(1).x) {
Collections.swap(saveListPoints, 0, 1);
}
if(saveListPoints.get(2).x<saveListPoints.get(3).x) {
Collections.swap(saveListPoints, 2, 3);
}
}
}
void copyPointList() {
for(int i = 0;i<listPoints.size();i++) {
for (int i = 0; i < listPoints.size(); i++) {
saveListPoints.add(listPoints.get(i));
}
}
@ -321,6 +323,7 @@ public class GUI extends JFrame {
labelDraw.setSize(widthIcon,heigthIcon);
labelDraw.width = widthIcon;
labelDraw.heigth = heigthIcon;
labelDraw.paintImmediately(0, 0, widthIcon, heigthIcon);
}
}