Revision 2061

View differences:

org.gvsig.raster.wcs/tags/tagdate_29082013/org.gvsig.raster.wcs/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/tagdate_29082013/org.gvsig.raster.wcs/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/tagdate_29082013/org.gvsig.raster.wcs/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/tagdate_29082013/org.gvsig.raster.wcs/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/tagdate_29082013/org.gvsig.raster.wcs/org.gvsig.raster.wcs.app.wcsclient/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
  <id>gvsig-plugin-package</id>
3
  <formats>
4
    <format>zip</format>
5
  </formats>
6
  <baseDirectory>${project.artifactId}</baseDirectory>
7
  <includeBaseDirectory>true</includeBaseDirectory>
8
  <files>
9
    <file>
10
      <source>target/${project.artifactId}-${project.version}.jar</source>
11
      <outputDirectory>lib</outputDirectory>
12
    </file>
13
    <file>
14
      <source>target/package.info</source>
15
    </file>
16
  </files>
17

  
18
  <fileSets>
19
    <fileSet>
20
      <directory>src/main/resources-plugin</directory>
21
      <outputDirectory>.</outputDirectory>
22
    </fileSet>
23
  </fileSets>
24

  
25

  
26
  <dependencySets>
27
    <dependencySet>
28
      <useProjectArtifact>false</useProjectArtifact>
29
	  <useTransitiveDependencies>false</useTransitiveDependencies>
30
      <outputDirectory>lib</outputDirectory>
31
      <includes> 
32
				<include>org.gvsig:org.gvsig.raster.wcs.app.wcsclient:jar</include>
33
				<include>org.gvsig:org.gvsig.raster.wcs.io:jar</include>
34
	  </includes>
35
	</dependencySet>
36
  </dependencySets>
37
</assembly>
0 38

  
org.gvsig.raster.wcs/tags/tagdate_29082013/org.gvsig.raster.wcs/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/tagdate_29082013/org.gvsig.raster.wcs/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/tagdate_29082013/org.gvsig.raster.wcs/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/tagdate_29082013/org.gvsig.raster.wcs/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.util.HashMap;
54
import java.util.List;
55

  
56
import javax.print.attribute.PrintRequestAttributeSet;
57
import javax.swing.JOptionPane;
58

  
59
import org.cresques.cts.IProjection;
60
import org.gvsig.compat.net.ICancellable;
61
import org.gvsig.fmap.dal.DALLocator;
62
import org.gvsig.fmap.dal.DataManager;
63
import org.gvsig.fmap.dal.DataParameters;
64
import org.gvsig.fmap.dal.DataStore;
65
import org.gvsig.fmap.dal.DataStoreParameters;
66
import org.gvsig.fmap.dal.coverage.RasterLocator;
67
import org.gvsig.fmap.dal.coverage.RasterManager;
68
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
69
import org.gvsig.fmap.dal.coverage.datastruct.ViewPortData;
70
import org.gvsig.fmap.dal.coverage.exception.FilePaletteException;
71
import org.gvsig.fmap.dal.coverage.exception.InfoByPointException;
72
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
73
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
74
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
75
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
76
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
77
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
78
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters;
79
import org.gvsig.fmap.dal.coverage.store.parameter.TileDataParameters;
80
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
81
import org.gvsig.fmap.dal.exception.DataException;
82
import org.gvsig.fmap.dal.exception.InitializeException;
83
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
84
import org.gvsig.fmap.dal.exception.ReadException;
85
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
86
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
87
import org.gvsig.fmap.geom.GeometryLocator;
88
import org.gvsig.fmap.geom.GeometryManager;
89
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
90
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
91
import org.gvsig.fmap.geom.primitive.Envelope;
92
import org.gvsig.fmap.mapcontext.ViewPort;
93
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
94
import org.gvsig.fmap.mapcontext.layers.FLayer;
95
import org.gvsig.fmap.mapcontext.layers.FLyrDefault;
96
import org.gvsig.fmap.mapcontext.layers.Tiling;
97
import org.gvsig.gui.beans.Messages;
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.WCSServerExplorer;
104
import org.gvsig.raster.wcs.io.WCSServerExplorerParameters;
105
import org.gvsig.tools.ToolsLocator;
106
import org.gvsig.tools.dynobject.DynObjectSet;
107
import org.gvsig.tools.dynobject.DynStruct;
108
import org.gvsig.tools.persistence.PersistenceManager;
109
import org.gvsig.tools.persistence.PersistentState;
110
import org.gvsig.tools.persistence.exception.PersistenceException;
111
import org.gvsig.tools.task.Cancellable;
112
import org.gvsig.tools.task.SimpleTaskStatus;
113
import org.gvsig.tools.task.TaskStatusManager;
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
public class FLyrWCS extends DefaultFLyrRaster {
145
    public static final String           PERSISTENT_NAME           = "FLyrWCS_Persistent";
146
    public static final String           PERSISTENT_DESCRIPTION    = "FLyrWCS Persistent Definition";
147
    private static final int             MAX_RETRY_TIMES           = 5;
148

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

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

  
159
    private boolean						 firstLoad                 = false;
160
    private Envelope					 fullEnvelope              = null;
161
    private int                          callCount;
162
    private RasterManager                rManager                  = RasterLocator.getManager();
163
    private DataStoreParameters          params                    = null;
164
    private WCSServerExplorer            explorer                  = null;
165
    private boolean                      deleteCache               = false;
166

  
167
    @SuppressWarnings("unused")
168
    private class MyCancellable implements ICancellable {
169
        private Cancellable original;
170

  
171
        public MyCancellable(Cancellable cancelOriginal) {
172
            this.original = cancelOriginal;
173
        }
174

  
175
        public boolean isCanceled() {
176
            return original.isCanceled();
177
        }
178

  
179
        public Object getID() {
180
            return this;
181
        }
182
    }
183

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

  
194
    public FLyrWCS(DataStoreParameters dataStoreParameters) throws Exception {
195
        this();
196
        //Create the explorer and connect
197
        DataManager dataManager = DALLocator.getDataManager();
198
        WCSServerExplorerParameters explorerParams = (WCSServerExplorerParameters) 
199
        dataManager.createServerExplorerParameters(WCSServerExplorer.NAME);
200
        explorerParams.setHost((String)dataStoreParameters.getDynValue("uri"));
201
        WCSServerExplorer wmsServerExplorer = 
202
            (WCSServerExplorer) dataManager.openServerExplorer(WCSServerExplorer.NAME, explorerParams);
203
        wmsServerExplorer.connect(null);
204
        wmsServerExplorer.getCoverageList();
205
        
206
        //Set the parameters
207
        setParameters((WCSDataParameters)dataStoreParameters);
208
        setExplorer(wmsServerExplorer);
209
    }
210

  
211
    public static DataStore createDataStore(String host, IProjection srs) throws InitializeException {
212
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
213
        RasterDataParameters params = null;
214
        try {
215
            params = (RasterDataParameters)dataman.createServerExplorerParameters(WCSServerExplorer.NAME);
216
        } catch (InitializeException e) {
217
            return null;
218
        } catch (ProviderNotRegisteredException e) {
219
            return null;
220
        }
221
        params.setURI(host);
222
        params.setSRS(srs);
223

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

  
233
    /*
234
     * (non-Javadoc)
235
     * @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#setDataStore(org.gvsig.fmap.dal.DataStore)
236
     */
237
    public void setDataStore(DataStore dataStore) throws LoadLayerException {
238
        this.dataStore = (RasterDataStore) dataStore;
239
        try {
240
            if(this.dataStore.isOpen())
241
                enableOpen();
242
        } catch (NotAvailableStateException e) {
243
            logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
244
        }
245
        setProjection(this.dataStore.getProjection());
246
    }
247

  
248
    /*
249
     *  (non-Javadoc)
250
     * @see com.iver.cit.gvsig.fmap.layers.FLayer#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable, double)
251
     */
252
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel, double scale) throws ReadException {
253
        TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
254
		SimpleTaskStatus taskStatus = new RasterTaskStatus("Drawing " + getName() + "...", cancel);
255
		manager.add(taskStatus);
256
		taskStatus.setAutoremove(true);
257

  
258
        if(!firstLoad) {
259
            try {
260
                initFilters();
261
            } catch (FilePaletteException e) {
262
                logger.error(e.getMessage(), this, e);
263
            }
264
            firstLoad = true;
265
        }
266

  
267
        callCount = 0;  
268

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

  
277
        if (isWithinScale(scale)) {
278

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

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

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

  
315
    /**
316
     * This is the method used to draw a tile in a WCS mosaic layer.
317
     * @throws LoadLayerException
318
     * @throws ReadDriverException
319
     * @return true when a tile has been painted
320
     */
321
    @SuppressWarnings("deprecation")
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
            Extent ex = rManager.getDataStructFactory().createExtent(
356
                vp.getAdjustedEnvelope().getMinimum(0), 
357
                vp.getAdjustedEnvelope().getMaximum(1), 
358
                vp.getAdjustedEnvelope().getMaximum(0), 
359
                vp.getAdjustedEnvelope().getMinimum(1));
360
            ViewPortData vpData = rManager.getDataStructFactory().createViewPortData(vp.getProjection(), ex, sz );
361
            vpData.setMat(vp.getAffineTransform());
362
    		
363
            try {
364
                getParameters().setExtent(bBox);
365
                getParameters().setWidth(wImg);
366
                getParameters().setHeight(hImg);
367
                if(params instanceof WCSDataParameters) {
368
					getRender().draw(g, vpData, taskStatus);
369
                } else {
370
                	Envelope adjustedExtent = vp.getAdjustedExtent();
371
					Extent e = rManager.getDataStructFactory().createExtent(adjustedExtent.getLowerCorner().getX(),
372
							adjustedExtent.getUpperCorner().getY(), adjustedExtent.getUpperCorner().getX(),
373
							adjustedExtent.getLowerCorner().getY());
374
					ViewPortData vp2 = rManager.getDataStructFactory().createViewPortData(vp.getProjection(), e, vp.getImageSize() );
375
					vp2.setMat(vp.getAffineTransform());
376
					getParameters().setExtent(ex.toRectangle2D());
377
					getRender().drawTiledService(g, vp2, vp.getImageSize(), taskStatus);
378
                }
379
            } catch (RasterDriverException e) {
380
            	setAvailable(false);
381
				JOptionPane.showMessageDialog(null, "Problems drawing this layer:" + e.getMessage(), Messages.getText("Error"), JOptionPane.ERROR_MESSAGE);
382
				logger.info("Problems drawing this layer:" + e.getMessage(), e);
383
            } catch (InvalidSetViewException e) {
384
                throw new RemoteServiceException("Problems drawing this layer: " + e.getMessage(), e);
385
            } catch (ProcessInterruptedException e) {
386
            } finally {
387
            	taskStatus.terminate();            	
388
            }
389

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

  
407
    /**
408
     * Gets the explorer
409
     * @return
410
     */
411
    public WCSServerExplorer getExplorer() {
412
        return this.explorer;
413
    }
414

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

  
444
    private Rectangle2D.Double getRectable2DFromEnvelope(Envelope env) {
445
        return new Rectangle2D.Double(env.getMinimum(0), env.getMinimum(1), env
446
            .getLength(0), env.getLength(1));
447
    }
448

  
449
    /**
450
     * Calcula el contenido del fichero de georreferenciaci?n de una imagen.
451
     * @param bBox Tama?o y posici?n de la imagen (en coordenadas de usuario)
452
     * @param sz Tama?o de la imagen en pixeles.
453
     * @return el 'WorldFile', como String.
454
     * @throws IOException
455
     */
456
    public String getDataWorldFile(Rectangle2D bBox, Dimension sz) throws IOException {
457
        StringBuffer data = new StringBuffer();
458
        data.append((bBox.getMaxX() - bBox.getMinX()) / (sz.getWidth() - 1) + "\n");
459
        data.append("0.0\n");
460
        data.append("0.0\n");
461
        data.append("-" + (bBox.getMaxY() - bBox.getMinY()) / (sz.getHeight() - 1) + "\n");
462
        data.append("" + bBox.getMinX() + "\n");
463
        data.append("" + bBox.getMaxY() + "\n");
464
        return data.toString();
465
    }
466

  
467
    /*
468
     * (non-Javadoc)
469
     * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#cloneLayer()
470
     */
471
    public FLayer cloneLayer() throws Exception {
472
        RasterDataStore  ds = dataStore.cloneDataStore();
473
        FLyrWCS layer = new FLyrWCS();
474
        layer.setName(getParameters().getCoverageName());
475
        layer.setOpenRasterStore(ds);
476
        layer.fullEnvelope = fullEnvelope;
477
        layer.params = params;
478
        layer.explorer = explorer;
479

  
480
        List<RasterFilter> filters = getRender().getFilterList().getStatusCloned();
481

  
482
        //Hacemos una copia de las bandas a renderizar
483
        if(getRender().getRenderBands() != null) {
484
            int[] rb = new int[getRender().getRenderBands().length];
485
            for (int i = 0; i < rb.length; i++)
486
                rb[i] = getRender().getRenderBands()[i];
487
            layer.getRender().setRenderBands(rb);
488
        }
489

  
490
        //Asignamos el entorno
491
        if(layer.getRender().getFilterList() == null)
492
            layer.getRender().setFilterList(RasterLocator.getManager().createEmptyFilterList(getRender().getFilterList().getInitDataType()));
493
        layer.getRender().getFilterList().setEnv(getRender().getFilterList().getEnv());
494
        layer.getRender().getFilterList().setStatus(filters);
495

  
496
        // Asignamos los valores noData del original
497
        layer.setNoDataValue(getNoDataValue());
498
        if(dataStore.getNoDataValue().isDefined())
499
        	layer.setNoDataTransparent(true);
500
        layer.enableOpen();
501

  
502
        return layer;
503
    }
504

  
505
    public Transparency getRenderTransparency() {
506
        return getRender().getLastTransparency();
507
    }
508

  
509
    /*
510
     * (non-Javadoc)
511
     * @see org.gvsig.fmap.raster.layers.FLyrRasterSE#print(java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.utiles.swing.threads.Cancellable, double, javax.print.attribute.PrintRequestAttributeSet)
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
    /*
578
     *  (non-Javadoc)
579
     * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#getTileSize()
580
     */
581
    public int[] getTileSize() {
582
        int[] size = {maxTileDrawWidth, maxTileDrawHeight};
583
        return size;
584
    }
585

  
586
    /*
587
     * (non-Javadoc)
588
     * @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#getTocImageIcon()
589
     */
590
    public String getTocImageIcon() {
591
        return "ico-WCS-Layer";
592
    }
593

  
594
    /*
595
     *  (non-Javadoc)
596
     * @see com.iver.cit.gvsig.fmap.layers.RasterOperations#isTiled()
597
     */
598
    public boolean isTiled() {
599
        return mustTileDraw;
600
    }
601

  
602
    @SuppressWarnings("deprecation")
603
    @Override
604
    public DynObjectSet getInfo(Point p, double tolerance, Cancellable cancel,
605
        boolean fast) throws LoadLayerException, DataException {
606

  
607
        //try {
608
        ViewPort viewPort = getMapContext().getViewPort();
609

  
610
        Point tiledPoint = new Point((int) p.getX() % maxTilePrintWidth, (int) p.getY() % maxTilePrintHeight);
611
        Rectangle rect = new Rectangle(0, 0, viewPort.getImageWidth() - 1, viewPort.getImageHeight() - 1);
612
        Tiling tiles = new Tiling(maxTilePrintWidth, maxTilePrintHeight, rect);
613
        tiles.setAffineTransform((AffineTransform) viewPort.getAffineTransform().clone());
614
        int nCols = tiles.getNumCols();
615

  
616
        int col = (int) p.getX() / maxTilePrintWidth;
617
        int row = (int) p.getY() / maxTilePrintHeight;
618
        int tileIndex = (row * nCols) + col;
619

  
620
        ViewPort vp = null;
621
        try {
622
            vp = tiles.getTileViewPort(viewPort, tileIndex);
623
        } catch (NoninvertibleTransformException e1) {
624
            throw new LoadLayerException("", e1);
625
        }
626

  
627
        getParameters().setExtent(this.getRectable2DFromEnvelope(vp.getAdjustedExtent()));
628
        getParameters().setWidth(vp.getImageWidth());
629
        getParameters().setHeight(vp.getImageHeight());
630

  
631
        CancelTaskImpl cancellable = new CancelTaskImpl(cancel);
632
        getParameters().setCancellable(cancellable);
633

  
634
        String fInfo;
635
        try {
636
            fInfo = getDataStore().getInfoByPoint(tiledPoint.getX(), tiledPoint.getY(), cancellable);
637
        } catch (InfoByPointException e) {
638
            throw new LoadLayerException("Error in getInfoByPoint", e);
639
        }
640
        return new DynObjectSetWCSInfo(fInfo, DynObjectSetWCSInfo.TYPE_TEXT);
641
    }
642
    
643
	/*
644
	 * (non-Javadoc)
645
	 * @see org.gvsig.raster.fmap.layers.FLyrRaster#getFileFormat()
646
	 */
647
	@Override
648
	public String getFileFormat() {
649
		return "WCS";
650
	}
651

  
652
    /*
653
     * (non-Javadoc)
654
     * @see org.gvsig.fmap.raster.layers.FLyrRasterSE#isActionEnabled(int)
655
     */
656
    public boolean isActionEnabled(int action) {
657
        switch (action) {
658
        case IRasterLayerActions.ZOOM_PIXEL_RESOLUTION:
659
        case IRasterLayerActions.FLYRASTER_BAR_TOOLS:
660
        case IRasterLayerActions.BANDS_FILE_LIST:
661
        case IRasterLayerActions.GEOLOCATION:
662
        case IRasterLayerActions.PANSHARPENING:
663
        case IRasterLayerActions.SAVE_COLORINTERP:
664
            return false;
665
        case IRasterLayerActions.BANDS_RGB:
666
        case IRasterLayerActions.REMOTE_ACTIONS:
667
        case IRasterLayerActions.COLOR_TABLE:
668
            return true;
669
        }
670

  
671
        return super.isActionEnabled(action);
672
    }
673

  
674
    /*
675
     * (non-Javadoc)
676
     * @see org.gvsig.fmap.raster.layers.FLyrRasterSE#overviewsSupport()
677
     */
678
    public boolean overviewsSupport() {
679
        return false;
680
    }
681

  
682
    /*
683
     * (non-Javadoc)
684
     * @see org.gvsig.raster.fmap.layers.FLyrRaster#getFullRasterExtent()
685
     */
686
    public org.gvsig.fmap.dal.coverage.datastruct.Extent getFullRasterExtent() {
687
        Envelope env = getFullEnvelope();
688
        double minx = env.getMinimum(0);
689
        double miny = env.getMinimum(1);
690
        double maxx = env.getMaximum(0);
691
        double maxy = env.getMaximum(1);
692
        Point2D ul = new Point2D.Double(minx, maxy);
693
        Point2D ur = new Point2D.Double(maxx, maxy);
694
        Point2D ll = new Point2D.Double(minx, miny);
695
        Point2D lr = new Point2D.Double(maxx, miny);
696
        return rManager.getDataStructFactory().createExtent(ul, lr, ur, ll);
697
    }
698

  
699
    @SuppressWarnings("deprecation")
700
    public WCSDataParameters getParameters() {
701
        if(params == null) {
702
            DataManager datamanager = DALLocator.getDataManager();
703
            WCSServerExplorerParameters explorerParams = null;
704
            try {
705
                explorerParams = (WCSServerExplorerParameters) datamanager.createServerExplorerParameters(WCSServerExplorer.NAME);
706
                explorerParams.setHost("");
707
                explorer = (WCSServerExplorer) datamanager.createServerExplorer(explorerParams);
708
                DataStoreParameters parameters = explorer.getStoreParameters();
709
                if(parameters instanceof WCSDataParameters) {
710
                    params = (WCSDataParameters) parameters;
711
                }
712
            } catch (InitializeException e) {
713
            } catch (ProviderNotRegisteredException e) {
714
            } catch (ValidateDataParametersException e) {
715
            }
716
        }
717
        return getWCSParameters(params);
718
    }
719
    
720
    /**
721
     * Gets <code>WCSDataParameters</code>
722
     * @param parameters
723
     * @return
724
     */
725
    private WCSDataParameters getWCSParameters(DataStoreParameters parameters) {
726
    	WCSDataParameters params = null;
727
    	if(parameters instanceof WCSDataParameters) {
728
			params = (WCSDataParameters) parameters;
729
		}
730
		
731
		if(parameters instanceof TileDataParameters) {
732
			DataParameters p = ((TileDataParameters) parameters).getDataParameters();
733
			if(p instanceof WCSDataParameters) {
734
				params = (WCSDataParameters) p;
735
			}
736
		}
737
		return params;
738
    }
739

  
740
    /**
741
     * Sets the explorer
742
     * @param explorer
743
     */
744
    public void setExplorer(WCSServerExplorer explorer) {
745
        this.explorer = explorer;
746
    }
747
    
748
    /**
749
	 * Assigns the flag to delete this layer from the cache
750
	 * @param selected
751
	 */
752
	public void deleteCache(boolean deleteCache) {
753
		this.deleteCache = deleteCache;
754
	}
755

  
756
    /**
757
     * Sets the data store parameters
758
     * @param params
759
     * @throws InitializeException
760
     */
761
    public void setParameters(DataStoreParameters params) throws InitializeException {
762
        this.params = params;
763
        
764
        if(params instanceof TileDataParameters) {
765
			((TileDataParameters)params).deleteCache(deleteCache);
766
		}
767
        
768
        DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
769
        try {
770
            DataStore dStore = dataman.openStore(params.getDataStoreName(), params);
771
            this.setDataStore(dStore);
772

  
773
			if(params instanceof WCSDataParameters) {
774
				this.setName((String)((WCSDataParameters)params).getURI());
775
			}
776
			
777
			if(params instanceof TileDataParameters) {
778
				DataParameters p = ((TileDataParameters) params).getDataParameters();
779
				if(p instanceof WCSDataParameters) {
780
					this.setName((String)((WCSDataParameters) p).getURI());
781
				}
782
			}
783
        } catch (ValidateDataParametersException e) {
784
            throw new InitializeException(e);
785
        } catch (ProviderNotRegisteredException e) {
786
            throw new InitializeException(e);
787
        } catch (LoadLayerException e) {
788
            throw new InitializeException(e);
789
        }
790
    }
791
    
792
	/*
793
	 * (non-Javadoc)
794
	 * @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#loadFromState(org.gvsig.tools.persistence.PersistentState)
795
	 */
796
	@Override
797
	public void loadFromState(PersistentState state)
798
	throws PersistenceException {
799
		String host = state.getString("host");
800
		
801
		getParameters();
802
		((WCSServerExplorerParameters)explorer.getParameters()).setHost(host);
803
		
804
		if(!explorer.isHostReachable()) {
805
			loadLayer = false;
806
			super.loadFromState(state);
807
			return;
808
		}
809
		
810
		try {
811
			explorer.connect(new CancelTaskImpl());
812
			explorer.getCoverageList();
813
		} catch (Exception e) {
814
			loadLayer = false;
815
			super.loadFromState(state);
816
			return;
817
		}
818
		
819
		loadLayer = true;
820

  
821
		super.loadFromState(state);
822
		params = getDataStore().getParameters();
823
		this.fullEnvelope = (Envelope) state.get("fullEnvelope");
824
		try {
825
			if(this.dataStore.isOpen())
826
				enableOpen();
827
		} catch (NotAvailableStateException e) {
828
			logger.error("Fallo el estado de open. Closed=" + isClosed() + " Awake=" + isAwake(), this, e);
829
		}
830
		//getParameters().setCoverageName((String)state.get("name"));
831
	}
832

  
833
	/*
834
	 * (non-Javadoc)
835
	 * @see org.gvsig.raster.fmap.layers.DefaultFLyrRaster#saveToState(org.gvsig.tools.persistence.PersistentState)
836
	 */
837
	@Override
838
	public void saveToState(PersistentState state) throws PersistenceException {
839
		super.saveToState(state);
840
		state.set("fullEnvelope", this.fullEnvelope);
841
		state.set("host", getParameters().getURI());
842
		state.set("name", getName());
843
	}
844
    
845
	public static void registerPersistent() {
846
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
847
		DynStruct definition = manager.getDefinition(PERSISTENT_NAME);
848
		if( definition == null ) {
849
			if (manager.getDefinition(FLyrDefault.class) == null) {
850
				FLyrDefault.registerPersistent();
851
			}
852

  
853
			definition = manager.addDefinition(
854
					FLyrWCS.class,
855
					PERSISTENT_NAME,
856
					PERSISTENT_DESCRIPTION,
857
					null, 
858
					null
859
			);
860
			
861
			definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, "FLyrDefault");
862
		}
863

  
864
		DefaultFLyrRaster.registerPersistence(definition);
865
		definition.addDynFieldObject("fullEnvelope").setClassOfValue(Envelope.class).setMandatory(false);
866
		definition.addDynFieldString("host").setMandatory(false);
867
		definition.addDynFieldString("name").setMandatory(false);
868
	}
869
    
870
   /* public static void registerPersistent() {
871
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
872
		DynStruct definition = manager.getDefinition(PERSISTENT_NAME);
873
		if( definition == null ) {
874
			if (manager.getDefinition(DefaultFLyrRaster.class) == null) {
875
				DefaultFLyrRaster.registerPersistence();
876
			}
877

  
878
			definition = manager.addDefinition(
879
					FLyrWCS.class,
880
					PERSISTENT_NAME,
881
					PERSISTENT_DESCRIPTION,
882
					null, 
883
					null
884
			);
885
			
886
			definition.extend(PersistenceManager.PERSISTENCE_NAMESPACE, DefaultFLyrRaster.PERSISTENT_NAME);
887
		}
888

  
889
		definition.addDynFieldObject("fullEnvelope").setClassOfValue(Envelope.class).setMandatory(true);
890
		definition.addDynFieldString("host").setMandatory(true);
891
		definition.addDynFieldBoolean("deleteCache").setMandatory(false);
892
		definition.addDynFieldString("time").setMandatory(false);
893
		definition.addDynFieldObject("maxres").setClassOfValue(Point2D.class).setMandatory(false);
894
		definition.addDynFieldString("parameter").setMandatory(false);
895
		definition.addDynFieldString("srsstr").setMandatory(false);
896
		definition.addDynFieldString("format").setMandatory(false);
897
		definition.addDynFieldString("name").setMandatory(false);
898
		definition.addDynFieldObject("extent").setClassOfValue(Rectangle2D.class).setMandatory(false);
899
		definition.addDynFieldInt("width").setMandatory(true);
900
		definition.addDynFieldInt("height").setMandatory(true);
901
		definition.addDynFieldBoolean("override").setMandatory(false);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff