From c7463393b4b402f8d9e6c3aeda410f83165432e4 Mon Sep 17 00:00:00 2001 From: shadowik Date: Tue, 15 Nov 2022 04:17:57 +0400 Subject: [PATCH] LabWork04 --- .../doubledeckerbus/ControllerBus.java | 9 +++++++- .../ControllerMapWithSetBus.java | 20 +++++++++++++++++ .../doubledeckerbus/DrawingObjectBus.java | 4 ++++ .../MapWithSetBusesGeneric.java | 22 +++++++++++++++++-- .../doubledeckerbus/MapsCollection.java | 16 ++++++++++++++ .../com/example/doubledeckerbus/FormBus.fxml | 2 +- .../doubledeckerbus/FormMapWithSetBus.fxml | 8 ++++--- 7 files changed, 74 insertions(+), 7 deletions(-) diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java index a811492..078a89b 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java @@ -21,7 +21,7 @@ import static com.example.doubledeckerbus.ControllerMapWithSetBus._mapBusesColle public class ControllerBus { - protected DrawingBus _bus; + public static DrawingBus _bus; public DrawingBus SelectedBus; protected ObservableList countOfDoors = FXCollections.observableArrayList(3, 4, 5); @FXML @@ -82,6 +82,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 +100,9 @@ public class ControllerBus { public void initialize() { choiceDoors.setItems(countOfDoors); choiceDoors.setValue(3); + if (_bus != null) { + Draw(); + } } InvalidationListener listener = o -> BorderChanged(); @@ -156,6 +162,7 @@ public class ControllerBus { } } + _bus = null; FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml")); Scene scene = new Scene(fxmlLoader.load()); Form.myStage.setTitle("DoubleDeckerBus"); diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java index 05fed9f..7083c28 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java @@ -132,6 +132,8 @@ public class ControllerMapWithSetBus { } } + + @FXML private void ButtonAddBus_Click(ActionEvent event) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBus.fxml")); @@ -176,6 +178,23 @@ public class ControllerMapWithSetBus { } + @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) { @@ -196,6 +215,7 @@ public class ControllerMapWithSetBus { int pos; try { pos = Integer.parseInt(textBoxPosition.getText()); + if (pos < 1 || pos > _mapsCollection.GetId(selected).getCount()) return; } catch (Exception e) { return; diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingObjectBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingObjectBus.java index dc37f2d..3abfd35 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingObjectBus.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/DrawingObjectBus.java @@ -39,4 +39,8 @@ public class DrawingObjectBus implements IDrawingObject { { _bus.DrawTransport(gc); } + + public DrawingBus getBus() { + return _bus; + } } diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java index 3215a9d..43074d1 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapWithSetBusesGeneric.java @@ -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 { private final int _pictureWidth; @@ -11,6 +11,7 @@ public class MapWithSetBusesGeneric _setBuses; + private final Stack _deletedBuses; private U _map; public MapWithSetBusesGeneric(int picWidth, int picHeight, U map) @@ -21,6 +22,7 @@ public class MapWithSetBusesGeneric(); } public void changeMap(U map) { @@ -34,7 +36,15 @@ public class MapWithSetBusesGeneric height) return; } } + + public int getCount() { + return _setBuses.Count(); + } + + public T getBus(int ind){ + return _setBuses.Get(ind); + } } diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapsCollection.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapsCollection.java index b7cf218..b802b7d 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapsCollection.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/MapsCollection.java @@ -46,4 +46,20 @@ public class MapsCollection { return result; } + public MapWithSetBusesGeneric 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; + } + } diff --git a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml index 49bbe9c..791b0ad 100644 --- a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml +++ b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml @@ -33,7 +33,7 @@ - + -