Revision 7723

View differences:

org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/test/java/org/gvsig/wcs/app/extension/gui/panel/TestFormatsPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.wcs.app.extension.gui.panel;
20

  
21
import javax.swing.JFrame;
22

  
23
import org.gvsig.raster.wcs.app.wcsclient.gui.panel.FormatPanel;
24

  
25
public class TestFormatsPanel {
26
	private int               w        = 510;
27
	private int               h        = 610;
28
	private JFrame            frame    = new JFrame();
29
	private FormatPanel       desc     = null;
30

  
31
	public TestFormatsPanel() {
32
		desc = new FormatPanel();
33
		frame.getContentPane().add(desc);
34
		frame.setSize(w, h);
35
		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
36
		frame.setVisible(true);
37
	}
38

  
39
	public static void main(String[] args) {
40
		new TestFormatsPanel();
41
	}
42
}
0 43

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/test/java/org/gvsig/wcs/app/extension/gui/panel/TestInfoPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.wcs.app.extension.gui.panel;
20

  
21
import javax.swing.JFrame;
22

  
23
import org.gvsig.raster.wcs.app.wcsclient.gui.panel.InfoPanel;
24

  
25
public class TestInfoPanel {
26
	private int               w        = 510;
27
	private int               h        = 610;
28
	private JFrame            frame    = new JFrame();
29
	private InfoPanel         desc     = null;
30

  
31
	public TestInfoPanel() {
32
		desc = new InfoPanel();
33
		frame.getContentPane().add(desc);
34
		frame.setSize(w, h);
35
		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
36
		frame.setVisible(true);
37
	}
38

  
39
	public static void main(String[] args) {
40
		new TestInfoPanel();
41
	}
42
}
0 43

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/test/java/org/gvsig/wcs/app/extension/gui/panel/TestLayerPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.wcs.app.extension.gui.panel;
20

  
21
import javax.swing.JFrame;
22

  
23
import org.gvsig.raster.wcs.app.wcsclient.gui.panel.LayerPanel;
24

  
25
public class TestLayerPanel {
26
	private int               w        = 510;
27
	private int               h        = 610;
28
	private JFrame            frame    = new JFrame();
29
	private LayerPanel        desc     = null;
30

  
31
	public TestLayerPanel() {
32
		desc = new LayerPanel();
33
		frame.getContentPane().add(desc);
34
		frame.setSize(w, h);
35
		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
36
		frame.setVisible(true);
37
	}
38

  
39
	public static void main(String[] args) {
40
		new TestLayerPanel();
41
	}
42
}
0 43

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/test/java/org/gvsig/wcs/app/extension/gui/panel/TestParameterPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.wcs.app.extension.gui.panel;
20

  
21
import javax.swing.JFrame;
22

  
23
import org.gvsig.raster.wcs.app.wcsclient.gui.panel.ParameterPanel;
24

  
25
public class TestParameterPanel {
26
	private int               w        = 510;
27
	private int               h        = 610;
28
	private JFrame            frame    = new JFrame();
29
	private ParameterPanel    desc     = null;
30

  
31
	public TestParameterPanel() {
32
		desc = new ParameterPanel();
33
		frame.getContentPane().add(desc);
34
		frame.setSize(w, h);
35
		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
36
		frame.setVisible(true);
37
	}
38

  
39
	public static void main(String[] args) {
40
		new TestParameterPanel();
41
	}
42
}
0 43

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/main/java/org/gvsig/raster/wcs/app/wcsclient/WCSClientExtension.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.wcs.app.wcsclient;
23

  
24
import org.gvsig.andami.IconThemeHelper;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.app.extension.AddLayer;
27
import org.gvsig.raster.wcs.app.wcsclient.gui.toc.WCSPropsTocMenuEntry;
28
import org.gvsig.raster.wcs.app.wcsclient.gui.toc.WCSZoomPixelCursorTocMenuEntry;
29
import org.gvsig.raster.wcs.app.wcsclient.gui.wizard.WCSWizard;
30
import org.gvsig.raster.wcs.app.wcsclient.layer.DynObjectSetWCSInfo;
31
import org.gvsig.raster.wcs.app.wcsclient.layer.FLyrWCS;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.extensionpoint.ExtensionPoint;
34

  
35

  
36
/**
37
 * Extension for adding WCS support to gvSIG.
38
 * @author jaume
39
 */
40
public class WCSClientExtension extends Extension {
41
	/**
42
	 * Initializes the toc menu
43
	 */
44
	public void initialize() {
45
		// Adds a new tab to the "add layer" wizard for WCS layer creation
46
		ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add(
47
				"View_TocActions");
48
		
49
		AddLayer.addWizard(WCSWizard.class);
50

  
51
		exPoint.append("WCSProperties", "", new WCSPropsTocMenuEntry());
52
    	exPoint.append("WCSZoomPixel", "", new WCSZoomPixelCursorTocMenuEntry());
53

  
54
		ToolsLocator.getExtensionPointManager().add("CatalogLayers").append(
55
				"OGC:WCS", "", FLyrWCS.class);
56
    	initializeIcons();
57
    	DynObjectSetWCSInfo.registerDynClass();
58
	}
59
	
60
	/*
61
	 * (non-Javadoc)
62
	 * @see org.gvsig.andami.plugins.Extension#postInitialize()
63
	 */
64
	public void postInitialize() {
65
		FLyrWCS.registerPersistent();
66
	}
67

  
68
	public void execute(String actionCommand) {
69
		// no commands, no code.
70
	}
71

  
72
	public boolean isEnabled() {
73
		// may return whatever
74
		return true;
75
	}
76

  
77
	public boolean isVisible() {
78
		// may return whatever
79
		return false;
80
	}
81

  
82
	void initializeIcons(){
83
		IconThemeHelper.registerIcon(null, "view-previsualize-area", this);
84
		IconThemeHelper.registerIcon(null, "ico-WCS-Layer", this);
85
	}
86
}
0 87

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/main/java/org/gvsig/raster/wcs/app/wcsclient/layer/DynObjectSetWCSInfo.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.wcs.app.wcsclient.layer;
23

  
24
import org.gvsig.fmap.dal.feature.FeatureSet;
25
import org.gvsig.tools.ToolsLocator;
26
import org.gvsig.tools.dispose.DisposableIterator;
27
import org.gvsig.tools.dynobject.DynClass;
28
import org.gvsig.tools.dynobject.DynObject;
29
import org.gvsig.tools.dynobject.DynObjectManager;
30
import org.gvsig.tools.dynobject.DynObjectSet;
31
import org.gvsig.tools.exception.BaseException;
32
import org.gvsig.tools.observer.Observable;
33
import org.gvsig.tools.observer.Observer;
34
import org.gvsig.tools.observer.impl.BaseWeakReferencingObservable;
35
import org.gvsig.tools.visitor.Visitor;
36

  
37
/**
38
 * {@link DynObject} implementation to facade of a {@link FeatureSet} and allow
39
 * to be used as a {@link DynObjectSet}.
40
 * 
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 * @version $Id$
43
 */
44
public class DynObjectSetWCSInfo extends BaseWeakReferencingObservable
45
    implements DynObjectSet, Observer {
46
	public static final int             TYPE_TEXT = 0;
47
	public static final int             TYPE_HTML = 1;
48
	public static final int             TYPE_XML  = 2;
49
	private DynObjectIteratorWCSInfo   ite = null;
50
	
51
	public static void registerDynClass() {
52
		DynObjectManager manager = ToolsLocator.getDynObjectManager();
53
    	DynClass dynClass = manager.add("WCSInfoByPoint", "WCS InfoByPoint");
54
    	dynClass.setNamespace("InfoByPoint");
55
    	dynClass.addDynFieldString("info");
56
	}
57
	
58
    /**
59
     * Creates a new facade over a given info, with fast dynobject
60
     * iteration.
61
     */
62
    public DynObjectSetWCSInfo(String txt, int type) {
63
    	DynObjectManager manager = ToolsLocator.getDynObjectManager();
64
    	DynObject dynObject = manager.createDynObject("WCSInfoByPoint");
65
    	dynObject.setDynValue("info", txt);
66
    	ite = new DynObjectIteratorWCSInfo(dynObject);
67
    }
68

  
69
    public void dispose() {
70

  
71
    }
72

  
73
    public void accept(final Visitor visitor, long firstValueIndex) throws BaseException {
74
    	while(ite.hasNext()) {
75
    		visitor.visit(ite.next());
76
    	}
77
    }
78

  
79
    public void accept(final Visitor visitor) throws BaseException {
80
    	while(ite.hasNext()) {
81
    		visitor.visit(ite.next());
82
    	}
83
    }
84

  
85
    public long getSize() throws BaseException {
86
       return ite.getSize();
87
    }
88

  
89
    public DisposableIterator iterator(long index) throws BaseException {
90
        return iterator();
91
    }
92

  
93
    public DisposableIterator iterator() throws BaseException {
94
    	return ite;
95
    }
96

  
97
    public boolean isEmpty() throws BaseException {
98
    	return (getSize() == 0);
99
    }
100

  
101
    public boolean isDeleteEnabled() {
102
    	return true;
103
    }
104

  
105
    public void delete(DynObject dynObject) throws BaseException {
106

  
107
    }
108

  
109
    public boolean isUpdateEnabled() {
110
    	return true;
111
    }
112

  
113
    public void update(DynObject dynObject) throws BaseException {
114
    	System.out.println();
115
    }
116

  
117
    public void update(Observable observable, Object notification) {
118
    	System.out.println();
119
    }
120
}
0 121

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/main/java/org/gvsig/raster/wcs/app/wcsclient/layer/FLyrWCS.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.raster.wcs.app.wcsclient.layer;
42

  
43
import java.awt.Dimension;
44
import java.awt.Graphics2D;
45
import java.awt.Point;
46
import java.awt.Rectangle;
47
import java.awt.geom.AffineTransform;
48
import java.awt.geom.NoninvertibleTransformException;
49
import java.awt.geom.Point2D;
50
import java.awt.geom.Rectangle2D;
51
import java.awt.image.BufferedImage;
52
import java.io.IOException;
53
import java.net.URI;
54
import java.net.URISyntaxException;
55
import java.util.HashMap;
56
import java.util.List;
57

  
58
import javax.print.attribute.PrintRequestAttributeSet;
59

  
60
import org.cresques.cts.IProjection;
61

  
62
import org.gvsig.compat.net.ICancellable;
63
import org.gvsig.fmap.dal.DALLocator;
64
import org.gvsig.fmap.dal.DataManager;
65
import org.gvsig.fmap.dal.DataParameters;
66
import org.gvsig.fmap.dal.DataStore;
67
import org.gvsig.fmap.dal.DataStoreParameters;
68
import org.gvsig.fmap.dal.coverage.RasterLocator;
69
import org.gvsig.fmap.dal.coverage.RasterManager;
70
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
71
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData;
72
import org.gvsig.fmap.dal.coverage.exception.FilePaletteException;
73
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException;
74
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
75
import org.gvsig.fmap.dal.coverage.exception.QueryException;
76
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
77
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
78
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
79
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
80
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
81
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
82
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
83
import org.gvsig.fmap.dal.exception.DataException;
84
import org.gvsig.fmap.dal.exception.InitializeException;
85
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
86
import org.gvsig.fmap.dal.exception.ReadException;
87
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
88
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
89
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
90
import org.gvsig.fmap.geom.GeometryLocator;
91
import org.gvsig.fmap.geom.GeometryManager;
92
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
93
import org.gvsig.fmap.geom.primitive.Envelope;
94
import org.gvsig.fmap.mapcontext.ViewPort;
95
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
96
import org.gvsig.fmap.mapcontext.layers.FLayer;
97
import org.gvsig.fmap.mapcontext.layers.Tiling;
98
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster;
99
import org.gvsig.raster.fmap.layers.IRasterLayerActions;
100
import org.gvsig.raster.fmap.layers.NotAvailableStateException;
101
import org.gvsig.raster.util.CancelTaskImpl;
102
import org.gvsig.raster.wcs.io.WCSDataParameters;
103
import org.gvsig.raster.wcs.io.WCSProvider;
104
import org.gvsig.raster.wcs.io.WCSServerExplorer;
105
import org.gvsig.raster.wcs.io.WCSServerExplorerParameters;
106
import org.gvsig.tools.ToolsLocator;
107
import org.gvsig.tools.dynobject.DynObjectSet;
108
import org.gvsig.tools.dynobject.DynStruct;
109
import org.gvsig.tools.persistence.PersistenceManager;
110
import org.gvsig.tools.task.Cancellable;
111
import org.gvsig.tools.task.SimpleTaskStatus;
112
import org.gvsig.tools.task.TaskStatusManager;
113

  
114
import org.slf4j.Logger;
115
import org.slf4j.LoggerFactory;
116

  
117

  
118
/**
119
 * Class for the WCS layer.
120
 *
121
 * Capa para el WCS.
122
 *
123
 * Las capas WCS son tileadas para descargarlas del servidor. Esto quiere decir que
124
 * est?n formadas por multiples ficheros raster. Por esto la fuente de datos raster (IRasterDatasource)
125
 * de la capa FLyrWCS es un objeto de tipo CompositeDataset. Este objeto est? compuesto por un array
126
 * bidimensional de MultiRasterDataset. Cada uno de los MultiRasterDataset corresponde con un tile
127
 * salvado en disco. Estos MultiRasterDataset se crean cada vez que se repinta ya que en WCS a cada
128
 * zoom varian los ficheros fuente. La secuencia de creaci?n de un CompositeDataset ser?a la siguiente:
129
 * <UL>
130
 * <LI>Se hace una petici?n de dibujado por parte del usuario llamando al m?todo draw de FLyrWCS</LI>
131
 * <LI>Se tilea la petici?n</LI>
132
 * <LI>Cada tile se dibuja abriendo una FLyrRaster para ese tile</LI>
133
 * <LI>Si es el primer dibujado se guarda una referencia en la capa WCS a las propiedades de renderizado, orden de bandas,
134
 * transparencia, filtros aplicados, ...</LI>
135
 * <LI>Si no es el primer dibujado se asignan las propiedades de renderizado cuya referencia se guarda en la capa WCS</LI>
136
 * <LI>Se guarda el MultiRasterDataset de cada tile</LI>
137
 * <LI>Al acabar todos los tiles creamos un CompositeDataset con los MultiRasterDataset de todos los tiles</LI>
138
 * <LI>Asignamos a la capa la referencia de las propiedades de renderizado que tenemos almacenadas. De esta forma si hay
139
 * alguna modificaci?n desde el cuadro de propiedades ser? efectiva sobre los tiles que se dibujan.</LI>
140
 * </UL>
141
 *
142
 * @author jaume - jaume.dominguez@iver.es
143
 */
144
@SuppressWarnings("deprecation")
145
public class FLyrWCS extends DefaultFLyrRaster {
146
    private static final int             MAX_RETRY_TIMES           = 5;
147

  
148
    private static final GeometryManager geomManager               = GeometryLocator.getGeometryManager();
149
    private static final Logger          logger                    = LoggerFactory.getLogger(FLyrWCS.class);
150
    private boolean 					 isPrinting                = false;
151

  
152
    private boolean 					 mustTileDraw              = false;
153
    private int 						 maxTileDrawWidth          = 1023;
154
    private int							 maxTileDrawHeight         = 1023;
155
    private final int 					 maxTilePrintWidth         = 1023;
156
    private final int 					 maxTilePrintHeight        = 1023;
157

  
158
    private boolean						 firstLoad                 = false;
159
    private Envelope					 fullEnvelope              = null;
160
    private int                          callCount;
161
    private RasterManager                rManager                  = RasterLocator.getManager();
162
    private boolean                      deleteCache               = false;
163

  
164
    @SuppressWarnings("unused")
165
    private class MyCancellable implements ICancellable {
166
        private Cancellable original;
167

  
168
        public MyCancellable(Cancellable cancelOriginal) {
169
            this.original = cancelOriginal;
170
        }
171

  
172
        public boolean isCanceled() {
173
            return original.isCanceled();
174
        }
175

  
176
        public Object getID() {
177
            return this;
178
        }
179
    }
180

  
181
    public FLyrWCS() {
182
        super();
183
        this.updateDrawVersion();
184
        try {
185
            enableAwake();
186
        } catch (NotAvailableStateException e) {
187
            logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
188
        }
189
    }
190

  
191
    public FLyrWCS(DataStoreParameters dataStoreParameters) throws Exception {
192
        this();
193
        //Create the explorer and connect
194
        DataManager dataManager = DALLocator.getDataManager();
195
        WCSServerExplorerParameters explorerParams = (WCSServerExplorerParameters)
196
        dataManager.createServerExplorerParameters(WCSProvider.NAME);
197
        explorerParams.setHost((String)dataStoreParameters.getDynValue("uri"));
198
        WCSServerExplorer wmsServerExplorer =
199
            (WCSServerExplorer) dataManager.openServerExplorer(WCSProvider.NAME, explorerParams);
200
        wmsServerExplorer.connect(null);
201
        wmsServerExplorer.getCoverageList();
202

  
203
        //Set the parameters
204
        setParameters((WCSDataParameters)dataStoreParameters);
205
        setExplorer(wmsServerExplorer);
206
    }
207

  
208
    public static DataStore createDataStore(String host, IProjection srs) throws InitializeException {
209
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
210
        RasterDataParameters params = null;
211
        try {
212
            params = (RasterDataParameters)dataman.createServerExplorerParameters(WCSProvider.NAME);
213
        } catch (InitializeException e) {
214
            return null;
215
        } catch (ProviderNotRegisteredException e) {
216
            return null;
217
        }
218
        URI uriHost;
219
        try {
220
            uriHost = new URI(host);
221
        } catch (URISyntaxException e1) {
222
            throw new InitializeException(e1);
223
        }
224
        params.setURI(uriHost);
225
        params.setSRS(srs);
226

  
227
        try {
228
            return dataman.openStore(params.getDataStoreName(), params);
229
        } catch (ValidateDataParametersException e) {
230
            throw new InitializeException(e);
231
        } catch (ProviderNotRegisteredException e) {
232
            throw new InitializeException(e);
233
        }
234
    }
235

  
236
    public void setDataStore(DataStore dataStore) throws LoadLayerException {
237
        this.dataStore = (RasterDataStore) dataStore;
238
        try {
239
            if(this.dataStore.isOpen())
240
                enableOpen();
241
        } catch (NotAvailableStateException e) {
242
            logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
243
        }
244
        setProjection(this.dataStore.getProjection());
245
    }
246

  
247
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws ReadException {
248
        TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
249
		SimpleTaskStatus taskStatus = new RasterTaskStatus("Drawing " + getName() + "...", cancel);
250
		manager.add(taskStatus);
251
		taskStatus.setAutoremove(true);
252

  
253
        if(!firstLoad) {
254
            try {
255
                initFilters();
256
                try {
257
					if(!isOpen())
258
						enableOpen();
259
				} catch (NotAvailableStateException e) {
260
					throw new ReadException("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), e);
261
				}
262
            } catch (FilePaletteException e) {
263
                logger.error(e.getMessage(), this, e);
264
            }
265
            firstLoad = true;
266
        }
267

  
268
        callCount = 0;
269

  
270
        enableStopped();
271

  
272
        if(recalcLevel) {
273
			double pixelSize = viewPort.getEnvelope().getLength(0) / (double)viewPort.getImageWidth();
274
			zoomLevel = dataStore.getNearestLevel(pixelSize);
275
		}
276
		recalcLevel = true;
277

  
278
        if (isWithinScale(scale)) {
279

  
280
            if(mustTileDraw) {
281
                Point2D p = viewPort.getOffset();
282
                Rectangle r = new Rectangle((int) p.getX(), (int) p.getY(), viewPort.getImageWidth(), viewPort.getImageHeight());
283
                Tiling tiles = new Tiling(maxTileDrawWidth, maxTileDrawHeight, r);
284
                tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
285

  
286
                for (int tileNr = 0; tileNr < tiles.getNumTiles(); tileNr++) {
287
                    // drawing part
288
                    try {
289
                        ViewPort vp = tiles.getTileViewPort(viewPort, tileNr);
290
                        drawTile(g, vp, taskStatus, scale);
291
                    } catch (LoadLayerException e) {
292
                        throw new ReadException(e.getMessage(), e);
293
                    } catch (NoninvertibleTransformException e) {
294
                        throw new ReadException(e.getMessage(), e);
295
                    }
296
                }
297
            } else {
298
                try {
299
                    drawTile(g, viewPort, taskStatus, scale);
300
                } catch (LoadLayerException e) {
301
                    throw new ReadException(e.getMessage(), e);
302
                }
303
            }
304
        }
305
        disableStopped();
306

  
307
        /*Runtime r = Runtime.getRuntime();
308
		System.err.println("********************WCS**********************");
309
		System.err.println("Memoria Total: " + (r.totalMemory() / 1024) +"KB");
310
		System.err.println("Memoria Usada: " + ((r.totalMemory() - r.freeMemory()) / 1024) +"KB");
311
		System.err.println("Memoria Libre: " + (r.freeMemory() / 1024) +"KB");
312
		System.err.println("Memoria MaxMemory: " + (r.maxMemory() / 1024) +"KB");
313
		System.err.println("*********************************************");*/
314
    }
315

  
316
    /**
317
     * This is the method used to draw a tile in a WCS mosaic layer.
318
     * @throws LoadLayerException
319
     * @throws ReadDriverException
320
     * @return true when a tile has been painted
321
     */
322
    private void drawTile(Graphics2D g, ViewPort vp, SimpleTaskStatus taskStatus, double scale) throws LoadLayerException, ReadException {
323
        callCount++;
324

  
325
        // Compute the query geometry
326
        // 1. Check if it is within borders
327
        Envelope envelope = getFullEnvelope();
328
        Envelope vpEnv = vp.getAdjustedExtent();
329
        if (!vpEnv.intersects(envelope)) {
330
            return;
331
        }
332

  
333
        // 2. Compute extent to be requested.
334
        Rectangle2D bBox = new Rectangle2D.Double();
335
        Rectangle2D.intersect(getRectable2DFromEnvelope(vpEnv),
336
            getRectable2DFromEnvelope(envelope), bBox);
337

  
338
        // 3. Compute size in pixels
339
        double scalex = vp.getAffineTransform().getScaleX();
340
        double scaley = vp.getAffineTransform().getScaleY();
341
        int wImg = (int) Math.ceil(Math.abs(bBox.getWidth() * scalex) + 1);
342
        int hImg = (int) Math.ceil(Math.abs(bBox.getHeight() * scaley) + 1);
343

  
344
        Dimension sz = new Dimension(wImg, hImg);
345

  
346
        if ((wImg <= 0) || (hImg <= 0)) {
347
            return;
348
        }
349

  
350
        try {
351
            //Rectangle2D extent = new Rectangle2D.Double();
352
            //Rectangle2D.Double vpExtent = this.getRectable2DFromEnvelope(vpEnv);
353
            //Rectangle2D.intersect(vpExtent, bBox, extent);
354

  
355
            Envelope vpAdjustedEnvelope = vp.getAdjustedEnvelope();
356
            Extent ex = rManager.getDataStructFactory().createExtent(
357
                vpAdjustedEnvelope.getMinimum(0),
358
                vpAdjustedEnvelope.getMaximum(1),
359
                vpAdjustedEnvelope.getMaximum(0),
360
                vpAdjustedEnvelope.getMinimum(1));
361
            ViewPortData vpData = rManager.getDataStructFactory().createViewPortData(vp.getProjection(), ex, sz );
362
            vpData.setMat(vp.getAffineTransform());
363
            vpData.setDPI((int)vp.getDPI());
364

  
365
            try {
366
                getParameters().setExtent(bBox);
367
                getParameters().setWidth(wImg);
368
                getParameters().setHeight(hImg);
369
                if(getDataStore().getParameters() instanceof WCSDataParameters) {
370
					getRender().draw(g, vpData, taskStatus);
371
                } else {
372
                	Envelope adjustedExtent = vp.getAdjustedExtent();
373
					Extent e = rManager.getDataStructFactory().createExtent(adjustedExtent.getLowerCorner().getX(),
374
							adjustedExtent.getUpperCorner().getY(), adjustedExtent.getUpperCorner().getX(),
375
							adjustedExtent.getLowerCorner().getY());
376
					ViewPortData vp2 = rManager.getDataStructFactory().createViewPortData(vp.getProjection(), e, vp.getImageSize() );
377
					vp2.setMat(vp.getAffineTransform());
378
					vp2.setDPI((int)vp.getDPI());
379
					getParameters().setExtent(ex.toRectangle2D());
380
					getRender().drawTiledService(g, vp2, vp.getImageSize(), taskStatus);
381
                }
382
            /*} catch (RasterDriverException e) {
383
            	setAvailable(false);
384
				JOptionPane.showMessageDialog(null, "Problems drawing this layer:" + e.getMessage(), Messages.getText("Error"), JOptionPane.ERROR_MESSAGE);
385
				logger.info("Problems drawing this layer:" + e.getMessage(), e);*/
386
            } catch (ProcessInterruptedException e) {
387
            } catch (QueryException e) {
388
            	throw new RemoteServiceException("Problems drawing this layer: " + e.getMessage(), e);
389
			} finally {
390
            	taskStatus.terminate();
391
            }
392

  
393
        } catch (RemoteServiceException e) {
394
            if (!taskStatus.isCancellationRequested()) {
395
                if (callCount < MAX_RETRY_TIMES) {
396
                    logger.warn("\n[ FLyrWCS.drawFixedSize() ]  Failed in trying " + callCount + "/" + MAX_RETRY_TIMES + ")\n"); // mess code
397
                    drawTile(g, vp, taskStatus, scale);
398
                } else {
399
                    if (!isPrinting) {
400
                        this.setVisible(false);
401
                    }
402
                    throw new LoadLayerException(getName(), e);
403
                }
404
            }
405
        }
406
        callCount--;
407
        return;
408
    }
409

  
410
    /**
411
     * <p>
412
     * Gets the max resolution allowed by the coverage. Requesting a higher resolution
413
     * than this value does not cause any error, but the info responsed is just an
414
     * interpolation. <br>
415
     * </p>
416
     *
417
     * <p>
418
     * In exchange for obtaining a greater file and without additional information,
419
     * we can easily fit it into the View. <br>
420
     * </p>
421
     *
422
     * <p>
423
     * Obtiene la resoluci?n m?xima soportada por la cobertura. La petici?n
424
     * de una resoluci?n superior a la soportada no provoca ning?n error, aunque
425
     * la informaci?n obtenida s?lo es una mera interpolaci?n de informaci?n. <br>
426
     * </p>
427
     *
428
     * <p>
429
     * A cambio de obtener un archivo mayor y sin informaci?n adicional, podemos
430
     * f?cilmente acoplarlo a la vista. <br>
431
     * </p>
432
     *
433
     * @return double
434
     */
435
    public Point2D getMaxResolution() {
436
        return getExplorer().getMaxResolution(getName());
437
    }
438

  
439
    private Rectangle2D.Double getRectable2DFromEnvelope(Envelope env) {
440
        return new Rectangle2D.Double(env.getMinimum(0), env.getMinimum(1), env
441
            .getLength(0), env.getLength(1));
442
    }
443

  
444

  
445
    /**
446
     * Gets the explorer
447
     * @return
448
     */
449
    public WCSServerExplorer getExplorer() {
450
    	try {
451
			return (WCSServerExplorer)getDataStore().getExplorer();
452
		} catch (ValidateDataParametersException e) {
453
			logger.debug("Error getting the explorer", e);
454
		} catch (DataException e) {
455
			logger.debug("Error getting the explorer", e);
456
		}
457
    	return null;
458
    }
459

  
460
    /**
461
     * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
462
     * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
463
     * @param sz Tama?o de la imagen en pixeles.
464
     * @return el 'WorldFile', como String.
465
     * @throws IOException
466
     */
467
    public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException {
468
        StringBuffer data = new StringBuffer();
469
        data.append((bBox.getMaxX() - bBox.getMinX()) / (sz.getWidth() - 1) + "\n");
470
        data.append("0.0\n");
471
        data.append("0.0\n");
472
        data.append("-" + (bBox.getMaxY() - bBox.getMinY()) / (sz.getHeight() - 1) + "\n");
473
        data.append("" + bBox.getMinX() + "\n");
474
        data.append("" + bBox.getMaxY() + "\n");
475
        return data.toString();
476
    }
477

  
478
    public FLayer cloneLayer() throws Exception {
479
        RasterDataStore  ds = dataStore.cloneDataStore();
480
        FLyrWCS layer = new FLyrWCS();
481
        layer.setName(getParameters().getCoverageName());
482
        layer.setOpenRasterStore(ds);
483
        layer.fullEnvelope = fullEnvelope;
484
        layer.setExplorer(getExplorer());
485

  
486
        List<RasterFilter> filters = getRender().getFilterList().getStatusCloned();
487

  
488
        //Hacemos una copia de las bandas a renderizar
489
        ColorInterpretation ci = getRender().getRenderColorInterpretation();
490
		if(ci != null) {
491
			layer.getRender().setRenderColorInterpretation(ci.cloneColorInterpretation());
492
		}
493

  
494
        //Asignamos el entorno
495
        if(layer.getRender().getFilterList() == null)
496
            layer.getRender().setFilterList(RasterLocator.getManager().createEmptyFilterList(getRender().getFilterList().getInitDataType()));
497
        layer.getRender().getFilterList().setEnv(getRender().getFilterList().getEnv());
498
        layer.getRender().getFilterList().setStatus(filters);
499

  
500
        // Asignamos los valores noData del original
501
        layer.setNoDataValue(getNoDataValue());
502
        if(dataStore.getNoDataValue().isDefined())
503
        	layer.setNoDataTransparent(true);
504
        layer.enableOpen();
505

  
506
        return layer;
507
    }
508

  
509
    public Transparency getRenderTransparency() {
510
        return getRender().getRenderingTransparency();
511
    }
512

  
513
    public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale, PrintRequestAttributeSet properties) throws ReadException {
514
        if (isVisible() && isWithinScale(scale)){
515
            draw(null, g, viewPort, cancel, scale);
516
        }
517
    }
518

  
519
    /**
520
     * Inserta la extensi?n total de la capa en la proyeccion original.
521
     *
522
     * @param fullExtent
523
     *            Rect?ngulo.
524
     */
525
    public void setFullEnvelope(Envelope envelope) {
526
        Envelope cur = this.getFullEnvelope();
527
        if (cur == envelope) {
528
            return;
529
        }
530
        if (cur != null && cur.equals(envelope)) {
531
            return;
532
        }
533

  
534
        this.fullEnvelope = envelope;
535
        this.updateDrawVersion();
536
    }
537

  
538
    /**
539
     * Sets the layer's full extent.
540
     *
541
     * Establece la extensi?n m?xima de la capa.
542
     *
543
     * @param rect
544
     */
545
    public void setFullExtent(Rectangle2D fullExtent) {
546
        this.setFullEnvelope(this.getEnvelopeFromRectable2D(fullExtent));
547
    }
548

  
549
    private Envelope getEnvelopeFromRectable2D(Rectangle2D rect) {
550
        try {
551
            return geomManager.createEnvelope(rect.getMinX(), rect.getMinY(),
552
                rect.getMaxX(), rect.getMaxY(),
553
                SUBTYPES.GEOM2D);
554
        } catch (CreateEnvelopeException e) {
555
            logger.error("Error creating the envelope", e);
556
        }
557
        return null;
558
    }
559

  
560

  
561
    public HashMap<String, Object> getProperties() {
562
        HashMap<String, Object> info = new HashMap<String, Object>();
563
        try {
564
            info.put("name", getName());
565
            info.put("selectedLayers", getParameters().getCoverageName());
566
            info.put("host", getParameters().getURI());
567
            info.put("crs", getParameters().getSRSCode());
568
            info.put("format", getParameters().getFormat());
569
            info.put("time", getParameters().getTime());
570
            return info;
571
        } catch (Exception e) {
572
            e.printStackTrace();
573
        }
574
        return null;
575
    }
576

  
577
    public int[] getTileSize() {
578
        int[] size = {maxTileDrawWidth, maxTileDrawHeight};
579
        return size;
580
    }
581

  
582
    public String getTocImageIcon() {
583
        return "ico-WCS-Layer";
584
    }
585

  
586
    public boolean isTiled() {
587
        return mustTileDraw;
588
    }
589

  
590
	public boolean isRemote() {
591
		return true;
592
	}
593

  
594
    @Override
595
    public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel,
596
        boolean fast) throws LoadLayerException, DataException {
597

  
598
        //try {
599
        ViewPort viewPort = getMapContext().getViewPort();
600

  
601
        Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight);
602
        Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
603
        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
604
        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
605
        int nCols = tiles.getNumCols();
606

  
607
        int col = (int) p.getX() / maxTilePrintWidth;
608
        int row = (int) p.getY() / maxTilePrintHeight;
609
        int tileIndex = (row * nCols) + col;
610

  
611
        ViewPort vp = null;
612
        try {
613
            vp = tiles.getTileViewPort(viewPort, tileIndex);
614
        } catch (NoninvertibleTransformException e1) {
615
            throw new LoadLayerException("", e1);
616
        }
617

  
618
        getParameters().setExtent(this.getRectable2DFromEnvelope(vp.getAdjustedExtent()));
619
        getParameters().setWidth(vp.getImageWidth());
620
        getParameters().setHeight(vp.getImageHeight());
621

  
622
        CancelTaskImpl cancellable = new CancelTaskImpl(cancel);
623
        getParameters().setCancellable(cancellable);
624

  
625
        String fInfo;
626
        try {
627
            fInfo = getDataStore().getInfoByPoint(tiledPoint.getX(), tiledPoint.getY(), cancellable);
628
        } catch (InfoByPointException e) {
629
            throw new LoadLayerException("Error in getInfoByPoint", e);
630
        }
631
        return new DynObjectSetWCSInfo(fInfo, DynObjectSetWCSInfo.TYPE_TEXT);
632
    }
633

  
634
	@Override
635
	public String getFileFormat() {
636
		return "WCS";
637
	}
638

  
639
    public boolean isActionEnabled(int action) {
640
        switch (action) {
641
        case IRasterLayerActions.ZOOM_PIXEL_RESOLUTION:
642
        case IRasterLayerActions.FLYRASTER_BAR_TOOLS:
643
        case IRasterLayerActions.BANDS_FILE_LIST:
644
        case IRasterLayerActions.GEOLOCATION:
645
        case IRasterLayerActions.PANSHARPENING:
646
        case IRasterLayerActions.SAVE_COLORINTERP:
647
            return false;
648
        case IRasterLayerActions.BANDS_RGB:
649
        case IRasterLayerActions.REMOTE_ACTIONS:
650
        case IRasterLayerActions.COLOR_TABLE:
651
            return true;
652
        }
653

  
654
        return super.isActionEnabled(action);
655
    }
656

  
657
    public boolean overviewsSupport() {
658
        return false;
659
    }
660

  
661
    public org.gvsig.fmap.dal.coverage.datastruct.Extent getFullRasterExtent() {
662
        Envelope env = getFullEnvelope();
663
        double minx = env.getMinimum(0);
664
        double miny = env.getMinimum(1);
665
        double maxx = env.getMaximum(0);
666
        double maxy = env.getMaximum(1);
667
        Point2D ul = new Point2D.Double(minx, maxy);
668
        Point2D ur = new Point2D.Double(maxx, maxy);
669
        Point2D ll = new Point2D.Double(minx, miny);
670
        Point2D lr = new Point2D.Double(maxx, miny);
671
        return rManager.getDataStructFactory().createExtent(ul, lr, ur, ll);
672
    }
673

  
674
    public WCSDataParameters getParameters() {
675
        /*if(params == null) {
676
            DataManager datamanager = DALLocator.getDataManager();
677
            WCSServerExplorerParameters explorerParams = null;
678
            try {
679
                explorerParams = (WCSServerExplorerParameters) datamanager.createServerExplorerParameters(WCSServerExplorer.NAME);
680
                explorerParams.setHost("");
681
                explorer = (WCSServerExplorer) datamanager.createServerExplorer(explorerParams);
682
                DataStoreParameters parameters = explorer.getStoreParameters();
683
                if(parameters instanceof WCSDataParameters) {
684
                    params = (WCSDataParameters) parameters;
685
                }
686
            } catch (InitializeException e) {
687
            } catch (ProviderNotRegisteredException e) {
688
            } catch (ValidateDataParametersException e) {
689
            }
690
        }*/
691
        return getWCSParameters(getDataStore().getParameters());
692
    }
693

  
694
    /**
695
     * Gets <code>WCSDataParameters</code>
696
     * @param parameters
697
     * @return
698
     */
699
    private WCSDataParameters getWCSParameters(DataStoreParameters parameters) {
700
    	WCSDataParameters params = null;
701
    	if(parameters instanceof WCSDataParameters) {
702
			params = (WCSDataParameters) parameters;
703
		}
704

  
705
		if(parameters instanceof TileDataParameters) {
706
			DataParameters p = ((TileDataParameters) parameters).getDataParameters();
707
			if(p instanceof WCSDataParameters) {
708
				params = (WCSDataParameters) p;
709
			}
710
		}
711
		return params;
712
    }
713

  
714
    /**
715
     * Sets the explorer
716
     * @param explorer
717
     */
718
    public void setExplorer(WCSServerExplorer explorer) {
719
    	if(getDataStore() != null)
720
    		getDataStore().setExplorer(explorer);
721
    }
722

  
723
    /**
724
	 * Assigns the flag to delete this layer from the cache
725
	 * @param selected
726
	 */
727
	public void deleteCache(boolean deleteCache) {
728
		this.deleteCache = deleteCache;
729
	}
730

  
731
    /**
732
     * Sets the data store parameters
733
     * @param params
734
     * @throws InitializeException
735
     */
736
    public void setParameters(DataStoreParameters params) throws InitializeException {
737
        if(params instanceof TileDataParameters) {
738
			((TileDataParameters)params).deleteCache(deleteCache);
739
		}
740

  
741
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
742
        try {
743
            DataStore dStore = dataman.openStore(params.getDataStoreName(), params);
744
            this.setDataStore(dStore);
745

  
746
			if(params instanceof WCSDataParameters) {
747
				this.setName(((WCSDataParameters)params).getURI().getPath());
748
			}
749

  
750
			if(params instanceof TileDataParameters) {
751
				DataParameters p = ((TileDataParameters) params).getDataParameters();
752
				if(p instanceof WCSDataParameters) {
753
					this.setName(((WCSDataParameters)p).getURI().getPath());
754
				}
755
			}
756
        } catch (ValidateDataParametersException e) {
757
            throw new InitializeException(e);
758
        } catch (ProviderNotRegisteredException e) {
759
            throw new InitializeException(e);
760
        } catch (LoadLayerException e) {
761
            throw new InitializeException(e);
762
        }
763
    }
764

  
765
	/*@Override
766
	public void loadFromState(PersistentState state)
767
	throws PersistenceException {
768
		String host = state.getString("host");
769

  
770
		getParameters();
771
		((WCSServerExplorerParameters)explorer.getParameters()).setHost(host);
772

  
773
		if(!explorer.isHostReachable()) {
774
			loadDataStore = false;
775
			super.loadFromState(state);
776
			return;
777
		}
778

  
779
		try {
780
			explorer.connect(new CancelTaskImpl());
781
			explorer.getCoverageList();
782
		} catch (Exception e) {
783
			loadDataStore = false;
784
			super.loadFromState(state);
785
			return;
786
		}
787

  
788
		loadDataStore = true;
789

  
790
		super.loadFromState(state);
791
		params = getDataStore().getParameters();
792
		this.fullEnvelope = (Envelope) state.get("fullEnvelope");
793
		try {
794
			if(this.dataStore.isOpen())
795
				enableOpen();
796
		} catch (NotAvailableStateException e) {
797
			logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
798
		}
799
		//getParameters().setCoverageName((String)state.get("name"));
800
	}*/
