11package com .demo .custom ;
22
33import java .awt .BorderLayout ;
4+ import java .awt .event .ActionEvent ;
5+ import java .awt .event .ActionListener ;
46
7+ import javax .swing .JButton ;
58import javax .swing .JLabel ;
9+ import javax .swing .JProgressBar ;
10+ import javax .swing .Timer ;
611
712import com .notification .Notification ;
813import com .notification .NotificationBuilder ;
914import com .notification .types .BorderLayoutNotification ;
1015import com .theme .TextTheme ;
1116import com .theme .ThemePackage ;
17+ import com .theme .WindowTheme ;
1218
1319/**
1420 * This is a CustomNotification which will only have one line of text.
1521 */
1622public class CustomNotification extends BorderLayoutNotification {
1723 private JLabel m_label ;
24+ private JButton m_button ;
25+ private JProgressBar m_progress ;
26+
27+ private TextTheme m_theme ;
1828
1929 public CustomNotification () {
2030 m_label = new JLabel ();
31+ m_button = new JButton ("Click me!" );
32+ m_progress = new JProgressBar ();
33+
34+ m_button .addActionListener (new ActionListener () {
35+ @ Override
36+ public void actionPerformed (ActionEvent e ) {
37+ removeComponent (m_button );
38+ addComponent (m_progress , BorderLayout .SOUTH );
39+ final Timer timer = new Timer (100 , null );
40+
41+ timer .addActionListener (new ActionListener () {
42+ @ Override
43+ public void actionPerformed (ActionEvent e ) {
44+ m_progress .setValue (m_progress .getValue () + 1 );
45+ m_progress .repaint ();
46+
47+ if (m_progress .getValue () == 100 ) {
48+ timer .stop ();
49+ hide ();
50+ }
51+ }
52+ });
53+
54+ timer .start ();
55+ }
56+ });
57+
2158 this .addComponent (m_label , BorderLayout .CENTER );
59+ this .addComponent (m_button , BorderLayout .SOUTH );
2260 }
2361
2462 /**
@@ -27,7 +65,13 @@ public CustomNotification() {
2765 * @param theme
2866 */
2967 public void setTextTeme (TextTheme theme ) {
68+ System .out .println ("Text theme set" );
3069 m_label .setFont (theme .title );
70+ m_label .setForeground (theme .titleColor );
71+ m_button .setFont (theme .subtitle );
72+ m_button .setForeground (theme .subtitleColor );
73+
74+ m_theme = theme ;
3175 }
3276
3377 public String getText () {
@@ -38,6 +82,19 @@ public void setText(String text) {
3882 m_label .setText (text );
3983 }
4084
85+ @ Override
86+ protected void themeSet (WindowTheme theme ) {
87+ super .themeSet (theme );
88+
89+ if (m_theme != null ) {
90+ // the WindowNotification is going to automatically give all our labels with the set foreground color, but
91+ // we
92+ // want to change this to the title color of the font
93+ m_label .setForeground (m_theme .titleColor );
94+ m_button .setForeground (m_theme .subtitleColor );
95+ }
96+ }
97+
4198 public static class CustomBuilder implements NotificationBuilder {
4299 @ Override
43100 public Notification buildNotification (ThemePackage pack , Object [] args ) {
0 commit comments