Commit | Line | Data |
---|---|---|
a3b510ab NR |
1 | package com.googlecode.lanterna.gui2.dialogs; |
2 | ||
3 | import com.googlecode.lanterna.TerminalSize; | |
4 | import com.googlecode.lanterna.gui2.LocalizedString; | |
5 | ||
6 | import java.io.File; | |
7 | ||
8 | /** | |
9 | * Dialog builder for the {@code FileDialog} class, use this to create instances of that class and to customize | |
10 | * them | |
11 | * @author Martin | |
12 | */ | |
13 | public class FileDialogBuilder extends AbstractDialogBuilder<FileDialogBuilder, FileDialog> { | |
14 | ||
15 | private String actionLabel; | |
16 | private TerminalSize suggestedSize; | |
17 | private File selectedFile; | |
18 | private boolean showHiddenDirectories; | |
19 | ||
20 | /** | |
21 | * Default constructor | |
22 | */ | |
23 | public FileDialogBuilder() { | |
24 | super("FileDialog"); | |
25 | actionLabel = LocalizedString.OK.toString(); | |
26 | suggestedSize = new TerminalSize(45, 10); | |
27 | showHiddenDirectories = false; | |
28 | selectedFile = null; | |
29 | } | |
30 | ||
31 | @Override | |
32 | protected FileDialog buildDialog() { | |
33 | return new FileDialog(title, description, actionLabel, suggestedSize, showHiddenDirectories, selectedFile); | |
34 | } | |
35 | ||
36 | /** | |
37 | * Defines the label to be but on the confirmation button (default: "ok"). You probably want to set this to | |
38 | * {@code LocalizedString.Save.toString()} or {@code LocalizedString.Open.toString()} | |
39 | * @param actionLabel Label to put on the confirmation button | |
40 | * @return Itself | |
41 | */ | |
42 | public FileDialogBuilder setActionLabel(String actionLabel) { | |
43 | this.actionLabel = actionLabel; | |
44 | return this; | |
45 | } | |
46 | ||
47 | /** | |
48 | * Returns the label on the confirmation button | |
49 | * @return Label on the confirmation button | |
50 | */ | |
51 | public String getActionLabel() { | |
52 | return actionLabel; | |
53 | } | |
54 | ||
55 | /** | |
56 | * Sets the suggested size for the file dialog, it won't have exactly this size but roughly. Default suggested size | |
57 | * is 45x10. | |
58 | * @param suggestedSize Suggested size for the file dialog | |
59 | * @return Itself | |
60 | */ | |
61 | public FileDialogBuilder setSuggestedSize(TerminalSize suggestedSize) { | |
62 | this.suggestedSize = suggestedSize; | |
63 | return this; | |
64 | } | |
65 | ||
66 | /** | |
67 | * Returns the suggested size for the file dialog | |
68 | * @return Suggested size for the file dialog | |
69 | */ | |
70 | public TerminalSize getSuggestedSize() { | |
71 | return suggestedSize; | |
72 | } | |
73 | ||
74 | /** | |
75 | * Sets the file that is initially selected in the dialog | |
76 | * @param selectedFile File that is initially selected in the dialog | |
77 | * @return Itself | |
78 | */ | |
79 | public FileDialogBuilder setSelectedFile(File selectedFile) { | |
80 | this.selectedFile = selectedFile; | |
81 | return this; | |
82 | } | |
83 | ||
84 | /** | |
85 | * Returns the file that is initially selected in the dialog | |
86 | * @return File that is initially selected in the dialog | |
87 | */ | |
88 | public File getSelectedFile() { | |
89 | return selectedFile; | |
90 | } | |
91 | ||
92 | /** | |
93 | * Sets if hidden files and directories should be visible in the dialog (default: {@code false} | |
94 | * @param showHiddenDirectories If {@code true} then hidden files and directories will be visible | |
95 | */ | |
96 | public void setShowHiddenDirectories(boolean showHiddenDirectories) { | |
97 | this.showHiddenDirectories = showHiddenDirectories; | |
98 | } | |
99 | ||
100 | /** | |
101 | * Checks if hidden files and directories will be visible in the dialog | |
102 | * @return If {@code true} then hidden files and directories will be visible | |
103 | */ | |
104 | public boolean isShowHiddenDirectories() { | |
105 | return showHiddenDirectories; | |
106 | } | |
107 | ||
108 | @Override | |
109 | protected FileDialogBuilder self() { | |
110 | return this; | |
111 | } | |
112 | } |