SomethingStrange
This commit is contained in:
parent
eb7971ed29
commit
8ca127a778
@ -1,34 +1,98 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.ListSelectionEvent;
|
||||||
|
import javax.swing.event.ListSelectionListener;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.image.CropImageFilter;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.PriorityQueue;
|
||||||
|
import java.util.Queue;
|
||||||
|
|
||||||
class CollectionFrame extends JComponent {
|
class CollectionFrame extends JComponent {
|
||||||
private final CarsGenericCollection<DrawTanker, DrawingObjectTanker> _tanks;
|
private final CarsGenericStorage _tanksStorage;
|
||||||
|
private final GarageFrame frame;
|
||||||
|
private Queue<DrawTanker> removedTankers;
|
||||||
protected final int Width;
|
protected final int Width;
|
||||||
protected final int Height;
|
protected final int Height;
|
||||||
public CollectionFrame(int width, int height)
|
public CollectionFrame(int width, int height, GarageFrame fr)
|
||||||
{
|
{
|
||||||
Width = width;
|
Width = width;
|
||||||
Height = height;
|
Height = height;
|
||||||
_tanks = new CarsGenericCollection<>(Width, Height);
|
_tanksStorage = new CarsGenericStorage(Width, Height);
|
||||||
|
frame = fr;
|
||||||
|
removedTankers = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
g.drawImage(_tanks.ShowCars(), 0, 0, this);
|
if (frame.listStorage.getSelectedIndex() == -1)
|
||||||
|
return;
|
||||||
|
var obj = _tanksStorage.get(frame.listStorage.getSelectedValue());
|
||||||
|
if (obj == null)
|
||||||
|
return;
|
||||||
|
if (obj.ShowCars() == null)
|
||||||
|
return;
|
||||||
|
g.drawImage(obj.ShowCars(), 0, 0, this);
|
||||||
super.repaint();
|
super.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = frame.listStorage.getSelectedIndex();
|
||||||
|
frame.listModel.clear();
|
||||||
|
for (String key : _tanksStorage.Keys())
|
||||||
|
{
|
||||||
|
frame.listModel.addElement(key);
|
||||||
|
}
|
||||||
|
if (!frame.listModel.isEmpty() && (index == -1 || index >= frame.listModel.size()))
|
||||||
|
{
|
||||||
|
frame.listStorage.setSelectedIndex(0);
|
||||||
|
}
|
||||||
|
else if (!frame.listModel.isEmpty() && index > -1 && index < frame.listModel.size())
|
||||||
|
{
|
||||||
|
frame.listStorage.setSelectedIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
protected void ButtonAddObject_Click()
|
||||||
|
{
|
||||||
|
String name = frame.nameStorageField.getText();
|
||||||
|
if (name.length() == 0)
|
||||||
|
return;
|
||||||
|
_tanksStorage.AddSet(name);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void ButtonRemoveObject_Click()
|
||||||
|
{
|
||||||
|
if (frame.listStorage.getSelectedIndex() == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (JOptionPane.showConfirmDialog(null, "Delete object " + frame.listStorage.getSelectedValue() + "?", "Delete", JOptionPane.YES_NO_OPTION) == JOptionPane.NO_OPTION)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_tanksStorage.DelSet(frame.listStorage.getSelectedValue());
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
|
||||||
protected void ButtonAddTank_Click()
|
protected void ButtonAddTank_Click()
|
||||||
{
|
{
|
||||||
|
if (frame.listStorage.getSelectedIndex() == -1)
|
||||||
|
return;
|
||||||
|
var obj = _tanksStorage.get(frame.listStorage.getSelectedValue());
|
||||||
|
if (obj == null)
|
||||||
|
return;
|
||||||
ConfigFrame form = new ConfigFrame();
|
ConfigFrame form = new ConfigFrame();
|
||||||
form.setVisible(true);
|
form.setVisible(true);
|
||||||
form.buttonAdd.addActionListener(
|
form.buttonAdd.addActionListener(
|
||||||
new ActionListener() {
|
new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e){
|
public void actionPerformed(ActionEvent e){
|
||||||
if (_tanks.plus(form.Gasoline._tanker) != -1)
|
DrawTanker dT = form.Gasoline._tanker;
|
||||||
|
if (dT != null && obj.plus(dT) != -1)
|
||||||
{
|
{
|
||||||
form.dispose();
|
form.dispose();
|
||||||
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Объект добавлен", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
@ -48,11 +112,23 @@ class CollectionFrame extends JComponent {
|
|||||||
|
|
||||||
protected void ButtonRemoveTank_Click(String text)
|
protected void ButtonRemoveTank_Click(String text)
|
||||||
{
|
{
|
||||||
|
if (frame.listStorage.getSelectedIndex() == -1)
|
||||||
|
return;
|
||||||
|
var obj = _tanksStorage.get(frame.listStorage.getSelectedValue());
|
||||||
|
if (obj == null)
|
||||||
|
return;
|
||||||
if (JOptionPane.showConfirmDialog(null, "Delete Tanker?", "Delete", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
if (JOptionPane.showConfirmDialog(null, "Delete Tanker?", "Delete", JOptionPane.YES_NO_OPTION) == JOptionPane.OK_OPTION)
|
||||||
{
|
{
|
||||||
if (_tanks.minus(Integer.parseInt(text)) != null)
|
int index = -1;
|
||||||
|
DrawTanker deleted = null;
|
||||||
|
try {
|
||||||
|
deleted = obj.minus(Integer.parseInt(text));
|
||||||
|
} catch(NumberFormatException e) {
|
||||||
|
}
|
||||||
|
if (deleted != null)
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Объект удален", "Информация", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
removedTankers.add(deleted);
|
||||||
super.repaint();
|
super.repaint();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -65,6 +141,14 @@ class CollectionFrame extends JComponent {
|
|||||||
|
|
||||||
protected void ButtonUpdate_Click() {super.repaint();}
|
protected void ButtonUpdate_Click() {super.repaint();}
|
||||||
|
|
||||||
|
protected void ButtonCreateDeleted_Click()
|
||||||
|
{
|
||||||
|
if (removedTankers.isEmpty())
|
||||||
|
return;
|
||||||
|
var tank = removedTankers.poll();
|
||||||
|
BaseFrame f = new BaseFrame(tank);
|
||||||
|
f.setVisible(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class GarageFrame extends JFrame {
|
class GarageFrame extends JFrame {
|
||||||
@ -76,6 +160,18 @@ class GarageFrame extends JFrame {
|
|||||||
protected static final int Width = 1000;
|
protected static final int Width = 1000;
|
||||||
protected static final int Height = 600;
|
protected static final int Height = 600;
|
||||||
CollectionFrame Collection;
|
CollectionFrame Collection;
|
||||||
|
|
||||||
|
JButton addTankerButton;
|
||||||
|
JTextField indexTankerField;
|
||||||
|
JButton deleteTankerButton;
|
||||||
|
JButton updateCollectionButton;
|
||||||
|
JList<String> listStorage;
|
||||||
|
DefaultListModel<String> listModel;
|
||||||
|
JButton addCollectionButton;
|
||||||
|
JTextField nameStorageField;
|
||||||
|
JButton deleteCollectionbutton;
|
||||||
|
JButton createDeletedButton;
|
||||||
|
|
||||||
private void initUI()
|
private void initUI()
|
||||||
{
|
{
|
||||||
setSize(Width, Height);
|
setSize(Width, Height);
|
||||||
@ -86,7 +182,7 @@ class GarageFrame extends JFrame {
|
|||||||
setResizable(false);
|
setResizable(false);
|
||||||
|
|
||||||
|
|
||||||
JButton addTankerButton = new JButton("Add tanker");
|
addTankerButton = new JButton("Add tanker");
|
||||||
addTankerButton.setLayout(null);
|
addTankerButton.setLayout(null);
|
||||||
addTankerButton.setBounds(Width-200, Height-550, 200, 30);
|
addTankerButton.setBounds(Width-200, Height-550, 200, 30);
|
||||||
add(addTankerButton);
|
add(addTankerButton);
|
||||||
@ -97,12 +193,12 @@ class GarageFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JTextField indexTankerField = new JTextField();
|
indexTankerField = new JTextField();
|
||||||
indexTankerField.setBounds(Width- 200, Height-500, 200, 30);
|
indexTankerField.setBounds(Width- 200, Height-500, 200, 30);
|
||||||
indexTankerField.setLayout(null);
|
indexTankerField.setLayout(null);
|
||||||
add(indexTankerField);
|
add(indexTankerField);
|
||||||
|
|
||||||
JButton deleteTankerButton = new JButton("Delete tanker");
|
deleteTankerButton = new JButton("Delete tanker");
|
||||||
deleteTankerButton.setLayout(null);
|
deleteTankerButton.setLayout(null);
|
||||||
deleteTankerButton.setBounds(Width-200, Height-450, 200, 30);
|
deleteTankerButton.setBounds(Width-200, Height-450, 200, 30);
|
||||||
add(deleteTankerButton);
|
add(deleteTankerButton);
|
||||||
@ -113,7 +209,7 @@ class GarageFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton updateCollectionButton = new JButton("Update collection");
|
updateCollectionButton = new JButton("Update collection");
|
||||||
updateCollectionButton.setLayout(null);
|
updateCollectionButton.setLayout(null);
|
||||||
updateCollectionButton.setBounds(Width-200, Height-400, 200, 30);
|
updateCollectionButton.setBounds(Width-200, Height-400, 200, 30);
|
||||||
add(updateCollectionButton);
|
add(updateCollectionButton);
|
||||||
@ -124,9 +220,59 @@ class GarageFrame extends JFrame {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
listModel = new DefaultListModel<>();
|
||||||
|
listStorage = new JList<String>(listModel);
|
||||||
|
listStorage.setLayout(null);
|
||||||
|
listStorage.setBounds(Width - 190, Height - 250, 180, 130);
|
||||||
|
add(listStorage);
|
||||||
|
listStorage.addListSelectionListener(new ListSelectionListener() {
|
||||||
|
@Override
|
||||||
|
public void valueChanged(ListSelectionEvent e) {
|
||||||
|
Collection.repaint();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
Collection = new CollectionFrame(Width-200, Height);
|
addCollectionButton = new JButton("Add Collection");
|
||||||
|
addCollectionButton.setLayout(null);
|
||||||
|
addCollectionButton.setBounds(Width-190, Height - 350, 180, 30);
|
||||||
|
add(addCollectionButton);
|
||||||
|
addCollectionButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Collection.ButtonAddObject_Click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
nameStorageField = new JTextField();
|
||||||
|
nameStorageField.setBounds(Width- 190, Height- 300, 180, 30);
|
||||||
|
nameStorageField.setLayout(null);
|
||||||
|
add(nameStorageField);
|
||||||
|
|
||||||
|
|
||||||
|
deleteCollectionbutton = new JButton("Remove Collection");
|
||||||
|
deleteCollectionbutton.setBounds(Width-190, Height - 100, 180, 30);
|
||||||
|
deleteCollectionbutton.setLayout(null);
|
||||||
|
add(deleteCollectionbutton);
|
||||||
|
deleteCollectionbutton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Collection.ButtonRemoveObject_Click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
createDeletedButton = new JButton("Create deleted");
|
||||||
|
createDeletedButton.setLayout(null);
|
||||||
|
createDeletedButton.setBounds(Width - 200, 10, 200, 30);
|
||||||
|
add(createDeletedButton);
|
||||||
|
createDeletedButton.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
Collection.ButtonCreateDeleted_Click();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Collection = new CollectionFrame(Width-200, Height, this);
|
||||||
Collection.setLayout(null);
|
Collection.setLayout(null);
|
||||||
Collection.setBounds(0, 0, Width-200, Height);
|
Collection.setBounds(0, 0, Width-200, Height);
|
||||||
add(Collection);
|
add(Collection);
|
||||||
|
@ -39,11 +39,13 @@ public class DrawWheelCircle implements IWheelDraw {
|
|||||||
g2d.drawString("S",85 + _startPosX, 75 + _startPosY);
|
g2d.drawString("S",85 + _startPosX, 75 + _startPosY);
|
||||||
if (wheelCounter == null)
|
if (wheelCounter == null)
|
||||||
return;
|
return;
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
switch (wheelCounter)
|
switch (wheelCounter)
|
||||||
{
|
{
|
||||||
case THREE -> {g2d.fillOval(45 + _startPosX, 60 + _startPosY ,20, 20);}
|
case THREE -> {g2d.fillOval(45 + _startPosX, 60 + _startPosY ,20, 20);}
|
||||||
case FOUR -> {g2d.fillOval(30 + _startPosX, 60 + _startPosY ,20, 20); g2d.fillOval(60 + _startPosX, 60 + _startPosY ,20, 20);}
|
case FOUR -> {g2d.fillOval(30 + _startPosX, 60 + _startPosY ,20, 20); g2d.fillOval(60 + _startPosX, 60 + _startPosY ,20, 20);}
|
||||||
}
|
}
|
||||||
|
g2d.setColor(stringColor);
|
||||||
switch (wheelCounter)
|
switch (wheelCounter)
|
||||||
{
|
{
|
||||||
case THREE -> {g2d.drawString("S",50 + _startPosX, 75 + _startPosY);}
|
case THREE -> {g2d.drawString("S",50 + _startPosX, 75 + _startPosY);}
|
||||||
|
@ -39,6 +39,7 @@ public class DrawWheelSquare implements IWheelDraw{
|
|||||||
g2d.fillRect(85 + _startPosX, 65 + _startPosY, 10, 10);
|
g2d.fillRect(85 + _startPosX, 65 + _startPosY, 10, 10);
|
||||||
if (wheelCounter == null)
|
if (wheelCounter == null)
|
||||||
return;
|
return;
|
||||||
|
g2d.setColor(bodyColor);
|
||||||
switch (wheelCounter) {
|
switch (wheelCounter) {
|
||||||
case THREE -> {
|
case THREE -> {
|
||||||
g2d.fillOval(45 + _startPosX, 60 + _startPosY, 20, 20);
|
g2d.fillOval(45 + _startPosX, 60 + _startPosY, 20, 20);
|
||||||
@ -48,6 +49,7 @@ public class DrawWheelSquare implements IWheelDraw{
|
|||||||
g2d.fillOval(60 + _startPosX, 60 + _startPosY, 20, 20);
|
g2d.fillOval(60 + _startPosX, 60 + _startPosY, 20, 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
g2d.setColor(stringColor);
|
||||||
switch (wheelCounter)
|
switch (wheelCounter)
|
||||||
{
|
{
|
||||||
case THREE -> {g2d.fillRect(50 + _startPosX, 65 + _startPosY, 10, 10);}
|
case THREE -> {g2d.fillRect(50 + _startPosX, 65 + _startPosY, 10, 10);}
|
||||||
|
Loading…
Reference in New Issue
Block a user