Revision 1835

View differences:

org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.postgis.io.DefaultPostGISRasterIOLibrary
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/java/org/gvsig/raster/postgis/io/DefaultPostGISRasterIOLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.raster.postgis.io;
23

  
24
import org.gvsig.fmap.dal.DALFileLibrary;
25
import org.gvsig.fmap.dal.DALLibrary;
26
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
27
import org.gvsig.tools.ToolsLibrary;
28
import org.gvsig.tools.library.AbstractLibrary;
29
import org.gvsig.tools.library.Library;
30
import org.gvsig.tools.library.LibraryException;
31
/**
32
 *
33
 * @author Nacho Brodin (nachobrodin@gmail.com)
34
 */
35
public class DefaultPostGISRasterIOLibrary extends AbstractLibrary {	
36

  
37
	public DefaultPostGISRasterIOLibrary() {
38
		super(DefaultPostGISRasterIOLibrary.class,Library.TYPE.IMPL);
39
		require(ToolsLibrary.class);
40
		require(DALLibrary.class);
41
		require(DALFileLibrary.class);
42
	}
43
	
44
	@Override
45
	protected void doInitialize() throws LibraryException {
46
		//RasterLibrary.wakeUp();
47
	}
48

  
49
	@Override
50
	protected void doPostInitialize() throws LibraryException {
51
		PostGISRasterServerExplorerParameters.registerDynClass();
52
		
53
		PostGISRasterProvider.register();
54
		PostGISRasterDataParameters.registerDynClass();
55
		PostGISRasterDataParameters.registerPersistence();
56
	}
57
}
0 58

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/java/org/gvsig/raster/postgis/io/PostGISRasterCoreException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.raster.postgis.io;
23

  
24
/**
25
 * This exception is thrown when the pool of threads fails
26
 *
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class PostGISRasterCoreException extends Exception {
30
	private static final long serialVersionUID = 1L;
31
	
32
	String message;
33

  
34
	public PostGISRasterCoreException() {
35
		super();
36
	}
37

  
38
	/**
39
	 * Crea ThreadPoolException.
40
	 *
41
	 * @param message
42
	 */
43
	public PostGISRasterCoreException(String message) {
44
        super();
45
        this.message = message;
46
	}
47

  
48
	/**
49
	 * Crea ThreadPoolException.
50
	 *
51
	 * @param message
52
	 * @param cause
53
	 */
54
	public PostGISRasterCoreException(String message, Throwable cause) {
55
		super(format(message, 200), cause);
56
	}
57

  
58
	/**
59
	  * Crea ThreadPoolException.
60
	 *
61
	 * @param cause
62
	 */
63
	public PostGISRasterCoreException(Throwable cause) {
64
		super(cause);
65
	}
66
    
67
    /**
68
     * Cuts the message text to force its lines to be shorter or equal to 
69
     * lineLength.
70
     * @param message, the message.
71
     * @param lineLength, the max line length in number of characters.
72
     * @return the formated message.
73
     */
74
    private static String format(String message, int lineLength){
75
        if (message.length() <= lineLength) return message;
76
        String[] lines = message.split("\n");
77
        String theMessage = "";
78
        for (int i = 0; i < lines.length; i++) {
79
            String line = lines[i].trim();
80
            if (line.length()<lineLength)
81
                theMessage += line+"\n";
82
            else {
83
                String[] chunks = line.split(" ");
84
                String newLine = "";
85
                for (int j = 0; j < chunks.length; j++) {
86
                    int currentLength = newLine.length();
87
                    chunks[j] = chunks[j].trim();
88
                    if (chunks[j].length()==0)
89
                        continue;
90
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
91
                        newLine += chunks[j] + " ";
92
                    else {
93
                        newLine += "\n"+chunks[j]+" ";
94
                        theMessage += newLine;
95
                        newLine = "";
96
                    }
97
                }
98
                
99
            }
100
        }
101
        return theMessage;
102
    }
103
}
0 104

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/java/org/gvsig/raster/postgis/io/PostGISRasterServerExplorer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

  
23
package org.gvsig.raster.postgis.io;
24

  
25
import java.util.List;
26

  
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.DataServerExplorerParameters;
30
import org.gvsig.fmap.dal.DataStoreParameters;
31
import org.gvsig.fmap.dal.NewDataStoreParameters;
32
import org.gvsig.fmap.dal.exception.DataException;
33
import org.gvsig.fmap.dal.exception.InitializeException;
34
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
35
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
36
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
37

  
38
/**
39
 * Server explorer for a PostGIS raster server
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
 @SuppressWarnings("unchecked")
43
public class PostGISRasterServerExplorer implements DataServerExplorerProvider {
44
	public static final String                    NAME                     = PostGISRasterProvider.NAME;
45
	private PostGISRasterServerExplorerParameters parameters               = null;
46
	
47
	public PostGISRasterServerExplorer(
48
			PostGISRasterServerExplorerParameters parameters,
49
			DataServerExplorerProviderServices services)
50
			throws InitializeException {
51
		this.parameters = parameters;
52
	}
53
	
54
	public DataServerExplorerProviderServices getServerExplorerProviderServices() {
55
		return null;
56
	}
57

  
58
	public boolean add(String provider, NewDataStoreParameters parameters,
59
			boolean overwrite) throws DataException {
60
		return false;
61
	}
62

  
63
	public boolean canAdd() {
64
		return false;
65
	}
66

  
67
	public boolean canAdd(String storeName) throws DataException {
68
		return false;
69
	}
70

  
71
	public NewDataStoreParameters getAddParameters(String storeName)
72
			throws DataException {
73
		return null;
74
	}
75

  
76
	public List getDataStoreProviderNames() {
77
		return null;
78
	}
79

  
80
	public DataServerExplorerParameters getParameters() {
81
		return null;
82
	}
83

  
84
	public String getProviderName() {
85
		return null;
86
	}
87

  
88
	public List list() throws DataException {
89
		return null;
90
	}
91

  
92
	public List list(int mode) throws DataException {
93
		return null;
94
	}
95

  
96
	public void remove(DataStoreParameters parameters) throws DataException {
97
		
98
	}
99

  
100
	public void dispose() {
101
		
102
	}
103
	
104
	public DataStoreParameters getStoreParameters() throws PostGISRasterCoreException {
105
		DataManager manager = DALLocator.getDataManager();
106
		PostGISRasterDataParameters params = null;
107
		try {
108
			params = (PostGISRasterDataParameters) manager.createStoreParameters(PostGISRasterProvider.NAME);
109
			params.setURI(parameters.getHost());
110
		} catch (InitializeException e) {
111
			throw new PostGISRasterCoreException("Error initializating parameters", e);
112
		} catch (ProviderNotRegisteredException e) {
113
			throw new PostGISRasterCoreException("Provider not registered", e);
114
		}
115
		return params;
116
	}
117
	
118
}
0 119

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/java/org/gvsig/raster/postgis/io/PostGISRasterProvider.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.raster.postgis.io;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.util.ArrayList;
26
import java.util.Collections;
27
import java.util.Iterator;
28
import java.util.List;
29

  
30
import org.gvsig.fmap.dal.DALLocator;
31
import org.gvsig.fmap.dal.DataManager;
32
import org.gvsig.fmap.dal.DataStore;
33
import org.gvsig.fmap.dal.coverage.RasterLocator;
34
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
35
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
36
import org.gvsig.fmap.dal.coverage.datastruct.DatasetBand;
37
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
38
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
39
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
40
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
41
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
42
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.exception.InitializeException;
45
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
46
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
47
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer;
48
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
49
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
50
import org.gvsig.fmap.dal.store.db.DBStoreParameters;
51
import org.gvsig.metadata.MetadataLocator;
52
import org.gvsig.raster.cache.tile.provider.TileListener;
53
import org.gvsig.raster.gdal.io.GdalDataParameters;
54
import org.gvsig.raster.gdal.io.GdalNative;
55
import org.gvsig.raster.gdal.io.GdalProvider;
56
import org.gvsig.raster.impl.buffer.DefaultRasterQuery;
57
import org.gvsig.raster.impl.datastruct.BandListImpl;
58
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
59
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
60
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
61
import org.gvsig.raster.impl.store.DefaultStoreFactory;
62
import org.gvsig.tools.ToolsLocator;
63
import org.gvsig.tools.task.TaskStatus;
64
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
66
/**
67
 * This class represents the data access just for PostGIS raster databases.
68
 * @author Nacho Brodin (nachobrodin@gmail.com)
69
 */
70
public class PostGISRasterProvider extends GdalProvider {
71
	public static String           NAME                     = "PostGIS Raster Store";
72
	public static String           DESCRIPTION              = "PostGIS Raster file";
73
	public static final String     METADATA_DEFINITION_NAME = "PostGISRasterStore";
74
	private static final String    OVERVIEW_PREFIX          = "o_";
75
	
76
	private DBServerExplorer       dbServerExplorer         = null;
77
	private DBStoreParameters      dbParameters             = null;
78
	private ArrayList<Overview>    overviews                = null;
79
	private DataManager            dataManager              = DALLocator.getDataManager();
80
	private DefaultRasterProvider  selectedProvider         = null;
81
	private Overview               mainOverview             = null;
82
	private static Logger          logger                   = LoggerFactory.getLogger(PostGISRasterProvider.class.getName());
83
	
84
	class Overview implements Comparable<Overview> {
85
		public int                         width               = 0;
86
		public int                         height              = 0;
87
		public int                         factor              = 0;
88
		public double                      pxSizeOverview      = 0;
89
		public DefaultRasterProvider       provider            = null;
90
		
91
		public Overview() {
92
			
93
		}
94
		
95
		public Overview(int f, int w, int h, PostGISRasterDataParameters p) throws NotSupportedExtensionException {
96
			this.width = w;
97
			this.height = h;
98
			this.factor = f;
99
			if(p != null)
100
				createProvider(p);
101
			this.pxSizeOverview = getExtent().width() / (double)w;
102
		}
103
		
104
		public void createProvider(PostGISRasterDataParameters p) throws NotSupportedExtensionException {
105
			GdalDataParameters gdalParams = new GdalDataParameters();
106
			gdalParams.setURI(p.getURI());
107
			try {
108
				this.provider = new GdalProvider(gdalParams, storeServices);
109
			} catch (NotSupportedExtensionException e) {
110
				logger.info("===>" + gdalParams.getURI() + " " + e.getMessage(), e);
111
			}
112
			this.width = (int)provider.getWidth();
113
			this.height = (int)provider.getHeight();
114
			this.pxSizeOverview = provider.getExtent().width() / (double)this.width;
115
		}
116
		
117
		public int compareTo(Overview o) {
118
			if(factor < o.factor)
119
				return -1;
120
			if(factor > o.factor)
121
				return 1;
122
			return 0;
123
		}
124
	}
125
	
126
	public static void register() {
127
		RasterLocator.getManager().registerFileProvidersTiled(PostGISRasterProvider.class);
128
		
129
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
130
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
131
			dataman.registerStoreProvider(NAME,
132
					PostGISRasterProvider.class, PostGISRasterDataParameters.class);
133
		}
134

  
135
		if (!dataman.getExplorerProviders().contains(PostGISRasterProvider.NAME)) {
136
			dataman.registerExplorerProvider(PostGISRasterServerExplorer.NAME, PostGISRasterServerExplorer.class, PostGISRasterServerExplorerParameters.class);
137
		}
138
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
139
	}
