Skip to content

Commit feff570

Browse files
committed
Added a ProgressBarNotification and fixed a font contrast problem in AcceptNotification
1 parent db67faf commit feff570

File tree

8 files changed

+113
-40
lines changed

8 files changed

+113
-40
lines changed

src/com/demo/SimpleManagerDemo.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.notification.NotificationFactory.Location;
77
import com.notification.types.AcceptNotification;
88
import com.notification.types.IconNotification;
9+
import com.notification.types.ProgressBarNotification;
910
import com.notification.types.TextNotification;
1011
import com.platform.Platform;
1112
import com.theme.ThemePackagePresets;
@@ -47,13 +48,18 @@ public static void main(String[] args) throws InterruptedException {
4748
fade.addNotification(accept, Time.seconds(4));
4849

4950
boolean didAccept = accept.blockUntilReply();
50-
TextNotification reply = null;
51+
ProgressBarNotification reply = null;
5152
if (didAccept) {
52-
reply = factory.buildTextNotification("You accepted", "");
53+
reply = factory.buildProgressBarNotification("You accepted");
5354
} else {
54-
reply = factory.buildTextNotification("You did not accept", "");
55+
reply = factory.buildProgressBarNotification("You did not accept");
5556
}
5657
reply.setCloseOnClick(true);
5758
fade.addNotification(reply, Time.infinite());
59+
60+
for (int i = 0; i < 100; i++) {
61+
reply.setProgress(i);
62+
Thread.sleep(100);
63+
}
5864
}
5965
}

src/com/demo/custom/CustomNotification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public void actionPerformed(ActionEvent e) {
5959
}
6060

6161
/**
62-
* This will set the text font to that of the title font.
63-
*
62+
* This will set the title and subtitle font and color.
63+
*
6464
* @param theme
6565
*/
6666
public void setTextTeme(TextTheme theme) {

src/com/notification/NotificationFactory.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import com.notification.types.AcceptNotification;
88
import com.notification.types.IconNotification;
9+
import com.notification.types.ProgressBarNotification;
910
import com.notification.types.TextNotification;
1011
import com.theme.ThemePackage;
1112
import com.theme.ThemePackagePresets;
@@ -79,19 +80,19 @@ public <T extends Notification> T build(Class<T> notificationClass) {
7980
}
8081

8182
/**
82-
* Builds a Notification using the NotificationBuilder associated with the name.
83+
* Builds a Notification using the NotificationBuilder associated with the notification class.
8384
*
84-
* @param clazz
85+
* @param notificationClass
8586
* @param args
8687
* the args passed to the NotificationBuilder
8788
* @return
8889
*/
89-
public <T extends Notification> T build(Class<T> clazz, Object... args) {
90-
if (!m_builders.containsKey(clazz))
91-
throw new RuntimeException("No NotificationBuilder for: " + clazz);
90+
public <T extends Notification> T build(Class<T> notificationClass, Object... args) {
91+
if (!m_builders.containsKey(notificationClass))
92+
throw new RuntimeException("No NotificationBuilder for: " + notificationClass);
9293

9394
@SuppressWarnings("unchecked")
94-
T note = (T) m_builders.get(clazz).buildNotification(m_pack, args);
95+
T note = (T) m_builders.get(notificationClass).buildNotification(m_pack, args);
9596
return note;
9697
}
9798

@@ -172,4 +173,18 @@ public IconNotification buildIconNotification(String title, String subtitle, Ima
172173

173174
return iconNote;
174175
}
176+
177+
/**
178+
* Builds a ProgressBarNotification.
179+
*
180+
* @param title
181+
* @return
182+
*/
183+
public ProgressBarNotification buildProgressBarNotification(String title) {
184+
ProgressBarNotification progress = new ProgressBarNotification();
185+
progress.setWindowTheme(m_pack.windowTheme);
186+
progress.setTextTeme(m_pack.textTheme);
187+
progress.setTitle(title);
188+
return progress;
189+
}
175190
}

src/com/notification/types/AcceptNotification.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package com.notification.types;
22

33
import java.awt.BorderLayout;
4+
import java.awt.Color;
45
import java.awt.Dimension;
56
import java.awt.event.ActionEvent;
67
import java.awt.event.ActionListener;
78

89
import javax.swing.JButton;
910
import javax.swing.JPanel;
1011

11-
import com.theme.TextTheme;
1212
import com.theme.WindowTheme;
1313

1414
/**
@@ -58,7 +58,7 @@ public void actionPerformed(ActionEvent e) {
5858
/**
5959
* Will wait for the user to click a button (if the Notification hides, this method will act as if the user clicked
6060
* deny).
61-
*
61+
*
6262
* @return the user's response
6363
*/
6464
public boolean blockUntilReply() {
@@ -73,7 +73,7 @@ public boolean blockUntilReply() {
7373

7474
/**
7575
* Sets the preferred size of the buttons.
76-
*
76+
*
7777
* @param d
7878
*/
7979
public void setButtonDimensions(Dimension d) {
@@ -90,7 +90,7 @@ public String getAcceptText() {
9090

9191
/**
9292
* Sets the text on the accept button.
93-
*
93+
*
9494
* @param acceptText
9595
*/
9696
public void setAcceptText(String acceptText) {
@@ -106,7 +106,7 @@ public String getDeclineText() {
106106

107107
/**
108108
* Sets the text on the decline button.
109-
*
109+
*
110110
* @param declineText
111111
*/
112112
public void setDeclineText(String declineText) {
@@ -127,21 +127,13 @@ public void hide() {
127127
}
128128
}
129129

130-
@Override
131-
public void setTextTheme(TextTheme theme) {
132-
super.setTextTheme(theme);
133-
134-
m_accept.setForeground(theme.subtitleColor);
135-
m_decline.setForeground(theme.subtitleColor);
136-
}
137-
138130
@Override
139131
public void setWindowTheme(WindowTheme theme) {
140132
super.setWindowTheme(theme);
141133

142-
if (getTextTheme() != null) {
143-
m_accept.setForeground(getTextTheme().subtitleColor);
144-
m_decline.setForeground(getTextTheme().subtitleColor);
145-
}
134+
// override any color setting done automatically by the WindowTheme
135+
// since black is the only color that looks good on buttons
136+
m_accept.setForeground(Color.black);
137+
m_decline.setForeground(Color.black);
146138
}
147139
}

src/com/notification/types/IconNotification.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
* An IconNotification displays text, but with an icon.
1515
*/
1616
public class IconNotification extends BorderLayoutNotification {
17-
protected TextTheme m_theme;
18-
1917
private String m_title;
2018
private String m_subtitle;
2119

@@ -24,6 +22,8 @@ public class IconNotification extends BorderLayoutNotification {
2422

2523
private JLabel m_iconLabel;
2624

25+
protected TextTheme m_theme;
26+
2727
public static final int ICON_PADDING = 10;
2828

2929
public IconNotification() {
@@ -42,7 +42,7 @@ public IconNotification() {
4242

4343
/**
4444
* Sets the icon to use.
45-
*
45+
*
4646
* @param icon
4747
*/
4848
public void setIcon(ImageIcon icon) {
@@ -58,7 +58,7 @@ public String getTitle() {
5858

5959
/**
6060
* Sets the title String.
61-
*
61+
*
6262
* @param title
6363
*/
6464
public void setTitle(String title) {
@@ -75,7 +75,7 @@ public String getSubtitle() {
7575

7676
/**
7777
* Sets the subtitle String.
78-
*
78+
*
7979
* @param subtitle
8080
*/
8181
public void setSubtitle(String subtitle) {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.notification.types;
2+
3+
import java.awt.BorderLayout;
4+
5+
import javax.swing.BorderFactory;
6+
import javax.swing.JLabel;
7+
import javax.swing.JPanel;
8+
import javax.swing.JProgressBar;
9+
10+
import com.theme.TextTheme;
11+
12+
public class ProgressBarNotification extends BorderLayoutNotification {
13+
private JLabel m_label;
14+
private JProgressBar m_progress;
15+
16+
public ProgressBarNotification() {
17+
m_label = new JLabel();
18+
m_progress = new JProgressBar();
19+
20+
this.addComponent(m_label, BorderLayout.NORTH);
21+
22+
JPanel progressPanel = new JPanel(new BorderLayout());
23+
progressPanel.setBorder(BorderFactory.createEmptyBorder(15, 10, 15, 10));
24+
progressPanel.add(m_progress, BorderLayout.CENTER);
25+
this.addComponent(progressPanel, BorderLayout.CENTER);
26+
}
27+
28+
/**
29+
* This will set the text font to that of the title font.
30+
*
31+
* @param theme
32+
*/
33+
public void setTextTeme(TextTheme theme) {
34+
m_label.setFont(theme.title);
35+
m_label.setForeground(theme.titleColor);
36+
}
37+
38+
public String getTitle() {
39+
return m_label.getText();
40+
}
41+
42+
public void setTitle(String title) {
43+
m_label.setText(title);
44+
}
45+
46+
/**
47+
* Sest the progress of the progress bar, from 0 to 100.
48+
*
49+
* @param progress
50+
*/
51+
public void setProgress(int progress) {
52+
m_progress.setValue(progress);
53+
}
54+
55+
/**
56+
* @return the progress of the progress bar, from 0 to 100
57+
*/
58+
public int getProgress() {
59+
return m_progress.getValue();
60+
}
61+
}

src/com/notification/types/TextNotification.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
* A text notification which will display a title and a subtitle.
1212
*/
1313
public class TextNotification extends BorderLayoutNotification {
14-
private TextTheme m_textTheme;
15-
1614
private JLabel m_titleLabel;
1715
private JLabel m_subtitleLabel;
1816

17+
private TextTheme m_textTheme;
18+
1919
public TextNotification() {
2020
m_titleLabel = new JLabel();
2121
m_subtitleLabel = new JLabel();

src/com/notification/types/WindowNotification.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ public abstract class WindowNotification extends Notification {
1919
private JWindow m_window;
2020
private JPanel m_panel;
2121
private boolean m_closeOnClick;
22+
private MouseAdapter m_listener;
2223

2324
private WindowTheme m_theme;
2425

25-
private MouseAdapter m_listener;
26-
2726
private static final int DEFAULT_WIDTH = 300;
2827
private static final int DEFAULT_HEIGHT = 100;
2928

@@ -81,7 +80,7 @@ protected WindowTheme getWindowTheme() {
8180
/**
8281
* Sets the theme of the WindowNotification. It is up to the subclasses how they want to interpret the "image"
8382
* attribute of the theme.
84-
*
83+
*
8584
* @param theme
8685
*/
8786
public void setWindowTheme(WindowTheme theme) {
@@ -144,7 +143,7 @@ public void setSize(int width, int height) {
144143

145144
/**
146145
* Gets the opacity of the window between 0 and 1.
147-
*
146+
*
148147
* @return
149148
*/
150149
@Override
@@ -154,7 +153,7 @@ public double getOpacity() {
154153

155154
/**
156155
* Sets the opacity, overriding the value given in the window theme.
157-
*
156+
*
158157
* @param opacity
159158
* the opacity (clamped to between 0 and 1)
160159
*/

0 commit comments

Comments
 (0)