11package com .forsrc .gwt .client .application .plantuml ;
22
3+ import com .google .gwt .dom .client .Document ;
4+ import com .google .gwt .http .client .URL ;
5+ import com .google .gwt .resources .client .ImageResource ;
6+ import com .google .gwt .safehtml .shared .SafeHtmlUtils ;
37import com .google .gwt .safehtml .shared .UriUtils ;
8+ import com .google .gwt .user .client .Window ;
9+ import com .google .gwt .user .client .ui .HTML ;
10+ import com .google .gwt .user .client .ui .HasText ;
11+ import com .google .gwt .util .tools .shared .StringUtils ;
412
5- import gwt .material .design .client .ui .MaterialImage ;
13+ import gwt .material .design .client .base .HasImage ;
14+ import gwt .material .design .client .base .MaterialWidget ;
15+ import gwt .material .design .client .base .mixin .ImageMixin ;
16+ import gwt .material .design .client .constants .CssName ;
617
7- public class PlantumlMaterialImage extends MaterialImage {
18+ public class PlantumlMaterialImage extends MaterialWidget implements HasText , HasImage {
819
20+ private ImageMixin <PlantumlMaterialImage > imageMixin ;
921 private String src ;
1022 private String uml ;
23+
24+ public PlantumlMaterialImage () {
25+ super (Document .get ().createImageElement (), CssName .RESPONSIVE_IMG );
26+ }
1127
1228 @ Override
1329 protected void onLoad () {
@@ -16,10 +32,11 @@ protected void onLoad() {
1632 if (uml == null ) {
1733 return ;
1834 }
19- // String url = getSrc() + uml;
20- String url = getSrc () + UriUtils . encode ( param ( uml ) );
35+ //String url = getSrc() + uml;
36+ String url = getSrc () + URL . encodeQueryString ( uml );
2137 this .getElement ().setAttribute ("src" , url );
2238 // setUrl(url);
39+ //getImageMixin().setUrl(url);
2340 }
2441
2542 public void setSrc (String src ) {
@@ -30,11 +47,40 @@ public String getSrc() {
3047 return src ;
3148 }
3249
33- public void setUml (String uml ) {
34- this .uml = uml ;
50+ @ Override
51+ public String getText () {
52+ return this .uml ;
53+ }
54+
55+ @ Override
56+ public void setText (String text ) {
57+ this .uml = new HTML (text ).getText ();
58+ }
59+
60+ @ Override
61+ public void setUrl (String url ) {
62+ this .src = url ;
63+ }
64+
65+ @ Override
66+ public String getUrl () {
67+ return this .src ;
68+ }
69+
70+ @ Override
71+ public void setResource (ImageResource resource ) {
72+ getImageMixin ().setResource (resource );
3573 }
3674
37- private String param (String uml ) {
38- return uml .replaceAll ("(%0A)|(\\ \\ n)" , "\n " );
75+ @ Override
76+ public ImageResource getResource () {
77+ return getImageMixin ().getResource ();
78+ }
79+
80+ protected ImageMixin <PlantumlMaterialImage > getImageMixin () {
81+ if (imageMixin == null ) {
82+ imageMixin = new ImageMixin <>(this );
83+ }
84+ return imageMixin ;
3985 }
4086}
0 commit comments