lab4
This commit is contained in:
parent
5ccd5bf644
commit
5eef861388
@ -36,17 +36,17 @@ public class FormDopClassParameters {
|
|||||||
|
|
||||||
public void AddEntityUsta() {
|
public void AddEntityUsta() {
|
||||||
rnd = new Random();
|
rnd = new Random();
|
||||||
EntityUsta entityLocomotive;
|
EntityUsta entityUsta;
|
||||||
Color color = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
Color color = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
||||||
Color color2 = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
Color color2 = new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
|
||||||
if (rnd.nextBoolean()) {
|
if (rnd.nextBoolean()) {
|
||||||
entityLocomotive = new EntityUsta(
|
entityUsta = new EntityUsta(
|
||||||
rnd.nextInt(100, 300),
|
rnd.nextInt(100, 300),
|
||||||
rnd.nextInt(1000, 3000),
|
rnd.nextInt(1000, 3000),
|
||||||
color
|
color
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
entityLocomotive = new EntityUstaBat(
|
entityUsta = new EntityUstaBat(
|
||||||
rnd.nextInt(100, 300),
|
rnd.nextInt(100, 300),
|
||||||
rnd.nextInt(1000, 3000),
|
rnd.nextInt(1000, 3000),
|
||||||
color,
|
color,
|
||||||
@ -55,7 +55,7 @@ public class FormDopClassParameters {
|
|||||||
rnd.nextBoolean()
|
rnd.nextBoolean()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_dopClassParameters.Add(entityLocomotive);
|
_dopClassParameters.Add(entityUsta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddRandomWheels() {
|
public void AddRandomWheels() {
|
||||||
|
@ -142,4 +142,14 @@ public class FormUstaBat {
|
|||||||
pictureBox.paint(g);
|
pictureBox.paint(g);
|
||||||
_drawingUsta.DrawTransport((Graphics2D) g);
|
_drawingUsta.DrawTransport((Graphics2D) g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ChangeUsta(DrawingUsta newUsta){
|
||||||
|
try {
|
||||||
|
_drawingUsta = newUsta;
|
||||||
|
_drawingUsta.SetPosition(20, 20);
|
||||||
|
Draw();
|
||||||
|
} catch (Exception e){
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormUstaCollections">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FormUstaCollections">
|
||||||
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="MainPanel" layout-manager="GridLayoutManager" row-count="2" column-count="2" 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>
|
||||||
<xy x="20" y="20" width="1175" height="504"/>
|
<xy x="232" y="129" width="913" height="469"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="none"/>
|
<border type="none"/>
|
||||||
@ -11,23 +11,23 @@
|
|||||||
<grid id="c25f7" binding="pictureBoxCollections" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="c25f7" binding="pictureBoxCollections" layout-manager="GridLayoutManager" row-count="1" column-count="1" 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="0" fill="3" indent="0" use-parent-layout="false">
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true">
|
||||||
<minimum-size width="700" height="500"/>
|
<minimum-size width="700" height="430"/>
|
||||||
<preferred-size width="700" height="500"/>
|
<preferred-size width="700" height="430"/>
|
||||||
<maximum-size width="700" height="500"/>
|
<maximum-size width="700" height="430"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties/>
|
<properties/>
|
||||||
<border type="line"/>
|
<border type="line"/>
|
||||||
<children/>
|
<children/>
|
||||||
</grid>
|
</grid>
|
||||||
<grid id="40d5" binding="Instruments" layout-manager="GridLayoutManager" row-count="7" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="40d5" binding="Instruments" layout-manager="GridLayoutManager" row-count="10" column-count="2" 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="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="true">
|
||||||
<minimum-size width="200" height="400"/>
|
<minimum-size width="160" height="400"/>
|
||||||
<preferred-size width="300" height="400"/>
|
<preferred-size width="160" height="400"/>
|
||||||
<maximum-size width="300" height="400"/>
|
<maximum-size width="160" height="400"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
@ -39,20 +39,64 @@
|
|||||||
<children>
|
<children>
|
||||||
<vspacer id="1eee0">
|
<vspacer id="1eee0">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="1" row-span="6" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
|
<grid row="3" column="1" row-span="7" 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="5039" class="javax.swing.JTextField" binding="textBoxStorageName">
|
||||||
|
<constraints>
|
||||||
|
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="-1"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
</component>
|
||||||
|
<component id="50eff" class="javax.swing.JButton" binding="ButtonAddObject">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<horizontalAlignment value="0"/>
|
||||||
|
<horizontalTextPosition value="0"/>
|
||||||
|
<text value="Добавить набор"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="5ef9c" class="javax.swing.JList" binding="listBoxStorage">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="2" anchor="0" fill="3" indent="0" use-parent-layout="false">
|
||||||
|
<preferred-size width="150" height="50"/>
|
||||||
|
</grid>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<model/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
<component id="1b1c" class="javax.swing.JButton" binding="ButtonCreateRandomUsta">
|
||||||
|
<constraints>
|
||||||
|
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Создать рандомную арт. уст. "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
<component id="138d" class="javax.swing.JButton" binding="ButtonAddUsta">
|
<component id="138d" class="javax.swing.JButton" binding="ButtonAddUsta">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Добавить арт. уст."/>
|
<text value="Добавить арт. уст."/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
|
<component id="b21cb" class="javax.swing.JButton" binding="ButtonRefreshCollection">
|
||||||
|
<constraints>
|
||||||
|
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Обновить "/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
<component id="1d01d" class="javax.swing.JButton" binding="ButtonRemoveUsta">
|
<component id="1d01d" class="javax.swing.JButton" binding="ButtonRemoveUsta">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Удалить арт. уст"/>
|
<text value="Удалить арт. уст"/>
|
||||||
@ -60,7 +104,7 @@
|
|||||||
</component>
|
</component>
|
||||||
<component id="25553" class="javax.swing.JTextField" binding="textFieldNumber">
|
<component id="25553" class="javax.swing.JTextField" binding="textFieldNumber">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||||
<preferred-size width="150" height="-1"/>
|
<preferred-size width="150" height="-1"/>
|
||||||
</grid>
|
</grid>
|
||||||
</constraints>
|
</constraints>
|
||||||
@ -68,24 +112,24 @@
|
|||||||
<text value="-"/>
|
<text value="-"/>
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
<component id="b21cb" class="javax.swing.JButton" binding="ButtonRefreshCollection">
|
<component id="d1477" class="javax.swing.JButton" binding="ButtonRemoveObject">
|
||||||
<constraints>
|
<constraints>
|
||||||
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
</constraints>
|
</constraints>
|
||||||
<properties>
|
<properties>
|
||||||
<text value="Обновить "/>
|
<text value="Удалить набор"/>
|
||||||
</properties>
|
|
||||||
</component>
|
|
||||||
<component id="1b1c" class="javax.swing.JButton" binding="ButtonCreateRandomUsta">
|
|
||||||
<constraints>
|
|
||||||
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
|
||||||
</constraints>
|
|
||||||
<properties>
|
|
||||||
<text value="Создать рандомную арт. уст."/>
|
|
||||||
</properties>
|
</properties>
|
||||||
</component>
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
|
<component id="ab73" class="javax.swing.JButton" binding="Button_OpenFormRemovedUsta">
|
||||||
|
<constraints>
|
||||||
|
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties>
|
||||||
|
<text value="Открыть удаленную арт. уст."/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
</children>
|
</children>
|
||||||
</grid>
|
</grid>
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.util.Stack;
|
||||||
|
|
||||||
//готовая лаба 3
|
//готовая лаба 3
|
||||||
|
|
||||||
public class FormUstaCollections {
|
public class FormUstaCollections {
|
||||||
FrameDopClassParameters frameDopClassParameters;
|
FormUstaBat formustabat;
|
||||||
private JPanel MainPanel;
|
private JPanel MainPanel;
|
||||||
private JPanel pictureBoxCollections;
|
private JPanel pictureBoxCollections;
|
||||||
private JPanel Instruments;
|
private JPanel Instruments;
|
||||||
@ -13,26 +15,66 @@ public class FormUstaCollections {
|
|||||||
private JButton ButtonRefreshCollection;
|
private JButton ButtonRefreshCollection;
|
||||||
private JButton ButtonRemoveUsta;
|
private JButton ButtonRemoveUsta;
|
||||||
private JButton ButtonCreateRandomUsta;
|
private JButton ButtonCreateRandomUsta;
|
||||||
|
private JTextField textBoxStorageName;
|
||||||
|
private JButton ButtonAddObject;
|
||||||
|
private JList listBoxStorage;
|
||||||
|
private JButton ButtonRemoveObject;
|
||||||
|
private JButton Button_OpenFormRemovedUsta;
|
||||||
public DrawingUsta usta;
|
public DrawingUsta usta;
|
||||||
UstaGenericCollection<DrawingUsta, DrawingObjectUsta> _usta;
|
final UstaGenericStorage _storage;
|
||||||
|
FrameUstaBat _frameRemovedUsta;
|
||||||
|
private Stack<DrawingUsta> _stackRemoveObjects;
|
||||||
|
FrameDopClassParameters frameDopClassParameters;
|
||||||
public JPanel getPictureBoxCollections() {
|
public JPanel getPictureBoxCollections() {
|
||||||
return MainPanel;
|
return MainPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FormUstaCollections() {
|
public FormUstaCollections() {
|
||||||
_usta = new UstaGenericCollection<>(700, 430);
|
formustabat = new FormUstaBat();
|
||||||
|
_storage = new UstaGenericStorage(700,430);
|
||||||
|
_stackRemoveObjects = new Stack<>();
|
||||||
|
listBoxStorage.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
||||||
|
|
||||||
|
ButtonAddObject.addActionListener(e ->
|
||||||
|
{
|
||||||
|
String NameStorage = textBoxStorageName.getText();
|
||||||
|
if (NameStorage.equals("")) {
|
||||||
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||||
|
"Где данные? Напиши хоть что-нибудь",
|
||||||
|
"Ошибка",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(NameStorage);
|
||||||
|
ReloadObjects();
|
||||||
|
Refresh();
|
||||||
|
});
|
||||||
|
|
||||||
|
ButtonRemoveObject.addActionListener(e ->
|
||||||
|
{
|
||||||
|
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(), "Коллекция удалена", "Удаление", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
_storage.DelSet((String) listBoxStorage.getSelectedValue()); //ТУТ СТРИНГ ОБРАТИ ВНИМАНИЕ КАК-НИБУДЬ
|
||||||
|
ReloadObjects();
|
||||||
|
});
|
||||||
|
|
||||||
ButtonAddUsta.addActionListener(e -> {
|
ButtonAddUsta.addActionListener(e -> {
|
||||||
FrameUstaBat frameElectricUsta = new FrameUstaBat();
|
if (listBoxStorage.getSelectedIndex() == -1)
|
||||||
frameElectricUsta.setVisible(true);
|
return;
|
||||||
frameElectricUsta._formUstaCollection.ButtonSelectUsta.addActionListener(e2 -> {
|
var obj = _storage.get(listBoxStorage.getSelectedValue().toString()); // ТУТ ЕЩЕ РАЗ - ОБРАТИ ВНИМАНИЕ НА СТРИНГ
|
||||||
usta = frameElectricUsta._formUstaCollection._drawingUsta;
|
if (obj == null) {
|
||||||
frameElectricUsta.dispose();
|
return;
|
||||||
|
}
|
||||||
|
FrameUstaBat frameUstaBat = new FrameUstaBat();
|
||||||
|
frameUstaBat.setVisible(true);
|
||||||
|
frameUstaBat._formUstaCollection.ButtonSelectUsta.addActionListener(e2 -> {
|
||||||
|
usta = frameUstaBat._formUstaCollection._drawingUsta;
|
||||||
|
frameUstaBat.dispose();
|
||||||
if (usta != null) {
|
if (usta != null) {
|
||||||
//проверяем, удалось ли нам загрузить объект
|
//проверяем, удалось ли нам загрузить объект
|
||||||
if (_usta.AddOverload(usta) != -1) {
|
if (obj.AddOverload(usta)!= -1) {
|
||||||
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен");
|
JOptionPane.showMessageDialog(getPictureBoxCollections(), "Объект добавлен");
|
||||||
Refresh();
|
Refresh();
|
||||||
} else {
|
} else {
|
||||||
@ -49,10 +91,41 @@ public class FormUstaCollections {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ButtonRemoveUsta.addActionListener(e -> {
|
ButtonRemoveUsta.addActionListener(e -> {
|
||||||
|
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage.get(listBoxStorage.getSelectedValue().toString());
|
||||||
|
if (obj == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int pos;
|
||||||
try {
|
try {
|
||||||
int pos = Integer.parseInt(textFieldNumber.getText());
|
pos = Integer.parseInt(textFieldNumber.getText());
|
||||||
if (_usta.SubOverload(pos) != null) {
|
} catch (NumberFormatException ex) {
|
||||||
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||||
|
"Неверное значение",
|
||||||
|
"Ошибка",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Object[] options = {"Да", "Нет"};
|
||||||
|
int n = JOptionPane.showOptionDialog(this.getPictureBoxCollections(),
|
||||||
|
"Удалить объект?",
|
||||||
|
"Все серьезно",
|
||||||
|
JOptionPane.YES_NO_OPTION,
|
||||||
|
JOptionPane.QUESTION_MESSAGE,
|
||||||
|
null,
|
||||||
|
options,
|
||||||
|
options[0]
|
||||||
|
);
|
||||||
|
if (n == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DrawingUsta removedUsta = obj.SubOverload(pos);
|
||||||
|
if (removedUsta != null) {
|
||||||
|
_stackRemoveObjects.push(removedUsta);
|
||||||
Refresh();
|
Refresh();
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||||
"Объект удален",
|
"Объект удален",
|
||||||
"Успех",
|
"Успех",
|
||||||
@ -63,22 +136,51 @@ public class FormUstaCollections {
|
|||||||
"Ошибка",
|
"Ошибка",
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
|
||||||
"Неверное значение",
|
|
||||||
"Ошибка",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonRefreshCollection.addActionListener(e -> {
|
ButtonRefreshCollection.addActionListener(e -> {
|
||||||
Refresh();
|
Refresh();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Button_OpenFormRemovedUsta.addActionListener(e -> {
|
||||||
|
if(_stackRemoveObjects.empty()) {
|
||||||
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||||
|
"Вы ничего не удалили, кажется...",
|
||||||
|
"ой",
|
||||||
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
FrameUstaBat RemUsta = new FrameUstaBat();
|
||||||
|
RemUsta._formUstaCollection.ChangeUsta(_stackRemoveObjects.pop());
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ReloadObjects() {
|
||||||
|
int index = listBoxStorage.getSelectedIndex();
|
||||||
|
listBoxStorage.setListData(_storage.Keys().toArray());
|
||||||
|
if (listBoxStorage.getModel().getSize() > 0 && (index == -1 || index >= listBoxStorage.getModel().getSize())) {
|
||||||
|
listBoxStorage.setSelectedIndex(0);
|
||||||
|
} else if (listBoxStorage.getModel().getSize() > 0 && index > -1 && index < listBoxStorage.getModel().getSize()) {
|
||||||
|
listBoxStorage.setSelectedIndex(index);
|
||||||
|
}
|
||||||
|
listBoxStorage.invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void listBoxObjectsSelectedIndexChanged(ListSelectionEvent e) {
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
public void Refresh() {
|
public void Refresh() {
|
||||||
|
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage.get(listBoxStorage.getSelectedValue().toString());
|
||||||
|
if (obj == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Graphics g = pictureBoxCollections.getGraphics();
|
Graphics g = pictureBoxCollections.getGraphics();
|
||||||
pictureBoxCollections.paint(g);
|
pictureBoxCollections.paint(g);
|
||||||
_usta.ShowLocomotives((Graphics2D) g);
|
obj.ShowLocomotives((Graphics2D) g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ public class FrameUstaBat extends JFrame {
|
|||||||
public FrameUstaBat() {
|
public FrameUstaBat() {
|
||||||
super();
|
super();
|
||||||
setTitle("UstaBat");
|
setTitle("UstaBat");
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
_formUstaCollection = new FormUstaBat();
|
_formUstaCollection = new FormUstaBat();
|
||||||
setContentPane(_formUstaCollection.getPictureBox());
|
setContentPane(_formUstaCollection.getPictureBox());
|
||||||
setDefaultLookAndFeelDecorated(false);
|
setDefaultLookAndFeelDecorated(false);
|
||||||
|
@ -1,61 +1,67 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class SetGeneric<T extends DrawingUsta>{
|
public class SetGeneric<T extends DrawingUsta>{
|
||||||
private T[] _places;
|
private ArrayList<T> _places;
|
||||||
public int Count(){
|
|
||||||
return _places.length;
|
public int Count()
|
||||||
}
|
{
|
||||||
public SetGeneric(int count) {
|
return _places.size();
|
||||||
_places = (T[]) new DrawingUsta[count];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T loco)
|
public int maxCount;
|
||||||
|
|
||||||
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
return Insert(loco, 0);
|
maxCount = count;
|
||||||
|
_places = new ArrayList<>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T loco, int position)
|
public int Insert(T usta)
|
||||||
{
|
{
|
||||||
int NoEmpty = 0, temp = 0;
|
return Insert(usta, 0);
|
||||||
for (int i = position; i < Count(); i++)
|
|
||||||
{
|
|
||||||
if (_places[i] != null) NoEmpty++;
|
|
||||||
}
|
}
|
||||||
if (NoEmpty == Count() - position - 1) return -1;
|
|
||||||
|
|
||||||
if (position < Count() && position >= 0)
|
public int Insert(T usta, int position)
|
||||||
{
|
{
|
||||||
for (int j = position; j < Count(); j++)
|
if(position < 0 || position > maxCount)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (_places[j] == null)
|
_places.add(position, usta);
|
||||||
{
|
|
||||||
temp = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// shift right
|
|
||||||
for (int i = temp; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
_places[position] = loco;
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count() || position < 0)
|
if (position >= Count() || position < 0)
|
||||||
return null;
|
return null;
|
||||||
|
else
|
||||||
T tmp = _places[position];
|
{
|
||||||
_places[position] = null;
|
T plane = _places.get(position);
|
||||||
return tmp;
|
_places.set(position, null);
|
||||||
|
return plane;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Get(int position)
|
public T Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
|
||||||
if (position < 0 || position >= Count()) return null;
|
if (position < 0 || position >= Count()) return null;
|
||||||
return _places[position];
|
return _places.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Set(int position, T usta) {
|
||||||
|
// Проверка позиции
|
||||||
|
// Проверка свободных мест в списке
|
||||||
|
if (position < 0 || position >= maxCount || Count() == maxCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Вставка в список по позиции
|
||||||
|
_places.set(position, usta);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<T> GetEnumerator() {
|
||||||
|
return _places;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -2,10 +2,8 @@ import java.awt.*;
|
|||||||
|
|
||||||
public class UstaGenericCollection<T extends DrawingUsta,U extends IMoveableObject>
|
public class UstaGenericCollection<T extends DrawingUsta,U extends IMoveableObject>
|
||||||
{
|
{
|
||||||
//ширина/высота окна
|
|
||||||
private final int _pictureWidth;
|
private final int _pictureWidth;
|
||||||
private final int _pictureHeight;
|
private final int _pictureHeight;
|
||||||
//ширина/высота занимаемого места
|
|
||||||
private final int _placeSizeWidth = 210;
|
private final int _placeSizeWidth = 210;
|
||||||
private final int _placeSizeHeight = 90;
|
private final int _placeSizeHeight = 90;
|
||||||
|
|
||||||
@ -14,8 +12,6 @@ public class UstaGenericCollection<T extends DrawingUsta,U extends IMoveableObje
|
|||||||
|
|
||||||
public UstaGenericCollection(int picWidth, int picHeight)
|
public UstaGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
// немного странная логика, что-то я пока ее не особо понимаю, зачем нам ААААА дошло...
|
|
||||||
// высчитываем размер массива для setgeneric
|
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
int height = picHeight / _placeSizeHeight;
|
int height = picHeight / _placeSizeHeight;
|
||||||
_pictureWidth = picWidth;
|
_pictureWidth = picWidth;
|
||||||
@ -23,18 +19,21 @@ public class UstaGenericCollection<T extends DrawingUsta,U extends IMoveableObje
|
|||||||
_collection = new SetGeneric<T>(width*height);
|
_collection = new SetGeneric<T>(width*height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Перегрузка оператора сложения
|
public int AddOverload(T usta){
|
||||||
//да емае, почему в яве все по-другому?...
|
if(usta == null){
|
||||||
|
|
||||||
public int AddOverload(T loco){
|
|
||||||
if(loco == null){
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return _collection.Insert(loco);
|
return _collection.Insert(usta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T SubOverload(int pos){
|
public T SubOverload(int pos){
|
||||||
return _collection.Remove(pos);
|
|
||||||
|
T usta = _collection.Get(pos);
|
||||||
|
if (usta != null)
|
||||||
|
{
|
||||||
|
_collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return usta;
|
||||||
}
|
}
|
||||||
|
|
||||||
// получение объекта imoveableObj
|
// получение объекта imoveableObj
|
||||||
|
Loading…
x
Reference in New Issue
Block a user