LabWork4 PIbd-21 Zacharchenko #4
@ -4,6 +4,8 @@ import javafx.beans.InvalidationListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.Event;
|
||||
import javafx.event.EventHandler;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Scene;
|
||||
@ -21,7 +23,7 @@ import static com.example.doubledeckerbus.ControllerMapWithSetBus._mapBusesColle
|
||||
|
||||
public class ControllerBus {
|
||||
|
||||
protected DrawingBus _bus;
|
||||
public static DrawingBus _bus;
|
||||
public DrawingBus SelectedBus;
|
||||
protected ObservableList<Integer> countOfDoors = FXCollections.observableArrayList(3, 4, 5);
|
||||
@FXML
|
||||
@ -60,21 +62,31 @@ public class ControllerBus {
|
||||
@FXML
|
||||
protected ChoiceBox<Integer> choiceDoors;
|
||||
|
||||
@FXML
|
||||
private ColorPicker bodyColorPicker;
|
||||
|
||||
@FXML
|
||||
private ColorPicker extraColorPicker;
|
||||
|
||||
|
||||
@FXML
|
||||
void ButtonCreate_Click(ActionEvent event) {
|
||||
pictureBoxBus.widthProperty().addListener(listener);
|
||||
pictureBoxBus.heightProperty().addListener(listener);
|
||||
|
||||
Random rnd = new Random();
|
||||
|
||||
_bus = new DrawingBus(rnd.nextInt(100, 300), rnd.nextFloat(1000, 2000),
|
||||
Color.rgb(rnd.nextInt(256), rnd.nextInt(0, 256), rnd.nextInt(0, 256)), choiceDoors.getValue());
|
||||
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), (int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
||||
bodyColorPicker.getValue(), choiceDoors.getValue());
|
||||
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||
(int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
||||
BorderChanged();
|
||||
}
|
||||
|
||||
void SetData() {
|
||||
Random rnd = new Random();
|
||||
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100), (int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
||||
_bus.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),
|
||||
(int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight());
|
||||
statusSpeed.setText("Скорость: %s".formatted(_bus.Bus.Speed));
|
||||
statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight));
|
||||
statusColor.setText("Цвет: %s".formatted(_bus.Bus.BodyColor));
|
||||
@ -82,6 +94,9 @@ public class ControllerBus {
|
||||
|
||||
@FXML
|
||||
void ButtonMove_Click(ActionEvent event) {
|
||||
pictureBoxBus.widthProperty().addListener(listener);
|
||||
pictureBoxBus.heightProperty().addListener(listener);
|
||||
|
||||
if (_bus == null) return;
|
||||
String name = ((Button) event.getSource()).getId();
|
||||
switch (name) {
|
||||
@ -97,6 +112,9 @@ public class ControllerBus {
|
||||
public void initialize() {
|
||||
choiceDoors.setItems(countOfDoors);
|
||||
choiceDoors.setValue(3);
|
||||
if (_bus != null) {
|
||||
Draw();
|
||||
}
|
||||
|
||||
}
|
||||
InvalidationListener listener = o -> BorderChanged();
|
||||
@ -122,10 +140,8 @@ public class ControllerBus {
|
||||
pictureBoxBus.heightProperty().addListener(listener);
|
||||
Random rnd = new Random();
|
||||
_bus = new DrawingDDB(rnd.nextInt(300), rnd.nextInt(2000),
|
||||
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
choiceDoors.getValue(),
|
||||
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
|
||||
rnd.nextBoolean(), rnd.nextBoolean());
|
||||
bodyColorPicker.getValue(), choiceDoors.getValue(),
|
||||
extraColorPicker.getValue(), rnd.nextBoolean(), rnd.nextBoolean());
|
||||
SetData();
|
||||
BorderChanged();
|
||||
}
|
||||
@ -143,7 +159,7 @@ public class ControllerBus {
|
||||
|
||||
DrawingObjectBus bus = new DrawingObjectBus(SelectedBus);
|
||||
|
||||
if (_mapBusesCollectionGeneric.add(bus) != -1) {
|
||||
if (ControllerMapWithSetBus.AddNewBus(bus) != -1) {
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle("SelectBus");
|
||||
alert.setContentText("Вы создали объект");
|
||||
@ -156,11 +172,11 @@ public class ControllerBus {
|
||||
}
|
||||
}
|
||||
|
||||
_bus = null;
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
Form.myStage.setTitle("DoubleDeckerBus");
|
||||
Form.myStage.setScene(scene);
|
||||
Form.myStage.show();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
package com.example.doubledeckerbus;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.event.ActionEvent;
|
||||
@ -12,13 +14,27 @@ import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
public class ControllerMapWithSetBus {
|
||||
static MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap> _mapBusesCollectionGeneric;
|
||||
private HashMap<String, AbstractMap> _mapsDict = new HashMap<>();
|
||||
{
|
||||
_mapsDict.put("Простая карта", new SimpleMap());
|
||||
_mapsDict.put("Водная карта", new WaterMap());
|
||||
}
|
||||
AbstractMap map = new SimpleMap();
|
||||
|
||||
public static int AddNewBus (DrawingObjectBus bus) {
|
||||
return _mapsCollection.GetId(selected).add(bus);
|
||||
}
|
||||
static public MapsCollection _mapsCollection;
|
||||
|
||||
static String selected;
|
||||
|
||||
static String map_name = "Простая карта";
|
||||
protected ObservableList<String> countOfMap = FXCollections.observableArrayList("Простая карта", "Водная карта");
|
||||
|
||||
@ -58,28 +74,66 @@ public class ControllerMapWithSetBus {
|
||||
@FXML
|
||||
private TextField textBoxPosition;
|
||||
|
||||
@FXML
|
||||
private ListView<String> listViewMaps;
|
||||
|
||||
@FXML
|
||||
private TextField TextFieldMap;
|
||||
|
||||
@FXML
|
||||
private void initialize(){
|
||||
gc = canvasBus.getGraphicsContext2D();
|
||||
if (selected != null) {
|
||||
showStorage();
|
||||
}
|
||||
if (_mapsCollection == null)
|
||||
_mapsCollection = new MapsCollection((int) canvasBus.getWidth(), (int) canvasBus.getHeight());
|
||||
comboBoxSelectorMap.setItems(countOfMap);
|
||||
comboBoxSelectorMap.setValue(map_name);
|
||||
listViewMaps.getSelectionModel().selectedItemProperty()
|
||||
.addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observableValue, String s, String t1) {
|
||||
selected = t1;
|
||||
showStorage();
|
||||
}
|
||||
});
|
||||
listViewMaps.setItems(_mapsCollection.toObserveList());
|
||||
}
|
||||
|
||||
GraphicsContext gc;
|
||||
private void FirstIncome() {
|
||||
if (_mapBusesCollectionGeneric == null) {
|
||||
_mapBusesCollectionGeneric = new MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>(
|
||||
(int) pictureBoxBus.getWidth(), (int) pictureBoxBus.getHeight(), map);
|
||||
}
|
||||
gc = canvasBus.getGraphicsContext2D();
|
||||
if (comboBoxSelectorMap.getValue() != map_name) {
|
||||
map_name = comboBoxSelectorMap.getValue();
|
||||
switch (map_name) {
|
||||
case "Простая карта" -> map = new SimpleMap();
|
||||
case "Водная карта" -> map = new WaterMap();
|
||||
}
|
||||
_mapBusesCollectionGeneric.changeMap(map);
|
||||
}
|
||||
}
|
||||
|
||||
private void ReloadMaps()
|
||||
{
|
||||
int index = listViewMaps.getSelectionModel().getSelectedIndex();
|
||||
|
||||
ObservableList<String> listMaps = FXCollections.observableArrayList();
|
||||
|
||||
for (int i = 0; i < _mapsCollection.Keys().size(); i++)
|
||||
{
|
||||
listMaps.add(_mapsCollection.Keys().get(i));
|
||||
}
|
||||
listViewMaps.setItems(listMaps);
|
||||
|
||||
if (listMaps.size() > 0 && (index == -1 || index >= listMaps.size()))
|
||||
{
|
||||
listViewMaps.getSelectionModel().select(0);
|
||||
}
|
||||
else if (listMaps.size() > 0 && index > -1 && index < listMaps.size())
|
||||
{
|
||||
listViewMaps.getSelectionModel().select(index);
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonAddBus_Click(ActionEvent event) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBus.fxml"));
|
||||
@ -90,6 +144,57 @@ public class ControllerMapWithSetBus {
|
||||
|
||||
FirstIncome();
|
||||
}
|
||||
@FXML
|
||||
private void ButtonAddMap_Click(ActionEvent event)
|
||||
{
|
||||
if ((Objects.equals(TextFieldMap.getText(), "")))
|
||||
{
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle("SelectMap");
|
||||
alert.setContentText("Не все данные заполнены");
|
||||
Optional<ButtonType> option = alert.showAndWait();
|
||||
return;
|
||||
}
|
||||
if (!_mapsDict.containsKey(comboBoxSelectorMap.getValue()))
|
||||
{
|
||||
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||
alert.setTitle("SelectMap");
|
||||
alert.setContentText("Нет такой карты");
|
||||
Optional<ButtonType> option = alert.showAndWait();
|
||||
return;
|
||||
}
|
||||
_mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(comboBoxSelectorMap.getValue()));
|
||||
ReloadMaps();
|
||||
showStorage();
|
||||
}
|
||||
@FXML
|
||||
private void ButtonDeleteMap_Click(ActionEvent event)
|
||||
{
|
||||
if (listViewMaps.getSelectionModel().selectedItemProperty().isNull().get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection.DelMap(listViewMaps.getSelectionModel().getSelectedItem());
|
||||
ReloadMaps();
|
||||
showStorage();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonDeleteEditBus_Click(ActionEvent event) throws IOException {
|
||||
if (selected == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DrawingObjectBus deleteBus = _mapsCollection.get(selected).getDeletedBus();
|
||||
if (deleteBus != null) {
|
||||
ControllerBus._bus = deleteBus.getBus();
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBus.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
Form.myStage.setTitle("DoubleDeckerBus");
|
||||
Form.myStage.setScene(scene);
|
||||
Form.myStage.show();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonRemoveBus_Click(ActionEvent event)
|
||||
@ -111,12 +216,13 @@ public class ControllerMapWithSetBus {
|
||||
int pos;
|
||||
try {
|
||||
pos = Integer.parseInt(textBoxPosition.getText());
|
||||
if (pos < 1 || pos > _mapsCollection.GetId(selected).getCount()) return;
|
||||
}
|
||||
catch (Exception e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_mapBusesCollectionGeneric.remove(pos) != null)
|
||||
if (_mapsCollection.GetId(selected).remove(pos) != null)
|
||||
{
|
||||
alert = new Alert(Alert.AlertType.WARNING);
|
||||
alert.setTitle("RemoveBus");
|
||||
@ -130,36 +236,31 @@ public class ControllerMapWithSetBus {
|
||||
alert.setContentText("Не удалось удалить объект");
|
||||
option = alert.showAndWait();
|
||||
}
|
||||
showStorage();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonShowStorage_Click(ActionEvent event)
|
||||
{
|
||||
FirstIncome();
|
||||
if (_mapBusesCollectionGeneric == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gc.setFill(Color.WHITE);
|
||||
gc.fillRect(0, 0, pictureBoxBus.getWidth(), pictureBoxBus.getHeight());
|
||||
_mapBusesCollectionGeneric.ShowSet(gc);
|
||||
showStorage();
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonShowOnMap_Click(ActionEvent event) {
|
||||
FirstIncome();
|
||||
if (_mapBusesCollectionGeneric == null) {
|
||||
if (selected == null) {
|
||||
return;
|
||||
}
|
||||
gc.setFill(Color.WHITE);
|
||||
gc.fillRect(0, 0, pictureBoxBus.getWidth(), pictureBoxBus.getHeight());
|
||||
_mapBusesCollectionGeneric.ShowOnMap(gc);
|
||||
gc.fillRect(0, 0, canvasBus.getWidth(), canvasBus.getHeight());
|
||||
_mapsCollection.GetId(selected).ShowOnMap(gc);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void ButtonMove_Click(ActionEvent event)
|
||||
{
|
||||
if (_mapBusesCollectionGeneric == null)
|
||||
if (selected == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -172,8 +273,19 @@ public class ControllerMapWithSetBus {
|
||||
case "buttonLeft" -> dir = Direction.Left;
|
||||
case "buttonRight" -> dir = Direction.Right;
|
||||
}
|
||||
_mapBusesCollectionGeneric.MoveObject(dir);
|
||||
_mapsCollection.GetId(selected).MoveObject(dir);
|
||||
}
|
||||
|
||||
private void showStorage() {
|
||||
if (selected == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gc.setFill(Color.WHITE);
|
||||
gc.fillRect(0, 0, pictureBoxBus.getWidth(), pictureBoxBus.getHeight());
|
||||
_mapsCollection.GetId(selected).ShowSet(gc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -39,4 +39,8 @@ public class DrawingObjectBus implements IDrawingObject {
|
||||
{
|
||||
_bus.DrawTransport(gc);
|
||||
}
|
||||
|
||||
public DrawingBus getBus() {
|
||||
return _bus;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class Form extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormPolymorph.fxml"));
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml"));
|
||||
Scene scene = new Scene(fxmlLoader.load());
|
||||
myStage = stage;
|
||||
myStage.setTitle("DoubleDeckerBus");
|
||||
|
@ -3,7 +3,7 @@ package com.example.doubledeckerbus;
|
||||
import javafx.scene.canvas.GraphicsContext;
|
||||
import javafx.scene.paint.Color;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||
private final int _pictureWidth;
|
||||
@ -11,6 +11,7 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
||||
private final int _placeSizeWidth = 210;
|
||||
private final int _placeSizeHeight = 90;
|
||||
private final SetBusesGeneric<T> _setBuses;
|
||||
private final Stack<T> _deletedBuses;
|
||||
private U _map;
|
||||
|
||||
public MapWithSetBusesGeneric(int picWidth, int picHeight, U map)
|
||||
@ -21,6 +22,7 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_map = map;
|
||||
_deletedBuses = new Stack<>();
|
||||
}
|
||||
|
||||
public void changeMap(U map) {
|
||||
@ -34,7 +36,15 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
||||
|
||||
public T remove(int position)
|
||||
{
|
||||
return _setBuses.Remove(position);
|
||||
T deletedBus = _setBuses.Remove(position);
|
||||
_deletedBuses.push(deletedBus);
|
||||
return deletedBus;
|
||||
}
|
||||
|
||||
public T getDeletedBus(){
|
||||
if(_deletedBuses.empty())
|
||||
return null;
|
||||
return _deletedBuses.pop();
|
||||
}
|
||||
|
||||
public void ShowSet(GraphicsContext gc)
|
||||
@ -46,9 +56,8 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
||||
public void ShowOnMap(GraphicsContext gc)
|
||||
{
|
||||
Shaking();
|
||||
for (int i = 0; i < _setBuses.Count(); i++)
|
||||
for (var bus: _setBuses.GetBuses())
|
||||
{
|
||||
var bus = _setBuses.Get(i);
|
||||
if (bus != null)
|
||||
{
|
||||
_map.CreateMap(_pictureWidth, _pictureHeight, bus, gc);
|
||||
@ -111,15 +120,15 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
||||
int currentWidth = width - 1;
|
||||
int currentHeight = 0;
|
||||
|
||||
for (int i = 0; i < _setBuses.Count(); i++) {
|
||||
if (_setBuses.Get(i) == null){
|
||||
for (var bus: _setBuses.GetBuses()) {
|
||||
if (bus == null){
|
||||
continue;
|
||||
}
|
||||
|
||||
_setBuses.Get(i).SetObject(currentWidth * _placeSizeWidth,
|
||||
bus.SetObject(currentWidth * _placeSizeWidth,
|
||||
currentHeight * _placeSizeHeight,
|
||||
_pictureWidth, _pictureHeight);
|
||||
_setBuses.Get(i).DrawingObject(gc);
|
||||
bus.DrawingObject(gc);
|
||||
|
||||
if (currentWidth > 0)
|
||||
currentWidth--;
|
||||
@ -130,5 +139,13 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
||||
if (currentHeight > height) return;
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return _setBuses.Count();
|
||||
}
|
||||
|
||||
public T getBus(int ind){
|
||||
return _setBuses.Get(ind);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,65 @@
|
||||
package com.example.doubledeckerbus;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class MapsCollection {
|
||||
HashMap<String, MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>> _mapStorages;
|
||||
|
||||
public List<String> Keys() {
|
||||
return _mapStorages.keySet().stream().toList();
|
||||
}
|
||||
|
||||
private int _pictureWidth;
|
||||
|
||||
private int _pictureHeight;
|
||||
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new HashMap<>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddMap(String name, AbstractMap map)
|
||||
{
|
||||
if (Keys().contains(name)) return;
|
||||
_mapStorages.put(name, new MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
}
|
||||
|
||||
public void DelMap(String name)
|
||||
{
|
||||
_mapStorages.remove(name);
|
||||
}
|
||||
|
||||
public MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap> GetId(String id)
|
||||
{
|
||||
return _mapStorages.get(id);
|
||||
}
|
||||
|
||||
public ObservableList<String> toObserveList() {
|
||||
ObservableList<String> result = FXCollections.observableArrayList();
|
||||
result.addAll(_mapStorages.keySet());
|
||||
return result;
|
||||
}
|
||||
|
||||
public MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap> get(String id) {
|
||||
if (_mapStorages.containsKey(id))
|
||||
{
|
||||
return _mapStorages.get(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public DrawingObjectBus get(String name, int id) {
|
||||
if (_mapStorages.containsKey(name))
|
||||
{
|
||||
return _mapStorages.get(name).getBus(id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -1,15 +1,20 @@
|
||||
package com.example.doubledeckerbus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
class SetBusesGeneric<T> {
|
||||
private Object[] _places;
|
||||
private ArrayList<T> _places;
|
||||
private int BusyPlaces = 0;
|
||||
|
||||
private int _maxCount;
|
||||
|
||||
public SetBusesGeneric(int count) {
|
||||
_places = new Object[count];
|
||||
_maxCount = count;
|
||||
_places = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int Insert(T bus)
|
||||
@ -19,37 +24,39 @@ class SetBusesGeneric<T> {
|
||||
|
||||
public int Insert(T bus, int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.length|| BusyPlaces == _places.length) return -1;
|
||||
if (position < 0 || position >= _maxCount || BusyPlaces == _maxCount) return -1;
|
||||
|
||||
BusyPlaces++;
|
||||
while (_places[position] != null) {
|
||||
for (int i = _places.length - 1; i > 0; --i) {
|
||||
if (_places[i] == null && _places[i - 1] != null) {
|
||||
_places[i] = _places[i - 1];
|
||||
_places[i - 1] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
_places[position] = bus;
|
||||
_places.add(position, bus);
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.length) return null;
|
||||
T savedBus = (T)_places[position];
|
||||
_places[position] = null;
|
||||
if (position < 0 || position >= _maxCount) return null;
|
||||
T savedBus = _places.get(position - 1);
|
||||
_places.set(position - 1, null);
|
||||
return savedBus;
|
||||
}
|
||||
|
||||
public T Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _places.length) return null;
|
||||
return (T)_places[position];
|
||||
if (position < 0 || position >= _maxCount) return null;
|
||||
return _places.get(position);
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<T> GetBuses() {
|
||||
ArrayList<T> result = new ArrayList<>();
|
||||
for (var bus: _places) {
|
||||
if (bus != null){
|
||||
result.add(bus);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public int Count() {
|
||||
return _places.length;
|
||||
return _places.size();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
<?import javafx.scene.canvas.Canvas?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ChoiceBox?>
|
||||
<?import javafx.scene.control.ColorPicker?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
@ -27,13 +28,15 @@
|
||||
<Label fx:id="statusSpeed" text="Скорость:" />
|
||||
<Label fx:id="statusWeight" text="Вес:" />
|
||||
<Label fx:id="statusColor" text="Цвет:" />
|
||||
<ColorPicker fx:id="bodyColorPicker" />
|
||||
<ColorPicker fx:id="extraColorPicker" />
|
||||
<Label text="Колл-во дверей:" />
|
||||
<ChoiceBox fx:id="choiceDoors" prefHeight="24.0" prefWidth="58.0" />
|
||||
</children>
|
||||
</HBox>
|
||||
<AnchorPane fx:id="pictureBoxBus" maxHeight="2000000.0" maxWidth="2000000.0" minHeight="0.0" minWidth="0.0" prefHeight="603.0" prefWidth="1020.0">
|
||||
<children>
|
||||
<Canvas fx:id="canvasBus" layoutY="38.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<Canvas fx:id="canvasBus" height="603.0" layoutY="38.0" width="1021.0" AnchorPane.leftAnchor="0.0" AnchorPane.topAnchor="0.0" />
|
||||
<Button fx:id="buttonLeft" layoutX="975.0" layoutY="427.0" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="0.0" prefWidth="0.0" AnchorPane.bottomAnchor="40.0" AnchorPane.rightAnchor="60.0">
|
||||
<graphic>
|
||||
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
||||
|
@ -4,6 +4,7 @@
|
||||
<?import javafx.scene.canvas.Canvas?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.ChoiceBox?>
|
||||
<?import javafx.scene.control.ListView?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
@ -12,7 +13,7 @@
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="463.0" prefWidth="779.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.doubledeckerbus.ControllerMapWithSetBus">
|
||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="745.0" prefWidth="819.0" xmlns="http://javafx.com/javafx/18" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.example.doubledeckerbus.ControllerMapWithSetBus">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="ALWAYS" maxWidth="463.0" minWidth="10.0" percentWidth="70.0" prefWidth="423.0" />
|
||||
<ColumnConstraints hgrow="NEVER" maxWidth="294.0" minWidth="10.0" percentWidth="30.0" prefWidth="177.0" />
|
||||
@ -23,7 +24,7 @@
|
||||
<children>
|
||||
<AnchorPane fx:id="pictureBoxBus" prefHeight="9.9999999E7" prefWidth="9.9999999E7">
|
||||
<children>
|
||||
<Canvas fx:id="canvasBus" height="463.0" width="537.0" />
|
||||
<Canvas fx:id="canvasBus" height="745.0" width="573.0" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<Group GridPane.columnIndex="1" />
|
||||
@ -34,21 +35,24 @@
|
||||
<rowConstraints>
|
||||
<RowConstraints maxHeight="120.0" minHeight="0.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="200.0" minHeight="10.0" prefHeight="24.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="200.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="200.0" minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="200.0" minHeight="8.0" prefHeight="27.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="269.0" minHeight="10.0" prefHeight="65.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="250.0" minHeight="0.0" prefHeight="44.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="272.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="272.0" minHeight="10.0" prefHeight="34.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="272.0" minHeight="0.0" prefHeight="46.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="272.0" minHeight="0.0" prefHeight="46.0" vgrow="SOMETIMES" />
|
||||
<RowConstraints maxHeight="272.0" minHeight="10.0" prefHeight="134.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<ChoiceBox fx:id="comboBoxSelectorMap" prefHeight="50.0" prefWidth="9.9999999E7" />
|
||||
<Button fx:id="buttonAddBus" mnemonicParsing="false" onAction="#ButtonAddBus_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Добавить автобус" GridPane.rowIndex="2" />
|
||||
<TextField fx:id="textBoxPosition" GridPane.rowIndex="3" />
|
||||
<Button fx:id="buttonRemoveCar" mnemonicParsing="false" onAction="#ButtonRemoveBus_Click" prefHeight="63.0" prefWidth="9.999999999E9" text="Удалить автобус" GridPane.rowIndex="4" />
|
||||
<Button fx:id="buttonShowMap" mnemonicParsing="false" onAction="#ButtonShowOnMap_Click" prefHeight="63.0" prefWidth="9.99999999999E11" text="Посмотреть карту" GridPane.rowIndex="7" />
|
||||
<AnchorPane prefHeight="157.0" prefWidth="332.0" GridPane.rowIndex="8">
|
||||
<ChoiceBox fx:id="comboBoxSelectorMap" prefHeight="50.0" prefWidth="9.9999999E7" GridPane.rowIndex="1" />
|
||||
<Button fx:id="buttonAddBus" mnemonicParsing="false" onAction="#ButtonAddBus_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Добавить автобус" GridPane.rowIndex="5" />
|
||||
<TextField fx:id="textBoxPosition" GridPane.rowIndex="6" />
|
||||
<Button fx:id="buttonRemoveCar" mnemonicParsing="false" onAction="#ButtonRemoveBus_Click" prefHeight="63.0" prefWidth="9.999999999E9" text="Удалить автобус" GridPane.rowIndex="7" />
|
||||
<Button fx:id="buttonShowMap" mnemonicParsing="false" onAction="#ButtonShowOnMap_Click" prefHeight="63.0" prefWidth="9.99999999999E11" text="Посмотреть карту" GridPane.rowIndex="10" />
|
||||
<AnchorPane prefHeight="157.0" prefWidth="332.0" GridPane.rowIndex="11">
|
||||
<children>
|
||||
<Button fx:id="buttonLeft" layoutX="38.0" layoutY="52.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" mnemonicParsing="false" onAction="#ButtonMove_Click" prefHeight="30.0" prefWidth="30.0" AnchorPane.bottomAnchor="52.0" AnchorPane.rightAnchor="111.0">
|
||||
<graphic>
|
||||
@ -88,7 +92,12 @@
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<Button fx:id="buttonShowStorage" mnemonicParsing="false" onAction="#ButtonShowStorage_Click" prefHeight="50.0" prefWidth="1.0E16" text="Посмотреть хранилище" GridPane.rowIndex="6" />
|
||||
<Button fx:id="buttonShowStorage" mnemonicParsing="false" onAction="#ButtonShowStorage_Click" prefHeight="50.0" prefWidth="1.0E16" text="Посмотреть хранилище" GridPane.rowIndex="9" />
|
||||
<TextField fx:id="TextFieldMap" />
|
||||
<Button fx:id="Map" mnemonicParsing="false" onAction="#ButtonAddMap_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Добавить карту" GridPane.rowIndex="2" />
|
||||
<ListView fx:id="listViewMaps" prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="3" />
|
||||
<Button fx:id="buttonDeleteMap" mnemonicParsing="false" onAction="#ButtonDeleteMap_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Удалить карту" GridPane.rowIndex="4" />
|
||||
<Button fx:id="ButtonDeleteEditBus" mnemonicParsing="false" onAction="#ButtonDeleteEditBus_Click" prefHeight="63.0" prefWidth="9.999999999E9" text="Вернуть автобус" GridPane.rowIndex="8" />
|
||||
</children>
|
||||
</GridPane>
|
||||
</children>
|
||||
|
Loading…
Reference in New Issue
Block a user