140
	
141
	public PostGISRasterProvider() {
142
		
143
	}
144
	
145
	public PostGISRasterProvider (PostGISRasterDataParameters params,
146
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
147
		super(params, storeServices, ToolsLocator.getDynObjectManager()
148
				.createDynObject(
149
						MetadataLocator.getMetadataManager().getDefinition(
150
								DataStore.METADATA_DEFINITION_NAME)));
151
		init(params, storeServices);
152
	}
153
	
154
	/**
155
	 * Creates data base references and loads structures with the information and metadata
156
	 * @param params load parameters
157
	 * @throws NotSupportedExtensionException
158
	 */
159
	public void init (AbstractRasterDataParameters params,
160
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
161
		try {
162
			setParam(storeServices, params);
163
			mainOverview = new Overview();
164
			mainOverview.createProvider((PostGISRasterDataParameters)param);
165
			mainOverview.factor = 1;
166
			file = ((GdalProvider)mainOverview.provider).getNative();
167
			setColorInterpretation(file.getColorInterpretation());
168
			setColorTable(file.getColorTable());
169
			noData = file.getNoDataValue();
170
			wktProjection = file.getProjectionRef();
171
			//CrsWkt crs = new CrsWkt(wktProjection);
172
			//IProjection proj = CRSFactory.getCRS("EPSG:23030");
173
			ownTransformation = file.getOwnTransformation();
174
			externalTransformation = (AffineTransform)ownTransformation.clone();
175
			bandCount = file.getRasterCount();
176
			load();
177
		} catch (Exception e) {
178
			throw new NotSupportedExtensionException("Gdal library can't be initialized with this PostGIS raster parameters", e);
179
		} 
180

  
181
		//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
182
		int[] dt = new int[file.getDataType().length];
183
		for (int i = 0; i < dt.length; i++)
184
			dt[i] = GdalNative.getRasterBufTypeFromGdalType(file.getDataType()[i]);
185
		setDataType(dt);
186
		
187
		PostGISRasterDataParameters p = (PostGISRasterDataParameters)params;
188
		//Object obj = p.getDynValue(PostGISRasterDataParameters.FIELD_DBPARAMS);
189
		dbParameters = (DBStoreParameters)p.getDynValue(PostGISRasterDataParameters.FIELD_DBPARAMS);
190
		dbServerExplorer = (DBServerExplorer)p.getDynValue(PostGISRasterDataParameters.FIELD_DBEXPLORER);
191
	}
192
	
193
	/*
194
	 * (non-Javadoc)
195
	 * @see org.gvsig.raster.impl.provider.RasterProvider#getRMFFile()
196
	 */
197
	public String getRMFFile() {
198
		if(uri.startsWith("PG:host=")) {
199
			String uri = getURI().replace("'", "");
200
			return uri + ".rmf";
201
		} else 
202
			return fileUtil.getNameWithoutExtension(uri) + ".rmf";
203
	}
204
	
205
	/**
206
	 * Reads overviews from database. The overviews in PostGIS raster are loaded 
207
	 * in separated tables. The name of those tables is the same that the original table
208
	 * with a overview prefix. Now this prefix is "o_X_" where the X is a factor scale.
209
	 * 
210
	 * For that reason the overview object contains the DataParameter which correspond
211
	 * to each table.
212
	 * @throws DataException 
213
	 * @throws DataException
214
	 */
215
	@SuppressWarnings("unchecked")
216
	private void readOverviews() throws DataException  {
217
		if(overviews == null) {
218
			overviews = new ArrayList<Overview>();
219
			String mainHost = ((PostGISRasterDataParameters)param).getURI();
220

  
221
			String mainTable = dbParameters.getTable();
222
			List parameters = dbServerExplorer.list();
223

  
224
			int mainFactor = 1; 
225
				
226
			if(isOverview(mainTable, mainTable)) {
227
				mainFactor = getFactor(mainTable);
228
			}
229
			overviews.add(mainOverview);
230
			
231
			Iterator iter = parameters.iterator();
232
			while (iter.hasNext()) {
233
				DBStoreParameters p = (DBStoreParameters) iter.next();
234
				String tname = p.getTable();
235

  
236
				try {
237
					if(isOverview(mainTable, tname)) {
238
						Overview o = new Overview();
239
						o.factor = (getFactor(tname) / mainFactor);
240
						o.width = (int)(getWidth() / o.factor);
241
						o.height = (int)(getHeight() / o.factor);
242
						o.pxSizeOverview = getExtent().width() / (double)o.width;
243
						o.createProvider(createParameters(mainHost, mainTable, tname));
244
						overviews.add(o);
245
					}
246
				} catch (NumberFormatException e) {
247
				} catch (PostGISRasterCoreException e) {
248
				} catch (ValidateDataParametersException e) {
249
				} catch (NotSupportedExtensionException e) {
250
				}
251
			}
252
			Collections.sort(overviews);
253
		}
254
	}
255
	
256
	/**
257
	 * Returns true if tname is an overview of mainTable
258
	 * @param mainTable
259
	 * @param tname
260
	 * @return
261
	 */
262
	private boolean isOverview(String mainTable, String tname) throws NumberFormatException {
263
		if(mainTable.compareTo(tname) != 0) {
264
			return ((tname.endsWith(mainTable) && tname.startsWith(OVERVIEW_PREFIX)) ||
265
					(tname.startsWith(OVERVIEW_PREFIX) && mainTable.startsWith(OVERVIEW_PREFIX) && getFactor(tname) > getFactor(mainTable)));
266
		}
267
		return false;
268
	}
