18 package org.turro.zkoss.svg;
20 import java.io.Writer;
21 import java.util.HashMap;
23 import org.apache.commons.text.StringEscapeUtils;
24 import org.turro.string.Strings;
25 import org.turro.html.HTMLGenerator;
26 import org.turro.util.IdGenerator;
27 import org.zkoss.zk.ui.Executions;
28 import org.zkoss.zul.Div;
34 public class Svg extends Div {
37 private String forceStyle =
null, forceTransform=
null, clickElement =
null;
40 public void startComposing(String onUserEvent, String width, String height,
double scale) {
41 id = IdGenerator.generate();
45 "xmlns:n='http://www.zkoss.org/2005/zk/native'",
46 onUserEvent !=
null ?
"onUser='" + onUserEvent +
"'" :
""
50 "width='" + width +
"'",
51 "height='" + height +
"'",
53 "xmlns='http://www.w3.org/2000/svg'",
54 "xmlns:z='zk' style='overflow:auto'"
57 "transform='scale(" + scale +
")'"
64 "style='fill:${each};cursor:pointer'",
65 "z:forEach='${bgnds}'",
66 "cx='${50+rads[forEachStatus.index]}'",
67 "cy='${20+rads[forEachStatus.index]}'",
68 "r='${rads[forEachStatus.index]}'",
69 "onclick=\"zAu.send(new zk.Event(zk.Widget.$('$" +
id +
"'), 'onUser', '${each}'));\""
75 Executions.createComponentsDirectly(htmlGenerator.
toString(),
"zul",
this, args);
82 public void circle(
int x,
int y,
int r) {
86 public void circle(
int x,
int y,
int r,
double opacity) {
87 circle(x, y, r,
null,
null,
null, opacity);
90 public void circle(
int x,
int y,
int r, String stroke, String strokeWidth, String fill,
double opacity) {
91 doTag(
"n:circle",
new String[] {
95 (stroke ==
null ? null :
"stroke='" + stroke +
"'"),
96 (strokeWidth ==
null ?
null :
"stroke-width='" + strokeWidth +
"'"),
97 (fill ==
null ? null :
"fill='" + fill +
"'"),
98 "opacity='" + opacity +
"'",
99 forceStyle !=
null ?
"style='" + forceStyle +
"'" :
null,
100 forceTransform !=
null ?
"transform='" + forceTransform +
"'" :
null,
101 clickElement !=
null ?
"onclick=\"" + clickElement +
"\"" :
null
104 forceTransform =
null;
108 public void line(
int x1,
int y1,
int x2,
int y2, String stroke, String strokeWidth) {
109 line(x1, y1, x2, y2, stroke, strokeWidth, 1);
112 public void line(
int x1,
int y1,
int x2,
int y2, String stroke, String strokeWidth,
double opacity) {
113 doTag(
"n:line",
new String[] {
118 (stroke ==
null ? null :
"stroke='" + stroke +
"'"),
119 (strokeWidth ==
null ?
null :
"stroke-width='" + strokeWidth +
"'"),
120 "opacity='" + opacity +
"'",
121 forceStyle !=
null ?
"style='" + forceStyle +
"'" :
"",
122 forceTransform !=
null ?
"transform='" + forceTransform +
"'" :
"",
123 clickElement !=
null ?
"onclick=\"" + clickElement +
"\"" :
""
126 forceTransform =
null;
130 public void rectangle(
int x,
int y,
int width,
int height, String fill) {
134 public void rectangle(
int x,
int y,
int width,
int height, String fill,
double opacity) {
135 rectangle(x, y, width, height, fill, opacity,
null);
138 public void rectangle(
int x,
int y,
int width,
int height, String fill,
double opacity, String tooltip) {
142 "width='" + width +
"'",
143 "height='" + height +
"'",
144 "fill='" + fill +
"'",
145 "opacity='" + opacity +
"'",
146 forceStyle !=
null ?
"style='" + forceStyle +
"'" :
"",
147 forceTransform !=
null ?
"transform='" + forceTransform +
"'" :
"",
148 clickElement !=
null ?
"onclick=\"" + clickElement +
"\"" :
""
150 if(!Strings.isBlank(tooltip)) {
155 forceTransform =
null;
163 public void roundRectangle(
int x,
int y,
int width,
int height, String fill,
double opacity) {
167 public void roundRectangle(
int x,
int y,
int width,
int height, String fill,
double opacity, String tooltip) {
168 roundRectangle(x, y, 5, 5, width, height, fill, opacity, tooltip);
171 public void roundRectangle(
int x,
int y,
int rx,
int ry,
int width,
int height, String fill,
double opacity) {
175 public void roundRectangle(
int x,
int y,
int rx,
int ry,
int width,
int height, String fill,
double opacity, String tooltip) {
181 "width='" + width +
"'",
182 "height='" + height +
"'",
183 "fill='" + fill +
"'",
184 "opacity='" + opacity +
"'",
185 forceStyle !=
null ?
"style='" + forceStyle +
"'" :
"",
186 forceTransform !=
null ?
"transform='" + forceTransform +
"'" :
"",
187 clickElement !=
null ?
"onclick=\"" + clickElement +
"\"" :
""
189 if(!Strings.isBlank(tooltip)) {
194 forceTransform =
null;
202 public void text(String
text,
int x,
int y, String tooltip) {
206 forceStyle !=
null ?
"style='" + forceStyle +
"'" :
"",
207 forceTransform !=
null ?
"transform='" + forceTransform +
"'" :
"",
208 clickElement !=
null ?
"onclick=\"" + clickElement +
"\"" :
""
210 if(!Strings.isBlank(tooltip)) {
215 forceTransform =
null;
219 public void span(
int x,
int y,
int width,
int height, String fill,
double opacity) {
220 rectangle(x, y, width, height / 2, fill, opacity);
221 rectangle(x, y, height / 2, height, fill, opacity);
222 rectangle(x + width - (height / 2), y, height / 2, height, fill, opacity);
225 public void roundSpan(
int x,
int y,
int width,
int height, String fill,
double opacity) {
228 roundRectangle(x + width - (height / 2), y, height / 2, height, fill, opacity);
231 public void shadowedSpan(
int x,
int y,
int width,
int height, String fill,
double opacity) {
233 rectangle(x + 2, y + 2, width, height / 2,
"gray", 0.2);
235 rectangle(x, y, width, height / 2, fill, opacity);
237 rectangle(x + 2, y + 2, height / 2, height,
"gray", 0.2);
239 rectangle(x, y, height / 2, height, fill, opacity);
241 rectangle(x + width - (height / 2) + 2, y + 2, height / 2, height,
"gray", 0.2);
243 rectangle(x + width - (height / 2), y, height / 2, height, fill, opacity);
246 public void shadowedRoundSpan(
int x,
int y,
int width,
int height, String fill,
double opacity) {
256 roundRectangle(x + width - (height / 2) + 2, y + 2, height / 2, height,
"gray", 0.2);
258 roundRectangle(x + width - (height / 2), y, height / 2, height, fill, opacity);
261 public void shadowedLine(
int x1,
int y1,
int x2,
int y2, String stroke, String strokeWidth,
double opacity) {
263 line(x1 + 2, y1 + 2, x2 + 2, y2 + 2, stroke, strokeWidth, 0.2);
265 line(x1, y1, x2, y2, stroke, strokeWidth, opacity);
268 public void shadowedRectangle(
int x,
int y,
int width,
int height, String fill,
double opacity) {
270 rectangle(x + 2, y + 2, width, height,
"gray", 0.2);
272 rectangle(x, y, width, height, fill, opacity);
283 this.forceStyle = forceStyle;
287 this.forceTransform = forceTransform;
291 this.clickElement =
"zAu.send(new zk.Event(zk.Widget.$('$" +
id +
"'), 'onUser', '" + clickElementData +
"'));";
307 return htmlGenerator.
write(value);
311 return htmlGenerator.
startTag(tag, attributes);
315 return htmlGenerator.
startTag(tag, attributes);
359 return htmlGenerator.
startAnchor(url, hint, cssClass, onClick);
363 return htmlGenerator.
startAnchor(url, hint, cssClass);
371 htmlGenerator.
setOut(out);
375 return htmlGenerator.
endTag(tag);
379 return htmlGenerator.
endTag();
399 return htmlGenerator.
endCSS();
411 return htmlGenerator.
doTag(tag, attributes);
415 return htmlGenerator.
doTag(tag, attributes);
419 return htmlGenerator.
doTag(tag);
434 private final HashMap<String, String> saved =
new HashMap<>();
436 private void clearValues() {
437 saved.put(
"forceStyle", forceStyle);
438 saved.put(
"forceTransform", forceTransform);
439 saved.put(
"clickElement", clickElement);
444 private void restoreValues() {
445 forceStyle = saved.get(
"forceStyle");
446 forceTransform = saved.get(
"forceTransform");
447 clickElement = saved.get(
"clickElement");
HTMLGenerator endAllTags()
HTMLGenerator write(String value)
HTMLGenerator doTag(String tag)
HTMLGenerator writeNewLine()
HTMLGenerator endTableRow()
HTMLGenerator writeHorizontalStrut(int pixels)
HTMLGenerator startTag(String tag)
HTMLGenerator endJavaScript()
HTMLGenerator startTableRow(String attributes)
HTMLGenerator endTableCol()
boolean checkTag(String tag)
HTMLGenerator writeSeparator()
HTMLGenerator startJavaScript()
HTMLGenerator addJavaScriptLink(String jsFile)
HTMLGenerator endBeforeTag(String tag)
HTMLGenerator startExtAnchor(String url, String hint)
HTMLGenerator startAnchor(String url, String hint)
HTMLGenerator startTableCol(String attributes)
HTMLGenerator addCSSLink(String cssFile)
HTMLGenerator startTable(String attributes)
void text(String text, int x, int y, String tooltip)
HTMLGenerator endJavaScript()
HTMLGenerator startTableRow(String[] attributes)
HTMLGenerator startAnchor(String url, String hint, String cssClass, String onClick)
void startComposing(String onUserEvent, String width, String height, double scale)
HTMLGenerator writeSeparator()
HTMLGenerator endTag(String tag)
void rectangle(int x, int y, int width, int height, String fill, double opacity)
void roundSpan(int x, int y, int width, int height, String fill, double opacity)
HTMLGenerator endAllTags()
HTMLGenerator writeNewLine()
HTMLGenerator startExtAnchor(String url, String hint)
void roundRectangle(int x, int y, int width, int height, String fill, double opacity, String tooltip)
HTMLGenerator startJavaScript()
HTMLGenerator addCSSLink(String cssFile)
HTMLGenerator write(String value)
void span(int x, int y, int width, int height, String fill, double opacity)
HTMLGenerator endTableCol()
void circle(int x, int y, int r, double opacity)
void roundRectangle(int x, int y, int rx, int ry, int width, int height, String fill, double opacity)
HTMLGenerator writeHorizontalStrut(int pixels)
void shadowedRoundSpan(int x, int y, int width, int height, String fill, double opacity)
void shadowedRoundRectangle(int x, int y, int width, int height, String fill, double opacity, String tooltip)
void roundRectangle(int x, int y, int width, int height, String fill, double opacity)
void rectangle(int x, int y, int width, int height, String fill, double opacity, String tooltip)
void circle(int x, int y, int r)
HTMLGenerator endTableRow()
void setForceStyle(String forceStyle)
HTMLGenerator startAnchor(String url, String hint)
void roundRectangle(int x, int y, int rx, int ry, int width, int height, String fill, double opacity, String tooltip)
void roundRectangle(int x, int y, int width, int height, String fill)
HTMLGenerator startTag(String tag, String[] attributes)
void shadowedSpan(int x, int y, int width, int height, String fill, double opacity)
boolean checkTag(String tag)
void setClickElementData(String clickElementData)
void line(int x1, int y1, int x2, int y2, String stroke, String strokeWidth)
HTMLGenerator startTag(String tag, String attributes)
HTMLGenerator startTableRow(String attributes)
HTMLGenerator startTableCol(String attributes)
void setForceTransform(String forceTransform)
void text(String text, int x, int y)
HTMLGenerator doTag(String tag, String attributes)
HTMLGenerator startTag(String tag)
HTMLGenerator startTableCol(String[] attributes)
void shadowedRectangle(int x, int y, int width, int height, String fill, double opacity)
HTMLGenerator doTag(String tag, String[] attributes)
HTMLGenerator startTable(String attributes)
HTMLGenerator startTable(String[] attributes)
void line(int x1, int y1, int x2, int y2, String stroke, String strokeWidth, double opacity)
void rectangle(int x, int y, int width, int height, String fill)
void circle(int x, int y, int r, String stroke, String strokeWidth, String fill, double opacity)
HTMLGenerator startAnchor(String url, String hint, String cssClass)
void generateContent(Map args)
HTMLGenerator addJavaScriptLink(String jsFile)
void shadowedLine(int x1, int y1, int x2, int y2, String stroke, String strokeWidth, double opacity)
HTMLGenerator endBeforeTag(String tag)
HTMLGenerator doTag(String tag)