Skip to content

Commit 3b931b7

Browse files
author
Sergey
committed
Merge pull request #55 from aNNiMON/notifications
Notifications
2 parents fe6dcb1 + da2174e commit 3b931b7

6 files changed

Lines changed: 167 additions & 41 deletions

File tree

libs/jfxmessagebox-1.1.0.jar

-32.6 KB
Binary file not shown.

nbproject/project.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ file.reference.asm-analysis-4.1.jar=libs/asm-analysis-4.1.jar
5353
file.reference.asm-tree-4.1.jar=libs/asm-tree-4.1.jar
5454
file.reference.asm-util-4.1.jar=libs/asm-util-4.1.jar
5555
file.reference.hamcrest-core-1.3.jar=libs/test/hamcrest-core-1.3.jar
56-
file.reference.jfxmessagebox-1.1.0.jar=libs/jfxmessagebox-1.1.0.jar
5756
file.reference.junit-4.12.jar=libs/test/junit-4.12.jar
5857
file.reference.junit-benchmarks-0.7.2.jar=libs/test/junit-benchmarks-0.7.2.jar
5958
file.reference.NoticEditor-src=src
@@ -77,7 +76,6 @@ javac.classpath=\
7776
${file.reference.parboiled-core-1.1.7.jar}:\
7877
${file.reference.parboiled-java-1.1.7.jar}:\
7978
${file.reference.pegdown-1.5.0.jar}:\
80-
${file.reference.jfxmessagebox-1.1.0.jar}:\
8179
${file.reference.jsoup-1.8.3.jar}:\
8280
${file.reference.zip4j-1.3.2.jar}
8381
# Space-separated list of extra javac options

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() {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.temporaryteam.noticeditor.view;
2+
3+
import javafx.animation.KeyFrame;
4+
import javafx.animation.Timeline;
5+
import javafx.animation.TranslateTransition;
6+
import javafx.event.ActionEvent;
7+
import javafx.scene.control.Label;
8+
import javafx.scene.layout.VBox;
9+
import javafx.scene.paint.Color;
10+
import javafx.scene.paint.Paint;
11+
import javafx.util.Duration;
12+
13+
/**
14+
* Simple notification.
15+
* @author aNNiMON
16+
*/
17+
public final class Notification {
18+
19+
public static final Duration DURATION_SHORT = new Duration(2000);
20+
public static final Duration DURATION_LONG = new Duration(5000);
21+
22+
private static final Duration TRANSITION_DURATION = new Duration(300);
23+
private static final Paint PAINT_MESSAGE = Color.WHITE;
24+
private static final Paint PAINT_ERROR = Color.rgb(255, 80, 80);
25+
private static final Paint PAINT_SUCCESS = Color.LIGHTGREEN;
26+
27+
private static VBox notificationBox;
28+
private static Label notificationLabel;
29+
30+
private static Timeline hideTimer;
31+
private static TranslateTransition transitionIn, transitionOut;
32+
33+
public static void init(VBox vbox, Label label) {
34+
notificationBox = vbox;
35+
notificationLabel = label;
36+
37+
transitionIn = new TranslateTransition(TRANSITION_DURATION, notificationBox);
38+
transitionIn.setToY(0);
39+
40+
transitionOut = new TranslateTransition(TRANSITION_DURATION, notificationBox);
41+
transitionOut.setFromY(0);
42+
transitionOut.setOnFinished((e) -> notificationBox.setVisible(false));
43+
}
44+
45+
public static void show(String text) {
46+
show(text, DURATION_SHORT);
47+
}
48+
49+
public static void show(String text, Duration duration) {
50+
show(text, duration, PAINT_MESSAGE);
51+
}
52+
53+
public static void error(String text) {
54+
show(text, DURATION_LONG, PAINT_ERROR);
55+
}
56+
57+
public static void success(String text) {
58+
show(text, DURATION_LONG, PAINT_SUCCESS);
59+
}
60+
61+
public static void show(String text, Duration duration, Paint textFill) {
62+
if (hideTimer != null) {
63+
// show new notification while previous exists
64+
hideTimer.stop();
65+
transitionOut.stop();
66+
}
67+
notificationLabel.setTextFill(textFill);
68+
notificationLabel.setText(text);
69+
hideTimer = new Timeline(new KeyFrame(duration.add(TRANSITION_DURATION)));
70+
hideTimer.setOnFinished(Notification::hide);
71+
hideTimer.playFromStart();
72+
notificationBox.setVisible(true);
73+
74+
transitionIn.setFromY(notificationBox.getHeight());
75+
transitionIn.playFromStart();
76+
}
77+
78+
private static void hide(ActionEvent e) {
79+
if (hideTimer != null) {
80+
hideTimer.stop();
81+
hideTimer = null;
82+
}
83+
transitionOut.setToY(notificationBox.getHeight());
84+
transitionOut.playFromStart();
85+
}
86+
}

src/fxml/Main.fxml

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<?import javafx.scene.text.*?>
77
<?import javafx.scene.control.*?>
88
<?import java.lang.*?>
9+
<?import java.net.*?>
910
<?import javafx.scene.layout.*?>
1011

1112
<VBox prefWidth="800.0" prefHeight="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.temporaryteam.noticeditor.controller.NoticeController">
@@ -36,36 +37,48 @@
3637
</Menu>
3738
</menus>
3839
</MenuBar>
39-
<SplitPane dividerPositions="0.25" prefWidth="200.0" prefHeight="160.0" VBox.vgrow="ALWAYS">
40-
<items>
41-
<SplitPane SplitPane.resizableWithParent="false" dividerPositions="0.1, 0.8" orientation="VERTICAL">
42-
<items>
43-
<TextField fx:id="searchField" promptText="%search" focusTraversable="false" >
44-
<padding>
45-
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
46-
</padding>
47-
</TextField>
48-
<TreeView fx:id="noticeTreeView" editable="true" prefHeight="200.0" prefWidth="200.0" showRoot="false">
49-
<contextMenu>
50-
<ContextMenu>
51-
<items>
52-
<MenuItem fx:id="addBranchItem" onAction="#handleContextMenu" text="Add branch" />
53-
<MenuItem fx:id="addNoticeItem" onAction="#handleContextMenu" text="Add notice" />
54-
<MenuItem fx:id="deleteItem" onAction="#handleContextMenu" text="Delete" />
55-
</items>
56-
</ContextMenu>
57-
</contextMenu>
58-
</TreeView>
59-
<fx:include fx:id="noticeSettings" source="NoticeSettings.fxml" />
60-
</items>
61-
</SplitPane>
62-
<SplitPane fx:id="editorPanel" dividerPositions="0.5" prefWidth="390.0" prefHeight="400.0">
63-
<items>
64-
<TextArea fx:id="noticeArea" prefWidth="215.0" prefHeight="400.0" />
65-
<WebView fx:id="viewer" prefWidth="310.0" prefHeight="400.0" />
66-
</items>
67-
</SplitPane>
68-
</items>
69-
</SplitPane>
40+
<StackPane VBox.vgrow="ALWAYS">
41+
<children>
42+
<SplitPane dividerPositions="0.25" prefWidth="200.0" prefHeight="160.0" VBox.vgrow="ALWAYS">
43+
<items>
44+
<SplitPane SplitPane.resizableWithParent="false" dividerPositions="0.1, 0.8" orientation="VERTICAL">
45+
<items>
46+
<TextField fx:id="searchField" promptText="%search" focusTraversable="false" >
47+
<padding>
48+
<Insets bottom="3.0" left="3.0" right="3.0" top="3.0" />
49+
</padding>
50+
</TextField>
51+
<TreeView fx:id="noticeTreeView" editable="true" prefHeight="200.0" prefWidth="200.0" showRoot="false">
52+
<contextMenu>
53+
<ContextMenu>
54+
<items>
55+
<MenuItem fx:id="addBranchItem" onAction="#handleContextMenu" text="Add branch" />
56+
<MenuItem fx:id="addNoticeItem" onAction="#handleContextMenu" text="Add notice" />
57+
<MenuItem fx:id="deleteItem" onAction="#handleContextMenu" text="Delete" />
58+
</items>
59+
</ContextMenu>
60+
</contextMenu>
61+
</TreeView>
62+
<fx:include fx:id="noticeSettings" source="NoticeSettings.fxml" />
63+
</items>
64+
</SplitPane>
65+
<SplitPane fx:id="editorPanel" dividerPositions="0.5" prefWidth="390.0" prefHeight="400.0">
66+
<items>
67+
<TextArea fx:id="noticeArea" prefWidth="215.0" prefHeight="400.0" />
68+
<WebView fx:id="viewer" prefWidth="310.0" prefHeight="400.0" />
69+
</items>
70+
</SplitPane>
71+
</items>
72+
</SplitPane>
73+
<VBox fx:id="notificationBox" maxHeight="-Infinity" maxWidth="-Infinity" styleClass="notificationBox" visible="false" StackPane.alignment="BOTTOM_CENTER">
74+
<children>
75+
<Label fx:id="notificationLabel" styleClass="notificationLabel" textAlignment="CENTER" />
76+
</children>
77+
</VBox>
78+
</children>
79+
</StackPane>
7080
</children>
81+
<stylesheets>
82+
<URL value="@/resources/styles/main.css" />
83+
</stylesheets>
7184
</VBox>

src/resources/styles/main.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.notificationBox {
2+
-fx-background-color: #000000AA;
3+
-fx-padding: 10;
4+
-fx-background-radius: 3 3 0 0;
5+
-fx-effect: dropshadow(two-pass-box, rgba(0,0,0,0.25), 4, 0.0, 0, 1);
6+
}
7+
.notificationLabel {
8+
-fx-text-fill: #FFF;
9+
-fx-font-size: 14;
10+
}

0 commit comments

Comments
 (0)