Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / project / documents / table / gui / Statistics.java @ 40558

History | View | Annotate | Download (8.12 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.project.documents.table.gui;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.FlowLayout;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.util.ArrayList;
31
import java.util.List;
32

    
33
import javax.swing.JButton;
34
import javax.swing.JPanel;
35
import javax.swing.JScrollPane;
36
import javax.swing.JTextArea;
37

    
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.ui.mdiManager.IWindow;
40
import org.gvsig.andami.ui.mdiManager.WindowInfo;
41
import org.gvsig.app.project.documents.table.ExportStatisticsFile;
42
import org.gvsig.tools.swing.api.ToolsSwingLocator;
43

    
44
/**
45
 * @author Fernando Gonz?lez Cort?s
46
 */
47
public class Statistics extends JPanel implements IWindow {
48

    
49
    /**
50
         * 
51
         */
52
    private static final long serialVersionUID = 4121044001351869615L;
53
    private JScrollPane jScrollPane = null;
54
    private JTextArea txtStatistics = null;
55
    private JButton jButton = null;
56
    private JPanel jPanel = null;
57
    private JButton jButtonExport;
58

    
59
    // private Hashtable<String, Number> valores = new Hashtable<String,
60
    // Number>();
61
    // private TreeMap<String, Number> valores = new TreeMap<String, Number>();
62
    private List<MyObjectStatistics> valores =
63
        new ArrayList<MyObjectStatistics>();
64

    
65
    // private HashSet<String, Number> valores = new HashSet<String, Number>();
66
    /**
67
     * This is the default constructor
68
     */
69
    public Statistics() {
70
        super();
71
        initialize();
72
    }
73

    
74
    /**
75
     * This method initializes this
76
     * 
77
     * @return void
78
     */
79
    private void initialize() {
80
        this.setLayout(new BorderLayout());
81
        this.setSize(300, 200);
82
        this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
83
        this.add(getJPanel(), java.awt.BorderLayout.SOUTH);
84
    }
85

    
86
    /**
87
     * This method initializes jScrollPane
88
     * 
89
     * @return javax.swing.JScrollPane
90
     */
91
    private JScrollPane getJScrollPane() {
92
        if (jScrollPane == null) {
93
            jScrollPane = new JScrollPane();
94
            jScrollPane.setViewportView(getTxtStatistics());
95
        }
96
        return jScrollPane;
97
    }
98

    
99
    /**
100
     * This method initializes jTextArea
101
     * 
102
     * @return javax.swing.JTextArea
103
     */
104
    private JTextArea getTxtStatistics() {
105
        if (txtStatistics == null) {
106
            txtStatistics = new JTextArea();
107
        }
108
        return txtStatistics;
109
    }
110

    
111
    /**
112
     * This method initializes jButton
113
     * 
114
     * @return JButton
115
     */
116
    private JButton getJButton() {
117
        if (jButton == null) {
118
            jButton =
119
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
120
            jButton.setPreferredSize(new java.awt.Dimension(100, 18));
121
            jButton.setText(PluginServices.getText(this, "cerrar"));
122
            jButton.addActionListener(new ActionListener() {
123

    
124
                public void actionPerformed(ActionEvent e) {
125
                    PluginServices.getMDIManager().closeWindow(Statistics.this);
126
                }
127
            });
128
        }
129
        return jButton;
130
    }
131

    
132
    /**
133
     * This method initializes jButton
134
     * 
135
     * @return JButton
136
     *         - New JButton to Export the statistics
137
     */
138
    private JButton getJButtonExport() {
139
        if (jButtonExport == null) {
140
            jButtonExport =
141
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
142
            jButtonExport.setPreferredSize(new java.awt.Dimension(100, 18));
143
            jButtonExport.setText(PluginServices.getText(this, "exportar"));
144
            jButtonExport.addActionListener(new ActionListener() {
145

    
146
                public void actionPerformed(ActionEvent e) {
147
                    new ExportStatisticsFile(valores); // Class to export
148
                                                       // statistics to dbf or
149
                                                       // csv format
150
                }
151
            });// listener
152
        }
153
        return jButtonExport;
154
    }
155

    
156
    /**
157
     * This method initializes jPanel
158
     * 
159
     * @return javax.swing.JPanel
160
     */
161
    private JPanel getJPanel() {
162
        if (jPanel == null) {
163
            jPanel = new JPanel();
164
            FlowLayout layout = new FlowLayout();
165
            layout.setAlignment(FlowLayout.RIGHT);
166
            jPanel.setLayout(layout);
167
            jPanel.add(getJButtonExport(), null);
168
            jPanel.add(getJButton(), null);
169
        }
170
        return jPanel;
171
    }
172

    
173
    /**
174
     * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowInfo()
175
     */
176
    public WindowInfo getWindowInfo() {
177
        WindowInfo vi = new WindowInfo(WindowInfo.MODALDIALOG);
178
        vi.setTitle(PluginServices.getText(this, "estadisticas"));
179
        return vi;
180
    }
181

    
182
    /**
183
     * @param i
184
     * @param j
185
     * @param k
186
     * @param l
187
     * @param m
188
     * @param n
189
     * @param o
190
     * @param p
191
     */
192
    public void setStatistics(double media, double maximo, double minimo,
193
        double varianza, double desviacion, long numero, double ambito,
194
        double suma) {
195
        getTxtStatistics().setText(
196
            PluginServices.getText(this, "suma") + ": " + suma + "\n"
197
                + PluginServices.getText(this, "recuento") + ": " + numero
198
                + "\n" + PluginServices.getText(this, "media") + ": " + media
199
                + "\n" + PluginServices.getText(this, "maximo") + ": " + maximo
200
                + "\n" + PluginServices.getText(this, "minimo") + ": " + minimo
201
                + "\n" + PluginServices.getText(this, "ambito") + ": " + ambito
202
                + "\n" + PluginServices.getText(this, "varianza") + ": "
203
                + varianza + "\n"
204
                + PluginServices.getText(this, "desviacion_tipica") + ": "
205
                + desviacion);
206

    
207
        // Saving the statistics table values necessary in
208
        // ExportStatisticsFile.java
209
        valores.add(new MyObjectStatistics(
210
            PluginServices.getText(this, "suma"), suma));
211
        valores.add(new MyObjectStatistics(PluginServices.getText(this,
212
            "recuento"), numero));
213
        valores.add(new MyObjectStatistics(PluginServices
214
            .getText(this, "media"), media));
215
        valores.add(new MyObjectStatistics(PluginServices.getText(this,
216
            "maximo"), maximo));
217
        valores.add(new MyObjectStatistics(PluginServices.getText(this,
218
            "minimo"), minimo));
219
        valores.add(new MyObjectStatistics(PluginServices.getText(this,
220
            "ambito"), ambito));
221
        valores.add(new MyObjectStatistics(PluginServices.getText(this,
222
            "varianza"), varianza));
223
        valores.add(new MyObjectStatistics(PluginServices.getText(this,
224
            "desviacion_tipica"), desviacion));
225

    
226
    }
227

    
228
    /**
229
     * Class to create an object with key and value.
230
     * 
231
     * @author ?ngel Fraile Gri??n e-mail: angel.fraile@iver.es
232
     * 
233
     */
234

    
235
    public class MyObjectStatistics {
236

    
237
        private String key;
238
        private double value;
239

    
240
        public MyObjectStatistics(String key, double value) {
241
            this.key = key;
242
            this.value = value;
243
        }
244

    
245
        public String getKey() {
246
            return this.key;
247
        }
248

    
249
        public double getValue() {
250
            return this.value;
251
        }
252

    
253
    }
254

    
255
    public Object getWindowProfile() {
256
        return WindowInfo.DIALOG_PROFILE;
257
    }
258

    
259
}