forked from se-edu/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathMainWindow.java
191 lines (153 loc) · 5.47 KB
/
MainWindow.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
package seedu.address.ui;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.MenuItem;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import seedu.address.commons.core.Config;
import seedu.address.commons.core.GuiSettings;
import seedu.address.commons.events.ui.ExitAppRequestEvent;
import seedu.address.logic.Logic;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.ReadOnlyPerson;
/**
* The Main Window. Provides the basic application layout containing
* a menu bar and space where other JavaFX elements can be placed.
*/
public class MainWindow extends UiPart {
private static final String ICON = "/images/address_book_32.png";
private static final String FXML = "MainWindow.fxml";
private static final int MIN_HEIGHT = 600;
private static final int MIN_WIDTH = 450;
private Logic logic;
// Independent Ui parts residing in this Ui container
private BrowserPanel browserPanel;
private PersonListPanel personListPanel;
private ResultDisplay resultDisplay;
private StatusBarFooter statusBarFooter;
private CommandBox commandBox;
private Config config;
private UserPrefs userPrefs;
// Handles to elements of this Ui container
private VBox rootLayout;
private String addressBookName;
@FXML
private AnchorPane browserPlaceholder;
@FXML
private AnchorPane commandBoxPlaceholder;
@FXML
private MenuItem helpMenuItem;
@FXML
private AnchorPane personListPanelPlaceholder;
@FXML
private AnchorPane resultDisplayPlaceholder;
@FXML
private AnchorPane statusbarPlaceholder;
@Override
public void setNode(Node node) {
rootLayout = (VBox) node;
}
@Override
public String getFxmlPath() {
return FXML;
}
public static MainWindow load(Stage primaryStage, Config config, UserPrefs prefs, Logic logic) {
MainWindow mainWindow = UiPartLoader.loadUiPart(primaryStage, new MainWindow());
mainWindow.configure(config.getAppTitle(), config.getAddressBookName(), config, prefs, logic);
return mainWindow;
}
private void configure(String appTitle, String addressBookName, Config config, UserPrefs prefs,
Logic logic) {
// Set dependencies
this.logic = logic;
this.addressBookName = addressBookName;
this.config = config;
this.userPrefs = prefs;
// Configure the UI
setTitle(appTitle);
setIcon(ICON);
setWindowMinSize();
setWindowDefaultSize(prefs);
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
setAccelerators();
}
private void setAccelerators() {
helpMenuItem.setAccelerator(KeyCombination.valueOf("F1"));
}
void fillInnerParts() {
browserPanel = BrowserPanel.load(browserPlaceholder);
personListPanel = PersonListPanel.load(primaryStage, getPersonListPlaceholder(), logic.getFilteredPersonList());
resultDisplay = ResultDisplay.load(primaryStage, getResultDisplayPlaceholder());
statusBarFooter = StatusBarFooter.load(primaryStage, getStatusbarPlaceholder(),
config.getAddressBookFilePath());
commandBox = CommandBox.load(primaryStage, getCommandBoxPlaceholder(), logic);
}
private AnchorPane getCommandBoxPlaceholder() {
return commandBoxPlaceholder;
}
private AnchorPane getStatusbarPlaceholder() {
return statusbarPlaceholder;
}
private AnchorPane getResultDisplayPlaceholder() {
return resultDisplayPlaceholder;
}
private AnchorPane getPersonListPlaceholder() {
return personListPanelPlaceholder;
}
void hide() {
primaryStage.hide();
}
private void setTitle(String appTitle) {
primaryStage.setTitle(appTitle);
}
/**
* Sets the default size based on user preferences.
*/
private void setWindowDefaultSize(UserPrefs prefs) {
primaryStage.setHeight(prefs.getGuiSettings().getWindowHeight());
primaryStage.setWidth(prefs.getGuiSettings().getWindowWidth());
if (prefs.getGuiSettings().getWindowCoordinates() != null) {
primaryStage.setX(prefs.getGuiSettings().getWindowCoordinates().getX());
primaryStage.setY(prefs.getGuiSettings().getWindowCoordinates().getY());
}
}
private void setWindowMinSize() {
primaryStage.setMinHeight(MIN_HEIGHT);
primaryStage.setMinWidth(MIN_WIDTH);
}
/**
* Returns the current size and the position of the main Window.
*/
GuiSettings getCurrentGuiSetting() {
return new GuiSettings(primaryStage.getWidth(), primaryStage.getHeight(),
(int) primaryStage.getX(), (int) primaryStage.getY());
}
@FXML
public void handleHelp() {
HelpWindow helpWindow = HelpWindow.load(primaryStage);
helpWindow.show();
}
void show() {
primaryStage.show();
}
/**
* Closes the application.
*/
@FXML
private void handleExit() {
raise(new ExitAppRequestEvent());
}
public PersonListPanel getPersonListPanel() {
return this.personListPanel;
}
void loadPersonPage(ReadOnlyPerson person) {
browserPanel.loadPersonPage(person);
}
void releaseResources() {
browserPanel.freeResources();
}
}