This commit is contained in:
ZakenChannel 2024-05-07 14:04:36 +04:00
parent 2df2b62be9
commit cf332ea14a
7 changed files with 167 additions and 187 deletions

View File

@ -11,7 +11,8 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version> </properties> <junit.version>5.9.2</junit.version>
</properties>
<dependencies> <dependencies>
<dependency> <dependency>
@ -40,7 +41,8 @@
<artifactId>junit-jupiter-engine</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version> <version>${junit.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependencies> </dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
@ -62,7 +64,8 @@
<!-- Default configuration for running with: mvn clean javafx:run --> <!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id> <id>default-cli</id>
<configuration> <configuration>
<mainClass>com.example.projectairfighter/com.example.projectairfighter.HelloApplication</mainClass> <mainClass>com.example.projectairfighter/com.example.projectairfighter.HelloApplication
</mainClass>
<launcher>app</launcher> <launcher>app</launcher>
<jlinkZipName>app</jlinkZipName> <jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName> <jlinkImageName>app</jlinkImageName>

View File

@ -238,34 +238,51 @@ public class FormWarPlaneCollection extends Application implements Initializable
*/ */
@FXML @FXML
private void saveToolStripMenuItem() { private void saveToolStripMenuItem() {
Stage mainStage = (Stage) splitPane.getScene().getWindow(); FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Сохранить данные");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("Text Files (*.txt)", "*.txt")
);
Stage dialog = new Stage(); File selectedFile = fileChooser.showSaveDialog(null);
dialog.setResizable(false); if (selectedFile != null) {
dialog.initOwner(mainStage); boolean success = storageCollection.saveData(selectedFile.getAbsolutePath());
dialog.initModality(Modality.APPLICATION_MODAL); // Блокируем доступ к основному окну if (success) {
dialog.setTitle("Выберите коллекцию для сохранения"); showAlert("Сохранение прошло успешно", "Результат", Alert.AlertType.INFORMATION);
} else {
VBox layout = new VBox(10); showAlert("Не сохранилось", "Результат", Alert.AlertType.ERROR);
layout.setAlignment(Pos.CENTER); }
}
ToggleGroup toggleGroup = new ToggleGroup();
for (String collection : listViewCollection.getItems()) {
RadioButton radioButton = new RadioButton(collection);
radioButton.setPadding(new Insets(5));
radioButton.setToggleGroup(toggleGroup);
layout.getChildren().add(radioButton);
} }
RadioButton allCollections = new RadioButton("Все коллекции"); /**
Button submitButton = new Button("Сохранить"); * Обработка кнопки загрузки
allCollections.setToggleGroup(toggleGroup); */
layout.getChildren().addAll(allCollections, submitButton); @FXML
private void loadToolStripMenuItem() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Открыть текстовый файл");
submitButton.setOnAction(e -> { FileChooser.ExtensionFilter txtFilter = new FileChooser.ExtensionFilter("Text Files (*.txt)", "*.txt");
if (toggleGroup.getSelectedToggle() == null || storageCollection.keys().isEmpty()) { fileChooser.getExtensionFilters().add(txtFilter);
showError("Не выбрана коллекция или выбранная коллекция пуста");
File selectedFile = fileChooser.showOpenDialog(null);
if (selectedFile != null) {
boolean success = storageCollection.loadData(selectedFile.getAbsolutePath());
if (success) {
refreshListBoxItems();
showAlert("Загрузка прошла успешно", "Результат", Alert.AlertType.INFORMATION);
} else {
showAlert("Загрузка не выполнена", "Результат", Alert.AlertType.ERROR);
}
}
}
@FXML
private void loadToolStripMenuItemSelectedCompany() {
if (listViewCollection.getSelectionModel().getSelectedIndex() < 0 || listViewCollection.getSelectionModel().getSelectedItem() == null) {
showAlert("Коллекция не выбрана");
return; return;
} }
@ -277,50 +294,13 @@ public class FormWarPlaneCollection extends Application implements Initializable
File selectedFile = fileChooser.showSaveDialog(null); File selectedFile = fileChooser.showSaveDialog(null);
if (selectedFile != null) { if (selectedFile != null) {
boolean success; boolean success = storageCollection.saveData(selectedFile.getAbsolutePath(), listViewCollection.getSelectionModel().getSelectedItem());
RadioButton selectedRadioButton = (RadioButton) toggleGroup.getSelectedToggle();
if (selectedRadioButton.getText().equals("Все коллекции"))
success = storageCollection.saveData(selectedFile.getAbsolutePath());
else
success = storageCollection.saveData(selectedFile.getAbsolutePath(), selectedRadioButton.getText());
if (success) { if (success) {
showAlert("Сохранение прошло успешно", "Результат", Alert.AlertType.INFORMATION); showAlert("Сохранение прошло успешно", "Результат", Alert.AlertType.INFORMATION);
} else { } else {
showAlert("Не сохранилось", "Результат", Alert.AlertType.ERROR); showAlert("Не сохранилось", "Результат", Alert.AlertType.ERROR);
} }
} }
dialog.close(); // Закрыть диалог после сохранения
});
Scene scene = new Scene(layout, 250, 200);
dialog.setScene(scene);
dialog.showAndWait(); // Показываем диалог и ждем закрытия
}
/**
* Обработка кнопки загрузки
*/
@FXML
private void loadToolStripMenuItem() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Открыть текстовый файл");
// Настройка фильтра расширений для выбора только текстовых файлов
FileChooser.ExtensionFilter txtFilter = new FileChooser.ExtensionFilter("Text Files (*.txt)", "*.txt");
fileChooser.getExtensionFilters().add(txtFilter);
// Отображение диалога открытия файла
File selectedFile = fileChooser.showOpenDialog(null);
if (selectedFile != null) {
boolean success = storageCollection.loadData(selectedFile.getAbsolutePath());
if (success) {
refreshListBoxItems();
showAlert("Загрузка прошла успешно", "Результат", Alert.AlertType.INFORMATION);
} else {
showAlert("Загрузка не выполнена", "Результат", Alert.AlertType.ERROR);
}
}
} }
private void refreshListBoxItems() { private void refreshListBoxItems() {

View File

@ -45,6 +45,8 @@ public interface ICollectionGenericObjects<T> {
*/ */
T get(int position); T get(int position);
void clear();
/** /**
* Получение типа коллекции. * Получение типа коллекции.
* *

View File

@ -39,6 +39,11 @@ public class ListGenericObjects<T> implements ICollectionGenericObjects<T> {
} }
} }
@Override
public void clear() {
collection.clear();
}
@Override @Override
public CollectionType getCollectionType() { public CollectionType getCollectionType() {
return CollectionType.List; return CollectionType.List;

View File

@ -1,5 +1,6 @@
package com.projectairfighter.collectiongenericobjects; package com.projectairfighter.collectiongenericobjects;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -40,6 +41,13 @@ public class MassiveGenericObjects<T> implements ICollectionGenericObjects<T> {
return null; return null;
} }
@Override
public void clear() {
if (collection != null) {
Arrays.fill(collection, null);
}
}
@Override @Override
public CollectionType getCollectionType() { public CollectionType getCollectionType() {
return CollectionType.Massive; return CollectionType.Massive;

View File

@ -125,6 +125,7 @@ public class StorageCollection<T extends DrawningWarPlane> {
/** /**
* Сохранение информации в файл * Сохранение информации в файл
*
* @param path путь к файлу * @param path путь к файлу
* @return результат сохранения * @return результат сохранения
*/ */
@ -175,6 +176,7 @@ public class StorageCollection<T extends DrawningWarPlane> {
/** /**
* Сохранение в файл по имени коллекции * Сохранение в файл по имени коллекции
*
* @param path путь к файлу * @param path путь к файлу
* @param collection название коллекции для сохранения * @param collection название коллекции для сохранения
* @return результат сохранения * @return результат сохранения
@ -226,6 +228,7 @@ public class StorageCollection<T extends DrawningWarPlane> {
/** /**
* Обработка данных в файле * Обработка данных в файле
*
* @param recordLine строка данных для обработки * @param recordLine строка данных для обработки
* @param keyValueSeparator разделитель ключа и значения * @param keyValueSeparator разделитель ключа и значения
* @param itemSeparator разделитель свойств * @param itemSeparator разделитель свойств
@ -238,8 +241,16 @@ public class StorageCollection<T extends DrawningWarPlane> {
return false; return false;
} }
ICollectionGenericObjects<T> collection;
if (storages.containsKey(record[0])) {
storages.get(record[0]).clear();
collection = storages.get(record[0]);
} else {
CollectionType collectionType = CollectionType.valueOf(record[1]); CollectionType collectionType = CollectionType.valueOf(record[1]);
ICollectionGenericObjects<T> collection = StorageCollection.createCollection(collectionType); collection = StorageCollection.createCollection(collectionType);
}
if (collection == null) { if (collection == null) {
return false; return false;
} }

View File

@ -6,71 +6,41 @@
<?import javafx.scene.layout.*?> <?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?> <?import javafx.scene.text.*?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="795.0" <AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="795.0" prefWidth="1292.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.projectairfighter.FormWarPlaneCollection">
prefWidth="1292.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" <SplitPane dividerPositions="0.811965811965812" layoutX="1.0" layoutY="27.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="765.0" prefWidth="1292.0">
fx:controller="com.projectairfighter.FormWarPlaneCollection">
<SplitPane dividerPositions="0.811965811965812" layoutX="1.0" layoutY="27.0" maxHeight="-Infinity"
maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="765.0" prefWidth="1292.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="698.0" prefWidth="965.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="698.0" prefWidth="965.0">
<Canvas fx:id="canvasWarPlane" height="763.0" width="1044.0" /> <Canvas fx:id="canvasWarPlane" height="763.0" width="1044.0" />
</AnchorPane> </AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="196.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="196.0">
<SplitPane dividerPositions="0.43889618922470436" orientation="VERTICAL" prefHeight="763.0" <SplitPane dividerPositions="0.43889618922470436" orientation="VERTICAL" prefHeight="763.0" prefWidth="237.0">
prefWidth="237.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Инструменты" AnchorPane.leftAnchor="14.0" <Text strokeType="OUTSIDE" strokeWidth="0.0" text="Инструменты" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="6.0" />
AnchorPane.topAnchor="6.0"/> <TextField fx:id="textFieldCollectionName" layoutX="6.0" layoutY="49.0" prefHeight="25.0" prefWidth="224.0" />
<TextField fx:id="textFieldCollectionName" layoutX="6.0" layoutY="49.0" prefHeight="25.0" <RadioButton fx:id="radioButtonMassive" layoutX="25.0" layoutY="77.0" mnemonicParsing="false" text="Массив">
prefWidth="224.0"/>
<RadioButton fx:id="radioButtonMassive" layoutX="25.0" layoutY="77.0" mnemonicParsing="false"
text="Массив">
<toggleGroup> <toggleGroup>
<ToggleGroup fx:id="toggle" /> <ToggleGroup fx:id="toggle" />
</toggleGroup> </toggleGroup>
</RadioButton> </RadioButton>
<RadioButton fx:id="radioButtonList" layoutX="141.0" layoutY="77.0" mnemonicParsing="false" <RadioButton fx:id="radioButtonList" layoutX="141.0" layoutY="77.0" mnemonicParsing="false" text="Список" toggleGroup="$toggle" />
text="Список" toggleGroup="$toggle"/> <Button layoutX="6.0" layoutY="101.0" mnemonicParsing="false" onAction="#buttonCollectionAdd" prefHeight="25.0" prefWidth="224.0" text="Добавить в коллекцию" />
<Button layoutX="6.0" layoutY="101.0" mnemonicParsing="false" onAction="#buttonCollectionAdd" <Button layoutX="6.0" layoutY="299.0" mnemonicParsing="false" onAction="#buttonCollectionDel" prefHeight="25.0" prefWidth="224.0" text="Удалить коллекцию" />
prefHeight="25.0" prefWidth="224.0" text="Добавить в коллекцию"/> <ListView fx:id="listViewCollection" layoutX="6.0" layoutY="136.0" prefHeight="155.0" prefWidth="224.0" />
<Button layoutX="6.0" layoutY="299.0" mnemonicParsing="false" onAction="#buttonCollectionDel"
prefHeight="25.0" prefWidth="224.0" text="Удалить коллекцию"/>
<ListView fx:id="listViewCollection" layoutX="6.0" layoutY="136.0" prefHeight="155.0"
prefWidth="224.0"/>
<Label layoutX="56.0" layoutY="26.0" text="Название коллекции" /> <Label layoutX="56.0" layoutY="26.0" text="Название коллекции" />
</AnchorPane> </AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<SplitPane fx:id="splitPane" dividerPositions="0.18691588785046728" layoutY="-8.0" <SplitPane fx:id="splitPane" dividerPositions="0.18691588785046728" layoutY="-8.0" orientation="VERTICAL" prefHeight="430.0" prefWidth="237.0">
orientation="VERTICAL" prefHeight="430.0" prefWidth="237.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="116.0" prefWidth="235.0"> <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="116.0" prefWidth="235.0">
<ComboBox fx:id="comboBox" layoutX="6.0" layoutY="15.0" <ComboBox fx:id="comboBox" layoutX="6.0" layoutY="15.0" onAction="#comboBoxSelectorCompany" prefHeight="25.0" prefWidth="224.0" />
onAction="#comboBoxSelectorCompany" prefHeight="25.0" <Button layoutX="6.0" layoutY="46.0" mnemonicParsing="false" onAction="#buttonCreateCompany" prefHeight="25.0" prefWidth="224.0" text="Создать компанию" />
prefWidth="224.0"/>
<Button layoutX="6.0" layoutY="46.0" mnemonicParsing="false"
onAction="#buttonCreateCompany" prefHeight="25.0" prefWidth="224.0"
text="Создать компанию"/>
</AnchorPane> </AnchorPane>
<AnchorPane disable="true" minHeight="0.0" minWidth="0.0" prefHeight="312.0" <AnchorPane disable="true" minHeight="0.0" minWidth="0.0" prefHeight="312.0" prefWidth="235.0">
prefWidth="235.0"> <Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="48.0" mnemonicParsing="false" onAction="#buttonGoToFormCreate" prefHeight="35.0" prefWidth="224.0" text="Добавление самолета" />
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="5.0" layoutY="12.0" <TextField fx:id="textBox" layoutX="6.0" layoutY="132.0" prefHeight="25.0" prefWidth="224.0" />
mnemonicParsing="false" onAction="#buttonGoToFormCreate" <Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="162.0" mnemonicParsing="false" onAction="#buttonRemovePlaneClicked" prefHeight="35.0" prefWidth="224.0" text="Удалить истребитель" />
prefHeight="35.0" prefWidth="224.0" text="Добавление самолета"/> <Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="215.0" mnemonicParsing="false" onAction="#buttonGoToCheck" prefHeight="35.0" prefWidth="224.0" text="Передать на тесты" />
<TextField fx:id="textBox" layoutX="6.0" layoutY="132.0" prefHeight="25.0" <Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="300.0" mnemonicParsing="false" onAction="#buttonRefresh" prefHeight="35.0" prefWidth="224.0" text="Обновить" />
prefWidth="224.0"/> <Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="90.0" mnemonicParsing="false" onAction="#buttonGoFormConstructor" prefHeight="35.0" prefWidth="224.0" text="Добавить через конструктор" />
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="162.0" <Button layoutX="6.0" layoutY="257.0" mnemonicParsing="false" onAction="#buttonGoToFormWithDeleteObject" prefHeight="35.0" text="Передать на тесты удаленный объект" />
mnemonicParsing="false" onAction="#buttonRemovePlaneClicked"
prefHeight="35.0" prefWidth="224.0" text="Удалить истребитель"/>
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="215.0"
mnemonicParsing="false" onAction="#buttonGoToCheck" prefHeight="35.0"
prefWidth="224.0" text="Передать на тесты"/>
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="300.0"
mnemonicParsing="false" onAction="#buttonRefresh" prefHeight="35.0"
prefWidth="224.0" text="Обновить"/>
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="90.0"
mnemonicParsing="false" onAction="#buttonGoFormConstructor"
prefHeight="35.0" prefWidth="224.0" text="Добавить через конструктор"/>
<Button layoutX="6.0" layoutY="257.0" mnemonicParsing="false"
onAction="#buttonGoToFormWithDeleteObject" prefHeight="35.0"
text="Передать на тесты удаленный объект"/>
</AnchorPane> </AnchorPane>
</SplitPane> </SplitPane>
</AnchorPane> </AnchorPane>
@ -89,6 +59,7 @@
<KeyCodeCombination alt="UP" code="L" control="DOWN" meta="UP" shift="UP" shortcut="UP" /> <KeyCodeCombination alt="UP" code="L" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator> </accelerator>
</MenuItem> </MenuItem>
<MenuItem mnemonicParsing="false" onAction="#loadToolStripMenuItemSelectedCompany" text="Сохранить выбранную компанию" />
</Menu> </Menu>
</MenuBar> </MenuBar>
</AnchorPane> </AnchorPane>