801

  
802
    /*@Override
803
	public void saveToState(PersistentState state) throws PersistenceException {
804
		super.saveToState(state);
805
		state.set("fullEnvelope", this.fullEnvelope);
806
		state.set("host", getParameters().getURI());
807
		state.set("name", getName());
808
	}*/
809

  
810
	/*public static void registerPersistent() {
811
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
812
		DynStruct definition = manager.getDefinition(PERSISTENT_NAME);
813
		if( definition == null ) {
814
			if (manager.getDefinition(FLyrDefault.class) == null) {
815
				FLyrDefault.registerPersistent();
816
			}
817

  
818
			definition = manager.addDefinition(
819
					FLyrWCS.class,
820
					PERSISTENT_NAME,
821
					PERSISTENT_DESCRIPTION,
822
					null,
823
					null
824
			);
825

  
826
			definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, "FLyrDefault");
827
		}
828

  
829
		DefaultFLyrRaster.registerPersistence(definition);
830
		definition.addDynFieldObject("fullEnvelope").setClassOfValue(Envelope.class).setMandatory(false);
831
		definition.addDynFieldString("host").setMandatory(false);
832
		definition.addDynFieldString("name").setMandatory(false);
833
	}*/
834

  
835
	public static void registerPersistent() {
836
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
837
		DynStruct definition = manager.getDefinition("FLyrWCS_Persistent");
838
		if( definition == null ) {
839
			if (manager.getDefinition(DefaultFLyrRaster.class) == null) {
840
				DefaultFLyrRaster.registerPersistence();
841
			}
842

  
843
			definition = manager.addDefinition(
844
					FLyrWCS.class,
845
					"FLyrWCS_Persistent",
846
					"FLyrWCS Persistent Definition",
847
					null,
848
					null
849
			);
850

  
851
			definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, DefaultFLyrRaster.PERSISTENT_NAME);
852
		}
853

  
854
		DefaultFLyrRaster.registerPersistence(definition);
855
	}
856
}
0 857

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/main/java/org/gvsig/raster/wcs/app/wcsclient/layer/DynObjectIteratorWCSInfo.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.wcs.app.wcsclient.layer;
23

  
24
import java.util.ArrayList;
25

  
26
import org.gvsig.fmap.dal.feature.Feature;
27
import org.gvsig.tools.dispose.DisposableIterator;
28
import org.gvsig.tools.dynobject.DynObject;
29
import org.gvsig.tools.dynobject.DynObjectSet;
30

  
31
/**
32
 * {@link DynObject} implementation to facade a iterator of a WCSInfo
33
 * and allow to be used as a {@link DynObjectSet} iterator.
34
 * 
35
 * @author Nacho Brodin (nachobrodin@gmail.com)
36
 * @version $Id$
37
 * 
38
 */
39
public class DynObjectIteratorWCSInfo implements DisposableIterator {
40

  
41
    private ArrayList<Object> infoList = new ArrayList<Object>();
42
    private int               index    = -1;
43

  
44
    /**
45
     * Creates a new DynObjects iterator facade over a feature iterator.
46
     * Each WMTSInfo will be returned through a new or reused
47
     * {@link DynObjectWMTSInfo} which allows the {@link Feature} to be
48
     * used like a DynObject.
49
     * 
50
     * @param featureIterator
51
     *            to facade
52
     * @param featureFacade
53
     *            if not null this object will be reused as the facade for the
54
     *            Feature objects of the feature iterator
55
     */
56
    public DynObjectIteratorWCSInfo(Object info) {
57
        this.infoList.add(info);
58
        index = 0;
59
    }
60
    
61
    public void addObject(Object info) {
62
    	this.infoList.add(info);
63
    	if(index == -1)
64
    		index = 0;
65
    }
66

  
67
    public synchronized void dispose() {
68
    	this.infoList.clear();
69
    	index = -1;
70
    }
71

  
72
    public synchronized boolean hasNext() {
73
        return (infoList.size() == 0 || index >= infoList.size()) ? false : true;
74
    }
75

  
76
    public synchronized Object next() {
77
        Object o = infoList.get(index);
78
        index ++;
79
        return o;
80
    }
81

  
82
    public synchronized void remove() {
83
    	if(index < infoList.size() && index >= 0) {
84
    		index --;
85
    		infoList.remove(index);
86
    	}
87
    }
88
    
89
    public long getSize() {
90
        return infoList.size();
91
    }
92
}
0 93

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/main/java/org/gvsig/raster/wcs/app/wcsclient/exception/WCSDriverExceptionType.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.wcs.app.wcsclient.exception;
23

  
24
import org.gvsig.remoteclient.wcs.WCSStatus;
25
import org.gvsig.utils.ExceptionDescription;
26

  
27

  
28
public class WCSDriverExceptionType extends ExceptionDescription {
29

  
30
	WCSStatus status;
31
	
32
	public WCSDriverExceptionType(){
33
		super(60, "Error al acceder a un servicio WCS");
34
		
35
	}
36
	
37
	public String getHtmlErrorMessage() {
38
		String message = "<p><b>Error en una petici?n a servidor WCS</b></p>";
39
		message += "Informaci?n adicional:<br>";
40
		message += "Mensaje del error: " + status.getMessage();
41
		message += "Direcci?n: " + status.getOnlineResource();
42
		message += "<br> Par?metros: "+status.getParameters();
43
		return message;
44
	}
45

  
46
	public WCSStatus getWcsStatus() {
47
		return status;
48
	}
49

  
50
	public void setWcsStatus(WCSStatus wcsStatus) {
51
		this.status = wcsStatus;
52
	}
53

  
54
}
55

  
0 56

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.58/org.gvsig.raster.wcs.app.wcsclient/src/main/java/org/gvsig/raster/wcs/app/wcsclient/gui/toc/WCSZoomToPixelTocMenuEntry.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
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff