Revision 1287

View differences:

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

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

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

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

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

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

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

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

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

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

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

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

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

  
157
        return m_ViewInfo;
158
    }
159

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

  
169
    }
170

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

  
181
    }
182

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

  
193
    }
194

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

  
204
    }
205

  
206
    @Override
207
    public Object getWindowProfile() {
208
        return WindowInfo.EDITOR_PROFILE;
209
    }
210
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.250/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/FolderFormat.java
1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.hyperlink.app.extension.actions;
25

  
26
import java.io.File;
27
import java.io.Serializable;
28
import java.net.URI;
29
import javax.swing.JOptionPane;
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.desktopopen.DesktopOpen;
32
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
33
import org.gvsig.hyperlink.app.extension.LinkTarget;
34
import org.gvsig.tools.util.ToolsUtilLocator;
35

  
36
public class FolderFormat extends AbstractActionManager implements Serializable {
37

  
38
    public static final String ACTION_CODE = "Folder_format";
39
            
40
    public FolderFormat() {
41
        super(ACTION_CODE,"Folder_formats","Shows_Folders_in_gvSIG");
42
    }
43

  
44
    @Override
45
    public void showDocument(LinkTarget doc) {
46
        File folder = doc.toFile();
47
        if ( folder==null ) {
48
            JOptionPane.showMessageDialog(null, PluginServices.getText(this, "Bad_path"));
49
            return;
50
        }
51
        if( !folder.exists() ) {
52
            JOptionPane.showMessageDialog(null, PluginServices.getText(this, "Bad_path") + " : " + folder.getAbsolutePath());
53
            return;
54
        }
55
        URI uri = doc.toURI();
56
        DesktopOpen desktop = ToolsUtilLocator.getToolsUtilManager().createDesktopOpen();
57
        desktop.browse(uri);
58
    }
59

  
60
}
61

  
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.250/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/ImgFormat.java
1
/* gvSIG. Desktop Geographic Information System.
2

  
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24

  
25
package org.gvsig.hyperlink.app.extension.actions;
26

  
27
import java.awt.Image;
28
import java.awt.image.BufferedImage;
29
import java.io.Serializable;
30
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
31
import org.gvsig.hyperlink.app.extension.LinkTarget;
32
import org.gvsig.imageviewer.ImageViewer;
33
import org.gvsig.tools.swing.api.SimpleImage;
34
import org.gvsig.tools.swing.api.ToolsSwingLocator;
35
import org.gvsig.tools.swing.api.ToolsSwingUtils;
36
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
37
import org.gvsig.tools.util.ToolsUtilLocator;
38

  
39
public class ImgFormat extends AbstractActionManager implements Serializable {
40

  
41
    public static final String ACTION_CODE = "Image_format";
42

  
43
    public ImgFormat() {
44
        super(ACTION_CODE,"Image_format","Shows_image_files_in_gvSIG");
45
    }
46

  
47
    @Override
48
    public void showDocument(LinkTarget document) {
49
        String title = "Image";
50
        ImageViewer viewer = ToolsUtilLocator.getImageViewerManager().createImageViewer();
51
        if (document.getURL() != null) {
52
            title = document.getURL().toString();
53
            viewer.setImage(document.getURL());
54
        } else if (document.getFromProfile() != null) {            
55
            try {
56
                Object profileContent = document.getFromProfile();
57
                BufferedImage bufferedImage = null;
58
                if (profileContent instanceof SimpleImage) {
59
                    bufferedImage = ((SimpleImage) profileContent).getBufferedImage();
60
                    viewer.setImage(bufferedImage);
61
                } else {
62
                    try {
63
                        viewer.setImage((Image) profileContent);
64
                    } catch (Exception ex) {
65
                        LOGGER.warn("Not able to convert content from field into image");
66
                    }
67
                }
68
            } catch (Exception ex)  {
69
                LOGGER.warn("Not able to get buffered image from document");
70
            }
71
        }
72
        ToolsSwingUtils.ensureRowsCols(viewer.asJComponent(), 20, 100, 40, 150);
73
        WindowManager windowManager = ToolsSwingLocator.getWindowManager();
74
        windowManager.showWindow(
75
                viewer.asJComponent(),
76
                "Hyperlink"+": "+title, 
77
                WindowManager.MODE.WINDOW
78
        );
79
    }
80

  
81

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

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

  
25
import java.io.Serializable;
26
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
27
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
28
import org.gvsig.hyperlink.app.extension.LinkTarget;
29

  
30
public class SvgFormat extends AbstractActionManager implements Serializable {
31

  
32
    public static final String ACTION_CODE = "SVG_format";
33

  
34
    public SvgFormat() {
35
        super(ACTION_CODE, "SVG_format","Shows_SVG_files_in_gvSIG");
36
    }
37
    
38
    @Override
39
    public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException {
40
        return new SvgPanel(doc);
41
    }
42

  
43
    @Override
44
    public boolean hasPanel() {
45
        return true;
46
    }
47

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

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

  
25
import java.io.Serializable;
26
import java.net.URL;
27
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
28
import org.gvsig.hyperlink.app.extension.LinkTarget;
29
import org.gvsig.tools.swing.api.ToolsSwingLocator;
30
import org.gvsig.tools.swing.api.ToolsSwingUtils;
31
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
32
import org.gvsig.tools.util.ToolsUtilLocator;
33
import org.gvsig.webbrowser.WebBrowserPanel;
34
import org.gvsig.webbrowser.WebBrowserManager;
35

  
36
@SuppressWarnings("UseSpecificCatch")
37
public class TxtFormat extends AbstractActionManager implements Serializable {
38

  
39
    public static final String ACTION_CODE = "Txt_format";
40

  
41

  
42
    public TxtFormat() {
43
        super(ACTION_CODE,"HTML_and_text_formats","Shows_HTML_or_text_files_in_gvSIG");
44
    }
45

  
46
    @Override
47
    public void showDocument(LinkTarget document) {
48
        String title = "";
49
        URL url = document.getURL();
50
        try {
51
            url = url.toURI().normalize().toURL();
52
            title = url.toString();
53
            WebBrowserManager manager = ToolsUtilLocator.getWebBrowserManager();
54
            WebBrowserPanel viewer = manager.createWebBrowserPanel();     
55
            viewer.setPage(url);
56
            ToolsSwingUtils.ensureRowsCols(viewer.asJComponent(), 20, 100, 40, 150);
57
            WindowManager windowManager = ToolsSwingLocator.getWindowManager();
58
            windowManager.showWindow(
59
                    viewer.asJComponent(),
60
                    "Hyperlink"+": "+title,
61
                    WindowManager.MODE.WINDOW
62
            );
63
        } catch (Exception ex) {
64
            LOGGER.warn("Can't show text/html document url="+url, ex);
65
        }
66
    }
67

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

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

  
25
import java.io.Serializable;
26
import java.net.URI;
27
import java.net.URISyntaxException;
28
import org.gvsig.desktopopen.DesktopOpen;
29

  
30
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
31
import org.gvsig.hyperlink.app.extension.LinkTarget;
32
import org.gvsig.tools.util.ToolsUtilLocator;
33

  
34
public class ExternTxtFormat extends AbstractActionManager implements Serializable {
35

  
36
    public static final String ACTION_CODE = "TxtExtern_format";
37
            
38
    public ExternTxtFormat() {
39
        super(ACTION_CODE,"HTML_and_text_formats_in_system_application","Shows_HTML_or_text_files_in_system_application");
40
    }
41

  
42
    @Override
43
    public void showDocument(LinkTarget doc) {
44
        try {
45
            URI uri = doc.toURI();
46
            DesktopOpen desktop = ToolsUtilLocator.getToolsUtilManager().createDesktopOpen();
47
            desktop.browse(uri);
48
        } catch (Exception ex) {
49
            LOGGER.warn("Cant show document "+doc.getURL(),ex);
50
        }
51
    }
52
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.250/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/SvgPanel.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22

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

  
25
import java.awt.BorderLayout;
26
import java.awt.Dimension;
27
import java.awt.Graphics2D;
28
import java.awt.Image;
29
import java.awt.RenderingHints;
30
import java.awt.geom.AffineTransform;
31
import java.awt.geom.Rectangle2D;
32
import java.awt.image.BufferedImage;
33
import java.net.URI;
34
import java.net.URL;
35

  
36
import javax.swing.ImageIcon;
37
import javax.swing.JLabel;
38

  
39
import org.apache.batik.bridge.BridgeContext;
40
import org.apache.batik.bridge.DocumentLoader;
41
import org.apache.batik.bridge.GVTBuilder;
42
import org.apache.batik.bridge.UserAgentAdapter;
43
import org.apache.batik.bridge.ViewBox;
44
import org.apache.batik.gvt.GraphicsNode;
45
import org.apache.batik.gvt.renderer.StaticRenderer;
46
import org.w3c.dom.Document;
47
import org.w3c.dom.Element;
48
import org.w3c.dom.svg.SVGDocument;
49

  
50
import org.gvsig.andami.PluginServices;
51
import org.gvsig.andami.messages.NotificationManager;
52
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
53
import org.gvsig.hyperlink.app.extension.LinkTarget;
54

  
55
/**
56
 * This class extends AbstractHyperLink, and provides suppot to open images of
57
 * many formats.
58
 * The common supported formats are JPG, ICO, BMP, TIFF, GIF and PNG. Implements
59
 * methods from
60
 * IExtensionBuilder to make it extending.
61
 * 
62
 * @author Eustaquio Vercher (IVER)
63
 * @author Cesar Martinez Izquierdo (IVER)
64
 */
65
public class SvgPanel extends AbstractHyperLinkPanel {
66

  
67
    private static final long serialVersionUID = -5200841105188251551L;
68
    private GVTBuilder gvtBuilder = new GVTBuilder();
69
    private GraphicsNode gvtRoot = null;
70
    private BridgeContext ctx = null;
71
    private StaticRenderer renderer = new StaticRenderer();
72
    private Element elt;
73
    protected static RenderingHints defaultRenderingHints;
74
    static {
75
        defaultRenderingHints = new RenderingHints(null);
76
        defaultRenderingHints.put(RenderingHints.KEY_ANTIALIASING,
77
            RenderingHints.VALUE_ANTIALIAS_ON);
78

  
79
        defaultRenderingHints.put(RenderingHints.KEY_INTERPOLATION,
80
            RenderingHints.VALUE_INTERPOLATION_BILINEAR);
81
    }
82

  
83
    /**
84
     * Default constructor.
85
     */
86
    public SvgPanel(LinkTarget doc) {
87
        super(doc);
88
        initialize();
89
    }
90

  
91
    /**
92
     * Initializes this panel.
93
     */
94
    void initialize() {
95
        this.setLayout(new BorderLayout());
96
        showDocument();
97
        // this.setSize(600, 400);
98
    }
99

  
100
    /**
101
     * Implements the necessary code to open images in this panel.
102
     */
103
    protected void showDocument() {
104
        if (!checkAndNormalizeURI()) {
105
            return;
106
        }
107

  
108
        ImageIcon image;
109
        // try {
110
        image = new ImageIcon(getSvgAsImage(document.getURL()));
111

  
112
        if (image == null)
113
            ; // Incluir error
114
        this.setPreferredSize(new Dimension(image.getIconWidth(),
115
            image.getIconHeight()));
116
        this.setSize(new Dimension(image.getIconWidth(), image.getIconHeight()));
117
        JLabel label = new JLabel(image);
118
        this.add(label);
119

  
120
        // } catch (MalformedURLException e) {
121
        //
122
        // }
123
    }
124

  
125
    /**
126
     * Allows paint SVG images in the panel.
127
     * 
128
     * @param file
129
     *            , this file has been extracted from the URI
130
     */
131
    private Image getSvgAsImage(URL url) {
132
        BufferedImage img =
133
            new BufferedImage(400, 400, BufferedImage.TYPE_INT_ARGB);
134
        Graphics2D g = img.createGraphics();
135
        Rectangle2D rect = new Rectangle2D.Double();
136
        rect.setFrame(0, 0, 400, 400);
137
        obtainStaticRenderer(url);
138
        drawSVG(g, rect, null);
139
        return img;
140
    }
141

  
142
    /**
143
     * Render the image to add to the panel.
144
     * 
145
     * @param file
146
     *            , this file has been extracted from the URI
147
     */
148
    private void obtainStaticRenderer(URL url) {
149
        try {
150
            UserAgentAdapter userAgent = new UserAgentAdapter();
151
            DocumentLoader loader = new DocumentLoader(userAgent);
152
            ctx = new BridgeContext(userAgent, loader);
153
            // Document svgDoc = loader.loadDocument(file.toURI().toString());
154
            Document svgDoc = loader.loadDocument(url.toString());
155
            gvtRoot = gvtBuilder.build(ctx, svgDoc);
156
            renderer.setTree(gvtRoot);
157
            elt = ((SVGDocument) svgDoc).getRootElement();
158
        } catch (Exception ex) {
159
            NotificationManager.addWarning(PluginServices.getText(this,
160
                "Hyperlink_linked_field_doesnot_exist"), ex);
161
        }
162
    }
163

  
164
    /**
165
     * Draw SVG in the Graphics that receives like parameter.
166
     * 
167
     * @param g
168
     *            Graphics
169
     * @param rect
170
     *            Rectangle that fills the Graphic.
171
     * @param rv
172
     *            Rectangle. This forms the visible part in the Layout
173
     */
174
    private void drawSVG(Graphics2D g, Rectangle2D rect, Rectangle2D rv) {
175
        if ((rv == null) || rv.contains(rect)) {
176
            AffineTransform ataux = new AffineTransform();
177

  
178
            ataux.translate(rect.getX(), rect.getY());
179
            try {
180
                ataux.concatenate(ViewBox.getViewTransform(null,
181
                    elt,
182
                    (float) rect.getWidth(),
183
                    (float) rect.getHeight(),
184
                    ctx));
185
                gvtRoot.setTransform(ataux);
186

  
187
            } catch (Exception e) {
188
                // TODO: handle exception
189
            }
190
        } else {
191
            AffineTransform ataux = new AffineTransform();
192

  
193
            ataux.translate(rect.getX(), rect.getY());
194
            ataux.concatenate(ViewBox.getViewTransform(null,
195
                elt,
196
                (float) rect.getWidth(),
197
                (float) rect.getHeight(),
198
                ctx));
199

  
200
            gvtRoot.setTransform(ataux);
201
        }
202

  
203
        RenderingHints renderingHints = defaultRenderingHints;
204
        g.setRenderingHints(renderingHints);
205

  
206
        if (gvtRoot != null) {
207
            gvtRoot.paint(g);
208
        }
209
    }
210

  
211
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.250/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/PdfFormat.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.IOException;
26
import java.io.Serializable;
27
import java.util.logging.Level;
28
import java.util.logging.Logger;
29

  
30
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
31
import org.gvsig.hyperlink.app.extension.LinkTarget;
32
import org.gvsig.pdf.lib.api.PDFDocument;
33
import org.gvsig.pdf.lib.api.PDFLocator;
34
import org.gvsig.pdf.swing.api.PDFSwingLocator;
35
import org.gvsig.pdf.swing.api.PDFViewer;
36
import org.gvsig.tools.swing.api.ToolsSwingLocator;
37
import org.gvsig.tools.swing.api.ToolsSwingUtils;
38
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
39

  
40
public class PdfFormat extends AbstractActionManager implements Serializable {
41

  
42
    public static final String ACTION_CODE = "PDF_format";
43

  
44
    public PdfFormat() {
45
        super(ACTION_CODE, "PDF_format", "Shows_PDF_files_in_gvSIG");
46
    }
47
    
48
    @Override
49
    public void showDocument(LinkTarget document) {
50
        try {
51
            PDFDocument pdfdoc = PDFLocator.getPDFManager().createPDFDocument();
52
            String title = "PDF";
53
            if (document.getURL() != null) {
54
                title = document.getURL().toString();
55
                pdfdoc.setSource(document.getURL());
56
            } else if (document.getFromProfile() != null) {
57
                try {
58
                    Object profileContent = document.getFromProfile();
59
                    if (!(profileContent instanceof PDFDocument)) {
60
                        LOGGER.warn("Not able to convert content from field into pdf");
61
                    }
62
                    pdfdoc = (PDFDocument) profileContent;
63
                } catch (Exception ex)  {
64
                    LOGGER.warn("Not able to get PDF from document");
65
                }
66
            }
67
            PDFViewer viewer = PDFSwingLocator.getPDFSwingManager().createPDFViewer();
68
            viewer.put(pdfdoc);
69
            ToolsSwingUtils.ensureRowsCols(viewer.asJComponent(), 20, 100, 40, 150);
70
            WindowManager windowManager = ToolsSwingLocator.getWindowManager();
71
            windowManager.showWindow(
72
                    viewer.asJComponent(),
73
                    "Hyperlink"+": "+title,
74
                    WindowManager.MODE.WINDOW
75
            );
76
        } catch (IOException ex) {
77
            Logger.getLogger(PdfFormat.class.getName()).log(Level.SEVERE, null, ex);
78
        }
79
    }
80

  
81
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.250/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/HyperlinkExtension.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.util.Map;
25

  
26
import org.slf4j.Logger;
27
import org.slf4j.LoggerFactory;
28
import org.gvsig.andami.IconThemeHelper;
29
import org.gvsig.andami.PluginServices;
30
import org.gvsig.andami.plugins.Extension;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.documents.view.ViewDocument;
33
import org.gvsig.app.project.documents.view.gui.IView;
34
import org.gvsig.app.project.documents.view.legend.gui.ThemeManagerWindow;
35
import org.gvsig.fmap.mapcontext.MapContext;
36
import org.gvsig.fmap.mapcontext.layers.FLayer;
37
import org.gvsig.fmap.mapcontext.layers.FLayers;
38
import org.gvsig.fmap.mapcontext.layers.LayersIterator;
39
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
40
import org.gvsig.fmap.mapcontrol.MapControl;
41
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
42
import org.gvsig.hyperlink.app.extension.actions.ExternTxtFormat;
43
import org.gvsig.hyperlink.app.extension.actions.FolderFormat;
44
import org.gvsig.hyperlink.app.extension.actions.ImgFormat;
45
import org.gvsig.hyperlink.app.extension.actions.PdfFormat;
46
import org.gvsig.hyperlink.app.extension.actions.SvgFormat;
47
import org.gvsig.hyperlink.app.extension.actions.TxtFormat;
48
import org.gvsig.hyperlink.app.extension.config.LayerLinkConfig;
49
import org.gvsig.hyperlink.app.extension.config.LinkConfig;
50
import org.gvsig.hyperlink.app.extension.config.gui.ConfigTab;
51
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry;
52
import org.gvsig.hyperlink.app.extension.layers.VectLayerManager;
53
import org.gvsig.tools.ToolsLocator;
54
import org.gvsig.tools.extensionpoint.ExtensionPoint;
55
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
56
import org.gvsig.tools.library.LibraryException;
57
import org.gvsig.tools.util.Caller;
58
import org.gvsig.tools.util.impl.DefaultCaller;
59

  
60
/**
61
 * Andami extension to show Hyperlink in the application.
62
 *
63
 * @author gvSIG Team
64
 * @version $Id$
65
 */
66
public class HyperlinkExtension extends Extension {
67

  
68
    private static final Logger LOG = LoggerFactory
69
        .getLogger(HyperlinkExtension.class);
70
    ManagerRegistry layerManager;
71
    public static final String LAYERPROPERTYNAME = "org.gvsig.hyperlink.config";
72
    public static final String TOOLNAME = "org.gvsig.hyperlink.tool";
73
    public static final String ACTIONSEXTENSIONPOINT = "HyperLinkAction";
74

  
75
    private static final int LEGACY_IMAGE_TYPE = 0;
76
    private static final int LEGACY_HTML_TYPE = 1;
77
    private static final int LEGACY_PDF_TYPE = 2;
78
    private static final int LEGACY_SVG_TYPE = 3;
79

  
80
    /**
81
     * @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
82
     */
83
    public void execute(String s) {
84
        IView view = (IView) PluginServices.getMDIManager().getActiveWindow();
85
        MapControl mapCtrl = view.getMapControl();
86
        LOG.debug("Comand : " + s);
87

  
88
        if (s.compareTo("view-show-hyperlink") == 0) {
89
            initTool(view);
90
            mapCtrl.setTool(TOOLNAME);
91
        }
92
    }
93

  
94
    /**
95
     * Inits the tool for the provided view.
96
     *
97
     * @param view
98
     */
99
    public void initTool(IView view) {
100
        MapControl mapCtrl = view.getMapControl();
101
        if (view.getMapControl().getNamesMapTools().get(TOOLNAME) == null) {
102
            mapCtrl.addBehavior(TOOLNAME,
103
                new PointBehavior(new LinkListener(mapCtrl, layerManager)));
104
            loadLegacyConfig(view);
105
        }
106
    }
107

  
108
    public void loadLegacyConfig(IView view) {
109
        LayersIterator iterator =
110
            new LayersIterator(view.getMapControl().getMapContext().getLayers());
111
        while (iterator.hasNext()) {
112
            FLayer layer = iterator.nextLayer();
113
            loadLegacyConfig(layer);
114
        }
115
    }
116

  
117
    /**
118
     * Returns a LayerLinkConfig object if an old-style or new-style hyperlink
119
     * was found and configured,
120
     * or null otherwise.
121
     *
122
     * @param layer
123
     */
124
    public LayerLinkConfig loadLegacyConfig(FLayer layer) {
125
        LayerLinkConfig layerConfig =
126
            (LayerLinkConfig) layer.getProperty(LAYERPROPERTYNAME);
127
        if (layerConfig != null) { // don't apply compatibility if the layer
128
                                   // already has new 1.9.0 configuration
129
            return layerConfig;
130
        }
131
        Object fName = layer.getProperty("legacy.hyperlink.selectedField");
132
        if (fName != null && fName instanceof String) {
133
            Map properties = layer.getExtendedProperties();
134
            properties.remove("legacy.hyperlink.selectedField");
135
            // remove it from layer to don't keep legacy properties for ever
136
            // in the project
137

  
138
            String fieldName = (String) fName;
139
            Object extObj = layer.getProperty("legacy.hyperlink.extension");
140
            String extension = null;
141
            if (extObj != null && extObj instanceof String) {
142
                properties.remove("legacy.hyperlink.extension");
143
                // remove it from layer to don't keep legacy properties for ever
144
                // in the project
145
                extension = (String) extObj;
146
            }
147
            Object typeObj = layer.getProperty("legacy.hyperlink.type");
148
            int type = -1;
149
            if (typeObj != null && typeObj instanceof Integer) {
150
                properties.remove("legacy.hyperlink.type");
151
                // remove it from layer to don't keep legacy properties for ever
152
                // in the project
153
                type = ((Integer) typeObj).intValue();
154
            }
155
            LayerLinkConfig config = new LayerLinkConfig();
156
            config.setEnabled(true);
157
            config.addLink(getLegacyActionCode(type), fieldName, extension);
158
            layer.setProperty(LAYERPROPERTYNAME, config);
159
            return config;
160
        }
161
        return null;
162
    }
163

  
164
    private String getLegacyActionCode(int type) {
165
        switch (type) {
166
        case LEGACY_IMAGE_TYPE:
167
            return ImgFormat.ACTION_CODE;
168
        case LEGACY_PDF_TYPE:
169
            return PdfFormat.ACTION_CODE;
170
        case LEGACY_SVG_TYPE:
171
            return SvgFormat.ACTION_CODE;
172
        case LEGACY_HTML_TYPE:
173
        default:
174
            return TxtFormat.ACTION_CODE;
175
        }
176
    }
177

  
178
    /**
179
     * @see com.iver.mdiApp.plugins.IExtension#isVisible()
180
     */
181
    public boolean isVisible() {
182
        IWindow f = PluginServices.getMDIManager().getActiveWindow();
183

  
184
        if (f == null) {
185
            return false;
186
        }
187

  
188
        if (f instanceof IView) {
189

  
190
            MapContext mapa = ((IView) f).getViewDocument().getMapContext();
191

  
192
            return mapa.getLayers().getLayersCount() > 0;
193
        } else {
194
            return false;
195
        }
196
    }
197

  
198
    /**
199
     * @see com.iver.andami.plugins.IExtension#isEnabled()
200
     */
201
    public boolean isEnabled() {
202
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
203

  
204
        if (window == null) {
205
            return false;
206
        }
207

  
208
        if (window instanceof IView) {
209
            IView view = (IView) window;
210
            ViewDocument viewDocument = view.getViewDocument();
211

  
212
            if (viewDocument != null
213
                && viewDocument.getMapContext() != null
214
                && viewDocument.getMapContext().getLayers().getVisibles().length > 0) {
215
            	FLayers lyrs = viewDocument.getMapContext().getLayers();
216
            	FLayer[] lyrsSelected = lyrs.getActives();
217
            	for (int i = 0; i < lyrsSelected.length; i++) {
218
            		Object obj = lyrsSelected[i].getProperty(HyperlinkExtension.LAYERPROPERTYNAME);
219
					if(obj != null)
220
						return true;
221
				}
222
            }
223
        }
224
        return false;
225
    }
226

  
227
    public void postInitialize() {
228
        Caller caller = new DefaultCaller();
229

  
230
        caller.add(new LinkConfig.RegisterPersistence());
231
        caller.add(new LayerLinkConfig.RegisterPersistence());
232
        if( !caller.call() ) {
233
            throw new LibraryException(HyperlinkExtension.class, caller.getExceptions());
234
        }
235

  
236
        registerLayers();
237
        registerActions();
238
        registerConfigPanel();
239
    }
240

  
241
    private void registerLayers() {
242
        layerManager = new ManagerRegistry();
243
        layerManager.put(FLyrVect.class, VectLayerManager.class);
244
    }
245

  
246
    public ManagerRegistry getLayerManager() {
247
        return layerManager;
248
    }
249

  
250
    private void registerActions() {
251
        ExtensionPointManager epm = ToolsLocator.getExtensionPointManager();
252
        ExtensionPoint ep =
253
            epm.add(ACTIONSEXTENSIONPOINT,
254
                "Registers Actions that are able to manage specific format types.");
255

  
256
        ep.append(TxtFormat.ACTION_CODE, "", TxtFormat.class);
257
        ep.append(ExternTxtFormat.ACTION_CODE, "", ExternTxtFormat.class);
258
        ep.append(ImgFormat.ACTION_CODE, "", ImgFormat.class);
259
        ep.append(PdfFormat.ACTION_CODE, "", PdfFormat.class);
260
        ep.append(SvgFormat.ACTION_CODE, "", SvgFormat.class);
261
        ep.append(FolderFormat.ACTION_CODE, "", FolderFormat.class);
262

  
263
    }
264

  
265
    private void registerConfigPanel() {
266
        // pages
267
        ThemeManagerWindow.addPage(ConfigTab.class);
268

  
269
        ThemeManagerWindow.setTabEnabledForLayer(ConfigTab.class,
270
            FLyrVect.class,
271
            true);
272
    }
273

  
274
    public void initialize() {
275
        IconThemeHelper.registerIcon("action",
276
            "view-show-hyperlink", this);
277
        IconThemeHelper.registerIcon("cursor",
278
            "cursor-view-show-hyperlink", this);
279

  
280
    }
281

  
282
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.250/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/LinkListener.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.Cursor;
26
import java.awt.Image;
27
import java.awt.Point;
28
import java.awt.Toolkit;
29
import java.awt.geom.Point2D;
30
import java.net.URI;
31

  
32
import org.gvsig.andami.IconThemeHelper;
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.app.project.documents.view.toolListeners.InfoListener;
35
import org.gvsig.fmap.mapcontext.layers.FLayer;
36
import org.gvsig.fmap.mapcontrol.MapControl;
37
import org.gvsig.fmap.mapcontrol.tools.BehaviorException;
38
import org.gvsig.fmap.mapcontrol.tools.Events.PointEvent;
39
import org.gvsig.fmap.mapcontrol.tools.Listeners.PointListener;
40
import org.gvsig.hyperlink.app.extension.config.LayerLinkConfig;
41
import org.gvsig.hyperlink.app.extension.config.LinkConfig;
42
import org.gvsig.hyperlink.app.extension.layers.ILinkLayerManager;
43
import org.gvsig.hyperlink.app.extension.layers.IncompatibleLayerException;
44
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry;
45
import org.gvsig.tools.ToolsLocator;
46
import org.gvsig.tools.extensionpoint.ExtensionPoint;
47
import org.slf4j.Logger;
48
import org.slf4j.LoggerFactory;
49

  
50
/**
51
 * Listener that implements PointListener to show the information of the
52
 * HyperLink of the layer,
53
 * if the actual layer allows it. When the user selects the tool and make one
54
 * clic with
55
 * the mouse throws an event to create Panels with the information of the
56
 * associated HyperLink
57
 * to the layer. Creates one panel for URI provided, to load the information.
58
 * 
59
 * @author Vicente Caballero Navarro
60
 * @author Cesar Martinez Izqueirdo
61
 * 
62
 */
63
public class LinkListener implements PointListener {
64

  
65
    private static Logger logger = LoggerFactory.getLogger(InfoListener.class);
66
    private Cursor cur = null;
67
    private MapControl mapCtrl;
68
    private ManagerRegistry registry;
69
//    private Image imageCursor = null;
70
    public static final int TYPELINKIMAGE = 0;
71
    public static final int TYPELINKTEXT = 1;
72
    public ExtensionPoint formatManagers;
73

  
74
    /**
75
     * Creates a new LinkListener
76
     * 
77
     * @param mc
78
     *            mapControl
79
     */
80
    public LinkListener(MapControl mc, ManagerRegistry registry) {
81
        this.mapCtrl = mc;
82
        this.registry = registry;
83
        formatManagers =
84
            ToolsLocator.getExtensionPointManager()
85
                .get(HyperlinkExtension.ACTIONSEXTENSIONPOINT);
86
        initialize();
87
    }
88

  
89
    private void initialize() {
90
        cur = Toolkit.getDefaultToolkit().createCustomCursor(this.getImageCursor(),
91
                    new Point(16, 16),
92
                    "Hyperlink");
93
    }
94

  
95
    /**
96
     * Creates one LinkPanel for URI provided. Gets the active layers and
97
     * invokes getLink
98
     * with the catched point and the allowed tolerance if these layers allows
99
     * HyperLinks.
100
     * getLink provides an array of URIs, this method is invoked for all active
101
     * layers.
102
     * 
103
     * @param event
104
     *            PointEvent
105
     * @throws BehaviorException
106
     * 
107
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
108
     */
109
    @Override
110
    public void point(PointEvent event) throws BehaviorException {
111
        Point2D pReal =
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff