BrightSide Workbench Full Report + Source Code
As.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.Strings;
23 import org.zkoss.zk.ui.event.EventListener;
24 import org.zkoss.zk.ui.event.Events;
25 import org.zkoss.zul.A;
26 
31 public class As {
32 
33  public As width(String width) {
34  anchor.setWidth(width);
35  return this;
36  }
37 
38  public As height(String height) {
39  anchor.setHeight(height);
40  return this;
41  }
42 
43  public As hflex(String flex) {
44  anchor.setHflex(flex);
45  return this;
46  }
47 
48  public As vflex(String flex) {
49  anchor.setVflex(flex);
50  return this;
51  }
52 
53  public As style(String style) {
54  anchor.setStyle(style);
55  return this;
56  }
57 
58  public As tooltiptext(String text) {
59  anchor.setTooltiptext(text);
60  return this;
61  }
62 
63  public As dark() {
64  return cssClass("darkLink");
65  }
66 
67  public As cssClass(String cssClass) {
68  anchor.setSclass(cssClass);
69  return this;
70  }
71 
72  public As max(int maxChars) {
73  return tooltiptext(anchor.getLabel())
74  .value(Strings.truncateAndWarn(anchor.getLabel(), maxChars));
75  }
76 
77  public As value(String text) {
78  anchor.setLabel(text);
79  return this;
80  }
81 
82  public As icon(String icon) {
83  anchor.setIconSclass("z-icon-" + icon);
84  return this;
85  }
86 
87  public As focus() {
88  anchor.setFocus(true);
89  return this;
90  }
91 
92  public As onClick(EventListener listener) {
93  anchor.addEventListener(Events.ON_CLICK, listener);
94  return this;
95  }
96 
97  public A get() {
98  return anchor;
99  }
100 
101  public A get(Consumer<A> onGet) {
102  onGet.accept(anchor);
103  return anchor;
104  }
105 
106  /* Factory */
107 
108  public static As content(String text) {
109  return new As(text, null);
110  }
111 
112  public static As content(String text, String image) {
113  return new As(text, image);
114  }
115 
116  public static As image(String image) {
117  return new As(null, image);
118  }
119 
120  public static As icon(String icon, String tip) {
121  return new As(null, null).tooltiptext(tip).icon(icon);
122  }
123 
124  private final A anchor;
125 
126  private As(String text, String image) {
127  this.anchor = Strings.isBlank(image) ?
128  new A(text) : new A(text, image);
129  }
130 
131 }
static As content(String text, String image)
Definition: As.java:112
As value(String text)
Definition: As.java:77
As style(String style)
Definition: As.java:53
As tooltiptext(String text)
Definition: As.java:58
As hflex(String flex)
Definition: As.java:43
As onClick(EventListener listener)
Definition: As.java:92
static As image(String image)
Definition: As.java:116
As vflex(String flex)
Definition: As.java:48
As icon(String icon)
Definition: As.java:82
As cssClass(String cssClass)
Definition: As.java:67
As height(String height)
Definition: As.java:38
static As icon(String icon, String tip)
Definition: As.java:120
As width(String width)
Definition: As.java:33
As max(int maxChars)
Definition: As.java:72
static As content(String text)
Definition: As.java:108