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

@ -2,77 +2,80 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.projectairfighter</groupId>
<artifactId>ProjectAirFighter</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ProjectAirFighter</name>
<groupId>com.example.projectairfighter</groupId>
<artifactId>ProjectAirFighter</artifactId>
<version>1.0-SNAPSHOT</version>
<name>ProjectAirFighter</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version> </properties>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19.0.2</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency> </dependencies>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19.0.2</version>
</dependency>
<dependency>
<groupId>org.controlsfx</groupId>
<artifactId>controlsfx</artifactId>
<version>11.1.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.projectairfighter/com.example.projectairfighter.HelloApplication</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.projectairfighter/com.example.projectairfighter.HelloApplication
</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -238,63 +238,21 @@ public class FormWarPlaneCollection extends Application implements Initializable
*/
@FXML
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();
dialog.setResizable(false);
dialog.initOwner(mainStage);
dialog.initModality(Modality.APPLICATION_MODAL); // Блокируем доступ к основному окну
dialog.setTitle("Выберите коллекцию для сохранения");
VBox layout = new VBox(10);
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);
File selectedFile = fileChooser.showSaveDialog(null);
if (selectedFile != null) {
boolean success = storageCollection.saveData(selectedFile.getAbsolutePath());
if (success) {
showAlert("Сохранение прошло успешно", "Результат", Alert.AlertType.INFORMATION);
} else {
showAlert("Не сохранилось", "Результат", Alert.AlertType.ERROR);
}
}
RadioButton allCollections = new RadioButton("Все коллекции");
Button submitButton = new Button("Сохранить");
allCollections.setToggleGroup(toggleGroup);
layout.getChildren().addAll(allCollections, submitButton);
submitButton.setOnAction(e -> {
if (toggleGroup.getSelectedToggle() == null || storageCollection.keys().isEmpty()) {
showError("Не выбрана коллекция или выбранная коллекция пуста");
return;
}
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Сохранить данные");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("Text Files (*.txt)", "*.txt")
);
File selectedFile = fileChooser.showSaveDialog(null);
if (selectedFile != null) {
boolean success;
RadioButton selectedRadioButton = (RadioButton) toggleGroup.getSelectedToggle();
if (selectedRadioButton.getText().equals("Все коллекции"))
success = storageCollection.saveData(selectedFile.getAbsolutePath());
else
success = storageCollection.saveData(selectedFile.getAbsolutePath(), selectedRadioButton.getText());
if (success) {
showAlert("Сохранение прошло успешно", "Результат", Alert.AlertType.INFORMATION);
} else {
showAlert("Не сохранилось", "Результат", Alert.AlertType.ERROR);
}
}
dialog.close(); // Закрыть диалог после сохранения
});
Scene scene = new Scene(layout, 250, 200);
dialog.setScene(scene);
dialog.showAndWait(); // Показываем диалог и ждем закрытия
}
/**
@ -305,11 +263,9 @@ public class FormWarPlaneCollection extends Application implements Initializable
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());
@ -323,6 +279,30 @@ public class FormWarPlaneCollection extends Application implements Initializable
}
}
@FXML
private void loadToolStripMenuItemSelectedCompany() {
if (listViewCollection.getSelectionModel().getSelectedIndex() < 0 || listViewCollection.getSelectionModel().getSelectedItem() == null) {
showAlert("Коллекция не выбрана");
return;
}
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Сохранить данные");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("Text Files (*.txt)", "*.txt")
);
File selectedFile = fileChooser.showSaveDialog(null);
if (selectedFile != null) {
boolean success = storageCollection.saveData(selectedFile.getAbsolutePath(), listViewCollection.getSelectionModel().getSelectedItem());
if (success) {
showAlert("Сохранение прошло успешно", "Результат", Alert.AlertType.INFORMATION);
} else {
showAlert("Не сохранилось", "Результат", Alert.AlertType.ERROR);
}
}
}
private void refreshListBoxItems() {
listViewCollection.getItems().clear();
for (String colName : storageCollection.keys()) {

View File

@ -45,6 +45,8 @@ public interface ICollectionGenericObjects<T> {
*/
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
public CollectionType getCollectionType() {
return CollectionType.List;

View File

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

View File

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

View File

@ -6,71 +6,41 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<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">
<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 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">
<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">
<Canvas fx:id="canvasWarPlane" height="763.0" width="1044.0"/>
<Canvas fx:id="canvasWarPlane" height="763.0" width="1044.0" />
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="196.0">
<SplitPane dividerPositions="0.43889618922470436" orientation="VERTICAL" prefHeight="763.0"
prefWidth="237.0">
<SplitPane dividerPositions="0.43889618922470436" orientation="VERTICAL" prefHeight="763.0" prefWidth="237.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"
AnchorPane.topAnchor="6.0"/>
<TextField fx:id="textFieldCollectionName" layoutX="6.0" layoutY="49.0" prefHeight="25.0"
prefWidth="224.0"/>
<RadioButton fx:id="radioButtonMassive" layoutX="25.0" layoutY="77.0" mnemonicParsing="false"
text="Массив">
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Инструменты" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="6.0" />
<TextField fx:id="textFieldCollectionName" layoutX="6.0" layoutY="49.0" prefHeight="25.0" prefWidth="224.0" />
<RadioButton fx:id="radioButtonMassive" layoutX="25.0" layoutY="77.0" mnemonicParsing="false" text="Массив">
<toggleGroup>
<ToggleGroup fx:id="toggle"/>
<ToggleGroup fx:id="toggle" />
</toggleGroup>
</RadioButton>
<RadioButton fx:id="radioButtonList" layoutX="141.0" layoutY="77.0" mnemonicParsing="false"
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="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="Название коллекции"/>
<RadioButton fx:id="radioButtonList" layoutX="141.0" layoutY="77.0" mnemonicParsing="false" 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="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="Название коллекции" />
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0">
<SplitPane fx:id="splitPane" dividerPositions="0.18691588785046728" layoutY="-8.0"
orientation="VERTICAL" prefHeight="430.0" prefWidth="237.0">
<SplitPane fx:id="splitPane" dividerPositions="0.18691588785046728" layoutY="-8.0" orientation="VERTICAL" prefHeight="430.0" prefWidth="237.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="116.0" prefWidth="235.0">
<ComboBox fx:id="comboBox" layoutX="6.0" layoutY="15.0"
onAction="#comboBoxSelectorCompany" prefHeight="25.0"
prefWidth="224.0"/>
<Button layoutX="6.0" layoutY="46.0" mnemonicParsing="false"
onAction="#buttonCreateCompany" prefHeight="25.0" prefWidth="224.0"
text="Создать компанию"/>
<ComboBox fx:id="comboBox" layoutX="6.0" layoutY="15.0" onAction="#comboBoxSelectorCompany" prefHeight="25.0" prefWidth="224.0" />
<Button layoutX="6.0" layoutY="46.0" mnemonicParsing="false" onAction="#buttonCreateCompany" prefHeight="25.0" prefWidth="224.0" text="Создать компанию" />
</AnchorPane>
<AnchorPane disable="true" minHeight="0.0" minWidth="0.0" prefHeight="312.0"
prefWidth="235.0">
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="5.0" layoutY="12.0"
mnemonicParsing="false" onAction="#buttonGoToFormCreate"
prefHeight="35.0" prefWidth="224.0" text="Добавление самолета"/>
<TextField fx:id="textBox" layoutX="6.0" layoutY="132.0" prefHeight="25.0"
prefWidth="224.0"/>
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="162.0"
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 disable="true" minHeight="0.0" minWidth="0.0" prefHeight="312.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="Добавление самолета" />
<TextField fx:id="textBox" layoutX="6.0" layoutY="132.0" prefHeight="25.0" prefWidth="224.0" />
<Button alignment="CENTER" contentDisplay="CENTER" layoutX="6.0" layoutY="162.0" 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>
</SplitPane>
</AnchorPane>
@ -81,14 +51,15 @@
<Menu mnemonicParsing="false" text="Файл">
<MenuItem mnemonicParsing="false" onAction="#saveToolStripMenuItem" text="Сохранить">
<accelerator>
<KeyCodeCombination alt="UP" code="S" control="DOWN" meta="UP" shift="UP" shortcut="UP"/>
<KeyCodeCombination alt="UP" code="S" control="DOWN" meta="UP" shift="UP" shortcut="UP" />
</accelerator>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#loadToolStripMenuItem" text="Загрузить">
<accelerator>
<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>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#loadToolStripMenuItemSelectedCompany" text="Сохранить выбранную компанию" />
</Menu>
</MenuBar>
</AnchorPane>