4 lab not formatted
This commit is contained in:
parent
bbc0734544
commit
d168f11ea6
10
.idea/uiDesigner.xml
generated
10
.idea/uiDesigner.xml
generated
@ -86,11 +86,6 @@
|
|||||||
<preferred-size width="150" height="50" />
|
<preferred-size width="150" height="50" />
|
||||||
</default-constraints>
|
</default-constraints>
|
||||||
</item>
|
</item>
|
||||||
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
|
||||||
<preferred-size width="200" height="200" />
|
|
||||||
</default-constraints>
|
|
||||||
</item>
|
|
||||||
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
|
||||||
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
<preferred-size width="200" height="200" />
|
<preferred-size width="200" height="200" />
|
||||||
@ -99,6 +94,11 @@
|
|||||||
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
</item>
|
</item>
|
||||||
|
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
|
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
|
||||||
|
<preferred-size width="200" height="200" />
|
||||||
|
</default-constraints>
|
||||||
|
</item>
|
||||||
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
|
||||||
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
|
||||||
</item>
|
</item>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?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="ProjectElectricLocomotive.FormElectricLocomotive">
|
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="ProjectElectricLocomotive.FormElectricLocomotive">
|
||||||
<grid id="27dc6" binding="pictureBox" layout-manager="GridLayoutManager" row-count="6" column-count="6" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
<grid id="27dc6" binding="pictureBox" custom-create="true" layout-manager="GridLayoutManager" row-count="6" 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>
|
||||||
<xy x="24" y="37" width="663" height="500"/>
|
<xy x="24" y="37" width="663" height="500"/>
|
||||||
|
@ -5,11 +5,11 @@ import java.awt.event.ActionEvent;
|
|||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class FormElectricLocomotive {
|
public class FormElectricLocomotive extends JDialog{
|
||||||
public DrawingLocomotive _drawingLocomotive;
|
public DrawingLocomotive _drawingLocomotive;
|
||||||
AbstractStrategy _abstractStrategy;
|
AbstractStrategy _abstractStrategy;
|
||||||
private JButton buttonCreateElectricLocomotive;
|
private JButton buttonCreateElectricLocomotive;
|
||||||
private JPanel pictureBox;
|
public JComponent pictureBox;
|
||||||
private JButton buttonUp;
|
private JButton buttonUp;
|
||||||
private JButton buttonDown;
|
private JButton buttonDown;
|
||||||
private JButton buttonLeft;
|
private JButton buttonLeft;
|
||||||
@ -21,10 +21,27 @@ public class FormElectricLocomotive {
|
|||||||
public DrawingLocomotive SelectedLocomotive;
|
public DrawingLocomotive SelectedLocomotive;
|
||||||
public boolean IsSelect = false;
|
public boolean IsSelect = false;
|
||||||
|
|
||||||
public JPanel getPictureBox()
|
public JComponent getPictureBox()
|
||||||
{
|
{
|
||||||
return pictureBox;
|
return pictureBox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Canvas extends JPanel{
|
||||||
|
public Canvas(){
|
||||||
|
}
|
||||||
|
public void paintComponent (Graphics g){
|
||||||
|
if (_drawingLocomotive == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics2D g2d = (Graphics2D)g;
|
||||||
|
g2d.setColor(getBackground());
|
||||||
|
g2d.fillRect(0, 0, getWidth(), getHeight());
|
||||||
|
super.paintComponents(g);
|
||||||
|
_drawingLocomotive.DrawTransport(g2d);
|
||||||
|
super.repaint();
|
||||||
|
}
|
||||||
|
}
|
||||||
public FormElectricLocomotive()
|
public FormElectricLocomotive()
|
||||||
{
|
{
|
||||||
buttonUp.setName("buttonUp");
|
buttonUp.setName("buttonUp");
|
||||||
@ -34,11 +51,18 @@ public class FormElectricLocomotive {
|
|||||||
|
|
||||||
buttonCreateLocomotive.addActionListener(e -> {
|
buttonCreateLocomotive.addActionListener(e -> {
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
Color color = JColorChooser.showDialog(null, "Цвет", null);
|
Color color = JColorChooser.showDialog(
|
||||||
_drawingLocomotive = new DrawingLocomotive(rnd.nextInt(100, 300),
|
null,
|
||||||
rnd.nextInt(1000, 3000), color,
|
"Цвет",
|
||||||
|
null
|
||||||
|
);
|
||||||
|
_drawingLocomotive = new DrawingLocomotive(
|
||||||
|
rnd.nextInt(100, 300),
|
||||||
|
rnd.nextInt(1000, 3000),
|
||||||
|
color,
|
||||||
pictureBox.getWidth(),
|
pictureBox.getWidth(),
|
||||||
pictureBox.getHeight());
|
pictureBox.getHeight()
|
||||||
|
);
|
||||||
|
|
||||||
_drawingLocomotive.SetWheelsCount(rnd.nextInt(2, 5));
|
_drawingLocomotive.SetWheelsCount(rnd.nextInt(2, 5));
|
||||||
_drawingLocomotive.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100));
|
_drawingLocomotive.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100));
|
||||||
@ -93,9 +117,10 @@ public class FormElectricLocomotive {
|
|||||||
if (_abstractStrategy == null) {
|
if (_abstractStrategy == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_abstractStrategy.SetData(new
|
_abstractStrategy.SetData(
|
||||||
DrawingObjectLocomotive(_drawingLocomotive), pictureBox.getWidth(),
|
new DrawingObjectLocomotive(_drawingLocomotive), pictureBox.getWidth(),
|
||||||
pictureBox.getHeight());
|
pictureBox.getHeight()
|
||||||
|
);
|
||||||
comboBoxStrategy.setEnabled(false);
|
comboBoxStrategy.setEnabled(false);
|
||||||
}
|
}
|
||||||
if (_abstractStrategy == null) {
|
if (_abstractStrategy == null) {
|
||||||
@ -136,11 +161,11 @@ public class FormElectricLocomotive {
|
|||||||
buttonRight.addActionListener(buttonMoveClickedListener);
|
buttonRight.addActionListener(buttonMoveClickedListener);
|
||||||
}
|
}
|
||||||
public void Draw() {
|
public void Draw() {
|
||||||
if (_drawingLocomotive.EntityLocomotive == null) {
|
pictureBox.repaint();
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
Graphics g = pictureBox.getGraphics();
|
private void createUIComponents(){
|
||||||
pictureBox.paint(g);
|
pictureBox = new Canvas();
|
||||||
_drawingLocomotive.DrawTransport(g);
|
pictureBox.setBounds(new Rectangle(400, 300));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import java.util.Stack;
|
|||||||
//готовая лаба 3
|
//готовая лаба 3
|
||||||
|
|
||||||
public class FormLocomotiveCollections {
|
public class FormLocomotiveCollections {
|
||||||
|
FormElectricLocomotive formElectricLocomotive;
|
||||||
private JPanel MainPanel;
|
private JPanel MainPanel;
|
||||||
private JPanel pictureBoxCollections;
|
private JPanel pictureBoxCollections;
|
||||||
private JPanel Instruments;
|
private JPanel Instruments;
|
||||||
@ -24,19 +25,16 @@ public class FormLocomotiveCollections {
|
|||||||
public DrawingLocomotive loco;
|
public DrawingLocomotive loco;
|
||||||
final LocomotivesGenericStorage _storage;
|
final LocomotivesGenericStorage _storage;
|
||||||
FrameElectricLocomotive _frameRemovedLocomotives;
|
FrameElectricLocomotive _frameRemovedLocomotives;
|
||||||
|
private Stack<DrawingLocomotive> _stackRemoveObjects;
|
||||||
private Stack<DrawingLocomotive> stackRemoveObjects;
|
|
||||||
FrameDopClassParameters frameDopClassParameters;
|
FrameDopClassParameters frameDopClassParameters;
|
||||||
// LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
|
||||||
public JPanel getPictureBoxCollections() {
|
public JPanel getPictureBoxCollections() {
|
||||||
return MainPanel;
|
return MainPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public FormLocomotiveCollections() {
|
public FormLocomotiveCollections() {
|
||||||
//_locomotives = new LocomotiveGenericCollection<>(400, 300);
|
formElectricLocomotive = new FormElectricLocomotive();
|
||||||
_storage = new LocomotivesGenericStorage(/*pictureBoxCollections.getWidth(), pictureBoxCollections.getHeight()*/400,300);
|
_storage = new LocomotivesGenericStorage(400,300);
|
||||||
stackRemoveObjects = new Stack<>();
|
_stackRemoveObjects = new Stack<>();
|
||||||
listBoxStorage.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
listBoxStorage.addListSelectionListener(this::listBoxObjectsSelectedIndexChanged);
|
||||||
|
|
||||||
ButtonAddObject.addActionListener(e ->
|
ButtonAddObject.addActionListener(e ->
|
||||||
@ -95,40 +93,6 @@ public class FormLocomotiveCollections {
|
|||||||
});
|
});
|
||||||
|
|
||||||
ButtonRemoveLocomotive.addActionListener(e -> {
|
ButtonRemoveLocomotive.addActionListener(e -> {
|
||||||
/*if (listBoxStorage.getSelectedIndex() == -1) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var obj = _storage.get(listBoxStorage.getSelectedValue().toString());
|
|
||||||
if (obj == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int pos = 0;
|
|
||||||
try {
|
|
||||||
pos = Integer.parseInt(textFieldNumber.getText());
|
|
||||||
}
|
|
||||||
catch (NumberFormatException ex)
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
|
||||||
"Неверное значение",
|
|
||||||
"Ошибка",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
DrawingLocomotive deletedLoco = obj.SubOverload(pos);
|
|
||||||
if (deletedLoco != null) {
|
|
||||||
// logic for push deleted loco in stack
|
|
||||||
stackRemoveObjects.push(deletedLoco);
|
|
||||||
Refresh();
|
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
|
||||||
"Объект удален",
|
|
||||||
"Успех",
|
|
||||||
JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
|
||||||
"Не удалось удалить объект",
|
|
||||||
"Ошибка",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (listBoxStorage.getSelectedIndex() == -1) {
|
if (listBoxStorage.getSelectedIndex() == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -161,19 +125,19 @@ public class FormLocomotiveCollections {
|
|||||||
}
|
}
|
||||||
DrawingLocomotive removedPlane = obj.SubOverload(pos);
|
DrawingLocomotive removedPlane = obj.SubOverload(pos);
|
||||||
if (removedPlane != null) {
|
if (removedPlane != null) {
|
||||||
stackRemoveObjects.push(removedPlane);
|
_stackRemoveObjects.push(removedPlane);
|
||||||
|
Refresh();
|
||||||
|
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||||
"Объект удален",
|
"Объект удален",
|
||||||
"Успех",
|
"Успех",
|
||||||
JOptionPane.INFORMATION_MESSAGE);Refresh();
|
JOptionPane.INFORMATION_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||||
"Не удалось удалить объект",
|
"Не удалось удалить объект",
|
||||||
"Ошибка",
|
"Ошибка",
|
||||||
JOptionPane.ERROR_MESSAGE);
|
JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ButtonRefreshCollection.addActionListener(e -> {
|
ButtonRefreshCollection.addActionListener(e -> {
|
||||||
@ -181,7 +145,7 @@ public class FormLocomotiveCollections {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Button_OpenFormRemovedLocomotives.addActionListener(e -> {
|
Button_OpenFormRemovedLocomotives.addActionListener(e -> {
|
||||||
if(stackRemoveObjects.empty()) {
|
if(_stackRemoveObjects.empty()) {
|
||||||
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
JOptionPane.showMessageDialog(this.getPictureBoxCollections(),
|
||||||
"Вы ничего не удалили, кажется...",
|
"Вы ничего не удалили, кажется...",
|
||||||
"ой",
|
"ой",
|
||||||
@ -189,10 +153,9 @@ public class FormLocomotiveCollections {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_frameRemovedLocomotives = new FrameElectricLocomotive();
|
_frameRemovedLocomotives = new FrameElectricLocomotive();
|
||||||
_frameRemovedLocomotives._formElectricLocomotive._drawingLocomotive = stackRemoveObjects.pop();
|
_frameRemovedLocomotives._formElectricLocomotive._drawingLocomotive = _stackRemoveObjects.pop();
|
||||||
_frameRemovedLocomotives.setVisible(true);
|
_frameRemovedLocomotives.setVisible(true);
|
||||||
_frameRemovedLocomotives._formElectricLocomotive.Draw();
|
_frameRemovedLocomotives._formElectricLocomotive.Draw();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
package ProjectElectricLocomotive;
|
package ProjectElectricLocomotive;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
|
|
||||||
public class SetGeneric<T extends DrawingLocomotive>{
|
public class SetGeneric<T extends DrawingLocomotive>{
|
||||||
private ArrayList<T> _places;
|
private ArrayList<T> _places;
|
||||||
@ -17,7 +15,7 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
|||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
maxCount = count;
|
maxCount = count;
|
||||||
_places = new ArrayList<T>(count);
|
_places = new ArrayList<>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T loco)
|
public int Insert(T loco)
|
||||||
@ -27,7 +25,7 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
|||||||
|
|
||||||
public int Insert(T loco, int position)
|
public int Insert(T loco, int position)
|
||||||
{
|
{
|
||||||
if(position < 0 || position > Count())
|
if(position < 0 || position > maxCount)
|
||||||
return -1;
|
return -1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -43,7 +41,6 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
T plane = _places.get(position);
|
T plane = _places.get(position);
|
||||||
_places.remove(position);
|
|
||||||
_places.set(position, null);
|
_places.set(position, null);
|
||||||
return plane;
|
return plane;
|
||||||
}
|
}
|
||||||
@ -69,35 +66,4 @@ public class SetGeneric<T extends DrawingLocomotive>{
|
|||||||
return _places;
|
return _places;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* public Iterable<T> GetLocomotives(final Integer maxLocomotives) {
|
|
||||||
return new Iterable<T>() {
|
|
||||||
@Override
|
|
||||||
public Iterator<T> iterator() {
|
|
||||||
return new Iterator<T>() {
|
|
||||||
private int currentIndex = 0;
|
|
||||||
private int count = 0;
|
|
||||||
|
|
||||||
//есть ли в коллекции еще место (значения)
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return currentIndex < _places.size() &&
|
|
||||||
(maxLocomotives == null || count < maxLocomotives);
|
|
||||||
}
|
|
||||||
|
|
||||||
//ну и, соответственно, переходим к следующему, если хэз некст == true
|
|
||||||
@Override
|
|
||||||
public T next() {
|
|
||||||
if (hasNext()) {
|
|
||||||
count++;
|
|
||||||
return _places.get(currentIndex++);
|
|
||||||
}
|
|
||||||
throw new NoSuchElementException();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};*/
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user