OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 112 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
112 ilm 1
package org.openconcerto.modules.operation;
2
 
3
import java.awt.Font;
4
import java.awt.print.PageFormat;
5
import java.text.DateFormat;
6
import java.util.Calendar;
7
import java.util.List;
8
 
9
import org.jopencalendar.model.JCalendarItem;
10
import org.jopencalendar.print.CalendarItemPrinter;
11
 
12
public class OperationCalendarItemPrinter extends CalendarItemPrinter {
158 ilm 13
    public static final Font FONT_LINE = new Font("Arial", Font.PLAIN, 9);
112 ilm 14
 
15
    public OperationCalendarItemPrinter(String title, List<JCalendarItem> items, PageFormat pf) {
16
        super(title, items, pf);
17
    }
18
 
19
    @Override
20
    public String getLine1Text(JCalendarItem item) {
21
        final String siteName = ((JCalendarItemDB) item).getSiteName().toUpperCase();
22
        final String siteComment = ((JCalendarItemDB) item).getSiteComment();
23
        if (siteComment != null && !siteComment.isEmpty()) {
24
            return siteName + " - " + siteComment;
25
        }
26
        return siteName;
27
    }
28
 
29
    @Override
30
    public String getLine2Text(JCalendarItem item) {
31
        final String type = ((JCalendarItemDB) item).getType();
32
        final String description = item.getDescription();
33
        if (description != null && !description.isEmpty()) {
34
            return type + " - " + description;
35
        }
36
        return type;
37
    }
38
 
39
    @Override
40
    public String getTitle() {
41
        final List<JCalendarItem> items = this.getItems();
42
        int totalMinutes = 0;
43
        for (JCalendarItem jCalendarItem : items) {
44
            long t2 = jCalendarItem.getDtEnd().getTimeInMillis();
45
            long t1 = jCalendarItem.getDtStart().getTimeInMillis();
46
            int min = (int) ((t2 - t1) / (1000 * 60));
47
            totalMinutes += min;
48
        }
49
 
50
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
51
        String title = super.getTitle();
52
        title += " (au " + df.format(Calendar.getInstance().getTime()) + ") Total : ";
53
        String m = String.valueOf(totalMinutes % 60);
54
        if (m.length() < 2) {
55
            m = "0" + m;
56
        }
57
        title += totalMinutes / 60 + "h " + m + " m";
58
 
59
        return title;
60
    }
61
 
62
    @Override
63
    public String getDate(DateFormat df, JCalendarItem item) {
64
        String str = super.getDate(df, item);
65
        int week = item.getDtStart().get(Calendar.WEEK_OF_YEAR);
66
        return str + ", semaine " + week;
67
    }
68
 
69
    @Override
70
    public Font getLine1Font(JCalendarItem item) {
71
        return FONT_LINE;
72
    }
73
 
74
    @Override
75
    public Font getLine2Font(JCalendarItem item) {
76
        return FONT_LINE;
77
    }
78
}