269
	
270
	/**
271
	 * Gets the overview factor number reading the name of the table
272
	 * @param tname
273
	 * @return
274
	 * @throws NumberFormatException
275
	 */
276
	private int getFactor(String tname) throws NumberFormatException {
277
		String factor = tname.substring(tname.indexOf('_') + 1);
278
		factor = factor.substring(0, factor.indexOf('_'));
279
		return new Integer(factor);
280
	}
281
	
282
	/**
283
	 * Creates the list of parameters
284
	 * @param mainHost
285
	 * @param mainTable
286
	 * @param tableName
287
	 * @return
288
	 * @throws PostGISRasterCoreException 
289
	 * @throws PostGISRasterCoreException
290
	 * @throws ProviderNotRegisteredException 
291
	 * @throws InitializeException 
292
	 * @throws ValidateDataParametersException 
293
	 */
294
	@SuppressWarnings("deprecation")
295
	private PostGISRasterDataParameters createParameters(String mainHost, String mainTable, String tableName) throws PostGISRasterCoreException, ValidateDataParametersException, InitializeException, ProviderNotRegisteredException {
296
		String newHost = mainHost.replaceFirst(mainTable, tableName);
297
		
298
		PostGISRasterServerExplorerParameters explorerParams = (PostGISRasterServerExplorerParameters) dataManager.createServerExplorerParameters(PostGISRasterServerExplorer.NAME);
299
		explorerParams.setHost(newHost);
300
		PostGISRasterServerExplorer explorer = (PostGISRasterServerExplorer) dataManager.createServerExplorer(explorerParams);
301
		RasterDataParameters storeParameters = (RasterDataParameters)explorer.getStoreParameters();
302
		storeParameters.setURI(newHost);
303
		return (PostGISRasterDataParameters)storeParameters;
304
	}
305
	
306
	/**
307
	 * Selects the right overview. The right overview means the first 
308
	 * one with a pixel size lesser or equals than the original. 
309
	 * @param pixels
310
	 * @param mts
311
	 */
312
	private void overviewSelector(int pixels, double mts) {
313
		this.selectedProvider = overviews.get(overviews.size() - 1).provider;
314
		//System.out.println("*************" + overviews.get(overviews.size() - 1).pxSizeOverview + "**************");
315
		double pxSizeRequest = mts / (double)pixels;
316
		for (int i = overviews.size() - 1; i > 0; i--) {
317
			Overview ovb = overviews.get(i);
318
			if(pxSizeRequest <= ovb.pxSizeOverview) {
319
				this.selectedProvider = ovb.provider;
320
				//System.out.println(ovb.pxSizeOverview);
321
			}
322
		}
323
		//System.out.println("***************************");
324
	}
325
	
326
	/*
327
	 * (non-Javadoc)
328
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
329
	 */
330
	public void getWindow(Extent ex, int bufWidth, int bufHeight, 
331
			BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
332
//		PostGISRasterDataParameters p = (PostGISRasterDataParameters)param;
333
//		Buffer buf = RasterLocator.getManager().createBuffer(getDataType()[0], bufWidth, bufHeight, getBandCount(), true);
334
//		TileCacheManager m = TileCacheLocator.getManager();
335
//		Tile tile = m.createTile(-1, 0, 0);
336
//		
337
//		//Creamos un BandList con todas las bandas del fichero
338
//		BandList bl = new BandListImpl();
339
//		for(int i = 0; i < getBandCount(); i++) {
340
//			try {
341
//				DatasetBand band = new DatasetBandImpl(selectedProvider.getURIOfFirstProvider(), i, getDataType()[i], getBandCount());
342
//				bl.addBand(band, i);
343
//			} catch(BandNotFoundInListException e) {
344
//				//No a?adimos la banda
345
//			}
346
//		}
347
//		
348
//		if(p.getNumberOfBlocks() > 1) {
349
//			for (int i = 0; i < p.getNumberOfBlocks(); i++) {
350
//				GdalNative gdal;
351
//				try {
352
//					gdal = new GdalNative(p.getURI() + " column='rast' where='rid = " + i + "'");
353
//					gdal.readWindow(buf, bandList, 0, 0, gdal.width, gdal.height, bufWidth, bufHeight);
354
//					Extent ext = gdal.getExtentWithoutRot();
355
//					tile.setUl(new Point2D.Double(ext.getULX(), ext.getULY()));
356
//					tile.setLr(new Point2D.Double(ext.getLRX(), ext.getLRY()));
357
//					tile.setData(new Object[]{buf, null, null});
358
//					listener.tileReady(tile);
359
//				} catch (GdalException e) {
360
//					throw new RasterDriverException("", e);
361
//				} catch (IOException e) {
362
//					throw new RasterDriverException("", e);
363
//				} catch (TileGettingException e) {
364
//					throw new RasterDriverException("", e);
365
//				}
366
//			}
367
//		}
368
		super.getWindow(ex, bufWidth, bufHeight, bandList, listener, status);
369
	}
370

  
371
	/*
372
	 * (non-Javadoc)
373
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
374
	 */
375
	public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) 
376
		throws ProcessInterruptedException, RasterDriverException {
377
		return super.getWindow(ex, bandList, rasterBuf, status);
378
	}
379

  
380
	/*
381
	 * (non-Javadoc)
382
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
383
	 */
384
	public Buffer getWindow(double ulx, double uly, double w, double h, 
385
			BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
386
		return super.getWindow(ulx, uly, w, h, bandList, rasterBuf, adjustToExtent, status);
387
	}
388

  
389
	/*
390
	 * (non-Javadoc)
391
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
392
	 */
393
	public Buffer getWindow(Extent extent, 
394
			int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
395

  
396
		try {
397
			readOverviews();
398
		} catch (DataException e) {
399
			throw new RasterDriverException("Overviews can't be read", e);
400
		}
401

  
402
		overviewSelector(bufWidth, extent.width());
403
		//Creamos un BandList con todas las bandas del fichero
404
		BandList bl = new BandListImpl();
405
		for(int i = 0; i < getBandCount(); i++) {
406
			try {
407
				DatasetBand band = new DatasetBandImpl(selectedProvider.getURIOfFirstProvider(), i, getDataType()[i], getBandCount());
408
				bl.addBand(band);
409
			} catch(BandNotFoundInListException e) {
410
				//No a?adimos la banda
411
			}
412
		}
413
		bl.setDrawableBands(bandList.getDrawableBands());
414

  
415
		DefaultRasterQuery q = (DefaultRasterQuery)RasterLocator.getManager().createQuery();
416
		q.setAreaOfInterest(extent, bufWidth, bufHeight);
417
		q.setBandList(bandList);
418
		q.setBuffer(rasterBuf);
419
		q.setAdjustToExtent(adjustToExtent);
420
		return selectedProvider.getDataSet(q);
421
	}
422

  
423
	/*
424
	 * (non-Javadoc)
425
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
426
	 */
427
	public Buffer getWindow(int x, int y, int w, int h, 
428
			int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException {
429
		return super.getWindow(x, y, w, h, bandList, rasterBuf, status);
430
	}
431

  
432
	/*
433
	 * (non-Javadoc)
434
	 * @see org.gvsig.raster.impl.provider.RasterProvider#isTiled()
435
	 */
436
	/*public boolean isTiled() {
437
		PostGISRasterDataParameters p = (PostGISRasterDataParameters)param;
438
		return p.getNumberOfBlocks() > 1;
439
	}*/
440

  
441
}
0 442

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/java/org/gvsig/raster/postgis/io/PostGISRasterServerExplorerParameters.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

  
23
package org.gvsig.raster.postgis.io;
24

  
25
import org.gvsig.fmap.dal.DataServerExplorerParameters;
26
import org.gvsig.fmap.dal.spi.AbstractDataParameters;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dataTypes.DataTypes;
29
import org.gvsig.tools.dynobject.DelegatedDynObject;
30
import org.gvsig.tools.dynobject.DynClass;
31
import org.gvsig.tools.dynobject.DynField;
32
import org.gvsig.tools.dynobject.DynObjectManager;
33

  
34
/**
35
 * Parameters for the PostGIS Raster provider
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class PostGISRasterServerExplorerParameters extends AbstractDataParameters implements DataServerExplorerParameters {
39
	public static final String     DYNCLASS_NAME       = "PostGISRasterServerExplorerParameters";
40
	protected static final String  FIELD_HOST          = "host";
41
	protected static DynClass      DYNCLASS            = null;
42
	private DelegatedDynObject     delegatedDynObject  = null;
43
	
44
	public PostGISRasterServerExplorerParameters() {
45
		super();
46
		initialize();
47
	}
48

  
49
	protected void initialize() {
50
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
51
				.getDynObjectManager().createDynObject(
52
						DYNCLASS);
53
	}
54
	
55
	@SuppressWarnings("deprecation")
56
	public static void registerDynClass() {
57
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
58
		DynClass dynClass;
59
		DynField field;
60
		
61
		if(dynman == null)
62
			return;
63
		
64
		if (DYNCLASS == null) {
65
			dynClass = dynman.add(DYNCLASS_NAME);
66

  
67
			field = dynClass.addDynField(FIELD_HOST);
68
			field.setTheTypeOfAvailableValues(DynField.ANY);
69
			field.setDescription("Uniform Resource Identifier (File name or URL)");
70
			field.setType(DataTypes.STRING);
71
			field.setMandatory(true);
72
			
73
			DYNCLASS = dynClass;
74
		}
75

  
76
	}
77
	
78
	protected DelegatedDynObject getDelegatedDynObject() {
79
		return delegatedDynObject;
80
	}
81
	
82
	/**
83
	 * Gets the assigned host
84
	 * @return
85
	 */
86
	public String getHost() {
87
		return (String) this.getDynValue(FIELD_HOST);
88
	}
89

  
90
	/**
91
	 * Assign the host to this explorer
92
	 * @param host
93
	 */
94
	public void setHost(String host) {
95
		this.setDynValue(FIELD_HOST, host);
96
	}
97

  
98
	/*
99
	 * (non-Javadoc)
100
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName()
101
	 */
102
	public String getDataStoreName() {
103
		return PostGISRasterProvider.NAME;
104
	}
105
	
106
	/*
107
	 * (non-Javadoc)
108
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDescription()
109
	 */
110
	public String getDescription() {
111
		return PostGISRasterProvider.DESCRIPTION;
112
	}
113

  
114
	public String getExplorerName() {
115
		return PostGISRasterProvider.NAME;
116
	}
