1 /* 2 * ************************************************************************************************************************************************************* 3 * 4 * TheseFoolishThings: Miscellaneous utilities 5 * http://tidalwave.it/projects/thesefoolishthings 6 * 7 * Copyright (C) 2009 - 2025 by Tidalwave s.a.s. (http://tidalwave.it) 8 * 9 * ************************************************************************************************************************************************************* 10 * 11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 12 * You may obtain a copy of the License at 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 16 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 17 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 18 * 19 * ************************************************************************************************************************************************************* 20 * 21 * git clone https://bitbucket.org/tidalwave/thesefoolishthings-src 22 * git clone https://github.com/tidalwave-it/thesefoolishthings-src 23 * 24 * ************************************************************************************************************************************************************* 25 */ 26 package it.tidalwave.util.ui; 27 28 import javax.annotation.Nonnull; 29 import javax.annotation.concurrent.Immutable; 30 import lombok.Getter; 31 import lombok.RequiredArgsConstructor; 32 import lombok.ToString; 33 import static it.tidalwave.util.BundleUtilities.getMessage; 34 import static lombok.AccessLevel.PROTECTED; 35 36 /*************************************************************************************************************************************************************** 37 * 38 * @author Fabrizio Giudici 39 * 40 **************************************************************************************************************************************************************/ 41 @Getter @Immutable 42 @RequiredArgsConstructor(access = PROTECTED) @ToString 43 public class UserNotification 44 { 45 @Nonnull 46 protected final String text; 47 48 @Nonnull 49 protected final String caption; 50 51 /*********************************************************************************************************************************************************** 52 * Creates a notification with empty caption and text. 53 * 54 * @return the notification 55 **********************************************************************************************************************************************************/ 56 @Nonnull 57 public static UserNotification notification() 58 { 59 return new UserNotification("", ""); 60 } 61 62 /*********************************************************************************************************************************************************** 63 * Associates a caption to the notification. 64 * 65 * @param caption the caption 66 * @return the notification 67 **********************************************************************************************************************************************************/ 68 @Nonnull 69 public UserNotification withCaption (@Nonnull final String caption) 70 { 71 return new UserNotification(text, caption); 72 } 73 74 /*********************************************************************************************************************************************************** 75 * Associates a caption to the notification, retrieved from a resource bundle. 76 * 77 * @param bundleClass the class where to search the resource bundle from 78 * @param resourceName the resource name of the caption in the bundle 79 * @param params some (optional) parameters to the resource 80 * @return the notification 81 **********************************************************************************************************************************************************/ 82 @Nonnull 83 public UserNotification withCaption (@Nonnull final Class<?> bundleClass, 84 @Nonnull final String resourceName, 85 @Nonnull final Object ... params) 86 { 87 return new UserNotification(text, getMessage(bundleClass, resourceName, params)); 88 } 89 90 /*********************************************************************************************************************************************************** 91 * Associates a text to the notification. 92 * 93 * @param text the text 94 * @return the notification 95 **********************************************************************************************************************************************************/ 96 @Nonnull 97 public UserNotification withText (@Nonnull final String text) 98 { 99 return new UserNotification(text, caption); 100 } 101 102 /*********************************************************************************************************************************************************** 103 * Associates a text to the notification, retrieved from a resource bundle. 104 * 105 * @param bundleClass the class where to search the resource bundle from 106 * @param resourceName the resource name of the text in the bundle 107 * @param params some (optional) parameters to the resource 108 * @return the notification 109 **********************************************************************************************************************************************************/ 110 @Nonnull 111 public UserNotification withText (@Nonnull final Class<?> bundleClass, 112 @Nonnull final String resourceName, 113 @Nonnull final Object ... params) 114 { 115 return new UserNotification(getMessage(bundleClass, resourceName, params), caption); 116 } 117 }