Revision 739

View differences:

org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.90/LEEME.txt
1
===============
2
gvSIG Educa
3
===============
4

  
5
---------------------
6
Vistas Portables
7
---------------------
8

  
9
Descripci?n
10
==============
11

  
12
Este directorio contiene los fuentes de la funcionalidad Vistas Portables.
13

  
14
Requisitos
15
==============
16

  
17
* Maven 2.6 or higher
18

  
19
* Java JDK 1.5 or higher
20

  
21
Para trabajar con eclipse
22
--------------------------
23

  
24
Ver `Gu?a del desarrollador en gvSIG.org <https://gvsig.org/web/projects/gvsig-desktop/docs/devel/gvsig-devel-guide/2.0.0/>`_ y el fichero ``REAME-ECLIPSE.txt``
25

  
26
Contenido
27
==========
28

  
29
org.gvsig.educa.portableview.lib
30
---------------------------------
31

  
32
Fuentes de la funcionalidad. Estos proyectos contienen los procesos y l?gica principal sin dependencias de interface de usuario.
33

  
34
org.gvsig.educa.portableview.swing
35
-------------------------------------
36

  
37
Componentes de interface de usuario para gestionar los servicios que ofrece la librer??a.
38

  
39
org.gvsig.educa.portableview.main
40
-----------------------------------
41

  
42
Peque?a aplicaci?n que permite ejecutar las funcionalidades y realizar pruebas funcionales.
43

  
44
Ver `Ejecutar aplicaci?n de pruebas`_ para saber como arrancarla.
45

  
46
pom.xml
47
---------
48

  
49
Archivo de definici?n de proyecto Maven.
50

  
51
README.txt LEEME.txt
52
----------------------
53

  
54
Este fichero (en formato reStructureText, para mas informaci?n sobre este ver el `portal de gvSIG <https://gvsig.org/web/projects/gvsig-desktop/docs/devel/guia-para-documentar/el-formato-restructuredtext>`_  en la `referencia de docUtils  <http://docutils.sourceforge.net/rst.html>`_)
55

  
56

  
57
Compilaci?n
58
================
59

  
60
Desde el shell
61
----------------
62

  
63
Ejecute este comando::
64

  
65
    org.gvsig.educa.portablewview$ mvn clean install
66

  
67

  
68
Desde eclipse
69
--------------
70
Ver `Trabajar con un proyecto de la gu?a de desarrollador en gvSIG.org <https://gvsig.org/web/projects/gvsig-desktop/docs/devel/gvsig-devel-guide/2.0.0/trabajar-con-un-proyecto>`_
71

  
72
En algunos proyectos puede que sea necesario user el comando ``mvn eclipse:clean eclipse:eclipse`` e importar como *Standar/Import existing project...* en vez de cargar como *Maven Project*. Esto es debido a que, en algunas circunstancias, parece que el plugin de Maven del eclipse no prepara el *classpath* de forma correcta.
73

  
74

  
75
Empaquetado
76
===============
77

  
78
Esta funcionalidad no tiene ning?n proyecto pensado para empaquetar de forma independiente.
79

  
80
Versionado
81
--------------
82

  
83
Para cambiar el n?mero de versi?n de los plugins solo es necesario ajustar la etiqueta ``project/version`` del fichero *pom.xml*. Los subproyectos heredar?n el valor.
84

  
85
La pol??tica de versi?n es la est?ndar. Los cambios en los numeroso son:
86

  
87
* tercer n?mero: Arreglo de errores y mejoras menores. Sin cambios en el API.
88
* segundo n?mero: Arreglo de erroes y mejoras. Pueden haber cambios menores en el API. Los elementos marcados como *deprecated* en versiones anteriores pueden eliminarse. Sin cambios de arquitectura.
89
* primer n?mero: Cambios mayores.
90

  
91
Crear un tag
92
------------------
93

  
94
TODO: usar el plugin *release* de maven
95

  
96
Usar el comando *svn copy*. El proceso podr?a ser:
97

  
98
#. Comprobar que no hay cambios en la copia local::
99

  
100
   svn up ; svn status
101

  
102
#. Comprobar que los proyecto compilan y pasan todas las bater?as de test::
103

  
104
   mvn clean install
105

  
106
#. Actualizar el fichero *pom.xml* con la versi?n de tag (normalmente quitando el sufijo *-SNAPSHOT*)
107
#. Crear el directorio para el tag en el servidor::
108

  
109
   svn mkdir -m "Create {version} tag folder" https://devel.gvsig.org/svn/gvsig-educa/org.gvsig.educa.portablewview.app/tags/{version}
110

  
111
#. Subir la copia local al directorio del tag en el servidor::
112

  
113
   svn copy -m "Create {version} tag" * https://devel.gvsig.org/svn/gvsig-educa/org.gvsig.educa.portablewview.app/tags/{version}
114

  
115
#. Actualizar el *pom.xml* a la siguiente version (y a?adirle el sufijo *-SNAPSHOT*)
116
#. Subir los cambios del *pom.xml*::
117

  
118
   svn commit -m "Set new version {version}-SNAPSHOT" pom.xml
119

  
120

  
121
i18n
122
======
123

  
124
Los ficheros de internacionalizaci?n se pueden encontrar en los directorios:
125

  
126
+ */org.gvsig.educa.portableview.swing/org.gvsig.educa.portableview.swing.impl/src/main/resources/org/gvsig/educa/portableview/swing/impl/i18n*
127
+ *org.gvsig.educa.portableview.lib/org.gvsig.educa.portableview.lib.impl/src/main/resources/org/gvsig/educa/portableview/impl/i18n*
128

  
129
La internacionalizaci?n est? basada en el mecanismo est?ndar de los *resource bundle*. Para a?adir un nuevo idioma es necesario a?adir el fichero de propiedades en todos los directorio con el codigo de idioma adecuado.
130

  
131
Ejecutar aplicaci?n de pruebas
132
=================================
133

  
134
Desde el Shell
135
----------------
136

  
137
Despu?s del proceso de `Compilaci?n`_ , ejecute estos comandos::
138

  
139
    org.gvsig.educa.portablewview$ cd org.gvsig.educa.portablewview.main
140
    org.gvsig.educa.portablewview/org.gvsig.educa.portablewview.main$ mvn exec:java
141

  
142
Desde el eclipse
143
------------------
144

  
145
Seleccione el proyecto ``org.gvsig.educa.portableview.main`` en el *Project tree* de la *Java perspective*, haga click con el bot?n derecho y seleccione ``Run as.../Java application``. Seleccione la clase ``Main`` del propio proyecto.
146

  
147
Si tiene problemas al ejecutar, compruebe la nota de la secci?n `Compilaci?n`_ sobre la importaci?n del proyecto.
148

  
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.90/org.gvsig.educa.portableview.app/org.gvsig.educa.portableview.app.viewer/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
  <dependencySets>
26
    <dependencySet>
27
      <useProjectArtifact>false</useProjectArtifact>
28
      <useTransitiveDependencies>false</useTransitiveDependencies>
29
      <outputDirectory>lib</outputDirectory>
30
      <includes>
31
		<include>org.gvsig:org.gvsig.educa.portableview.lib.api</include>
32
		<include>org.gvsig:org.gvsig.educa.portableview.lib.impl</include>
33
		<include>org.gvsig:org.gvsig.educa.portableview.lib.prov.installer</include>
34
		<include>org.gvsig:org.gvsig.educa.portableview.swing.api</include>
35
		<include>org.gvsig:org.gvsig.educa.portableview.swing.impl</include>
36
      </includes>
37
    </dependencySet>
38
  </dependencySets>
39

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

  
24
import java.beans.PropertyChangeEvent;
25
import java.beans.PropertyChangeListener;
26
import java.io.IOException;
27

  
28
import org.apache.commons.lang3.ObjectUtils;
29
import org.apache.commons.lang3.StringUtils;
30
import org.gvsig.app.project.Project;
31
import org.gvsig.app.project.ProjectManager;
32
import org.gvsig.app.project.documents.AbstractDocument;
33
import org.gvsig.app.project.documents.DocumentManager;
34
import org.gvsig.app.project.documents.view.ViewDocument;
35
import org.gvsig.educa.portableview.PortableViewLocator;
36
import org.gvsig.educa.portableview.PortableViewManager;
37
import org.gvsig.educa.portableview.app.viewer.exception.PortableViewLoadingException;
38
import org.gvsig.educa.portableview.app.viewer.exception.PortableViewNotFoundException;
39
import org.gvsig.educa.portableview.map.CantLoadContextException;
40
import org.gvsig.educa.portableview.map.InvalidPortableViewFormatException;
41
import org.gvsig.educa.portableview.map.PortableView;
42
import org.gvsig.educa.portableview.map.PortableViewInformation;
43
import org.gvsig.fmap.mapcontext.MapContext;
44
import org.gvsig.tools.persistence.PersistentState;
45
import org.gvsig.tools.persistence.exception.PersistenceException;
46

  
47
/**
48
 * PortableView document
49
 *
50
 * @author gvSIG Team
51
 * @version $Id$
52
 *
53
 */
54
public class PortableViewDocument extends AbstractDocument implements
55
    PropertyChangeListener {
56

  
57
    /**
58
     *
59
     */
60
    private static final long serialVersionUID = 1241724510305853337L;
61

  
62
    private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory
63
        .getLogger(PortableViewDocument.class);
64

  
65
    private final PortableViewManager thMapManager;
66

  
67
    private PortableView portableView;
68
    private ViewDocument sourceView;
69

  
70
    public PortableViewDocument() {
71
        this(null);
72
    }
73

  
74
    public PortableViewDocument(DocumentManager factory) {
75
        super(factory);
76
        thMapManager = PortableViewLocator.getManager();
77
        portableView = null;
78
    }
79

  
80
    public PortableViewDocument(DocumentManager factory, PortableView map) {
81
        this(factory);
82
        setPortableView(map);
83
    }
84

  
85
    /**
86
     * @param map
87
     */
88
    protected void setPortableView(PortableView map) {
89
        if (portableView != null) {
90
            throw new IllegalStateException("Portable view already set");
91
        }
92
        portableView = map;
93
        super.setName(map.getInformation().getName());
94
    }
95

  
96
    public PortableView getPortableView() {
97
        return portableView;
98
    }
99

  
100
    public void reloadPortableView() throws InvalidPortableViewFormatException,
101
        CantLoadContextException, IOException {
102
        if (portableView == null) {
103
            throw new IllegalStateException("Portable not set");
104
        }
105

  
106
        try {
107
            portableView.close();
108
        } catch (IOException ex) {
109
            // TODO
110
        }
111
        PortableView newMap =
112
            thMapManager.getMapById(portableView.getInformation().getId());
113

  
114
        newMap.open();
115

  
116
        // TODO raise a propertyChange event (need access to supper
117
        // propertySupport
118
        portableView = newMap;
119

  
120
    }
121

  
122
    @Override
123
    public void setCreationDate(String string) {
124
        throw new UnsupportedOperationException();
125
    }
126

  
127
    @Override
128
    public String getCreationDate() {
129
        if (portableView == null) {
130
            return null;
131
        }
132
        return portableView.getInformation().getCreationTimestamp().toString();
133
    }
134

  
135
    @Override
136
    public void setOwner(String string) {
137
        throw new UnsupportedOperationException();
138
    }
139

  
140
    @Override
141
    public String getOwner() {
142
        return null;
143
    }
144

  
145
    /**
146
     *
147
     */
148
    @Override
149
    public void loadFromState(PersistentState state)
150
        throws PersistenceException {
151
        String id = state.getString("id");
152
        String name = state.getString("name");
153
        String comment = state.getString("comment");
154
        int version = state.getInt("version");
155
        ViewDocument sourceView = (ViewDocument) state.get("sourceView");
156
        int bn = state.getInt("buildNumber");
157

  
158
        PortableView map;
159
        try {
160
            map = thMapManager.getMapById(id);
161
        } catch (Exception ex) {
162
            throw new PortableViewLoadingException(ex, id, version, bn);
163
        }
164
        if (map == null) {
165
            throw new PortableViewNotFoundException(id, version, bn);
166
        }
167
        PortableViewInformation info = map.getInformation();
168

  
169
        if (info.getVersion() != version) {
170
            // XXX Make anything else
171
            LOG.warn(
172
                "Version number of PortableView {} no match: in project '{}', installed '{}'",
173
                new Object[] { id, version, info.getVersion() });
174

  
175
        } else
176
            if (info.getBuildNumber() != bn) {
177
                LOG.warn(
178
                    "Version number of PortableView {} no match: in project '{}', installed '{}'",
179
                    new Object[] { id, bn, info.getBuildNumber() });
180
            }
181

  
182
        this.portableView = map;
183
        this.sourceView = sourceView;
184
        listenProjectChanges(sourceView != null);
185
        super.setName(name);
186
        super.setComment(comment);
187
    }
188

  
189
    @Override
190
    public void saveToState(PersistentState state) throws PersistenceException {
191
        state.set("id", portableView.getInformation().getId());
192
        state.set("name", getName());
193
        state.set("comment", getComment());
194
        state.set("version", portableView.getInformation().getVersion());
195
        state.set("buildNumber", portableView.getInformation().getBuildNumber());
196
        state.set("sourceView", sourceView);
197
    }
198

  
199
    /**
200
     * @param map
201
     * @return
202
     */
203
    public boolean isMap(PortableView map) {
204
        return ObjectUtils.equals(portableView, map);
205
    }
206

  
207
    public MapContext getMapContext() {
208
        if (portableView == null) {
209
            return null;
210
        }
211
        return portableView.getMapContext();
212
    }
213

  
214
    /**
215
     * @param sourceView
216
     *            the sourceView to set
217
     */
218
    public void setSourceView(ViewDocument sourceView) {
219
        // TODO raise a propertyChange event
220
        this.sourceView = sourceView;
221
        listenProjectChanges(sourceView != null);
222
    }
223

  
224
    /**
225
     * Start or left to listen project changes (to get notify if related
226
     * document has been removed)
227
     *
228
     * @param listen
229
     */
230
    private void listenProjectChanges(boolean listen) {
231
        if (listen) {
232
            ProjectManager.getInstance().getCurrentProject()
233
                .addPropertyChangeListener(this);
234
        } else {
235
            // TODO remove this instance from project listener (NO API
236
            // TO DO IT)
237

  
238
        }
239
    }
240

  
241
    /**
242
     * @return the sourceView
243
     */
244
    public ViewDocument getSourceView() {
245
        return sourceView;
246
    }
247

  
248
    public void propertyChange(PropertyChangeEvent evt) {
249
        if (evt.getSource() instanceof Project) {
250
            // Check if removed related view
251
            if (sourceView == null) {
252
                listenProjectChanges(false);
253
                return;
254
            }
255
            if (StringUtils.equals(evt.getPropertyName(), "delDocument")) {
256
                if (ObjectUtils.equals(evt.getOldValue(), sourceView)) {
257
                    sourceView = null;
258
                    listenProjectChanges(false);
259
                }
260
            }
261
        }
262
    }
263

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

  
24
import org.gvsig.andami.PluginServices;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.andami.ui.mdiManager.IWindow;
27
import org.gvsig.app.project.documents.view.toolListeners.InfoListener;
28
import org.gvsig.educa.portableview.app.viewer.ui.PortableViewDocumentViewer;
29
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
30
import org.gvsig.educa.portableview.swing.viewer.MapControlToolRegistrant;
31
import org.gvsig.fmap.mapcontext.layers.FLayers;
32
import org.gvsig.fmap.mapcontrol.MapControl;
33
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior;
34

  
35
/**
36
 * PortableView Info-by-point tool
37
 *
38
 * @author gvSIG Team
39
 * @version $Id$
40
 *
41
 */
42
public class PortableViewInfoByPointToolsExtension extends Extension implements
43
    MapControlToolRegistrant {
44

  
45
    private static final String LAYER_INFO_BY_POINT = "layer-info-by-point";
46

  
47
	public void initialize() {
48
        // Nothing to do
49

  
50
    }
51

  
52
    @Override
53
    public void postInitialize() {
54

  
55
        // Register tools
56
        PortableViewSwingLocator.getSwingManager().addMapControlRegistrant(this);
57
    }
58

  
59
    public boolean isEnabled() {
60
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
61

  
62
        if (window instanceof PortableViewDocumentViewer) {
63
            PortableViewDocumentViewer viewer =
64
                (PortableViewDocumentViewer) window;
65

  
66
            FLayers layers =
67
                viewer.getPortableView().getMapContext().getLayers();
68

  
69
            for (int i = 0; i < layers.getLayersCount(); i++) {
70
                if (layers.getLayer(i).isAvailable()) {
71
                    return true;
72
                }
73
            }
74
        }
75
        return false;
76
    }
77

  
78
    public boolean isVisible() {
79
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
80
        return window instanceof PortableViewDocumentViewer;
81
    }
82

  
83
    public void registerTools(MapControl mapControl) {
84

  
85
        // Info por punto
86
        InfoListener il = new InfoListener(mapControl);
87
        mapControl.addBehavior("info", new PointBehavior(il));
88

  
89
    }
90

  
91
    public void execute(String actionCommand) {
92
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
93
        if (!(window instanceof PortableViewDocumentViewer)) {
94
            return;
95
        }
96
        PortableViewDocumentViewer tmDocViewer =
97
            (PortableViewDocumentViewer) window;
98
        MapControl mapCtrl = tmDocViewer.getViewer().getMapControl();
99
        if (actionCommand.equals(LAYER_INFO_BY_POINT)) {
100
            mapCtrl.setTool("info");
101
        }
102
    }
103
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.90/org.gvsig.educa.portableview.app/org.gvsig.educa.portableview.app.viewer/src/main/java/org/gvsig/educa/portableview/app/viewer/PortableViewMeasureToolsExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.app.viewer;
23

  
24
import org.gvsig.andami.PluginServices;
25
import org.gvsig.andami.plugins.Extension;
26
import org.gvsig.andami.ui.mdiManager.IWindow;
27
import org.gvsig.app.project.documents.view.toolListeners.AreaListener;
28
import org.gvsig.app.project.documents.view.toolListeners.MeasureListener;
29
import org.gvsig.educa.portableview.app.viewer.ui.PortableViewDocumentViewer;
30
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
31
import org.gvsig.educa.portableview.swing.viewer.MapControlToolRegistrant;
32
import org.gvsig.fmap.mapcontext.layers.FLayers;
33
import org.gvsig.fmap.mapcontrol.MapControl;
34
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolygonBehavior;
35
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior;
36

  
37
/**
38
 * PortableView Measure tool extension
39
 *
40
 * @author gvSIG Team
41
 * @version $Id$
42
 *
43
 */
44
public class PortableViewMeasureToolsExtension extends Extension implements
45
    MapControlToolRegistrant {
46

  
47
    private static final String VIEW_QUERY_AREA = "view-query-area";
48
	private static final String VIEW_QUERY_DISTANCE = "view-query-distance";
49

  
50
	public void initialize() {
51
        // Nothing to do
52

  
53
    }
54

  
55
    @Override
56
    public void postInitialize() {
57

  
58
        // Register tools
59
        PortableViewSwingLocator.getSwingManager().addMapControlRegistrant(this);
60
    }
61

  
62
    public boolean isEnabled() {
63
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
64

  
65
        if (window instanceof PortableViewDocumentViewer) {
66
            PortableViewDocumentViewer viewer =
67
                (PortableViewDocumentViewer) window;
68

  
69
            FLayers layers =
70
                viewer.getPortableView().getMapContext().getLayers();
71

  
72
            for (int i = 0; i < layers.getLayersCount(); i++) {
73
                if (layers.getLayer(i).isAvailable()) {
74
                    return true;
75
                }
76
            }
77
        }
78
        return false;
79
    }
80

  
81
    public boolean isVisible() {
82
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
83
        return window instanceof PortableViewDocumentViewer;
84
    }
85

  
86
    public void registerTools(MapControl mapControl) {
87
        // Medir
88

  
89
        MeasureListener mli = new MeasureListener(mapControl);
90
        mapControl.addBehavior("medicion", new PolylineBehavior(mli));
91

  
92
        // Area
93
        AreaListener ali = new AreaListener(mapControl);
94
        mapControl.addBehavior("area", new PolygonBehavior(ali));
95

  
96
    }
97

  
98
    public void execute(String actionCommand) {
99
        IWindow window = PluginServices.getMDIManager().getActiveWindow();
100
        if (!(window instanceof PortableViewDocumentViewer)) {
101
            return;
102
        }
103
        PortableViewDocumentViewer tmDocViewer =
104
            (PortableViewDocumentViewer) window;
105
        MapControl mapCtrl = tmDocViewer.getViewer().getMapControl();
106
        if (actionCommand.equals(VIEW_QUERY_DISTANCE)) {
107
            mapCtrl.setTool("medicion");
108
        }
109
        if (actionCommand.equals(VIEW_QUERY_AREA)) {
110
            mapCtrl.setTool("area");
111
        }
112
    }
113
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.90/org.gvsig.educa.portableview.app/org.gvsig.educa.portableview.app.viewer/src/main/java/org/gvsig/educa/portableview/app/viewer/PortableViewDocumentManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.app.viewer;
23

  
24
import java.util.Arrays;
25
import java.util.Iterator;
26
import java.util.List;
27

  
28
import javax.swing.ImageIcon;
29

  
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.app.project.Project;
33
import org.gvsig.app.project.ProjectManager;
34
import org.gvsig.app.project.documents.AbstractDocument;
35
import org.gvsig.app.project.documents.AbstractDocumentManager;
36
import org.gvsig.app.project.documents.Document;
37
import org.gvsig.app.project.documents.gui.IDocumentWindow;
38
import org.gvsig.app.project.documents.gui.WindowLayout;
39
import org.gvsig.app.project.documents.view.ViewDocument;
40
import org.gvsig.educa.portableview.PortableViewManager;
41
import org.gvsig.educa.portableview.app.viewer.ui.PortableViewDocumentProperties;
42
import org.gvsig.educa.portableview.app.viewer.ui.PortableViewDocumentViewer;
43
import org.gvsig.educa.portableview.app.viewer.ui.PortableViewSelector;
44
import org.gvsig.educa.portableview.map.PortableView;
45
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
46
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
47
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.dynobject.DynObjectManager;
49
import org.gvsig.tools.dynobject.DynStruct;
50
import org.gvsig.tools.persistence.PersistenceManager;
51
import org.gvsig.tools.swing.api.windowmanager.WindowManager.MODE;
52

  
53
/**
54
 * @author gvSIG Team
55
 * @version $Id$
56
 *
57
 */
58
public class PortableViewDocumentManager extends AbstractDocumentManager {
59

  
60
    public static final String PERSISTENCE_PORTABLEVIEW_DOCUMENT_DEFINITION_NAME =
61
        "PortableViewDocument";
62

  
63
    public static String TYPENAME = "project.document.portableView";
64

  
65
    private DynStruct persistenceDefinition = null;
66

  
67
    private final PortableViewSwingManager tmSwingManager;
68

  
69
    private final PortableViewManager tmManager;
70

  
71
    /**
72
     * Registers in the points of extension the Factory with alias.
73
     *
74
     */
75
    public static void register() {
76

  
77
        PortableViewDocumentManager factory = new PortableViewDocumentManager();
78

  
79
        ProjectManager.getInstance().registerDocumentFactory(factory);
80

  
81
        registerIcons();
82

  
83
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
84
        manager.registerFactory(factory);
85

  
86
        if (factory.persistenceDefinition == null) {
87
            DynObjectManager dynman = ToolsLocator.getDynObjectManager();
88
            factory.persistenceDefinition =
89
                dynman.createDynClass(PersistenceManager.PERSISTENCE_NAMESPACE,
90
                    PERSISTENCE_PORTABLEVIEW_DOCUMENT_DEFINITION_NAME,
91
                    "Portable view document Persistence definition");
92

  
93
            factory.persistenceDefinition.addDynFieldString("id").setMandatory(
94
                true);
95
            factory.persistenceDefinition.addDynFieldInt("version")
96
                .setMandatory(true);
97
            factory.persistenceDefinition.addDynFieldInt("buildNumber")
98
                .setMandatory(true);
99
            factory.persistenceDefinition.addDynFieldString("name")
100
                .setMandatory(true);
101
            factory.persistenceDefinition.addDynFieldString("comment")
102
                .setMandatory(false);
103
            factory.persistenceDefinition.addDynFieldObject("sourceView")
104
                .setMandatory(false).setClassOfValue(ViewDocument.class);
105

  
106
        }
107

  
108
    }
109

  
110
    /**
111
     *
112
     */
113
    private static void registerIcons() {
114
        PluginServices.getIconTheme().registerDefault(
115
            "document-portableview-icon",
116
            PortableViewDocumentManager.class.getClassLoader().getResource(
117
                "images/document-portableview-icon.png"));
118
        PluginServices.getIconTheme().registerDefault(
119
            "document-portableview-icon-sel",
120
            PortableViewDocumentManager.class.getClassLoader().getResource(
121
                "images/document-portableview-icon-sel.png"));
122
    }
123

  
124
    /**
125
     *
126
     */
127
    public PortableViewDocumentManager() {
128
        tmSwingManager = PortableViewSwingLocator.getSwingManager();
129
        tmManager = tmSwingManager.getManager();
130
    }
131

  
132
    @Override
133
    public ImageIcon getIcon() {
134
        if (!PluginServices.getIconTheme().exists("document-portableview-icon")) {
135
            registerIcons();
136
        }
137
        return PluginServices.getIconTheme().get("document-portableview-icon");
138
    }
139

  
140
    @Override
141
    public ImageIcon getIconSelected() {
142
        if (!PluginServices.getIconTheme().exists(
143
            "document-portableview-icon-sel")) {
144
            registerIcons();
145
        }
146
        return PluginServices.getIconTheme().get(
147
            "document-portableview-icon-sel");
148
    }
149

  
150
    @Override
151
    public String getTitle() {
152
        return tmSwingManager.getTranslation("Portable_View");
153
    }
154

  
155
    public String getTypeName() {
156
        return TYPENAME;
157
    }
158

  
159
    public AbstractDocument createDocument() {
160
        return new PortableViewDocument(this);
161
    }
162

  
163
    public PortableViewDocument createDocument(PortableView portableView) {
164
        return new PortableViewDocument(this, portableView);
165
    }
166

  
167
    @Override
168
    public AbstractDocument createDocumentByUser() {
169
        Iterator<? extends Document> iterator = createDocumentsByUser();
170
        if (iterator == null || !iterator.hasNext()) {
171
            return null;
172
        }
173
        return (AbstractDocument) iterator.next();
174
    }
175

  
176
    @Override
177
    public Iterator<? extends Document> createDocumentsByUser() {
178
        PortableViewSelector selector =
179
            new PortableViewSelector(this, tmManager.getInstalledMaps());
180
        tmSwingManager.getWindowManager().showWindow(selector,
181
            tmSwingManager.getTranslation("open_portable_view"), MODE.DIALOG);
182

  
183
        if (selector.getDocuments() == null
184
            || selector.getDocuments().isEmpty()) {
185
            return Arrays.asList(new Document[] {}).iterator();
186
        }
187
        return selector.getDocuments().iterator();
188
    }
189

  
190
    public IWindow getMainWindow(Document doc, WindowLayout layout) {
191
        IDocumentWindow portableViewPanel;
192
        portableViewPanel =
193
            (IDocumentWindow) PluginServices.getMDIManager()
194
                .getSingletonWindow(getMainWindowClass(), doc);
195
        if (portableViewPanel != null) {
196
            // The window document is already created, return it.
197
            return portableViewPanel;
198
        }
199

  
200
        portableViewPanel = this.createDocumentWindow(doc);
201
        if (layout != null && portableViewPanel != null) {
202
            portableViewPanel.setWindowLayout(layout);
203
        }
204
        return portableViewPanel;
205
    }
206

  
207
    public IWindow getPropertiesWindow(Document doc) {
208
        PortableViewDocumentProperties propertiesPanel =
209
            (PortableViewDocumentProperties) PluginServices.getMDIManager()
210
                .getSingletonWindow(PortableViewDocumentProperties.class, doc);
211
        if (propertiesPanel != null) {
212
            // The table window document is already created, return it.
213
            return propertiesPanel;
214
        }
215

  
216
        propertiesPanel =
217
            new PortableViewDocumentProperties((PortableViewDocument) doc);
218
        return propertiesPanel;
219
    }
220

  
221
    public Class<? extends IDocumentWindow> getMainWindowClass() {
222
        return PortableViewDocumentViewer.class;
223
    }
224

  
225
    public boolean manages(Object object) {
226
        return object instanceof PortableViewDocument;
227
    }
228

  
229
    public DynStruct getDefinition(String className) {
230
        // TODO review it
231
        if (this.persistenceDefinition.getName().equalsIgnoreCase(className)) {
232
            return this.persistenceDefinition;
233
        }
234
        if (this.persistenceDefinition.getFullName()
235
            .equalsIgnoreCase(className)) {
236
            return this.persistenceDefinition;
237
        }
238
        if (this.getDocumentClass().getName().equals(className)) {
239
            return this.persistenceDefinition;
240
        }
241
        return null;
242
    }
243

  
244
    @SuppressWarnings("rawtypes")
245
    @Override
246
    protected Class getDocumentClass() {
247
        return PortableViewDocument.class;
248
    }
249

  
250
    /**
251
     * Gets the first document which map is the specified
252
     *
253
     * @param curMap
254
     * @return
255
     */
256
    public PortableViewDocument getDocumentForMap(PortableView map) {
257
        if (map == null) {
258
            return null;
259
        }
260
        List<Document> docs = getProject().getDocuments(TYPENAME);
261
        for (Document document : docs) {
262
            if (((PortableViewDocument) document).isMap(map)) {
263
                return (PortableViewDocument) document;
264
            }
265
        }
266
        return null;
267
    }
268

  
269
    /**
270
     * Gets current project
271
     *
272
     * @return
273
     */
274
    private Project getProject() {
275
        return ProjectManager.getInstance().getCurrentProject();
276
    }
277
}
org.gvsig.educa.portableview/tags/org.gvsig.educa.portableview-1.0.90/org.gvsig.educa.portableview.app/org.gvsig.educa.portableview.app.viewer/src/main/java/org/gvsig/educa/portableview/app/viewer/ui/TocImageProvider.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.educa.portableview.app.viewer.ui;
23

  
24
import javax.swing.ImageIcon;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.educa.portableview.swing.viewer.PortableViewTocImageProvider;
28
import org.gvsig.fmap.mapcontext.layers.FLayer;
29
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
30
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
31

  
32
/**
33
 * Image provider for Portable View TOC items
34
 *
35
 * @author gvSIG Team
36
 * @version $Id$
37
 *
38
 */
39
public class TocImageProvider implements PortableViewTocImageProvider {
40

  
41
    public ImageIcon getImageIconForLayer(FLayer layer) {
42
        return PluginServices.getIconTheme().get(layer.getTocImageIcon());
43
    }
44

  
45
    public ImageIcon getSymbolPreview(ISymbol symbol, FLayer sourceLayer) {
46
        // Use default
47
        return null;
48
    }
49

  
50
    public ImageIcon getUnavailableIconForLayer(){
51
    	return PluginServices.getIconTheme().get("layer-unavialable");
52
    }
53

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

  
24
import java.awt.GridLayout;
25
import java.beans.PropertyChangeEvent;
26
import java.beans.PropertyChangeListener;
27
import java.io.IOException;
28

  
29
import javax.help.UnsupportedOperationException;
30
import javax.swing.BorderFactory;
31
import javax.swing.JPanel;
32

  
33
import org.cresques.cts.IProjection;
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.ui.mdiFrame.NewStatusBar;
36
import org.gvsig.andami.ui.mdiManager.IWindowTransform;
37
import org.gvsig.andami.ui.mdiManager.WindowInfo;
38
import org.gvsig.app.project.documents.Document;
39
import org.gvsig.app.project.documents.gui.IDocumentWindow;
40
import org.gvsig.app.project.documents.gui.WindowLayout;
41
import org.gvsig.educa.portableview.app.viewer.PortableViewBasicMapControlExtension;
42
import org.gvsig.educa.portableview.app.viewer.PortableViewDocument;
43
import org.gvsig.educa.portableview.map.CantLoadContextException;
44
import org.gvsig.educa.portableview.map.InvalidPortableViewFormatException;
45
import org.gvsig.educa.portableview.map.PortableView;
46
import org.gvsig.educa.portableview.map.PortableViewInformation;
47
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
48
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
49
import org.gvsig.educa.portableview.swing.viewer.PortableViewViewer;
50
import org.gvsig.fmap.mapcontext.MapContext;
51
import org.gvsig.fmap.mapcontext.events.ColorEvent;
52
import org.gvsig.fmap.mapcontext.events.ExtentEvent;
53
import org.gvsig.fmap.mapcontext.events.ProjectionEvent;
54
import org.gvsig.fmap.mapcontext.events.listeners.ViewPortListener;
55
import org.gvsig.fmap.mapcontrol.MapControl;
56

  
57
/**
58
 * Document Window to show PortableViews
59
 *
60
 * @author gvSIG Team
61
 * @version $Id$
62
 *
63
 */
64
public class PortableViewDocumentViewer extends JPanel implements
65
    IDocumentWindow, IWindowTransform, PropertyChangeListener {
66

  
67
    /**
68
     *
69
     */
70
    private static final long serialVersionUID = 6987853732480183690L;
71

  
72
    private static final int DEFAULT_HEIGHT = 450;
73

  
74
    private static final int DEFAULT_WIDTH = 700;
75

  
76
    private WindowInfo windowInfo;
77
    private final PortableViewDocument model;
78
    private boolean isPalette = false;
79

  
80
    private final PortableViewSwingManager tmSwingManager;
81

  
82
    private PortableViewViewer viewer;
83

  
84
    private String title;
85

  
86
    private ViewPortListener viewPortListener;
87

  
88
    /**
89
     * Default contructor
90
     *
91
     * @throws IOException
92
     * @throws CantLoadContextException
93
     * @throws InvalidPortableViewFormatException
94
     *
95
     */
96
    public PortableViewDocumentViewer(Document document)
97
        throws InvalidPortableViewFormatException, CantLoadContextException,
98
        IOException {
99
        super();
100
        model = (PortableViewDocument) document;
101
        tmSwingManager = PortableViewSwingLocator.getSwingManager();
102
        setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
103
        setLayout(new GridLayout(1, 1));
104

  
105
        model.addPropertyChangeListener(this);
106

  
107
        updateViewer();
108
        updateTitle();
109
    }
110

  
111
    /**
112
     * Gets the title for this window
113
     *
114
     * @return
115
     */
116
    public String getTitle() {
117
        return title;
118
    }
119

  
120
    /**
121
     * Update the panel title
122
     *
123
     */
124
    protected void updateTitle() {
125
        title =
126
            tmSwingManager.getTranslation("Portable_View").concat(": ")
127
                .concat(this.model.getName());
128
        if (windowInfo != null) {
129
            windowInfo.setTitle(title);
130
        }
131
    }
132

  
133
    /**
134
     * Update the view contained in the panel
135
     *
136
     * @throws InvalidPortableViewFormatException
137
     * @throws CantLoadContextException
138
     * @throws IOException
139
     */
140
    protected void updateViewer() throws InvalidPortableViewFormatException,
141
        CantLoadContextException, IOException {
142
        String toolId = null;
143

  
144
        // Remove previous viewer
145
        if (viewer != null) {
146
            // backup current tool
147
            toolId = viewer.getMapControl().getCurrentTool();
148
            remove(viewer.getSwingComponent());
149
            if (viewPortListener != null) {
150
                viewer.getMapControl().getViewPort()
151
                    .removeViewPortListener(viewPortListener);
152
            }
153
            viewer.dispose();
154
            viewer = null;
155
        }
156

  
157
        // create new viewer
158
        viewer = tmSwingManager.getViewer(model.getPortableView());
159
        add(viewer.getSwingComponent());
160
        final MapControl mapControl = viewer.getMapControl();
161

  
162
        // restore tool (if any)
163
        if (toolId != null) {
164
            mapControl.setTool(toolId);
165
        } else {
166
            mapControl.setTool(PortableViewBasicMapControlExtension.TOOL_PAN_ID);
167
        }
168
        if (mapControl.getViewPort() != null) {
169
            viewPortListener = new ViewPortListener() {
170

  
171
                public void extentChanged(ExtentEvent e) {
172
                    if (PluginServices.getMainFrame() != null) {
173
                        NewStatusBar statusBar =
174
                            PluginServices.getMainFrame().getStatusBar();
175
                        statusBar
176
                            .setControlValue("scale", String.valueOf(mapControl
177
                                .getMapContext().getScaleView()));
178
                        statusBar.setMessage("projection", mapControl
179
                            .getViewPort().getProjection().getAbrev());
180
                    }
181
                }
182

  
183
                public void backColorChanged(ColorEvent e) {
184
                    // Do nothing
185
                }
186

  
187
                public void projectionChanged(ProjectionEvent e) {
188
                    // Do nothing
189
                }
190
            };
191
            mapControl.getViewPort().addViewPortListener(viewPortListener);
192
        }
193
    }
194

  
195
    /**
196
     * @return the viewer
197
     */
198
    public PortableViewViewer getViewer() {
199
        return viewer;
200
    }
201

  
202
    /**
203
     * @return the viewer
204
     */
205
    public PortableView getPortableView() {
206
        return viewer.getPortableView();
207
    }
208

  
209
    /**
210
     * @return the viewer
211
     */
212
    public PortableViewInformation getPortableViewInformation() {
213
        return viewer.getPortableView().getInformation();
214
    }
215

  
216
    // IWindow interface
217

  
218
    public WindowInfo getWindowInfo() {
219
        if (windowInfo == null) {
220
            windowInfo =
221
                new WindowInfo(WindowInfo.ICONIFIABLE | WindowInfo.MAXIMIZABLE
222
                    | WindowInfo.RESIZABLE);
223

  
224
            windowInfo.setTitle(getTitle());
225

  
226
            windowInfo.setWidth(DEFAULT_WIDTH);
227
            windowInfo.setHeight(DEFAULT_HEIGHT);
228
        }
229
        return windowInfo;
230
    }
231

  
232
    // SingletonWindow interface
233

  
234
    public Object getWindowModel() {
235
        return this.model;
236
    }
237

  
238
    public void toPalette() {
239
        isPalette = true;
240
        windowInfo.toPalette(true);
241
        windowInfo.setClosed(false);
242
        PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
243
    }
244

  
245
    public void restore() {
246
        isPalette = false;
247
        windowInfo.toPalette(false);
248
        windowInfo.setClosed(false);
249
        PluginServices.getMDIManager().changeWindowInfo(this, getWindowInfo());
250
    }
251

  
252
    public boolean isPalette() {
253
        return isPalette;
254
    }
255

  
256
    public Object getWindowProfile() {
257
        return WindowInfo.EDITOR_PROFILE;
258
    }
259

  
260
    public void windowActivated() {
261
        NewStatusBar statusbar = PluginServices.getMainFrame().getStatusBar();
262
        MapContext mapContext = model.getMapContext();
263

  
264
        statusbar.setMessage("units",
265
            PluginServices.getText(this, mapContext.getDistanceName()));
266
        statusbar.setControlValue("scale",
267
            String.valueOf(mapContext.getScaleView()));
268
        IProjection proj = viewer.getMapControl().getViewPort().getProjection();
269
        if (proj != null) {
270
            statusbar.setMessage("projection", proj.getAbrev());
271
        } else {
272
            statusbar.setMessage("projection", "");
273
        }
274
    }
275

  
276
    public void windowClosed() {
277

  
278
    }
279

  
280
    public WindowLayout getWindowLayout() {
281
        return null;
282
    }
283

  
284
    public void setWindowLayout(WindowLayout layout) {
285

  
286
    }
287

  
288
    public void setDocument(Document document) {
289
        throw new UnsupportedOperationException();
290
    }
291

  
292
    public Document getDocument() {
293
        return model;
294
    }
295

  
296
    public PortableViewDocument getPortableViewDocument() {
297
        return model;
298
    }
299

  
300
    /**
301
     * Changes in source document
302
     *
303
     */
304
    public void propertyChange(PropertyChangeEvent evt) {
305
        if (evt.getPropertyName().equals("name")) {
306
            updateTitle();
307
        } else
308
            if (evt.getPropertyName().equals("portableView")) {
309

  
310
            }
311

  
312
    }
313

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

  
24
import java.awt.BorderLayout;
25
import java.awt.Dimension;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.MouseAdapter;
28
import java.awt.event.MouseEvent;
29
import java.util.ArrayList;
30
import java.util.Collections;
31
import java.util.List;
32

  
33
import javax.swing.AbstractAction;
34
import javax.swing.BorderFactory;
35
import javax.swing.Box;
36
import javax.swing.BoxLayout;
37
import javax.swing.JButton;
38
import javax.swing.JList;
39
import javax.swing.JPanel;
40
import javax.swing.JScrollPane;
41
import javax.swing.ListSelectionModel;
42
import javax.swing.event.ListSelectionEvent;
43
import javax.swing.event.ListSelectionListener;
44

  
45
import org.gvsig.educa.portableview.app.viewer.PortableViewDocument;
46
import org.gvsig.educa.portableview.app.viewer.PortableViewDocumentManager;
47
import org.gvsig.educa.portableview.map.PortableView;
48
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
49
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
50
import org.gvsig.educa.portableview.swing.viewer.PortableViewInforamtionViewer;
51
import org.gvsig.tools.swing.api.ToolsSwingLocator;
52
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
53

  
54
/**
55
 * Open Portable View dialog
56
 * <p>
57
 * Allows user to select one o many Portable view to open
58
 * </p>
59
 *
60
 * @author gvSIG Team
61
 * @version $Id$
62
 *
63
 */
64
public class PortableViewSelector extends JPanel implements
65
		ListSelectionListener {
66

  
67
	/**
68
     *
69
     */
70
	private static final long serialVersionUID = 1L;
71

  
72
	@SuppressWarnings("unused")
73
	private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory
74
			.getLogger(PortableViewSelector.class);
75

  
76
	private final PortableViewSwingManager swingManager;
77
	private final UsabilitySwingManager usabManager;
78

  
79
	private List<PortableView> maps;
80
	private final List<String> mapNames;
81
	private JPanel listPanel;
82
	private JList list;
83
	private JPanel informationPanel;
84
	private PortableViewInforamtionViewer information;
85

  
86
	private JPanel actionPanel;
87
	private JButton botOpen;
88
	private JButton botCancel;
89
	private PortableView lastSelected;
90

  
91
	private int lastSelectedIndex;
92

  
93
	private final PortableViewDocumentManager documentManager;
94

  
95
	private List<PortableViewDocument> documents;
96

  
97
	public PortableViewSelector(PortableViewDocumentManager documentManager,
98
			List<PortableView> installedMaps) {
99
		super();
100

  
101
		this.documentManager = documentManager;
102

  
103
		swingManager = PortableViewSwingLocator.getSwingManager();
104

  
105
		usabManager = ToolsSwingLocator.getUsabilitySwingManager();
106

  
107
		maps = installedMaps;
108
		mapNames = new ArrayList<String>(installedMaps.size());
109
		for (PortableView map : maps) {
110
			mapNames.add(map.getInformation().getName());
111
		}
112
		lastSelected = null;
113
		lastSelectedIndex = -1;
114

  
115
		initializeUI();
116

  
117
	}
118

  
119
	/**
120
	 * Initialize user interface
121
	 *
122
	 */
123
	private void initializeUI() {
124
		setLayout(new BorderLayout(10, 10));
125
		setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
126

  
127
		setMaximumSize(new Dimension(300, 200));
128
		setPreferredSize(new Dimension(800, 600));
129

  
130
		list = new JList(mapNames.toArray());
131
		list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
132
		list.addListSelectionListener(this);
133

  
134
		// Listen to click so it can change map information
135
		list.addMouseListener(new MouseAdapter() {
136

  
137
			@Override
138
			public void mouseClicked(MouseEvent e) {
139
				int itemClicked = -1;
140

  
141
				// check in visible list element which was clicked
142
				int firstVisibleIndex = list.getFirstVisibleIndex();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff