22
33import com .structurizr .model .*;
44import com .structurizr .util .StringUtils ;
5+ import com .structurizr .util .TagUtils ;
56
67import java .util .*;
78
@@ -88,13 +89,14 @@ public RelationshipStyle addRelationshipStyle(String tag) {
8889 *
8990 *
9091 * @param tag the tag (a String)
91- * @return an ElementStyle instance
92+ * @return an ElementStyle instance, or null if there is no style for the given tag
9293 */
9394 public ElementStyle findElementStyle (String tag ) {
9495 if (tag == null ) {
9596 return null ;
9697 }
9798
99+ boolean elementStyleExists = false ;
98100 tag = tag .trim ();
99101 ElementStyle style = new ElementStyle (tag );
100102
@@ -106,11 +108,16 @@ public ElementStyle findElementStyle(String tag) {
106108
107109 for (ElementStyle elementStyle : elementStyles ) {
108110 if (elementStyle != null && elementStyle .getTag ().equals (tag )) {
111+ elementStyleExists = true ;
109112 style .copyFrom (elementStyle );
110113 }
111114 }
112115
113- return style ;
116+ if (elementStyleExists ) {
117+ return style ;
118+ } else {
119+ return null ;
120+ }
114121 }
115122
116123 /**
@@ -119,13 +126,14 @@ public ElementStyle findElementStyle(String tag) {
119126 *
120127 *
121128 * @param tag the tag (a String)
122- * @return a RelationshipStyle instance
129+ * @return a RelationshipStyle instance, or null if there is no style for the given tag
123130 */
124131 public RelationshipStyle findRelationshipStyle (String tag ) {
125132 if (tag == null ) {
126133 return null ;
127134 }
128135
136+ boolean relationshipStyleExists = false ;
129137 tag = tag .trim ();
130138 RelationshipStyle style = new RelationshipStyle (tag );
131139
@@ -138,10 +146,15 @@ public RelationshipStyle findRelationshipStyle(String tag) {
138146 for (RelationshipStyle relationshipStyle : relationshipStyles ) {
139147 if (relationshipStyle != null && relationshipStyle .getTag ().equals (tag )) {
140148 style .copyFrom (relationshipStyle );
149+ relationshipStyleExists = true ;
141150 }
142151 }
143152
144- return style ;
153+ if (relationshipStyleExists ) {
154+ return style ;
155+ } else {
156+ return null ;
157+ }
145158 }
146159
147160 /**
@@ -155,7 +168,7 @@ public RelationshipStyle findRelationshipStyle(String tag) {
155168 * @return an ElementStyle object
156169 */
157170 public ElementStyle findElementStyle (Element element ) {
158- ElementStyle style = new ElementStyle ("" ).background ("#dddddd" ).color ("#000000" ).shape (Shape .Box ).fontSize (24 ).border (Border .Solid ).opacity (100 ).metadata (true ).description (true );
171+ ElementStyle style = new ElementStyle (Tags . ELEMENT ).background ("#dddddd" ).color ("#000000" ).shape (Shape .Box ).fontSize (24 ).border (Border .Solid ).opacity (100 ).metadata (true ).description (true );
159172
160173 if (element instanceof DeploymentNode ) {
161174 style .setBackground ("#ffffff" );
@@ -164,6 +177,8 @@ public ElementStyle findElementStyle(Element element) {
164177 }
165178
166179 if (element != null ) {
180+ Set <String > tagsUsedToComposeStyle = new LinkedHashSet <>();
181+ tagsUsedToComposeStyle .add (Tags .ELEMENT );
167182 String tags = element .getTags ();
168183
169184 if (element instanceof SoftwareSystemInstance ) {
@@ -179,9 +194,12 @@ public ElementStyle findElementStyle(Element element) {
179194 ElementStyle elementStyle = findElementStyle (tag );
180195 if (elementStyle != null ) {
181196 style .copyFrom (elementStyle );
197+ tagsUsedToComposeStyle .add (elementStyle .getTag ());
182198 }
183199 }
184200 }
201+
202+ style .setTag (TagUtils .toString (tagsUsedToComposeStyle ));
185203 }
186204
187205 if (style .getWidth () == null ) {
@@ -219,9 +237,11 @@ public ElementStyle findElementStyle(Element element) {
219237 * @return a RelationshipStyle object
220238 */
221239 public RelationshipStyle findRelationshipStyle (Relationship relationship ) {
222- RelationshipStyle style = new RelationshipStyle ("" ).thickness (2 ).color ("#707070" ).dashed (true ).routing (Routing .Direct ).fontSize (24 ).width (200 ).position (50 ).opacity (100 );
240+ RelationshipStyle style = new RelationshipStyle (Tags . RELATIONSHIP ).thickness (2 ).color ("#707070" ).dashed (true ).routing (Routing .Direct ).fontSize (24 ).width (200 ).position (50 ).opacity (100 );
223241
224242 if (relationship != null ) {
243+ Set <String > tagsUsedToComposeStyle = new LinkedHashSet <>();
244+ tagsUsedToComposeStyle .add (Tags .RELATIONSHIP );
225245 String tags = relationship .getTags ();
226246 String linkedRelationshipId = relationship .getLinkedRelationshipId ();
227247
@@ -239,9 +259,12 @@ public RelationshipStyle findRelationshipStyle(Relationship relationship) {
239259 RelationshipStyle relationshipStyle = findRelationshipStyle (tag );
240260 if (relationshipStyle != null ) {
241261 style .copyFrom (relationshipStyle );
262+ tagsUsedToComposeStyle .add (relationshipStyle .getTag ());
242263 }
243264 }
244265 }
266+
267+ style .setTag (TagUtils .toString (tagsUsedToComposeStyle ));
245268 }
246269
247270 return style ;
0 commit comments