From e520452540b96a68f30b25b659fb73f551b6c01f Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 18 Nov 2022 16:31:49 +0400 Subject: [PATCH 1/5] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=205-?= =?UTF-8?q?=D0=B9=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/DrawingAirbus.java | 33 +- Project/src/DrawingPlane.java | 84 ++-- Project/src/EntityAirbus.java | 24 +- Project/src/FormMapWithSetPlanesGeneric.java | 43 +- Project/src/FormPlane.java | 4 +- Project/src/FormPlaneConfig.form | 419 +++++++++++++++++++ Project/src/FormPlaneConfig.java | 237 +++++++++++ 7 files changed, 768 insertions(+), 76 deletions(-) create mode 100644 Project/src/FormPlaneConfig.form create mode 100644 Project/src/FormPlaneConfig.java diff --git a/Project/src/DrawingAirbus.java b/Project/src/DrawingAirbus.java index 8dab024..5d8009b 100644 --- a/Project/src/DrawingAirbus.java +++ b/Project/src/DrawingAirbus.java @@ -2,11 +2,14 @@ import java.awt.*; public class DrawingAirbus extends DrawingPlane { + private Color addColor; + //Конструктор - public DrawingAirbus(int speed, int weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine) + public DrawingAirbus(int speed, int weight, Color corpusColor, int countWindow, Color addColor, boolean addCompartment, boolean addEngine) { - super(speed, weight, corpusColor, 70, 30); + super(speed, weight, corpusColor, countWindow, 70, 30); Plane = new EntityAirbus(speed, weight, corpusColor, addColor, addCompartment, addEngine); + this.addColor = addColor; } //Второй конструктор @@ -16,6 +19,22 @@ public class DrawingAirbus extends DrawingPlane Plane = plane; } + public void SetAddColor(Color color) + { + var temp = (EntityAirbus) Plane; + Plane = new EntityAirbus(temp.GetSpeed(), temp.GetWeight(), temp.GetColor(), color, + temp.AddCompartment(), temp.AddEngine()); + addColor = color; + } + + @Override + public void SetColor(Color color) + { + var temp = (EntityAirbus) Plane; + addColor = addColor == null ? Color.WHITE : addColor; + Plane = new EntityAirbus(temp.GetSpeed(), temp.GetWeight(), color, addColor, temp.AddCompartment(), temp.AddEngine()); + } + @Override public void DrawTransport(Graphics g) { @@ -35,21 +54,23 @@ public class DrawingAirbus extends DrawingPlane _startPosY -= 5; //дополнительный пассажирский отсек - if (airbus.AddСompartment) + if (airbus.AddCompartment()) { - g2d.setPaint(airbus.AddColor); + g2d.setPaint(airbus.AddColor()); g2d.fillRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3); g2d.setPaint(Color.BLACK); g2d.drawRect((int)_startPosX + 30, (int)_startPosY + 12, 14, 3); } //дополнительный двигатель - if (airbus.AddEngine) + if (airbus.AddEngine()) { - g2d.setPaint(airbus.AddColor); + g2d.setPaint(airbus.AddColor()); g2d.fillOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5); g2d.setPaint(Color.BLACK); g2d.drawOval((int)_startPosX + 24, (int)_startPosY + 22, 10, 5); } + + super.repaint(); } } diff --git a/Project/src/DrawingPlane.java b/Project/src/DrawingPlane.java index fe40eed..c3c1822 100644 --- a/Project/src/DrawingPlane.java +++ b/Project/src/DrawingPlane.java @@ -5,42 +5,6 @@ import java.util.Random; public class DrawingPlane extends JPanel { - protected EntityPlane Plane; //класс-сущность - public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки - - public void SetAddEnum() - { - Random rnd = new Random(); - int numbEnum = rnd.nextInt(1, 4); - _airplaneWindow.SetAddEnum(numbEnum); - } - - public void SetFormEnum() - { - Random rnd = new Random(); - int numbEnum = rnd.nextInt(1, 4); - - if(numbEnum == 1) - { - _airplaneWindow = new DrawingAirplaneWindow(); - } - - if(numbEnum == 2) - { - _airplaneWindow = new DrawingTriangleAirplaneWindow(); - } - - if(numbEnum == 3) - { - _airplaneWindow = new DrawingRectAirplaneWindow(); - } - } - - public EntityPlane GetPlane() - { - return Plane; - } - protected float _startPosX; //левая координата отрисовки protected float _startPosY; //верхняя координата отрисовки private Integer _pictureWidth = null; //ширина окна отрисовки @@ -48,18 +12,52 @@ public class DrawingPlane extends JPanel protected int _airbusWidth = 50; //ширина отрисовки самолёта protected int _airbusHeight = 16; //высота отрисовки самолёта - //конструктор - public DrawingPlane(int speed, float weight, Color corpusColor) + protected EntityPlane Plane; //класс-сущность + public IAdditionalDrawingObject _airplaneWindow; //для дополнительной отрисовки + + public void SetColor(Color color) { - Plane = new EntityPlane(speed, weight, corpusColor); - SetFormEnum(); - SetAddEnum(); + Plane = new EntityPlane(Plane.GetSpeed(), Plane.GetWeight(), color); + } + + public void SetTypeWindow(int countWindow, IAdditionalDrawingObject window) + { + _airplaneWindow = window; + _airplaneWindow.SetAddEnum(countWindow); + } + + public EntityPlane GetPlane() + { + return Plane; } //конструктор - public DrawingPlane(int speed, float weight, Color corpusColor, int planeWidth, int planeHeight) + public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow) { - this(speed, weight, corpusColor); + Random rnd = new Random(); + int randomTypeWindow = rnd.nextInt(3); + Plane = new EntityPlane(speed, weight, corpusColor); + + if(randomTypeWindow == 1) + { + _airplaneWindow = new DrawingAirplaneWindow(); + } + else if(randomTypeWindow == 2) + { + _airplaneWindow = new DrawingRectAirplaneWindow(); + } + else + { + _airplaneWindow = new DrawingTriangleAirplaneWindow(); + } + + _airplaneWindow.SetAddEnum(countWindow); + } + + //конструктор + public DrawingPlane(int speed, float weight, Color corpusColor, int countWindow, int planeWidth, int planeHeight) + { + this(speed, weight, corpusColor, countWindow); _airbusWidth = planeWidth; _airbusHeight = planeHeight; } diff --git a/Project/src/EntityAirbus.java b/Project/src/EntityAirbus.java index 10cfcfe..af6603c 100644 --- a/Project/src/EntityAirbus.java +++ b/Project/src/EntityAirbus.java @@ -3,20 +3,32 @@ import java.awt.*; public class EntityAirbus extends EntityPlane { //Дополнительный цвет - public Color AddColor; + public Color addColor; + public Color AddColor() + { + return addColor; + } //Признак наличия дополнительно пассажирского отсека - public boolean AddСompartment; + public boolean addСompartment; + public boolean AddCompartment() + { + return addСompartment; + } //Признак наличия дополнительных двигателей - public boolean AddEngine; + public boolean addEngine; + public boolean AddEngine() + { + return addEngine; + } //Инициализация свойств public EntityAirbus(int speed, float weight, Color corpusColor, Color addColor, boolean addCompartment, boolean addEngine) { super(speed, weight, corpusColor); - AddColor = addColor; - AddСompartment = addCompartment; - AddEngine = addEngine; + this.addColor = addColor; + this.addСompartment = addCompartment; + this.addEngine = addEngine; } } diff --git a/Project/src/FormMapWithSetPlanesGeneric.java b/Project/src/FormMapWithSetPlanesGeneric.java index cc74529..50a3ef2 100644 --- a/Project/src/FormMapWithSetPlanesGeneric.java +++ b/Project/src/FormMapWithSetPlanesGeneric.java @@ -186,30 +186,35 @@ public class FormMapWithSetPlanesGeneric { } }); - //добавление самолёта + //добавление самолёта с использованием делегата ButtonAddPlane.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if(ListBoxMaps.getSelectedIndex() == -1) - { - return; - } + FormPlaneConfig form = new FormPlaneConfig(); - FormPlane form = new FormPlane(); - form.setSize(700,400); + form.AddEvent(newPlane ->{ + if(ListBoxMaps.getSelectedIndex() == -1) + { + return; + } + + if(newPlane != null) + { + DrawningObjectPlane plane = new DrawningObjectPlane(newPlane); + + if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1) + { + JOptionPane.showMessageDialog(null, "Объект добавлен"); + UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet()); + } + else + { + JOptionPane.showMessageDialog(null, "Не удалось добавить объект"); + } + } + }); + form.setSize(975, 360); form.setVisible(true); - form.setModal(true); - DrawningObjectPlane plane = new DrawningObjectPlane(form.GetSelectedShip()); - - if(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).Add(plane) != -1) - { - JOptionPane.showMessageDialog(null,"Объект добавлен"); - UpdateWindow(_mapsCollection.get(ListBoxMaps.getSelectedValue().toString()).ShowSet()); - } - else - { - JOptionPane.showMessageDialog(null,"Не удалось добавить объект"); - } } }); diff --git a/Project/src/FormPlane.java b/Project/src/FormPlane.java index dabac37..5700e0a 100644 --- a/Project/src/FormPlane.java +++ b/Project/src/FormPlane.java @@ -134,7 +134,7 @@ public class FormPlane extends JDialog Color colorSimple = JColorChooser.showDialog(null, "Выберите цвет", null); _plane = new DrawingPlane(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), - colorSimple); + colorSimple, rnd.nextInt(3)); SetData(); @@ -156,7 +156,7 @@ public class FormPlane extends JDialog Color colorModif = JColorChooser.showDialog(null, "Выберите цвет", null); _plane = new DrawingAirbus(rnd.nextInt(100, 300), rnd.nextInt(1000, 2000), - colorSimple, colorModif, rnd.nextBoolean(), rnd.nextBoolean()); + colorSimple, rnd.nextInt(3), colorModif, rnd.nextBoolean(), rnd.nextBoolean()); SetData(); diff --git a/Project/src/FormPlaneConfig.form b/Project/src/FormPlaneConfig.form new file mode 100644 index 0000000..e551733 --- /dev/null +++ b/Project/src/FormPlaneConfig.form @@ -0,0 +1,419 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Project/src/FormPlaneConfig.java b/Project/src/FormPlaneConfig.java new file mode 100644 index 0000000..d41e9f9 --- /dev/null +++ b/Project/src/FormPlaneConfig.java @@ -0,0 +1,237 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.*; +import java.awt.image.BufferedImage; +import java.beans.Expression; +import java.rmi.server.ExportException; +import java.util.concurrent.CountDownLatch; +import java.util.function.Consumer; + +public class FormPlaneConfig extends JDialog{ + private JButton ButtonAddObject; + private JButton ButtonCancel; + private JPanel GroupBoxConfig; + private JPanel PanelObject; + private JPanel GroupBoxColors; + private JPanel PanelRed; + private JPanel PanelGreen; + private JPanel PanelBlue; + private JPanel PanelYellow; + private JPanel PanelPurple; + private JPanel PanelBlack; + private JPanel PanelGray; + private JPanel PanelWhite; + private JLabel LabelSimpleObject; + private JLabel LabelModifiedObject; + private JLabel LabelBaseColor; + private JLabel LabelAddColor; + private JPanel PictureBoxObject; + private JLabel LabelSpeed; + private JLabel LabelWeight; + private JSpinner NumericUpDownWeight; + private JSpinner NumericUpDownSpeed; + private JCheckBox CheckBoxAddСompartment; + private JCheckBox CheckBoxAddEngine; + private JPanel GroupBoxSelectPlaneWindow; + private JPanel GroubBoxSelectedCountWindow; + private JSpinner NumericUpDownCountWindow; + private JPanel MainPanel; + private JLabel LabelTypeWindow; + private JLabel LabelSimpleWindow; + private JLabel LabelRectWindow; + private JLabel LabelTriangleWindow; + + //переменная-выбранный самолёт + DrawingPlane _plane; + + //событие + Consumer EventAddPlane; + + public void AddEvent(Consumer ev){ + EventAddPlane = ev; + } + + //конструктор + public FormPlaneConfig() + { + super(new Frame("Аэробус")); + CreateWindow(); + setModal(true); + getContentPane().add(MainPanel); + } + + public void Draw(DrawingPlane _plane) + { + PictureBoxObject.removeAll(); + BufferedImage bmp = new BufferedImage(250, 200, BufferedImage.TYPE_INT_RGB); + Graphics gr = bmp.getGraphics(); + + gr.setColor(new Color(238, 238, 238)); + gr.fillRect(0, 0, 250, 200); + + if (_plane.GetPlane() != null) { + _plane.DrawTransport(gr); + JLabel imageOfLogo = new JLabel(); + imageOfLogo.setPreferredSize(PictureBoxObject.getSize()); + imageOfLogo.setMinimumSize(new Dimension(1, 1)); + imageOfLogo.setIcon(new ImageIcon(bmp)); + PictureBoxObject.add(imageOfLogo, BorderLayout.CENTER); + } + + validate(); + } + + public void CreateWindow() + { + setPreferredSize(new Dimension(1000, 700)); + getContentPane().add(MainPanel); + + //рамки у Label + LabelAddColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + LabelTypeWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + LabelBaseColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + LabelModifiedObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + LabelSimpleObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + LabelSimpleWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + LabelRectWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + LabelTriangleWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); + + //настройка значений у NumericUpDown + NumericUpDownSpeed.setModel(new SpinnerNumberModel(1000, 1000, 3000, 1)); + NumericUpDownWeight.setModel(new SpinnerNumberModel(750, 100, 1500, 1)); + NumericUpDownCountWindow.setModel(new SpinnerNumberModel(1, 1, 3, 1)); + + MouseAdapter drag = new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) { + setCursor(new Cursor(Cursor.HAND_CURSOR)); + } + + @Override + public void mouseReleased(MouseEvent e) { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + Drop((JComponent) e.getSource()); + } + }; + + MouseAdapter defCursor = new MouseAdapter() { + @Override + public void mouseExited(MouseEvent e) { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } + }; + + //настройки курсоров + PictureBoxObject.addMouseListener(defCursor); + LabelBaseColor.addMouseListener(defCursor); + LabelAddColor.addMouseListener(defCursor); + LabelTypeWindow.addMouseListener(defCursor); + + PanelBlack.addMouseListener(drag); + PanelPurple.addMouseListener(drag); + PanelGray.addMouseListener(drag); + PanelGreen.addMouseListener(drag); + PanelRed.addMouseListener(drag); + PanelWhite.addMouseListener(drag); + PanelYellow.addMouseListener(drag); + PanelBlue.addMouseListener(drag); + + LabelSimpleObject.addMouseListener(drag); + LabelModifiedObject.addMouseListener(drag); + LabelSimpleWindow.addMouseListener(drag); + LabelRectWindow.addMouseListener(drag); + LabelTriangleWindow.addMouseListener(drag); + + ButtonAddObject.addActionListener(e -> { + EventAddPlane.accept(_plane); + dispose(); + }); + + ButtonCancel.addActionListener(e -> dispose()); + } + + public void Drop(JComponent dropItem) + { + if(dropItem == null) + { + return; + } + + if(dropItem instanceof JPanel panel) + { + if(_plane == null) + { + return; + } + + if(LabelBaseColor.getMousePosition() != null) + { + _plane.SetColor(panel.getBackground()); + Draw(_plane); + } + + if(LabelAddColor.getMousePosition() != null && _plane instanceof DrawingAirbus airbus) + { + airbus.SetAddColor(panel.getBackground()); + Draw(_plane); + } + } + + if(dropItem instanceof JLabel label && PictureBoxObject.getMousePosition() != null) + { + int speed = (int)NumericUpDownSpeed.getValue(); + int weight = (int)NumericUpDownWeight.getValue(); + int countWindow = (int)NumericUpDownCountWindow.getValue(); + boolean addCompartment = CheckBoxAddСompartment.isSelected(); + boolean addEngine = CheckBoxAddEngine.isSelected(); + + if(label == LabelSimpleObject) + { + try + { + PictureBoxObject.remove(_plane); + _plane = new DrawingPlane(speed, weight, Color.WHITE, countWindow); + Draw(_plane); + } + catch(Exception ex) { } + } + else if(label == LabelModifiedObject) + { + try + { + PictureBoxObject.remove(_plane); + _plane = new DrawingAirbus(speed, weight, Color.WHITE, countWindow, Color.WHITE, addCompartment, addEngine); + Draw(_plane); + } + catch (Exception ex) { }; + } + + if(_plane != null) + { + _plane.SetPosition(PictureBoxObject.getWidth() - 200, PictureBoxObject.getHeight() - 150, PictureBoxObject.getWidth(), PictureBoxObject.getHeight()); + PictureBoxObject.add(_plane, BorderLayout.CENTER); + Draw(_plane); + } + } + else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane != null) + { + if(label == LabelSimpleWindow) + { + _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingAirplaneWindow()); + Draw(_plane); + } + + if(label == LabelRectWindow) + { + _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingRectAirplaneWindow()); + Draw(_plane); + } + + if(label == LabelTriangleWindow) + { + _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingTriangleAirplaneWindow()); + Draw(_plane); + } + } + } +} -- 2.25.1 From 80a4d1c7d7b52fd51a935e28a492947730caaa89 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 18 Nov 2022 18:38:30 +0400 Subject: [PATCH 2/5] =?UTF-8?q?5-=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/FormMapWithSetPlanesGeneric.java | 3 +- Project/src/FormPlaneConfig.form | 17 ++++----- Project/src/FormPlaneConfig.java | 40 +++++++++++--------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/Project/src/FormMapWithSetPlanesGeneric.java b/Project/src/FormMapWithSetPlanesGeneric.java index 50a3ef2..9e59919 100644 --- a/Project/src/FormMapWithSetPlanesGeneric.java +++ b/Project/src/FormMapWithSetPlanesGeneric.java @@ -10,7 +10,7 @@ import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.util.HashMap; -public class FormMapWithSetPlanesGeneric { +public class FormMapWithSetPlanesGeneric extends JFrame{ public JPanel MainPanel; private JPanel PictureBoxPlane; private JPanel GroupBoxTools; @@ -44,6 +44,7 @@ public class FormMapWithSetPlanesGeneric { public FormMapWithSetPlanesGeneric() { + super("Хранилище"); CreateWindow(); _mapsCollection = new MapsCollection(730, 650); ComboBoxSelectorMap.removeAllItems(); diff --git a/Project/src/FormPlaneConfig.form b/Project/src/FormPlaneConfig.form index e551733..7566cae 100644 --- a/Project/src/FormPlaneConfig.form +++ b/Project/src/FormPlaneConfig.form @@ -335,15 +335,6 @@ - - - - - - - - - @@ -354,6 +345,14 @@ + + + + + + + + diff --git a/Project/src/FormPlaneConfig.java b/Project/src/FormPlaneConfig.java index d41e9f9..401d12f 100644 --- a/Project/src/FormPlaneConfig.java +++ b/Project/src/FormPlaneConfig.java @@ -2,12 +2,12 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.image.BufferedImage; -import java.beans.Expression; -import java.rmi.server.ExportException; -import java.util.concurrent.CountDownLatch; +import java.util.function.Consumer; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.function.Consumer; -public class FormPlaneConfig extends JDialog{ +public class FormPlaneConfig extends JFrame{ private JButton ButtonAddObject; private JButton ButtonCancel; private JPanel GroupBoxConfig; @@ -25,7 +25,6 @@ public class FormPlaneConfig extends JDialog{ private JLabel LabelModifiedObject; private JLabel LabelBaseColor; private JLabel LabelAddColor; - private JPanel PictureBoxObject; private JLabel LabelSpeed; private JLabel LabelWeight; private JSpinner NumericUpDownWeight; @@ -40,6 +39,7 @@ public class FormPlaneConfig extends JDialog{ private JLabel LabelSimpleWindow; private JLabel LabelRectWindow; private JLabel LabelTriangleWindow; + private JPanel PictureBoxPlane; //переменная-выбранный самолёт DrawingPlane _plane; @@ -54,15 +54,13 @@ public class FormPlaneConfig extends JDialog{ //конструктор public FormPlaneConfig() { - super(new Frame("Аэробус")); + super("Самолёт"); CreateWindow(); - setModal(true); - getContentPane().add(MainPanel); } public void Draw(DrawingPlane _plane) { - PictureBoxObject.removeAll(); + PictureBoxPlane.removeAll(); BufferedImage bmp = new BufferedImage(250, 200, BufferedImage.TYPE_INT_RGB); Graphics gr = bmp.getGraphics(); @@ -72,10 +70,10 @@ public class FormPlaneConfig extends JDialog{ if (_plane.GetPlane() != null) { _plane.DrawTransport(gr); JLabel imageOfLogo = new JLabel(); - imageOfLogo.setPreferredSize(PictureBoxObject.getSize()); + imageOfLogo.setPreferredSize(PictureBoxPlane.getSize()); imageOfLogo.setMinimumSize(new Dimension(1, 1)); imageOfLogo.setIcon(new ImageIcon(bmp)); - PictureBoxObject.add(imageOfLogo, BorderLayout.CENTER); + PictureBoxPlane.add(imageOfLogo, BorderLayout.CENTER); } validate(); @@ -122,7 +120,7 @@ public class FormPlaneConfig extends JDialog{ }; //настройки курсоров - PictureBoxObject.addMouseListener(defCursor); + PictureBoxPlane.addMouseListener(defCursor); LabelBaseColor.addMouseListener(defCursor); LabelAddColor.addMouseListener(defCursor); LabelTypeWindow.addMouseListener(defCursor); @@ -168,16 +166,18 @@ public class FormPlaneConfig extends JDialog{ { _plane.SetColor(panel.getBackground()); Draw(_plane); + repaint(); } if(LabelAddColor.getMousePosition() != null && _plane instanceof DrawingAirbus airbus) { airbus.SetAddColor(panel.getBackground()); Draw(_plane); + repaint(); } } - if(dropItem instanceof JLabel label && PictureBoxObject.getMousePosition() != null) + if(dropItem instanceof JLabel label && PictureBoxPlane.getMousePosition() != null) { int speed = (int)NumericUpDownSpeed.getValue(); int weight = (int)NumericUpDownWeight.getValue(); @@ -189,9 +189,9 @@ public class FormPlaneConfig extends JDialog{ { try { - PictureBoxObject.remove(_plane); _plane = new DrawingPlane(speed, weight, Color.WHITE, countWindow); Draw(_plane); + repaint(); } catch(Exception ex) { } } @@ -199,21 +199,23 @@ public class FormPlaneConfig extends JDialog{ { try { - PictureBoxObject.remove(_plane); _plane = new DrawingAirbus(speed, weight, Color.WHITE, countWindow, Color.WHITE, addCompartment, addEngine); Draw(_plane); + repaint(); } catch (Exception ex) { }; } if(_plane != null) { - _plane.SetPosition(PictureBoxObject.getWidth() - 200, PictureBoxObject.getHeight() - 150, PictureBoxObject.getWidth(), PictureBoxObject.getHeight()); - PictureBoxObject.add(_plane, BorderLayout.CENTER); + _plane.SetPosition(PictureBoxPlane.getWidth() - 200, PictureBoxPlane.getHeight() - 150, PictureBoxPlane.getWidth(), PictureBoxPlane.getHeight()); + PictureBoxPlane.add(_plane, BorderLayout.CENTER); Draw(_plane); + repaint(); + revalidate(); } } - else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane != null) + else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane!=null) { if(label == LabelSimpleWindow) { @@ -232,6 +234,8 @@ public class FormPlaneConfig extends JDialog{ _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingTriangleAirplaneWindow()); Draw(_plane); } + + repaint(); } } } -- 2.25.1 From 5d93c8bf38836b4d150517473c06a880f2a0b53a Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 18 Nov 2022 18:45:28 +0400 Subject: [PATCH 3/5] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/FormPlaneConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project/src/FormPlaneConfig.java b/Project/src/FormPlaneConfig.java index 401d12f..2dfcd85 100644 --- a/Project/src/FormPlaneConfig.java +++ b/Project/src/FormPlaneConfig.java @@ -171,7 +171,7 @@ public class FormPlaneConfig extends JFrame{ if(LabelAddColor.getMousePosition() != null && _plane instanceof DrawingAirbus airbus) { - airbus.SetAddColor(panel.getBackground()); + airbus.SetAddColor(panel.getBackground()); Draw(_plane); repaint(); } -- 2.25.1 From 55364bb61969b69457f2788294064d3289a1c296 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Mon, 21 Nov 2022 23:43:44 +0400 Subject: [PATCH 4/5] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B5=20DnD=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B5?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/FormPlaneConfig.form | 23 +++-- Project/src/FormPlaneConfig.java | 111 ++++++++++++++++++---- Project/src/IAdditionalDrawingObject.java | 2 +- 3 files changed, 102 insertions(+), 34 deletions(-) diff --git a/Project/src/FormPlaneConfig.form b/Project/src/FormPlaneConfig.form index 7566cae..e0549e8 100644 --- a/Project/src/FormPlaneConfig.form +++ b/Project/src/FormPlaneConfig.form @@ -1,6 +1,6 @@
- + @@ -335,16 +335,6 @@ - - - - - - - - - - @@ -397,7 +387,7 @@ - + @@ -406,6 +396,15 @@ + + + + + + + + + diff --git a/Project/src/FormPlaneConfig.java b/Project/src/FormPlaneConfig.java index 2dfcd85..4ca8353 100644 --- a/Project/src/FormPlaneConfig.java +++ b/Project/src/FormPlaneConfig.java @@ -35,7 +35,6 @@ public class FormPlaneConfig extends JFrame{ private JPanel GroubBoxSelectedCountWindow; private JSpinner NumericUpDownCountWindow; private JPanel MainPanel; - private JLabel LabelTypeWindow; private JLabel LabelSimpleWindow; private JLabel LabelRectWindow; private JLabel LabelTriangleWindow; @@ -47,7 +46,14 @@ public class FormPlaneConfig extends JFrame{ //событие Consumer EventAddPlane; - public void AddEvent(Consumer ev){ + //объект для контролирования работы DnD + Object dragObject; + + //хранит в себе объект иллюминатор + Object enterObject; + + public void AddEvent(Consumer ev) + { EventAddPlane = ev; } @@ -86,7 +92,6 @@ public class FormPlaneConfig extends JFrame{ //рамки у Label LabelAddColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); - LabelTypeWindow.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); LabelBaseColor.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); LabelModifiedObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); LabelSimpleObject.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); @@ -123,7 +128,6 @@ public class FormPlaneConfig extends JFrame{ PictureBoxPlane.addMouseListener(defCursor); LabelBaseColor.addMouseListener(defCursor); LabelAddColor.addMouseListener(defCursor); - LabelTypeWindow.addMouseListener(defCursor); PanelBlack.addMouseListener(drag); PanelPurple.addMouseListener(drag); @@ -140,12 +144,20 @@ public class FormPlaneConfig extends JFrame{ LabelRectWindow.addMouseListener(drag); LabelTriangleWindow.addMouseListener(drag); + //передача объекта через событие ButtonAddObject.addActionListener(e -> { EventAddPlane.accept(_plane); dispose(); }); + //лямбда-выражение для закрытия формы ButtonCancel.addActionListener(e -> dispose()); + + AdditWindowDropObject(LabelSimpleWindow); + AdditWindowDropObject(LabelRectWindow); + AdditWindowDropObject(LabelTriangleWindow); + + AdditWindowDropTarget(PictureBoxPlane); } public void Drop(JComponent dropItem) @@ -215,27 +227,84 @@ public class FormPlaneConfig extends JFrame{ revalidate(); } } - else if(dropItem instanceof JLabel label && LabelTypeWindow.getMousePosition() != null && _plane!=null) + } + + void AdditWindowDropTarget(JComponent obj) + { + obj.addMouseListener(new MouseAdapter() { + @Override + public void mouseEntered(MouseEvent e) {super.mouseEntered(e); + Paddle_DragEnter(obj); + } + @Override + public void mouseExited(MouseEvent e) {super.mouseExited(e); + DragExit(); + } + }); + } + + void AdditWindowDropObject(JComponent obj) + { + obj.addMouseListener(new MouseAdapter() { + @Override + public void mousePressed(MouseEvent e) {super.mousePressed(e); + Paddle_MouseDown(obj); + } + @Override + public void mouseReleased(MouseEvent e) {super.mouseReleased(e); + Paddle_DragDrop(); + } + }); + } + + void Paddle_MouseDown(Object sender) + { + IAdditionalDrawingObject windows; + switch (((JLabel)sender).getText()){ + case "Простая": + windows = new DrawingAirplaneWindow(); + break; + case "Треугольная": + windows = new DrawingTriangleAirplaneWindow(); + break; + case "Квадратная": + windows = new DrawingRectAirplaneWindow(); + break; + default: + return; + } + + enterObject = windows; + } + + void Paddle_DragEnter(Object sender) + { + if(enterObject != null && IAdditionalDrawingObject.class.isAssignableFrom(enterObject.getClass()) && _plane != null) { - if(label == LabelSimpleWindow) - { - _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingAirplaneWindow()); - Draw(_plane); - } + setCursor(new Cursor(Cursor.HAND_CURSOR)); + dragObject = sender; + } + } - if(label == LabelRectWindow) - { - _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingRectAirplaneWindow()); - Draw(_plane); - } + void Paddle_DragDrop() + { + if(dragObject == null) + { + return; + } - if(label == LabelTriangleWindow) - { - _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), new DrawingTriangleAirplaneWindow()); - Draw(_plane); - } + _plane.SetTypeWindow((int)NumericUpDownCountWindow.getValue(), (IAdditionalDrawingObject)enterObject); + DragExit(); + enterObject = null; + } - repaint(); + void DragExit() + { + if(enterObject != null && dragObject != null) + { + setCursor(Cursor.getDefaultCursor()); + Draw(_plane); + dragObject = null; } } } diff --git a/Project/src/IAdditionalDrawingObject.java b/Project/src/IAdditionalDrawingObject.java index cf9f27b..7b47141 100644 --- a/Project/src/IAdditionalDrawingObject.java +++ b/Project/src/IAdditionalDrawingObject.java @@ -1,6 +1,6 @@ import java.awt.*; -public interface IAdditionalDrawingObject +public interface IAdditionalDrawingObject { void SetAddEnum(int airplaneWindow); void DrawAirplaneWindow(Color colorAirplaneWindow, Graphics g, float _startPosX, float _startPosY); -- 2.25.1 From 179f3ecb140b950185e02ff53335e3de67d2936d Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Thu, 24 Nov 2022 23:17:14 +0400 Subject: [PATCH 5/5] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE=20=D0=BE?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8E.=20?= =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D1=91=D0=BD=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=206-=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project/src/FormMapWithSetPlanesGeneric.java | 4 +++- Project/src/FormPlaneConfig.java | 25 ++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Project/src/FormMapWithSetPlanesGeneric.java b/Project/src/FormMapWithSetPlanesGeneric.java index 9e59919..88b52b3 100644 --- a/Project/src/FormMapWithSetPlanesGeneric.java +++ b/Project/src/FormMapWithSetPlanesGeneric.java @@ -214,6 +214,7 @@ public class FormMapWithSetPlanesGeneric extends JFrame{ } } }); + form.setSize(975, 360); form.setVisible(true); } @@ -365,7 +366,8 @@ public class FormMapWithSetPlanesGeneric extends JFrame{ public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); - if ((c < '0') || (c > '9')) { + if ((c < '0') || (c > '9')) + { e.consume(); } } diff --git a/Project/src/FormPlaneConfig.java b/Project/src/FormPlaneConfig.java index 4ca8353..6a6cce7 100644 --- a/Project/src/FormPlaneConfig.java +++ b/Project/src/FormPlaneConfig.java @@ -144,6 +144,13 @@ public class FormPlaneConfig extends JFrame{ LabelRectWindow.addMouseListener(drag); LabelTriangleWindow.addMouseListener(drag); + //настройка DnD для перетаскивания формы иллюминаторов + AdditWindowDropObject(LabelSimpleWindow); + AdditWindowDropObject(LabelRectWindow); + AdditWindowDropObject(LabelTriangleWindow); + + AdditWindowDropTarget(PictureBoxPlane); + //передача объекта через событие ButtonAddObject.addActionListener(e -> { EventAddPlane.accept(_plane); @@ -152,12 +159,6 @@ public class FormPlaneConfig extends JFrame{ //лямбда-выражение для закрытия формы ButtonCancel.addActionListener(e -> dispose()); - - AdditWindowDropObject(LabelSimpleWindow); - AdditWindowDropObject(LabelRectWindow); - AdditWindowDropObject(LabelTriangleWindow); - - AdditWindowDropTarget(PictureBoxPlane); } public void Drop(JComponent dropItem) @@ -234,7 +235,7 @@ public class FormPlaneConfig extends JFrame{ obj.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) {super.mouseEntered(e); - Paddle_DragEnter(obj); + Window_DragEnter(obj); } @Override public void mouseExited(MouseEvent e) {super.mouseExited(e); @@ -248,16 +249,16 @@ public class FormPlaneConfig extends JFrame{ obj.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) {super.mousePressed(e); - Paddle_MouseDown(obj); + Window_MouseDown(obj); } @Override public void mouseReleased(MouseEvent e) {super.mouseReleased(e); - Paddle_DragDrop(); + Window_DragDrop(); } }); } - void Paddle_MouseDown(Object sender) + void Window_MouseDown(Object sender) { IAdditionalDrawingObject windows; switch (((JLabel)sender).getText()){ @@ -277,7 +278,7 @@ public class FormPlaneConfig extends JFrame{ enterObject = windows; } - void Paddle_DragEnter(Object sender) + void Window_DragEnter(Object sender) { if(enterObject != null && IAdditionalDrawingObject.class.isAssignableFrom(enterObject.getClass()) && _plane != null) { @@ -286,7 +287,7 @@ public class FormPlaneConfig extends JFrame{ } } - void Paddle_DragDrop() + void Window_DragDrop() { if(dragObject == null) { -- 2.25.1