This commit is contained in:
parent
ebf5c1d39e
commit
74abba5e80
3 changed files with 67 additions and 13 deletions
|
@ -1,7 +1,7 @@
|
||||||
package de.com.baseband.clientboot;
|
package de.com.baseband.clientboot;
|
||||||
|
|
||||||
class CBCallbackContainer {
|
public class CBCallbackContainer {
|
||||||
final String name;
|
public String name;
|
||||||
final CBCallback callback;
|
final CBCallback callback;
|
||||||
|
|
||||||
CBCallbackContainer(String name, CBCallback callback) {
|
CBCallbackContainer(String name, CBCallback callback) {
|
||||||
|
|
|
@ -47,9 +47,34 @@ public class CBWindow extends JFrame implements WindowListener {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void checkSelected(boolean wasMovingUp) {
|
||||||
public void setVisible(boolean b) {
|
List<CBCallbackContainer> list = options.peek();
|
||||||
super.setVisible(b);
|
if(list.isEmpty()) {
|
||||||
|
selected = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int min = Integer.MAX_VALUE;
|
||||||
|
int max = 0;
|
||||||
|
while (list.get(selected).callback == null) {
|
||||||
|
if(wasMovingUp) {
|
||||||
|
if(selected-- == 0) {
|
||||||
|
selected++;
|
||||||
|
wasMovingUp = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(selected++ == list.size()) {
|
||||||
|
selected--;
|
||||||
|
wasMovingUp = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
min = Math.min(selected, min);
|
||||||
|
max = Math.max(selected, max);
|
||||||
|
if(min == 0 && max == list.size()) {
|
||||||
|
selected = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -112,13 +137,18 @@ public class CBWindow extends JFrame implements WindowListener {
|
||||||
|
|
||||||
List<CBCallbackContainer> list = options.peek();
|
List<CBCallbackContainer> list = options.peek();
|
||||||
for (int i = 0; i < list.size(); i++) {
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
CBCallbackContainer item = list.get(i);
|
||||||
|
if(item.callback != null) {
|
||||||
if (justRanSomething.isLocked() && i == selected) {
|
if (justRanSomething.isLocked() && i == selected) {
|
||||||
g.setColor(new Color(0xee00ee));
|
g.setColor(new Color(0xee00ee));
|
||||||
g.drawString("> "+ list.get(i).name, 7, y += 2 + 15);
|
g.drawString("> " + item.name, 7, y += 2 + 15);
|
||||||
g.setColor(new Color(0xcc00cc));
|
g.setColor(new Color(0xcc00cc));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
g.drawString((i == selected ? "> " : "") + list.get(i).name, 5, y += 2 + 15);
|
g.drawString((i == selected ? "> " : "") + item.name, 5, y += 2 + 15);
|
||||||
|
} else {
|
||||||
|
g.drawString(item.name, 3, y += 2 + 15);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,13 +181,20 @@ public class CBWindow extends JFrame implements WindowListener {
|
||||||
justRanSomething.unlock();
|
justRanSomething.unlock();
|
||||||
if(e.getKeyCode() == KeyEvent.VK_DOWN && options.peek().size() > selected + 1) {
|
if(e.getKeyCode() == KeyEvent.VK_DOWN && options.peek().size() > selected + 1) {
|
||||||
selected++;
|
selected++;
|
||||||
|
checkSelected(false);
|
||||||
}
|
}
|
||||||
if(e.getKeyCode() == KeyEvent.VK_UP && selected != 0) {
|
if(e.getKeyCode() == KeyEvent.VK_UP && selected > 0) {
|
||||||
selected--;
|
selected--;
|
||||||
|
checkSelected(true);
|
||||||
}
|
}
|
||||||
if(e.getKeyCode() == KeyEvent.VK_ENTER) {
|
if(e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||||
justRanSomething.lock(200);
|
justRanSomething.lock(200);
|
||||||
options.peek().get(selected).callback.run(parent);
|
CBCallback cb = options.peek().get(selected).callback;
|
||||||
|
if(cb != null)
|
||||||
|
cb.run(parent);
|
||||||
|
}
|
||||||
|
if(e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
||||||
|
parent.back();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,14 +3,17 @@ package de.com.baseband.clientboot;
|
||||||
import de.tudbut.parsing.TCN;
|
import de.tudbut.parsing.TCN;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ClientBoot {
|
public class ClientBoot {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new ClientBoot("ClientBoot Test")
|
new ClientBoot("ClientBoot Test")
|
||||||
.option("Print something", x -> x.newScreen()
|
.option("Print something", x -> x.newScreen()
|
||||||
|
.label("Here, you can print stuff!")
|
||||||
.option("Hello!", x1 -> System.out.println("Hello!"))
|
.option("Hello!", x1 -> System.out.println("Hello!"))
|
||||||
.option("Hellorld!", x1 -> System.out.println("Hellorld!"))
|
.option("Hellorld!", x1 -> System.out.println("Hellorld!"))
|
||||||
|
.label("Here, you can exit!")
|
||||||
.option("Back", ClientBoot::back))
|
.option("Back", ClientBoot::back))
|
||||||
.option("Exit", ClientBoot::finish)
|
.option("Exit", ClientBoot::finish)
|
||||||
.show();
|
.show();
|
||||||
|
@ -31,6 +34,14 @@ public class ClientBoot {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ClientBoot label(String name) {
|
||||||
|
List<CBCallbackContainer> list = window.options.peek();
|
||||||
|
if(window.selected == list.size())
|
||||||
|
window.selected++;
|
||||||
|
list.add(new CBCallbackContainer(name, null));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ClientBoot option(String name, CBCallback callback) {
|
public ClientBoot option(String name, CBCallback callback) {
|
||||||
window.options.peek().add(new CBCallbackContainer(name, callback));
|
window.options.peek().add(new CBCallbackContainer(name, callback));
|
||||||
return this;
|
return this;
|
||||||
|
@ -38,6 +49,8 @@ public class ClientBoot {
|
||||||
|
|
||||||
public void back() {
|
public void back() {
|
||||||
window.options.pop();
|
window.options.pop();
|
||||||
|
if(window.options.isEmpty())
|
||||||
|
finish();
|
||||||
window.selected = 0;
|
window.selected = 0;
|
||||||
window.justRanSomething.unlock();
|
window.justRanSomething.unlock();
|
||||||
}
|
}
|
||||||
|
@ -46,6 +59,10 @@ public class ClientBoot {
|
||||||
window.windowClosing(null);
|
window.windowClosing(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CBCallbackContainer currentOption() {
|
||||||
|
return window.options.peek().get(window.selected);
|
||||||
|
}
|
||||||
|
|
||||||
public TCN show() {
|
public TCN show() {
|
||||||
window.waitForClose();
|
window.waitForClose();
|
||||||
return data;
|
return data;
|
||||||
|
|
Loading…
Add table
Reference in a new issue