LabWork04

This commit is contained in:
shadowik 2022-11-15 04:17:57 +04:00
parent 393c030e88
commit c7463393b4
7 changed files with 74 additions and 7 deletions

View File

@ -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<Integer> 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");

View File

@ -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;

View File

@ -39,4 +39,8 @@ public class DrawingObjectBus implements IDrawingObject {
{
_bus.DrawTransport(gc);
}
public DrawingBus getBus() {
return _bus;
}
}

View File

@ -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)
@ -129,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);
}
}

View File

@ -46,4 +46,20 @@ public class MapsCollection {
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;
}
}

View File

@ -33,7 +33,7 @@
</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">

View File

@ -40,6 +40,7 @@
<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" />
@ -50,8 +51,8 @@
<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="9" />
<AnchorPane prefHeight="157.0" prefWidth="332.0" GridPane.rowIndex="10">
<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>
@ -91,11 +92,12 @@
</Button>
</children>
</AnchorPane>
<Button fx:id="buttonShowStorage" mnemonicParsing="false" onAction="#ButtonShowStorage_Click" prefHeight="50.0" prefWidth="1.0E16" text="Посмотреть хранилище" GridPane.rowIndex="8" />
<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>