Revision 1182

View differences:

org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<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">
3
    <modelVersion>4.0.0</modelVersion>
4
    <artifactId>org.gvsig.hyperlink.app</artifactId>
5
    <packaging>pom</packaging>
6
    <version>1.0.229</version>
7
    <name>${project.artifactId}</name>
8
    <description>View. Hyperlink support</description>
9
	
10
    <parent>
11
        <groupId>org.gvsig</groupId>
12
        <artifactId>org.gvsig.desktop</artifactId>
13
        <version>2.0.426</version>
14
    </parent>
15
        
16
    <url>https://devel.gvsig.org/redmine/projects/gvsig-hyperlink</url>
17
	
18
    <scm>
19
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229</connection>
20
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229</developerConnection>
21
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229</url>
22
    </scm>
23
    
24
    <developers>
25
        <developer>
26
            <id>jjdelcerro</id>
27
            <name>Joaqu?n Jos? del Cerro</name>
28
            <email>jjdelcerro@gvsig.org</email>
29
            <roles>
30
                <role>Architect</role>
31
                <role>Developer</role>
32
            </roles>
33
        </developer>
34
        <developer>
35
            <id>cordinyana</id>
36
            <name>C?sar Ordi?ana</name>
37
            <email>cordinyana@gvsig.com</email>
38
            <roles>
39
                <role>Architect</role>
40
                <role>Developer</role>
41
            </roles>
42
        </developer>
43
    </developers>
44
    <distributionManagement>
45
        <site>
46
            <id>gvsig-repository</id>
47
            <url>dav:https://devel.gvsig.org/sites/org.gvsig.hyperlink.app/${project.version}</url>
48
        </site>
49
    </distributionManagement>
50
    <repositories>
51
        <repository>
52
            <id>gvsig-public-http-repository</id>
53
            <name>gvSIG maven public HTTP repository</name>
54
            <url>http://devel.gvsig.org/m2repo/j2se</url>
55
            <releases>
56
                <enabled>true</enabled>
57
                <updatePolicy>daily</updatePolicy>
58
                <checksumPolicy>warn</checksumPolicy>
59
            </releases>
60
            <snapshots>
61
                <enabled>true</enabled>
62
                <updatePolicy>daily</updatePolicy>
63
                <checksumPolicy>warn</checksumPolicy>
64
            </snapshots>
65
        </repository>
66
    </repositories>
67

  
68
    <build>
69
        <plugins>
70
            <plugin>
71
                <artifactId>maven-release-plugin</artifactId>
72
                <configuration>
73
                    <tagBase>https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags</tagBase>
74
                </configuration>
75
            </plugin>			
76
     
77
        </plugins>   
78
    </build>
79
                
80
    <dependencyManagement>
81
        <dependencies>
82
            <dependency>
83
                <groupId>org.gvsig</groupId>
84
                <artifactId>org.gvsig.pdf.swing.api</artifactId>
85
                <version>${org.gvsig.pdf.version}</version>
86
                <scope>compile</scope>
87
            </dependency>
88

  
89
        </dependencies>
90
    </dependencyManagement>
91
    <properties>
92
        <org.gvsig.pdf.version>1.0.134</org.gvsig.pdf.version>
93
    </properties>
94
        
95
    <modules>
96
        <module>org.gvsig.hyperlink.app.extension</module>
97
    </modules>
98
</project>
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229/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.229/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
package org.gvsig.hyperlink.app.extension;
23

  
24
import java.io.File;
25
import java.io.IOException;
26
import java.net.URI;
27
import java.net.URISyntaxException;
28
import java.util.logging.Level;
29

  
30
import javax.swing.JPanel;
31

  
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.messages.NotificationManager;
34
import org.gvsig.tools.util.URLUtils;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

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

  
48
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractHyperLinkPanel.class);
49

  
50
    protected LinkTarget document;
51

  
52
    public AbstractHyperLinkPanel(LinkTarget linkTarget) {
53
        super();
54
        document = linkTarget;
55
    }
56

  
57
    public LinkTarget getLinkTarget() {
58
        return document;
59
    }
60

  
61
    /**
62
     * Tries to make an absolute url from a relative one, and returns true if
63
     * the URL is valid. false otherwise
64
     *
65
     * @return
66
     */
67
    protected boolean checkAndNormalizeURI() {
68
        if (document == null) {
69
            LOGGER.warn("Hyperlink linked field does not exits");
70
            return false;
71
        } else if (document.getURL() != null) {
72
            try {
73
                if (!document.getURL().toURI().isAbsolute()) {
74
                    try {
75
                        // try as a relative path
76
                        File file = this.document.toFile();
77
                        if (file == null) {
78
                            LOGGER.warn("Hyperlink can't get file from '" + this.document.getURL() + "'.");
79
                            return false;
80
                        }
81
                        file = file.getCanonicalFile();
82
                        if (!file.exists()) {
83
                            LOGGER.warn("Hyperlink linked field, file '"+file+"' not exits");
84
                            return false;
85
                        }
86
                        document.setURL(URLUtils.toURL(file));
87
                        return true;
88
                    } catch (IOException e) {
89
                        LOGGER.warn("Hyperlink linked field does not exits");
90
                        return false;
91
                    }
92
                }
93
            } catch (URISyntaxException ex) {
94
                LOGGER.warn("Hyperlink linked field does not exits");
95
                return false;
96
            }
97
        }
98
        return true;
99
    }
100
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/DefaultLinkTarget.java
1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.hyperlink.app.extension;
7

  
8
import java.io.File;
9
import java.net.MalformedURLException;
10
import java.net.URI;
11
import java.net.URISyntaxException;
12
import java.net.URL;
13
import java.net.URLClassLoader;
14
import java.util.logging.Level;
15
import java.util.logging.Logger;
16
import java.util.regex.Matcher;
17
import java.util.regex.Pattern;
18
import org.apache.commons.io.FileUtils;
19
import org.apache.commons.lang3.StringUtils;
20
import org.gvsig.app.ApplicationLocator;
21
import org.gvsig.app.project.Project;
22
import org.gvsig.app.project.ProjectManager;
23
import org.gvsig.fmap.dal.exception.DataException;
24
import org.gvsig.fmap.dal.feature.Feature;
25
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
26
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
27
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
28
import org.gvsig.tools.util.URLUtils;
29

  
30
/**
31
 *
32
 * @author osc
33
 */
34
public class DefaultLinkTarget implements LinkTarget {
35

  
36
    private URL url;
37
    private final String fieldExtension;
38
    private final FLyrVect _layer;
39
    private final String fieldName;
40
    private Object content;
41
    private String profileName;
42

  
43

  
44
    public DefaultLinkTarget(FLyrVect layer,Feature feature, String fieldName, String fieldExtension) {
45
        this.fieldName = fieldName;
46
        this.fieldExtension = fieldExtension;
47
        this._layer = layer;
48
        this.url = null;
49
        Object val = feature.get(fieldName);
50
        String fieldValue = (val == null) ? "" : val.toString();
51
        if (!fieldValue.equals("")) {
52
            try {
53
                URI uri = this.getURI(fieldValue, fieldExtension);
54
                if (uri != null) {
55
                    this.url = uri.toURL();
56
                } else {
57
                    this.url = null;
58
                }
59

  
60
            } catch (URISyntaxException ex) {
61
                Logger.getLogger(DefaultLinkTarget.class.getName()).log(Level.SEVERE, null, ex);
62
                this.url = null;
63
            } catch (MalformedURLException ex) {
64
                Logger.getLogger(DefaultLinkTarget.class.getName()).log(Level.SEVERE, null, ex);
65
                this.url = null;
66
            }
67
            if (this.url == null) {
68
                FeatureAttributeDescriptor fad;
69

  
70
                try {
71
                    this.content = feature.getFromProfile(fieldName);
72
                    fad = feature.getStore().getDefaultFeatureType().getAttributeDescriptor(fieldName);
73
                } catch (DataException ex) {
74
                    fad = null;
75
                    Logger.getLogger(DefaultLinkTarget.class.getName()).log(Level.SEVERE, null, ex);
76
                }
77
                if (fad != null) {
78
                    this.profileName = fad.getDataProfileName();
79
                } else {
80
                    this.profileName = null;
81
                }
82

  
83
            }
84
        }
85
        
86

  
87
    }
88
    protected URI getBasicURI(String baseURI, String extension) throws URISyntaxException {
89
        String pathname;
90
        if( StringUtils.isEmpty(extension) ) {
91
            pathname = baseURI;
92
        } else {
93
            if (extension.startsWith(".")) {
94
                pathname = baseURI + extension;
95
            } else {
96
                pathname = baseURI + "." + extension;
97
            }
98
        }
99
        pathname = pathname.replace("\\","//");
100
        if( this._layer.getFeatureStore().getParameters() instanceof FilesystemStoreParameters ) {
101
            FilesystemStoreParameters params = (FilesystemStoreParameters) this._layer.getFeatureStore().getParameters();
102
            File f = params.getFile();
103
            URLClassLoader loader = new URLClassLoader(new URL[] {toURL(f)});
104
            URL url = loader.getResource(pathname);
105
            if( url != null ) {
106
                return url.toURI();
107
            }
108
            url = loader.getResource("/" + pathname);
109
            if( url != null ) {
110
                return url.toURI();
111
            }
112
            File ff = FileUtils.getFile(f.getParentFile(), pathname);
113
            if( ff.exists() ) {
114
                return ff.toURI();
115
            }
116
        }
117
        ProjectManager projectManager = ApplicationLocator.getProjectManager();
118
        Project project = projectManager.getCurrentProject();
119
        if( project.getFile()!=null ) {
120
            File ff = FileUtils.getFile(project.getFile().getParentFile(), pathname);
121
            if( ff.exists() ) {
122
                return ff.toURI();
123
            }
124
        }
125
        File ff = new File(pathname);
126
        if( ff.exists() ) {
127
            return ff.toURI();
128
        }
129
        return null;
130
    }
131
    
132
     protected URI getURI(String baseURI, String extension) throws URISyntaxException {
133
        if( StringUtils.isEmpty(baseURI) ) {
134
            return null;
135
        }
136
        URI uri = getBasicURI(baseURI, extension);
137
        if( uri!=null ) {
138
            return uri;
139
        }
140
        String value = baseURI.trim();
141

  
142
        Pattern pattern = Pattern.compile(".*<img[^>]*src=\"([^\"]*)\".*",  Pattern.CASE_INSENSITIVE|Pattern.MULTILINE|Pattern.DOTALL);
143
        Matcher m = pattern.matcher(value);
144
        if( m!=null && m.matches() ) {
145
            String x = m.group(1);
146
            if( !StringUtils.isEmpty(x) ) {
147
                uri = getBasicURI(x, extension);
148
                if( uri!=null ) {
149
                    return uri;
150
                }
151
            }
152
        }
153
        pattern = Pattern.compile(".*<a[^>]*href=\"([^\"]*)\".*", Pattern.CASE_INSENSITIVE|Pattern.MULTILINE|Pattern.DOTALL);
154
        m = pattern.matcher(value);
155
        if( m!=null && m.matches() ) {
156
            String x = m.group(1);
157
            if( !StringUtils.isEmpty(x) ) {
158
                uri = getBasicURI(x, extension);
159
                if( uri!=null ) {
160
                    return uri;
161
                }
162
            }
163
        }
164
        try {
165
            URI createURI = new URI(baseURI);
166
            return createURI;
167
        } catch (Exception e) {
168
            //throw new URISyntaxException(baseURI, "Can't make a valid URI.");
169
            return null;
170
        }
171
    }
172
     
173
    private URL toURL(File f) {
174
        try {
175
            return f.toURI().toURL();
176
        } catch (MalformedURLException ex) {
177
            return null;
178
        }
179
    }
180
    
181
    @Override
182
    public URL getURL() {
183
        return this.url;
184
    }
185

  
186
    @Override
187
    public File toFile() {
188
        return URLUtils.toFile(this.url);
189
    }
190

  
191
    @Override
192
    public Object getFromProfile() {
193
        return this.content;
194
 }
195

  
196
    @Override
197
    public String getProfileName() {
198
        return this.profileName;
199
    }
200

  
201
    @Override
202
    public void setURL(URL url) {
203
        this.url = url;
204
    }
205

  
206
    @Override
207
    public URI toURI() {
208
        try {
209
            return this.url.toURI();
210
        } catch (URISyntaxException ex) {
211
            return null;
212
        }
213
    }
214

  
215
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229/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
import javax.swing.JOptionPane;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.i18n.I18nManager;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

  
32
public abstract class AbstractActionManager implements ILinkActionManager {
33

  
34
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractActionManager.class);
35
    private final String actionCode;
36
    private final String name;
37
    private final String description;
38
    
39
    protected AbstractActionManager(String actionCode, String name, String description) {
40
        I18nManager i18n = ToolsLocator.getI18nManager();
41
        this.actionCode = actionCode;
42
        this.name = i18n.getTranslation(name);
43
        this.description = i18n.getTranslation(description);
44
    }
45
    
46
    @Override
47
    public AbstractHyperLinkPanel createPanel(LinkTarget document) throws UnsupportedOperationException {
48
        return null;
49
    }
50

  
51
    @Override
52
    public String getActionCode() {
53
        return actionCode;
54
    }
55

  
56
    public boolean hasPanel() {
57
        return false;
58
    }
59
    
60
    @Override
61
    public String getDescription() {
62
        return this.description;
63
    }
64

  
65
    @Override
66
    public String getName() {
67
        return this.name;
68
    }
69
    
70
    @Override
71
    public void showDocument(LinkTarget doc) throws UnsupportedOperationException {
72
        LOGGER.warn("showDocument not implemented in "+this.getClass().getSimpleName());
73
    }
74
    
75
    public Object create() {
76
        return this;
77
    }
78

  
79
    public Object create(Object[] args) {
80
        return this;
81
    }
82

  
83
    public Object create(Map args) {
84
        return this;
85
    }
86

  
87
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229/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.229/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.229/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.229/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
import org.gvsig.tools.dispose.DisposeUtils;
56

  
57
public class VectLayerManager implements ILinkLayerManager {
58

  
59
    private FLyrVect _layer = null;
60

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

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

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

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

  
87
                    while (it.hasNext()) {
88
                        Feature feature = (Feature) it.next();
89

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

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

  
161
    @Override
162
    public FLayer getLayer() {
163
        return _layer;
164
    }
165

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

  
175
    public Object create() {
176
        return this;
177
    }
178

  
179
    public Object create(Object[] args) {
180
        return this;
181
    }
182

  
183
    public Object create(Map args) {
184
        return this;
185
    }
186

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

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

  
277
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.229/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.229/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.229/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
     */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff