Revision 26241

View differences:

branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/project/document/table/gui/Statistics.java
1
package org.gvsig.project.document.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.ArrayList;
8
import java.util.List;
9

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

  
14
import org.gvsig.gui.beans.swing.JButton;
15
import org.gvsig.project.document.table.ExportStatisticsFile;
16

  
17
import com.iver.andami.PluginServices;
18
import com.iver.andami.ui.mdiManager.IWindow;
19
import com.iver.andami.ui.mdiManager.WindowInfo;
20
/**
21
 * @author Fernando Gonz?lez Cort?s
22
 */
23
public class Statistics extends JPanel implements IWindow {
24

  
25
	private JScrollPane jScrollPane = null;
26
	private JTextArea txtStatistics = null;
27
	private JButton jButton = null;
28
	private JPanel jPanel = null;
29
private JButton jButtonExport;
30

  
31
//	private Hashtable<String, Number> valores = new Hashtable<String, Number>();
32
	//private TreeMap<String, Number> valores = new TreeMap<String, Number>();
33
	private List<MyObjectStatistics> valores = new ArrayList<MyObjectStatistics>();
34
//	private HashSet<String, Number> valores = new HashSet<String, Number>();
35
	/**
36
	 * This is the default constructor
37
	 */
38
	public Statistics() {
39
		super();
40
		initialize();
41
	}
42
	/**
43
	 * This method initializes this
44
	 *
45
	 * @return void
46
	 */
47
	private  void initialize() {
48
		this.setLayout(new BorderLayout());
49
		this.setSize(300,200);
50
		this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
51
		this.add(getJPanel(), java.awt.BorderLayout.SOUTH);
52
	}
53
	/**
54
	 * This method initializes jScrollPane
55
	 *
56
	 * @return javax.swing.JScrollPane
57
	 */
58
	private JScrollPane getJScrollPane() {
59
		if (jScrollPane == null) {
60
			jScrollPane = new JScrollPane();
61
			jScrollPane.setViewportView(getTxtStatistics());
62
		}
63
		return jScrollPane;
64
	}
65
	/**
66
	 * This method initializes jTextArea
67
	 *
68
	 * @return javax.swing.JTextArea
69
	 */
70
	private JTextArea getTxtStatistics() {
71
		if (txtStatistics == null) {
72
			txtStatistics = new JTextArea();
73
		}
74
		return txtStatistics;
75
	}
76
	/**
77
	 * This method initializes jButton
78
	 *
79
	 * @return JButton
80
	 */
81
	private JButton getJButton() {
82
		if (jButton == null) {
83
			jButton = new JButton();
84
			jButton.setPreferredSize(new java.awt.Dimension(100,18));
85
			jButton.setText(PluginServices.getText(this, "cerrar"));
86
			jButton.addActionListener(new ActionListener() {
87
                public void actionPerformed(ActionEvent e) {
88
                    PluginServices.getMDIManager().closeWindow(Statistics.this);
89
                }
90
            });
91
		}
92
		return jButton;
93
	}
94
	/**
95
	 * This method initializes jButton
96
	 *
97
	 * @return JButton
98
	 * 				- New JButton to Export the statistics
99
	 */
100
	private JButton getJButtonExport() {
101
		if (jButtonExport == null) {
102
			jButtonExport = new JButton();
103
			jButtonExport.setPreferredSize(new java.awt.Dimension(100,18));
104
			jButtonExport.setText(PluginServices.getText(this, "exportar"));
105
			jButtonExport.addActionListener(new ActionListener() {
106
				public void actionPerformed(ActionEvent e) {
107
					new ExportStatisticsFile(valores); // Class to export statistics to dbf or csv format
108
				}
109
            });//listener
110
		}
111
		return jButtonExport;
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.add(new MyObjectStatistics(PluginServices.getText(this, "suma"),suma));
159
		valores.add(new MyObjectStatistics(PluginServices.getText(this, "recuento"),numero));
160
		valores.add(new MyObjectStatistics(PluginServices.getText(this, "media"),media));
161
		valores.add(new MyObjectStatistics(PluginServices.getText(this, "maximo"),maximo));
162
		valores.add(new MyObjectStatistics(PluginServices.getText(this, "minimo"),minimo));
163
		valores.add(new MyObjectStatistics(PluginServices.getText(this, "ambito"),ambito));
164
		valores.add(new MyObjectStatistics(PluginServices.getText(this, "varianza"),varianza));
165
		valores.add(new MyObjectStatistics(PluginServices.getText(this, "desviacion_tipica"),desviacion));
166

  
167

  
168
    }
169
    /**
170
	 * Class to create an object with key and value.
171
	 *
172
	 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
173
	 *
174
	 */
175

  
176
	public class MyObjectStatistics{
177
		private String key;
178
		private double value;
179
		public MyObjectStatistics(String key, double value) {
180
			this.key = key;
181
			this.value = value;
182
		}
183

  
184
		public String getKey() {
185
			return this.key;
186
		}
187
		public double getValue() {
188
			return this.value;
189
		}
190

  
191
	}
192
    }
0 193

  
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/project/document/table/gui/JoinWizardController.java
1
/**
2
 *
3
 */
