Лаба 4 хард, почищен код
This commit is contained in:
parent
dbfe33b361
commit
9262f67b28
@ -9,7 +9,6 @@ public class FormLocomotive extends JComponent{
|
|||||||
return SelectedLocomotive;
|
return SelectedLocomotive;
|
||||||
}
|
}
|
||||||
public void SetLocomotive(DrawningObjectLocomotive locomotive){
|
public void SetLocomotive(DrawningObjectLocomotive locomotive){
|
||||||
// TODO добавлен геттер в drawningobjectlocomotive
|
|
||||||
_locomotive = locomotive.GetDrawningLocomotive();
|
_locomotive = locomotive.GetDrawningLocomotive();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,6 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class FormMapWithSetLocomotives extends JComponent {
|
public class FormMapWithSetLocomotives extends JComponent {
|
||||||
private BufferedImage bufferImg = null;
|
private BufferedImage bufferImg = null;
|
||||||
/// Объект от класса карты с набором объектов
|
|
||||||
//private MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric;
|
|
||||||
|
|
||||||
/// Словарь для выпадающего списка
|
/// Словарь для выпадающего списка
|
||||||
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {
|
private final HashMap<String, AbstractMap> _mapsDict = new HashMap<>() {
|
||||||
{
|
{
|
||||||
@ -29,12 +26,8 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
TextField textFieldNewMapName;
|
TextField textFieldNewMapName;
|
||||||
JComboBox mapSelectComboBox;
|
JComboBox mapSelectComboBox;
|
||||||
DefaultListModel<String> mapsListModel = new DefaultListModel<>();
|
DefaultListModel<String> mapsListModel = new DefaultListModel<>();
|
||||||
|
|
||||||
JScrollPane listScroller = new JScrollPane();
|
JScrollPane listScroller = new JScrollPane();
|
||||||
|
|
||||||
JList listBoxMaps;
|
JList listBoxMaps;
|
||||||
//TODO
|
|
||||||
|
|
||||||
|
|
||||||
public FormMapWithSetLocomotives() {
|
public FormMapWithSetLocomotives() {
|
||||||
formFrame = new JFrame("Form Map With SetLocomotives");
|
formFrame = new JFrame("Form Map With SetLocomotives");
|
||||||
@ -60,34 +53,9 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
};
|
};
|
||||||
mapSelectComboBox = new JComboBox(maps);
|
mapSelectComboBox = new JComboBox(maps);
|
||||||
mapSelectComboBox.setEditable(true);
|
mapSelectComboBox.setEditable(true);
|
||||||
/*mapSelectComboBox.addActionListener(e -> {
|
|
||||||
AbstractMap map = null;
|
|
||||||
String item = (String)mapSelectComboBox.getSelectedItem();
|
|
||||||
switch (item) {
|
|
||||||
case "Simple Map":
|
|
||||||
map = new SimpleMap();
|
|
||||||
break;
|
|
||||||
case "Spike Map":
|
|
||||||
map = new SpikeMap();
|
|
||||||
break;
|
|
||||||
case "Rail Map":
|
|
||||||
map = new RailMap();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (map != null)
|
|
||||||
{
|
|
||||||
_mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap>
|
|
||||||
(600, 500, map);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_mapLocomotivesCollectionGeneric = null;
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
statusPanel.add(mapSelectComboBox);
|
statusPanel.add(mapSelectComboBox);
|
||||||
|
|
||||||
// Initialization
|
// Initialization
|
||||||
// TODO
|
|
||||||
_mapsCollection = new MapsCollection(600, 500);
|
_mapsCollection = new MapsCollection(600, 500);
|
||||||
mapSelectComboBox.removeAllItems();
|
mapSelectComboBox.removeAllItems();
|
||||||
for (var elem : _mapsDict.keySet())
|
for (var elem : _mapsDict.keySet())
|
||||||
@ -101,11 +69,9 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
// логика добавления
|
// логика добавления
|
||||||
if (mapSelectComboBox.getSelectedIndex() == -1 || textFieldNewMapName.getText() == null)
|
if (mapSelectComboBox.getSelectedIndex() == -1 || textFieldNewMapName.getText() == null)
|
||||||
{
|
{
|
||||||
//MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
JOptionPane.showMessageDialog(null, "Not all data is complete!");
|
JOptionPane.showMessageDialog(null, "Not all data is complete!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//TODO фиг знает как этот комбобокс работает, может не найдет карту
|
|
||||||
if (!_mapsDict.containsKey(mapSelectComboBox.getSelectedItem().toString()))
|
if (!_mapsDict.containsKey(mapSelectComboBox.getSelectedItem().toString()))
|
||||||
{
|
{
|
||||||
JOptionPane.showMessageDialog(null, "No such map");
|
JOptionPane.showMessageDialog(null, "No such map");
|
||||||
@ -119,7 +85,6 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
// ListBox для созданных карт
|
// ListBox для созданных карт
|
||||||
listBoxMaps = new JList(mapsListModel);
|
listBoxMaps = new JList(mapsListModel);
|
||||||
listBoxMaps.addListSelectionListener(e -> {
|
listBoxMaps.addListSelectionListener(e -> {
|
||||||
//TODO фиг знает как этот лист работает, может не вернет ничего
|
|
||||||
if(listBoxMaps.getSelectedValue() == null) return;
|
if(listBoxMaps.getSelectedValue() == null) return;
|
||||||
bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
repaint();
|
repaint();
|
||||||
@ -138,7 +103,6 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//TODO фиг знает как этот лист работает, может не вернет ничего
|
|
||||||
if(listBoxMaps.getSelectedValue().toString() == null) return;
|
if(listBoxMaps.getSelectedValue().toString() == null) return;
|
||||||
_mapsCollection.DelMap(listBoxMaps.getSelectedValue().toString());
|
_mapsCollection.DelMap(listBoxMaps.getSelectedValue().toString());
|
||||||
ReloadMaps();
|
ReloadMaps();
|
||||||
@ -161,7 +125,6 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(formLocomotive.getSelectedLocomotive());
|
DrawningObjectLocomotive locomotive = new DrawningObjectLocomotive(formLocomotive.getSelectedLocomotive());
|
||||||
//TODO
|
|
||||||
if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(locomotive)!= -1) {
|
if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Plus(locomotive)!= -1) {
|
||||||
JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION);
|
JOptionPane.showMessageDialog(formFrame, "Object added", "Success", JOptionPane.OK_CANCEL_OPTION);
|
||||||
bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
@ -195,7 +158,6 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int position = Integer.parseInt(finalMaskedTextFieldPosition.getText());
|
int position = Integer.parseInt(finalMaskedTextFieldPosition.getText());
|
||||||
//TODO
|
|
||||||
if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Minus(position) != null) {
|
if (_mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).Minus(position) != null) {
|
||||||
JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION);
|
JOptionPane.showMessageDialog(formFrame, "Object removed", "Success", JOptionPane.OK_CANCEL_OPTION);
|
||||||
bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
bufferImg = _mapsCollection.Get(listBoxMaps.getSelectedValue().toString()).ShowSet();
|
||||||
@ -210,7 +172,6 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
JButton showStorageButton = new JButton("Show Storage");
|
JButton showStorageButton = new JButton("Show Storage");
|
||||||
showStorageButton.addActionListener(e -> {
|
showStorageButton.addActionListener(e -> {
|
||||||
// логика просмотра
|
// логика просмотра
|
||||||
//TODO
|
|
||||||
if (listBoxMaps.getSelectedIndex() == -1)
|
if (listBoxMaps.getSelectedIndex() == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -223,7 +184,6 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
JButton showOnMapButton = new JButton("Show On Map");
|
JButton showOnMapButton = new JButton("Show On Map");
|
||||||
showOnMapButton.addActionListener(e -> {
|
showOnMapButton.addActionListener(e -> {
|
||||||
// логика просмотра
|
// логика просмотра
|
||||||
//TODO
|
|
||||||
if (listBoxMaps.getSelectedIndex() == -1)
|
if (listBoxMaps.getSelectedIndex() == -1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -234,7 +194,6 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
statusPanel.add(showOnMapButton);
|
statusPanel.add(showOnMapButton);
|
||||||
|
|
||||||
ActionListener moveButtonListener = new ActionListener() {
|
ActionListener moveButtonListener = new ActionListener() {
|
||||||
//TODO
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (listBoxMaps.getSelectedIndex() == -1)
|
if (listBoxMaps.getSelectedIndex() == -1)
|
||||||
@ -299,15 +258,12 @@ public class FormMapWithSetLocomotives extends JComponent {
|
|||||||
if (locomotive != null) {
|
if (locomotive != null) {
|
||||||
JDialog dialog = new JDialog(formFrame, "Deleted", true);
|
JDialog dialog = new JDialog(formFrame, "Deleted", true);
|
||||||
FormLocomotive formLocomotive = new FormLocomotive(dialog);
|
FormLocomotive formLocomotive = new FormLocomotive(dialog);
|
||||||
// TODO чтобы передать локомотив в форму добавляем метод в formlocomotive
|
|
||||||
formLocomotive.SetLocomotive(locomotive);
|
formLocomotive.SetLocomotive(locomotive);
|
||||||
dialog.setSize(800, 500);
|
dialog.setSize(800, 500);
|
||||||
dialog.setContentPane(formLocomotive);
|
dialog.setContentPane(formLocomotive);
|
||||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
statusPanel.add(showDeletedButton);
|
statusPanel.add(showDeletedButton);
|
||||||
|
|
||||||
|
@ -13,9 +13,6 @@ public class MapWithSetLocomotivesGeneric
|
|||||||
private final int _placeSizeWidth = 210;
|
private final int _placeSizeWidth = 210;
|
||||||
/// Размер занимаемого объектом места (высота)
|
/// Размер занимаемого объектом места (высота)
|
||||||
private final int _placeSizeHeight = 90;
|
private final int _placeSizeHeight = 90;
|
||||||
|
|
||||||
/// Набор объектов
|
|
||||||
//TODO переделал на public, узнать так ли вообще надо?
|
|
||||||
public final SetLocomotivesGeneric<T> _setLocomotives;
|
public final SetLocomotivesGeneric<T> _setLocomotives;
|
||||||
|
|
||||||
// Список удаленных объектов
|
// Список удаленных объектов
|
||||||
|
@ -40,7 +40,6 @@ public class MapsCollection {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// Доп.индексатор из задания
|
// Доп.индексатор из задания
|
||||||
// TODO поле setlocomotives в mapwithsetlocomotivesgeneric было изменено на public
|
|
||||||
public DrawningObjectLocomotive Get (String name, int position) {
|
public DrawningObjectLocomotive Get (String name, int position) {
|
||||||
if (_mapStorages.containsKey(name)) return _mapStorages.get(name)._setLocomotives.Get(position);
|
if (_mapStorages.containsKey(name)) return _mapStorages.get(name)._setLocomotives.Get(position);
|
||||||
else return null;
|
else return null;
|
||||||
|
@ -42,22 +42,8 @@ public class SetLocomotivesGeneric <T>
|
|||||||
}
|
}
|
||||||
return _places.get(position);
|
return _places.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Проход по набору до первого пустого
|
|
||||||
public Iterable<T> GetLocomotives()
|
public Iterable<T> GetLocomotives()
|
||||||
{
|
{
|
||||||
/*for (var locomotive : _places)
|
|
||||||
{
|
|
||||||
if (locomotive != null)
|
|
||||||
{
|
|
||||||
yield return locomotive;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
yield break;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
return _places;
|
return _places;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user