Revision 431

View differences:

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

  
3
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.hyperlink.app</artifactId>
6
	<packaging>pom</packaging>
7
	<version>1.0.81</version>
8
	<name>${project.artifactId}</name>
9
	<description>View. Hyperlink support</description>
10
	
11
    <parent>
12
        <groupId>org.gvsig</groupId>
13
        <artifactId>org.gvsig.desktop</artifactId>
14
        <version>2.0.247</version>
15
    </parent>
16
        
17
	<url>https://devel.gvsig.org/redmine/projects/gvsig-hyperlink</url>
18
	
19
    <scm>
20
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.81</connection>
21
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.81</developerConnection>
22
        <url>scm:svn:https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.81</url>
23
    </scm>
24
    
25
	<build>
26
        <plugins>
27
		    <plugin>
28
		      <artifactId>maven-release-plugin</artifactId>
29
		      <configuration>
30
		        <tagBase>https://devel.gvsig.org/svn/gvsig-hyperlink/org.gvsig.hyperlink.app/tags</tagBase>
31
		      </configuration>
32
		    </plugin>			
33
     
34
        </plugins>   
35
    </build>
36
    
37
	<developers>
38
		<developer>
39
			<id>jjdelcerro</id>
40
			<name>Joaqu?n Jos? del Cerro</name>
41
			<email>jjdelcerro@gvsig.org</email>
42
			<roles>
43
				<role>Architect</role>
44
				<role>Developer</role>
45
			</roles>
46
		</developer>
47
		<developer>
48
			<id>cordinyana</id>
49
			<name>C?sar Ordi?ana</name>
50
			<email>cordinyana@gvsig.com</email>
51
			<roles>
52
				<role>Architect</role>
53
				<role>Developer</role>
54
			</roles>
55
		</developer>
56
	</developers>
57
	<distributionManagement>
58
		<site>
59
			<id>gvsig-repository</id>
60
            <url>dav:https://devel.gvsig.org/sites/org.gvsig.hyperlink.app/${project.version}</url>
61
		</site>
62
	</distributionManagement>
63
	<repositories>
64
		<repository>
65
			<id>gvsig-public-http-repository</id>
66
			<name>gvSIG maven public HTTP repository</name>
67
			<url>http://devel.gvsig.org/m2repo/j2se</url>
68
			<releases>
69
				<enabled>true</enabled>
70
				<updatePolicy>daily</updatePolicy>
71
				<checksumPolicy>warn</checksumPolicy>
72
			</releases>
73
			<snapshots>
74
				<enabled>true</enabled>
75
				<updatePolicy>daily</updatePolicy>
76
				<checksumPolicy>warn</checksumPolicy>
77
			</snapshots>
78
		</repository>
79
	</repositories>
80
	<modules>
81
		<module>org.gvsig.hyperlink.app.extension</module>
82
	</modules>
83
</project>
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.81/org.gvsig.hyperlink.app.extension/buildNumber.properties
1
#Sat Oct 05 18:41:39 CEST 2019
2
buildNumber=2168
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.81/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.81/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.81/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.81/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/actions/DesktopApi.java
1
package org.gvsig.hyperlink.app.extension.actions;
2

  
3
/*
4
 * Based on portions of code of MightyPork, http://www.ondrovo.com/
5
 * extracted from :
6
 * http://stackoverflow.com/questions/18004150/desktop-api-is-not-supported-on-the-current-platform
7
 */
8

  
9
import java.awt.Desktop;
10
import java.io.File;
11
import java.io.IOException;
12
import java.net.URL;
13
import java.util.ArrayList;
14
import java.util.List;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

  
18
public class DesktopApi {
19

  
20
    private static Logger logger = LoggerFactory.getLogger(DesktopApi.class);
21

  
22
    public static boolean browse(URL uri) {
23

  
24
        if ( browseDESKTOP(uri) ) {
25
            return true;
26
        }
27

  
28
        if ( openSystemSpecific(uri.toString()) ) {
29
            return true;
30
        }
31

  
32
        return false;
33
    }
34

  
35
    public static boolean open(File file) {
36

  
37
        if ( openDESKTOP(file) ) {
38
            return true;
39
        }
40

  
41
        if ( openSystemSpecific(file.getPath()) ) {
42
            return true;
43
        }
44

  
45
        return false;
46
    }
47

  
48
    public static boolean edit(File file) {
49

  
50
        if ( editDESKTOP(file) ) {
51
            return true;
52
        }
53

  
54
        if ( openSystemSpecific(file.getPath()) ) {
55
            return true;
56
        }
57

  
58
        return false;
59
    }
60

  
61
    private static boolean openSystemSpecific(String what) {
62

  
63
        EnumOS os = getOs();
64

  
65
        if (os.isLinux()) {
66
//            if (runCommand("gnome-open", "%s", what)) {
67
//                return true;
68
//            }
69
//            if (runCommand("kde-open", "%s", what)) {
70
//                return true;
71
//            }
72
            if (runCommand("xdg-open", "%s", what)) {
73
                return true;
74
            }
75
        }
76

  
77
        if ( os.isMac() ) {
78
            if ( runCommand("open", "%s", what) ) {
79
                return true;
80
            }
81
        }
82

  
83
        if ( os.isWindows() ) {
84
            if ( runCommand("explorer", "%s", what) ) {
85
                return true;
86
            }
87
        }
88

  
89
        return false;
90
    }
91

  
92
    private static boolean browseDESKTOP(URL uri) {
93

  
94
        logOut("Trying to use Desktop.getDesktop().browse() with " + uri.toString());
95
        try {
96
            if ( !Desktop.isDesktopSupported() ) {
97
                logErr("Platform is not supported.");
98
                return false;
99
            }
100

  
101
            if ( !Desktop.getDesktop().isSupported(Desktop.Action.BROWSE) ) {
102
                logErr("BROWSE is not supported.");
103
                return false;
104
            }
105

  
106
            Desktop.getDesktop().browse(uri.toURI());
107

  
108
            return true;
109
        } catch (Throwable t) {
110
            logErr("Error using desktop browse.", t);
111
            return false;
112
        }
113
    }
114

  
115
    private static boolean openDESKTOP(File file) {
116

  
117
        logOut("Trying to use Desktop.getDesktop().open() with " + file.toString());
118
        try {
119
            if ( !Desktop.isDesktopSupported() ) {
120
                logErr("Platform is not supported.");
121
                return false;
122
            }
123

  
124
            if ( !Desktop.getDesktop().isSupported(Desktop.Action.OPEN) ) {
125
                logErr("OPEN is not supported.");
126
                return false;
127
            }
128

  
129
            Desktop.getDesktop().open(file);
130

  
131
            return true;
132
        } catch (Throwable t) {
133
            logErr("Error using desktop open.", t);
134
            return false;
135
        }
136
    }
137

  
138
    private static boolean editDESKTOP(File file) {
139

  
140
        logOut("Trying to use Desktop.getDesktop().edit() with " + file);
141
        try {
142
            if ( !Desktop.isDesktopSupported() ) {
143
                logErr("Platform is not supported.");
144
                return false;
145
            }
146

  
147
            if ( !Desktop.getDesktop().isSupported(Desktop.Action.EDIT) ) {
148
                logErr("EDIT is not supported.");
149
                return false;
150
            }
151

  
152
            Desktop.getDesktop().edit(file);
153

  
154
            return true;
155
        } catch (Throwable t) {
156
            logErr("Error using desktop edit.", t);
157
            return false;
158
        }
159
    }
160

  
161
    private static boolean runCommand(String command, String args, String file) {
162

  
163
        logOut("Trying to exec:\n   cmd = " + command + "\n   args = " + args + "\n   %s = " + file);
164

  
165
        String[] parts = prepareCommand(command, args, file);
166

  
167
        try {
168
            Process p = Runtime.getRuntime().exec(parts);
169
            if ( p == null ) {
170
                return false;
171
            }
172

  
173
            try {
174
                int retval = p.exitValue();
175
                if ( retval == 0 ) {
176
                    logErr("Process ended immediately.");
177
                    return false;
178
                } else {
179
                    logErr("Process crashed.");
180
                    return false;
181
                }
182
            } catch (IllegalThreadStateException itse) {
183
                logErr("Process is running.");
184
                return true;
185
            }
186
        } catch (IOException e) {
187
            logErr("Error running command.", e);
188
            return false;
189
        }
190
    }
191

  
192
    private static String[] prepareCommand(String command, String args, String file) {
193

  
194
        List<String> parts = new ArrayList<String>();
195
        parts.add(command);
196

  
197
        if ( args != null ) {
198
            for ( String s : args.split(" ") ) {
199
                s = String.format(s, file); // put in the filename thing
200

  
201
                parts.add(s.trim());
202
            }
203
        }
204

  
205
        return parts.toArray(new String[parts.size()]);
206
    }
207

  
208
    private static void logErr(String msg, Throwable t) {
209
        logger.warn(msg,t);
210
    }
211

  
212
    private static void logErr(String msg) {
213
        logger.warn(msg);
214
    }
215

  
216
    private static void logOut(String msg) {
217
        logger.info(msg);
218
    }
219

  
220
    public static enum EnumOS {
221

  
222
        linux, macos, solaris, unknown, windows;
223

  
224
        public boolean isLinux() {
225

  
226
            return this == linux || this == solaris;
227
        }
228

  
229
        public boolean isMac() {
230

  
231
            return this == macos;
232
        }
233

  
234
        public boolean isWindows() {
235

  
236
            return this == windows;
237
        }
238
    }
239

  
240
    public static EnumOS getOs() {
241

  
242
        String s = System.getProperty("os.name").toLowerCase();
243

  
244
        if ( s.contains("win") ) {
245
            return EnumOS.windows;
246
        }
247

  
248
        if ( s.contains("mac") ) {
249
            return EnumOS.macos;
250
        }
251

  
252
        if ( s.contains("solaris") ) {
253
            return EnumOS.solaris;
254
        }
255

  
256
        if ( s.contains("sunos") ) {
257
            return EnumOS.solaris;
258
        }
259

  
260
        if ( s.contains("linux") ) {
261
            return EnumOS.linux;
262
        }
263

  
264
        if ( s.contains("unix") ) {
265
            return EnumOS.linux;
266
        } else {
267
            return EnumOS.unknown;
268
        }
269
    }
270
}
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.81/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.awt.Desktop;
27
import java.io.File;
28
import java.io.IOException;
29
import java.io.Serializable;
30
import java.net.URI;
31
import javax.swing.JOptionPane;
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
34
import org.gvsig.hyperlink.app.extension.AbstractHyperLinkPanel;
35
import org.gvsig.hyperlink.app.extension.LinkTarget;
36
import org.slf4j.Logger;
37
import org.slf4j.LoggerFactory;
38

  
39
public class FolderFormat extends AbstractActionManager implements Serializable {
40

  
41
    /**
42
     *
43
     */
44
    private static final long serialVersionUID = 1L;
45
    public static final String actionCode = "Folder_format";
46
    private static Logger logger = LoggerFactory.getLogger(FolderFormat.class);
47

  
48
    public String getActionCode() {
49
        return actionCode;
50
    }
51

  
52
    public boolean hasPanel() {
53
        return false;
54
    }
55

  
56
    public void showDocument(LinkTarget doc) {
57
        File folder = new File(doc.getURL().getPath());
58
        if ( folder.exists() ) {
59
               DesktopApi.browse(doc.getURL());
60
//               DesktopApi.open(folder);
61
//             Desktop desktop = Desktop.getDesktop();
62
//             try {
63
//                desktop.open(folder);
64
//            } catch (IOException e1) {
65
//                logger.error("Can't open folder '" + folder.getAbsolutePath() + "'.", e1);
66
//            }
67

  
68
        } else {
69
            JOptionPane.showMessageDialog(null, PluginServices.getText(this, "Bad_path") + " : " + folder.getAbsolutePath());
70
        }
71
    }
72

  
73
    public String getDescription() {
74
        return PluginServices.getText(this, "Shows_Folders_in_gvSIG");
75
    }
76

  
77
    public String getName() {
78
        return PluginServices.getText(this, "Folder_formats");
79
    }
80

  
81
    public AbstractHyperLinkPanel createPanel(LinkTarget doc)
82
            throws UnsupportedOperationException {
83
        return null;
84
    }
85

  
86
}
87

  
org.gvsig.hyperlink.app/tags/org.gvsig.hyperlink.app-1.0.81/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.io.Serializable;
28
import java.net.URI;
29

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

  
35
public class ImgFormat extends AbstractActionManager implements Serializable {
36

  
37
    /**
38
     *
39
     */
40
    private static final long serialVersionUID = -7625497033974714867L;
41
    public static final String actionCode = "Image_format";
42

  
43
    @Override
44
    public AbstractHyperLinkPanel createPanel(LinkTarget doc) throws UnsupportedOperationException {
45
        return new ImgPanel(doc);
46
    }
47

  
48
    @Override
49
    public String getActionCode() {
50
        return actionCode;
51
    }
52

  
53
    @Override
54
    public boolean hasPanel() {
55
        return true;
56
    }
57

  
58
    @Override
59
    public void showDocument(LinkTarget doc) {
60
        throw new UnsupportedOperationException();
61
    }
62

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

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

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

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

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

  
33
public class SvgFormat extends AbstractActionManager implements Serializable {
34

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

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

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

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

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

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

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

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

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

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

  
33
public class TxtFormat extends AbstractActionManager implements Serializable {
34

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
33
public class ExternTxtFormat extends AbstractActionManager implements Serializable {
34

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  
94
    private void initialize() {
95

  
96
        pf = new PdfDecoder();
97

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

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

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

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

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

  
151
    private void initializeViewer() {
152

  
153
        Container cPane = this;
154
        cPane.setLayout(new BorderLayout());
155

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

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

  
167
        cPane.add(topBar, BorderLayout.NORTH);
168

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

  
173
        // pack();
174

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

  
183
    private Component[] initChangerPanel() {
184

  
185
        Component[] list = new Component[12];
186

  
187
        /** back to page 1 */
188
        JButton start = new JButton();
189
        start.setBorderPainted(false);
190
        start.setIcon( IconThemeHelper.getImageIcon("go-first"));      
191
        start.setToolTipText(PluginServices.getText(this, "primera_pagina"));
192
        // currentBar1.add(start);
193
        list[0] = start;
194
        start.addActionListener(new ActionListener() {
195

  
196
            public void actionPerformed(ActionEvent e) {
197
                if (pf != null && currentPage != 1) {
198
                    currentPage = 1;
199
                    try {
200
                        pf.decodePage(currentPage);
201
                        pf.invalidate();
202
                        repaint();
203
                    } catch (Exception e1) {
204
                        System.err.println("back to page 1");
205
                        e1.printStackTrace();
206
                    }
207

  
208
                    // set page number display
209
                    pageCounter2.setText(currentPage + "");
210
                }
211
            }
212
        });
213

  
214
        /** back 10 icon */
215
        JButton fback = new JButton();
216
        fback.setBorderPainted(false);
217
        fback.setIcon( IconThemeHelper.getImageIcon("go-previous-fast"));
218
        fback.setToolTipText(PluginServices.getText(this, "diez_paginas_atras"));
219
        // currentBar1.add(fback);
220
        list[1] = fback;
221
        fback.addActionListener(new ActionListener() {
222

  
223
            public void actionPerformed(ActionEvent e) {
224
                if (pf != null && currentPage > 10) {
225
                    currentPage -= 10;
226
                    try {
227
                        pf.decodePage(currentPage);
228
                        pf.invalidate();
229
                        repaint();
230
                    } catch (Exception e1) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff