From 9b156e2f0362f0e2378da5702443ca26040caa13 Mon Sep 17 00:00:00 2001 From: shadowik Date: Tue, 15 Nov 2022 10:55:23 +0400 Subject: [PATCH] LabWork Passed --- .../doubledeckerbus/ControllerBus.java | 25 ++++++++++----- .../ControllerMapWithSetBus.java | 32 +++++++++++-------- .../doubledeckerbus/SetBusesGeneric.java | 3 -- .../com/example/doubledeckerbus/FormBus.fxml | 3 ++ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java index 078a89b..2bfd57b 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerBus.java @@ -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; @@ -60,21 +62,31 @@ public class ControllerBus { @FXML protected ChoiceBox 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)); @@ -128,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(); } @@ -168,6 +178,5 @@ public class ControllerBus { Form.myStage.setTitle("DoubleDeckerBus"); Form.myStage.setScene(scene); Form.myStage.show(); - } } diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java index 7083c28..caa7a48 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/ControllerMapWithSetBus.java @@ -82,8 +82,10 @@ public class ControllerMapWithSetBus { @FXML private void initialize(){ -// canvasBus.setWidth(pictureBoxBus.getWidth()); -// canvasBus.setWidth(pictureBoxBus.getHeight()); + gc = canvasBus.getGraphicsContext2D(); + if (selected != null) { + showStorage(); + } if (_mapsCollection == null) _mapsCollection = new MapsCollection((int) canvasBus.getWidth(), (int) canvasBus.getHeight()); comboBoxSelectorMap.setItems(countOfMap); @@ -93,6 +95,7 @@ public class ControllerMapWithSetBus { @Override public void changed(ObservableValue observableValue, String s, String t1) { selected = t1; + showStorage(); } }); listViewMaps.setItems(_mapsCollection.toObserveList()); @@ -100,7 +103,6 @@ public class ControllerMapWithSetBus { GraphicsContext gc; private void FirstIncome() { - gc = canvasBus.getGraphicsContext2D(); if (comboBoxSelectorMap.getValue() != map_name) { map_name = comboBoxSelectorMap.getValue(); switch (map_name) { @@ -132,8 +134,6 @@ public class ControllerMapWithSetBus { } } - - @FXML private void ButtonAddBus_Click(ActionEvent event) throws IOException { FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBus.fxml")); @@ -165,6 +165,7 @@ public class ControllerMapWithSetBus { } _mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(comboBoxSelectorMap.getValue())); ReloadMaps(); + showStorage(); } @FXML private void ButtonDeleteMap_Click(ActionEvent event) @@ -175,7 +176,7 @@ public class ControllerMapWithSetBus { } _mapsCollection.DelMap(listViewMaps.getSelectionModel().getSelectedItem()); ReloadMaps(); - + showStorage(); } @FXML @@ -235,19 +236,14 @@ public class ControllerMapWithSetBus { alert.setContentText("Не удалось удалить объект"); option = alert.showAndWait(); } + showStorage(); } @FXML private void ButtonShowStorage_Click(ActionEvent event) { FirstIncome(); - if (selected == null) - { - return; - } - gc.setFill(Color.WHITE); - gc.fillRect(0, 0, pictureBoxBus.getWidth(), pictureBoxBus.getHeight()); - _mapsCollection.GetId(selected).ShowSet(gc); + showStorage(); } @FXML @@ -280,7 +276,15 @@ public class ControllerMapWithSetBus { _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); + } } diff --git a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java index b8f1ccb..983a1c5 100644 --- a/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java +++ b/DoubleDeckerBus/src/main/java/com/example/doubledeckerbus/SetBusesGeneric.java @@ -52,9 +52,6 @@ class SetBusesGeneric { if (bus != null){ result.add(bus); } - else { - break; - } } return result; } diff --git a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml index 791b0ad..23b7112 100644 --- a/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml +++ b/DoubleDeckerBus/src/main/resources/com/example/doubledeckerbus/FormBus.fxml @@ -4,6 +4,7 @@ + @@ -27,6 +28,8 @@