Revision 11613 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/project/documents/gui/Annotation_Modify.java

View differences:

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

  
3
import com.hardcode.driverManager.Driver;
3
import jwizardcomponent.FinishAction;
4
import jwizardcomponent.JWizardComponents;
4 5

  
5 6
import com.hardcode.gdbms.engine.data.driver.DriverException;
6

  
7
import com.iver.andami.PluginServices;
8

  
9 7
import com.iver.cit.gvsig.fmap.MapContext;
10
import com.iver.cit.gvsig.fmap.core.FShape;
11
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
12
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
13
import com.iver.cit.gvsig.fmap.drivers.SHPLayerDefinition;
14
import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver;
15
import com.iver.cit.gvsig.fmap.edition.EditionException;
16
import com.iver.cit.gvsig.fmap.edition.IWriter;
17
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter;
18 8
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
19 9
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
20
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
21 10
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
22 11
import com.iver.cit.gvsig.gui.panels.annotation.ConfigureLabel;
23 12

  
24
import com.iver.utiles.SimpleFileFilter;
25

  
26
import jwizardcomponent.FinishAction;
27
import jwizardcomponent.JWizardComponents;
28

  
29
import java.awt.Component;
30

  
31
import java.io.File;
32
import java.io.IOException;
33

  
34
import javax.swing.JFileChooser;
35
import javax.swing.JOptionPane;
36

  
37

  
38 13
/**
39 14
 * Dialog to create a new annotation layer.
40
 *
15
 * 
41 16
 * @author Vicente Caballero Navarro
42 17
 */
43 18
public class Annotation_Modify extends FinishAction {
44
    private JWizardComponents myWizardComponents;
45
    private MapContext map;
46
    private Annotation_Layer layerAnnotation;
19
	private JWizardComponents myWizardComponents;
47 20

  
48
    public Annotation_Modify(JWizardComponents wizardComponents,
49
        MapContext map, Annotation_Layer layerAnnotation) {
50
        super(wizardComponents);
51
        this.map = map;
52
        this.layerAnnotation = layerAnnotation;
53
        myWizardComponents = wizardComponents;
54
    }
21
	private MapContext map;
55 22

  
56
    public void performAction() {
57
        myWizardComponents.getFinishButton().setEnabled(false);
23
	private Annotation_Layer layerAnnotation;
58 24

  
59
        Annotation_FieldSelect panel1 = (Annotation_FieldSelect) myWizardComponents.getWizardPanel(0);
60
        Annotation_ConfigureLabel panel2 = (Annotation_ConfigureLabel) myWizardComponents.getWizardPanel(1);
25
	public Annotation_Modify(JWizardComponents wizardComponents,
26
			MapContext map, Annotation_Layer layerAnnotation) {
27
		super(wizardComponents);
28
		this.map = map;
29
		this.layerAnnotation = layerAnnotation;
30
		myWizardComponents = wizardComponents;
31
	}
61 32

  
62
        SelectableDataSource source;
63
        Annotation_Mapping mapping = new Annotation_Mapping();
33
	public void performAction() {
34
		myWizardComponents.getFinishButton().setEnabled(false);
64 35

  
65
        try {
66
            source = this.layerAnnotation.getRecordset();
36
		Annotation_FieldSelect panel1 = (Annotation_FieldSelect) myWizardComponents
37
				.getWizardPanel(0);
38
		Annotation_ConfigureLabel panel2 = (Annotation_ConfigureLabel) myWizardComponents
39
				.getWizardPanel(1);
67 40

  
68
            mapping.setColumnText(source.getFieldIndexByName(panel1.getField()));
41
		SelectableDataSource source;
42
		Annotation_Mapping mapping = new Annotation_Mapping();
69 43

  
70
            if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
71
                mapping.setColumnRotate(source.getFieldIndexByName(
72
                        panel2.getAngleFieldName()));
73
            }
44
		try {
45
			source = this.layerAnnotation.getRecordset();
74 46

  
75
            if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
76
                mapping.setColumnColor(source.getFieldIndexByName(
77
                        panel2.getColorFieldName()));
78
            }
47
			mapping
48
					.setColumnText(source
49
							.getFieldIndexByName(panel1.getField()));
79 50

  
80
            if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
81
                mapping.setColumnHeight(source.getFieldIndexByName(
82
                        panel2.getSizeFieldName()));
83
            }
51
			if (!panel2.getAngleFieldName().equals(
52
					ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
53
				mapping.setColumnRotate(source.getFieldIndexByName(panel2
54
						.getAngleFieldName()));
55
			}
84 56

  
85
            this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
57
			if (!panel2.getColorFieldName().equals(
58
					ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
59
				mapping.setColumnColor(source.getFieldIndexByName(panel2
60
						.getColorFieldName()));
61
			}
86 62

  
87
            this.layerAnnotation.deleteSpatialIndex();
88
            if (!panel2.getFontFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
89
                mapping.setColumnTypeFont(source.getFieldIndexByName(
90
                        panel2.getFontFieldName()));
91
            }
92
        } catch (com.iver.cit.gvsig.fmap.DriverException e) {
93
            e.printStackTrace();
63
			if (!panel2.getSizeFieldName().equals(
64
					ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
65
				mapping.setColumnHeight(source.getFieldIndexByName(panel2
66
						.getSizeFieldName()));
67
			}
94 68

  
95
            return;
96
        } catch (DriverException e) {
97
            e.printStackTrace();
98
        }
69
			this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
99 70

  
100
        //		this.layerAnnotation.setName(panel1.getNewLayerName());
101
        this.layerAnnotation.setMapping(mapping);
71
			this.layerAnnotation.deleteSpatialIndex();
72
			if (!panel2.getFontFieldName().equals(
73
					ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
74
				mapping.setColumnTypeFont(source.getFieldIndexByName(panel2
75
						.getFontFieldName()));
76
			}
77
		} catch (com.iver.cit.gvsig.fmap.DriverException e) {
78
			e.printStackTrace();
102 79

  
103
//        try {
104
//            saveToShp(map, this.layerAnnotation);
105
//        } catch (EditionException e) {
106
//            e.printStackTrace();
107
//        } catch (DriverIOException e) {
108
//            e.printStackTrace();
109
//        }
80
			return;
81
		} catch (DriverException e) {
82
			e.printStackTrace();
83
		}
110 84

  
111
        this.myWizardComponents.getCancelAction().performAction();
112
    }
85
		// this.layerAnnotation.setName(panel1.getNewLayerName());
86
		this.layerAnnotation.setMapping(mapping);
113 87

  
114
//    public void saveToShp(MapContext mapContext, Annotation_Layer layer)
115
//        throws EditionException, DriverIOException {
116
//        try {
117
//            JFileChooser jfc = new JFileChooser();
118
//            SimpleFileFilter filterShp = new SimpleFileFilter("shp",
119
//                    PluginServices.getText(this, "shp_files"));
120
//            jfc.setFileFilter(filterShp);
121
//
122
//            if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
123
//                File newFile = jfc.getSelectedFile();
124
//                String path = newFile.getAbsolutePath();
125
//
126
//                if (newFile.exists()) {
127
//                    int resp = JOptionPane.showConfirmDialog((Component) PluginServices.getMainFrame(),
128
//                            PluginServices.getText(this,
129
//                                "fichero_ya_existe_seguro_desea_guardarlo"),
130
//                            PluginServices.getText(this, "guardar"),
131
//                            JOptionPane.YES_NO_OPTION);
132
//
133
//                    if (resp != JOptionPane.YES_OPTION) {
134
//                        return;
135
//                    }
136
//                }
137
//
138
//                if (!(path.toLowerCase().endsWith(".shp"))) {
139
//                    path = path + ".shp";
140
//                }
141
//
142
//                newFile = new File(path);
143
//
144
//                SelectableDataSource sds = layer.getRecordset();
145
//                FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
146
//
147
//                ShpWriter writer = (ShpWriter) LayerFactory.getWM().getWriter("Shape Writer");
148
//                Driver driver = null;
149
//
150
//                SHPLayerDefinition lyrDefPoint = new SHPLayerDefinition();
151
//                lyrDefPoint.setFieldsDesc(fieldsDescrip);
152
//
153
//                File filePoints = new File(path);
154
//                lyrDefPoint.setFile(filePoints);
155
//                lyrDefPoint.setName(filePoints.getName());
156
//                lyrDefPoint.setShapeType(FShape.POINT);
157
//                writer.setFile(filePoints);
158
//                writer.initialize(lyrDefPoint);
159
//                driver = getOpenAnnotationDriver(filePoints);
160
//                writeFeatures(mapContext, layer, writer, driver);
161
//            }
162
//        } catch (DriverException e) {
163
//            e.printStackTrace();
164
//            throw new EditionException(e);
165
//        } catch (IOException e) {
166
//            e.printStackTrace();
167
//        } catch (com.iver.cit.gvsig.fmap.DriverException e) {
168
//            e.printStackTrace();
169
//        }
170
//    }
88
		// try {
89
		// saveToShp(map, this.layerAnnotation);
90
		// } catch (EditionException e) {
91
		// e.printStackTrace();
92
		// } catch (DriverIOException e) {
93
		// e.printStackTrace();
94
		// }
171 95

  
172
//    private Driver getOpenAnnotationDriver(File filePoints)
173
//        throws IOException {
174
//        IndexedShpDriver drv = new IndexedShpDriver();
175
//
176
//        if (!filePoints.exists()) {
177
//            filePoints.createNewFile();
178
//
179
//            File newFileSHX = new File(filePoints.getAbsolutePath().replaceAll("[.]shp",
180
//                        ".shx"));
181
//            newFileSHX.createNewFile();
182
//
183
//            File newFileDBF = new File(filePoints.getAbsolutePath().replaceAll("[.]shp",
184
//                        ".dbf"));
185
//            newFileDBF.createNewFile();
186
//        }
187
//
188
//        File newFileGVA = new File(filePoints.getAbsolutePath().replaceAll("[.]shp",
189
//                    ".gva"));
190
//
191
//        if (!newFileGVA.exists()) {
192
//            newFileGVA.createNewFile();
193
//        }
194
//
195
//        drv.open(filePoints);
196
//
197
//        return drv;
198
//    }
96
		this.myWizardComponents.getCancelAction().performAction();
97
	}
199 98

  
200
//    private void writeFeatures(MapContext mapContext, Annotation_Layer layer,
201
//        IWriter writer, Driver reader)
202
//        throws DriverIOException, com.iver.cit.gvsig.fmap.DriverException {
203
//        PluginServices.cancelableBackgroundExecution(new Annotation_TaskCreate(
204
//                mapContext, layer, writer, reader));
205
//    }
99
	// public void saveToShp(MapContext mapContext, Annotation_Layer layer)
100
	// throws EditionException, DriverIOException {
101
	// try {
102
	// JFileChooser jfc = new JFileChooser();
103
	// SimpleFileFilter filterShp = new SimpleFileFilter("shp",
104
	// PluginServices.getText(this, "shp_files"));
105
	// jfc.setFileFilter(filterShp);
106
	//
107
	// if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) ==
108
	// JFileChooser.APPROVE_OPTION) {
109
	// File newFile = jfc.getSelectedFile();
110
	// String path = newFile.getAbsolutePath();
111
	//
112
	// if (newFile.exists()) {
113
	// int resp = JOptionPane.showConfirmDialog((Component)
114
	// PluginServices.getMainFrame(),
115
	// PluginServices.getText(this,
116
	// "fichero_ya_existe_seguro_desea_guardarlo"),
117
	// PluginServices.getText(this, "guardar"),
118
	// JOptionPane.YES_NO_OPTION);
119
	//
120
	// if (resp != JOptionPane.YES_OPTION) {
121
	// return;
122
	// }
123
	// }
124
	//
125
	// if (!(path.toLowerCase().endsWith(".shp"))) {
126
	// path = path + ".shp";
127
	// }
128
	//
129
	// newFile = new File(path);
130
	//
131
	// SelectableDataSource sds = layer.getRecordset();
132
	// FieldDescription[] fieldsDescrip = sds.getFieldsDescription();
133
	//
134
	// ShpWriter writer = (ShpWriter) LayerFactory.getWM().getWriter("Shape
135
	// Writer");
136
	// Driver driver = null;
137
	//
138
	// SHPLayerDefinition lyrDefPoint = new SHPLayerDefinition();
139
	// lyrDefPoint.setFieldsDesc(fieldsDescrip);
140
	//
141
	// File filePoints = new File(path);
142
	// lyrDefPoint.setFile(filePoints);
143
	// lyrDefPoint.setName(filePoints.getName());
144
	// lyrDefPoint.setShapeType(FShape.POINT);
145
	// writer.setFile(filePoints);
146
	// writer.initialize(lyrDefPoint);
147
	// driver = getOpenAnnotationDriver(filePoints);
148
	// writeFeatures(mapContext, layer, writer, driver);
149
	// }
150
	// } catch (DriverException e) {
151
	// e.printStackTrace();
152
	// throw new EditionException(e);
153
	// } catch (IOException e) {
154
	// e.printStackTrace();
155
	// } catch (com.iver.cit.gvsig.fmap.DriverException e) {
156
	// e.printStackTrace();
157
	// }
158
	// }
159

  
160
	// private Driver getOpenAnnotationDriver(File filePoints)
161
	// throws IOException {
162
	// IndexedShpDriver drv = new IndexedShpDriver();
163
	//
164
	// if (!filePoints.exists()) {
165
	// filePoints.createNewFile();
166
	//
167
	// File newFileSHX = new
168
	// File(filePoints.getAbsolutePath().replaceAll("[.]shp",
169
	// ".shx"));
170
	// newFileSHX.createNewFile();
171
	//
172
	// File newFileDBF = new
173
	// File(filePoints.getAbsolutePath().replaceAll("[.]shp",
174
	// ".dbf"));
175
	// newFileDBF.createNewFile();
176
	// }
177
	//
178
	// File newFileGVA = new
179
	// File(filePoints.getAbsolutePath().replaceAll("[.]shp",
180
	// ".gva"));
181
	//
182
	// if (!newFileGVA.exists()) {
183
	// newFileGVA.createNewFile();
184
	// }
185
	//
186
	// drv.open(filePoints);
187
	//
188
	// return drv;
189
	// }
190

  
191
	// private void writeFeatures(MapContext mapContext, Annotation_Layer layer,
192
	// IWriter writer, Driver reader)
193
	// throws DriverIOException, com.iver.cit.gvsig.fmap.DriverException {
194
	// PluginServices.cancelableBackgroundExecution(new Annotation_TaskCreate(
195
	// mapContext, layer, writer, reader));
196
	// }
206 197
}

Also available in: Unified diff