feat(ui): add collection sorting menu and sort method selection
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
package ru.project.model;
|
||||||
|
|
||||||
|
public enum SortMethod {
|
||||||
|
NORMAL,
|
||||||
|
PARITY
|
||||||
|
}
|
||||||
@@ -14,11 +14,13 @@ public class MainMenu extends BaseModalWindow {
|
|||||||
private final ActionListBox menu;
|
private final ActionListBox menu;
|
||||||
|
|
||||||
private final BaseModalWindow createCollectionMenu;
|
private final BaseModalWindow createCollectionMenu;
|
||||||
|
private final BaseModalWindow sortCollectionMenu;
|
||||||
|
|
||||||
public MainMenu(WindowBasedTextGUI gui, AppState state) {
|
public MainMenu(WindowBasedTextGUI gui, AppState state) {
|
||||||
super("Главное меню", gui);
|
super("Главное меню", gui);
|
||||||
|
|
||||||
this.createCollectionMenu = new CreateCollectionMenu(gui, state);
|
this.createCollectionMenu = new CreateCollectionMenu(gui, state);
|
||||||
|
this.sortCollectionMenu = new SortCollectionMenu(gui, state);
|
||||||
|
|
||||||
menu = new ActionListBox();
|
menu = new ActionListBox();
|
||||||
|
|
||||||
@@ -57,8 +59,7 @@ public class MainMenu extends BaseModalWindow {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sortCollection() {
|
private void sortCollection() {
|
||||||
// TODO
|
sortCollectionMenu.showModal();
|
||||||
MessageWindow.showModal(gui, "Не реализовано.");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void searchCollection() {
|
private void searchCollection() {
|
||||||
|
|||||||
@@ -0,0 +1,101 @@
|
|||||||
|
package ru.project.ui.menu;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.Button;
|
||||||
|
import com.googlecode.lanterna.gui2.Label;
|
||||||
|
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||||
|
import com.googlecode.lanterna.gui2.Panel;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import ru.project.model.AppState;
|
||||||
|
import ru.project.model.SortMethod;
|
||||||
|
import ru.project.ui.base.BaseModalWindow;
|
||||||
|
import ru.project.ui.window.MessageWindow;
|
||||||
|
import ru.project.ui.window.SortMethodSelectionWindow;
|
||||||
|
|
||||||
|
public class SortCollectionMenu extends BaseModalWindow {
|
||||||
|
|
||||||
|
private final AppState state;
|
||||||
|
|
||||||
|
private final Label sortMethodLabel;
|
||||||
|
private final SortMethodSelectionWindow sortMethodSelectionWindow;
|
||||||
|
|
||||||
|
private SortMethod selectedSortMethod;
|
||||||
|
|
||||||
|
public SortCollectionMenu(WindowBasedTextGUI gui, AppState state) {
|
||||||
|
|
||||||
|
super("Меню сортировки текущей коллекции", gui);
|
||||||
|
|
||||||
|
this.state = state;
|
||||||
|
this.selectedSortMethod = SortMethod.NORMAL;
|
||||||
|
|
||||||
|
Panel panel = new Panel();
|
||||||
|
panel.setLayoutManager(new LinearLayout());
|
||||||
|
|
||||||
|
this.sortMethodLabel = new Label("Способ сортировки: " + getSortMethodName(selectedSortMethod));
|
||||||
|
|
||||||
|
this.sortMethodSelectionWindow =
|
||||||
|
new SortMethodSelectionWindow(
|
||||||
|
gui,
|
||||||
|
sortMethod -> {
|
||||||
|
selectedSortMethod = sortMethod;
|
||||||
|
|
||||||
|
sortMethodLabel.setText(
|
||||||
|
"Способ сортировки: " + getSortMethodName(selectedSortMethod));
|
||||||
|
});
|
||||||
|
|
||||||
|
panel.addComponent(sortMethodLabel);
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Выбрать способ сортировки", this::selectSortMethod));
|
||||||
|
|
||||||
|
panel.addComponent(
|
||||||
|
new Button("Настроить текущий способ сортировки", this::setupCurrentSortMethod));
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Сортировать текущую коллекцию", this::sortCurrentCollection));
|
||||||
|
|
||||||
|
panel.addComponent(new Button("Выйти", this::close));
|
||||||
|
|
||||||
|
setComponent(panel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupCurrentSortMethod() {
|
||||||
|
MessageWindow.showModal(gui, "Настройка способа сортировки пока не реализована.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectSortMethod() {
|
||||||
|
sortMethodSelectionWindow.showModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sortCurrentCollection() {
|
||||||
|
if (state.getMainCollection() == null || state.getMainCollection().isEmpty()) {
|
||||||
|
|
||||||
|
MessageWindow.showModal(gui, "Текущая коллекция пуста.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (selectedSortMethod) {
|
||||||
|
case NORMAL:
|
||||||
|
sortNormally();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PARITY:
|
||||||
|
sortByParity();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sortNormally() {
|
||||||
|
// TODO
|
||||||
|
MessageWindow.showModal(gui, "Обычная сортировка не реализована.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sortByParity() {
|
||||||
|
// TODO
|
||||||
|
MessageWindow.showModal(gui, "Сортировка по чётности не реализована.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSortMethodName(SortMethod sortMethod) {
|
||||||
|
return switch (sortMethod) {
|
||||||
|
case NORMAL -> "Обычная сортировка";
|
||||||
|
case PARITY -> "Сортировка по чётности";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package ru.project.ui.window;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.ActionListBox;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import ru.project.model.SortMethod;
|
||||||
|
import ru.project.ui.base.BaseModalWindow;
|
||||||
|
|
||||||
|
public class SortMethodSelectionWindow extends BaseModalWindow {
|
||||||
|
|
||||||
|
private final Consumer<SortMethod> onSortMethodSelected;
|
||||||
|
|
||||||
|
public SortMethodSelectionWindow(
|
||||||
|
WindowBasedTextGUI gui, Consumer<SortMethod> onSortMethodSelected) {
|
||||||
|
|
||||||
|
super("Выбрать способ сортировки", gui);
|
||||||
|
|
||||||
|
this.onSortMethodSelected = onSortMethodSelected;
|
||||||
|
|
||||||
|
ActionListBox menu = new ActionListBox();
|
||||||
|
|
||||||
|
menu.addItem("Обычная сортировка", () -> selectSortMethod(SortMethod.NORMAL));
|
||||||
|
|
||||||
|
menu.addItem("Сортировка по чётности", () -> selectSortMethod(SortMethod.PARITY));
|
||||||
|
|
||||||
|
setComponent(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void selectSortMethod(SortMethod sortMethod) {
|
||||||
|
onSortMethodSelected.accept(sortMethod);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user