4
package org.gvsig.project.document.table.gui;
5

  
6
import java.awt.Dimension;
7
import java.awt.event.ItemEvent;
8
import java.awt.event.ItemListener;
9

  
10
import javax.swing.ImageIcon;
11

  
12
import org.gvsig.fmap.dal.exception.ReadException;
13
import org.gvsig.fmap.dal.feature.FeatureStore;
14
import org.gvsig.project.document.table.FeatureTableDocument;
15

  
16
import jwizardcomponent.FinishAction;
17

  
18
import com.iver.andami.PluginServices;
19
import com.iver.andami.messages.NotificationManager;
20
import com.iver.cit.gvsig.TableOperations;
21
import com.iver.cit.gvsig.gui.simpleWizard.SimpleWizard;
22
import com.iver.cit.gvsig.project.documents.table.FieldSelectionModel;
23

  
24
public class JoinWizardController {
25
	private final TableOperations tableOperations;
26

  
27
	/**
28
	 * @param tableOperations
29
	 */
30
	public JoinWizardController(TableOperations tableOperations) {
31
		this.tableOperations = tableOperations;
32
	}
33

  
34

  
35
	public void runWizard(FeatureTableDocument[] pts) {
36
		// create wizard
37
		ImageIcon logo = PluginServices.getIconTheme().get("table-join");
38
		final SimpleWizard wizard = new SimpleWizard(logo);
39
		wizard.getWindowInfo().setTitle(PluginServices.getText(this, "Table_Join"));
40

  
41
		// create first step (source table)
42
		final TableWizardStep srcTableWzrd = new TableWizardStep(wizard.getWizardComponents(), "Title" );
43
		srcTableWzrd.getHeaderLbl().setText(PluginServices.getText(this,"Source_table_options"));
44
		srcTableWzrd.getTableNameLbl().setText(PluginServices.getText(this,"Source_table_"));
45
		srcTableWzrd.getFieldNameLbl().setText(PluginServices.getText(this,"Field_to_use_for_JOIN_"));
46
		srcTableWzrd.getFieldPrefixLbl().setText(PluginServices.getText(this,"Field_prefix_"));
47
		srcTableWzrd.getTableNameCmb().addItemListener(
48
				new ItemListener() {
49

  
50
					public void itemStateChanged(ItemEvent e) {
51
						if (e.getStateChange()==e.SELECTED) {
52
							FeatureTableDocument pt = (FeatureTableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
53

  
54
							try {
55
								srcTableWzrd.setFieldModel(new FieldSelectionModel(
56
										pt.getStore(),
57
										PluginServices.getText(this, "seleccione_campo_enlace"),
58
										-1));
59
								srcTableWzrd.getFieldPrefixTxt().setText(tableOperations.sanitizeFieldName(pt.getName()));
60
							} catch (ReadException e1) {
61
								NotificationManager.addError(
62
										PluginServices.getText(this, "Error_getting_table_fields"),
63
										e1);
64
							}
65
						}
66

  
67
					}
68
				}
69
		);
70
		for (int i=0; i<pts.length; i++) {
71
			srcTableWzrd.getTableNameCmb().addItem(pts[i]);
72
		}
73

  
74
		// create second step (target table)
75
		final TableWizardStep targTableWzrd = new TableWizardStep(wizard.getWizardComponents(), "Title" );
76
		targTableWzrd.getHeaderLbl().setText(PluginServices.getText(this,"Target_table_options"));
77
		targTableWzrd.getTableNameLbl().setText(PluginServices.getText(this,"Target_table_"));
78
		targTableWzrd.getFieldNameLbl().setText(PluginServices.getText(this,"Field_to_use_for_JOIN_"));
79
		targTableWzrd.getFieldPrefixLbl().setText(PluginServices.getText(this,"Field_prefix_"));
80
		targTableWzrd.getTableNameCmb().addItemListener(
81
				new ItemListener() {
82

  
83
					public void itemStateChanged(ItemEvent e) {
84
						if (e.getStateChange()==e.SELECTED) {
85
							try {
86
								//tabla
87
								FeatureTableDocument sourcePt = (FeatureTableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
88
								FeatureTableDocument targetPt = (FeatureTableDocument) targTableWzrd.getTableNameCmb().getSelectedItem();
89
								targTableWzrd.getFieldPrefixTxt().setText(tableOperations.sanitizeFieldName(targetPt.getName()));
90

  
91
								//?ndice del campo
92
								FeatureStore sds = sourcePt.getStore();
93
								String fieldName = (String) srcTableWzrd.getFieldNameCmb().getSelectedItem();
94
								int fieldIndex = sds.getFieldIndexByName(fieldName);
95
								if (fieldIndex!=-1) {
96
									int type = sds.getFieldType(fieldIndex);
97
									targTableWzrd.setFieldModel(new FieldSelectionModel(
98
											targetPt.getModelo().getRecordset(),
99
											PluginServices.getText(this, "seleccione_campo_enlace"),
100
											type));
101
								}
102
								else {
103
									NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields")
104
											, new Exception());
105
								}
106
							} catch (ReadException e2) {
107
								NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields"),
108
										e2);
109
							}
110
						}
111

  
112
					}
113
				}
114
		);
115
		for (int i=0; i<pts.length; i++) {
116
			targTableWzrd.getTableNameCmb().addItem(pts[i]);
117
		}
118

  
119
		// add steps and configure wizard
120
		wizard.getWizardComponents().addWizardPanel(srcTableWzrd);
121
		wizard.getWizardComponents().addWizardPanel(targTableWzrd);
122
		wizard.getWizardComponents().updateComponents();
123
		wizard.setSize(new Dimension(450, 230));
124
		wizard.getWizardComponents().setFinishAction(new FinishAction(wizard.getWizardComponents()) {
125
			public void performAction() {
126
				FeatureTableDocument sourceProjectTable = (FeatureTableDocument) srcTableWzrd.getTableNameCmb().getSelectedItem();
127
				String field1 = (String) srcTableWzrd.getFieldNameCmb().getSelectedItem();
128
				String prefix1 = srcTableWzrd.getFieldPrefixTxt().getText();
129
				if (sourceProjectTable==null || field1==null || prefix1 == null) {
130
					NotificationManager.showMessageError(
131
							PluginServices.getText(this, "Join_parameters_are_incomplete"), new InvalidParameterException());
132
					return;
133
				}
134
				FeatureTableDocument targetProjectTable = (FeatureTableDocument) targTableWzrd.getTableNameCmb().getSelectedItem();
135
				String field2 = (String) targTableWzrd.getFieldNameCmb().getSelectedItem();
136
				String prefix2 = targTableWzrd.getFieldPrefixTxt().getText();
137
				if (targetProjectTable==null || field2==null || prefix2 == null) {
138
					NotificationManager.showMessageError(
139
							PluginServices.getText(this, "Join_parameters_are_incomplete"), new InvalidParameterException());
140
					return;
141
				}
142
				tableOperations.execJoin(sourceProjectTable, field1, prefix1, targetProjectTable, field2, prefix2);
143

  
144
				PluginServices.getMDIManager().closeWindow(wizard);
145
			}
146
		}
147
		);
148

  
149
		// show the wizard
150
		PluginServices.getMDIManager().addWindow(wizard);
151
	}
152

  
153
	private class InvalidParameterException extends Exception {
154
	}
155
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/project/document/table/gui/TableWizardStep.java
1
/**
2
 *
3
 */
4
package org.gvsig.project.document.table.gui;
5

  
6
import java.awt.Font;
7
import java.awt.GridBagConstraints;
8
import java.awt.GridBagLayout;
9
import java.awt.Insets;
10

  
11
import javax.swing.JLabel;
12
import javax.swing.JTextField;
13

  
14
import jwizardcomponent.JWizardComponents;
15
import jwizardcomponent.JWizardPanel;
16

  
17
import com.iver.andami.PluginServices;
18
import com.iver.andami.messages.NotificationManager;
19
import com.iver.utiles.swing.JComboBox;
20
import com.iver.utiles.swing.objectSelection.ObjectSelectionModel;
21

  
22
public class TableWizardStep extends JWizardPanel {
23
	private JLabel lbl_header = null;
24
	private static final long serialVersionUID = 1L;
25
	private JLabel tableNameLbl = null;
26
	private JComboBox tableNameCmb = null;
27
	private JLabel fieldNameLbl = null;
28
	private JComboBox fieldNameCmb = null;
29
	private JLabel fieldPrefixLbl = null;
30
	private JTextField fieldPrefixTxt = null;
31

  
32

  
33
	public TableWizardStep(JWizardComponents wizardComponents, String title) {
34
		super(wizardComponents, title);
35
		initialize();
36
	}
37

  
38
	public void setTableModel(ObjectSelectionModel model) {
39
		getTableNameCmb().removeAllItems();
40
		Object[] tableNames;
41
		try {
42
			tableNames = model.getObjects();
43
			for (int i=0; i<tableNames.length; i++) {
44
				getTableNameCmb().addItem(tableNames[i]);
45
			}
46
		} catch (Exception e) {
47
			NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields"), e);
48
		}
49
	}
50

  
51
	public void setFieldModel(ObjectSelectionModel model) {
52
		getFieldNameCmb().removeAllItems();
53
		Object[] fieldNames;
54
		try {
55
			fieldNames = model.getObjects();
56
			for (int i=0; i<fieldNames.length; i++) {
57
				getFieldNameCmb().addItem(fieldNames[i]);
58
			}
59
		} catch (Exception e) {
60
			NotificationManager.addError(PluginServices.getText(this, "Error_getting_table_fields"), e);
61
		}
62

  
63
	}
64

  
65
	private void initialize() {
66
		this.setLayout(new GridBagLayout());
67

  
68
		GridBagConstraints constraints = new GridBagConstraints();
69
		constraints.gridx = 0;
70
		constraints.gridy = 0;
71
		constraints.gridwidth = 2;
72
		constraints.anchor = GridBagConstraints.NORTH;
73
		constraints.fill = GridBagConstraints.HORIZONTAL;
74
		constraints.weightx = 1.0;
75
		constraints.weighty = 0.0;
76
		constraints.insets = new Insets(4,10,8,4);
77
		this.add(getHeaderLbl(), constraints);
78

  
79
		constraints.gridx = 0;
80
		constraints.gridy = 1;
81
		constraints.gridwidth = 1;
82
		constraints.anchor = GridBagConstraints.NORTHWEST;
83
		constraints.fill = GridBagConstraints.NONE;
84
		constraints.weightx = 0.0;
85
		constraints.weighty = 0.0;
86
		constraints.insets = new Insets(4,10,4,6);
87
		this.add(getTableNameLbl(), constraints);
88

  
89
		constraints.gridx = 1;
90
		constraints.gridy = 1;
91
		constraints.gridwidth = 1;
92
		constraints.anchor = GridBagConstraints.NORTHWEST;
93
		constraints.fill = GridBagConstraints.HORIZONTAL;
94
		constraints.weightx = 0.5;
95
		constraints.weighty = 0.0;
96
		this.add(getTableNameCmb(), constraints);
97

  
98
		constraints.gridx = 0;
99
		constraints.gridy = 2;
100
		constraints.gridwidth = 1;
101
		constraints.anchor = GridBagConstraints.NORTHWEST;
102
		constraints.fill = GridBagConstraints.NONE;
103
		constraints.weightx = 0.0;
104
		constraints.weighty = 0.0;
105
		constraints.insets = new Insets(4,10,4,6);
106
		this.add(getFieldNameLbl(), constraints);
107

  
108
		constraints.gridx = 1;
109
		constraints.gridy = 2;
110
		constraints.gridwidth = 1;
111
		constraints.anchor = GridBagConstraints.NORTHWEST;
112
		constraints.fill = GridBagConstraints.HORIZONTAL;
113
		constraints.weightx = 0.5;
114
		constraints.weighty = 0.0;
115
		this.add(getFieldNameCmb(), constraints);
116

  
117
		constraints.gridx = 0;
118
		constraints.gridy = 3;
119
		constraints.gridwidth = 1;
120
		constraints.anchor = GridBagConstraints.NORTHWEST;
121
		constraints.fill = GridBagConstraints.NONE;
122
		constraints.weightx = 0.0;
123
		constraints.weighty = 0.0;
124
		constraints.insets = new Insets(4,10,4,6);
125
		this.add(getFieldPrefixLbl(), constraints);
126

  
127
		constraints.gridx = 1;
128
		constraints.gridy = 3;
129
		constraints.gridwidth = 1;
130
		constraints.anchor = GridBagConstraints.NORTHWEST;
131
		constraints.fill = GridBagConstraints.HORIZONTAL;
132
		constraints.weightx = 0.5;
133
		constraints.weighty = 0.0;
134
		this.add(getFieldPrefixTxt(), constraints);
135
	}
136

  
137
	public JLabel getHeaderLbl() {
138
		if (lbl_header==null) {
139
			lbl_header = new JLabel();
140
			Font font = lbl_header.getFont();
141
			lbl_header.setFont(font.deriveFont(Font.BOLD));
142
		}
143
		return lbl_header;
144
	}
145

  
146
	public JLabel getTableNameLbl() {
147
		if (tableNameLbl == null) {
148
			tableNameLbl = new JLabel();
149
		}
150
		return tableNameLbl;
151
	}
152

  
153
	public JComboBox getTableNameCmb() {
154
		if (tableNameCmb == null) {
155
			tableNameCmb = new JComboBox();
156
		}
157
		return tableNameCmb;
158
	}
159

  
160
	public JLabel getFieldNameLbl() {
161
		if (fieldNameLbl==null) {
162
			fieldNameLbl = new JLabel();
163
		}
164
		return fieldNameLbl;
165
	}
166

  
167
	public JComboBox getFieldNameCmb() {
168
		if (fieldNameCmb==null) {
169
			fieldNameCmb = new JComboBox();
170
		}
171
		return fieldNameCmb;
172
	}
173

  
174
	public JLabel getFieldPrefixLbl() {
175
		if (fieldPrefixLbl==null) {
176
			fieldPrefixLbl = new JLabel();
177
		}
178
		return fieldPrefixLbl;
179
	}
180

  
181
	public JTextField getFieldPrefixTxt() {
182
		if (fieldPrefixTxt==null) {
183
			fieldPrefixTxt = new JTextField();
184
		}
185
		return fieldPrefixTxt;
186
	}
187
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/project/document/table/gui/CSVSeparatorOptionsPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*/
19
package org.gvsig.project.document.table.gui;
20

  
21
import java.awt.GridBagConstraints;
22
import java.awt.event.ActionEvent;
23
import java.awt.event.ActionListener;
24
import java.awt.event.ItemEvent;
25
import java.awt.event.ItemListener;
26

  
27
import javax.swing.ButtonGroup;
28
import javax.swing.JButton;
29
import javax.swing.JPanel;
30
import javax.swing.JRadioButton;
31
import javax.swing.JTextField;
32

  
33
import com.iver.andami.PluginServices;
34
import com.iver.andami.ui.mdiManager.IWindow;
35
import com.iver.andami.ui.mdiManager.WindowInfo;
36

  
37
/**
38
 * Class to create csv file at disk with the statistics group generated from a table with an Specifically separator
39
 *
40
 *  Basic separator "," -> csv basic file
41
 *  Excel separator ";" -> csv file to work in gvSIG documents
42
 *
43
 *  Optionally separator -> the user can enter a character or a string
44
 *
45
 *
46
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
47
 *
48
 */
49

  
50

  
51
public class CSVSeparatorOptionsPanel extends JPanel implements IWindow,ItemListener,ActionListener{
52

  
53
	private static final long serialVersionUID = 1L;
54

  
55
	public static final String commaChar = ",";
56
	public static final String semicolonChar = ";";
57
	private JButton buttonAccept;
58
	private JButton buttonCancel;
59
	private JRadioButton commaOption;
60
	private JRadioButton semicolonOption;
61
	private JRadioButton otherSymbol;
62
	private JTextField symbol;
63
	private String separator = null;
64

  
65

  
66
	public CSVSeparatorOptionsPanel() {
67

  
68
		setName("Separation options");
69
		// Initialize component
70
		inicialize();
71

  
72
	}
73
	/**
74
	 * Creating  a basic option separator panel
75
	 *
76
	 */
77
	private void inicialize() {
78

  
79
		GridBagConstraints gridBagConstraints = new GridBagConstraints();
80

  
81
		setLayout(new java.awt.GridBagLayout());
82

  
83
        gridBagConstraints = new java.awt.GridBagConstraints();
84
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
85
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 5, 5);
86
        add(getJCheckBoxPointComma(), gridBagConstraints);
87

  
88

  
89
        gridBagConstraints = new java.awt.GridBagConstraints();
90
        gridBagConstraints.gridwidth = 2;
91
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
92
        gridBagConstraints.weightx = 1.0;
93
        gridBagConstraints.insets = new java.awt.Insets(10, 5, 5, 10);
94
        add(getJCheckBoxComma(), gridBagConstraints);
95

  
96
        gridBagConstraints = new java.awt.GridBagConstraints();
97
        gridBagConstraints.gridx = 0;
98
        gridBagConstraints.gridy = 1;
99
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
100
        gridBagConstraints.weighty = 1.0;
101
        gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 5);
102
        add(getJCheckBoxOtherSymbol(), gridBagConstraints);
103

  
104
        gridBagConstraints = new java.awt.GridBagConstraints();
105
        gridBagConstraints.gridx = 1;
106
        gridBagConstraints.gridy = 1;
107
        gridBagConstraints.gridwidth = 2;
108
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
109
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
110
        gridBagConstraints.weightx = 1.0;
111
        gridBagConstraints.weighty = 1.0;
112
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 10);
113
        add(getTextFieldSymbol(), gridBagConstraints);
114

  
115
        gridBagConstraints = new java.awt.GridBagConstraints();
116
        gridBagConstraints.gridx = 1;
117
        gridBagConstraints.gridy = 2;
118
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
119
        gridBagConstraints.weightx = 1.0;
120
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10);
121
        add(getAcceptButton(), gridBagConstraints);
122

  
123
	    gridBagConstraints = new java.awt.GridBagConstraints();
124
	    gridBagConstraints.gridx = 2;
125
	    gridBagConstraints.gridy = 2;
126
	    add(getCancelButton(), gridBagConstraints);
127

  
128
	    ButtonGroup group = new ButtonGroup();
129
	    group.add(commaOption);
130
	    group.add(semicolonOption);
131
	    group.add(otherSymbol);
132

  
133
	}
134

  
135

  
136
	/**
137
	 * Selection option comma as the separator
138
	 *
139
	 *
140
	 * @return JRadioButton
141
	 */
142

  
143
	private JRadioButton getJCheckBoxComma() {
144
		if (commaOption == null) {
145
			commaOption = new JRadioButton(PluginServices.getText(this, "comma"),
146
					false);
147
			commaOption.setEnabled(true);
148
			commaOption.setToolTipText(PluginServices.getText(this, "sepatator_info_coma"));
149
		}
150
		return commaOption;
151
	}
152

  
153
	/**
154
	 * Selection option semicolon as the separator
155
	 *
156
	 * @return JRadioButton
157
	 */
158
	private JRadioButton getJCheckBoxPointComma() {
159
		if (semicolonOption == null) {
160
			semicolonOption = new JRadioButton(PluginServices.getText(this, "semicolon"),
161
					true);
162
			semicolonOption.setEnabled(true);
163
			semicolonOption.setToolTipText(PluginServices.getText(this, "sepatator_info_semicolon"));
164
		}
165
		return semicolonOption;
166
	}
167

  
168
	/**
169
	 * The user can enter the separator
170
	 *
171
	 * @return JRadioButton
172
	 */
173
	private JRadioButton getJCheckBoxOtherSymbol() {
174
		if (otherSymbol == null) {
175
			otherSymbol = new JRadioButton(PluginServices.getText(this, "otro_simbolo"),
176
					false);
177
			otherSymbol.setEnabled(true);
178
			otherSymbol.addItemListener(this);
179
			otherSymbol.setToolTipText(PluginServices.getText(this, "sepatator_info_other"));
180
		}
181
		return otherSymbol;
182
	}
183

  
184

  
185
	/**
186
	 * Return textfield where the user can enter a separator (char or string)
187
	 *
188
	 * @return TextField.
189
	 */
190
	private JTextField getTextFieldSymbol() {
191
		if (symbol == null) {
192
			symbol = new JTextField(null, 4);
193
			symbol.setHorizontalAlignment(JTextField.RIGHT);
194
			symbol.setEnabled(otherSymbol.isSelected());
195
			symbol.setToolTipText(PluginServices.getText(this, "sepatator_info"));
196
		}
197
		return symbol;
198
	}
199

  
200
	/**
201
	 * Method that generates the button to accept selected separator
202
 	 *
203
	 * @return JButton
204
	 */
205
	private JButton getAcceptButton() {
206
		if (buttonAccept == null) {
207
			buttonAccept = new JButton();
208
			buttonAccept.setText(PluginServices.getText(this, "Aceptar"));
209
			buttonAccept.addActionListener(this);
210
			buttonAccept.setToolTipText(PluginServices.getText(this, "Aceptar"));
211
		}
212
		return buttonAccept;
213
	}
214

  
215
	/**
216
	 * Method that generates the button to cancel csv file creation
217
	 *
218
	 * @return JButton
219
	 */
220
	private JButton getCancelButton() {
221
		if (buttonCancel == null) {
222
			buttonCancel = new JButton();
223
			buttonCancel.setText(PluginServices.getText(this, "Cancelar"));
224
			buttonCancel.addActionListener(this);
225
			buttonCancel.setToolTipText(PluginServices.getText(this, "Cancelar"));
226
		}
227
		return buttonCancel;
228
	}
229

  
230
	/**
231
	 * Window properties
232
	 *
233
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
234
	 */
235
	public WindowInfo getWindowInfo() {
236
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
237
		m_viewinfo.setTitle(PluginServices.getText(this, "opciones_separacion"));
238
		m_viewinfo.setHeight(100);
239
		m_viewinfo.setWidth(300);
240
		return m_viewinfo;
241
	}
242

  
243
	/**
244
	 * Getting the window profile
245
	 */
246
//	public Object getWindowProfile() {
247
//		return WindowInfo.DIALOG_PROFILE;
248
//	}
249

  
250
	/**
251
	 * JRadioButton to enter the separator listener
252
	 */
253
	public void itemStateChanged(ItemEvent e) {
254
		symbol.setEnabled(otherSymbol.isSelected());
255
	}
256

  
257
	/**
258
	 * JButtons Accept and Cancel listener
259
	 */
260
	public void actionPerformed(ActionEvent event) {
261
		if (event.getSource() == this.buttonAccept) {
262
			if(commaOption.isSelected()) {
263
				separator = commaChar;
264

  
265
			}else if(semicolonOption.isSelected()) {
266
				separator = semicolonChar;
267
			}else if(otherSymbol.isSelected()) {
268
				separator = symbol.getText();
269

  
270
			}
271
			PluginServices.getMDIManager().closeWindow(this);
272

  
273
		}
274
		if (event.getSource() == this.buttonCancel) {
275
			separator = null;
276
			PluginServices.getMDIManager().closeWindow(this);
277
			return;
278
		}
279

  
280
	}
281

  
282
	/**
283
	 *
284
	 * @return separator
285
	 * 					- Chosen as the separator character or separator string
286
	 */
287
	public String getSeparator() {
288
		return separator;
289
	}
290
}
branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/project/document/table/ExportStatisticsFile.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
*
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
*/
19

  
20

  
21
package org.gvsig.project.document.table;
22

  
23
import java.awt.Component;
24
import java.io.File;
25
import java.io.FileWriter;
26
import java.io.IOException;
27
import java.sql.Types;
28
import java.util.Hashtable;
29
import java.util.Iterator;
30
import java.util.List;
31

  
32
import javax.swing.JFileChooser;
33
import javax.swing.JOptionPane;
34
import javax.swing.filechooser.FileFilter;
35

  
36
import org.apache.log4j.Logger;
37
import org.gvsig.project.document.table.gui.CSVSeparatorOptionsPanel;
38
import org.gvsig.project.document.table.gui.Statistics.MyObjectStatistics;
39

  
40
import com.iver.andami.PluginServices;
41

  
42
/**
43
 * Class to create dbf and csv files at disk with the statistics group generated from a table.
44
 *
45
 * dbf -> Data Base File
46
 * csv -> Comma Separated Value
47
 *
48
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
49
 *
50
 */
51

  
52

  
53
public class ExportStatisticsFile {
54

  
55

  
56
	private String lastPath = null;
57
	private Hashtable<String, MyFileFilter> dbfExtensionsSupported; // Supported extensions.
58
	private Hashtable<String, MyFileFilter> csvExtensionsSupported;
59

  
60
	private static Logger logger = Logger.getLogger(ExportStatisticsFile.class.getName());
61

  
62

  
63
	public ExportStatisticsFile(List<MyObjectStatistics> valores) {
64

  
65
        	JFileChooser jfc = new JFileChooser(lastPath);
66
			jfc.removeChoosableFileFilter(jfc.getAcceptAllFileFilter());
67

  
68
			// Adding required extensions (dbf, csv)
69
			dbfExtensionsSupported = new Hashtable<String, MyFileFilter>();
70
			csvExtensionsSupported = new Hashtable<String, MyFileFilter>();
71
			dbfExtensionsSupported.put("dbf", new MyFileFilter("dbf",PluginServices.getText(this, "Ficheros_dbf"), "dbf"));
72
			csvExtensionsSupported.put("csv", new MyFileFilter("csv",PluginServices.getText(this, "Ficheros_csv"), "csv"));
73

  
74
			Iterator<MyFileFilter> iter = csvExtensionsSupported.values().iterator();
75
			while (iter.hasNext()) {
76
				jfc.addChoosableFileFilter(iter.next());
77
			}
78

  
79
			iter = dbfExtensionsSupported.values().iterator();
80
			while (iter.hasNext()) {
81
				jfc.addChoosableFileFilter(iter.next());
82
			}
83

  
84
			// Opening a JFileCooser
85
			if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
86
					File endFile = jfc.getSelectedFile();
87
						if (endFile.exists()){// File exists in the directory.
88
							int resp = JOptionPane.showConfirmDialog(
89
									(Component) PluginServices.getMainFrame(),
90
									PluginServices.getText(this,
91
											"fichero_ya_existe_seguro_desea_guardarlo")+"\n"+endFile.getAbsolutePath(),
92
									PluginServices.getText(this,"guardar"), JOptionPane.YES_NO_OPTION);// Informing the user
93
							if (resp != JOptionPane.YES_OPTION) {//cancel pressed.
94
								return;
95
							}
96
						}//end if exits.
97
						MyFileFilter filter = (MyFileFilter)jfc.getFileFilter();// dbf, csv
98
						endFile = filter.normalizeExtension(endFile);//"name" + "." + "dbf", "name" + "." + "csv"
99

  
100
						if(filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("csv") == 0) { // csv file
101
							exportToCSVFile(valores,endFile); // export to csv format
102
						}
103
						else if(filter.getExtensionOfAFile(endFile).toLowerCase().compareTo("dbf") == 0) {// dbf file
104
							exportToDBFFile(valores,endFile); // export to dbf format
105
						}
106
			}//end if aprove option.
107
	}
108

  
109
	/**
110
	 * Creating  cvs format file with the statistics.
111
	 * Option to select the two columns separator.
112
	 *
113
	 * Example with semicolon: Name;data\n
114
	 * 					   Name2;data2\n
115
	 *
116
	 * @param valores
117
	 * 			- Pairs: String name (key) + Double value (
118
	 * @param endFile
119
	 * 			- File to write the information
120
	 */
121

  
122
	private void exportToCSVFile(List<MyObjectStatistics> valores, File endFile) {
123

  
124
		try {
125
			CSVSeparatorOptionsPanel csvSeparatorOptions = new CSVSeparatorOptionsPanel();
126
			PluginServices.getMDIManager().addWindow(csvSeparatorOptions);
127

  
128
			String separator = csvSeparatorOptions.getSeparator();
129

  
130
			if(separator != null) {
131

  
132
				FileWriter fileCSV = new FileWriter(endFile);
133

  
134
				fileCSV.write(PluginServices.getText(this, "Nombre") + separator + PluginServices.getText(this, "Valor")+ "\n");
135

  
136
				Iterator<MyObjectStatistics> iterador = valores.listIterator();
137

  
138
				while (iterador.hasNext()) {// Writing value,value\n
139
					 MyObjectStatistics data= (MyObjectStatistics) iterador.next();
140
					 fileCSV.write(data.getKey() + separator + (data.getValue())+ "\n");
141
				}
142
				fileCSV.close();
143
				JOptionPane.showMessageDialog(null, PluginServices.getText(this, "fichero_creado_en") + " " + endFile.getAbsolutePath(),
144
						PluginServices.getText(this, "fichero_creado_en_formato")+ " csv "+
145
						PluginServices.getText(this, "mediante_el_separador")+
146
						" \""+ separator + "\"", JOptionPane.INFORMATION_MESSAGE);// Informing the user
147
			}
148
			else
149
				return;
150

  
151
		} catch (IOException e) {// Informing the user
152
			logger.error("Error exportando a formato csv");
153
			JOptionPane.showMessageDialog(null, PluginServices.getText(this, "Error_exportando_las_estadisticas") + " " + endFile.getAbsolutePath(),
154
					PluginServices.getText(this, "Error"), JOptionPane.ERROR_MESSAGE);
155
		}
156

  
157
	}
158

  
159
	/**
160
	 * Creating dbf format file with the statistics
161
	 * @param valores
162
	 * 			- Pairs String name (key) + Double value
163
	 * @param endFile
164
	 * 			- File to write the information
165
	 */
166
	private void exportToDBFFile(List<MyObjectStatistics> valores, File endFile) {
167

  
168
		try {
169
			FileDriver driver = null;
170
			try {
171
				driver = (FileDriver) LayerFactory.getDM().getDriver("gdbms dbf driver");
172
			} catch (DriverLoadException e1) {
173
				logger.error("Error Creando el driver dbf");
174
			}
175

  
176
			try {
177
				if (!endFile.exists()){
178
					try {
179
						driver.createSource(endFile.getAbsolutePath(),new String[] {"0"},new int[] {Types.DOUBLE} );
180
					} catch (ReadDriverException e) {
181
						logger.error("Error en createSource");
182
					}
183
					endFile.createNewFile();
184
				}
185

  
186
				try {
187
					driver.open(endFile);
188
				} catch (OpenDriverException e) {
189
					logger.error("Error abriendo el fichero de destino");
190
				}
191
			} catch (IOException e) {
192
				try {
193
					throw new Exception("Error creando el fichero de destino", e);
194
				} catch (Exception e1) {
195
					logger.error("Error creando el fichero de destino");
196
				}
197
			}
198

  
199
			IWriter writer = ((IWriteable)driver).getWriter();
200
			ITableDefinition orgDef = new TableDefinition();
201
			try {
202
				// Preparing the total rows in the new dbf file, in this case two rows : Name  Value
203
				FieldDescription[] fields = new FieldDescription[2];
204
				fields[0] = new FieldDescription();
205
				fields[0].setFieldType(Types.VARCHAR);
206
				fields[0].setFieldName(PluginServices.getText(this, "Nombre"));
207
				fields[0].setFieldLength(50);
208
				fields[1] = new FieldDescription();
209
				fields[1].setFieldType(Types.DOUBLE);
210
				fields[1].setFieldName(PluginServices.getText(this, "Valor"));
211
				fields[1].setFieldLength(50);
212
				fields[1].setFieldDecimalCount(25);
213
				fields[1].setFieldLength(100);
214
				orgDef.setFieldsDesc(fields);
215
				writer.initialize(orgDef);
216
			} catch (InitializeWriterException e) {
217
				logger.error("Error en la inicializaci?n del writer");
218
			}
219
			try {
220
				writer.preProcess();
221
			} catch (StartWriterVisitorException e) {
222
				logger.error("Error en el preProcess del writer");
223
			}
224
			try {
225
				int index = 0;
226
				Value[] value = new Value[2];
227
				IFeature feat = null;
228

  
229
				Iterator<MyObjectStatistics> iterador = valores.listIterator();
230

  
231
				while (iterador.hasNext()) {
232
					MyObjectStatistics data= (MyObjectStatistics) iterador.next();
233
					value[0] = ValueFactory.createValue(data.getKey());
234
					value[1] = ValueFactory.createValue(data.getValue());
235
					feat = new DefaultFeature(null, value,"" + index++);
236
					write(writer, feat, index);
237
				}
238
			} catch (Exception e) {
239
				logger.error("Error en el write");
240
			}
241
			try {
242
				writer.postProcess();// Operation finished
243
				JOptionPane.showMessageDialog(null, PluginServices.getText(this, "fichero_creado_en") + " " + endFile.getAbsolutePath(),
244
						PluginServices.getText(this, "fichero_creado_en_formato")+ " dbf", JOptionPane.INFORMATION_MESSAGE);// Informing the user
245
			} catch (StopWriterVisitorException e) {
246
				logger.error("Error en el postProcess del writer");
247
			}
248
		} catch (Exception e) {// Informing the user
249
			logger.error("Error exportando a formato dbf");
250
			JOptionPane.showMessageDialog(null, PluginServices.getText(this, "Error_exportando_las_estadisticas") + " " + endFile.getAbsolutePath(),
251
					PluginServices.getText(this, "Error"), JOptionPane.ERROR_MESSAGE);
252
		}
253

  
254
	}
255

  
256
	/**
257
	 * Writer to create dbf file
258
	 *
259
	 * @param writer
260
	 * @param feature
261
	 * 				- fill with the corresponding rows
262
	 * @param index
263
	 * 				- fill file position
264
	 */
265
	private void write(IWriter writer, IFeature feature, int index) {
266
		DefaultRowEdited edRow = new DefaultRowEdited(feature,
267
				 DefaultRowEdited.STATUS_ADDED, index);
268
		 try {
269
			writer.process(edRow);
270
		} catch (VisitorException e) {
271
			logger.error("Error en la generaci?n del fichero dbf");
272
		}
273
	}
274
}
275

  
276
/**
277
 * @author ?ngel Fraile Gri??n  e-mail: angel.fraile@iver.es
278
 *
279
 * Class to work with the file extensions.
280
 */
281
class MyFileFilter extends FileFilter {
282

  
283
	private String[] extensiones = new String[1];
284
	private String description;
285
	private boolean dirs = true;
286
	private String info = null;
287

  
288
	public MyFileFilter(String[] ext, String desc) {
289
		extensiones = ext;
290
		description = desc;
291
	}
292

  
293
	public MyFileFilter(String[] ext, String desc, String info) {
294
		extensiones = ext;
295
		description = desc;
296
		this.info = info;
297
	}
298

  
299
	public MyFileFilter(String ext, String desc) {
300
		extensiones[0] = ext;
301
		description = desc;
302
	}
303

  
304
	public MyFileFilter(String ext, String desc, String info) {
305
		extensiones[0] = ext;
306
		description = desc;
307
		this.info = info;
308
	}
309

  
310
	public MyFileFilter(String ext, String desc, boolean dirs) {
311
		extensiones[0] = ext;
312
		description = desc;
313
		this.dirs = dirs;
314
	}
315

  
316
	public MyFileFilter(String ext, String desc, boolean dirs, String info) {
317
		extensiones[0] = ext;
318
		description = desc;
319
		this.dirs = dirs;
320
		this.info = info;
321
	}
322

  
323
	public boolean accept(File f) {
324
		if (f.isDirectory()) {
325
			if (dirs) {
326
				return true;
327
			} else {
328
				return false;
329
			}
330
		}
331
		for (int i = 0; i < extensiones.length; i++) {
332
			if (extensiones[i].equals("")) {
333
				continue;
334
			}
335
			if (getExtensionOfAFile(f).equalsIgnoreCase(extensiones[i])) {
336
				return true;
337
			}
338
		}
339
		return false;
340
	}
341

  
342
	public String getDescription() {
343
		return description;
344
	}
345

  
346
	public String[] getExtensions() {
347
		return extensiones;
348
	}
349

  
350
	public boolean isDirectory() {
351
		return dirs;
352
	}
353

  
354
	public String getExtensionOfAFile(File file) {
355
		String name;
356
		int dotPos;
357
		name = file.getName();
358
		dotPos = name.lastIndexOf(".");
359
		if (dotPos < 1) {
360
			return "";
361
		}
362
		return name.substring(dotPos + 1);
363
	}
364

  
365
	public File normalizeExtension(File file) {
366
		String ext = getExtensionOfAFile(file);
367
		if (ext.equals("") || !(this.accept(file))) {
368
			return new File(file.getAbsolutePath() + "." + extensiones[0]);
369
		}
370
		return file;
371
	}
372

  
373
	public String getInfo() {
374
		return this.info;
375
	}
376

  
377
	public void setInfo(String info) {
378
		this.info = info;
379
	}
380
}
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/TableNumericFieldOperations.java
13 13
import org.gvsig.fmap.dal.feature.FeatureStore;
14 14
import org.gvsig.fmap.mapcontext.rendering.legend.NullValue;
15 15
import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel;
16
import org.gvsig.project.document.table.gui.Statistics;
16 17

  
17 18
import com.iver.andami.PluginServices;
18 19
import com.iver.andami.plugins.Extension;
19 20
import com.iver.andami.ui.mdiManager.IWindow;
20
import com.iver.cit.gvsig.project.documents.table.gui.Statistics;
21 21

  
22 22
/**
23 23
 * @author Fernando Gonz?lez Cort?s
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/TableOperations.java
483 483
	public boolean isEnabled() {
484 484
		return true;
485 485
	}
486
	public void execJoin(FeatureTableDocument sourceProjectTable, String field1, String prefix1,
487
			FeatureTableDocument targetProjectTable, String field2, String prefix2) {
488
		// get source table and source field
489
		FeatureStore sds=null;
490
		try {
491
			sds = sourceProjectTable.getStore();
492
		} catch (ReadException e) {
493
			e.printStackTrace();
494
		}
495
		String tableName1 = sds.getName();
496
		// get target table and target field
497
		try {
498
			sds = targetProjectTable.getStore();
499
		} catch (ReadException e) {
500
			e.printStackTrace();
501
		}
502
		String tableName2 = sds.getName();
503
		// compute the join
504
		String sql =
505
			"custom com_iver_cit_gvsig_arcjoin tables '" +
506
			tableName1 + "', '" + tableName2 + "' values(" +
507
			field1 + ", " + field2 + ");";
508
		PluginServices.getLogger().debug(sql);
486 509

  
510
		try {
511
			SelectableDataSource result = new SelectableDataSource(LayerFactory.getDataSourceFactory()
512
					.executeSQL(sql,
513
							DataSourceFactory.AUTOMATIC_OPENING));
514
			EditableAdapter auxea=new EditableAdapter();
515
			auxea.setOriginalDataSource(result);
516
			renameFields(auxea, sourceProjectTable, sanitizeFieldName(prefix1),
517
					targetProjectTable, sanitizeFieldName(prefix2));
518
			sourceProjectTable.replaceDataSource(auxea);
519
		} catch (ParseException e) {
520
			throw new RuntimeException(e);
521
		} catch (DriverLoadException e) {
522
			NotificationManager.addError(PluginServices.getText(this, "Error_loading_driver"),
523
					e);
524
		} catch (ReadException e) {
525
			NotificationManager.addError(PluginServices.getText(this, "Error_reading_from_the_driver"),
526
					e);
527
		} catch (SemanticException e) {
528
			throw new RuntimeException(e);
529
		} catch (EvaluationException e) {
530
			NotificationManager.addError(PluginServices.getText(this, "Error_evaluationg_expression"),
531
					e);
532
		}
533
	}
534
	/**
535
	 * Ensure that field name only has 'safe' characters
536
	 * (no spaces, special characters, etc).
537
	 */
538
	public String sanitizeFieldName(String fieldName) {
539
		return fieldName.replaceAll("\\W", "_"); // replace any non-word character by an underscore
540
	}
487 541

  
542

  
488 543
}
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/table/gui/Statistics.java
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

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

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

  
14
import com.iver.andami.PluginServices;
15
import com.iver.andami.ui.mdiManager.IWindow;
16
import com.iver.andami.ui.mdiManager.WindowInfo;
17
/**
18
 * @author Fernando Gonz?lez Cort?s
19
 */
20
public class Statistics extends JPanel implements IWindow {
21

  
22
	private JScrollPane jScrollPane = null;
23
	private JTextArea txtStatistics = null;
24
	private JButton jButton = null;
25
	private JPanel jPanel = null;
26
	/**
27
	 * This is the default constructor
28
	 */
29
	public Statistics() {
30
		super();
31
		initialize();
32
	}
33
	/**
34
	 * This method initializes this
35
	 * 
36
	 * @return void
37
	 */
38
	private  void initialize() {
39
		this.setLayout(new BorderLayout());
40
		this.setSize(300,200);
41
		this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
42
		this.add(getJPanel(), java.awt.BorderLayout.SOUTH);
43
	}
44
	/**
45
	 * This method initializes jScrollPane	
46
	 * 	
47
	 * @return javax.swing.JScrollPane	
48
	 */    
49
	private JScrollPane getJScrollPane() {
50
		if (jScrollPane == null) {
51
			jScrollPane = new JScrollPane();
52
			jScrollPane.setViewportView(getTxtStatistics());
53
		}
54
		return jScrollPane;
55
	}
56
	/**
57
	 * This method initializes jTextArea	
58
	 * 	
59
	 * @return javax.swing.JTextArea	
60
	 */    
61
	private JTextArea getTxtStatistics() {
62
		if (txtStatistics == null) {
63
			txtStatistics = new JTextArea();			
64
		}
65
		return txtStatistics;
66
	}
67
	/**
68
	 * This method initializes jButton	
69
	 * 	
70
	 * @return JButton	
71
	 */    
72
	private JButton getJButton() {
73
		if (jButton == null) {
74
			jButton = new JButton();
75
			jButton.setPreferredSize(new java.awt.Dimension(100,18));
76
			jButton.setText(PluginServices.getText(this, "cerrar"));
77
			jButton.addActionListener(new ActionListener() {
78
                public void actionPerformed(ActionEvent e) {
79
                    PluginServices.getMDIManager().closeWindow(Statistics.this);
80
                }
81
            });
82
		}
83
		return jButton;
84
	}
85
	/**
86
	 * This method initializes jPanel	
87
	 * 	
88
	 * @return javax.swing.JPanel	
89
	 */    
90
	private JPanel getJPanel() {
91
		if (jPanel == null) {
92
			jPanel = new JPanel();
93
			FlowLayout layout = new FlowLayout();
94
			layout.setAlignment(FlowLayout.RIGHT);
95
			jPanel.setLayout(layout);
96
			jPanel.add(getJButton(), null);
97
		}
98
		return jPanel;
99
	}
100
    /**
101
     * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
102
     */
103
    public WindowInfo getWindowInfo() {
104
        WindowInfo vi = new WindowInfo(WindowInfo.MODALDIALOG);
105
        vi.setTitle(PluginServices.getText(this, "estadisticas"));
106
        return vi;
107
    }
108
    /**
109
     * @param i
110
     * @param j
111
     * @param k
112
     * @param l
113
     * @param m
114
     * @param n
115
     * @param o
116
     * @param p
117
     */
118
    public void setStatistics(double media, double maximo, double minimo, double varianza, double desviacion, int numero, double ambito, double suma) {
119
        getTxtStatistics().setText(PluginServices.getText(this, "suma") + ": " + suma + "\n"+
120
                PluginServices.getText(this, "recuento") + ": " + numero + "\n"+
121
                PluginServices.getText(this, "media") + ": " + media + "\n"+
122
                PluginServices.getText(this, "maximo") + ": " + maximo + "\n"+
123
                PluginServices.getText(this, "minimo") + ": " + minimo + "\n"+
124
                PluginServices.getText(this, "ambito") + ": " + ambito + "\n"+
125
                PluginServices.getText(this, "varianza") + ": " + varianza + "\n"+
126
                PluginServices.getText(this, "desviacion_tipica") + ": " + desviacion);        
127
    }
128
    }
branches/v2_0_0_prep/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/legend/gui/General.java
76 76
import org.gvsig.fmap.dal.exception.DataException;
77 77
import org.gvsig.fmap.dal.exception.ReadException;
78 78
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
79
import org.gvsig.fmap.dal.feature.FeatureSet;
79 80
import org.gvsig.fmap.dal.feature.FeatureStore;
80 81
import org.gvsig.fmap.dal.feature.FeatureType;
81 82
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
83
import org.gvsig.fmap.geom.Geometry;
82 84
import org.gvsig.fmap.geom.primitive.Envelope;
83 85
import org.gvsig.fmap.mapcontext.layers.FLayer;
84 86
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
......
689 691
//						info = info + "\n" + rv.getDriver().getName() + "\n";
690 692
//					}
691 693

  
694
					info += "\n" + PluginServices.getText(this,"type")+ ": "+getTypeVectorLayer() + "\n";
692 695

  
693

  
694 696
				} else {
695 697
					info=buff.toString();
696 698
					info = info + PluginServices.getText(this,"Origen_de_datos") + ": " + layer.getName();
......
701 703

  
702 704
		} catch (ReadException e) {
703 705
			NotificationManager.addError(e.getMessage(), e);
706
		} catch (DataException e) {
707
			NotificationManager.addError(e.getMessage(), e);
704 708
		}
705 709

  
706 710
    }
711
    private String getTypeVectorLayer() throws DataException {
712
    	if (layer instanceof FLyrVect){
713
        	String typeString="";
714
        	int typeShape=((FLyrVect)layer).getShapeType();
715
        	FeatureStore fs=((FLyrVect)layer).getFeatureStore();
716
			FeatureSet set=fs.getFeatureSet();
707 717

  
718
        	if (Geometry.TYPES.GEOMETRY==typeShape){
719
				if (set.getSize()>0){
720
					int type=((Geometry)set.getDefaultFeatureType().get(set.getDefaultFeatureType().getDefaultGeometryAttributeIndex())).getType();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff