Revision 37478

View differences:

tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/prepare-workspace.xml
1
<project name="org.gvsig.initial.build" default="prepare-workspace">
2
	
3
	<dirname property="org.gvsig.initial.build.basedir" file="${ant.file.org.gvsig.initial.build}"/>
4
	
5
	<property name="workspace.basedir" 
6
			  value="${org.gvsig.initial.build.basedir}/.."/>
7
	<property name="build.basedir" 
8
		      value="${workspace.basedir}/org.gvsig.maven.base.build"
9
		      description="Eclipse workspace location"/>
10
	<property name="build.jar.version" 
11
			 	  value="1.0.6-SNAPSHOT" />
12
	<property name="build.jar.file" 
13
		 	  value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
14
	
15
	<target name="check-maven-base-build-available">
16
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" 
17
				   property="maven-base-build-available"/>
18
	</target>
19
	
20
	<target name="get-maven-base-build-local" 
21
			depends="check-maven-base-build-available"
22
			if="maven-base-build-available">
23
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
24
		<unzip src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}"
25
		       dest="${workspace.basedir}">
26
		    <patternset>
27
		        <exclude name="META-INF/**"/>
28
		    </patternset>
29
		</unzip>	
30
	</target>
31
	
32
	<target name="get-maven-base-build-remote" 
33
			depends="check-maven-base-build-available"
34
			unless="maven-base-build-available">
35
		<!-- Download the build jar file -->
36
		<get src="http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" 
37
			 dest="target/${build.jar.file}"
38
			 verbose="true"/>
39
		
40
		<!-- Unzip de build jar file into the workspace root folder -->
41
		<unzip src="target/${build.jar.file}"
42
		       dest="${workspace.basedir}">
43
		    <patternset>
44
		        <exclude name="META-INF/**"/>
45
		    </patternset>
46
		</unzip>	
47
	</target>
48
	
49
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote">
50
		
51
		<mkdir dir="target"/>
52
	
53
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug"/>
54
		
55
		<!-- Copy the maven launchers to the workspace metadata folder -->
56
		<copy todir="${workspace.basedir}/.metadata">
57
		    <fileset dir="${build.basedir}/eclipse-launchers"/>
58
		</copy>
59
		
60
		<!-- Configure the eclipse workspace -->
61
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace"/>
62

  
63
		<!-- Configure the gvSIG profile -->
64
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" target="initialize"/>
65

  
66
		<!-- Compile, install and generate eclipse projects -->
67
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse"/>
68
		
69
		<echo>INFORMATION!!!</echo>
70
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
71
		
72
		<!-- TODO: copiar al proyecto de configuraciĆ³n general -->
73
	</target>
74
 	
75
	<target name="clean">
76
		<delete dir="target"/>
77
	</target>
78

  
79
</project>
0 80

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/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"
4
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5
	<modelVersion>4.0.0</modelVersion>
6
	<artifactId>org.gvsig.hyperlink.app</artifactId>
7
	<packaging>pom</packaging>
8
	<version>1.0.0-SNAPSHOT</version>
9
	<name>org.gvsig.hyperlink.app</name>
10
	<description>View. Hyperlink support</description>
11
	<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.hyperlink/${project.version}/basic/org.gvsig.hyperlink.app</url>
12
    <parent>
13
        <groupId>org.gvsig</groupId>
14
        <artifactId>org.gvsig.maven.base.extension.pom</artifactId>
15
        <version>1.0.8-SNAPSHOT</version>
16
    </parent>
17

  
18
	<scm>
19
		<connection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-hyperlink/org.gvsig.hyperlink/extension/trunk</connection>
20
		<developerConnection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-hyperlink/org.gvsig.hyperlink/extension/trunk</developerConnection>
21
		<url>https://forge.osor.eu/plugins/scmsvn/viewcvs.php/org.gvsig.hyperlink/extension/trunk/?root=gvsig-hyperlink</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>jbadia</id>
36
			<name>Jos? Bad?a</name>
37
			<email>badia_jos@gva.es</email>
38
			<roles>
39
				<role>Developer</role>
40
			</roles>
41
		</developer>
42
		<developer>
43
			<id>cordinyana</id>
44
			<name>C?sar Ordi?ana</name>
45
			<email>cordinyana@gvsig.com</email>
46
			<roles>
47
				<role>Architect</role>
48
				<role>Developer</role>
49
			</roles>
50
		</developer>
51
	</developers>
52

  
53
	<distributionManagement>
54
		<site>
55
			<id>gvsig-repository</id>
56
			<url>scp://shell.forge.osor.eu/home/groups/gvsig-desktop/www/downloads/pub/projects/gvSIG-desktop/docs/reference/org.gvsig.hyperlink/${project.version}/basic/org.gvsig.hyperlink.app</url>
57
		</site>
58
	</distributionManagement>
59
	<repositories>
60
		<repository>
61
			<id>gvsig-public-http-repository</id>
62
			<name>gvSIG maven public HTTP repository</name>
63
			<url>http://gvsig-desktop.forge.osor.eu/downloads/pub/projects/gvSIG-desktop/maven-repository</url>
64
			<releases>
65
				<enabled>true</enabled>
66
				<updatePolicy>daily</updatePolicy>
67
				<checksumPolicy>warn</checksumPolicy>
68
			</releases>
69
			<snapshots>
70
				<enabled>true</enabled>
71
				<updatePolicy>daily</updatePolicy>
72
				<checksumPolicy>warn</checksumPolicy>
73
			</snapshots>
74
		</repository>
75
	</repositories>
76
	<build>
77
		<plugins>
78
			<plugin>
79
				<groupId>org.apache.maven.plugins</groupId>
80
				<artifactId>maven-release-plugin</artifactId>
81
				<configuration>
82
					<tagBase>https://svn.forge.osor.eu/svn/gvsig-hyperlink/org.gvsig.hyperlink/extension/tags</tagBase>
83
				</configuration>
84
			</plugin>
85
		</plugins>
86
	</build>
87
    <dependencyManagement>
88
        <dependencies>          
89
            <dependency>
90
                <groupId>org.gvsig</groupId>
91
                <artifactId>org.gvsig.core.maven.dependencies</artifactId>
92
                <version>2.0.1-SNAPSHOT</version>
93
                <type>pom</type>
94
                <scope>import</scope>
95
            </dependency>
96
            <dependency>
97
                <groupId>org.gvsig</groupId>
98
                <artifactId>org.gvsig.fmap.dal.store.raster</artifactId>
99
                <version>2.0-SNAPSHOT</version>
100
                <scope>compile</scope>
101
            </dependency>
102
            <dependency>
103
                <groupId>org.gvsig</groupId>
104
                <artifactId>org.gvsig.app</artifactId>
105
                <version>2.0-SNAPSHOT</version>
106
                <scope>compile</scope>
107
            </dependency>
108
            <dependency>
109
                <groupId>org.gvsig</groupId>
110
                <artifactId>org.gvsig.dwg.extension</artifactId>
111
                <version>2.0-SNAPSHOT</version>
112
                <scope>compile</scope>
113
            </dependency>
114
		</dependencies>
115
	</dependencyManagement>
116

  
117
	<modules>
118
		<module>org.gvsig.hyperlink.app.extension</module>
119
	</modules>
120
	<properties>
121
		<package.info.state>alpha2</package.info.state>
122
	</properties>
123
</project>
0 124

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/README.txt
1
The first time you checkout the current project to a new workspace, 
2
you have to prepare it to be able to work easily with maven from
3
eclipse itself.
4

  
5
Perform the following steps:
6

  
7
1.- Launch the *prepare-workspace.xml* ant build file. 
8
    You can do it by loading the file into the ant view, 
9
    and running the default task, or right-clicking the 
10
    file from the package explorer or the navigator and
11
    select the option: *Run as > Ant build*. 
12
    
13
2.- Restart eclipse.
14

  
15
3.- Import the subprojects of the project you have just checked out.
16

  
17
Those steps are only needed once per workspace.     
18

  
0 19

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed Nov 23 09:49:28 CET 2011
3
buildNumber=2050
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/buildNumber.properties
1
#maven.buildNumber.plugin properties file
2
#Wed Nov 23 09:49:29 CET 2011
3
buildNumber=2042
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/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
import java.net.URL;
32

  
33
import javax.swing.ImageIcon;
34

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

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

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

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

  
91
    private void initialize() {
92
        URL url =
93
            PluginServices.getPluginServices(this)
94
                .getClassLoader()
95
                .getResource("images/LinkCursor.gif");
96
        if (url != null) {
97
            ImageIcon img = new ImageIcon(url);
98
            imageCursor = img.getImage();
99
            cur =
100
                Toolkit.getDefaultToolkit().createCustomCursor(imageCursor,
101
                    new Point(16, 16),
102
                    "Hyperlink");
103
        } else {
104
            PluginServices.getLogger()
105
                .error("Icon not found: images/LinkCursor.gif");
106
        }
107
    }
108

  
109
    /**
110
     * Creates one LinkPanel for URI provided. Gets the active layers and
111
     * invokes getLink
112
     * with the catched point and the allowed tolerance if these layers allows
113
     * HyperLinks.
114
     * getLink provides an array of URIs, this method is invoked for all active
115
     * layers.
116
     * 
117
     * @param event
118
     *            PointEvent
119
     * @throws BehaviorException
120
     * 
121
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.PointListener#point(com.iver.cit.gvsig.fmap.tools.Events.PointEvent)
122
     */
123
    public void point(PointEvent event) throws BehaviorException {
124
        Point2D pReal =
125
            mapCtrl.getMapContext().getViewPort().toMapPoint(event.getPoint());
126
        FLayer[] sel = mapCtrl.getMapContext().getLayers().getVisibles();
127

  
128
        URI[] links = null;
129
        LinkConfig linkConfig;
130
        ILinkLayerManager layerManager;
131
        ILinkActionManager actionManager;
132

  
133
        for (int layerCount = 0; layerCount < sel.length; layerCount++) {
134
            FLayer theLayer = sel[layerCount];
135
            if (!registry.hasManager(theLayer)) {
136
                continue;
137
            }
138
            try {
139
                layerManager = registry.get(theLayer);
140
                if (theLayer.getProperty(HyperlinkExtension.LAYERPROPERTYNAME) != null
141
                    && theLayer.getProperty(HyperlinkExtension.LAYERPROPERTYNAME) instanceof LayerLinkConfig) {
142
                    LayerLinkConfig layerLink =
143
                        (LayerLinkConfig) theLayer.getProperty(HyperlinkExtension.LAYERPROPERTYNAME);
144
                    if (layerLink.isEnabled() && layerLink.linkCount() > 0) { 
145
                        // there is
146
                                                                              // some
147
                                                                              // link
148
                                                                              // configured
149
                                                                              // for
150
                                                                              // this
151
                                                                              // layer
152

  
153
                        double tol = mapCtrl.getViewPort().toMapDistance(3);
154
                        for (int actionCount = 0; actionCount < layerLink.linkCount(); actionCount++) {
155
                            linkConfig = layerLink.getLink(actionCount);
156
                            links =
157
                                layerManager.getLink(pReal,
158
                                    tol,
159
                                    linkConfig.getFieldName(),
160
                                    linkConfig.getExtension());
161
                            for (int i = 0; i < links.length; i++) {
162
                                if (links[i] != null) {
163

  
164
                                    actionManager =
165
                                        (ILinkActionManager) formatManagers.get(linkConfig.getActionCode())
166
                                            .getExtension()
167
                                            .newInstance();
168
                                    if (actionManager == null) {
169
                                        logger.warn("Hyperlink error -- invalid action code: "
170
                                            + linkConfig.getActionCode());
171
                                        continue;
172
                                    }
173
                                    if (actionManager.hasPanel()) {
174
                                        ShowPanel lpanel =
175
                                            new ShowPanel(actionManager.createPanel(links[i]));
176
                                        // show the panel
177
                                        PluginServices.getMDIManager()
178
                                            .addWindow(lpanel);
179
                                    } else { // delegate in the format manager
180
                                             // to show the file
181
                                        actionManager.showDocument(links[i]);
182
                                    }
183
                                }
184
                            }
185
                        }
186
                    }
187
                }
188
            } catch (ClassNotFoundException e) {
189
                throw new BehaviorException("Hyperlink: There is no manager for this layer type",
190
                    e);
191
            } catch (InstantiationException e) {
192
                logger.error("Hyperlink error: " + e.getMessage(), e);
193
            } catch (IllegalAccessException e) {
194
                logger.error("Hyperlink error: " + e.getMessage(), e);
195
            } catch (IncompatibleLayerException e) {
196
                throw new BehaviorException("Hyperlink: There is no manager for this layer type",
197
                    e);
198
            }
199
        }
200
    }
201

  
202
    /**
203
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#getCursor()
204
     */
205
    public Cursor getCursor() {
206
        return cur;
207
    }
208

  
209
    /**
210
     * @see com.iver.cit.gvsig.fmap.tools.Listeners.ToolListener#cancelDrawing()
211
     */
212
    public boolean cancelDrawing() {
213
        return false;
214
    }
215

  
216
    public void pointDoubleClick(PointEvent event) throws BehaviorException {
217
        // TODO Auto-generated method stub
218

  
219
    }
220

  
221
    public Image getImageCursor() {
222
        return imageCursor;
223
    }
224
}
0 225

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/config/LayerLinkConfig.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.config;
24

  
25
import java.util.ArrayList;
26
import java.util.List;
27

  
28
import org.gvsig.tools.ToolsLocator;
29
import org.gvsig.tools.dynobject.DynStruct;
30
import org.gvsig.tools.persistence.PersistenceManager;
31
import org.gvsig.tools.persistence.Persistent;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34
import org.gvsig.tools.util.Callable;
35

  
36
public class LayerLinkConfig implements Persistent {
37

  
38
    protected List<LinkConfig> linkList;
39
    protected boolean enabled;
40
    public static final String LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME = "LayerLinkConfig";
41

  
42
    public LayerLinkConfig() {
43
        linkList = new ArrayList<LinkConfig>();
44
    }
45

  
46
    public void addLink(LinkConfig config) {
47
        linkList.add(config);
48
    }
49

  
50
    public void addLink(int position, LinkConfig config) {
51
        linkList.add(position, config);
52
    }
53

  
54
    public void addLink(String actionCode, String fieldName) {
55
        linkList.add(new LinkConfig(actionCode, fieldName));
56
    }
57

  
58
    public void addLink(String actionCode, String fieldName, String extension) {
59
        linkList.add(new LinkConfig(actionCode, fieldName, extension));
60
    }
61

  
62
    public LinkConfig removeLink(int linkIndex) {
63
        try {
64
            return linkList.remove(linkIndex);
65
        } catch (IndexOutOfBoundsException ex) {
66
            return null;
67
        }
68
    }
69

  
70
    public LinkConfig getLink(int index) {
71
        return linkList.get(index);
72
    }
73

  
74
    public int linkCount() {
75
        return linkList.size();
76
    }
77

  
78
    public String getClassName() {
79
        return this.getClass().getName();
80
    }
81

  
82
    public boolean isEnabled() {
83
        return enabled;
84
    }
85

  
86
    public void setEnabled(boolean enabled) {
87
        this.enabled = enabled;
88
    }
89

  
90
    public void saveToState(PersistentState state) throws PersistenceException {
91
        state.set("enabled", this.enabled);
92
        state.set("linkList", this.linkList);
93
    }
94

  
95
    @SuppressWarnings("unchecked")
96
    public void loadFromState(PersistentState state) throws PersistenceException {
97
        this.enabled = state.getBoolean("enabled");
98
        this.linkList = new ArrayList<LinkConfig>();
99
        this.linkList.addAll(state.getList("linkList"));
100
    }
101
    
102
    public static class RegisterPersistence implements Callable {
103

  
104
        public Object call() throws Exception {
105
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
106
            if( manager.getDefinition(LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME)==null ) {
107
                DynStruct definition = manager.addDefinition(
108
                        LayerLinkConfig.class,
109
                        LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME,
110
                        LAYERLINKCONFIG_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
111
                        null, 
112
                        null
113
                );
114

  
115
                definition.addDynFieldBoolean("enabled").setMandatory(true);
116
                definition.addDynFieldList("linkList").setMandatory(false).setClassOfItems(LinkConfig.class);
117
            }
118
            return Boolean.TRUE;
119
        }
120
        
121
    }
122

  
123
}
0 124

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/config/LinkConfig.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.config;
24

  
25
import org.gvsig.tools.ToolsLocator;
26
import org.gvsig.tools.dynobject.DynStruct;
27
import org.gvsig.tools.persistence.PersistenceManager;
28
import org.gvsig.tools.persistence.Persistent;
29
import org.gvsig.tools.persistence.PersistentState;
30
import org.gvsig.tools.persistence.exception.PersistenceException;
31
import org.gvsig.tools.util.Callable;
32

  
33
public class LinkConfig implements Persistent {
34

  
35
    private String fieldName;
36
    private String extension = "";
37
    private String actionCode;
38
    public static final String LINKCONFIG_PERSISTENCE_DEFINITION_NAME = "LinkConfig";
39

  
40
    public LinkConfig() {
41
    }
42

  
43
    public LinkConfig(String actionCode, String fieldName) {
44
        this.actionCode = actionCode;
45
        this.fieldName = fieldName;
46
    }
47

  
48
    public LinkConfig(String actionCode, String fieldName, String extension) {
49
        this.actionCode = actionCode;
50
        this.fieldName = fieldName;
51
        this.extension = extension;
52
    }
53

  
54
    public String getFieldName() {
55
        return fieldName;
56
    }
57

  
58
    public String getActionCode() {
59
        return actionCode;
60
    }
61

  
62
    public void setFieldName(String fieldName) {
63
        this.fieldName = fieldName;
64
    }
65

  
66
    public void setActionCode(String actionCode) {
67
        this.actionCode = actionCode;
68
    }
69

  
70
    public void setExtension(String extension) {
71
        this.extension = extension;
72
    }
73

  
74
    public String getExtension() {
75
        return extension;
76
    }
77

  
78
    public String getClassName() {
79
        return this.getClass().getName();
80
    }
81

  
82
    public void saveToState(PersistentState state) throws PersistenceException {
83
        state.set("fieldName", this.fieldName);
84
        state.set("extension", this.extension);
85
        state.set("actionCode", this.actionCode);
86
    }
87

  
88
    public void loadFromState(PersistentState state) throws PersistenceException {
89
        this.fieldName = state.getString("fieldName");
90
        this.extension = state.getString("extension");
91
        this.actionCode = state.getString("actionCode");
92
    }
93
    
94
    public static class RegisterPersistence implements Callable {
95

  
96
        public Object call() throws Exception {
97
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
98
            if( manager.getDefinition(LINKCONFIG_PERSISTENCE_DEFINITION_NAME)==null ) {
99
                DynStruct definition = manager.addDefinition(
100
                        LinkConfig.class,
101
                        LINKCONFIG_PERSISTENCE_DEFINITION_NAME,
102
                        LINKCONFIG_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
103
                        null, 
104
                        null
105
                );
106

  
107
                definition.addDynFieldString("fieldName").setMandatory(true);
108
                definition.addDynFieldString("extension").setMandatory(false);
109
                definition.addDynFieldString("actionCode").setMandatory(true);
110
            }
111
            return Boolean.TRUE;
112
        }
113
        
114
    }
115

  
116
}
0 117

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/config/gui/ConfigTab.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.config.gui;
24

  
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.Insets;
28
import java.awt.event.ActionEvent;
29
import java.awt.event.ActionListener;
30
import java.awt.event.ItemEvent;
31
import java.awt.event.ItemListener;
32
import java.util.ArrayList;
33

  
34
import javax.swing.BorderFactory;
35
import javax.swing.JButton;
36
import javax.swing.JCheckBox;
37
import javax.swing.JPanel;
38
import javax.swing.JScrollPane;
39
import javax.swing.border.EtchedBorder;
40
import javax.swing.border.TitledBorder;
41

  
42
import org.gvsig.andami.PluginServices;
43
import org.gvsig.andami.ui.mdiManager.IWindow;
44
import org.gvsig.andami.ui.mdiManager.WindowInfo;
45
import org.gvsig.app.project.documents.view.legend.gui.AbstractThemeManagerPage;
46
import org.gvsig.fmap.mapcontext.layers.FLayer;
47
import org.gvsig.hyperlink.app.extension.AbstractActionManager;
48
import org.gvsig.hyperlink.app.extension.HyperlinkExtension;
49
import org.gvsig.hyperlink.app.extension.config.LayerLinkConfig;
50
import org.gvsig.hyperlink.app.extension.config.LinkConfig;
51
import org.gvsig.hyperlink.app.extension.layers.ILinkLayerManager;
52
import org.gvsig.hyperlink.app.extension.layers.IncompatibleLayerException;
53
import org.gvsig.hyperlink.app.extension.layers.ManagerRegistry;
54
import org.gvsig.tools.ToolsLocator;
55
import org.gvsig.tools.extensionpoint.ExtensionPoint;
56

  
57
public class ConfigTab extends AbstractThemeManagerPage implements IWindow,
58
    ActionListener, ItemListener {
59

  
60
    FLayer layer;
61
    ArrayList rows = new ArrayList();
62
    JPanel rowList = null;
63
    GridBagLayout listLayout = null;
64
    private String[] actionCodes = null;
65
    private String[] actionNames = null;
66
    WindowInfo _windowInfo = null;
67
    JButton jbt_accept = null, jbt_cancel = null;
68
    JPanel emptyRow;
69
    JCheckBox jcb_enabled = null;
70
    JPanel borderPanel = null;
71
    JButton jbt_addAction = null, jbt_removeAction = null;
72

  
73
    public ConfigTab() {
74
        super();
75
        initialize();
76
    }
77

  
78
    private void initialize() {
79
        this.setLayout(new GridBagLayout());
80

  
81
        Insets insets = new Insets(8, 8, 8, 8);
82
        GridBagConstraints constraints = new GridBagConstraints();
83
        constraints.gridx = 0;
84
        constraints.gridy = 0;
85
        constraints.weightx = 1.0;
86
        constraints.fill = GridBagConstraints.NONE;
87
        constraints.insets = insets;
88
        constraints.anchor = GridBagConstraints.NORTHWEST;
89
        this.add(getEnabledCheckBox(), constraints);
90

  
91
        borderPanel = new JPanel(new GridBagLayout());
92
        borderPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED),
93
            PluginServices.getText(this, "Actions"),
94
            TitledBorder.DEFAULT_JUSTIFICATION,
95
            TitledBorder.DEFAULT_POSITION,
96
            null,
97
            null));
98

  
99
        insets = new Insets(8, 8, 8, 8);
100
        constraints = new GridBagConstraints();
101
        constraints.gridx = 0;
102
        constraints.gridy = 0;
103
        constraints.weightx = 1.0;
104
        constraints.fill = GridBagConstraints.NONE;
105
        constraints.insets = insets;
106
        constraints.anchor = GridBagConstraints.NORTHWEST;
107
        borderPanel.add(getAddRemoveActionsPanel(), constraints);
108

  
109
        listLayout = new GridBagLayout();
110
        rowList = new JPanel(listLayout);
111

  
112
        constraints.gridx = 0;
113
        constraints.gridy = 0;
114
        constraints.weightx = 1.0;
115
        constraints.weighty = 1.0;
116
        constraints.fill = GridBagConstraints.NONE;
117
        constraints.insets = insets;
118
        constraints.anchor = GridBagConstraints.SOUTH;
119
        emptyRow = new JPanel();
120
        rowList.add(emptyRow, constraints);
121

  
122
        JScrollPane scrolledList = new JScrollPane();
123
        scrolledList.setBorder(null);
124
        scrolledList.setViewportView(rowList);
125

  
126
        constraints.gridx = 0;
127
        constraints.gridy = 1;
128
        constraints.weightx = 1.0;
129
        constraints.weighty = 1.0;
130
        constraints.fill = GridBagConstraints.BOTH;
131
        constraints.insets = insets;
132
        constraints.anchor = GridBagConstraints.CENTER;
133
        borderPanel.add(scrolledList, constraints);
134

  
135
        constraints.gridx = 0;
136
        constraints.gridy = 1;
137
        constraints.weightx = 1.0;
138
        constraints.weighty = 1.0;
139
        constraints.fill = GridBagConstraints.BOTH;
140
        constraints.insets = insets;
141
        constraints.anchor = GridBagConstraints.NORTHWEST;
142
        this.add(borderPanel, constraints);
143

  
144
        // initAcceptCancelButtons(); uncomment this if you want to use this
145
        // window outside the ThemeManager
146
    }
147

  
148
    private void initAcceptCancelButtons() {
149
        JPanel acceptCancelButtons = new JPanel(new GridBagLayout());
150
        Insets insets = new Insets(14, 4, 8, 8);
151
        GridBagConstraints constraints = new GridBagConstraints();
152
        constraints.gridx = 0;
153
        constraints.gridy = 0;
154
        constraints.weightx = 1.0;
155
        constraints.fill = GridBagConstraints.NONE;
156
        constraints.insets = insets;
157
        constraints.anchor = GridBagConstraints.EAST;
158
        acceptCancelButtons.add(getAcceptButton(), constraints);
159

  
160
        constraints.gridx = 1;
161
        constraints.gridy = 0;
162
        constraints.weightx = 0.0;
163
        constraints.fill = GridBagConstraints.NONE;
164
        constraints.insets = insets;
165
        constraints.anchor = GridBagConstraints.EAST;
166
        acceptCancelButtons.add(getCancelButton(), constraints);
167

  
168
        constraints.gridx = 0;
169
        constraints.gridy = 2;
170
        constraints.weightx = 0.0;
171
        constraints.fill = GridBagConstraints.NONE;
172
        constraints.insets = insets;
173
        constraints.anchor = GridBagConstraints.SOUTHEAST;
174
        this.add(acceptCancelButtons, constraints);
175
    }
176

  
177
    private String[] getActionNames() {
178
        if (actionNames == null) {
179
            ExtensionPoint actions =
180
                ToolsLocator.getExtensionPointManager()
181
                    .get(HyperlinkExtension.ACTIONSEXTENSIONPOINT);
182

  
183
            String[] actionArray = new String[actions.getCount()];
184
            String[] codes = getActionCodes();
185
            for (int i = 0; i < codes.length; i++) {
186
                try {
187
                    AbstractActionManager aam =
188
                        (AbstractActionManager) actions.get(codes[i])
189
                            .getExtension()
190
                            .newInstance();
191
                    actionArray[i] = aam.getName();
192
                } catch (InstantiationException e) {
193
                    // TODO Auto-generated catch block
194
                    e.printStackTrace();
195
                } catch (IllegalAccessException e) {
196
                    // TODO Auto-generated catch block
197
                    e.printStackTrace();
198
                }
199
            }
200
            actionNames = actionArray;
201
        }
202
        return actionNames;
203
    }
204

  
205
    private String[] getActionCodes() {
206
        if (actionCodes == null) {
207
            ExtensionPoint actions =
208
                ToolsLocator.getExtensionPointManager()
209
                    .get(HyperlinkExtension.ACTIONSEXTENSIONPOINT);
210
            String[] actionArray = new String[actions.getCount()];
211
            actionArray = (String[]) actions.getNames().toArray(actionArray);
212
            actionCodes = actionArray;
213
        }
214
        return actionCodes;
215
    }
216

  
217
    private String[] getCandidateFields() {
218
        HyperlinkExtension ext =
219
            (HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class);
220
        ManagerRegistry registry = ext.getLayerManager();
221
        try {
222
            ILinkLayerManager manager;
223
            manager = registry.get(layer);
224
            manager.setLayer(layer);
225
            return manager.getFieldCandidates();
226
        } catch (InstantiationException e) {
227
            PluginServices.getLogger()
228
                .warn("Hyperlink: error getting candidate fields", e);
229
        } catch (IllegalAccessException e) {
230
            PluginServices.getLogger()
231
                .warn("Hyperlink: error getting candidate fields", e);
232
        } catch (ClassNotFoundException e) {
233
            PluginServices.getLogger()
234
                .warn("Hyperlink: error getting candidate fields", e);
235
        } catch (IncompatibleLayerException e) {
236
            PluginServices.getLogger()
237
                .warn("Hyperlink: error getting candidate fields", e);
238
        } catch (NullPointerException e) {
239
            PluginServices.getLogger().warn("Hyperlink: error getting manager", e);
240
        }
241
        return new String[0];
242
    }
243

  
244
    public void acceptAction() {
245
        applyAction();
246
    }
247

  
248
    public void applyAction() {
249
        LayerLinkConfig config = new LayerLinkConfig();
250
        for (int i = 0; i < rows.size(); i++) {
251
            LinkRow row = (LinkRow) rows.get(i);
252
            config.addLink(getActionCodes()[row.getSelectedAction()],
253
                row.getSelectedField(),
254
                row.getExtension());
255
        }
256
        config.setEnabled(getEnabledCheckBox().isSelected());
257
        layer.setProperty(HyperlinkExtension.LAYERPROPERTYNAME, config);
258
    }
259

  
260
    public void cancelAction() {
261
    }
262

  
263
    public String getName() {
264
        return PluginServices.getText(this, "Hyperlink");
265
    }
266

  
267
    public void setModel(FLayer layer) {
268
        this.layer = layer;
269
        synchronized (rows) {
270
            HyperlinkExtension ext =
271
                (HyperlinkExtension) PluginServices.getExtension(HyperlinkExtension.class);
272
            LayerLinkConfig layerConfig = ext.loadLegacyConfig(layer);
273
            for (int i = rows.size() - 1; i >= 0; i--) { // clean rows
274
                LinkRow row = (LinkRow) rows.remove(i);
275
                rowList.remove(row);
276
            }
277

  
278
            if (layerConfig != null) {
279
                for (int i = 0; i < layerConfig.linkCount(); i++) {
280
                    LinkRow row = addRow();
281
                    LinkConfig config = layerConfig.getLink(i);
282
                    String selectedAction = config.getActionCode();
283
                    String[] actions = getActionCodes();
284
                    for (int j = 0; j < actions.length; j++) {
285
                        if (actions[j].equals(selectedAction)) {
286
                            row.setSelectedAction(j);
287
                        }
288
                    }
289
                    row.setSelectedField(config.getFieldName());
290
                    row.setExtension(config.getExtension());
291
                }
292
                if (layerConfig.linkCount() < 1) {
293
                    addRow(); // just one row by default
294
                }
295
                setLinkEnabled(layerConfig.isEnabled());
296
            } else {
297
                addRow(); // just one row by default
298
                setLinkEnabled(false);
299
            }
300
        }
301
    }
302

  
303
    protected JPanel getAddRemoveActionsPanel() {
304
        JPanel container = new JPanel();
305
        container.add(getAddActionButton());
306
        container.add(getRemoveActionButton());
307
        return container;
308
    }
309

  
310
    protected LinkRow addRow() {
311
        LinkRow row = new LinkRow();
312
        row.setFields(getCandidateFields());
313
        row.setActions(getActionNames());
314
        synchronized (rows) {
315
            rows.add(row);
316

  
317
            GridBagConstraints constraints = new GridBagConstraints();
318
            constraints.gridx = 0;
319
            constraints.gridy = rows.size() - 1;
320
            constraints.weightx = 1.0;
321
            constraints.weighty = 0.0;
322
            constraints.fill = GridBagConstraints.HORIZONTAL;
323
            constraints.insets = new Insets(2, 4, 2, 4);
324
            constraints.anchor = GridBagConstraints.NORTH;
325
            rowList.add(row, constraints);
326

  
327
            constraints = new GridBagConstraints();
328
            constraints.gridx = 0;
329
            constraints.gridy = rows.size();
330
            constraints.weightx = 1.0;
331
            constraints.weighty = 1.0;
332
            constraints.fill = GridBagConstraints.NONE;
333
            constraints.anchor = GridBagConstraints.CENTER;
334
            listLayout.setConstraints(emptyRow, constraints);
335
        }
336
        validate();
337
        return row;
338
    }
339

  
340
    protected boolean removeBottomRow() {
341
        LinkRow row;
342
        synchronized (rows) {
343
            if (rows.size() <= 1)
344
                return false;
345
            row = (LinkRow) rows.get(rows.size() - 1);
346
            rows.remove(rows.size() - 1);
347
        }
348
        rowList.remove(row);
349
        GridBagConstraints constraints = new GridBagConstraints();
350
        constraints.gridx = 0;
351
        constraints.gridy = rows.size();
352
        constraints.weightx = 1.0;
353
        constraints.weighty = 1.0;
354
        constraints.fill = GridBagConstraints.NONE;
355
        constraints.anchor = GridBagConstraints.CENTER;
356
        listLayout.setConstraints(emptyRow, constraints);
357

  
358
        validate();
359
        repaint();
360
        return true;
361
    }
362

  
363
    protected JButton getAddActionButton() {
364
        if (jbt_addAction == null) {
365
            jbt_addAction =
366
                new JButton(PluginServices.getText(this, "Add_action"));
367
            jbt_addAction.setSize(150, 70);
368
            jbt_addAction.setActionCommand("addButton");
369
            jbt_addAction.addActionListener(new ActionListener() {
370

  
371
                public void actionPerformed(ActionEvent e) {
372
                    if (e.getActionCommand().equals("addButton")) {
373
                        addRow();
374
                    }
375
                }
376
            });
377
        }
378
        return jbt_addAction;
379
    }
380

  
381
    protected JButton getRemoveActionButton() {
382
        if (jbt_removeAction == null) {
383
            jbt_removeAction =
384
                new JButton(PluginServices.getText(this, "Remove_action"));
385
            jbt_removeAction.setActionCommand("removeButton");
386
            jbt_removeAction.addActionListener(new ActionListener() {
387

  
388
                public void actionPerformed(ActionEvent e) {
389
                    if (e.getActionCommand().equals("removeButton")) {
390
                        removeBottomRow();
391
                    }
392
                }
393
            });
394
            return jbt_removeAction;
395
        }
396
        return jbt_removeAction;
397
    }
398

  
399
    public WindowInfo getWindowInfo() {
400
        if (_windowInfo == null) {
401
            _windowInfo =
402
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
403
                    | WindowInfo.RESIZABLE);
404
            _windowInfo.setWidth(680);
405
            _windowInfo.setHeight(500);
406
            _windowInfo.setTitle(PluginServices.getText(this,
407
                "Hyperlink_Settings"));
408
        }
409
        return _windowInfo;
410
    }
411

  
412
    protected JButton getAcceptButton() {
413
        if (jbt_accept == null) {
414
            jbt_accept =
415
                new org.gvsig.gui.beans.swing.JButton(PluginServices.getText(this,
416
                    "Aceptar"));
417
            jbt_accept.addActionListener(this);
418
        }
419
        return jbt_accept;
420
    }
421

  
422
    protected JButton getCancelButton() {
423
        if (jbt_cancel == null) {
424
            jbt_cancel =
425
                new org.gvsig.gui.beans.swing.JButton(PluginServices.getText(this,
426
                    "Cancel"));
427
            jbt_cancel.addActionListener(this);
428
        }
429
        return jbt_cancel;
430
    }
431

  
432
    protected JCheckBox getEnabledCheckBox() {
433
        if (jcb_enabled == null) {
434
            jcb_enabled =
435
                new JCheckBox(PluginServices.getText(this, "Enable_hyperlink"),
436
                    true);
437
            jcb_enabled.addItemListener(this);
438
        }
439
        return jcb_enabled;
440
    }
441

  
442
    public void actionPerformed(ActionEvent e) {
443
        if (e.getSource() == getAcceptButton()) {
444
            acceptAction();
445
            PluginServices.getMDIManager().closeWindow(this);
446

  
447
        } else
448
            if (e.getSource() == getCancelButton()) {
449
                cancelAction();
450
                PluginServices.getMDIManager().closeWindow(this);
451
            }
452
    }
453

  
454
    protected void setListEnabled(boolean enabled) {
455
        getAddActionButton().setEnabled(enabled);
456
        getRemoveActionButton().setEnabled(enabled);
457
        synchronized (rows) {
458
            for (int i = 0; i < rows.size(); i++) {
459
                LinkRow row = (LinkRow) rows.get(i);
460
                row.setEnabled(enabled);
461
            }
462
        }
463
    }
464

  
465
    protected void setLinkEnabled(boolean enabled) {
466
        getEnabledCheckBox().setSelected(enabled);
467
        setListEnabled(enabled);
468
    }
469

  
470
    public void itemStateChanged(ItemEvent e) {
471
        if (e.getSource() == getEnabledCheckBox()) {
472
            if (e.getStateChange() == ItemEvent.DESELECTED) {
473
                setListEnabled(false);
474
            } else {
475
                setListEnabled(true);
476
            }
477
        }
478
    }
479

  
480
    public Object getWindowProfile() {
481
        return WindowInfo.DIALOG_PROFILE;
482
    }
483
}
0 484

  
tags/v2_0_0_Build_2042/extensions/org.gvsig.hyperlink.app/org.gvsig.hyperlink.app.extension/src/main/java/org/gvsig/hyperlink/app/extension/config/gui/LinkRow.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.config.gui;
24

  
25
import java.awt.BorderLayout;
26
import java.awt.Dimension;
27

  
28
import javax.swing.BorderFactory;
29
import javax.swing.JComboBox;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JTextField;
33
import javax.swing.border.BevelBorder;
34

  
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
37

  
38
public class LinkRow extends JPanel {
39

  
40
    JPanel pnlFieldAndExtension = null;
41
    JPanel pnlHyperLinkAction = null;
42
    JLabel lblLinkExtension = null;
43
    JLabel lblLinkField = null;
44
    JLabel lblDefaultAction = null;
45
    JTextField txtLinkExtension = null;
46
    JComboBox cmbLinkField = null;
47
    JComboBox cmbLinkType = null;
48

  
49
    public LinkRow() {
50
        super();
51
        initialize();
52
    }
53

  
54
    private void initialize() {
55
        GridBagLayoutPanel aux = new GridBagLayoutPanel();
56
        aux.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
57
        aux.addComponent(getPnlFieldAndExtension(), getPnlHyperLinkAction());
58
        this.setLayout(new BorderLayout());
59
        this.add(aux, BorderLayout.CENTER);
60
    }
61

  
62
    public String getSelectedField() {
63
        return (String) getCmbLinkField().getSelectedItem();
64
    }
65

  
66
    public void setFields(String[] fields) {
67
        for (int i = 0; i < fields.length; i++) {
68
            getCmbLinkField().addItem(fields[i]);
69
        }
70
    }
71

  
72
    public void setSelectedField(String field) {
73
        getCmbLinkField().setSelectedItem(field);
74
    }
75

  
76
    public int getSelectedAction() {
77
        return getCmbLinkType().getSelectedIndex();
78
    }
79

  
80
    public String getSelectedActionName() {
81
        return (String) getCmbLinkType().getSelectedItem();
82
    }
83

  
84
    public void setActions(String[] actions) {
85
        for (int i = 0; i < actions.length; i++) {
86
            getCmbLinkType().addItem(actions[i]);
87
        }
88
    }
89

  
90
    public void setSelectedAction(String action) {
91
        getCmbLinkType().setSelectedItem(action);
92
    }
93

  
94
    public void setSelectedAction(int action) {
95
        getCmbLinkType().setSelectedIndex(action);
96
    }
97

  
98
    public String getExtension() {
99
        return getTxtLinkExtension().getText();
100
    }
101

  
102
    public void setExtension(String extension) {
103
        getTxtLinkExtension().setText(extension);
104
    }
105

  
106
    private JPanel getPnlFieldAndExtension() {
107
        if (pnlFieldAndExtension == null) {
108
            lblLinkExtension = new JLabel();
109
            lblLinkExtension.setText(" \t \t"
110
                + PluginServices.getText(this, "Extension"));
111
            lblLinkField = new JLabel();
112
            lblLinkField.setText(PluginServices.getText(this, "Campo"));
113
            pnlFieldAndExtension = new JPanel();
114
            pnlFieldAndExtension.add(lblLinkField, null);
115
            pnlFieldAndExtension.add(getCmbLinkField(), null);
116
            pnlFieldAndExtension.add(lblLinkExtension, null);
117
            pnlFieldAndExtension.add(getTxtLinkExtension(), null);
118
        }
119
        return pnlFieldAndExtension;
120
    }
121

  
122
    /**
123
     * This method initializes jPanel8. This panel contains the ComboBox to
124
     * select
125
     * the action, (type of HyperLink)
126
     * 
127
     * @return javax.swing.JPanel
128
     */
129
    private JPanel getPnlHyperLinkAction() {
130
        if (pnlHyperLinkAction == null) {
131
            lblDefaultAction = new JLabel();
132
            lblDefaultAction.setText(PluginServices.getText(this, "Action")
133
                + "  ");
134
            pnlHyperLinkAction = new JPanel();
135
            pnlHyperLinkAction.add(lblDefaultAction, null);
136
            pnlHyperLinkAction.add(getCmbLinkType(), null);
137
        }
138
        return pnlHyperLinkAction;
139
    }
140

  
141
    /**
142
     * This method initializes jComboBox
143
     * 
144
     * @return javax.swing.JComboBox
145
     */
146
    private JComboBox getCmbLinkField() {
147
        if (cmbLinkField == null) {
148
            cmbLinkField = new JComboBox();
149
        }
150
        return cmbLinkField;
151
    }
152

  
153
    /**
154
     * This method initializes jTextField
155
     * 
156
     * @return javax.swing.JTextField
157
     */
158
    private JTextField getTxtLinkExtension() {
159
        if (txtLinkExtension == null) {
160
            txtLinkExtension = new JTextField();
161
            txtLinkExtension.setPreferredSize(new Dimension(40, 20));
162
        }
163
        return txtLinkExtension;
164
    }
165

  
166
    /**
167
     * This method initializes jComboBox1
168
     * 
169
     * @return javax.swing.JComboBox
170
     */
171
    private JComboBox getCmbLinkType() {
172
        if (cmbLinkType == null) {
173
            cmbLinkType = new JComboBox();
174

  
175
        }
176
        return cmbLinkType;
177
    }
178

  
179
    public void setEnabled(boolean enabled) {
180
        super.setEnabled(enabled);
181
        getTxtLinkExtension().setEnabled(enabled);
182
        getCmbLinkField().setEnabled(enabled);
183
        getCmbLinkType().setEnabled(enabled);
184
        lblLinkField.setEnabled(enabled);
185
        lblDefaultAction.setEnabled(enabled);
186
        lblLinkExtension.setEnabled(enabled);
187
    }
188
}
0 189

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

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

Also available in: Unified diff