1 package com
.googlecode
.lanterna
.gui2
.dialogs
;
3 import com
.googlecode
.lanterna
.gui2
.Window
;
5 import java
.util
.Collections
;
6 import java
.util
.HashSet
;
10 * Abstract class for dialog building, containing much shared code between different kinds of dialogs
11 * @param <B> The real type of the builder class
12 * @param <T> Type of dialog this builder is building
15 public abstract class AbstractDialogBuilder
<B
, T
extends DialogWindow
> {
16 protected String title
;
17 protected String description
;
18 protected Set
<Window
.Hint
> extraWindowHints
;
21 * Default constructor for a dialog builder
22 * @param title Title to assign to the dialog
24 public AbstractDialogBuilder(String title
) {
26 this.description
= null;
27 this.extraWindowHints
= Collections
.singleton(Window
.Hint
.CENTERED
);
31 * Changes the title of the dialog
32 * @param title New title
35 public B
setTitle(String title
) {
44 * Returns the title that the built dialog will have
45 * @return Title that the built dialog will have
47 public String
getTitle() {
52 * Changes the description of the dialog
53 * @param description New description
56 public B
setDescription(String description
) {
57 this.description
= description
;
62 * Returns the description that the built dialog will have
63 * @return Description that the built dialog will have
65 public String
getDescription() {
70 * Assigns a set of extra window hints that you want the built dialog to have
71 * @param extraWindowHints Window hints to assign to the window in addition to the ones the builder will put
74 public B
setExtraWindowHints(Set
<Window
.Hint
> extraWindowHints
) {
75 this.extraWindowHints
= extraWindowHints
;
80 * Returns the list of extra window hints that will be assigned to the window when built
81 * @return List of extra window hints that will be assigned to the window when built
83 public Set
<Window
.Hint
> getExtraWindowHints() {
84 return extraWindowHints
;
88 * Helper method for casting this to {@code type} parameter {@code B}
89 * @return {@code this} as {@code B}
91 protected abstract B
self();
94 * Builds the dialog according to the builder implementation
95 * @return New dialog object
97 protected abstract T
buildDialog();
100 * Builds a new dialog following the specifications of this builder
101 * @return New dialog built following the specifications of this builder
103 public final T
build() {
104 T dialog
= buildDialog();
105 if(!extraWindowHints
.isEmpty()) {
106 Set
<Window
.Hint
> combinedHints
= new HashSet
<Window
.Hint
>(dialog
.getHints());
107 combinedHints
.addAll(extraWindowHints
);
108 dialog
.setHints(combinedHints
);