diff --git a/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/BoxView.java b/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/BoxView.java index f17c2f09..c436a545 100644 --- a/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/BoxView.java +++ b/spring-shell-core/src/main/java/org/springframework/shell/component/view/control/BoxView.java @@ -48,6 +48,8 @@ public class BoxView extends AbstractView { private Integer backgroundColor = -1; private int titleColor = -1; private int titleStyle = -1; + private int focusedTitleColor = -1; + private int focusedTitleStyle = -1; private HorizontalAlign titleAlign; @Override @@ -149,6 +151,26 @@ public class BoxView extends AbstractView { this.titleStyle = titleStyle; } + /** + * Sets a focused title color. Takes precedence set from + * {@link #setTitleColor(int)}. + * + * @param focusedTitleColor the title color + */ + public void setFocusedTitleColor(int focusedTitleColor) { + this.focusedTitleColor = focusedTitleColor; + } + + /** + * Sets a focused title style. Takes precedence set from + * {@link #setTitleStyle(int)}. + * + * @param focusedTitleStyle the title style + */ + public void setFocusedTitleStyle(int focusedTitleStyle) { + this.focusedTitleStyle = focusedTitleStyle; + } + /** * Sets a title align. * @@ -180,12 +202,22 @@ public class BoxView extends AbstractView { screen.writerBuilder().layer(getLayer()).build().border(rect.x(), rect.y(), rect.width(), rect.height()); if (StringUtils.hasText(title)) { Rectangle r = new Rectangle(rect.x() + 1, rect.y(), rect.width() - 2, 1); - if (titleColor > -1) { - screen.writerBuilder().layer(getLayer()).color(titleColor).style(titleStyle).build().text(title, r, titleAlign, VerticalAlign.TOP); + + int color = -1; + int style = -1; + if (hasFocus()) { + color = focusedTitleColor; + style = focusedTitleStyle; } - else { - screen.writerBuilder().layer(getLayer()).build().text(title, r, titleAlign, VerticalAlign.TOP); + if (color < 0) { + color = titleColor; } + if (style < 0) { + style = titleStyle; + } + + screen.writerBuilder().layer(getLayer()).color(color).style(style).build().text(title, r, titleAlign, + VerticalAlign.TOP); } } if (getDrawFunction() != null) { diff --git a/spring-shell-samples/spring-shell-sample-catalog/src/main/java/org/springframework/shell/samples/catalog/Catalog.java b/spring-shell-samples/spring-shell-sample-catalog/src/main/java/org/springframework/shell/samples/catalog/Catalog.java index 60b94589..a3047dae 100644 --- a/spring-shell-samples/spring-shell-sample-catalog/src/main/java/org/springframework/shell/samples/catalog/Catalog.java +++ b/spring-shell-samples/spring-shell-sample-catalog/src/main/java/org/springframework/shell/samples/catalog/Catalog.java @@ -47,6 +47,7 @@ import org.springframework.shell.component.view.geom.Rectangle; import org.springframework.shell.component.view.message.ShellMessageBuilder; import org.springframework.shell.component.view.screen.Screen; import org.springframework.shell.component.view.screen.Screen.Writer; +import org.springframework.shell.component.view.screen.ScreenItem; import org.springframework.shell.samples.catalog.scenario.Scenario; import org.springframework.shell.samples.catalog.scenario.ScenarioComponent; import org.springframework.util.ObjectUtils; @@ -196,6 +197,7 @@ public class Catalog { List items = List.copyOf(categoryMap.keySet()); categories.setItems(items); categories.setTitle("Categories"); + categories.setFocusedTitleStyle(ScreenItem.STYLE_BOLD); categories.setShowBorder(true); return categories; } @@ -215,6 +217,7 @@ public class Catalog { ListView scenarios = new ListView<>(); scenarios.setEventLoop(eventLoop); scenarios.setTitle("Scenarios"); + scenarios.setFocusedTitleStyle(ScreenItem.STYLE_BOLD); scenarios.setShowBorder(true); scenarios.setCellFactory(list -> new ScenarioListCell()); return scenarios;