117
}
0 118

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/src/main/java/org/gvsig/raster/postgis/io/PostGISRasterDataParameters.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22

  
23
package org.gvsig.raster.postgis.io;
24

  
25
import org.gvsig.fmap.dal.DataParameters;
26
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer;
27
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynobject.DelegatedDynObject;
30
import org.gvsig.tools.dynobject.DynClass;
31
import org.gvsig.tools.dynobject.DynField;
32
import org.gvsig.tools.dynobject.DynObjectManager;
33
import org.gvsig.tools.dynobject.DynStruct;
34
import org.gvsig.tools.persistence.PersistenceManager;
35
import org.gvsig.tools.persistence.PersistentState;
36
import org.gvsig.tools.persistence.exception.PersistenceException;
37

  
38
/**
39
 * Parameters for the PostGIS provider
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public class PostGISRasterDataParameters extends AbstractRasterDataParameters {
43
	public static final String         DYNCLASS_NAME                = "PostGISRasterDataParameters";
44
	protected DelegatedDynObject       delegatedDynObject           = null;
45
	private static DynClass            DYNCLASS                     = null;
46
	public static final String         FIELD_DBPARAMS               = "DBPARAMS";
47
	public static final String         FIELD_DBEXPLORER             = "DBEXPLORER";
48
	protected static final String      FIELD_BLOCKS                 = "BLOCKS";
49
	
50
	public static void registerDynClass() {
51
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
52
		DynClass dynClass;
53
		DynField field;
54
		
55
		if(dynman == null)
56
			return;
57
		
58
		if (DYNCLASS == null) {
59
			dynClass = AbstractRasterDataParameters.registerDynClass(DYNCLASS_NAME);
60
			
61
			field = dynClass.addDynFieldObject(FIELD_DBPARAMS);
62
			field.setDescription("Parameters for the selected table");
63
			field.setClassOfValue(Object.class);
64
			field.setMandatory(false);
65
			
66
			field = dynClass.addDynFieldObject(FIELD_DBEXPLORER);
67
			field.setDescription("Explorer for databases");
68
			field.setClassOfValue(Object.class);
69
			field.setMandatory(false);
70
			
71
			field = dynClass.addDynFieldLong(FIELD_BLOCKS);
72
			field.setDescription("Number of blocks of the selected table.");
73
			field.setClassOfValue(Long.class);
74
			field.setMandatory(true);
75
			
76
			DYNCLASS = dynClass;
77
		}
78
	}
79
	
80
	public PostGISRasterDataParameters() {
81
		super();
82
		initialize();
83
	}
84
	
85
	protected void initialize() {
86
		this.delegatedDynObject = (DelegatedDynObject) ToolsLocator
87
				.getDynObjectManager().createDynObject(
88
						DYNCLASS);
89
	}
90
	
91
	/*
92
	 * (non-Javadoc)
93
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName()
94
	 */
95
	public String getDataStoreName() {
96
		return PostGISRasterProvider.NAME;
97
	}
98

  
99
	/*
100
	 * (non-Javadoc)
101
	 * @see org.gvsig.fmap.dal.DataStoreParameters#getDescription()
102
	 */
103
	public String getDescription() {
104
		return PostGISRasterProvider.DESCRIPTION;
105
	}
106

  
107
	/*
108
	 * (non-Javadoc)
109
	 * @see org.gvsig.raster.impl.store.AbstractRasterDataParameters#loadFromState(org.gvsig.tools.persistence.PersistentState)
110
	 */
111
	public void loadFromState(PersistentState state)
112
	throws PersistenceException {
113
		super.loadFromState(state);
114
	}
115

  
116
	/*
117
	 * (non-Javadoc)
118
	 * @see org.gvsig.raster.impl.store.AbstractRasterDataParameters#saveToState(org.gvsig.tools.persistence.PersistentState)
119
	 */
120
	public void saveToState(PersistentState state) throws PersistenceException {
121
		super.saveToState(state);
122
	}	
123

  
124
	public static void registerPersistence() {
125
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
126
		DynStruct definition = manager.getDefinition("PostGISRasterDataParameters_Persistent");
127
		if( definition == null ) {
128
			definition = manager.addDefinition(
129
					PostGISRasterDataParameters.class,
130
					"PostGISRasterDataParameters_Persistent",
131
					"PostGISRasterDataParameters Persistent",
132
					null, 
133
					null
134
			);
135
			AbstractRasterDataParameters.registerPersistence(definition);
136
		}
137
	}
138

  
139
	@Override
140
	protected DelegatedDynObject getDelegatedDynObject() {
141
		return delegatedDynObject;
142
	}
143

  
144
	public boolean isOverridingHost() {
145
		return false;
146
	}
147

  
148
	public void setOverrideHost(boolean over) {
149
		
150
	}
151
	
152
	public DataParameters getDBStoreParameters() {
153
		return (DataParameters) this.getDynValue(FIELD_DBPARAMS);
154
	}
155
	
156
	public void setDBStoreParameters(DataParameters dbStoreParameters) {
157
		this.setDynValue(FIELD_DBPARAMS, dbStoreParameters);
158
	}
159
	
160
	public DBServerExplorer getDBExplorer() {
161
		return (DBServerExplorer) this.getDynValue(FIELD_DBEXPLORER);
162
	}
163
	
164
	public void setDBExplorer(DBServerExplorer dbStoreParameters) {
165
		this.setDynValue(FIELD_DBEXPLORER, dbStoreParameters);
166
	}
167
	
168
	/**
169
	 * Gets the number of blocks of the selected table
170
	 * @return
171
	 */
172
	public long getNumberOfBlocks() {
173
		return (Long) this.getDynValue(FIELD_BLOCKS);
174
	}
175

  
176
	/**
177
	 * Gets the number of blocks of the selected table
178
	 * @param host
179
	 */
180
	public void setNumberOfBlocks(long blocks) {
181
		this.setDynValue(FIELD_BLOCKS, blocks);
182
	}
183
}
0 184

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.io/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.postgis.io</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.raster.postgis.io</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.raster.postgis</artifactId>
10
		<version>2.0.1-SNAPSHOT</version>
11
	</parent>
12
    <properties>
13
        <build-dir>${basedir}/../../build</build-dir>
14
    </properties>
15
	<dependencies>
16
		<dependency>
17
			<groupId>org.gvsig</groupId>
18
			<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
19
            <scope>compile</scope>
20
		</dependency>
21
        <dependency>
22
            <groupId>org.gvsig</groupId>
23
            <artifactId>org.gvsig.raster.cache.lib.impl</artifactId>
24
            <scope>compile</scope>
25
        </dependency>
26
		<dependency>
27
			<groupId>org.gvsig</groupId>
28
			<artifactId>org.gvsig.raster.lib.api</artifactId>
29
            <scope>compile</scope>
30
		</dependency>
31
        <dependency>
32
            <groupId>org.gvsig</groupId>
33
            <artifactId>org.gvsig.raster.lib.impl</artifactId>
34
            <scope>compile</scope>
35
        </dependency>
36
        <dependency>
37
            <groupId>org.gvsig</groupId>
38
            <artifactId>org.gvsig.fmap.dal</artifactId>
39
            <scope>compile</scope>
40
        </dependency>
41
        <dependency>
42
            <groupId>org.gvsig</groupId>
43
            <artifactId>org.gvsig.fmap.dal</artifactId>
44
            <classifier>spi</classifier>
45
            <scope>compile</scope>
46
        </dependency>
47
        <dependency>
48
            <groupId>org.gvsig</groupId>
49
            <artifactId>org.gvsig.fmap.dal.file</artifactId>
50
            <scope>compile</scope>
51
        </dependency>
52
        <dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.fmap.dal.db</artifactId>
55
            <scope>compile</scope>
56
        </dependency>
57
        <dependency>
58
            <groupId>org.gvsig</groupId>
59
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
60
            <scope>compile</scope>
61
        </dependency>
62
        <dependency>
63
            <groupId>org.gvsig</groupId>
64
            <artifactId>org.gvsig.projection</artifactId>
65
            <scope>compile</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.compat</artifactId>
70
            <scope>compile</scope>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.fmap.geometry</artifactId>
75
            <scope>compile</scope>
76
        </dependency>
77
		<dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.tools.lib</artifactId>
80
            <scope>compile</scope>
81
        </dependency>
82
        <dependency>
83
			<groupId>org.gvsig</groupId>
84
			<artifactId>org.gvsig.raster.gdal.io</artifactId>
85
            <scope>compile</scope>
86
		</dependency>
87
        <dependency>
88
			<groupId>org.gvsig</groupId>
89
			<artifactId>org.gvsig.jgdal</artifactId>
90
            <scope>compile</scope>
91
		</dependency>
92
        <dependency>
93
            <groupId>org.gvsig</groupId>
94
            <artifactId>org.gvsig.jgdal</artifactId>
95
            <classifier>${native_classifier}</classifier>
96
            <type>tar.gz</type>
97
            <scope>runtime</scope>
98
        </dependency>
99
	</dependencies>
100
</project>
0 101

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.swing/org.gvsig.raster.postgis.swing.impl/src/test/java/org/gvsig/raster/postgis/swing/impl/TestConnectionChooserPanel.java
1
package org.gvsig.raster.postgis.swing.impl;
2

  
3

  
4
import javax.swing.JFrame;
5

  
6
import org.gvsig.raster.postgis.swing.impl.addlayer.ConnectionChooserPanel;
7
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
8

  
9
public class TestConnectionChooserPanel {
10
		private int                          w        = 300;
11
		private int                          h        = 100;
12
		private JFrame                       frame    = new JFrame();
13
		private ConnectionChooserPanel       ui       = null;
14

  
15
		public TestConnectionChooserPanel() {
16
			new DefaultLibrariesInitializer().fullInitialize(true);
17
			ui = new ConnectionChooserPanel(true);
18
			frame.getContentPane().add(ui);
19
			frame.setSize(w, h);
20
			frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
21
			frame.setVisible(true);
22
		}
23

  
24
		public static void main(String[] args) {
25
			new TestConnectionChooserPanel();
26
		}
27
	}
0 28

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.swing/org.gvsig.raster.postgis.swing.impl/src/test/java/org/gvsig/raster/postgis/swing/impl/TestAddLayerPanel.java
1
package org.gvsig.raster.postgis.swing.impl;
2

  
3

  
4
import java.text.DecimalFormat;
5

  
6
import javax.swing.JFrame;
7

  
8
import org.gvsig.raster.postgis.swing.impl.addlayer.AddPostGISRasterLayerDialog;
9
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
10

  
11
public class TestAddLayerPanel {
12
		private int                          w        = 300;
13
		private int                          h        = 400;
14
		private JFrame                       frame    = new JFrame();
15
		private AddPostGISRasterLayerDialog  ui       = null;
16

  
17
		public TestAddLayerPanel() {
18
			new DefaultLibrariesInitializer().fullInitialize(true);
19
			ui = new AddPostGISRasterLayerDialog();
20
			frame.getContentPane().add(ui);
21
			frame.setSize(w, h);
22
			frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
23
			frame.setVisible(true);
24
		}
25

  
26
		public static void main(String[] args) {
27
			DecimalFormat decFormat = new DecimalFormat("#.###");
28
			//double d1 = Double.parseDouble("2.0037508E7");
29
			double d2 = Double.parseDouble("-2.003750834E7");
30
			String s = decFormat.format(d2);
31
			System.out.println(s.replace(",", "."));
32
			new TestAddLayerPanel();
33
		}
34
	}
0 35

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.swing/org.gvsig.raster.postgis.swing.impl/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.postgis.swing.impl.PostGISRasterSwingImplLibrary
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.swing/org.gvsig.raster.postgis.swing.impl/src/main/resources/org/gvsig/raster/postgis/swing/impl/i18n/text.properties
1
select_db=Selecci?n de conexi?n
2
tables_chooser=Elecci?n de tablas
3
subdataset_chooser=Elecci?n de subdataset
4
tile_cache=Uso de cach\u00e9 de teselas local
5
tile_cache_tooltip=Marque esta casilla para usar la cach\u00e9 de teselas de almacenamiento local.
0 6

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.swing/org.gvsig.raster.postgis.swing.impl/src/main/java/org/gvsig/raster/postgis/swing/impl/DefaultPostGISRasterSwingManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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 2
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
 */
22
package org.gvsig.raster.postgis.swing.impl;
23

  
24
import org.gvsig.raster.postgis.swing.AddLayerUI;
25
import org.gvsig.raster.postgis.swing.PostGISRasterSwingManager;
26
import org.gvsig.raster.postgis.swing.PostGISRasterWindowManager;
27
import org.gvsig.raster.postgis.swing.impl.addlayer.AddPostGISRasterLayerDialog;
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.i18n.I18nManager;
30

  
31
/**
32
 * Default implementation of the {@link CartociudadSwingManager}.
33
 * 
34
 * @author gvSIG Team
35
 * @version $Id$
36
 */
37
public class DefaultPostGISRasterSwingManager implements PostGISRasterSwingManager {
38

  
39
    private PostGISRasterWindowManager postGISRasterWindowManager;
40
    private I18nManager i18nmanager = null;
41
   // private DataManager dataManager = null;
42

  
43
    public DefaultPostGISRasterSwingManager() {
44
        this.i18nmanager = ToolsLocator.getI18nManager();       
45
       // this.dataManager = DALLocator.getDataManager();
46
    }
47

  
48
    public String getTranslation(String key) {
49
        return this.i18nmanager.getTranslation(key);
50
    }
51

  
52
    public PostGISRasterWindowManager getWindowManager() {
53
        return postGISRasterWindowManager;
54
    }
55

  
56
    public void registerWindowManager(PostGISRasterWindowManager windowManager) {
57
        this.postGISRasterWindowManager = windowManager;        
58
    }
59

  
60
	public AddLayerUI createAddLayerUI() {
61
		return new AddPostGISRasterLayerDialog();
62
	}
63

  
64
}
0 65

  
org.gvsig.raster.postgis/tags/buildNumber_19/org.gvsig.raster.postgis/org.gvsig.raster.postgis.swing/org.gvsig.raster.postgis.swing.impl/src/main/java/org/gvsig/raster/postgis/swing/impl/addlayer/AddPostGISRasterLayerDialog.java
1
package org.gvsig.raster.postgis.swing.impl.addlayer;
2

  
3
import java.awt.BorderLayout;
4
import java.awt.event.ActionListener;
5
import java.util.Arrays;
6
import java.util.List;
7

  
8
import javax.swing.DefaultListModel;
9
import javax.swing.JComboBox;
10
import javax.swing.JComponent;
11
import javax.swing.JPanel;
12
import javax.swing.event.ListSelectionListener;
13

  
14
import org.gvsig.raster.postgis.swing.AddLayerUI;
15

  
16
public class AddPostGISRasterLayerDialog extends JPanel implements AddLayerUI {
17
	private static final long                   serialVersionUID   = 1L;
18
	private AddPostGISRasterLayerMainPanel      mainPanel          = null;
19
	
20
	public AddPostGISRasterLayerDialog() {
21
		init();
22
	}
23
	
24
	private void init() {
25
		setLayout(new BorderLayout());
26
		add(getMainPanel(), BorderLayout.CENTER);
27
	}
28
	
29
	public AddPostGISRasterLayerMainPanel getMainPanel() {
30
		if(mainPanel == null)
31
			mainPanel = new AddPostGISRasterLayerMainPanel();
32
		return mainPanel;
33
	}
34
	
35
	/*
36
	 * (non-Javadoc)
37
	 * @see org.gvsig.raster.postgis.swing.AddLayerUI#addActionListener(java.awt.event.ActionListener)
38
	 */
39
	public void addListenerToNewDBButton(ActionListener event) {
40
		getMainPanel().getNorthPanel().getJButton().addActionListener(event);
41
	}
42
	
43
	/*
44
	 * (non-Javadoc)
45
	 * @see org.gvsig.raster.postgis.swing.AddLayerUI#addListenerToBDSelectionCombo(java.awt.event.ActionListener)
46
	 */
47
	public void addListenerToBDSelectionCombo(ActionListener listener) {
48
		getMainPanel().getNorthPanel().getComboBox().addActionListener(listener);
49
	}
50
	
51
	/*
52
	 * (non-Javadoc)
53
	 * @see org.gvsig.raster.postgis.swing.AddLayerUI#addListenerToTableSelector(java.awt.event.ActionListener)
54
	 */
55
	public void addListenerToTableSelector(ListSelectionListener listener) {
56
		getMainPanel().getList().addListSelectionListener(listener);
57
	}
58
	
59
	/*
60
	 * (non-Javadoc)
61
	 * @see org.gvsig.raster.postgis.swing.AddLayerUI#isAddTableEvent(java.lang.Object)
62
	 */
63
	public boolean isAddTableEvent(Object obj) {
64
		return (obj == getMainPanel().getList());
65
	}
66

  
67
	/*
68
	 * (non-Javadoc)
69
	 * @see org.gvsig.raster.postgis.swing.AddLayerUI#getDBCombo()
70
	 */
71
	public JComboBox getDBCombo() {
72
		return getMainPanel().getNorthPanel().getComboBox();
73
	}
74

  
75
	/*
76
	 * (non-Javadoc)
77
	 * @see org.gvsig.raster.postgis.swing.AddLayerUI#getComponent()
78
	 */
79
	public JComponent getComponent() {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff