use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.
the class ExampleGui method createSelectBox.
private void createSelectBox() {
SelectBox<Object> selectBox = new SelectBox<>(20, 260, 100, 20);
selectBox.addElement(0.25f);
selectBox.addElement(0.5d);
selectBox.addElement(1);
selectBox.addElement("MyText");
selectBox.addElement(new Long(2L));
selectBox.setVisibleCount(7);
selectBox.setElementHeight(20);
selectBox.addSelectBoxChangeSelectionEventListener((SelectBoxChangeSelectionEventListener<Object>) event -> {
Dialog dialog = new Dialog("SelectBox clicked", 300, 100);
Label valueLabel = new Label("Value: " + event.getNewValue().toString(), 10, 10, 300, 20);
dialog.getContainer().add(valueLabel);
Label classLabel = new Label("Class: " + event.getNewValue().getClass().getName(), 10, 30, 300, 20);
dialog.getContainer().add(classLabel);
dialog.show(event.getFrame());
});
this.add(selectBox);
Button sbb = new Button("Add element", 130, 260, 70, 20);
sbb.getListenerMap().addListener(MouseClickEvent.class, (MouseClickEventListener) event -> {
if (event.getAction() == CLICK) {
selectBox.addElement("Dynamic#" + selectBox.getElements().size());
}
});
this.add(sbb);
}
use of com.spinyowl.legui.component.Button 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;
}
use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.
the class UpdateButtonStyleWidthListener method process.
/**
* Used to handle {@link ButtonContentChangeEvent} event.
*
* @param event event to handle.
*/
@Override
public void process(ButtonWidthChangeEvent event) {
Button button = event.getTargetComponent();
float textWidth = button.getTextState().getTextWidth();
button.getStyle().setWidth(textWidth);
}
use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.
the class FlatSelectBoxTheme method apply.
/**
* Used to apply theme only for component and not apply for child components.
*
* @param component component to apply theme.
*/
@Override
public void apply(T component) {
super.apply(component);
Button expandButton = component.getExpandButton();
expandButton.getStyle().setShadow(null);
expandButton.getStyle().getBackground().setColor(ColorConstants.transparent());
Button selectionButton = component.getSelectionButton();
selectionButton.getStyle().setShadow(null);
selectionButton.getStyle().getBackground().setColor(ColorConstants.transparent());
Icon collapseIcon = component.getCollapseIcon();
if (collapseIcon instanceof CharIcon) {
CharIcon bgIcon = (CharIcon) collapseIcon;
bgIcon.setColor(ColorUtil.oppositeBlackOrWhite(settings.backgroundColor()));
bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
}
Icon expandIcon = component.getExpandIcon();
if (expandIcon instanceof CharIcon) {
CharIcon bgIcon = (CharIcon) expandIcon;
bgIcon.setColor(ColorUtil.oppositeBlackOrWhite(settings.backgroundColor()));
bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
}
}
use of com.spinyowl.legui.component.Button in project legui by SpinyOwl.
the class FlatWidgetTheme method applyAll.
/**
* Used to apply theme for component and for all children of this component. Should be
* reimplemented for components that contains other child components.
*
* @param component component to apply theme.
*/
@Override
public void applyAll(T component) {
super.apply(component);
component.getStyle().getBackground().setColor(settings.backgroundColor());
Button minimizeButton = component.getMinimizeButton();
minimizeButton.getStyle().getBackground().setColor(settings.borderColor());
minimizeButton.getStyle().setShadow(null);
Button closeButton = component.getCloseButton();
closeButton.getStyle().getBackground().setColor(settings.borderColor());
closeButton.getStyle().setShadow(null);
Component titleContainer = component.getTitleContainer();
titleContainer.getStyle().getBackground().setColor(settings.borderColor());
Button resizeButton = component.getResizeButton();
resizeButton.getStyle().setBorder(null);
resizeButton.getStyle().getBackground().setColor(ColorConstants.transparent());
resizeButton.getHoveredStyle().getBackground().setColor(ColorConstants.transparent());
resizeButton.getPressedStyle().getBackground().setColor(ColorConstants.transparent());
CharIcon icon = new CharIcon(FontRegistry.MATERIAL_DESIGN_ICONS, '\uF45D');
icon.setHorizontalAlign(HorizontalAlign.RIGHT);
icon.setVerticalAlign(VerticalAlign.BOTTOM);
icon.setColor(settings.textColor());
resizeButton.getStyle().getBackground().setIcon(icon);
resizeButton.getStyle().setShadow(null);
component.getTitle().getStyle().setPadding(3f, 5f);
Icon closeIcon = component.getCloseIcon();
if (closeIcon instanceof CharIcon) {
CharIcon bgIcon = (CharIcon) closeIcon;
bgIcon.setColor(settings.textColor());
bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
}
Icon minimizeIcon = component.getMinimizeIcon();
if (minimizeIcon instanceof CharIcon) {
CharIcon bgIcon = (CharIcon) minimizeIcon;
bgIcon.setColor(settings.textColor());
bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
}
Icon maximizeIcon = component.getMaximizeIcon();
if (maximizeIcon instanceof CharIcon) {
CharIcon bgIcon = (CharIcon) maximizeIcon;
bgIcon.setColor(settings.textColor());
bgIcon.setHorizontalAlign(HorizontalAlign.CENTER);
bgIcon.setVerticalAlign(VerticalAlign.MIDDLE);
}
Themes.getDefaultTheme().applyAll(component.getContainer());
component.getContainer().getStyle().setShadow(null);
}
Aggregations