refactor: migrate UI from views and presenters to windows and menus
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package ru.project.ui.window;
|
||||
|
||||
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.TextBox;
|
||||
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||
import java.util.function.IntConsumer;
|
||||
import ru.project.ui.base.BaseWindow;
|
||||
|
||||
public class CollectionSizeInputWindow extends BaseWindow {
|
||||
|
||||
private final TextBox sizeTextBox;
|
||||
private final IntConsumer onSizeEntered;
|
||||
|
||||
public CollectionSizeInputWindow(WindowBasedTextGUI gui, IntConsumer onSizeEntered) {
|
||||
|
||||
super("Задать размер", gui);
|
||||
|
||||
this.onSizeEntered = onSizeEntered;
|
||||
|
||||
Panel panel = new Panel();
|
||||
panel.setLayoutManager(new LinearLayout());
|
||||
|
||||
panel.addComponent(new Label("Введите размер:"));
|
||||
|
||||
sizeTextBox = new TextBox();
|
||||
panel.addComponent(sizeTextBox);
|
||||
|
||||
panel.addComponent(new Button("Подтвердить", this::handleSizeEntered));
|
||||
|
||||
panel.addComponent(new Button("Выйти", this::close));
|
||||
|
||||
setComponent(panel);
|
||||
}
|
||||
|
||||
private void handleSizeEntered() {
|
||||
try {
|
||||
int size = Integer.parseInt(sizeTextBox.getText().trim());
|
||||
|
||||
if (size <= 0) {
|
||||
MessageWindow.create(gui, "Размер должен быть больше 0.");
|
||||
return;
|
||||
}
|
||||
|
||||
close();
|
||||
onSizeEntered.accept(size);
|
||||
|
||||
} catch (NumberFormatException e) {
|
||||
MessageWindow.create(gui, "Введите целое число.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package ru.project.ui.window;
|
||||
|
||||
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.collection.MyList;
|
||||
import ru.project.model.AppState;
|
||||
import ru.project.student.Student;
|
||||
import ru.project.ui.base.BaseWindow;
|
||||
|
||||
public class CurrentCollectionWindow extends BaseWindow {
|
||||
|
||||
public CurrentCollectionWindow(WindowBasedTextGUI gui, AppState state) {
|
||||
super("Текущая коллекция", gui);
|
||||
|
||||
Panel panel = new Panel();
|
||||
panel.setLayoutManager(new LinearLayout());
|
||||
|
||||
MyList<Student> collection = state.getCollection();
|
||||
|
||||
if (collection == null || collection.isEmpty()) {
|
||||
panel.addComponent(new Label("Текущая коллекция пуста."));
|
||||
} else {
|
||||
addStudents(panel, collection);
|
||||
}
|
||||
|
||||
panel.addComponent(new Button("Выйти", this::close));
|
||||
|
||||
setComponent(panel);
|
||||
}
|
||||
|
||||
private void addStudents(Panel panel, MyList<Student> collection) {
|
||||
for (int i = 0; i < collection.size(); i++) {
|
||||
Student student = collection.get(i);
|
||||
|
||||
panel.addComponent(new Label((i + 1) + ". " + student));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package ru.project.ui.window;
|
||||
|
||||
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.ui.base.BaseWindow;
|
||||
|
||||
public class MessageWindow extends BaseWindow {
|
||||
|
||||
public MessageWindow(WindowBasedTextGUI gui, String message) {
|
||||
super("Информация", gui);
|
||||
|
||||
Panel panel = new Panel();
|
||||
panel.setLayoutManager(new LinearLayout());
|
||||
|
||||
panel.addComponent(new Label(message));
|
||||
|
||||
panel.addComponent(new Button("OK", this::close));
|
||||
|
||||
setComponent(panel);
|
||||
}
|
||||
|
||||
public static void create(WindowBasedTextGUI gui, String message) {
|
||||
new MessageWindow(gui, message).show();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user