@author Simon Gwerder @version OGV 3.1, May 2015
| 17 | * |
| 18 | */ |
| 19 | public class MessageBar { |
| 20 | |
| 21 | private static int CLEAR_TIME_SECOND = 5; |
| 22 | private static TextField messageBar; |
| 23 | private final static String defaultStyle; |
| 24 | |
| 25 | private static AtomicInteger countDown = new AtomicInteger(0); |
| 26 | private static AtomicBoolean taskRunning = new AtomicBoolean(false); |
| 27 | |
| 28 | public static TextField getTextField() { |
| 29 | synchronized (messageBar) { |
| 30 | return messageBar; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | static { |
| 35 | messageBar = new TextField(); |
| 36 | defaultStyle = messageBar.getStyle(); |
| 37 | messageBar.setEditable(false); |
| 38 | messageBar.setFocusTraversable(false); |
| 39 | messageBar.setDisable(true); |
| 40 | messageBar.setMinHeight(28); |
| 41 | HBox.setHgrow(messageBar, Priority.ALWAYS); |
| 42 | HBox.setMargin(messageBar, new Insets(5, 5, 5, 5)); |
| 43 | } |
| 44 | |
| 45 | public static void setText(String text, MessageLevel level) { |
| 46 | synchronized (messageBar) { |
| 47 | messageBar.setText(text); |
| 48 | switch (level) { |
| 49 | case INFO: |
| 50 | String iconStyleInfo = "-fx-background-image:url(\"" + ResourceLocator.getResourcePath(Resource.MESSAGE_INFO_PNG).toExternalForm() + "\");"; |
| 51 | messageBar.setStyle(iconStyleInfo |
| 52 | + " -fx-padding: 0 5 0 25; -fx-background-repeat: no-repeat; -fx-background-position: left center; -fx-font-weight: bold; -fx-text-inner-color: #000000;"); |
| 53 | break; |
| 54 | case WARN: |
| 55 | String iconStyleWarn = "-fx-background-image:url(\"" + ResourceLocator.getResourcePath(Resource.MESSAGE_WARN_PNG).toExternalForm() + "\");"; |
| 56 | messageBar.setStyle(iconStyleWarn |
| 57 | + " -fx-padding: 0 5 0 25; -fx-background-repeat: no-repeat; -fx-background-position: left center; -fx-font-weight: bold; -fx-text-inner-color: #717100;"); |
| 58 | break; |
| 59 | case ALERT: |
| 60 | String iconStyleError = "-fx-background-image:url(\"" + ResourceLocator.getResourcePath(Resource.MESSAGE_ERROR_PNG).toExternalForm() + "\");"; |
| 61 | messageBar.setStyle(iconStyleError |
| 62 | + " -fx-padding: 0 5 0 25; -fx-background-repeat: no-repeat; -fx-background-position: left center; -fx-font-weight: bold; -fx-text-inner-color: #CC2900;"); |
| 63 | break; |
| 64 | default: |
| 65 | // String iconStyleDefault = "-fx-background-image:url(\"" + ResourceLocator.getResourcePath(Resource.MESSAGE_DEFAULT_PNG).toExternalForm() + "\");"; |
| 66 | // messageBar.setStyle(iconStyleDefault |
| 67 | // + " -fx-padding: 0 5 0 25; -fx-background-repeat: no-repeat; -fx-background-position: left center; -fx-font-weight: bold; -fx-text-inner-color: transparent;"); |
| 68 | messageBar.setStyle(defaultStyle); |
| 69 | break; |
| 70 | } |
| 71 | countDown.set(CLEAR_TIME_SECOND); |
| 72 | if (!taskRunning.get()) { |
| 73 | taskRunning.set(true); |
| 74 | new Thread(new MessageTask()).start(); |
| 75 | } |
| 76 | } |
nothing calls this directly
no test coverage detected