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
package timeflow.app.ui;
 
import timeflow.model.*;
import timeflow.app.ui.filter.FilterControlPanel;
import timeflow.data.db.*;
import timeflow.data.db.filter.ActFilter;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.*;
 
public class StatusPanel extends ModelPanel
{
   JLabel numLabel=new JLabel("")
   {
       public Dimension getPreferredSize()
       {
           return new Dimension(30,25);
       }
   };
   JLabel filterLabel=new JLabel("")
   {
       public Dimension getPreferredSize()
       {
           return new Dimension(30,25);
       }
   };
   
   static final DecimalFormat niceFormat=new DecimalFormat("###,###");
   
   public StatusPanel(TFModel model, final FilterControlPanel filterControls) {
       super(model);    
       setLayout(new BorderLayout());
       setBackground(new Color(245, 245, 245));
       setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 15));
       JPanel center=new JPanel();
       center.setBackground(getBackground());
       center.setLayout(new GridLayout(2,1));
       add(center, BorderLayout.CENTER);
       
       center.add(numLabel);
       numLabel.setFont(model.getDisplay().plain());
       numLabel.setBackground(new Color(245, 245, 245));
       
       JPanel bottom=new JPanel();
       center.add(bottom);
       bottom.setLayout(new BorderLayout());
       bottom.add(filterLabel, BorderLayout.CENTER);
       bottom.setBackground(new Color(245, 245, 245));
       filterLabel.setFont(model.getDisplay().plain());
       filterLabel.setBackground(new Color(245, 245, 245));
       filterLabel.setForeground(Color.red);
       
       JPanel clearPanel=new JPanel();
       clearPanel.setBackground(new Color(245, 245, 245));
       clearPanel.setLayout(new GridLayout(1,1));
       JButton clear=new JButton(new ImageIcon("images/button_clear_all.gif"));
       clear.setBorder(null);
       clear.addActionListener(new ActionListener() {
           @Override
           public void actionPerformed(ActionEvent e) {
               filterControls.clearFilters();
           }
       });
       clearPanel.add(clear);
       bottom.add(clearPanel, BorderLayout.EAST);
       
       add(new DottedLine(), BorderLayout.SOUTH);
   }
 
   @Override
   public void note(TFEvent e) {
       
       ActDB db=getModel().getDB();
       if (db==null || db.size()==0)
       {
           numLabel.setForeground(new Color(245,245,245));//Color.gray);
           numLabel.setText("No data");
           return;
       }
       int numTotal=db.size();
       ActList acts=getModel().getActs();
       int numShown=acts.size();
       filterLabel.setText(numShown<numTotal ? " Filters applied" : " Not Filtering");
       filterLabel.setForeground(numShown==numTotal ? Color.lightGray : Color.red);
       numLabel.setForeground(numShown==0 ? Color.red : Color.darkGray);
       String plural=(numTotal==1 ? "" : "s");
       if (numShown==numTotal)
           numLabel.setText(" Showing All "+niceFormat.format(numTotal)+" Event"+plural);
       else
           numLabel.setText(" Showing "+niceFormat.format(numShown)
                   +" / "+niceFormat.format(numTotal)+" Event"+ plural);
       repaint();
   }
 
}