Skip to content

Commit 2adf519

Browse files
Adds support for separate images for light and dark color schemes.
1 parent 146a514 commit 2adf519

File tree

17 files changed

+605
-194
lines changed

17 files changed

+605
-194
lines changed

changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## v5.0.0 (unreleased)
44

55
- structurizr-core: Removes support for deprecated enterprise and location concepts.
6-
- structurizr-core: Adds support for filtered deployment views (https://github.com/structurizr/java/issues/409).
6+
- structurizr-core: Adds support for filtered deployment views (https://github.com/structurizr/java/issues/409).
7+
- structurizr-core: Adds support for separate images for light and dark color schemes.
78
- structurizr-component: Fixes https://github.com/structurizr/java/issues/437 (Make ComponentFinder.run() not fail on empty Set<DiscoveredComponent>).
89
- structurizr-dsl: Adds support for `iconPosition` on element styles (options are `Top`, `Bottom`, `Left`).
910
- structurizr-dsl: Adds support for defining element and relationship styles for light and dark mode.

structurizr-core/src/main/java/com/structurizr/view/ImageView.java

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public final class ImageView extends View {
1313
private Element element;
1414
private String elementId;
1515
private String content;
16+
private String contentLight;
17+
private String contentDark;
1618
private String contentType;
1719

1820
ImageView() {
@@ -62,17 +64,58 @@ public String getContent() {
6264
return content;
6365
}
6466

67+
/**
68+
* Gets the content of this view (a URL or a data URI), for the light color scheme.
69+
*
70+
* @return the content, as a String
71+
*/
72+
public String getContentLight() {
73+
return contentLight;
74+
}
75+
76+
/**
77+
* Gets the content of this view (a URL or a data URI), for the dark color scheme.
78+
*
79+
* @return the content, as a String
80+
*/
81+
public String getContentDark() {
82+
return contentDark;
83+
}
84+
6585
/**
6686
* Sets the content of this image view, which needs to be a URL or a data URI.
6787
*
6888
* @param content the content of this view
6989
*/
7090
public void setContent(String content) {
91+
setContent(content, null);
92+
}
93+
94+
/**
95+
* Sets the content of this image view, which needs to be a URL or a data URI.
96+
*
97+
* @param content the content of this view
98+
*/
99+
public void setContent(String content, ColorScheme colorScheme) {
71100
if (StringUtils.isNullOrEmpty(content)) {
72-
this.content = null;
101+
if (colorScheme == ColorScheme.Dark) {
102+
this.contentDark = null;
103+
} else if (colorScheme == ColorScheme.Light) {
104+
this.contentLight = null;
105+
} else {
106+
this.content = null;
107+
}
73108
} else {
74109
ImageUtils.validateImage(content);
75-
this.content = content.trim();
110+
content = content.trim();
111+
112+
if (colorScheme == ColorScheme.Dark) {
113+
this.contentDark = content;
114+
} else if (colorScheme == ColorScheme.Light) {
115+
this.contentLight = content;
116+
} else {
117+
this.content = content;
118+
}
76119
}
77120
}
78121

@@ -99,4 +142,11 @@ public String getName() {
99142
return getTitle();
100143
}
101144

145+
public boolean hasContent() {
146+
return
147+
!StringUtils.isNullOrEmpty(content) ||
148+
!StringUtils.isNullOrEmpty(contentLight) ||
149+
!StringUtils.isNullOrEmpty(contentDark);
150+
}
151+
102152
}

structurizr-core/src/test/java/com/structurizr/view/ImageViewTests.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,31 @@ void construction_WhenAnElementIsSpecified() {
2727
assertEquals(softwareSystem.getId(), view.getElementId());
2828
}
2929

30+
@Test
31+
void hasContent_WhenNoContent() {
32+
ImageView view = views.createImageView("key");
33+
assertFalse(view.hasContent());
34+
}
35+
36+
@Test
37+
void hasContent_WhenContent() {
38+
ImageView view = views.createImageView("key");
39+
view.setContent("https://example.com/image.png");
40+
assertTrue(view.hasContent());
41+
}
42+
43+
@Test
44+
void hasContent_WhenContentLight() {
45+
ImageView view = views.createImageView("key");
46+
view.setContent("https://example.com/image.png", ColorScheme.Light);
47+
assertTrue(view.hasContent());
48+
}
49+
50+
@Test
51+
void hasContent_WhenContentDark() {
52+
ImageView view = views.createImageView("key");
53+
view.setContent("https://example.com/image.png", ColorScheme.Dark);
54+
assertTrue(view.hasContent());
55+
}
56+
3057
}

0 commit comments

Comments
 (0)