Fix UTF8 bug, create first executable JAR file
[jvcard.git] / src / com / googlecode / lanterna / gui2 / dialogs / MessageDialogBuilder.java
1 package com.googlecode.lanterna.gui2.dialogs;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 /**
7 * Dialog builder for the {@code MessageDialog} class, use this to create instances of that class and to customize
8 * them
9 * @author Martin
10 */
11 public class MessageDialogBuilder {
12 private String title;
13 private String text;
14 private List<MessageDialogButton> buttons;
15
16 /**
17 * Default constructor
18 */
19 public MessageDialogBuilder() {
20 this.title = "MessageDialog";
21 this.text = "Text";
22 this.buttons = new ArrayList<MessageDialogButton>();
23 }
24
25 /**
26 * Builds a new {@code MessageDialog} from the properties in the builder
27 * @return Newly build {@code MessageDialog}
28 */
29 public MessageDialog build() {
30 return new MessageDialog(
31 title,
32 text,
33 buttons.toArray(new MessageDialogButton[buttons.size()]));
34 }
35
36 /**
37 * Sets the title of the {@code MessageDialog}
38 * @param title New title of the message dialog
39 * @return Itself
40 */
41 public MessageDialogBuilder setTitle(String title) {
42 if(title == null) {
43 title = "";
44 }
45 this.title = title;
46 return this;
47 }
48
49 /**
50 * Sets the main text of the {@code MessageDialog}
51 * @param text Main text of the {@code MessageDialog}
52 * @return Itself
53 */
54 public MessageDialogBuilder setText(String text) {
55 if(text == null) {
56 text = "";
57 }
58 this.text = text;
59 return this;
60 }
61
62 /**
63 * Adds a button to the dialog
64 * @param button Button to add to the dialog
65 * @return Itself
66 */
67 public MessageDialogBuilder addButton(MessageDialogButton button) {
68 if(button != null) {
69 buttons.add(button);
70 }
71 return this;
72 }
73 }