Skip to content

Commit

Permalink
minor SButtonGroup fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tbee committed Sep 13, 2023
1 parent 672ef2f commit 263b6e5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,18 @@ var sList = new SList<City>()
sList.selection$().bindTo(sTable.selection$());

// A tree is nothing more than a root and a way to get the children of a node.
var sTree = new STree<City>()
var sTree = STree.of(amsterdam)
.render(new CityFormat())
.root(amsterdam)
.childrenOf(City::getPartnerCities);

// A tree often shows different classes as nodes, so several children mappings are needed.
// The Formats registered in the FormatRegistry are used for rendering automatically.
var sTree = new STree<City>()
.root(cities) // a list as root is automatically handled
var sTree = STree.of(cities) // a list as root is automatically handled
.childrenOf(City.class, City::getStreets)
.childrenOf(Street.class, Street::getBuildings);

// SButtonGroup revolves around the associated value, not the button
var sButtonGroup = new SButtonGroup<Integer>()
var sButtonGroup = SButtonGroup.<Integer>of()
.add(1, new SToggleButton("winner"))
.add(2, new SToggleButton("2nd"))
.add(3, new SToggleButton("3rd"))
Expand All @@ -78,8 +76,8 @@ var sBorderPanel = SBorderPanel.of(new STable())
.west(new SomeNavigationMenu())
.east(new SomeContextLinks());

// MigLayout is used by Sway anyhow
var migPanel = new MigPanel().fill();
// MigLayout is used by Sway internally anyhow, so the user can use this great layout as well.
var migPanel = MigPanel.of().fill();
migPanel.addLabelAndField(someLabel, someField).growX();
migPanel.wrap();

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/org/tbee/sway/SButtonGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,14 @@ private AbstractButton getSelectedButton() {
// ===========================================================================================================================
// CONVENIENCE

static public <T> SButtonGroup of() {
static public <T> SButtonGroup<T> of() {
return new SButtonGroup<T>();
}

/**
* Create a buttongroup using a format and factory (supplier)
* @param format
* @param supplier
* @param supplier creates a button component for each value
* @param values
* @return
* @param <T>
Expand All @@ -223,7 +223,7 @@ public static <T> SButtonGroup<T> of(Format<T> format, Supplier<AbstractButton>

/**
* Create a buttongroup using FormatRegistry and factory (supplier)
* @param supplier
* @param supplier creates a button component for each value
* @param values, cannot be empty
* @return
* @param <T>
Expand All @@ -235,7 +235,7 @@ public static <T> SButtonGroup<T> of(Class<T> clazz, Supplier<AbstractButton> su

/**
* Create a buttongroup using FormatRegistry and factory (supplier)
* @param supplier
* @param supplier creates a button component for each value
* @param values, cannot be empty
* @return
* @param <T>
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/tbee/sway/SButtonGroupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void happyJToggleButtonTest() throws Exception {
// GIVEN
var ref = new AtomicReference<SButtonGroup<Integer>>();
construct(() -> {
var sButtonGroup = new SButtonGroup<Integer>() //
var sButtonGroup = SButtonGroup.<Integer>of() //
.add(1, new SToggleButton("1")) //
.add(2, new SToggleButton("2")) //
.add(3, new SToggleButton("3"));
Expand Down
6 changes: 2 additions & 4 deletions src/test/java/org/tbee/sway/STreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ public void selectionModeMultiple() throws Exception {
rome.addPartnerCity(paris);
var cities = List.of(amsterdam, berlin, rome, paris);
construct(() -> {
sTree = new STree<City>()
sTree = STree.of(amsterdam)
.name("tree")
.render(new CityFormat(cities))
.root(amsterdam)
.childrenOf(City::getPartnerCities)
.selectionMode(STree.SelectionMode.MULTIPLE);
return TestUtil.inJFrame(sTree, focusMeComponent());
Expand Down Expand Up @@ -80,9 +79,8 @@ public void multipleTypes() throws Exception {
var cities = List.of(amsterdam, berlin, rome, paris);

construct(() -> {
sTree = new STree<Object>()
sTree = STree.of(cities)
.name("tree")
.root(cities)
.childrenOf(City.class, City::getStreets)
.childrenOf(Street.class, Street::getBuildings)
.registerFormat(City.class, new CityFormat())
Expand Down

0 comments on commit 263b6e5

Please sign in to comment.