Revision 410

View differences:

org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/org.gvsig.hyperlink.app.extension/buildNumber.properties
1
#Sun Mar 03 13:04:23 CET 2019
2
buildNumber=2164
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/org.gvsig.hyperlink.app.extension/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
<!-- org.gvsig.app.mainplugin provides these libraries
26
  <dependencySets>
27
  
28
    <dependencySet>
29
      <useProjectArtifact>false</useProjectArtifact>
30
      <useTransitiveDependencies>false</useTransitiveDependencies>
31
      <outputDirectory>lib</outputDirectory>
32
      <includes>
33
            <include>org.jpedal:jpedal_lgpl</include>
34
            <include>com.sun:jimi</include>
35
            <include>org.apache.xmlgraphics:batik-gvt</include>
36
            <include>org.apache.xmlgraphics:batik-bridge</include>
37
            <include>org.apache.xmlgraphics:batik-script</include>
38
            <include>xml-apis:xml-apis-ext</include>
39
      </includes>
40
    </dependencySet>
41
  </dependencySets>
42
-->
43

  
44
</assembly>
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/AbstractHyperLinkPanel.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.io.File;
26
import java.io.IOException;
27
import java.net.URI;
28

  
29
import javax.swing.JPanel;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.slf4j.Logger;
33
import org.slf4j.LoggerFactory;
34

  
35
/**
36
 * This class extends JPanel and implements IExtensioBuilder. Provides the
37
 * methods that will be reimplemented by the descendant class. Creates a panel
38
 * that shows the content of a URI. The necessary code that allows to show the
39
 * content of the URI is provided by the descendant class. Implmenting
40
 * IExtenssionBuilder this class and its the descendant provides a point of
41
 * extension for other extensions.
42
 */
