Commit | Line | Data |
---|---|---|
a3b510ab NR |
1 | package com.googlecode.lanterna.gui2.dialogs; |
2 | ||
3 | import com.googlecode.lanterna.gui2.*; | |
4 | ||
5 | import java.util.Collections; | |
6 | import java.util.HashSet; | |
7 | import java.util.Set; | |
8 | ||
9 | /** | |
10 | * Thin layer on top of the {@code AbstractWindow} class that automatically sets properties and hints to the window to | |
11 | * make it act more like a modal dialog window | |
12 | */ | |
13 | public abstract class DialogWindow extends AbstractWindow { | |
14 | ||
15 | private static final Set<Hint> GLOBAL_DIALOG_HINTS = | |
16 | Collections.unmodifiableSet(new HashSet<Hint>(Collections.singletonList(Hint.MODAL))); | |
17 | ||
18 | /** | |
19 | * Default constructor, takes a title for the dialog and runs code shared for dialogs | |
20 | * @param title | |
21 | */ | |
22 | protected DialogWindow(String title) { | |
23 | super(title); | |
24 | setHints(GLOBAL_DIALOG_HINTS); | |
25 | } | |
26 | ||
27 | /** | |
28 | * Opens the dialog by showing it on the GUI and doesn't return until the dialog has been closed | |
29 | * @param textGUI Text GUI to add the dialog to | |
30 | * @return Depending on the {@code DialogWindow} implementation, by default {@code null} | |
31 | */ | |
32 | public Object showDialog(WindowBasedTextGUI textGUI) { | |
33 | textGUI.addWindow(this); | |
34 | ||
35 | //Wait for the window to close, in case the window manager doesn't honor the MODAL hint | |
36 | waitUntilClosed(); | |
37 | return null; | |
38 | } | |
39 | } |