LabWork04
This commit is contained in:
parent
393c030e88
commit
c7463393b4
@ -21,7 +21,7 @@ import static com.example.doubledeckerbus.ControllerMapWithSetBus._mapBusesColle
|
|||||||
|
|
||||||
public class ControllerBus {
|
public class ControllerBus {
|
||||||
|
|
||||||
protected DrawingBus _bus;
|
public static DrawingBus _bus;
|
||||||
public DrawingBus SelectedBus;
|
public DrawingBus SelectedBus;
|
||||||
protected ObservableList<Integer> countOfDoors = FXCollections.observableArrayList(3, 4, 5);
|
protected ObservableList<Integer> countOfDoors = FXCollections.observableArrayList(3, 4, 5);
|
||||||
@FXML
|
@FXML
|
||||||
@ -82,6 +82,9 @@ public class ControllerBus {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void ButtonMove_Click(ActionEvent event) {
|
void ButtonMove_Click(ActionEvent event) {
|
||||||
|
pictureBoxBus.widthProperty().addListener(listener);
|
||||||
|
pictureBoxBus.heightProperty().addListener(listener);
|
||||||
|
|
||||||
if (_bus == null) return;
|
if (_bus == null) return;
|
||||||
String name = ((Button) event.getSource()).getId();
|
String name = ((Button) event.getSource()).getId();
|
||||||
switch (name) {
|
switch (name) {
|
||||||
@ -97,6 +100,9 @@ public class ControllerBus {
|
|||||||
public void initialize() {
|
public void initialize() {
|
||||||
choiceDoors.setItems(countOfDoors);
|
choiceDoors.setItems(countOfDoors);
|
||||||
choiceDoors.setValue(3);
|
choiceDoors.setValue(3);
|
||||||
|
if (_bus != null) {
|
||||||
|
Draw();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
InvalidationListener listener = o -> BorderChanged();
|
InvalidationListener listener = o -> BorderChanged();
|
||||||
@ -156,6 +162,7 @@ public class ControllerBus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_bus = null;
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(Form.class.getResource("FormMapWithSetBus.fxml"));
|
||||||
Scene scene = new Scene(fxmlLoader.load());
|
Scene scene = new Scene(fxmlLoader.load());
|
||||||
Form.myStage.setTitle("DoubleDeckerBus");
|
Form.myStage.setTitle("DoubleDeckerBus");
|
||||||
|
@ -132,6 +132,8 @@ 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"));
|
||||||
@ -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
|
@FXML
|
||||||
private void ButtonRemoveBus_Click(ActionEvent event)
|
private void ButtonRemoveBus_Click(ActionEvent event)
|
||||||
{
|
{
|
||||||
@ -196,6 +215,7 @@ public class ControllerMapWithSetBus {
|
|||||||
int pos;
|
int pos;
|
||||||
try {
|
try {
|
||||||
pos = Integer.parseInt(textBoxPosition.getText());
|
pos = Integer.parseInt(textBoxPosition.getText());
|
||||||
|
if (pos < 1 || pos > _mapsCollection.GetId(selected).getCount()) return;
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
return;
|
return;
|
||||||
|
@ -39,4 +39,8 @@ public class DrawingObjectBus implements IDrawingObject {
|
|||||||
{
|
{
|
||||||
_bus.DrawTransport(gc);
|
_bus.DrawTransport(gc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawingBus getBus() {
|
||||||
|
return _bus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package com.example.doubledeckerbus;
|
|||||||
import javafx.scene.canvas.GraphicsContext;
|
import javafx.scene.canvas.GraphicsContext;
|
||||||
import javafx.scene.paint.Color;
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Stack;
|
||||||
|
|
||||||
public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends AbstractMap> {
|
||||||
private final int _pictureWidth;
|
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 _placeSizeWidth = 210;
|
||||||
private final int _placeSizeHeight = 90;
|
private final int _placeSizeHeight = 90;
|
||||||
private final SetBusesGeneric<T> _setBuses;
|
private final SetBusesGeneric<T> _setBuses;
|
||||||
|
private final Stack<T> _deletedBuses;
|
||||||
private U _map;
|
private U _map;
|
||||||
|
|
||||||
public MapWithSetBusesGeneric(int picWidth, int picHeight, 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;
|
_pictureWidth = picWidth;
|
||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_map = map;
|
_map = map;
|
||||||
|
_deletedBuses = new Stack<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeMap(U map) {
|
public void changeMap(U map) {
|
||||||
@ -34,7 +36,15 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
|||||||
|
|
||||||
public T remove(int position)
|
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)
|
public void ShowSet(GraphicsContext gc)
|
||||||
@ -129,5 +139,13 @@ public class MapWithSetBusesGeneric<T extends IDrawingObject, U extends Abstract
|
|||||||
if (currentHeight > height) return;
|
if (currentHeight > height) return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return _setBuses.Count();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getBus(int ind){
|
||||||
|
return _setBuses.Get(ind);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,4 +46,20 @@ public class MapsCollection {
|
|||||||
return result;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
</HBox>
|
</HBox>
|
||||||
<AnchorPane fx:id="pictureBoxBus" maxHeight="2000000.0" maxWidth="2000000.0" minHeight="0.0" minWidth="0.0" prefHeight="603.0" prefWidth="1020.0">
|
<AnchorPane fx:id="pictureBoxBus" maxHeight="2000000.0" maxWidth="2000000.0" minHeight="0.0" minWidth="0.0" prefHeight="603.0" prefWidth="1020.0">
|
||||||
<children>
|
<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">
|
<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>
|
<graphic>
|
||||||
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
<ImageView fitHeight="27.0" fitWidth="10.0" pickOnBounds="true" preserveRatio="true">
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
<RowConstraints maxHeight="269.0" minHeight="10.0" prefHeight="65.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="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="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="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 maxHeight="272.0" minHeight="10.0" prefHeight="134.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" />
|
<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" />
|
<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="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" />
|
<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="10">
|
<AnchorPane prefHeight="157.0" prefWidth="332.0" GridPane.rowIndex="11">
|
||||||
<children>
|
<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">
|
<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>
|
<graphic>
|
||||||
@ -91,11 +92,12 @@
|
|||||||
</Button>
|
</Button>
|
||||||
</children>
|
</children>
|
||||||
</AnchorPane>
|
</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" />
|
<TextField fx:id="TextFieldMap" />
|
||||||
<Button fx:id="Map" mnemonicParsing="false" onAction="#ButtonAddMap_Click" prefHeight="50.0" prefWidth="9.999999999E9" text="Добавить карту" GridPane.rowIndex="2" />
|
<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" />
|
<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="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>
|
</children>
|
||||||
</GridPane>
|
</GridPane>
|
||||||
</children>
|
</children>
|
||||||
|
Loading…
Reference in New Issue
Block a user