43
public abstract class AbstractHyperLinkPanel extends JPanel {
44

  
45
    protected static final Logger logger = LoggerFactory.getLogger(AbstractHyperLinkPanel.class);
46
    
47
    protected URI document;
48

  
49
    public AbstractHyperLinkPanel(URI doc) {
50
        super();
51
        document = doc;
52
    }
53

  
54
    public URI getURI() {
55
        return document;
56
    }
57

  
58
    /**
59
     * Tries to make an absolute url from a relative one,
60
     * and returns true if the URL is valid.
61
     * false otherwise
62
     * 
63
     * @return
64
     */
65
    protected boolean checkAndNormalizeURI() {
66
        if (document == null) {
67
            PluginServices.getLogger().warn(PluginServices.getText(this,
68
                "Hyperlink_linked_field_doesnot_exist"));
69
            return false;
70
        } else
71
            if (!document.isAbsolute()) {
72
                try {
73
                    // try as a relative path
74
                    File file =
75
                        new File(document.toString()).getCanonicalFile();
76
                    if (!file.exists()) {
77
                        PluginServices.getLogger()
78
                            .warn(PluginServices.getText(this,
79
                                "Hyperlink_linked_field_doesnot_exist"));
80
                        return false;
81
                    }
82
                    document = file.toURI();
83
                } catch (IOException e) {
84
                    PluginServices.getLogger()
85
                        .warn(PluginServices.getText(this,
86
                            "Hyperlink_linked_field_doesnot_exist"));
87
                    return false;
88
                }
89
            }
90
        return true;
91
    }
92
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/AbstractActionManager.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.util.Map;
26

  
27
public abstract class AbstractActionManager implements ILinkActionManager {
28

  
29
    public boolean hasPanel() {
30
        return false;
31
    }
32

  
33
    public Object create() {
34
        return this;
35
    }
36

  
37
    public Object create(Object[] args) {
38
        return this;
39
    }
40

  
41
    public Object create(Map args) {
42
        return this;
43
    }
44

  
45
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/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(URI doc) throws UnsupportedOperationException;
45

  
46
    public boolean hasPanel();
47

  
48
    public AbstractHyperLinkPanel createPanel(URI 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.77/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 java.net.URI;
27

  
28
import org.gvsig.fmap.mapcontext.layers.FLayer;
29

  
30
public interface ILinkLayerManager {
31

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

  
34
    public FLayer getLayer();
35

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

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

  
46
    public String[] getFieldCandidates();
47
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/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.77/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.77/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.Map;
34
import java.util.logging.Level;
35
import java.util.logging.Logger;
36
import java.util.regex.Matcher;
37
import java.util.regex.Pattern;
38
import org.apache.commons.io.FileUtils;
39
import org.apache.commons.lang3.StringUtils;
40

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

  
57
public class VectLayerManager implements ILinkLayerManager {
58

  
59
    private FLyrVect _layer = null;
60

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

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

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

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

  
88
                while (it.hasNext()) {
89
                    Feature feature = (Feature) it.next();
90
                    val = feature.get(fieldName);
91
                    String fieldValue = (val == null) ? "" : val.toString();
92
                    if (!fieldValue.equals("")) {
93
                        try {
94
                            uriList.add(getURI(fieldValue, fileExtension));
95
                        } catch (URISyntaxException e) {
96
                            NotificationManager.addWarning(PluginServices.getText(this,
97
                                "Hyperlink__field_value_is_not_valid_file"),
98
                                e);
99
                        }
100
                    }
101

  
102
                }
103
                it.dispose();
104
                return (URI[]) uriList.toArray(new URI[0]);
105
            } catch (DataException e1) {
106
                PluginServices.getLogger()
107
                    .error("Hyperlink__cant_get_the_iterator", e1);
108
            }
109
        }
110
        return new URI[0];
111
    }
112

  
113
    private URL toURL(File f) {
114
        try {
115
            return f.toURI().toURL();
116
        } catch (MalformedURLException ex) {
117
            return null;
118
        }
119
    }
120
    
121
    protected URI getBasicURI(String baseURI, String extension) throws URISyntaxException {
122
        String pathname;
123
        if( StringUtils.isEmpty(extension) ) {
124
            pathname = baseURI;
125
        } else {
126
            if (extension.startsWith(".")) {
127
                pathname = baseURI + extension;
128
            } else {
129
                pathname = baseURI + "." + extension;
130
            }
131
        }
132
        pathname = pathname.replace("\\","//");
133
        if( this._layer.getFeatureStore().getParameters() instanceof FilesystemStoreParameters ) {
134
            FilesystemStoreParameters params = (FilesystemStoreParameters) this._layer.getFeatureStore().getParameters();
135
            File f = params.getFile();
136
            URLClassLoader loader = new URLClassLoader(new URL[] {toURL(f)});
137
            URL url = loader.getResource(pathname);
138
            if( url != null ) {
139
                return url.toURI();
140
            }
141
            url = loader.getResource("/" + pathname);
142
            if( url != null ) {
143
                return url.toURI();
144
            }
145
            File ff = FileUtils.getFile(f.getParentFile(), pathname);
146
            if( ff.exists() ) {
147
                return ff.toURI();
148
            }
149
        }
150
        ProjectManager projectManager = ApplicationLocator.getProjectManager();
151
        Project project = projectManager.getCurrentProject();
152
        if( project.getFile()!=null ) {
153
            File ff = FileUtils.getFile(project.getFile().getParentFile(), pathname);
154
            if( ff.exists() ) {
155
                return ff.toURI();
156
            }
157
        }
158
        File ff = new File(pathname);
159
        if( ff.exists() ) {
160
            return ff.toURI();
161
        }
162
        return null;
163
    }
164
    
165
    protected URI getURI(String baseURI, String extension) throws URISyntaxException {
166
        if( StringUtils.isEmpty(baseURI) ) {
167
            return null;
168
        }
169
        URI uri = getBasicURI(baseURI, extension);
170
        if( uri!=null ) {
171
            return uri;
172
        }
173
        String value = baseURI.trim();
174

  
175
        Pattern pattern = Pattern.compile(".*<img[^>]*src=\"([^\"]*)\".*",  Pattern.CASE_INSENSITIVE|Pattern.MULTILINE|Pattern.DOTALL);
176
        Matcher m = pattern.matcher(value);
177
        if( m!=null && m.matches() ) {
178
            String x = m.group(1);
179
            if( !StringUtils.isEmpty(x) ) {
180
                uri = getBasicURI(x, extension);
181
                if( uri!=null ) {
182
                    return uri;
183
                }
184
            }
185
        }
186
        pattern = Pattern.compile(".*<a[^>]*href=\"([^\"]*)\".*", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE|Pattern.DOTALL);
187
        m = pattern.matcher(value);
188
        if( m!=null && m.matches() ) {
189
            String x = m.group(1);
190
            if( !StringUtils.isEmpty(x) ) {
191
                uri = getBasicURI(x, extension);
192
                if( uri!=null ) {
193
                    return uri;
194
                }
195
            }
196
        }
197
        try {
198
            URI createURI = new URI(baseURI);
199
            return createURI;
200
        } catch (Exception e) {
201
            throw new URISyntaxException(baseURI, "Can't make a valid URI.");
202
        }
203
    }
204

  
205
    public FLayer getLayer() {
206
        return _layer;
207
    }
208

  
209
    public void setLayer(FLayer layer) throws IncompatibleLayerException {
210
        try {
211
            _layer = (FLyrVect) layer;
212
        } catch (ClassCastException ex) {
213
            throw new IncompatibleLayerException(ex);
214
        }
215
    }
216

  
217
    public Object create() {
218
        return this;
219
    }
220

  
221
    public Object create(Object[] args) {
222
        return this;
223
    }
224

  
225
    public Object create(Map args) {
226
        return this;
227
    }
228

  
229
    public URI[][] getLink(Point2D point,
230
        double tolerance,
231
        String[] fieldName,
232
        String fileExtension) {
233
        FLyrVect lyrVect = (FLyrVect) _layer;
234
        FeatureSet features;
235
        FeatureType featureType;
236
        URI uri[][] = null;
237

  
238
        try {
239
            // FIXME: Habr? que ver como lo hacemos con las capas multigeometr?a
240
            featureType = _layer.getFeatureStore().getDefaultFeatureType();
241
            features = lyrVect.queryByPoint(point, tolerance, featureType);
242
        } catch (Exception e) {
243
            return null;
244
        }
245

  
246
        // Si el conjunto creado no est? vac?o creamos el vector de URLS
247
        // correspondientes
248
        // a la consulta que hemos hecho.
249

  
250
        if (features != null) {
251
            try {
252
                // Creo el vector de URL?s con la misma longitud que features
253
                uri = new URI[(int) features.getSize()][fieldName.length];
254

  
255
                // Recorremos las features siguiendo el ejemplo de la clase que
256
                // se
257
                // proporciona en la API
258
                int count = 0;
259
                DisposableIterator it = features.fastIterator();
260
                while (it.hasNext()) {
261
                    Feature feat = (Feature) it.next();
262
                    for (int fieldCount = 0; fieldCount < fieldName.length; fieldCount++) {
263
                        // get the field ID using the field name
264
                        String auxField =
265
                            feat.get(fieldName[fieldCount]).toString();
266
                        if (auxField != null) {
267
                            if (auxField.startsWith("http:/")) {
268
                                try {
269
                                    uri[count][fieldCount] = new URI(auxField);
270
                                } catch (URISyntaxException e) {
271
                                    PluginServices.getLogger().error("", e);
272
                                }
273
                            } else {
274
                                File file = new File(auxField);
275
                                uri[count][fieldCount] = file.toURI();
276
                            }
277
                        } else {
278
                            PluginServices.getLogger()
279
                                .error("Hyperlink error. Field "
280
                                    + fieldName[fieldCount] + "doesn't exist!!");
281
                            uri[count][fieldCount] = null;
282
                        }
283
                    }
284
                    count++;
285
                }
286
                it.dispose();
287

  
288
                return uri;
289
            } catch (DataException e) {
290
                PluginServices.getLogger().error("", e);
291
            }
292
        }
293
        return new URI[0][0];
294
    }
295

  
296
    public String[] getFieldCandidates() {
297
        try {
298
            FeatureType featureType =
299
                _layer.getFeatureStore().getDefaultFeatureType();
300
            ArrayList<String> fields = new ArrayList<String>();
301
            FeatureAttributeDescriptor[] descriptors =
302
                featureType.getAttributeDescriptors();
303
            for (int i = 0; i < descriptors.length; i++) {
304
                FeatureAttributeDescriptor descriptor = descriptors[i];
305
                if (  !(descriptor.getDataType().isObject() || 
306
                    descriptor.getDataType().getType() == DataTypes.GEOMETRY) ) {
307
                    fields.add(descriptor.getName());
308
                }
309
            }
310
            return (String[]) fields.toArray(new String[0]);
311
        } catch (DataException e) {
312
            NotificationManager.addError(PluginServices.getText(this,
313
                "Error_reading_layer_fields"), e);
314
        }
315
        return new String[0];
316
    }
317

  
318
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/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.77/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

  
31
import javax.swing.JPanel;
32
import javax.swing.JScrollPane;
33

  
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiManager.IWindow;
36
import org.gvsig.andami.ui.mdiManager.WindowInfo;
37

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

  
53
    private JScrollPane jScrollPane = null;
54
    private WindowInfo m_ViewInfo = null;
55
    private AbstractHyperLinkPanel contents = null;
56
    private static int xpos = 0;
57
    private static int ypos = 0;
58

  
59
    public ShowPanel(AbstractHyperLinkPanel contents) {
60
        super();
61
        this.contents = contents;
62
        initialize();
63
    }
64

  
65
    /**
66
     * This method initializes this
67
     */
68
    private void initialize() {
69
        this.setLayout(new BorderLayout());
70
        this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
71
        getJScrollPane().setViewportView(contents);
72
    }
73

  
74
    /**
75
     * Returns a Scroll Pane with the content of the HyperLink
76
     * 
77
     * @return jScrollPane
78
     */
79
    private JScrollPane getJScrollPane() {
80
        if (jScrollPane == null) {
81
            jScrollPane = new JScrollPane();
82
            // jScrollPane.setPreferredSize(new java.awt.Dimension(300, 400));
83
        }
84
        return jScrollPane;
85
    }
86

  
87
    /*
88
     * (non-Javadoc)
89
     * 
90
     * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
91
     */
92
    public WindowInfo getWindowInfo() {
93
        if (m_ViewInfo == null) {
94
            m_ViewInfo =
95
                new WindowInfo(WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE
96
                    | WindowInfo.ICONIFIABLE | WindowInfo.PALETTE);
97
            if (contents.getURI().toString().startsWith("file:")
98
                && contents.getURI().isAbsolute()) {
99
                try {
100
                    File file = new File(contents.getURI().toURL().getFile());
101
                    m_ViewInfo.setTitle(PluginServices.getText(this,
102
                        "Hyperlink") + " - " + file.getName());
103
                } catch (MalformedURLException e) {
104
                    m_ViewInfo.setTitle(PluginServices.getText(this,
105
                        "Hyperlink") + " - " + contents.getURI().toString());
106
                } catch (NullPointerException e) {
107
                    m_ViewInfo.setTitle(PluginServices.getText(this,
108
                        "Hyperlink") + " - " + contents.getURI().toString());
109
                }
110
            } else {
111
                m_ViewInfo.setTitle(PluginServices.getText(this, "Hyperlink")
112
                    + " - " + contents.getURI().toString());
113
            }
114
            int height = (int) contents.getPreferredSize().getHeight() + 15;
115
            if (height > 650)
116
                height = 650;
117
            else
118
                if (height < 450)
119
                    height = 450;
120
            int width = (int) contents.getPreferredSize().getWidth() + 20;
121
            if (width > 800)
122
                width = 800;
123
            else
124
                if (width < 450)
125
                    width = 450;
126
            m_ViewInfo.setWidth(width);
127
            m_ViewInfo.setHeight(height);
128
            m_ViewInfo.setX(xpos);
129
            xpos = (xpos + 20) % 270;
130
            m_ViewInfo.setY(ypos);
131
            ypos = (ypos + 15) % 150;
132
        }
133
        return m_ViewInfo;
134
    }
135

  
136
    /*
137
     * (non-Javadoc)
138
     * 
139
     * @see java.awt.event.ComponentListener#componentResized(java.awt.event.
140
     * ComponentEvent)
141
     */
142
    public void componentResized(ComponentEvent e) {
143

  
144
    }
145

  
146
    /*
147
     * (non-Javadoc)
148
     * 
149
     * @see
150
     * java.awt.event.ComponentListener#componentMoved(java.awt.event.ComponentEvent
151
     * )
152
     */
153
    public void componentMoved(ComponentEvent e) {
154

  
155
    }
156

  
157
    /*
158
     * (non-Javadoc)
159
     * 
160
     * @see
161
     * java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent
162
     * )
163
     */
164
    public void componentShown(ComponentEvent e) {
165

  
166
    }
167

  
168
    /*
169
     * (non-Javadoc)
170
     * 
171
     * @see java.awt.event.ComponentListener#componentHidden(java.awt.event.
172
     * ComponentEvent)
173
     */
174
    public void componentHidden(ComponentEvent e) {
175

  
176
    }
177

  
178
    public Object getWindowProfile() {
179
        return WindowInfo.EDITOR_PROFILE;
180
    }
181
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/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.net.MalformedURLException;
28
import java.net.URI;
29

  
30
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
31

  
32
import org.gvsig.imageviewer.ImageViewer;
33
import org.gvsig.tools.util.ToolsUtilLocator;
34

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

  
47
    private static final long serialVersionUID = -5200841105188251551L;
48

  
49
    private ImageViewer imageViewer;
50
    /**
51
     * Default constructor.
52
     * @param doc
53
     */
54
    public ImgPanel(URI doc) {
55
        super(doc);
56
        initialize();
57
    }
58

  
59
    /**
60
     * Initializes this panel.
61
     */
62
    private void initialize() {
63
        this.setLayout(new BorderLayout());
64
        this.imageViewer = ToolsUtilLocator.getImageViewerManager().createImageViewer();
65
        this.add(this.imageViewer.asJComponent(),BorderLayout.CENTER);
66
        this.setPreferredSize(new Dimension(400, 300));
67
        showDocument();
68
    }
69

  
70
    /**
71
     * Implements the necessary code to open images in this panel.
72
     */
73
    protected void showDocument() {
74
        if (!checkAndNormalizeURI()) {
75
            return;
76
        }
77
        try {
78
            this.imageViewer.setImage(document.toURL());
79
        } catch (MalformedURLException e) {
80
            logger.warn("Can't load image '"+document.toString()+"'.", e);
81
        }
82
    }
83

  
84
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/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.File;
26
import java.io.Serializable;
27
import java.net.URI;
28
import javax.swing.JOptionPane;
29

  
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
32
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
33

  
34
public class ExternTxtFormat extends AbstractActionManager implements Serializable {
35

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

  
38
    public AbstractHyperLinkPanel createPanel(URI doc) throws UnsupportedOperationException {
39
        return null;
40
    }
41

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

  
46
    public boolean hasPanel() {
47
        return false;
48
    }
49

  
50
    public void showDocument(URI doc) {
51
        DesktopApi.browse(doc);
52
    }
53

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

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

  
62
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.77/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

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

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

  
63
public class PdfHyperlinkPanel extends AbstractHyperLinkPanel implements
64
    PropertyChangeListener, IWindow {
65

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

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

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

  
87
    public PdfHyperlinkPanel(URI doc) {
88
        super(doc);
89
        initialize();
90
    }
91

  
92
    private void initialize() {
93

  
94
        pf = new PdfDecoder();
95

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

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

  
136
        // setup our GUI display
137
        initializeViewer();
138

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

  
145
    public void setCurrentURL(URI currentURL) {
146
        document = currentURL;
147
    }
148

  
149
    private void initializeViewer() {
150

  
151
        Container cPane = this;
152
        cPane.setLayout(new BorderLayout());
153

  
154
        // JButton open = initOpenBut();//setup open button
155
        Component[] itemsToAdd = initChangerPanel();// setup page display and
156
                                                    // changer
157

  
158
        JPanel topBar = new JPanel();
159
        topBar.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
160
        // topBar.add(pageChanger);
161
        for (int i = 0; i < itemsToAdd.length; i++) {
162
            topBar.add(itemsToAdd[i]);
163
        }
164

  
165
        cPane.add(topBar, BorderLayout.NORTH);
166

  
167
        JScrollPane display = getJPaneViewer();// setup scrollpane with pdf
168
                                               // display inside
169
        cPane.add(display, BorderLayout.CENTER);
170

  
171
        // pack();
172

  
173
        Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
174
        setSize(screen.width / 2, screen.height / 2);
175
        // <start-13>
176
        // setLocationRelativeTo(null);//centre on screen
177
        // <end-13>
178
        setVisible(true);
179
    }
180

  
181
    private Component[] initChangerPanel() {
182

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

Also available in: Unified diff