OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 158 | 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);
181 ilm 14
    private List<JCalendarItem> itemsToWork;
112 ilm 15
 
181 ilm 16
    public OperationCalendarItemPrinter(String title, List<JCalendarItem> items, PageFormat pf, List<JCalendarItem> itemsToWork) {
112 ilm 17
        super(title, items, pf);
181 ilm 18
        this.itemsToWork = itemsToWork;
112 ilm 19
    }
20
 
21
    @Override
22
    public String getLine1Text(JCalendarItem item) {
23
        final String siteName = ((JCalendarItemDB) item).getSiteName().toUpperCase();
24
        final String siteComment = ((JCalendarItemDB) item).getSiteComment();
25
        if (siteComment != null && !siteComment.isEmpty()) {
26
            return siteName + " - " + siteComment;
27
        }
28
        return siteName;
29
    }
30
 
31
    @Override
32
    public String getLine2Text(JCalendarItem item) {
33
        final String type = ((JCalendarItemDB) item).getType();
34
        final String description = item.getDescription();
35
        if (description != null && !description.isEmpty()) {
36
            return type + " - " + description;
37
        }
38
        return type;
39
    }
40
 
41
    @Override
42
    public String getTitle() {
181 ilm 43
        final List<JCalendarItem> items = this.itemsToWork;
112 ilm 44
        int totalMinutes = 0;
45
        for (JCalendarItem jCalendarItem : items) {
46
            long t2 = jCalendarItem.getDtEnd().getTimeInMillis();
47
            long t1 = jCalendarItem.getDtStart().getTimeInMillis();
48
            int min = (int) ((t2 - t1) / (1000 * 60));
49
            totalMinutes += min;
50
        }
51
 
52
        DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
53
        String title = super.getTitle();
54
        title += " (au " + df.format(Calendar.getInstance().getTime()) + ") Total : ";
55
        String m = String.valueOf(totalMinutes % 60);
56
        if (m.length() < 2) {
57
            m = "0" + m;
58
        }
59
        title += totalMinutes / 60 + "h " + m + " m";
60
 
61
        return title;
62
    }
63
 
64
    @Override
65
    public String getDate(DateFormat df, JCalendarItem item) {
66
        String str = super.getDate(df, item);
67
        int week = item.getDtStart().get(Calendar.WEEK_OF_YEAR);
68
        return str + ", semaine " + week;
69
    }
70
 
71
    @Override
72
    public Font getLine1Font(JCalendarItem item) {
73
        return FONT_LINE;
74
    }
75
 
76
    @Override
77
    public Font getLine2Font(JCalendarItem item) {
78
        return FONT_LINE;
79
    }
80
}