Statistics
| Revision:

root / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / gui / Annotation_Modify.java @ 11536

History | View | Annotate | Download (7.64 KB)

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

    
3
import com.hardcode.driverManager.Driver;
4

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

    
7
import com.iver.andami.PluginServices;
8

    
9
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
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
19
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping;
20
import com.iver.cit.gvsig.fmap.layers.LayerFactory;
21
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
22
import com.iver.cit.gvsig.gui.panels.annotation.ConfigureLabel;
23

    
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
/**
39
 * Dialog to create a new annotation layer.
40
 *
41
 * @author Vicente Caballero Navarro
42
 */
43
public class Annotation_Modify extends FinishAction {
44
    private JWizardComponents myWizardComponents;
45
    private MapContext map;
46
    private Annotation_Layer layerAnnotation;
47

    
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
    }
55

    
56
    public void performAction() {
57
        myWizardComponents.getFinishButton().setEnabled(false);
58

    
59
        Annotation_FieldSelect panel1 = (Annotation_FieldSelect) myWizardComponents.getWizardPanel(0);
60
        Annotation_ConfigureLabel panel2 = (Annotation_ConfigureLabel) myWizardComponents.getWizardPanel(1);
61

    
62
        SelectableDataSource source;
63
        Annotation_Mapping mapping = new Annotation_Mapping();
64

    
65
        try {
66
            source = this.layerAnnotation.getRecordset();
67

    
68
            mapping.setColumnText(source.getFieldIndexByName(panel1.getField()));
69

    
70
            if (!panel2.getAngleFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
71
                mapping.setColumnRotate(source.getFieldIndexByName(
72
                        panel2.getAngleFieldName()));
73
            }
74

    
75
            if (!panel2.getColorFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
76
                mapping.setColumnColor(source.getFieldIndexByName(
77
                        panel2.getColorFieldName()));
78
            }
79

    
80
            if (!panel2.getSizeFieldName().equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
81
                mapping.setColumnHeight(source.getFieldIndexByName(
82
                        panel2.getSizeFieldName()));
83
            }
84

    
85
            this.layerAnnotation.setInPixels(panel2.sizeUnitsInPixels());
86

    
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();
94

    
95
            return;
96
        } catch (DriverException e) {
97
            e.printStackTrace();
98
        }
99

    
100
        //                this.layerAnnotation.setName(panel1.getNewLayerName());
101
        this.layerAnnotation.setMapping(mapping);
102

    
103
//        try {
104
//            saveToShp(map, this.layerAnnotation);
105
//        } catch (EditionException e) {
106
//            e.printStackTrace();
107
//        } catch (DriverIOException e) {
108
//            e.printStackTrace();
109
//        }
110

    
111
        this.myWizardComponents.getCancelAction().performAction();
112
    }
113

    
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
//    }
171

    
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
//    }
199

    
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
//    }
206
}