BrightSide Workbench Full Report + Source Code
Toasts.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.elephant.util;
20 
21 import org.turro.string.Phrases;
22 import org.zkoss.zkmax.ui.util.Toast;
23 
28 public class Toasts {
29 
30  public Toasts info() {
31  this.type = "info";
32  return this;
33  }
34 
35  public Toasts warning() {
36  this.type = "warning";
37  return this;
38  }
39 
40  public Toasts error() {
41  this.type = "error";
42  return this;
43  }
44 
45  public Toasts top() {
46  this.position = "top_center";
47  return this;
48  }
49 
50  public Toasts bottom() {
51  this.position = "bottom_center";
52  return this;
53  }
54 
55  public Toasts duration(int duration) {
56  this.duration = duration;
57  return this;
58  }
59 
60  public Toasts closable() {
61  this.closable = true;
62  return this;
63  }
64 
65  public void show() {
66  Toast.show(phrases.newLine("<br/>").toString(), type, position, duration, closable);
67  }
68 
69  /* Phrases */
70 
71  private final Phrases phrases = Phrases.start();
72 
73  public Toasts add(String word) {
74  phrases.add(word);
75  return this;
76  }
77 
78  public Toasts add(String word, boolean withSpace) {
79  phrases.add(word, withSpace);
80  return this;
81  }
82 
83  public Toasts add(String word, String enclose) {
84  phrases.add(word, enclose);
85  return this;
86  }
87 
88  public Toasts add(String value, String enclose, boolean withSpace) {
89  phrases.add(value, enclose, withSpace);
90  return this;
91  }
92 
93  public Toasts format(String word, Object... args) {
94  phrases.format(word, args);
95  return this;
96  }
97 
98  public Toasts line() {
99  phrases.line();
100  return this;
101  }
102 
103  public Toasts paragraph() {
104  phrases.paragraph();
105  return this;
106  }
107 
108  /* Factory */
109 
110  public static Toasts instance() {
111  return new Toasts(null);
112  }
113 
114  public static Toasts message(String message) {
115  return new Toasts(message);
116  }
117 
118  private String type, position;
119  private int duration;
120  private boolean closable;
121 
122  private Toasts(String message) {
123  phrases.add(message);
124  type = "info";
125  position = "top_center";
126  duration = 0;
127  closable = false;
128  }
129 
130 }
Toasts add(String word, String enclose)
Definition: Toasts.java:83
Toasts add(String word, boolean withSpace)
Definition: Toasts.java:78
Toasts add(String word)
Definition: Toasts.java:73
static Toasts instance()
Definition: Toasts.java:110
static Toasts message(String message)
Definition: Toasts.java:114
Toasts add(String value, String enclose, boolean withSpace)
Definition: Toasts.java:88
Toasts format(String word, Object... args)
Definition: Toasts.java:93
Toasts duration(int duration)
Definition: Toasts.java:55