BrightSide Workbench Full Report + Source Code
Htmls.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.zkoss.label;
20 
21 import java.util.function.Consumer;
22 import org.turro.string.Phrases;
23 import org.turro.html.HtmlContent;
24 import org.zkoss.zk.ui.event.EventListener;
25 import org.zkoss.zk.ui.event.Events;
26 import org.zkoss.zul.Html;
27 
32 public class Htmls {
33 
34  public Htmls width(String width) {
35  html.setWidth(width);
36  return this;
37  }
38 
39  public Htmls height(String height) {
40  html.setHeight(height);
41  return this;
42  }
43 
44  public Htmls hflex(String flex) {
45  html.setHflex(flex);
46  return this;
47  }
48 
49  public Htmls vflex(String flex) {
50  html.setVflex(flex);
51  return this;
52  }
53 
54  public Htmls style(String style) {
55  html.setStyle(style);
56  return this;
57  }
58 
59  public Htmls tooltiptext(String text) {
60  html.setTooltiptext(text);
61  return this;
62  }
63 
64  public Htmls cssClass(String cssClass) {
65  html.setSclass(cssClass);
66  return this;
67  }
68 
69  public Htmls max(int maxChars) {
70  return tooltiptext(html.getContent())
71  .content(HtmlContent.truncate(html.getContent(), maxChars));
72  }
73 
74  public Htmls content(String text) {
75  html.setContent(text);
76  return this;
77  }
78 
79  public Htmls focus() {
80  html.setFocus(true);
81  return this;
82  }
83 
84  public Htmls onClick(EventListener listener) {
85  html.addEventListener(Events.ON_CLICK, listener);
86  return this;
87  }
88 
89  public Html get() {
90  return html;
91  }
92 
93  public Html get(Consumer<Html> onGet) {
94  onGet.accept(html);
95  return html;
96  }
97 
98  /* Factory */
99 
100  public static Htmls text(String content) {
101  return new Htmls(content);
102  }
103 
104  public static Htmls icon(String icon) {
105  return new Htmls(Phrases.start("<i class='").add(icon).add("icon'></i>").toString());
106  }
107 
108  private final Html html;
109 
110  private Htmls(String content) {
111  this.html = new Html(content);
112  }
113 
114 }
Htmls onClick(EventListener listener)
Definition: Htmls.java:84
Htmls height(String height)
Definition: Htmls.java:39
Htmls hflex(String flex)
Definition: Htmls.java:44
Htmls tooltiptext(String text)
Definition: Htmls.java:59
Htmls max(int maxChars)
Definition: Htmls.java:69
static Htmls icon(String icon)
Definition: Htmls.java:104
Htmls style(String style)
Definition: Htmls.java:54
static Htmls text(String content)
Definition: Htmls.java:100
Htmls content(String text)
Definition: Htmls.java:74
Htmls vflex(String flex)
Definition: Htmls.java:49
Htmls cssClass(String cssClass)
Definition: Htmls.java:64
Htmls width(String width)
Definition: Htmls.java:34