LabWork Passed

This commit is contained in:
shadowik 2022-11-15 10:55:23 +04:00
parent c7463393b4
commit 9b156e2f03
4 changed files with 38 additions and 25 deletions

View File

@ -4,6 +4,8 @@ import javafx.beans.InvalidationListener;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.scene.Scene; import javafx.scene.Scene;
@ -60,21 +62,31 @@ public class ControllerBus {
@FXML @FXML
protected ChoiceBox<Integer> choiceDoors; protected ChoiceBox<Integer> choiceDoors;
@FXML
private ColorPicker bodyColorPicker;
@FXML
private ColorPicker extraColorPicker;
@FXML @FXML
void ButtonCreate_Click(ActionEvent event) { void ButtonCreate_Click(ActionEvent event) {
pictureBoxBus.widthProperty().addListener(listener); pictureBoxBus.widthProperty().addListener(listener);
pictureBoxBus.heightProperty().addListener(listener); pictureBoxBus.heightProperty().addListener(listener);
Random rnd = new Random(); Random rnd = new Random();
_bus = new DrawingBus(rnd.nextInt(100, 300), rnd.nextFloat(1000, 2000), _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()); bodyColorPicker.getValue(), choiceDoors.getValue());
_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());
BorderChanged(); BorderChanged();
} }
void SetData() { void SetData() {
Random rnd = new Random(); 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)); statusSpeed.setText("Скорость: %s".formatted(_bus.Bus.Speed));
statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight)); statusWeight.setText("Вес: %s".formatted(_bus.Bus.Weight));
statusColor.setText("Цвет: %s".formatted(_bus.Bus.BodyColor)); statusColor.setText("Цвет: %s".formatted(_bus.Bus.BodyColor));
@ -128,10 +140,8 @@ public class ControllerBus {
pictureBoxBus.heightProperty().addListener(listener); pictureBoxBus.heightProperty().addListener(listener);
Random rnd = new Random(); Random rnd = new Random();
_bus = new DrawingDDB(rnd.nextInt(300), rnd.nextInt(2000), _bus = new DrawingDDB(rnd.nextInt(300), rnd.nextInt(2000),
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)), bodyColorPicker.getValue(), choiceDoors.getValue(),
choiceDoors.getValue(), extraColorPicker.getValue(), rnd.nextBoolean(), rnd.nextBoolean());
Color.rgb(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)),
rnd.nextBoolean(), rnd.nextBoolean());
SetData(); SetData();
BorderChanged(); BorderChanged();
} }
@ -168,6 +178,5 @@ public class ControllerBus {
Form.myStage.setTitle("DoubleDeckerBus"); Form.myStage.setTitle("DoubleDeckerBus");
Form.myStage.setScene(scene); Form.myStage.setScene(scene);
Form.myStage.show(); Form.myStage.show();
} }
} }

View File

