Some fixes

This commit is contained in:
Сергей Полевой 2022-11-07 15:32:44 +04:00
parent df909891d8
commit 680274195d

View File

@ -10,7 +10,6 @@ public class FormArtilleryConfig extends JFrame {
private final EventListener<DrawingArtillery> eventHandler = new EventListener<>(); private final EventListener<DrawingArtillery> eventHandler = new EventListener<>();
private DrawingArtillery artillery; private DrawingArtillery artillery;
private JComponent draggedComponent;
private JPanel contentPanel; private JPanel contentPanel;
private JPanel toolsPanel; private JPanel toolsPanel;
private JPanel workspacePanel; private JPanel workspacePanel;
@ -70,13 +69,12 @@ public class FormArtilleryConfig extends JFrame {
public void mousePressed(MouseEvent e) { public void mousePressed(MouseEvent e) {
super.mouseReleased(e); super.mouseReleased(e);
setCursor(new Cursor(Cursor.HAND_CURSOR)); setCursor(new Cursor(Cursor.HAND_CURSOR));
draggedComponent = (JComponent) e.getSource();
} }
@Override @Override
public void mouseReleased(MouseEvent e) { public void mouseReleased(MouseEvent e) {
super.mouseReleased(e); super.mouseReleased(e);
dispatchDrop(); dispatchDrop((JComponent) e.getSource());
} }
}; };
@ -107,13 +105,13 @@ public class FormArtilleryConfig extends JFrame {
eventHandler.addListener(listener); eventHandler.addListener(listener);
} }
public void dispatchDrop() { public void dispatchDrop(JComponent droppedComponent) {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
if (draggedComponent == null) { if (droppedComponent == null) {
return; return;
} }
if (draggedComponent instanceof JPanel panel) { if (droppedComponent instanceof JPanel panel) {
if (colorLabel.getMousePosition() != null) { if (colorLabel.getMousePosition() != null) {
artillery.setColor(panel.getBackground()); artillery.setColor(panel.getBackground());
artillery.getRollers().setColor(panel.getBackground()); artillery.getRollers().setColor(panel.getBackground());
@ -122,7 +120,7 @@ public class FormArtilleryConfig extends JFrame {
advanced.setDopColor(panel.getBackground()); advanced.setDopColor(panel.getBackground());
} }
} }
if (draggedComponent instanceof JLabel label && pictureBox.getMousePosition() != null) { if (droppedComponent instanceof JLabel label && pictureBox.getMousePosition() != null) {
int speed = (Integer) speedSpinner.getValue(); int speed = (Integer) speedSpinner.getValue();
int weight = (Integer) weightSpinner.getValue(); int weight = (Integer) weightSpinner.getValue();
int rollersCount = (Integer) rollersSpinner.getValue(); int rollersCount = (Integer) rollersSpinner.getValue();
@ -141,7 +139,7 @@ public class FormArtilleryConfig extends JFrame {
artillery.setRollers(new DrawingSquaredRollers(rollersCount, artillery.getArtillery().getBodyColor())); artillery.setRollers(new DrawingSquaredRollers(rollersCount, artillery.getArtillery().getBodyColor()));
} }
} }
draggedComponent = null;
repaint(); repaint();
} }