Revision 707

View differences:

org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.hyperlink.app</artifactId>
6
	<packaging>pom</packaging>
7
	<version>1.0.136</version>
8
	<name>${project.artifactId}</name>
9
	<description>View. Hyperlink support</description>
10
	
11
    <parent>
12
        <groupId>org.gvsig</groupId>
13
        <artifactId>org.gvsig.desktop</artifactId>
14
        <version>2.0.323</version>
15
    </parent>
16
        
17
	<url>https://devel.gvsig.org/redmine/projects/gvsig-hyperlink</url>
18
	
19
    <scm>
20
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136</connection>
21
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136</developerConnection>
22
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136</url>
23
    </scm>
24
    
25
	<build>
26
        <plugins>
27
		    <plugin>
28
		      <artifactId>maven-release-plugin</artifactId>
29
		      <configuration>
30
		        <tagBase>https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags</tagBase>
31
		      </configuration>
32
		    </plugin>			
33
     
34
        </plugins>   
35
    </build>
36
    
37
	<developers>
38
		<developer>
39
			<id>jjdelcerro</id>
40
			<name>Joaqu?n Jos? del Cerro</name>
41
			<email>jjdelcerro@gvsig.org</email>
42
			<roles>
43
				<role>Architect</role>
44
				<role>Developer</role>
45
			</roles>
46
		</developer>
47
		<developer>
48
			<id>cordinyana</id>
49
			<name>C?sar Ordi?ana</name>
50
			<email>cordinyana@gvsig.com</email>
51
			<roles>
52
				<role>Architect</role>
53
				<role>Developer</role>
54
			</roles>
55
		</developer>
56
	</developers>
57
	<distributionManagement>
58
		<site>
59
			<id>gvsig-repository</id>
60
            <url>dav:https://devel.gvsig.org/sites/org.gvsig.hyperlink.app/${project.version}</url>
61
		</site>
62
	</distributionManagement>
63
	<repositories>
64
		<repository>
65
			<id>gvsig-public-http-repository</id>
66
			<name>gvSIG maven public HTTP repository</name>
67
			<url>http://devel.gvsig.org/m2repo/j2se</url>
68
			<releases>
69
				<enabled>true</enabled>
70
				<updatePolicy>daily</updatePolicy>
71
				<checksumPolicy>warn</checksumPolicy>
72
			</releases>
73
			<snapshots>
74
				<enabled>true</enabled>
75
				<updatePolicy>daily</updatePolicy>
76
				<checksumPolicy>warn</checksumPolicy>
77
			</snapshots>
78
		</repository>
79
	</repositories>
80
	<modules>
81
		<module>org.gvsig.hyperlink.app.extension</module>
82
	</modules>
83
</project>
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/ILinkActionManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension;
24

  
25
import java.net.URI;
26

  
27
import org.gvsig.tools.extensionpoint.ExtensionBuilder;
28

  
29
/**
30
 * TODO document this interface
31
 * This interface must be implemented by format managers for the
32
 * hyperlink tool. A manager is able to load an specific file, either
33
 * by loading it in an AbstractHyperLinkPanel or by opening the proper
34
 * program to do the task.
35
 * 
36
 * Format managers must be registered in the ExtensionPoint named
37
 * "HyperLinkAction" in order to be available in the HyperLink tool.
38
 * 
39
 * @author cesar
40
 * 
41
 */
42
public interface ILinkActionManager extends ExtensionBuilder {
43

  
44
    public void showDocument(LinkTarget doc) throws UnsupportedOperationException;
45

  
46
    public boolean hasPanel();
47

  
48
    public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException;
49

  
50
    public String getActionCode();
51

  
52
    public String getName();
53

  
54
    public String getDescription();
55
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/layers/ILinkLayerManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.layers;
24

  
25
import java.awt.geom.Point2D;
26
import org.gvsig.fmap.mapcontext.layers.FLayer;
27
import org.gvsig.hyperlink.app.extension.LinkTarget;
28

  
29
public interface ILinkLayerManager {
30

  
31
    public void setLayer(FLayer layer) throws IncompatibleLayerException;
32

  
33
    public FLayer getLayer();
34

  
35
    public LinkTarget[] getLink(Point2D point,
36
        double tolerance,
37
        String fieldName,
38
        String fileExtension);
39

  
40
//    public URI[][] getLink(Point2D point,
41
//        double tolerance,
42
//        String[] fieldName,
43
//        String fileExtension);
44

  
45
    public String[] getFieldCandidates();
46
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/layers/IncompatibleLayerException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.layers;
24

  
25
public class IncompatibleLayerException extends Exception {
26

  
27
    public IncompatibleLayerException(Throwable ex) {
28
        super(ex);
29
    }
30

  
31
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/layers/ManagerRegistry.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.layers;
24

  
25
import java.util.Comparator;
26
import java.util.HashMap;
27
import java.util.HashSet;
28
import java.util.Iterator;
29
import java.util.TreeSet;
30

  
31
import org.gvsig.fmap.mapcontext.layers.FLayer;
32
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
33
import org.gvsig.tools.ToolsLocator;
34
import org.gvsig.tools.extensionpoint.ExtensionPoint;
35
import org.gvsig.tools.extensionpoint.ExtensionPoint.Extension;
36
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
37

  
38
public class ManagerRegistry {
39

  
40
    public static final String EXTENSIONPOINTNAME = "hyperlink.layer.manager";
41
    private ExtensionPoint extensionPoint;
42
    /**
43
     * We will cache the proper manager for each class, so that we don't
44
     * calculate the right one everytime.
45
     * This assumes that no manager will be added after extensions' initialize()
46
     * method, otherwise the
47
     * cached values will be incorrect.
48
     */
49
    private HashMap<Class, String> cachedManagers;
50
    /**
51
     * We will also cache the unmanaged layers (layers without managers).
52
     */
53
    private HashSet<Class> cachedUnmanagedLayers;
54

  
55
    public ManagerRegistry() {
56
        ExtensionPointManager epm = ToolsLocator.getExtensionPointManager();
57
        extensionPoint =
58
            epm.add(EXTENSIONPOINTNAME,
59
                "Registers ILinkToolManagers that are able to manage specific layer types.");
60
        cachedManagers = new HashMap<Class, String>();
61
        /*
62
         * Add vector layer
63
         * If we don't, persisted layers will not work well
64
         */
65
        cachedManagers.put(FLyrVect.class, FLyrVect.class.getName());
66

  
67
        cachedUnmanagedLayers = new HashSet<Class>();
68
    }
69

  
70
    public void put(Class layerType, Class manager) {
71
        if (layerType.isInterface()) {
72
            throw new RuntimeException("Interfaces are not supported");
73
        }
74
        if (!ILinkLayerManager.class.isAssignableFrom(manager)) {
75
            throw new RuntimeException("Managers must be of type ILinkLayerManager");
76
        }
77
        extensionPoint.append(layerType.getName(), "", manager);
78
    }
79

  
80
    public ILinkLayerManager get(FLayer layer) throws ClassNotFoundException,
81
        InstantiationException,
82
        IllegalAccessException,
83
        IncompatibleLayerException {
84
        if (cachedManagers.containsKey(layer.getClass())) {
85
            String layerType = cachedManagers.get(layer.getClass());
86
            ILinkLayerManager manager =
87
                (ILinkLayerManager) extensionPoint.create(layerType);
88
            manager.setLayer(layer);
89
            return manager;
90
        } else
91
            if (cachedUnmanagedLayers.contains(layer.getClass())) {
92
                return null;
93
            }
94
        // search for proper manager for this class
95
        Iterator it = extensionPoint.getNames().iterator();
96
        TreeSet<Class> classList = new TreeSet<Class>(new ClassComparator());
97
        while (it.hasNext()) {
98
            String layerType = it.next().toString();
99
            Class layerClass = Class.forName(layerType);
100
            if (layerClass.isInstance(layer)) {
101
                classList.add(layerClass);
102
            }
103
        }
104

  
105
        if (!classList.isEmpty()) {
106
            ILinkLayerManager manager =
107
                (ILinkLayerManager) extensionPoint.create(classList.first()
108
                    .getName());
109
            cachedManagers.put(layer.getClass(), classList.first().getName());
110
            manager.setLayer(layer);
111
            return manager;
112
        } else {
113
            cachedUnmanagedLayers.add(layer.getClass());
114
            return null;
115
        }
116
    }
117

  
118
    public boolean hasManager(FLayer layer) {
119
        if (cachedManagers.containsKey(layer.getClass())) {
120
            return true;
121
        } else
122
            if (cachedUnmanagedLayers.contains(layer.getClass())) {
123
                return false;
124
            }
125

  
126
        Iterator it = extensionPoint.iterator();
127
        while (it.hasNext()) {
128
            Class layerClass = ((Extension) it.next()).getExtension();
129
            if (layerClass.isInstance(layer)) {
130
                return true;
131
            }
132
        }
133

  
134
//        cachedUnmanagedLayers.add(layer.getClass());
135
        return false;
136
    }
137

  
138
    private class ClassComparator implements Comparator<Class> {
139

  
140
        public int compare(Class class1, Class class2) {
141
            if (class1.equals(class2))
142
                return 0;
143
            if (class1.isAssignableFrom(class2)) {
144
                return 1;
145
            } else {
146
                return -1;
147
            }
148
        }
149
    }
150
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/layers/VectLayerManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.layers;
24

  
25
import java.awt.geom.Point2D;
26
import java.io.File;
27
import java.net.MalformedURLException;
28
import java.net.URI;
29
import java.net.URISyntaxException;
30
import java.net.URL;
31
import java.net.URLClassLoader;
32
import java.util.ArrayList;
33
import java.util.List;
34
import java.util.Map;
35
import org.apache.commons.io.FileUtils;
36
import org.apache.commons.lang3.StringUtils;
37

  
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.messages.NotificationManager;
40
import org.gvsig.app.ApplicationLocator;
41
import org.gvsig.app.project.Project;
42
import org.gvsig.app.project.ProjectManager;
43
import org.gvsig.fmap.dal.DataTypes;
44
import org.gvsig.fmap.dal.exception.DataException;
45
import org.gvsig.fmap.dal.feature.Feature;
46
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
47
import org.gvsig.fmap.dal.feature.FeatureSet;
48
import org.gvsig.fmap.dal.feature.FeatureType;
49
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
50
import org.gvsig.fmap.mapcontext.layers.FLayer;
51
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
52
import org.gvsig.hyperlink.app.extension.DefaultLinkTarget;
53
import org.gvsig.hyperlink.app.extension.LinkTarget;
54
import org.gvsig.tools.dispose.DisposableIterator;
55

  
56
public class VectLayerManager implements ILinkLayerManager {
57

  
58
    private FLyrVect _layer = null;
59

  
60
    @Override
61
    public LinkTarget[] getLink(Point2D point,
62
        double tolerance,
63
        String fieldName,
64
        String fileExtension) {
65
        FLyrVect lyrVect = (FLyrVect) _layer;
66
        //ArrayList<LinkTarget> uriList = new ArrayList();
67
        List<LinkTarget> uriList = new ArrayList();
68
        FeatureSet features;
69
        FeatureType featureType;
70

  
71
        try {
72
            // FIXME: Habr? que ver como lo hacemos con las capas multigeometr?a
73
            featureType = _layer.getFeatureStore().getDefaultFeatureType();
74
            features = lyrVect.queryByPoint(point, tolerance, featureType);
75
        } catch (DataException e) {
76
            return null;
77
        }
78

  
79
        // Si el conjunto creado no est? vac?o creamos el vector de URLS
80
        // correspondientes
81
        // a la consulta que hemos hecho.
82

  
83
        if (features != null) {
84
            try {
85
                DisposableIterator it;
86
                it = features.fastIterator();
87
                Object val = null;
88

  
89
                while (it.hasNext()) {
90
                    Feature feature = (Feature) it.next();
91

  
92
                            DefaultLinkTarget target = new DefaultLinkTarget(_layer, feature, fieldName, fileExtension);
93
                            uriList.add(target); //getURI(fieldValue, fileExtension));
94
                    }
95
                it.dispose();
96
                return uriList.toArray(new LinkTarget[0]);//(LinkTarget[]) uriList.toArray(); //(URI[]) uriList.toArray(new URI[0]);
97
            } catch (DataException e1) {
98
                PluginServices.getLogger()
99
                    .error("Hyperlink__cant_get_the_iterator", e1);
100
            }
101
        }
102
        return null; //new URI[0];
103
    }
104

  
105
    private URL toURL(File f) {
106
        try {
107
            return f.toURI().toURL();
108
        } catch (MalformedURLException ex) {
109
            return null;
110
        }
111
    }
112
    
113
    protected URI getBasicURI(String baseURI, String extension) throws URISyntaxException {
114
        String pathname;
115
        if( StringUtils.isEmpty(extension) ) {
116
            pathname = baseURI;
117
        } else {
118
            if (extension.startsWith(".")) {
119
                pathname = baseURI + extension;
120
            } else {
121
                pathname = baseURI + "." + extension;
122
            }
123
        }
124
        pathname = pathname.replace("\\","//");
125
        if( this._layer.getFeatureStore().getParameters() instanceof FilesystemStoreParameters ) {
126
            FilesystemStoreParameters params = (FilesystemStoreParameters) this._layer.getFeatureStore().getParameters();
127
            File f = params.getFile();
128
            URLClassLoader loader = new URLClassLoader(new URL[] {toURL(f)});
129
            URL url = loader.getResource(pathname);
130
            if( url != null ) {
131
                return url.toURI();
132
            }
133
            url = loader.getResource("/" + pathname);
134
            if( url != null ) {
135
                return url.toURI();
136
            }
137
            File ff = FileUtils.getFile(f.getParentFile(), pathname);
138
            if( ff.exists() ) {
139
                return ff.toURI();
140
            }
141
        }
142
        ProjectManager projectManager = ApplicationLocator.getProjectManager();
143
        Project project = projectManager.getCurrentProject();
144
        if( project.getFile()!=null ) {
145
            File ff = FileUtils.getFile(project.getFile().getParentFile(), pathname);
146
            if( ff.exists() ) {
147
                return ff.toURI();
148
            }
149
        }
150
        File ff = new File(pathname);
151
        if( ff.exists() ) {
152
            return ff.toURI();
153
        }
154
        return null;
155
    }
156
    
157

  
158
    @Override
159
    public FLayer getLayer() {
160
        return _layer;
161
    }
162

  
163
    @Override
164
    public void setLayer(FLayer layer) throws IncompatibleLayerException {
165
        try {
166
            _layer = (FLyrVect) layer;
167
        } catch (ClassCastException ex) {
168
            throw new IncompatibleLayerException(ex);
169
        }
170
    }
171

  
172
    public Object create() {
173
        return this;
174
    }
175

  
176
    public Object create(Object[] args) {
177
        return this;
178
    }
179

  
180
    public Object create(Map args) {
181
        return this;
182
    }
183

  
184
//    public URI[][] getLink(Point2D point,
185
//        double tolerance,
186
//        String[] fieldName,
187
//        String fileExtension) {
188
//        FLyrVect lyrVect = (FLyrVect) _layer;
189
//        FeatureSet features;
190
//        FeatureType featureType;
191
//        URI uri[][] = null;
192
//
193
//        try {
194
//            // FIXME: Habr? que ver como lo hacemos con las capas multigeometr?a
195
//            featureType = _layer.getFeatureStore().getDefaultFeatureType();
196
//            features = lyrVect.queryByPoint(point, tolerance, featureType);
197
//        } catch (Exception e) {
198
//            return null;
199
//        }
200
//
201
//        // Si el conjunto creado no est? vac?o creamos el vector de URLS
202
//        // correspondientes
203
//        // a la consulta que hemos hecho.
204
//
205
//        if (features != null) {
206
//            try {
207
//                // Creo el vector de URL?s con la misma longitud que features
208
//                uri = new URI[(int) features.getSize()][fieldName.length];
209
//
210
//                // Recorremos las features siguiendo el ejemplo de la clase que
211
//                // se
212
//                // proporciona en la API
213
//                int count = 0;
214
//                DisposableIterator it = features.fastIterator();
215
//                while (it.hasNext()) {
216
//                    Feature feat = (Feature) it.next();
217
//                    for (int fieldCount = 0; fieldCount < fieldName.length; fieldCount++) {
218
//                        // get the field ID using the field name
219
//                        String auxField =
220
//                            feat.get(fieldName[fieldCount]).toString();
221
//                        if (auxField != null) {
222
//                            if (auxField.startsWith("http:/")) {
223
//                                try {
224
//                                    uri[count][fieldCount] = new URI(auxField);
225
//                                } catch (URISyntaxException e) {
226
//                                    PluginServices.getLogger().error("", e);
227
//                                }
228
//                            } else {
229
//                                File file = new File(auxField);
230
//                                uri[count][fieldCount] = file.toURI();
231
//                            }
232
//                        } else {
233
//                            PluginServices.getLogger()
234
//                                .error("Hyperlink error. Field "
235
//                                    + fieldName[fieldCount] + "doesn't exist!!");
236
//                            uri[count][fieldCount] = null;
237
//                        }
238
//                    }
239
//                    count++;
240
//                }
241
//                it.dispose();
242
//
243
//                return uri;
244
//            } catch (DataException e) {
245
//                PluginServices.getLogger().error("", e);
246
//            }
247
//        }
248
//        return new URI[0][0];
249
//    }
250

  
251
    @Override
252
    public String[] getFieldCandidates() {
253
        try {
254
            FeatureType featureType =
255
                _layer.getFeatureStore().getDefaultFeatureType();
256
            ArrayList<String> fields = new ArrayList<String>();
257
            FeatureAttributeDescriptor[] descriptors =
258
                featureType.getAttributeDescriptors();
259
            for (int i = 0; i < descriptors.length; i++) {
260
                FeatureAttributeDescriptor descriptor = descriptors[i];
261
                if (  !(descriptor.getDataType().isObject() || 
262
                    descriptor.getDataType().getType() == DataTypes.GEOMETRY) ) {
263
                    fields.add(descriptor.getName());
264
                }
265
            }
266
            return (String[]) fields.toArray(new String[0]);
267
        } catch (DataException e) {
268
            NotificationManager.addError(PluginServices.getText(this,
269
                "Error_reading_layer_fields"), e);
270
        }
271
        return new String[0];
272
    }
273

  
274
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/LinkConfigExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension;
24

  
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.andami.plugins.Extension;
27
import org.gvsig.andami.ui.mdiManager.IWindow;
28
import org.gvsig.app.project.documents.view.ViewDocument;
29
import org.gvsig.app.project.documents.view.gui.IView;
30
import org.gvsig.fmap.mapcontext.MapContext;
31
import org.gvsig.fmap.mapcontext.layers.FLayer;
32
import org.gvsig.hyperlink.app.extension.config.gui.ConfigTab;
33
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry;
34
import org.slf4j.Logger;
35
import org.slf4j.LoggerFactory;
36

  
37
/**
38
 * Extensi?n para gestionar los hiperlinks.
39
 * 
40
 * @author Vicente Caballero Navarro
41
 */
42
public class LinkConfigExtension extends Extension {
43

  
44
    private static final Logger logger =
45
        LoggerFactory.getLogger(LinkConfigExtension.class);
46
    ManagerRegistry layerManager;
47

  
48
    /**
49
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
50
     */
51
    public void execute(String s) {
52
        logger.debug("Command : " + s);
53

  
54
        if (s.compareTo("LINK_SETTINGS") == 0) {
55
            IView view =
56
                (IView) PluginServices.getMDIManager().getActiveWindow();
57
            HyperlinkExtension ext =
58
                (HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class);
59
            // init tool and load legacy config in case it has been not done
60
            ext.initTool(view);
61
            FLayer[] activas =
62
                view.getMapControl().getMapContext().getLayers().getActives();
63
            for (int i = 0; i < activas.length; i++) {
64
                if (!activas[i].isAvailable()) {
65
                    return;
66
                }
67

  
68
                if (layerManager.hasManager(activas[i])) {
69
                    ConfigTab configWindow = new ConfigTab();
70
                    configWindow.setModel(activas[i]);
71
                    PluginServices.getMDIManager()
72
                        .addCentredWindow(configWindow);
73
                }
74
            }
75

  
76
        }
77
    }
78

  
79
    /**
80
     * @see com.iver.mdiApp.plugins.IExtension#isVisible()
81
     */
82
    public boolean isVisible() {
83
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
84

  
85
        if (window == null) {
86
            return false;
87
        }
88

  
89
        if (window instanceof IView) {
90

  
91
            MapContext mapa =
92
                ((IView) window).getViewDocument().getMapContext();
93

  
94
            return mapa.getLayers().getLayersCount() > 0;
95
        } else {
96
            return false;
97
        }
98
    }
99

  
100
    /**
101
     * @see com.iver.andami.plugins.IExtension#isEnabled()
102
     */
103
    public boolean isEnabled() {
104
        // it will be enabled when there is only ONE active layer, and this
105
        // layer
106
        // is available and has a valid ILayerLinkManager
107
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
108

  
109
        if (window == null) {
110
            return false;
111
        }
112

  
113
        if (window instanceof IView) {
114
            IView view = (IView) window;
115
            ViewDocument model = view.getViewDocument();
116
            FLayer[] activas = model.getMapContext().getLayers().getActives();
117
            if (activas.length == 1) {
118
                if (activas[0].isAvailable()
119
                    && layerManager.hasManager(activas[0])) {
120
                    return true;
121
                }
122
            }
123
        }
124
        return false;
125
    }
126

  
127
    public void postInitialize() {
128
        HyperlinkExtension ext =
129
            (HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class);
130
        layerManager = ext.getLayerManager();
131
    }
132

  
133
    public void initialize() {
134
        //Do nothing
135
    }
136

  
137
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/ShowPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.event.ComponentEvent;
27
import java.awt.event.ComponentListener;
28
import java.io.File;
29
import java.net.MalformedURLException;
30
import java.net.URI;
31
import java.net.URISyntaxException;
32
import java.net.URL;
33
import java.util.logging.Level;
34
import java.util.logging.Logger;
35

  
36
import javax.swing.JPanel;
37
import javax.swing.JScrollPane;
38

  
39
import org.gvsig.andami.PluginServices;
40
import org.gvsig.andami.ui.mdiManager.IWindow;
41
import org.gvsig.andami.ui.mdiManager.WindowInfo;
42
import org.gvsig.app.project.documents.view.toolListeners.InfoListener;
43
import org.slf4j.LoggerFactory;
44

  
45
/**
46
 * This class extends JPanel. This class implements a Panel to show the content
47
 * of the URI
48
 * that the constructor of the class receives. This panel invokes a new one with
49
 * the content
50
 * of the URI. The type of the supported URI should be added like extension
51
 * point in the
52
 * initialization of the extension.
53
 * 
54
 * @author Vicente Caballero Navarro
55
 * @author Eustaquio Vercher
56
 * 
57
 */
58
public class ShowPanel extends JPanel implements IWindow, ComponentListener {
59

  
60
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(ShowPanel.class);
61
    private JScrollPane jScrollPane = null;
62
    private WindowInfo m_ViewInfo = null;
63
    private AbstractHyperLinkPanel contents = null;
64
    private static int xpos = 0;
65
    private static int ypos = 0;
66

  
67
    public ShowPanel(AbstractHyperLinkPanel contents) {
68
        super();
69
        this.contents = contents;
70
        initialize();
71
    }
72

  
73
    /**
74
     * This method initializes this
75
     */
76
    private void initialize() {
77
        this.setLayout(new BorderLayout());
78
        this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
79
        getJScrollPane().setViewportView(contents);
80
    }
81

  
82
    /**
83
     * Returns a Scroll Pane with the content of the HyperLink
84
     * 
85
     * @return jScrollPane
86
     */
87
    private JScrollPane getJScrollPane() {
88
        if (jScrollPane == null) {
89
            jScrollPane = new JScrollPane();
90
            // jScrollPane.setPreferredSize(new java.awt.Dimension(300, 400));
91
        }
92
        return jScrollPane;
93
    }
94

  
95
    /*
96
     * (non-Javadoc)
97
     * 
98
     * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
99
     */
100
    public WindowInfo getWindowInfo() {
101
        if (m_ViewInfo == null) {
102
            m_ViewInfo
103
                    = new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE
104
                            | WindowInfo.ICONIFIABLE | WindowInfo.PALETTE);
105
            URL urlContent = contents.getLinkTarget().getURL();
106
            if (urlContent != null) {
107
                URI uriContent = null;
108
                try {
109
                    uriContent = urlContent.toURI();
110
                } catch (URISyntaxException ex) {
111
                    logger.warn("Not able to convert to URI:" + urlContent.toString());
112
                }
113

  
114
                if (uriContent != null) {
115
                    if (uriContent.toString().startsWith("file:")
116
                            && uriContent.isAbsolute()) {
117
                        try {
118
                            File file = new File(uriContent.toURL().getFile());
119
                            m_ViewInfo.setTitle(PluginServices.getText(this,
120
                                    "Hyperlink") + " - " + file.getName());
121
                        } catch (MalformedURLException e) {
122
                            m_ViewInfo.setTitle(PluginServices.getText(this,
123
                                    "Hyperlink") + " - " + uriContent.toString());
124
                        } catch (NullPointerException e) {
125
                            m_ViewInfo.setTitle(PluginServices.getText(this,
126
                                    "Hyperlink") + " - " + uriContent.toString());
127
                        }
128
                    } else {
129
                        m_ViewInfo.setTitle(PluginServices.getText(this, "Hyperlink")
130
                                + " - " + uriContent.toString());
131
                    }
132
                }
133
            } else {
134
                m_ViewInfo.setTitle(PluginServices.getText(this, "Hyperlink"));
135
            }
136
        }
137

  
138
        int height = (int) contents.getPreferredSize().getHeight() + 15;
139
        if (height > 650) {
140
            height = 650;
141
        } else if (height < 450) {
142
            height = 450;
143
        }
144
        int width = (int) contents.getPreferredSize().getWidth() + 20;
145
        if (width > 800) {
146
            width = 800;
147
        } else if (width < 450) {
148
            width = 450;
149
        }
150
        m_ViewInfo.setWidth(width);
151
        m_ViewInfo.setHeight(height);
152
        m_ViewInfo.setX(xpos);
153
        xpos = (xpos + 20) % 270;
154
        m_ViewInfo.setY(ypos);
155
        ypos = (ypos + 15) % 150;
156

  
157
        return m_ViewInfo;
158
    }
159

  
160
    /*
161
     * (non-Javadoc)
162
     * 
163
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.
164
     * ComponentEvent)
165
     */
166
    @Override
167
    public void componentResized(ComponentEvent e) {
168

  
169
    }
170

  
171
    /*
172
     * (non-Javadoc)
173
     * 
174
     * @see
175
     * java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent
176
     * )
177
     */
178
    @Override
179
    public void componentMoved(ComponentEvent e) {
180

  
181
    }
182

  
183
    /*
184
     * (non-Javadoc)
185
     * 
186
     * @see
187
     * java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent
188
     * )
189
     */
190
    @Override
191
    public void componentShown(ComponentEvent e) {
192

  
193
    }
194

  
195
    /*
196
     * (non-Javadoc)
197
     * 
198
     * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.
199
     * ComponentEvent)
200
     */
201
    @Override
202
    public void componentHidden(ComponentEvent e) {
203

  
204
    }
205

  
206
    @Override
207
    public Object getWindowProfile() {
208
        return WindowInfo.EDITOR_PROFILE;
209
    }
210
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/SvgFormat.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.actions;
24

  
25
import java.io.Serializable;
26
import java.net.URI;
27

  
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
30
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
31
import org.gvsig.hyperlink.app.extension.LinkTarget;
32

  
33
public class SvgFormat extends AbstractActionManager implements Serializable {
34

  
35
    public static final String actionCode = "SVG_format";
36

  
37
    @Override
38
    public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException {
39
        return new SvgPanel(doc);
40
    }
41

  
42
    @Override
43
    public String getActionCode() {
44
        return actionCode;
45
    }
46

  
47
    @Override
48
    public boolean hasPanel() {
49
        return true;
50
    }
51

  
52
    @Override
53
    public void showDocument(LinkTarget doc) {
54
        throw new UnsupportedOperationException();
55
    }
56

  
57
    @Override
58
    public String getDescription() {
59
        return PluginServices.getText(this, "Shows_SVG_files_in_gvSIG");
60
    }
61

  
62
    @Override
63
    public String getName() {
64
        return PluginServices.getText(this, "SVG_format");
65
    }
66
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/TxtFormat.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.actions;
24

  
25
import java.io.Serializable;
26
import java.net.URI;
27

  
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
30
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
31
import org.gvsig.hyperlink.app.extension.LinkTarget;
32

  
33
public class TxtFormat extends AbstractActionManager implements Serializable {
34

  
35
    public static final String actionCode = "Txt_format";
36

  
37
    public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException {
38
        return new TxtPanel(doc);
39
    }
40

  
41
    public String getActionCode() {
42
        return actionCode;
43
    }
44

  
45
    public boolean hasPanel() {
46
        return true;
47
    }
48

  
49
    public void showDocument(LinkTarget doc) {
50
        throw new UnsupportedOperationException();
51
    }
52

  
53
    public String getDescription() {
54
        return PluginServices.getText(this, "Shows_HTML_or_text_files_in_gvSIG");
55
    }
56

  
57
    public String getName() {
58
        return PluginServices.getText(this, "HTML_and_text_formats");
59
    }
60

  
61
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/ImgPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.actions;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Dimension;
27
import java.awt.Image;
28
import java.awt.image.BufferedImage;
29
import java.net.MalformedURLException;
30
import java.net.URI;
31

  
32
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
33
import org.gvsig.hyperlink.app.extension.LinkTarget;
34

  
35
import org.gvsig.imageviewer.ImageViewer;
36
import org.gvsig.tools.swing.api.SimpleImage;
37
import org.gvsig.tools.swing.api.ToolsSwingLocator;
38
import org.gvsig.tools.swing.api.ToolsSwingManager;
39
import org.gvsig.tools.util.ToolsUtilLocator;
40

  
41
/**
42
 * This class extends AbstractHyperLink, and provides suppot to open images of
43
 * many formats.
44
 * The common supported formats are JPG, ICO, BMP, TIFF, GIF and PNG. Implements
45
 * methods from
46
 * IExtensionBuilder to make it extending.
47
 * 
48
 * @author Eustaquio Vercher (IVER)
49
 * @author Cesar Martinez Izquierdo (IVER)
50
 */
51
public class ImgPanel extends AbstractHyperLinkPanel {
52

  
53
    private static final long serialVersionUID = -5200841105188251551L;
54

  
55
    private ImageViewer imageViewer;
56
    /**
57
     * Default constructor.
58
     * @param doc
59
     */
60
    public ImgPanel(LinkTarget doc) {
61
        super(doc);
62
        initialize();
63
    }
64

  
65
    /**
66
     * Initializes this panel.
67
     */
68
    private void initialize() {
69
        this.setLayout(new BorderLayout());
70
        this.imageViewer = ToolsUtilLocator.getImageViewerManager().createImageViewer();
71
        this.add(this.imageViewer.asJComponent(),BorderLayout.CENTER);
72
        this.setPreferredSize(new Dimension(400, 300));
73
        showDocument();
74
    }
75

  
76
    /**
77
     * Implements the necessary code to open images in this panel.
78
     */
79
    protected void showDocument() {
80
        if (!checkAndNormalizeURI()) {
81
            return;
82
        }
83
        if (document.getURL() != null) {
84
            this.imageViewer.setImage(document.getURL());
85
        } else if (document.getFromProfile() != null) {
86
            try {
87
                Object profileContent = document.getFromProfile();
88
                BufferedImage bufferedImage = null;
89
                if (profileContent instanceof SimpleImage) {
90
                    bufferedImage = ((SimpleImage) profileContent).getBufferedImage();
91
                    this.imageViewer.setImage(bufferedImage);
92
                } else {
93
                    try {
94
                        this.imageViewer.setImage((Image) profileContent);
95
                    } catch (Exception ex) {
96
                        logger.warn("Not able to convert content from field into image");
97
                    }
98
                }
99
            } catch (Exception ex)  {
100
                logger.warn("Not able to get buffered image from document");
101
            }
102
        }
103
    }
104

  
105
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/ExternTxtFormat.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.actions;
24

  
25
import java.io.Serializable;
26
import java.net.URL;
27

  
28
import org.gvsig.andami.PluginServices;
29
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
30
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
31
import org.gvsig.hyperlink.app.extension.LinkTarget;
32

  
33
public class ExternTxtFormat extends AbstractActionManager implements Serializable {
34

  
35
    public static final String actionCode = "TxtExtern_format";
36

  
37
    @Override
38
    public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException {
39
        return null;
40
    }
41

  
42
    @Override
43
    public String getActionCode() {
44
        return actionCode;
45
    }
46

  
47
    @Override
48
    public boolean hasPanel() {
49
        return false;
50
    }
51

  
52
    @Override
53
    public void showDocument(LinkTarget doc) {
54
        URL tourl = doc.getURL();
55
        DesktopApi.browse(tourl);
56
    }
57

  
58
    @Override
59
    public String getDescription() {
60
        return PluginServices.getText(this, "Shows_HTML_or_text_files_in_system_application");
61
    }
62

  
63
    @Override
64
    public String getName() {
65
        return PluginServices.getText(this, "HTML_and_text_formats_in_system_application");
66
    }
67

  
68
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.136/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/PdfHyperlinkPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

  
23
package org.gvsig.hyperlink.app.extension.actions;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Component;
27
import java.awt.Container;
28
import java.awt.Dimension;
29
import java.awt.FlowLayout;
30
import java.awt.Toolkit;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.print.PageFormat;
34
import java.awt.print.Paper;
35
import java.awt.print.PrinterException;
36
import java.awt.print.PrinterJob;
37
import java.beans.PropertyChangeEvent;
38
import java.beans.PropertyChangeListener;
39
import java.net.URI;
40
import java.net.URL;
41

  
42
import javax.print.attribute.HashPrintRequestAttributeSet;
43
import javax.print.attribute.PrintRequestAttributeSet;
44
import javax.print.attribute.SetOfIntegerSyntax;
45
import javax.print.attribute.standard.PageRanges;
46
import javax.swing.JButton;
47
import javax.swing.JLabel;
48
import javax.swing.JOptionPane;
49
import javax.swing.JPanel;
50
import javax.swing.JScrollPane;
51
import javax.swing.JTextField;
52

  
53
import org.gvsig.andami.IconThemeHelper;
54
import org.gvsig.andami.PluginServices;
55
import org.gvsig.andami.messages.NotificationManager;
56
import org.gvsig.andami.ui.mdiManager.IWindow;
57
import org.gvsig.andami.ui.mdiManager.WindowInfo;
58
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
59
import org.gvsig.hyperlink.app.extension.LinkTarget;
60
import org.jpedal.Display;
61
import org.jpedal.PdfDecoder;
62
import org.jpedal.exception.PdfException;
63
import org.jpedal.objects.PrinterOptions;
64

  
65
public class PdfHyperlinkPanel extends AbstractHyperLinkPanel implements
66
    PropertyChangeListener, IWindow {
67

  
68
    private static final long serialVersionUID = 1L;
69
    private WindowInfo m_viewInfo;
70
    private PdfDecoder pf = null;
71

  
72
    private int currentPage = 1;
73
    private final JLabel pageCounter1 = new JLabel(" "
74
        + PluginServices.getText(this, "Pagina") + " ");
75
    private JTextField pageCounter2 = new JTextField(4);
76
    private JLabel pageCounter3 =
77
        new JLabel(PluginServices.getText(this, "de"));
78

  
79
    public static void initializeIcons() {
80
    	IconThemeHelper.registerIcon("toolbar-go", "go-next", PdfHyperlinkPanel.class);
81
    	IconThemeHelper.registerIcon("toolbar-go", "go-previous", PdfHyperlinkPanel.class);
82
    	IconThemeHelper.registerIcon("toolbar-go", "go-next-fast", PdfHyperlinkPanel.class);
83
    	IconThemeHelper.registerIcon("toolbar-go", "go-previous-fast", PdfHyperlinkPanel.class);
84
    	IconThemeHelper.registerIcon("toolbar-go", "go-first", PdfHyperlinkPanel.class);
85
    	IconThemeHelper.registerIcon("toolbar-go", "go-last", PdfHyperlinkPanel.class);
86
    	IconThemeHelper.registerIcon("action", "document-print", PdfHyperlinkPanel.class);
87
    }
88

  
89
    public PdfHyperlinkPanel(LinkTarget doc) {
90
        super(doc);
91
        initialize();
92
    }
93

  
94
    private void initialize() {
95

  
96
        pf = new PdfDecoder();
97

  
98
        try {
99
            if (document != null && document.getURL().toURI().isAbsolute()) {
100
                String urlString = document.getURL().toString();
101
                // avoid the openPdfFileFromURL method in first term, to avoid
102
                // the download dialog
103
                if (urlString.startsWith("file:")) {
104
                    urlString = urlString.replaceFirst("file:/*", "/"); // keep
105
                                                                        // just
106
                                                                        // one
107
                                                                        // slash
108
                                                                        // at
109
                                                                        // the
110
                                                                        // beginning
111
                    urlString = urlString.replaceAll("%20", " "); // PdfDecoder
112
                                                                  // doesn't
113
                                                                  // correctly
114
                                                                  // digest %20
115
                                                                  // spaces
116
                    pf.openPdfFile(urlString);
117
                } else {
118
                    pf.openPdfFileFromURL(urlString, true);
119
                }
120
            } else {
121
                PluginServices.getLogger().warn(PluginServices.getText(this,
122
                    "Hyperlink_linked_field_doesnot_exist"));
123
                return;
124
            }
125

  
126
            // these 2 lines opens page 1 at 100% scaling
127
            pf.decodePage(currentPage);
128
            float scaling = (float) 1.5;
129
            pf.setPageParameters(scaling, 1); // values scaling (1=100%). page
130
                                              // number
131
            pf.setDisplayView(Display.SINGLE_PAGE, Display.DISPLAY_CENTERED);
132
        } catch (Exception e) {
133
            NotificationManager.addWarning(PluginServices.getText(this,
134
                "Hyperlink_linked_field_doesnot_exist"), e);
135
            return;
136
        }
137

  
138
        // setup our GUI display
139
        initializeViewer();
140

  
141
        // set page number display
142
        pageCounter2.setText(currentPage + "");
143
        pageCounter3.setText(PluginServices.getText(this, "de") + " "
144
            + pf.getPageCount() + " ");
145
    }
146

  
147
    public void setCurrentLinkTarget(LinkTarget currentURL) {
148
        document = currentURL;
149
    }
150

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff