use of com.spinyowl.legui.component.TabbedPanel.Tab in project legui by SpinyOwl.
the class SingleClassExample method generateOnFly.
private static List<Component> generateOnFly() {
List<Component> list = new ArrayList<>();
Widget widget = new Widget(10, 50, 380, 240);
widget.getContainer().getStyle().setDisplay(FLEX);
widget.setDraggable(false);
TabbedPanel tabbedPanel = new TabbedPanel();
tabbedPanel.getStyle().setPosition(PositionType.RELATIVE);
tabbedPanel.getStyle().getFlexStyle().setFlexGrow(1);
tabbedPanel.getStyle().getFlexStyle().setFlexShrink(1);
tabbedPanel.getStyle().setMargin(10F);
tabbedPanel.getStyle().setBorder(new SimpleLineBorder(ColorConstants.black(), 1F));
widget.getContainer().add(tabbedPanel);
Tab tab1 = new Tab("Planes", new Label("Show all planes available"));
Tab tab2 = new Tab("Cars", new Label("Show all cars available"));
Tab tab3 = new Tab("Boats", new Label("Show all boats available"));
tabbedPanel.addTab(tab1);
tabbedPanel.addTab(tab2);
tabbedPanel.addTab(tab3);
AtomicInteger tabIdx = new AtomicInteger();
Button addTabButton = new Button("Add tab", 180, 10, 70, 30);
addTabButton.getListenerMap().addListener(MouseClickEvent.class, event -> {
if (MouseClickAction.CLICK.equals(event.getAction())) {
String tabName = "Tab #" + tabIdx.incrementAndGet();
Component tabComponent = new Panel();
tabComponent.getStyle().getBackground().setColor(ColorUtil.randomColor());
tabComponent.getStyle().setPadding(10F, 20F);
tabbedPanel.addTab(new Tab(tabName, tabComponent));
}
});
Button removeTabButton = new Button("Remove tab", 260, 10, 70, 30);
removeTabButton.getListenerMap().addListener(MouseClickEvent.class, event -> {
if (MouseClickAction.CLICK.equals(event.getAction()) && tabbedPanel.tabCount() > 0) {
tabbedPanel.removeTab(tabbedPanel.getCurrentTab());
}
});
Button changeStripPosition = new Button("Switch", 340, 10, 50, 30);
changeStripPosition.getListenerMap().addListener(MouseClickEvent.class, event -> {
if (MouseClickAction.CLICK.equals(event.getAction())) {
TabStripPosition current = tabbedPanel.getTabStripPosition();
if (TOP == current) {
tabbedPanel.setTabStripPosition(LEFT);
} else if (LEFT == current) {
tabbedPanel.setTabStripPosition(BOTTOM);
} else if (BOTTOM == current) {
tabbedPanel.setTabStripPosition(RIGHT);
} else {
tabbedPanel.setTabStripPosition(TOP);
}
}
});
widget.getTitle().getListenerMap().addListener(KeyEvent.class, event -> {
if (event.getAction() == GLFW_RELEASE) {
if (event.getKey() == GLFW_KEY_1) {
tabbedPanel.setTabWidth(30);
} else if (event.getKey() == GLFW_KEY_2) {
tabbedPanel.setTabHeight(120);
} else if (event.getKey() == GLFW_KEY_3) {
tabbedPanel.setTabStripPosition(LEFT);
} else if (event.getKey() == GLFW_KEY_4) {
tabbedPanel.setTabWidth(120);
} else if (event.getKey() == GLFW_KEY_5) {
tabbedPanel.setTabHeight(30);
} else if (event.getKey() == GLFW_KEY_6) {
tabbedPanel.setTabStripPosition(TOP);
}
}
});
list.add(addTabButton);
list.add(removeTabButton);
list.add(changeStripPosition);
list.add(widget);
return list;
}
Aggregations