@ -82,8 +82,10 @@ public class ControllerMapWithSetBus {
@FXML @FXML
private void initialize(){ private void initialize(){
// canvasBus.setWidth(pictureBoxBus.getWidth()); gc = canvasBus.getGraphicsContext2D();
// canvasBus.setWidth(pictureBoxBus.getHeight()); if (selected != null) {
showStorage();
}
if (_mapsCollection == null) if (_mapsCollection == null)
_mapsCollection = new MapsCollection((int) canvasBus.getWidth(), (int) canvasBus.getHeight()); _mapsCollection = new MapsCollection((int) canvasBus.getWidth(), (int) canvasBus.getHeight());
comboBoxSelectorMap.setItems(countOfMap); comboBoxSelectorMap.setItems(countOfMap);
@ -93,6 +95,7 @@ public class ControllerMapWithSetBus {
@Override @Override
public void changed(ObservableValue<? extends String> observableValue, String s, String t1) { public void changed(ObservableValue<? extends String> observableValue, String s, String t1) {
selected = t1; selected = t1;
showStorage();
} }
}); });
listViewMaps.setItems(_mapsCollection.toObserveList()); listViewMaps.setItems(_mapsCollection.toObserveList());
@ -100,7 +103,6 @@ public class ControllerMapWithSetBus {
GraphicsContext gc; GraphicsContext gc;
private void FirstIncome() { private void FirstIncome() {
gc = canvasBus.getGraphicsContext2D();
if (comboBoxSelectorMap.getValue() != map_name) { if (comboBoxSelectorMap.getValue() != map_name) {
map_name = comboBoxSelectorMap.getValue(); map_name = comboBoxSelectorMap.getValue();
switch (map_name) { switch (map_name) {
@ -132,8 +134,6 @@ public class ControllerMapWithSetBus {
} }
} }
@FXML @FXML
private void ButtonAddBus_Click(ActionEvent event) throws IOException { private void ButtonAddBus_Click(ActionEvent event) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBus.fxml")); FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormBus.fxml"));
@ -165,6 +165,7 @@ public class ControllerMapWithSetBus {
} }
_mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(comboBoxSelectorMap.getValue())); _mapsCollection.AddMap(TextFieldMap.getText(), _mapsDict.get(comboBoxSelectorMap.getValue()));
ReloadMaps(); ReloadMaps();
showStorage();
} }
@FXML @FXML
private void ButtonDeleteMap_Click(ActionEvent event) private void ButtonDeleteMap_Click(ActionEvent event)
@ -175,7 +176,7 @@ public class ControllerMapWithSetBus {
} }
_mapsCollection.DelMap(listViewMaps.getSelectionModel().getSelectedItem()); _mapsCollection.DelMap(listViewMaps.getSelectionModel().getSelectedItem());
ReloadMaps(); ReloadMaps();
showStorage();
} }
@FXML @FXML
@ -235,19 +236,14 @@ public class ControllerMapWithSetBus {
alert.setContentText("Не удалось удалить объект"); alert.setContentText("Не удалось удалить объект");
option = alert.showAndWait(); option = alert.showAndWait();
} }
showStorage();
} }
@FXML @FXML
private void ButtonShowStorage_Click(ActionEvent event) private void ButtonShowStorage_Click(ActionEvent event)
{ {
FirstIncome(); FirstIncome();
if (selected == null) showStorage();
{
return;
}
gc.setFill(Color.WHITE);
gc.fillRect(0, 0, pictureBoxBus.getWidth(), pictureBoxBus.getHeight());
_mapsCollection.GetId(selected).ShowSet(gc);
} }
@FXML @FXML
@ -280,7 +276,15 @@ public class ControllerMapWithSetBus {
_mapsCollection.GetId(selected).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);
}
} }

View File

@ -52,9 +52,6 @@ class SetBusesGeneric<T> {
if (bus != null){ if (bus != null){
result.add(bus); result.add(bus);
} }
else {
break;
}
} }
return result; return result;
} }

View File

@ -4,6 +4,7 @@
<?import javafx.scene.canvas.Canvas?> <?import javafx.scene.canvas.Canvas?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?> <?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.ColorPicker?>
<?import javafx.scene.control.Label?> <?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?> <?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?> <?import javafx.scene.image.ImageView?>
@ -27,6 +28,8 @@
<Label fx:id="statusSpeed" text="Скорость:" /> <Label fx:id="statusSpeed" text="Скорость:" />
<Label fx:id="statusWeight" text="Вес:" /> <Label fx:id="statusWeight" text="Вес:" />
<Label fx:id="statusColor" text="Цвет:" /> <Label fx:id="statusColor" text="Цвет:" />
<ColorPicker fx:id="bodyColorPicker" />
<ColorPicker fx:id="extraColorPicker" />
<Label text="Колл-во дверей:" /> <Label text="Колл-во дверей:" />
<ChoiceBox fx:id="choiceDoors" prefHeight="24.0" prefWidth="58.0" /> <ChoiceBox fx:id="choiceDoors" prefHeight="24.0" prefWidth="58.0" />
</children> </children>