Лабораторная работа №5 (возможно что-то да работает)
This commit is contained in:
parent
fcb6bf6d11
commit
f6d2369ac6
@ -40,7 +40,7 @@ public class FormCleaningCar extends JFrame {
|
|||||||
_drawningTruck.SetPictureSize(pictureBox.getWidth(), pictureBox.getHeight());
|
_drawningTruck.SetPictureSize(pictureBox.getWidth(), pictureBox.getHeight());
|
||||||
comboBoxStrategy.setEnabled(true);
|
comboBoxStrategy.setEnabled(true);
|
||||||
_strategy = null;
|
_strategy = null;
|
||||||
repaint(); //по-идее вызовет paint()
|
repaint();
|
||||||
}
|
}
|
||||||
public FormCleaningCar() {
|
public FormCleaningCar() {
|
||||||
setSize(1000, 600);
|
setSize(1000, 600);
|
||||||
|
@ -86,7 +86,6 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
|
|
||||||
//ButtonAddTruck_Click
|
//ButtonAddTruck_Click
|
||||||
buttonAddTruck.addActionListener(e -> {
|
buttonAddTruck.addActionListener(e -> {
|
||||||
//CreateObject("DrawningTruck");
|
|
||||||
FormTruckConfig form = new FormTruckConfig();
|
FormTruckConfig form = new FormTruckConfig();
|
||||||
form.Init();
|
form.Init();
|
||||||
form.setVisible(true);
|
form.setVisible(true);
|
||||||
@ -251,34 +250,6 @@ public class FormCleaningCarCollection extends JFrame{
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private void CreateObject(String type) {
|
|
||||||
if (_company == null) return;
|
|
||||||
Random random = new Random();
|
|
||||||
DrawningTruck drawningTruck;
|
|
||||||
switch (type) {
|
|
||||||
case "DrawningTruck":
|
|
||||||
drawningTruck = new DrawningTruck(random.nextInt(100, 300), random.nextDouble(100, 3000),
|
|
||||||
GetColor(random));
|
|
||||||
break;
|
|
||||||
case "DrawningCleaningCar":
|
|
||||||
drawningTruck = new DrawningCleaningCar(random.nextInt(100, 300), random.nextDouble(100, 3000),
|
|
||||||
GetColor(random), GetColor(random),
|
|
||||||
random.nextBoolean(), random.nextBoolean(), random.nextBoolean());
|
|
||||||
break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
if (_company._collection.Insert(drawningTruck, 0) != -1) {
|
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
|
||||||
repaint();
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private Color GetColor(Random random) {
|
|
||||||
Color color = new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256));
|
|
||||||
Color colorChooser = JColorChooser.showDialog(this, "Выберите цвет", color);
|
|
||||||
return colorChooser;
|
|
||||||
}
|
|
||||||
private void RefreshListBoxItems()
|
private void RefreshListBoxItems()
|
||||||
{
|
{
|
||||||
listBoxCollection.removeAll();
|
listBoxCollection.removeAll();
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
<children>
|
<children>
|
||||||
<grid id="50bbc" binding="GroupBoxConfig" layout-manager="GridLayoutManager" row-count="6" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="50bbc" binding="GroupBoxConfig" layout-manager="GridLayoutManager" row-count="7" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false">
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="2" indent="0" use-parent-layout="false">
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<children>
|
<children>
|
||||||
<component id="9090b" class="javax.swing.JLabel" binding="labelSimpleObject">
|
<component id="9090b" class="javax.swing.JLabel" binding="labelSimpleObject">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="5" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
<grid row="6" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="90" height="40"/>
|
<minimum-size width="90" height="40"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -33,19 +33,14 @@
|
|||||||
<verticalAlignment value="0"/>
|
<verticalAlignment value="0"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<hspacer id="56992">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="0" row-span="1" col-span="3" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
</hspacer>
|
|
||||||
<vspacer id="f3150">
|
<vspacer id="f3150">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="2" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="3" row-span="2" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
</vspacer>
|
</vspacer>
|
||||||
<component id="bef18" class="javax.swing.JLabel" binding="labelModifiedObject">
|
<component id="bef18" class="javax.swing.JLabel" binding="labelModifiedObject">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="5" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
<grid row="6" column="5" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="2" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="90" height="40"/>
|
<minimum-size width="90" height="40"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -58,7 +53,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="4ddc3" class="javax.swing.JLabel" binding="labelSpeed">
|
<component id="4ddc3" class="javax.swing.JLabel" binding="labelSpeed">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Скорость:"/>
|
<text value="Скорость:"/>
|
||||||
@ -66,9 +61,9 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="e70e0" class="javax.swing.JSpinner" binding="spinnerSpeed">
|
<component id="e70e0" class="javax.swing.JSpinner" binding="spinnerSpeed">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="70" height="20"/>
|
<minimum-size width="70" height="20"/>
|
||||||
<preferred-size width="61" height="20"/>
|
<preferred-size width="70" height="20"/>
|
||||||
<maximum-size width="70" height="-1"/>
|
<maximum-size width="70" height="-1"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -76,7 +71,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="32f" class="javax.swing.JLabel" binding="labelWeight">
|
<component id="32f" class="javax.swing.JLabel" binding="labelWeight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Вес:"/>
|
<text value="Вес:"/>
|
||||||
@ -84,9 +79,9 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="532dd" class="javax.swing.JSpinner" binding="spinnerWeight">
|
<component id="532dd" class="javax.swing.JSpinner" binding="spinnerWeight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="70" height="20"/>
|
<minimum-size width="70" height="20"/>
|
||||||
<preferred-size width="61" height="20"/>
|
<preferred-size width="70" height="20"/>
|
||||||
<maximum-size width="70" height="-1"/>
|
<maximum-size width="70" height="-1"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -94,7 +89,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="77aaa" class="javax.swing.JCheckBox" binding="checkBoxTank">
|
<component id="77aaa" class="javax.swing.JCheckBox" binding="checkBoxTank">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="3" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Признак наличия бака"/>
|
<text value="Признак наличия бака"/>
|
||||||
@ -102,15 +97,15 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="189fd" class="javax.swing.JCheckBox" binding="checkBoxSweepingBrush">
|
<component id="189fd" class="javax.swing.JCheckBox" binding="checkBoxSweepingBrush">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Признак наличия щётки"/>
|
<text value="Признак наличия щётки"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="69dcd" class="javax.swing.JCheckBox" binding="CheckBoxFlashLight">
|
<component id="69dcd" class="javax.swing.JCheckBox" binding="checkBoxFlashLight">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
<grid row="5" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Признак наличия маячка"/>
|
<text value="Признак наличия маячка"/>
|
||||||
@ -119,7 +114,7 @@
|
|||||||
<grid id="59a96" binding="groupBoxColors" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="59a96" binding="groupBoxColors" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
<margin top="0" left="0" bottom="0" right="0"/>
|
<margin top="0" left="0" bottom="0" right="0"/>
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="3" row-span="5" col-span="2" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
<grid row="0" column="4" row-span="6" col-span="2" vsize-policy="3" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
<minimum-size width="300" height="-1"/>
|
<minimum-size width="300" height="-1"/>
|
||||||
<preferred-size width="300" height="-1"/>
|
<preferred-size width="300" height="-1"/>
|
||||||
</grid>
|
</grid>
|
||||||
@ -235,6 +230,61 @@
|
|||||||
</grid>
|
</grid>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
|
<component id="8a3dc" class="javax.swing.JLabel" binding="labelCountWheels">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Число колёс:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="23c65" class="javax.swing.JSpinner" binding="spinnerCountWheels">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="70" height="20"/>
|
||||||
|
<preferred-size width="20" height="20"/>
|
||||||
|
<maximum-size width="70" height="20"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="ac4ad" class="javax.swing.JLabel" binding="labelTriangleWheels">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="70" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Треугольник"/>
|
||||||
|
<toolTipText value="Triangle"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="d0d6" class="javax.swing.JLabel" binding="labelCircleWheels">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="70" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="2"/>
|
||||||
|
<text value="Круг"/>
|
||||||
|
<toolTipText value="Circle"/>
|
||||||
|
<verticalTextPosition value="0"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="7ba83" class="javax.swing.JLabel" binding="labelRhombWheels">
|
||||||
|
<constraints>
|
||||||
|
<grid row="6" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||||
|
<minimum-size width="70" height="30"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<text value="Ромб"/>
|
||||||
|
<toolTipText value="Rhomb"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="292f4" binding="panelRight" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="292f4" binding="panelRight" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
import CollectionGenericObjects.AbstractCompany;
|
import CollectionGenericObjects.AbstractCompany;
|
||||||
import Drawnings.DrawningCleaningCar;
|
import Drawnings.*;
|
||||||
import Drawnings.DrawningTruck;
|
|
||||||
import Drawnings.IDrawningWheels;
|
|
||||||
import Entities.EntityCleaningCar;
|
import Entities.EntityCleaningCar;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@ -16,9 +14,6 @@ import java.awt.event.ActionListener;
|
|||||||
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class FormTruckConfig extends JFrame {
|
public class FormTruckConfig extends JFrame {
|
||||||
@ -34,7 +29,7 @@ public class FormTruckConfig extends JFrame {
|
|||||||
private JLabel labelWeight;
|
private JLabel labelWeight;
|
||||||
private JCheckBox checkBoxTank;
|
private JCheckBox checkBoxTank;
|
||||||
private JCheckBox checkBoxSweepingBrush;
|
private JCheckBox checkBoxSweepingBrush;
|
||||||
private JCheckBox CheckBoxFlashLight;
|
private JCheckBox checkBoxFlashLight;
|
||||||
private JPanel groupBoxColors;
|
private JPanel groupBoxColors;
|
||||||
private JPanel panelRed;
|
private JPanel panelRed;
|
||||||
private JPanel panelGreen;
|
private JPanel panelGreen;
|
||||||
@ -50,25 +45,34 @@ public class FormTruckConfig extends JFrame {
|
|||||||
private JPanel panelObject;
|
private JPanel panelObject;
|
||||||
private JLabel labelBodyColor;
|
private JLabel labelBodyColor;
|
||||||
private JLabel labelAdditionalColor;
|
private JLabel labelAdditionalColor;
|
||||||
|
private JSpinner spinnerCountWheels;
|
||||||
|
private JLabel labelCountWheels;
|
||||||
|
private JLabel labelTriangleWheels;
|
||||||
|
private JLabel labelCircleWheels;
|
||||||
|
private JLabel labelRhombWheels;
|
||||||
|
|
||||||
public FormTruckConfig() {
|
public FormTruckConfig() {
|
||||||
setTitle("Создание объекта");
|
setTitle("Создание объекта");
|
||||||
add(panel);
|
add(panel);
|
||||||
setMinimumSize(new Dimension(900, 300));
|
setMinimumSize(new Dimension(900, 300));
|
||||||
//setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
|
|
||||||
buttonCancel.addActionListener(e -> this.dispose());
|
buttonCancel.addActionListener(e -> this.dispose());
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
protected void Init() {
|
protected void Init() {
|
||||||
labelSimpleObject.setBorder(new LineBorder(Color.BLACK));
|
labelSimpleObject.setBorder(new LineBorder(Color.BLACK, 2));
|
||||||
labelModifiedObject.setBorder(new LineBorder(Color.BLACK));
|
labelModifiedObject.setBorder(new LineBorder(Color.BLACK, 2));
|
||||||
spinnerSpeed.setModel(new SpinnerNumberModel(0, 0, 1000, 1));
|
labelCircleWheels.setBorder(new LineBorder(Color.BLACK, 2));
|
||||||
spinnerWeight.setModel(new SpinnerNumberModel(0, 0, 1000, 1));
|
labelRhombWheels.setBorder(new LineBorder(Color.BLACK, 2));
|
||||||
|
labelTriangleWheels.setBorder(new LineBorder(Color.BLACK, 2));
|
||||||
|
spinnerSpeed.setModel(new SpinnerNumberModel(100, 1, 1000, 1));
|
||||||
|
spinnerWeight.setModel(new SpinnerNumberModel(100, 1, 1000, 1));
|
||||||
|
spinnerCountWheels.setModel(new SpinnerNumberModel(1, 1, 3, 1));
|
||||||
labelBodyColor.setBorder(new LineBorder(Color.BLACK));
|
labelBodyColor.setBorder(new LineBorder(Color.BLACK));
|
||||||
labelAdditionalColor.setBorder(new LineBorder(Color.BLACK));
|
labelAdditionalColor.setBorder(new LineBorder(Color.BLACK));
|
||||||
|
|
||||||
|
|
||||||
MouseAdapter labelObjectsMouseDown = new MouseAdapter() {
|
MouseAdapter labelObjectsMouseDown = new MouseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void mousePressed(MouseEvent e) {
|
public void mousePressed(MouseEvent e) {
|
||||||
@ -90,11 +94,40 @@ public class FormTruckConfig extends JFrame {
|
|||||||
labelModifiedObject.addMouseListener(labelObjectsMouseDown);
|
labelModifiedObject.addMouseListener(labelObjectsMouseDown);
|
||||||
labelModifiedObject.setTransferHandler(labelObjectsTransferHandler);
|
labelModifiedObject.setTransferHandler(labelObjectsTransferHandler);
|
||||||
|
|
||||||
|
ArrayList<JLabel> IDrawningWheelsLabels = new ArrayList<>();
|
||||||
|
IDrawningWheelsLabels.add(labelTriangleWheels);
|
||||||
|
IDrawningWheelsLabels.add(labelCircleWheels);
|
||||||
|
IDrawningWheelsLabels.add(labelRhombWheels);
|
||||||
|
for (JLabel i : IDrawningWheelsLabels) {
|
||||||
|
i.addMouseListener(labelObjectsMouseDown);
|
||||||
|
i.setTransferHandler(new TransferHandler(){
|
||||||
|
@Override
|
||||||
|
public int getSourceActions(JComponent c) {return TransferHandler.COPY;}
|
||||||
|
@Override
|
||||||
|
protected Transferable createTransferable(JComponent c) {
|
||||||
|
IDrawningWheels wheels;
|
||||||
|
switch (i.getToolTipText()) {
|
||||||
|
case "Triangle":
|
||||||
|
wheels = new DrawningTriangleWheels();
|
||||||
|
break;
|
||||||
|
case "Circle":
|
||||||
|
wheels = new DrawningCircleWheels();
|
||||||
|
break;
|
||||||
|
case "Rhomb":
|
||||||
|
wheels = new DrawningRhombWheels();
|
||||||
|
break;
|
||||||
|
default: return null;
|
||||||
|
}
|
||||||
|
return new WheelsTransferable(wheels);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
panelObject.setTransferHandler(new TransferHandler() {
|
panelObject.setTransferHandler(new TransferHandler() {
|
||||||
@Override
|
@Override
|
||||||
public boolean canImport(TransferHandler.TransferSupport support) {
|
public boolean canImport(TransferHandler.TransferSupport support) {
|
||||||
return support.isDataFlavorSupported(DataFlavor.stringFlavor
|
return support.isDataFlavorSupported(DataFlavor.stringFlavor)
|
||||||
/* || support.isDataFlavorSupported(DecksTransferable.decksDataFlavor*/);
|
|| support.isDataFlavorSupported(WheelsTransferable.wheelsDataFlavor);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public boolean importData(TransferHandler.TransferSupport support) {
|
public boolean importData(TransferHandler.TransferSupport support) {
|
||||||
@ -105,21 +138,28 @@ public class FormTruckConfig extends JFrame {
|
|||||||
case "Простой":
|
case "Простой":
|
||||||
_truck = new DrawningTruck((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
_truck = new DrawningTruck((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||||
Color.WHITE);
|
Color.WHITE);
|
||||||
System.out.println("a");
|
|
||||||
break;
|
break;
|
||||||
case "Продвинутый":
|
case "Продвинутый":
|
||||||
_truck = new DrawningCleaningCar((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
_truck = new DrawningCleaningCar((int) spinnerSpeed.getValue(), (int) spinnerWeight.getValue(),
|
||||||
Color.WHITE, Color.BLACK,
|
Color.WHITE, Color.BLACK,
|
||||||
checkBoxTank.isSelected(), checkBoxSweepingBrush.isSelected(), CheckBoxFlashLight.isSelected());
|
checkBoxTank.isSelected(), checkBoxSweepingBrush.isSelected(), checkBoxFlashLight.isSelected());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (_truck != null) {
|
if (_truck != null) {
|
||||||
_truck.SetPictureSize(panelObject.getWidth(), panelObject.getHeight());
|
_truck.SetPictureSize(panelObject.getWidth(), panelObject.getHeight());
|
||||||
_truck.SetPosition(20,20);
|
_truck.SetPosition(60,30);
|
||||||
|
_truck.drawningWheels.setCountWheels((int)spinnerCountWheels.getValue());
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
catch (UnsupportedFlavorException | IOException e) {}
|
catch (UnsupportedFlavorException | IOException e) {}
|
||||||
|
try {
|
||||||
|
IDrawningWheels wheels =
|
||||||
|
(IDrawningWheels) support.getTransferable().getTransferData(WheelsTransferable.wheelsDataFlavor);
|
||||||
|
_truck.drawningWheels = wheels;
|
||||||
|
_truck.drawningWheels.setCountWheels((int) spinnerCountWheels.getValue());
|
||||||
|
|
||||||
|
}catch (UnsupportedFlavorException | IOException e) {}
|
||||||
repaint();
|
repaint();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -198,30 +238,61 @@ public class FormTruckConfig extends JFrame {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
//SetTruck
|
||||||
buttonAdd.addActionListener(new ActionListener() {
|
buttonAdd.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (_company == null || _truck == null) {
|
if (_company == null || _truck == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DrawningTruck truck;
|
if (_company._collection.Insert(_truck, 0) != -1) {
|
||||||
if (_truck instanceof DrawningCleaningCar) {
|
|
||||||
truck = new DrawningCleaningCar((EntityCleaningCar) _truck.EntityTruck, _truck.drawningWheels);
|
|
||||||
} else {
|
|
||||||
truck = new DrawningTruck(_truck.getEntityTruck(), _truck.drawningWheels);
|
|
||||||
}
|
|
||||||
if (_company._collection.Insert(truck, 0) != -1) {
|
|
||||||
dispose();
|
|
||||||
FormCleaningCarCollection.Show();
|
FormCleaningCarCollection.Show();
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
JOptionPane.showMessageDialog(null, "Объект добавлен");
|
||||||
//_company = null;
|
|
||||||
} else {
|
} else {
|
||||||
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
JOptionPane.showMessageDialog(null, "Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
|
dispose();
|
||||||
|
_company = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
spinnerCountWheels.addChangeListener(e -> {
|
||||||
|
if (_truck == null) return;
|
||||||
|
_truck.drawningWheels.setCountWheels((int)spinnerCountWheels.getValue());
|
||||||
|
repaint();
|
||||||
|
});
|
||||||
|
|
||||||
|
checkBoxTank.addActionListener(e -> {
|
||||||
|
if (_truck == null) return;
|
||||||
|
if (_truck.EntityTruck instanceof EntityCleaningCar) {
|
||||||
|
((EntityCleaningCar) _truck.EntityTruck).setTank(checkBoxTank.isSelected());
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
checkBoxSweepingBrush.addActionListener(e -> {
|
||||||
|
if (_truck == null) return;
|
||||||
|
if (_truck.EntityTruck instanceof EntityCleaningCar) {
|
||||||
|
((EntityCleaningCar) _truck.EntityTruck).setSweepingBrush(checkBoxSweepingBrush.isSelected());
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
checkBoxFlashLight.addActionListener(e -> {
|
||||||
|
if (_truck == null) return;
|
||||||
|
if (_truck.EntityTruck instanceof EntityCleaningCar) {
|
||||||
|
((EntityCleaningCar) _truck.EntityTruck).setFlashLight(checkBoxFlashLight.isSelected());
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
spinnerWeight.addChangeListener(e -> {
|
||||||
|
if (_truck == null) return;
|
||||||
|
_truck.EntityTruck.setSpeed((int)spinnerSpeed.getValue());
|
||||||
|
});
|
||||||
|
spinnerWeight.addChangeListener(e -> {
|
||||||
|
if (_truck == null) return;
|
||||||
|
_truck.EntityTruck.setWeight((int)spinnerWeight.getValue());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
public void SetCompany(AbstractCompany company) {
|
public void SetCompany(AbstractCompany company) {
|
||||||
_company = company;
|
_company = company;
|
||||||
@ -259,4 +330,28 @@ public class FormTruckConfig extends JFrame {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class WheelsTransferable implements Transferable {
|
||||||
|
private IDrawningWheels wheels;
|
||||||
|
private static final DataFlavor wheelsDataFlavor = new DataFlavor(IDrawningWheels.class, "Decks");
|
||||||
|
public WheelsTransferable(IDrawningWheels wheels) {
|
||||||
|
this.wheels = wheels;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return new DataFlavor[]{wheelsDataFlavor};
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
return flavor.equals(wheelsDataFlavor);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
|
if (isDataFlavorSupported(flavor)) {
|
||||||
|
return wheels;
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user