Normand Briere
2018-07-07 e416acb9b012b17d1efe49ad2199ea7132d874d1
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
package timeflow.app.ui;
 
import timeflow.model.*;
import timeflow.app.ui.filter.FilterCategoryPanel;
import timeflow.data.db.*;
import timeflow.data.db.filter.FieldValueFilter;
import timeflow.data.db.filter.ValueFilter;
import timeflow.data.time.*;
 
import timeflow.util.*;
 
import java.awt.*;
 
import javax.swing.JLabel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
 
public class ColorLegendPanel extends ModelPanel {
   
 
   Field oldColor;
 
   public ColorLegendPanel(TFModel model)
   {
       super(model);
       setBackground(Color.white);
       setLayout(new GridLayout(1,1));
   }
   
   @Override
   public void note(TFEvent e) {
       Field color=getModel().getColorField();
       if (color!=null && color!=oldColor)
       {
               removeAll();
               final FilterCategoryPanel p=new FilterCategoryPanel("Color Legend: '"+color.getName()+"'", 
                       color, this);
               add(p);
               Bag<String> data=DBUtils.countValues(getModel().getDB().all(), color);
               p.setData(data);
               p.dataList.addListSelectionListener(new ListSelectionListener() {                
                   @Override
                   public void valueChanged(ListSelectionEvent e) {
                       ValueFilter f=(ValueFilter)p.defineFilter();    
                       getModel().setGrayFilter(f, this);
                   }
               });
               
               oldColor=color;
               revalidate();
               return;
       } else if (color==null)
       {
           removeAll();
       }
       repaint();
   }
   
   public Dimension getPreferredSize()
   {
       return new Dimension(200,400);
   }
}