001package com.studentgui.apphelpers;
002
003import java.awt.BorderLayout;
004import java.awt.Color;
005import java.awt.Font;
006
007import javax.swing.JLabel;
008import javax.swing.JWindow;
009import javax.swing.SwingUtilities;
010
011/**
012 * Very small non-modal notification window for quick status messages.
013 *
014 * Lightweight utility used across pages to display transient, non-blocking
015 * notifications to the user.
016 */
017public class UiNotifier {
018    private static JWindow window;
019    private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(UiNotifier.class);
020
021    /**
022     * Display a short, transient notification message on screen.
023     *
024     * @param message message text to display
025     */
026    public static void show(final String message) {
027        SwingUtilities.invokeLater(() -> {
028            if (window != null) {
029                window.dispose();
030            }
031            window = new JWindow();
032            JLabel label = new JLabel(message);
033            label.setOpaque(true);
034            label.setBackground(new Color(0x22, 0x22, 0x22, 200));
035            label.setForeground(Color.WHITE);
036            label.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
037            window.getContentPane().setLayout(new BorderLayout());
038            window.getContentPane().add(label, BorderLayout.CENTER);
039            window.pack();
040            window.setAlwaysOnTop(true);
041            window.setLocationRelativeTo(null);
042            window.setVisible(true);
043            // auto-hide after 2 seconds
044            new Thread(() -> {
045                try { Thread.sleep(2000); }
046                catch (InterruptedException ie) { LOG.debug("UiNotifier sleep interrupted", ie); Thread.currentThread().interrupt(); }
047                SwingUtilities.invokeLater(() -> { if (window != null) { window.dispose(); window = null; } });
048            }).start();
049        });
050    }
051    
052    // Note: UiNotifier.show is intentionally lightweight and non-blocking;
053    // the implemented method above contains the behavior and JavaDoc.
054
055    /**
056     * Private constructor to prevent instantiation.
057     */
058    private UiNotifier() {
059        // utility only
060    }
061}