Snackbar's color can be changed according to the message type

- load a separate css file to change the color
- if the assignment failed, the snackbar prompt will be red, otherwise theme color

#story[1278]
This commit is contained in:
Haoming Yin
2017-09-23 20:59:29 +12:00
parent 066557584f
commit 1042817e4e
5 changed files with 34 additions and 15 deletions
@@ -101,9 +101,7 @@ public class ViewManager {
System.exit(0); System.exit(0);
}); });
jfxSnackbar = new JFXSnackbar(); jfxSnackbar = new JFXSnackbar(decorator);
decorator.getChildren().add(jfxSnackbar);
jfxSnackbar.registerSnackbarContainer(decorator);
} }
/** /**
@@ -228,8 +226,16 @@ public class ViewManager {
* *
* @param snackbarText text to be displayed. * @param snackbarText text to be displayed.
*/ */
public void showSnackbar(String snackbarText) { public void showSnackbar(String snackbarText, boolean isWarning) {
jfxSnackbar.show(snackbarText, 1500); if (isWarning) {
decorator.getStylesheets()
.add(getClass().getResource("/css/dialogs/Snackbar.css").toExternalForm());
} else {
if (decorator.getStylesheets().size() > 1) {
decorator.getStylesheets().remove(1);
}
}
jfxSnackbar.show(snackbarText, "fuck", 1500);
} }
/** /**
@@ -105,8 +105,8 @@ public class KeyBindingDialogController implements Initializable {
/** /**
* Prompt success / failure message for reassigning key action * Prompt success / failure message for reassigning key action
*/ */
private void showSnackBar(String message) { private void showSnackBar(String message, Boolean isWarning) {
ViewManager.getInstance().showSnackbar(message); ViewManager.getInstance().showSnackbar(message, isWarning);
} }
/** /**
@@ -151,10 +151,10 @@ public class KeyBindingDialogController implements Initializable {
private void keyPressed(KeyEvent event, Button button) { private void keyPressed(KeyEvent event, Button button) {
KeyAction buttonAction = buttonActionMap.get(button); KeyAction buttonAction = buttonActionMap.get(button);
if (gameKeyBind.bindKeyToAction(event.getCode(), buttonAction)) { if (gameKeyBind.bindKeyToAction(event.getCode(), buttonAction)) {
showSnackBar(button.getId() + " is set to " + event.getCode().getName()); showSnackBar(button.getId() + " is set to " + event.getCode().getName(), false);
button.setText(gameKeyBind.getKeyCode(buttonAction).getName()); button.setText(gameKeyBind.getKeyCode(buttonAction).getName());
} else { } else {
showSnackBar(event.getCode().getName() + " is already in use"); showSnackBar(event.getCode().getName() + " is already in use", true);
} }
event.consume(); event.consume();
} }
+3 -6
View File
@@ -102,16 +102,13 @@
} }
.jfx-snackbar-content { .jfx-snackbar-content {
-fx-background-color: WHITE; -fx-background-color: -fx-pp-front-color;
-fx-padding: 0 5 0 5; -fx-padding: 0 5 0 5;
-fx-spacing: 0 5 0 5; -fx-spacing: 0 5 0 5;
-fx-font-size: 18px; -fx-font-size: 15;
} }
.jfx-snackbar-toast { .jfx-snackbar-toast {
-fx-text-fill: -fx-pp-theme-color; -fx-text-fill: -fx-pp-theme-color;
} -fx-font-size: 15;
.jfx-snackbar-action {
-fx-text-fill: #ff4081;
} }
@@ -30,3 +30,15 @@ JFXToggleButton {
#resetBtn:hover { #resetBtn:hover {
-fx-font-size: 20; -fx-font-size: 20;
} }
.jfx-snackbar-content {
-fx-background-color: #323232;
}
.jfx-snackbar-toast {
-fx-text-fill: WHITE;
}
.jfx-snackbar-action {
-fx-text-fill: #ff4081;
}
@@ -0,0 +1,4 @@
/* a separate file to dynamically change snackbar's color */
.jfx-snackbar-toast {
-fx-text-fill: red !important;
}