Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / table / gui / Statistics.java @ 26064

History | View | Annotate | Download (5.34 KB)

1
package com.iver.cit.gvsig.project.documents.table.gui;
2

    
3
import java.awt.BorderLayout;
4
import java.awt.FlowLayout;
5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
7
import java.util.Hashtable;
8

    
9
import javax.swing.JPanel;
10
import javax.swing.JScrollPane;
11
import javax.swing.JTextArea;
12

    
13
import org.gvsig.gui.beans.swing.JButton;
14

    
15
import com.iver.andami.PluginServices;
16
import com.iver.andami.ui.mdiManager.IWindow;
17
import com.iver.andami.ui.mdiManager.WindowInfo;
18
import com.iver.cit.gvsig.project.documents.table.ExportStatisticsFile;
19
/**
20
 * @author Fernando Gonz?lez Cort?s
21
 */
22
public class Statistics extends JPanel implements IWindow {
23

    
24

    
25
        private static final long serialVersionUID = 1L;
26
        private JScrollPane jScrollPane = null;
27
        private JTextArea txtStatistics = null;
28
        private JButton jButton = null;
29
        private JPanel jPanel = null;
30
        private JButton jButtonExport;
31
        
32
        private Hashtable<String, Number> valores = new Hashtable<String, Number>();
33
        /**
34
         * This is the default constructor
35
         */
36
        public Statistics() {
37
                super();
38
                initialize();
39
        }
40
        /**
41
         * This method initializes this
42
         * 
43
         * @return void
44
         */
45
        private  void initialize() {
46
                this.setLayout(new BorderLayout());
47
                this.setSize(300,200);
48
                this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
49
                this.add(getJPanel(), java.awt.BorderLayout.SOUTH);
50
        }
51
        /**
52
         * This method initializes jScrollPane        
53
         *         
54
         * @return javax.swing.JScrollPane        
55
         */    
56
        private JScrollPane getJScrollPane() {
57
                if (jScrollPane == null) {
58
                        jScrollPane = new JScrollPane();
59
                        jScrollPane.setViewportView(getTxtStatistics());
60
                }
61
                return jScrollPane;
62
        }
63
        /**
64
         * This method initializes jTextArea        
65
         *         
66
         * @return javax.swing.JTextArea        
67
         */    
68
        private JTextArea getTxtStatistics() {
69
                if (txtStatistics == null) {
70
                        txtStatistics = new JTextArea();                        
71
                }
72
                return txtStatistics;
73
        }
74
        /**
75
         * This method initializes jButton        
76
         *         
77
         * @return JButton        
78
         */    
79
        private JButton getJButton() {
80
                if (jButton == null) {
81
                        jButton = new JButton();
82
                        jButton.setPreferredSize(new java.awt.Dimension(100,18));
83
                        jButton.setText(PluginServices.getText(this, "cerrar"));
84
                        jButton.addActionListener(new ActionListener() {
85
                public void actionPerformed(ActionEvent e) {
86
                    PluginServices.getMDIManager().closeWindow(Statistics.this);
87
                }
88
            });
89
                }
90
                return jButton;
91
        }
92
        
93
        /**
94
         * This method initializes jButton
95
         *         
96
         * @return JButton        
97
         *                                 - New JButton to Export the statistics
98
         */    
99
        private JButton getJButtonExport() {
100
                if (jButtonExport == null) {
101
                        jButtonExport = new JButton();
102
                        jButtonExport.setPreferredSize(new java.awt.Dimension(100,18));
103
                        jButtonExport.setText(PluginServices.getText(this, "exportar"));
104
                        jButtonExport.addActionListener(new ActionListener() {
105
                                public void actionPerformed(ActionEvent e) {
106
                                        new ExportStatisticsFile(valores); // Class to export statistics to dbf or csv format
107
                                }
108
            });//listener
109
                }
110
                return jButtonExport;
111
        }
112
        
113
        /**
114
         * This method initializes jPanel        
115
         *         
116
         * @return javax.swing.JPanel        
117
         */    
118
        private JPanel getJPanel() {
119
                if (jPanel == null) {
120
                        jPanel = new JPanel();
121
                        FlowLayout layout = new FlowLayout();
122
                        layout.setAlignment(FlowLayout.RIGHT);
123
                        jPanel.setLayout(layout);
124
                        jPanel.add(getJButtonExport(),null);
125
                        jPanel.add(getJButton(), null);
126
                }
127
                return jPanel;
128
        }
129
    /**
130
     * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
131
     */
132
    public WindowInfo getWindowInfo() {
133
        WindowInfo vi = new WindowInfo(WindowInfo.MODALDIALOG);
134
        vi.setTitle(PluginServices.getText(this, "estadisticas"));
135
        return vi;
136
    }
137
    /**
138
     * @param i
139
     * @param j
140
     * @param k
141
     * @param l
142
     * @param m
143
     * @param n
144
     * @param o
145
     * @param p
146
     */
147
    public void setStatistics(double media, double maximo, double minimo, double varianza, double desviacion, int numero, double ambito, double suma) {
148
        getTxtStatistics().setText(PluginServices.getText(this, "suma") + ": " + suma + "\n"+
149
                PluginServices.getText(this, "recuento") + ": " + numero + "\n"+
150
                PluginServices.getText(this, "media") + ": " + media + "\n"+
151
                PluginServices.getText(this, "maximo") + ": " + maximo + "\n"+
152
                PluginServices.getText(this, "minimo") + ": " + minimo + "\n"+
153
                PluginServices.getText(this, "ambito") + ": " + ambito + "\n"+
154
                PluginServices.getText(this, "varianza") + ": " + varianza + "\n"+
155
                PluginServices.getText(this, "desviacion_tipica") + ": " + desviacion);
156
                        
157
                        // Saving the statistics table values necessary in ExportStatisticsFile.java
158
                        valores.put(PluginServices.getText(this, "suma"),suma);
159
                        Double num = numero * 1.0;// convert to double
160
                        valores.put(PluginServices.getText(this, "recuento"),num);
161
                        valores.put(PluginServices.getText(this, "media"),media);
162
                        valores.put(PluginServices.getText(this, "maximo"),maximo);
163
                        valores.put(PluginServices.getText(this, "minimo"),minimo);
164
                        valores.put(PluginServices.getText(this, "ambito"),ambito);
165
                        valores.put(PluginServices.getText(this, "varianza"),varianza);
166
                        valores.put(PluginServices.getText(this, "desviacion_tipica"),desviacion);
167
        
168
    }
169
    
170
        public Object getWindowProfile() {
171
                return WindowInfo.DIALOG_PROFILE;
172
        }
173
}