Statistics
| Revision:

gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.extension / src / main / java / org / gvsig / sextante / app / extension / core / gvOutputFactory.java @ 28

History | View | Annotate | Download (4.39 KB)

1
package org.gvsig.sextante.app.extension.core;
2

    
3
import java.util.Date;
4

    
5
import javax.swing.JDialog;
6

    
7
import org.gvsig.andami.Utilities;
8
import org.gvsig.andami.messages.NotificationManager;
9
import org.gvsig.app.ApplicationLocator;
10
import org.gvsig.app.project.ProjectPreferences;
11
import org.gvsig.fmap.dal.DataTypes;
12

    
13
import es.unex.sextante.core.ITaskMonitor;
14
import es.unex.sextante.core.OutputFactory;
15
import es.unex.sextante.dataObjects.IRasterLayer;
16
import es.unex.sextante.dataObjects.ITable;
17
import es.unex.sextante.dataObjects.IVectorLayer;
18
import es.unex.sextante.exceptions.UnsupportedOutputChannelException;
19
import es.unex.sextante.gui.core.DefaultTaskMonitor;
20
import es.unex.sextante.outputs.FileOutputChannel;
21
import es.unex.sextante.outputs.IOutputChannel;
22
import es.unex.sextante.rasterWrappers.GridExtent;
23

    
24
/**
25
 * An OutputFactory based on the gvSIG data model.
26
 * Supports only file-based outputs.
27
 * @author volaya
28
 *
29
 */
30
public class gvOutputFactory extends OutputFactory {
31

    
32
        public IVectorLayer getNewVectorLayer(String sName,
33
                                                                                  int iShapeType,
34
                                                                                  Class[] types,
35
                                                                                  String[] sFields,
36
                                                                                  IOutputChannel channel,
37
                                                                                  Object crs)
38
                                throws UnsupportedOutputChannelException {
39
                int[] fieldSize = new int[types.length];
40
                for (int i = 0; i < fieldSize.length; i++) 
41
                        fieldSize[i] = getSizeByType(types[i]);
42

    
43
                return getNewVectorLayer(sName,
44
                                                                        iShapeType,
45
                                                                        types,
46
                                                                        sFields,
47
                                                                        channel,
48
                                                                        crs,
49
                                                                        fieldSize);
50
        }
51
        
52
        /**
53
         * Gets the default size depending on the class type
54
         * @param type
55
         * @return size
56
         */
57
        private int getSizeByType(Class type) {
58
                if (type.equals(Integer.class))
59
                        return 10;
60
                else if (type.equals(Double.class))
61
                        return 20;
62
                else if (type.equals(Long.class))
63
                        return 20;
64
                else if (type.equals(Float.class))
65
                        return 15;
66
                else if (type.equals(String.class))
67
                        return 80;
68
                else if (type.equals(Date.class))
69
                        return 10;
70
                else if (type.equals(Boolean.class))
71
                        return 1;
72
                else 
73
                        return 30;
74
        }
75

    
76
        public IVectorLayer getNewVectorLayer(String sName,
77
                        int iShapeType,
78
                        Class[] types,
79
                        String[] sFields,
80
                        IOutputChannel channel,
81
                        Object crs,
82
                        int[] fieldSize)
83
        throws UnsupportedOutputChannelException {
84

    
85
                if (channel instanceof FileOutputChannel) {
86
                        String sFilename = ((FileOutputChannel)channel).getFilename();
87
                        gvVectorLayer layer = new gvVectorLayer();
88
                        layer.create(sName, sFilename, iShapeType,
89
                                        types, sFields, crs, fieldSize);
90

    
91
                        return layer;
92
                } else
93
                        throw new UnsupportedOutputChannelException();
94
                
95
        }
96

    
97

    
98
        public IRasterLayer getNewRasterLayer(String sName,
99
                                                                                        int iDataType,
100
                                                                                        GridExtent extent,
101
                                                                                        int iBands,
102
                                                                                        IOutputChannel channel,
103
                                                                                        Object crs)
104
                                throws UnsupportedOutputChannelException {
105
                if (channel instanceof FileOutputChannel) {
106
                        String sFilename = ((FileOutputChannel)channel).getFilename();
107
                        gvRasterLayer layer = new gvRasterLayer();
108
                        layer.create(sName, sFilename, extent,
109
                                                iDataType, iBands, crs);
110
                        return layer;
111
                } else
112
                        throw new UnsupportedOutputChannelException();
113
        }
114

    
115
        public ITable getNewTable(String sName, Class types[],
116
                                                        String[] sFields, IOutputChannel channel)
117
                                        throws UnsupportedOutputChannelException {
118

    
119
                if (channel instanceof FileOutputChannel) {
120
                        String sFilename = ((FileOutputChannel)channel).getFilename();
121
                        gvTable table = new gvTable();
122
                        table.create(sName, sFilename, types, sFields);
123
                        return table;
124
                } else
125
                        throw new UnsupportedOutputChannelException();
126
        }
127

    
128
        protected String getTempFolder() {
129
                return Utilities.createTempDirectory();
130
        }
131

    
132
        public String[] getRasterLayerOutputExtensions() {
133
                return new String[]{"tif", "asc"};
134
        }
135

    
136
        public String[] getVectorLayerOutputExtensions() {
137
                return new String[]{"shp", "dxf"};
138
        }
139

    
140
        public String[] getTableOutputExtensions() {
141
                return new String[]{"dbf"};
142
        }
143

    
144

    
145
        public void addMessage(String s) {
146
                NotificationManager.addInfo(s, null);
147
        }
148

    
149

    
150
        @Override
151
        public ITaskMonitor getTaskMonitor(String sTitle, boolean bDeterminate,
152
                        JDialog parent) {
153
                return new DefaultTaskMonitor(sTitle, bDeterminate, parent);
154
        }
155

    
156

    
157
        @Override
158
        public Object getDefaultCRS() {
159
                return ((ProjectPreferences) ApplicationLocator.getManager()
160
                                .getPreferences("project")).getDefaultProjection();
161
        }
162
}