OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
137 ilm 1
package org.jopencalendar.ui;
2
 
3
import java.awt.Color;
4
import java.awt.Component;
5
import java.awt.Graphics;
6
import java.util.Calendar;
7
import java.util.List;
8
 
9
import javax.swing.JComponent;
10
import javax.swing.JPanel;
11
import javax.swing.JTable;
12
import javax.swing.table.DefaultTableCellRenderer;
13
 
14
import org.jopencalendar.model.JCalendarItem;
15
 
16
public class MonthActivityStatesCellRenderer extends DefaultTableCellRenderer {
17
    private int squareSize;
18
 
19
    MonthActivityStatesCellRenderer(int squareSize) {
20
        this.squareSize = squareSize;
21
    }
22
 
23
    @Override
24
    public Component getTableCellRendererComponent(final JTable table, final Object value, final boolean isSelected, boolean hasFocus, final int row, final int column) {
25
        JComponent c = new JPanel() {
26
            @Override
27
            public void paint(Graphics g) {
28
                MonthActivityStates m = (MonthActivityStates) value;
29
                if (!isSelected) {
30
                    g.setColor(Color.WHITE);
31
                } else {
32
                    g.setColor(table.getSelectionBackground());
33
                }
34
                final int h = getHeight();
35
                g.fillRect(0, 0, getWidth(), h);
178 ilm 36
                // handle JTable$AccessibleJTable.getAccessibleChild()
37
                if (m == null)
38
                    return;
137 ilm 39
                // Week delimiters
40
                List<Integer> lIndexes = m.getMondayIndex();
41
 
42
                if (isSelected) {
43
                    g.setColor(Color.WHITE);
44
                } else {
45
                    g.setColor(Color.LIGHT_GRAY);
46
                }
47
                // Draw Week number
48
                if (row % 5 == 0) {
49
                    for (Integer integer : lIndexes) {
50
                        Calendar c = Calendar.getInstance();
51
                        c.clear();
52
                        c.set(Calendar.YEAR, m.getYear());
53
                        c.set(Calendar.MONTH, m.getMonth());
54
                        c.set(Calendar.DAY_OF_MONTH, integer);
55
                        int w = c.get(Calendar.WEEK_OF_YEAR) + 1;
56
                        int x = 4 + integer * squareSize;
57
                        int y = 16;
58
                        g.drawString(String.valueOf(w), x, y);
59
                    }
60
                }
61
                //
62
                for (Integer integer : lIndexes) {
63
 
64
                    int x = integer * squareSize;
65
                    if (x != 0) {
66
                        g.drawLine(x, 0, x, h / 2 - 2);
67
                        g.drawLine(x, h / 2 + 4, x, h - 4);
68
                    }
69
                }
70
                // Days
71
                List<List<JCalendarItem>> l = m.getList();
72
                if (l != null) {
73
                    int x = 0;
74
 
75
                    for (List<JCalendarItem> list : l) {
76
                        if (list != null) {
77
                            int y = 2;
78
                            int sh = (h - 1) / list.size();
79
                            for (JCalendarItem jCalendarItem : list) {
80
                                g.setColor(jCalendarItem.getColor());
81
                                g.fillRect(x, y, squareSize - 1, sh);
82
                                y += sh;
83
                            }
84
 
85
                        }
86
                        x += squareSize;
87
                    }
88
                }
89
 
90
            }
91
        };
92
 
93
        return c;
94
    }
95
}