Normand Briere
2018-07-07 09ddd38fd4a8a7100c834a5e976f4796fae53541
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package timeflow.vis.calendar;
 
import java.awt.*;
import java.util.Collection;
 
 
import timeflow.model.*;
import timeflow.vis.*;
import timeflow.data.time.*;
import timeflow.data.db.*;
 
public class CalendarVisuals {
   VisualEncoder encoder;
   TFModel model;
   Rectangle bounds=new Rectangle();
   public Grid grid;
   
   public enum Layout {DAY, WEEK, MONTH, YEAR};
   private Layout layoutStyle=Layout.DAY;
   
   public enum DrawStyle {LABEL, ICON};
   DrawStyle drawStyle=DrawStyle.ICON;
   
   public enum FitStyle {LOOSE, TIGHT};
   FitStyle fitStyle=FitStyle.LOOSE;
   
   public CalendarVisuals(TFModel model)
   {
       this.model=model;
       encoder=new VisualEncoder(model);
   }    
   
   public void render(Graphics2D g, Collection<Mouseover> objectLocations)
   {
       grid.render(g, model.getDisplay(), bounds, this, objectLocations);
   }    
   
   public Interval getGlobalInterval()
   {
       return DBUtils.range(model.getDB().all(), VirtualField.START);
   }
   
   public Rectangle getBounds() {
       return bounds;
   }
 
   public void setBounds(int x, int y, int w, int h) {
       bounds.setBounds(x,y,w,h);
       if (grid==null)
           makeGrid(true);
   }
   
   public void setDrawStyle(DrawStyle drawStyle)
   {
       this.drawStyle=drawStyle;
   }
   
   public void setLayoutStyle(Layout layoutStyle)
   {
       this.layoutStyle=layoutStyle;
       makeGrid(true);
   }
   
   public void setFitStyle(FitStyle fitStyle)
   {
       this.fitStyle=fitStyle;
       makeGrid(true);
   }
   
   public void makeGrid(boolean fresh)
   {
       Interval interval=getGlobalInterval();
       int dy=0;
       if (grid!=null)
           dy=grid.dy;
       switch(layoutStyle)
       {
           case DAY: grid=new Grid(TimeUnit.WEEK, TimeUnit.DAY_OF_WEEK, interval); break;
           case WEEK: grid=new Grid(TimeUnit.multipleWeeks(8), TimeUnit.WEEK, interval); break;
           case MONTH: grid=new Grid(TimeUnit.YEAR, TimeUnit.MONTH, interval); break;
           case YEAR: grid=new Grid(TimeUnit.DECADE, TimeUnit.YEAR, interval); 
       }        
       grid.makeCells(encoder.getVisualActs());
       if (!fresh)
           grid.dy=dy;
   }
 
   public void init()
   {
       note(new TFEvent(TFEvent.Type.DATABASE_CHANGE,null));
   }
   
   public void initAllButGrid()
   {
       encoder.createVisualActs();
       encoder.apply();
   }
   
   public void note(TFEvent e) {
       if (e.affectsRowSet())
       {
           encoder.createVisualActs();
       }
 
       updateVisuals(e.affectsRowSet());
   }
       
   public void updateVisuals(boolean fresh)
   {
       encoder.apply();
       makeGrid(fresh);
   }
}