001: /*
002: * uDig - User Friendly Desktop Internet GIS client
003: * http://udig.refractions.net
004: * (C) 2004, Refractions Research Inc.
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package net.refractions.udig.catalog.internal.worldimage;
018:
019: import java.io.File;
020: import java.io.IOException;
021: import java.io.Serializable;
022: import java.net.MalformedURLException;
023: import java.net.URL;
024: import java.util.ArrayList;
025: import java.util.List;
026: import java.util.Map;
027:
028: import net.refractions.udig.catalog.IServiceInfo;
029: import net.refractions.udig.catalog.URLUtils;
030: import net.refractions.udig.catalog.rasterings.AbstractRasterGeoResource;
031: import net.refractions.udig.catalog.rasterings.AbstractRasterService;
032:
033: import org.eclipse.core.runtime.IProgressMonitor;
034: import org.geotools.data.coverage.grid.GridFormatFactorySpi;
035:
036: /**
037: * Provides a handle to a world image service allowing the service to be lazily
038: * loaded.
039: * @author mleslie
040: * @since 0.6.0
041: */
042: public class WorldImageServiceImpl extends AbstractRasterService {
043: private WorldImageServiceInfo info;
044: private WorldImageGeoResourceImpl resource;
045:
046: /**
047: * Construct <code>WorldImageServiceImpl</code>.
048: *
049: * @param id
050: * @param factory
051: */
052: public WorldImageServiceImpl(URL id, GridFormatFactorySpi factory) {
053: super (id, factory);
054: }
055:
056: /** Added to prevent creation of new GeoResource on each call to members */
057: public synchronized WorldImageGeoResourceImpl getGeoResource(
058: IProgressMonitor monitor) {
059: if (resource == null) {
060: URL prjURL = null;
061: String filename = getIdentifier().toString();
062: String prjFile = filename.substring(0, filename
063: .indexOf('.'))
064: + ".prj"; //$NON-NLS-1$
065: try {
066: prjURL = new URL(prjFile);
067: } catch (MalformedURLException e) {
068: // TODO Auto-generated catch block
069: e.printStackTrace();
070: }
071:
072: resource = new WorldImageGeoResourceImpl(this , getTitle(),
073: prjURL);
074: }
075: return resource;
076: }
077:
078: @Override
079: public List<AbstractRasterGeoResource> members(
080: IProgressMonitor monitor) throws IOException {
081: List<AbstractRasterGeoResource> list = new ArrayList<AbstractRasterGeoResource>();
082: list.add(getGeoResource(monitor));
083: return list;
084: }
085:
086: public IServiceInfo getInfo(IProgressMonitor monitor)
087: throws IOException {
088: if (this .info == null) {
089: this .info = new WorldImageServiceInfo();
090: }
091: return this .info;
092: }
093:
094: @Override
095: public Map<String, Serializable> getConnectionParams() {
096: return new WorldImageServiceExtension()
097: .createParams(getIdentifier());
098: }
099:
100: public void dispose(IProgressMonitor monitor) {
101: // do nothing
102: }
103:
104: private class WorldImageServiceInfo extends IServiceInfo {
105: WorldImageServiceInfo() {
106: super ();
107: this .keywords = new String[] {
108: "WorldImage", "world image", ".gif", ".jpg", ".jpeg", //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
109: ".tif", ".tiff", ".png" }; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
110: }
111:
112: public String getTitle() {
113: return getIdentifier().getFile();
114: }
115:
116: public String getDescription() {
117: return getIdentifier().toString();
118: }
119: }
120: }
|