01: package org.airtodo.db.types;
02:
03: import java.awt.Color;
04: import java.util.Date;
05:
06: import javax.swing.Icon;
07: import javax.swing.JLabel;
08:
09: import org.air.framework.date.PeriodFormatterUtils;
10: import org.air.framework.gui.dialogs.login.ConnectDialog;
11: import org.air.framework.properties.Icons;
12:
13: public class PeriodUtils {
14: private static Date serverDateYMD = ConnectDialog
15: .getServerDateYMD();
16:
17: public static Period calcRemainPeriod(Period period) {
18: Period periodRemain = new Period(PeriodFormatterUtils.FIELD.DAY);
19: periodRemain.setValue(serverDateYMD, period.getDateEnd());
20: return periodRemain;
21: }
22:
23: public static boolean isInProgress(Period period) {
24: return serverDateYMD.compareTo(period.getDateStart()) >= 0
25: && serverDateYMD.compareTo(period.getDateEnd()) <= 0;
26: }
27:
28: public static boolean isExpired(Period period) {
29: return serverDateYMD.compareTo(period.getDateEnd()) > 0;
30: }
31:
32: public static boolean isFuture(Period period) {
33: return serverDateYMD.compareTo(period.getDateStart()) < 0;
34: }
35:
36: public static JLabel remainPeriodDecorator(JLabel label,
37: Period period) {
38: Color color = null;
39: String text = null;
40: Icon icon = null;
41: if (isFuture(period)) {
42: text = "WAITING";
43: icon = Icons.CLOCK;
44: color = Color.BLUE;
45: } else if (isInProgress(period)) {
46: text = calcRemainPeriod(period).toString();
47: icon = Icons.CLOCK_PLAY;
48: color = Color.BLACK;
49: } else if (isExpired(period)) {
50: text = "EXPIRED";
51: icon = Icons.CLOCK_STOP;
52: color = Color.RED;
53: }
54: label.setText(text);
55: label.setIcon(icon);
56: label.setForeground(color);
57: return label;
58: }
59: }
|