Skip to content

Commit 70c4ccb

Browse files
committed
Add notifications
1 parent 8df98d9 commit 70c4ccb

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

src/com/temporaryteam/noticeditor/controller/NoticeController.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
import com.temporaryteam.noticeditor.model.*;
2727
import com.temporaryteam.noticeditor.view.Chooser;
2828
import com.temporaryteam.noticeditor.view.EditNoticeTreeCell;
29+
import com.temporaryteam.noticeditor.view.Notification;
2930
import java.util.ResourceBundle;
3031
import java.util.logging.Level;
3132
import java.util.logging.Logger;
3233
import javafx.beans.binding.Bindings;
3334

3435
import javafx.beans.value.ChangeListener;
3536
import javafx.beans.value.ObservableValue;
36-
import jfx.messagebox.MessageBox;
37+
import javafx.scene.layout.VBox;
3738

3839
public class NoticeController {
3940

@@ -58,14 +59,20 @@ public class NoticeController {
5859
private Menu previewStyleMenu;
5960

6061
@FXML
61-
private TextField searchField;
62+
private TextField searchField;
6263

6364
@FXML
6465
private TreeView<NoticeItem> noticeTreeView;
6566

6667
@FXML
6768
private NoticeSettingsController noticeSettingsController;
6869

70+
@FXML
71+
private VBox notificationBox;
72+
73+
@FXML
74+
private Label notificationLabel;
75+
6976
@FXML
7077
private ResourceBundle resources;
7178

@@ -89,6 +96,7 @@ public void setApplication(Main main) {
8996
*/
9097
@FXML
9198
private void initialize() {
99+
Notification.init(notificationBox, notificationLabel);
92100
engine = viewer.getEngine();
93101

94102
// Set preview styles menu items
@@ -101,6 +109,7 @@ private void initialize() {
101109
item.setSelected(true);
102110
}
103111
item.setOnAction(new EventHandler<ActionEvent>() {
112+
@Override
104113
public void handle(ActionEvent e) {
105114
String path = cssPath;
106115
if (path != null) {
@@ -243,6 +252,7 @@ private void handleOpen(ActionEvent event) {
243252
noticeSettingsController.updateStatuses();
244253
} catch (IOException | JSONException e) {
245254
logger.log(Level.SEVERE, null, e);
255+
Notification.error("Unable to open " + fileSaved.getName());
246256
}
247257
}
248258

@@ -261,8 +271,9 @@ private void handleSaveAs(ActionEvent event) {
261271
.filter(Chooser.ZIP, Chooser.JSON)
262272
.title("Save notice")
263273
.show(main.getPrimaryStage());
264-
if (fileSaved == null)
274+
if (fileSaved == null) {
265275
return;
276+
}
266277

267278
saveDocument(fileSaved);
268279
}
@@ -275,24 +286,32 @@ private void saveDocument(File file) {
275286
} else {
276287
strategy = ExportStrategyHolder.ZIP;
277288
}
278-
DocumentFormat.save(file, noticeTree, strategy);
289+
try {
290+
DocumentFormat.save(file, noticeTree, strategy);
291+
Notification.success("Successfully saved!");
292+
} catch (ExportException e) {
293+
logger.log(Level.SEVERE, null, e);
294+
Notification.error("Successfully failed!");
295+
}
296+
279297
}
280298

281299
@FXML
282300
private void handleExportHtml(ActionEvent event) {
283301
File destDir = Chooser.directory()
284302
.title("Select directory to save HTML files")
285303
.show(main.getPrimaryStage());
286-
if (destDir == null)
304+
if (destDir == null) {
287305
return;
306+
}
288307

289308
try {
290309
ExportStrategyHolder.HTML.setProcessor(processor);
291310
ExportStrategyHolder.HTML.export(destDir, noticeTree);
292-
MessageBox.show(main.getPrimaryStage(), "Export success!", "", MessageBox.OK);
311+
Notification.success("Export success!");
293312
} catch (ExportException e) {
294313
logger.log(Level.SEVERE, null, e);
295-
MessageBox.show(main.getPrimaryStage(), "Export failed!", "", MessageBox.OK);
314+
Notification.error("Export failed!");
296315
}
297316
}
298317

@@ -309,7 +328,7 @@ private void handleSwitchOrientation(ActionEvent event) {
309328

310329
@FXML
311330
private void handleAbout(ActionEvent event) {
312-
331+
Notification.show("NoticEditor\n==========\n\nhttps://github.com/TemporaryTeam/NoticEditor");
313332
}
314333

315334
public NoticeTreeItem getCurrentNotice() {

src/fxml/Main.fxml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
</SplitPane>
7373
<VBox fx:id="notificationBox" maxHeight="-Infinity" maxWidth="-Infinity" styleClass="notificationBox" visible="false" StackPane.alignment="BOTTOM_CENTER">
7474
<children>
75-
<Label fx:id="notificationLabel" styleClass="notificationLabel" />
75+
<Label fx:id="notificationLabel" styleClass="notificationLabel" textAlignment="CENTER" />
7676
</children>
7777
</VBox>
7878
</children>

0 commit comments

Comments
 (0)