feat(view): add reusable base and action list views
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
package ru.project.view;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.ActionListBox;
|
||||||
|
|
||||||
|
public class ActionListView extends BaseView {
|
||||||
|
|
||||||
|
protected final ActionListBox actionList;
|
||||||
|
|
||||||
|
public ActionListView(String title) {
|
||||||
|
this(title, new ActionListBox());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ActionListView(String title, ActionListBox actionList) {
|
||||||
|
super(title, actionList);
|
||||||
|
this.actionList = actionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItem(String text, Runnable action) {
|
||||||
|
actionList.addItem(text, action);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package ru.project.view;
|
||||||
|
|
||||||
|
import com.googlecode.lanterna.gui2.BasicWindow;
|
||||||
|
import com.googlecode.lanterna.gui2.Component;
|
||||||
|
import com.googlecode.lanterna.gui2.WindowBasedTextGUI;
|
||||||
|
|
||||||
|
public abstract class BaseView {
|
||||||
|
|
||||||
|
protected final BasicWindow window;
|
||||||
|
|
||||||
|
protected BaseView(String title, Component mainComponent) {
|
||||||
|
window = new BasicWindow(title);
|
||||||
|
window.setComponent(mainComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show(WindowBasedTextGUI gui) {
|
||||||
|
gui.addWindowAndWait(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() {
|
||||||
|
window.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package ru.project.view;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class PanelView extends BaseView {
|
||||||
|
|
||||||
|
protected final Panel panel;
|
||||||
|
|
||||||
|
public PanelView(String title) {
|
||||||
|
this(new Panel(), title);
|
||||||
|
}
|
||||||
|
|
||||||
|
private PanelView(Panel panel, String title) {
|
||||||
|
super(title, panel);
|
||||||
|
|
||||||
|
this.panel = panel;
|
||||||
|
panel.setLayoutManager(new LinearLayout());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Button addButton(String text, Runnable action) {
|
||||||
|
Button button = new Button(text, action);
|
||||||
|
|
||||||
|
panel.addComponent(button);
|
||||||
|
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Label addLabel(String text) {
|
||||||
|
Label label = new Label(text);
|
||||||
|
|
||||||
|
panel.addComponent(label);
|
||||||
|
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextBox addTextBox() {
|
||||||
|
TextBox textBox = new TextBox();
|
||||||
|
|
||||||
|
panel.addComponent(textBox);
|
||||||
|
|
||||||
|
return textBox;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user