Revision 6477

View differences:

org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.wms</artifactId>
5
	<packaging>pom</packaging>
6
	<version>2.2.46</version>
7
	<name>${project.artifactId}</name>
8
	<description>wms client</description>
9
	<inceptionYear>2011</inceptionYear>
10
	
11
	<parent>
12
      <groupId>org.gvsig</groupId>
13
      <artifactId>org.gvsig.desktop</artifactId>
14
      <version>2.0.164</version>
15
  </parent>
16

  
17
        <properties>
18
            <!-- El plugin versions:use-latest-versions falla con scope import -->
19
            <!-- asi que toca usar el versions:update-properties que si que funciona -->
20
            <org.gvsig.raster.version>2.2.54</org.gvsig.raster.version>
21
        </properties>
22
    
23
    <repositories>
24
      <repository>
25
        <id>gvsig-public-http-repository</id>
26
        <name>gvSIG maven public HTTP repository</name>
27
        <url>http://devel.gvsig.org/m2repo/j2se</url>
28
        <releases>
29
          <enabled>true</enabled>
30
          <updatePolicy>daily</updatePolicy>
31
          <checksumPolicy>warn</checksumPolicy>
32
        </releases>
33
        <snapshots>
34
          <enabled>true</enabled>
35
          <updatePolicy>daily</updatePolicy>
36
          <checksumPolicy>warn</checksumPolicy>
37
        </snapshots>
38
      </repository>
39
    </repositories>
40
    
41
    <scm>
42
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46</connection>
43
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46</developerConnection>
44
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46</url>
45
    </scm>
46
    
47
    <build>
48
        <plugins>
49
            <plugin>
50
                <groupId>org.apache.maven.plugins</groupId>
51
                <artifactId>maven-release-plugin</artifactId>
52
                <configuration>
53
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.wms/tags/</tagBase>
54
                    <goals>deploy</goals>
55
                </configuration>
56
            </plugin>
57
        </plugins>
58
    </build>
59
    
60
    <dependencyManagement>
61
		<dependencies>
62
                        <dependency>
63
                                <groupId>org.gvsig</groupId>
64
                                <artifactId>org.gvsig.raster</artifactId>
65
                                <version>${org.gvsig.raster.version}</version>
66
                                <type>pom</type>
67
                                <scope>import</scope>
68
                        </dependency>
69

  
70
			<dependency>
71
				<groupId>org.gvsig</groupId>
72
				<artifactId>org.gvsig.raster.wms.io</artifactId>
73
				<version>2.2.46</version>
74
			</dependency>
75
			<dependency>
76
				<groupId>org.gvsig</groupId>
77
				<artifactId>org.gvsig.raster.wms.remoteclient</artifactId>
78
				<version>2.2.46</version>
79
			</dependency>
80
			<dependency>
81
				<groupId>org.gvsig</groupId>
82
				<artifactId>org.gvsig.raster.wms.app.wmsclient</artifactId>
83
				<version>2.2.46</version>
84
			</dependency>
85

  
86
		</dependencies>
87
	</dependencyManagement>
88

  
89
	<modules>
90
		<module>org.gvsig.raster.wms.remoteclient</module>
91
		<module>org.gvsig.raster.wms.io</module>
92
		<module>org.gvsig.raster.wms.app.wmsclient</module>
93
	</modules>
94
</project>
95

  
0 96

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46/org.gvsig.raster.wms.app.wmsclient/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

  
26
    <dependencySets>
27
        <dependencySet>
28
            <useProjectArtifact>false</useProjectArtifact>
29
            <useTransitiveDependencies>false</useTransitiveDependencies>
30
            <outputDirectory>lib</outputDirectory>
31
            <includes> 
32
                <include>org.gvsig:org.gvsig.raster.wms.remoteclient:jar</include>
33
                <include>org.gvsig:org.gvsig.raster.wms.io:jar</include>
34
            </includes>
35
        </dependencySet>
36
    </dependencySets>
37
</assembly>
0 38

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/gui/dialog/WMSPropsDialog.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.raster.wms.app.wmsclient.gui.dialog;
24

  
25
import java.awt.Dimension;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Vector;
31

  
32
import javax.swing.JButton;
33
import javax.swing.JDialog;
34
import javax.swing.JOptionPane;
35
import javax.swing.JPanel;
36
import javax.swing.tree.TreePath;
37

  
38
import org.gvsig.andami.PluginServices;
39
import org.gvsig.andami.ui.mdiManager.IWindow;
40
import org.gvsig.andami.ui.mdiManager.WindowInfo;
41
import org.gvsig.app.gui.wizards.WizardListener;
42
import org.gvsig.app.gui.wizards.WizardListenerSupport;
43
import org.gvsig.fmap.dal.coverage.exception.ConnectException;
44
import org.gvsig.fmap.dal.exception.InitializeException;
45
import org.gvsig.fmap.mapcontext.MapContext;
46
import org.gvsig.fmap.mapcontext.exceptions.ConnectionErrorLayerException;
47
import org.gvsig.fmap.mapcontext.exceptions.DriverLayerException;
48
import org.gvsig.fmap.mapcontext.exceptions.LegendLayerException;
49
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException;
50
import org.gvsig.fmap.mapcontext.exceptions.NameLayerException;
51
import org.gvsig.fmap.mapcontext.exceptions.ProjectionLayerException;
52
import org.gvsig.fmap.mapcontext.exceptions.TypeLayerException;
53
import org.gvsig.fmap.mapcontext.exceptions.URLLayerException;
54
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException;
55
import org.gvsig.fmap.mapcontext.layers.FLayer;
56
import org.gvsig.fmap.mapcontext.layers.FLayers;
57
import org.gvsig.fmap.mapcontrol.MapControl;
58
import org.gvsig.raster.fmap.layers.FLyrRaster;
59
import org.gvsig.raster.swing.RasterSwingLibrary;
60
import org.gvsig.raster.util.CancelTaskImpl;
61
import org.gvsig.raster.wms.app.wmsclient.gui.panel.WMSParamsPanel;
62
import org.gvsig.raster.wms.app.wmsclient.gui.wizard.LayerTreeModel;
63
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
64
import org.gvsig.raster.wms.io.RemoteWMSStyle;
65
import org.gvsig.raster.wms.io.WMSLayerNode;
66
import org.gvsig.raster.wms.io.WMSServerExplorer;
67
import org.slf4j.Logger;
68
import org.slf4j.LoggerFactory;
69

  
70

  
71
/**
72
 * The TOC WMS properties panel container.
73
 *
74
 * @author jaume - 
75
 *
76
 */
77
public class WMSPropsDialog extends JPanel implements IWindow {
78

  
79
	private static final long         serialVersionUID    = 1L;
80
	private Logger                   logger              = LoggerFactory.getLogger(WMSPropsDialog.class);
81
	JDialog                           dlg                 = null;  
82
	private JPanel                    buttonsPanel        = null;
83
	private FLyrRaster                fLayer              = null;
84
	boolean                           applied             = false;;
85
	private WindowInfo                m_ViewInfo          = null;
86

  
87
	private JButton                   btnApply            = null;
88
	private JButton                   btnOk               = null;
89
	private JButton                   btnCancel           = null;
90
	private WMSParamsPanel            wmsParamsTabbedPane;
91
    private CommandListener           m_actionListener;
92
    private WMSServerExplorer         explorer            = null;
93

  
94
    public WMSPropsDialog(FLayer layer) {
95
		super();
96
		if(layer instanceof FLyrRaster)
97
			initialize((FLyrRaster)layer);
98
	}
99

  
100

  
101
	private void initialize(FLyrRaster layer) {
102
		setLayout(null);
103

  
104
        setFLayer(layer);
105
        wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties());
106
        wmsParamsTabbedPane.addWizardListener(new WizardListener(){
107
			public void wizardStateChanged(boolean finishable) {
108
				getBtnOk().setEnabled(finishable);
109
				getBtnApply().setEnabled(finishable);
110
			}
111

  
112
			public void error(Exception e) {
113
			}
114

  
115
        })  ;
116
        wmsParamsTabbedPane.disableDisagregatedLayers();
117
        this.add(wmsParamsTabbedPane);
118
        this.add(getButtonsPanel(), null);
119

  
120
	}
121

  
122

  
123
	public void setFLayer(FLyrRaster f) {
124
		fLayer = f;
125
	}
126

  
127
	/**
128
	 * With getParamsPanel we have access to the map config TabbedPane.
129
	 * If this panel doesn't exist yet (which can occur when an existing project is
130
	 * recovered) it is been automatically constructed by connecting to the server,
131
	 * reloading the necessary data, filling up the content and setting the selected
132
	 * values that were selected when the projet was saved.
133
	 *
134
	 *
135
	 * Since a connection to the server is needed when rebuiliding the panel, this
136
	 * causes a delay for the panel's showing up or a nullPointer error if there is
137
	 * no path to the server.
138
	 *
139
	 *
140
	 * Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
141
	 * del mapa. Si este panel todav?a no existe (como puede ser cuando
142
	 * recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
143
	 * al servidor, recuperando los datos necesarios, rellenando el contenido y
144
	 * dejando seleccionados los valores que estaban seleccionados cuando se
145
	 * guarda el proyecto.
146
	 *
147
	 *
148
	 * Como para reconstruirse requiere una conexi?n con el servidor esto causa
149
	 * un retardo en la aparici?n en el toc o un error de nullPointer si no
150
	 * hay conexi?n hasta el servidor.
151
	 *
152
	 *
153
	 * @return WMSParamsPanel
154
	 */
155
	@SuppressWarnings({ "unchecked" })
156
	public WMSParamsPanel getParamsPanel(HashMap info) {
157
	    if (info != null) {
158
	    	try {
159
	    		if(explorer == null) {
160
					explorer = ((FLyrWMS)fLayer).getExplorer();
161
					
162
					try {
163
			    		explorer.connect(new CancelTaskImpl(), true);
164
					} catch (ConnectException e) {
165
						RasterSwingLibrary.messageBoxError("The connection cannot be established", this, e);
166
						return null;
167
					} 
168
	    		}
169
	    	} catch (Exception e) {
170
	    		explorer = null;
171
	    		JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE);
172
	    	}
173
	    	try {
174
	        	
175
                // name
176
	            WMSParamsPanel toc = new WMSParamsPanel();
177
	            toc.setLayerName((String)info.get("name"));
178
	            toc.setWizardData(explorer);
179

  
180
	            toc.setVisible(true);
181
	            toc.setListenerSupport(new WizardListenerSupport());
182

  
183
	            WMSLayerNode[] selectedLayers = (WMSLayerNode[]) ((Vector) info.get("selectedLayers")).toArray(new WMSLayerNode[0]);
184
	            for (int i = 0; i < selectedLayers.length; i++) {
185
	            	toc.getJustTreeLayer().clearSelection();
186
	            	//  Se a?ade a la lista de layers seleccionados
187
	            	TreePath path = new TreePath(((LayerTreeModel)toc.getJustTreeLayer()
188
	            						.getModel()).getNodeByName(selectedLayers[i].getName()));
189
	            	toc.getJustTreeLayer().addSelectionPath(path);
190
	            	toc.addLayer();
191
                }
192

  
193
                // srs
194
                String srs = (String) info.get("srs");
195
                int index = toc.getSRSIndex( srs );
196
	            if (index != -1) {
197
					toc.getLstSRSs().setSelectedIndex(index);
198
				}
199

  
200
                // format
201
	            String format = (String) info.get("format");
202
	            index = toc.getFormatIndex(format);
203
	            if (index != -1) {
204
					toc.getLstFormats().setSelectedIndex(index);
205
				}
206
	            
207
	            //info format
208
	            String infoFormat = (String) info.get("infoformat");
209
	            index = toc.getInfoFormatIndex(infoFormat);
210
	            if (index != -1) {
211
					toc.getLstInfoFormats().setSelectedIndex(index);
212
				}
213

  
214
	            // transparency
215
                toc.setTransparent(((Boolean) info.get("wmsTransparency")).booleanValue());
216

  
217
                // styles
218
                List<RemoteWMSStyle> l = (List<RemoteWMSStyle>) info.get("styles");
219
                if (l != null && l.size() > 0) {
220
					toc.setStyleSelections(l);
221
				}
222

  
223
                // dimensions
224
                Vector v = (Vector) info.get("dimensions");
225
                if (v != null) {
226
					toc.setDimensions(v);
227
				}
228

  
229
                // fixed sizes
230
                Dimension sz = (Dimension) info.get("fixedSize");
231
                if (sz != null) {
232
					toc.setFixedSize(sz);
233
				}
234
                toc.refreshInfo();
235
                applied = false;
236
	            return toc;
237
	        } catch (Exception e) {
238
	        	JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE);
239
	        }
240
	    }
241
	    return null;
242
	}
243

  
244

  
245
	public JPanel getButtonsPanel() {
246
		if (buttonsPanel == null) {
247
			m_actionListener = new CommandListener(this);
248
			buttonsPanel = new JPanel();
249
	        buttonsPanel.setBounds(5, wmsParamsTabbedPane.getHeight(), 471, 40);
250
			buttonsPanel.setLayout(null);
251
			buttonsPanel.setName("buttonPanel");
252

  
253
	        buttonsPanel.add(getBtnOk(), null);
254
	        buttonsPanel.add(getBtnApply(), null);
255
	        buttonsPanel.add(getBtnCancel(), null);
256
		}
257
		return buttonsPanel;
258
	}
259

  
260
	public JButton getBtnOk() {
261
		if (btnOk == null) {
262
	        btnOk = new JButton("ok");
263
	        btnOk.setText(PluginServices.getText(this,"ok"));
264
	        btnOk.setActionCommand("OK");
265
	        btnOk.addActionListener(m_actionListener);
266
	        btnOk.setBounds(367, 9, 90, 25);
267
		}
268
		return btnOk;
269
	}
270

  
271
	public JButton getBtnApply() {
272
		if (btnApply == null) {
273
	        btnApply = new JButton("apply");
274
	        btnApply.setText(PluginServices.getText(this,"apply"));
275
	        btnApply.setEnabled(false);
276
	        btnApply.setActionCommand("APPLY");
277
	        btnApply.addActionListener(m_actionListener);
278
	        btnApply.setBounds(267, 9, 90, 25);
279
		}
280
		return btnApply;
281
	}
282

  
283
	public JButton getBtnCancel() {
284
		if (btnCancel == null) {
285
	        btnCancel = new JButton("cancel");
286
	        btnCancel.setText(PluginServices.getText(this,"cancel"));
287
	        btnCancel.setActionCommand("CANCEL");
288
	        btnCancel.addActionListener(m_actionListener);
289
	        btnCancel.setBounds(137, 9, 90, 25);
290
		}
291
		return btnCancel;
292
	}
293

  
294
    private class CommandListener implements ActionListener {
295

  
296
        /**
297
         * Creates a new ComandosListener object.
298
         *
299
         * @param lg DOCUMENT ME!
300
         */
301
        public CommandListener(WMSPropsDialog tp) {
302
            //m_tp = tp;
303
        }
304

  
305
		@SuppressWarnings({ "unchecked" })
306
		public void actionPerformed(ActionEvent e) {
307
            if (e.getActionCommand() == "CANCEL") {
308
				close();
309
			} else {
310
            	/*try {
311
					((FLyrWMS) fLayer).setFullExtent(wmsParamsTabbedPane.getLayersRectangle());
312
				} catch (ProjectionLayerException ex) {
313
					ex.printStackTrace();
314
			        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), ex.getMessage());
315
			        return;
316
				}*/
317
				((FLyrWMS) fLayer).getParameters().setFormat(wmsParamsTabbedPane.getFormat());
318
				((FLyrWMS) fLayer).getParameters().setInfoFormat(wmsParamsTabbedPane.getInfoFormat());
319
                try {
320
                if (!wmsParamsTabbedPane.getDisagregatedLayers()) {
321
					((FLyrWMS) fLayer).getParameters().setLayerQuery(wmsParamsTabbedPane.getLayersQuery());
322
				}
323
                ((FLyrWMS) fLayer).getParameters().setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery());
324
                ((FLyrWMS) fLayer).getParameters().setSRS(wmsParamsTabbedPane.getSRS());
325
                ((FLyrWMS) fLayer).getParameters().setName(wmsParamsTabbedPane.getLayerName());
326
                ((FLyrWMS) fLayer).getParameters().setWmsTransparency(wmsParamsTabbedPane.getTransparency());
327
                ((FLyrWMS) fLayer).getParameters().setStyles(wmsParamsTabbedPane.getStyles());
328
                ((FLyrWMS) fLayer).getParameters().setDimensions(wmsParamsTabbedPane.getDimensions());
329
                ((FLyrWMS) fLayer).getParameters().setFixedSize(wmsParamsTabbedPane.getFixedSize());
330

  
331
            	//fLayer = wmsParamsTabbedPane.getLayer();
332
            	FLayers parent = ((FLayer)fLayer).getParentLayer();
333

  
334
                if (e.getActionCommand() == "APPLY"){
335
                	MapControl mapCtrl = null;
336
                	
337
                	IWindow[] w = PluginServices.getMDIManager().getAllWindows();
338
                	for (int i = 0; i < w.length; i++) {
339
						if (w[i] instanceof org.gvsig.app.project.documents.view.gui.AbstractViewPanel) {
340
							MapContext mapContext = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl().getMapContext();
341
							if(mapContext == fLayer.getMapContext())
342
								mapCtrl = ((org.gvsig.app.project.documents.view.gui.AbstractViewPanel)w[i]).getMapControl();
343
						}
344
					} 
345

  
346
                    if (parent != null) {
347
                    	if ( wmsParamsTabbedPane.getLayer() instanceof FLayers){
348
							mapCtrl.getMapContext().getLayers().
349
							replaceLayer(parent.getName(),mergeFLayers(parent,(FLayers)wmsParamsTabbedPane.getLayer()));
350
                    	}
351
                    }
352
                    else {
353
                    	mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wmsParamsTabbedPane.getLayer());
354
                    }
355
                    //mapCtrl.getMapContext().getLayers().addLayer( fLayer );
356
                    mapCtrl.getMapContext().invalidate();
357
                    applied = true;
358
                    getBtnApply().setEnabled(!applied);
359
                }
360
                if (e.getActionCommand() == "OK") {
361
                    if (!applied) {
362

  
363
                        org.gvsig.app.project.documents.view.gui.AbstractViewPanel vista = (org.gvsig.app.project.documents.view.gui.AbstractViewPanel) PluginServices.getMDIManager().getActiveWindow();
364
                        MapControl mapCtrl = vista.getMapControl();
365

  
366
                        if (parent != null){
367
                        	if ( wmsParamsTabbedPane.getLayer() instanceof FLayers){
368
                        		mapCtrl.getMapContext().getLayers().
369
                        		replaceLayer(parent.getName(),mergeFLayers(parent,(FLayers)wmsParamsTabbedPane.getLayer()));
370
                        	}
371
                        }
372
                        else {
373
                        	mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), wmsParamsTabbedPane.getLayer());
374
                        }                        mapCtrl.getMapContext().invalidate();
375
                    }
376
                    close();
377
                }
378
                } catch (ConnectionErrorLayerException e1) {
379
                	logger.info("", e1);
380
    			} catch (DriverLayerException e1) {
381
    				logger.info("", e1);
382
    			} catch (LegendLayerException e1) {
383
    				logger.info("", e1);
384
    			} catch (NameLayerException e1) {
385
    				logger.info("", e1);
386
    			} catch (ProjectionLayerException e1) {
387
    				logger.info("", e1);
388
    			} catch (TypeLayerException e1) {
389
    				logger.info("", e1);
390
    			} catch (UnsupportedVersionLayerException e1) {
391
    				logger.info("", e1);
392
    			} catch (URLLayerException e1) {
393
    				logger.info("", e1);
394
    			} catch (LoadLayerException e1) {
395
    				logger.info("", e1);
396
    			} catch (InitializeException e1) {
397
					logger.info("", e1);
398
				}
399
            }
400
		}
401
    }
402
    /**
403
     * Merge two FLayers in one
404
     * @param group1
405
     * @param group2
406
     * @return
407
     */
408
    private FLayers mergeFLayers(FLayers group1, FLayers group2)
409
    {
410
    	//FLayers agrupation = new FLayers(group1.getFMap(), group1.getParentLayer());
411
    	FLayer layer;
412
    	for(int i = 0; i < group2.getLayersCount(); i++)
413
    	{
414
    		layer = group2.getLayer( i );
415
    		if(group1.getLayer( layer.getName()) == null ){
416
    			group1.addLayer( layer );
417
    		}
418
    	}
419

  
420
    	return group1;
421
    }
422

  
423

  
424

  
425
	public WindowInfo getWindowInfo() {
426
		if (m_ViewInfo==null){
427
			m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
428
			m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WMS_layer"));
429
	        m_ViewInfo.setWidth(wmsParamsTabbedPane.getWidth()+10);
430
	        m_ViewInfo.setHeight(wmsParamsTabbedPane.getHeight()+40);
431

  
432
		}
433
		return m_ViewInfo;
434
	}
435

  
436
	public void close() {
437
		PluginServices.getMDIManager().closeWindow(this);
438
	}
439

  
440

  
441
	public Object getWindowProfile() {
442
		return WindowInfo.DIALOG_PROFILE;
443
	}
444

  
445
}  //  @jve:decl-index=0:visual-constraint="10,10"
0 446

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/gui/panel/InfoPanel.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.raster.wms.app.wmsclient.gui.panel;
24

  
25
import java.util.Vector;
26

  
27
import javax.swing.JEditorPane;
28
import javax.swing.JPanel;
29
import javax.swing.JScrollPane;
30

  
31
import org.gvsig.andami.PluginServices;
32
import org.gvsig.raster.wms.io.WMSLayerNode;
33
import org.gvsig.raster.wms.io.WMSServerExplorer;
34

  
35

  
36
/**
37
 * Service Information Panel
38
 */
39

  
40
class InfoPanel extends JPanel {
41
	private static final long serialVersionUID = 1L;
42
	private final String bgColor0 = "\"#FEEDD6\""; // light salmon
43
    private final String bgColor1 = "\"#EAEAEA\""; // light grey
44
    //private final String bgColor2 = "\"#F2FEFF\""; // light blue
45
    private final String bgColor3 = "\"#FBFFE1\""; // light yellow
46

  
47
    private final String service_title       = PluginServices.getText(this, "service_info");
48
    private final String server              = PluginServices.getText(this, "server");
49
    private final String server_type         = PluginServices.getText(this, "server_type");
50
    private final String server_abstract     = PluginServices.getText(this, "server_abstract");
51
    private final String server_title        = PluginServices.getText(this, "server_title");
52
    private final String layers_title        = PluginServices.getText(this, "selected_layers");
53
    private final String layer_title         = PluginServices.getText(this, "layer_title");
54
    private final String layer_abstract      = PluginServices.getText(this, "layer_abstract");
55
    private final String selected_dimensions = PluginServices.getText(this, "selected_dimensions");
56
    private final String style               = PluginServices.getText(this, "style");
57
    private final String format_title        = PluginServices.getText(this, "format");
58
    private final String infoformat_title    = PluginServices.getText(this, "infoformat");
59
    private final String srs_title           = "SRS";
60
    private final String properties			 = PluginServices.getText(this, "properties");
61
    private final String layer_name			 = PluginServices.getText(this, "name");
62
	private JEditorPane editor = null;
63

  
64

  
65
    /**
66
     * Creates a new instance of InfoPanel with double buffer and null layout
67
     *
68
     */
69
	public InfoPanel() {
70
		super();
71
        setLayout(null);
72
        JScrollPane src = new JScrollPane();
73
        src.setBounds(5, 5, 485, 375);
74
        add(src, null);
75
        src.setViewportView(getEditor());
76
	}
77

  
78
    /**
79
     * This method initializes tblInfo
80
     *
81
     * @return javax.swing.JTable
82
     */
83
    private JEditorPane getEditor() {
84
        if (editor == null) {
85
            editor = new JEditorPane();
86
            editor.setEditable(false);
87
        }
88
        return editor;
89
    }
90

  
91

  
92
    /**
93
     * Fills the text pane with a data table describing the service and the
94
     * selected settings.
95
     *
96
     * @param dataSource
97
     */
98
    @SuppressWarnings("unchecked")
99
	public void refresh(WMSServerExplorer dataSource, 
100
			Vector layers, 
101
			Vector styles, 
102
			String format, 
103
			String infoFormat, 
104
			String srs, 
105
			Vector dimensions) {
106

  
107
        String server_text = dataSource.getHost();
108
        String server_type_text = dataSource.getServerType();
109
        String server_title_text = dataSource.getTitle();
110
        String server_abstract_text = dataSource.getAbstract();
111
        String font = "Arial";
112

  
113
        if (server_text == null)
114
            server_text = "-";
115
        if (server_type_text == null)
116
            server_type_text = "-";
117
        if (server_title_text == null)
118
            server_title_text = "-";
119
        if (server_abstract_text == null)
120
            server_abstract_text = "-";
121

  
122
        if (format == null)
123
            format = PluginServices.getText(this, "none_selected");
124
        if (srs == null)
125
            srs = PluginServices.getText(this, "none_selected");
126

  
127
        String layers_html = "";
128
        for (int i = 0; i < layers.size(); i++) {
129
        	WMSLayerNode layer = (WMSLayerNode) layers.get(i);
130
            String layer_name_text = layer.getName();
131
            String style_title = (styles==null) ? PluginServices.getText(this, "not_available") : (String) styles.get(i);//((FMapWMSStyle) selectedStyles.get(i)).title;
132
            String layer_abstract_text = layer.getAbstract();
133
            String layer_title_text = layer.getTitle();
134

  
135
            if (layer_name_text ==null)
136
            	layer_name_text = "-";
137
            if (style_title==null)
138
            	style_title = "-";
139
            if (layer_abstract_text==null)
140
            	layer_abstract_text = "-";
141
            if (layer_title_text == null)
142
            	layer_title_text = "-";
143
            String layer_html =
144
            	"  <tr valign=\"top\">" +
145
                "     <td bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+layer_name+"</b></font></td>" +
146
                "     <td bgcolor="+bgColor0+"><font face=\"Arial\" size=\"3\">"+layer_name_text+"</font></td>" +
147
                "  </tr>" +
148
                "  <tr valign=\"top\">" +
149
                "     <td width=\"119\" height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"Arial\" size=\"3\"><b>"+layer_title+"</b></font></td>" +
150
                "     <td width=\"322\" height=\"18\" bgcolor="+bgColor1+"><font face=\"Arial\" size=\"3\">"+layer_title_text+"</font></td>" +
151
                "  </tr>" +
152
                "  <tr valign=\"top\">" +
153
                "     <td bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+layer_abstract+"</b></font></td>" +
154
                "     <td bgcolor="+bgColor0+"><font face=\"Arial\" size=\"3\">"+layer_abstract_text+"</font></td>" +
155
                "  </tr>" +
156
                "  <tr valign=\"top\">" +
157
                "     <td bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"Arial\" size=\"3\" align=\"right\"><b>"+style+"</b></font></td>" +
158
                "     <td bgcolor="+bgColor1+"><font face=\"Arial\" size=\"3\">"+style_title+"</font></td>" +
159
                "  </tr>" +
160
                "  <tr>" +
161
                "  </tr>";
162
            layers_html += layer_html;
163
        }
164
        if (!layers_html.equals(""))
165
            layers_html =
166
                "  <tr valign=\"top\" bgcolor=\"#FFFFFF\">" +
167
                "    <td width=\"92\" height=\"18\" bgcolor="+bgColor3+" colspan=\"2\"><font face=\""+font+"\" size=\"4\"><b>"+layers_title+"</font></b></td>" +
168
                "  </tr>" + layers_html;
169
        String dimension_html = "";
170
        if (dimensions != null) {
171
        	boolean swap = false;
172
        	for (int i = 0; i < dimensions.size(); i++) {
173
        		String color = swap ? bgColor0 : bgColor1;
174
        		String[] dimension = ((String) dimensions.get(i)).split("=");
175
        		dimension_html +=
176
        			"  <tr valign=\"top\" bgcolor=" + color + ">" +
177
        			"    <td width=\"120\" height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><b>" + dimension[0] + "</b></td>" +
178
        			"    <td width=\"322\" height=\"18\">" + dimension[1] + "</td>" +
179
        			"  </tr>";
180
        		swap = !swap;
181
        	}
182
        }
183
        if (!dimension_html.equals(""))
184
        	dimension_html =
185
        		"  <tr valign=\"top\">" +
186
        		"    <td width=\"92\" height=\"18\" bgcolor=" + bgColor3 + " colspan=\"2\"><font face=\"" + font + "\" size=\"4\"><b>" + selected_dimensions + "</font></b></td>" +
187
        		"  </tr>" + dimension_html;
188

  
189
        String format_html =
190
        	"  <tr valign=\"top\" bgcolor=\"#FFFFFF\">" +
191
            "    <td width=\"92\" height=\"18\" bgcolor=" + bgColor3 + " colspan=\"2\"><font face=\"" + font + "\" size=\"4\"><b>" + properties + "</font></b></td>" +
192
            "  </tr>" +
193
            "  <tr valign=\"top\" bgcolor=" + bgColor0 + ">" +
194
            "    <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"" + font + "\" size=\"3\"><b>" + format_title + "</b></font></td>" +
195
            "    <td><font face=\"" + font + "\" size=\"3\"><font face=\"" + font + "\" size=\"3\">" + format + "</font></td>" +
196
            "  </tr>" +
197
            "  <tr valign=\"top\" bgcolor=" + bgColor1 + ">" +
198
            "    <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"" + font + "\" size=\"3\"><b>" + srs_title + "</font></b></td>" +
199
            "    <td><font face=\"" + font + "\" size=\"3\">" + srs + "</font></td>" +
200
            "  </tr>" +
201
            "  <tr valign=\"top\" bgcolor=" + bgColor0 + ">" +
202
            "    <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"" + font + "\" size=\"3\"><b>" + infoformat_title + "</font></b></td>" +
203
            "    <td><font face=\"" + font + "\" size=\"3\">" + infoFormat + "</font></td>" +
204
            "  </tr>";
205

  
206
        String html =
207

  
208
            "<html>" +
209
            "<body>" +
210
            "<table align=\"center\" width=\"437\" height=\"156\" border=\"0\" cellpadding=\"4\" cellspacing=\"4\">" +
211
            "  <tr valign=\"top\" bgcolor=\"#FFFFFF\">" +
212
            "    <td width=\"92\" height=\"18\" bgcolor=" + bgColor3 + " colspan=\"2\"><font face=\"" + font + "\" size=\"4\"><b>"+service_title+"</font></b></td>" +
213
            "  </tr>" +
214
            "  <tr valign=\"top\" bgcolor=" + bgColor0 + ">" +
215
            "    <td width=\"92\" height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"" + font + "\" size=\"3\"><b>"+server+"</font></b></td>" +
216
            "    <td width=\"268\"><font face=\"" + font + "\" size=\"3\">" + server_text + "</font></td>" +
217
            "  </tr>" +
218
            "  <tr valign=\"top\" bgcolor=" + bgColor1 + ">" +
219
            "    <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"" + font + "\" size=\"3\"><b>" + server_type + "</b></font></td>" +
220
            "    <td><font face=\"" + font + "\" size=\"3\">" + server_type_text + "</font></td>" +
221
            "  </tr>" +
222
            "  <tr valign=\"top\" bgcolor=" + bgColor0 + ">" +
223
            "    <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"" + font + "\" size=\"3\"><b>" + server_title + "</b></font></td>" +
224
            "    <td><font face=\"" + font+  "\" size=\"3\"><font face=\"" + font + "\" size=\"3\">" + server_title_text + "</font></td>" +
225
            "  </tr>" +
226
            "  <tr valign=\"top\" bgcolor=" + bgColor1 + ">" +
227
            "    <td height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\"" + font + "\" size=\"3\"><b>" +  server_abstract + "</font></b></td>" +
228
            "    <td><font face=\"" + font + "\" size=\"3\">" + server_abstract_text + "</font></td>" +
229
            "  </tr>" +
230

  
231
            "  <tr>" +
232
            "  </tr>" +
233
            layers_html +
234
            dimension_html +
235
            format_html +
236
            "</table>" +
237
            "</body>" +
238
            "</html>";
239

  
240
        getEditor().setContentType("text/html");
241
        getEditor().setText(html);
242
    }
243
}
0 244

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/gui/panel/LayerTree.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.raster.wms.app.wmsclient.gui.panel;
24

  
25
import java.awt.Component;
26

  
27
import javax.swing.JToolTip;
28
import javax.swing.JTree;
29
import javax.swing.ToolTipManager;
30
import javax.swing.tree.DefaultTreeCellRenderer;
31

  
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.gui.beans.controls.MultiLineToolTip;
34
import org.gvsig.raster.wms.io.WMSLayerNode;
35

  
36

  
37
/**
38
 * LayerTree extends the standard JTree class to allow use custom tooltips.
39
 * It is just JTree containing RemoteLayerNode at its nodes.
40
 * 
41
 * @author jaume
42
 *
43
 */
44
public class LayerTree extends JTree {
45
	public boolean showLayerNames = false;
46
	private int count = 0;
47
	public LayerTree(){
48
        super();
49
        ToolTipManager.sharedInstance().registerComponent(this);
50
        ToolTipManager.sharedInstance().setDismissDelay(60*1000);
51
        setCellRenderer(new MyRenderer());
52
    }
53

  
54
    /**
55
     * Layer tree specific renderer allowing to show multiple line
56
     * tooltips 
57
     * @author jaume
58
     *
59
     */
60
    private class MyRenderer extends DefaultTreeCellRenderer {
61
       
62
        
63
       public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
64
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
65
            if (value instanceof WMSLayerNode){
66
            	WMSLayerNode layer = (WMSLayerNode) value;
67
                
68
                String myLatLonTxt = layer.getLatLonBox();
69
                if (myLatLonTxt == null)
70
                    myLatLonTxt = "-";
71
                
72
                String myAbstract = layer.getAbstract();
73
                
74
                if (myAbstract == null)
75
                    myAbstract = "-";
76
                else 
77
                    myAbstract = format(myAbstract.trim(), 100);
78
                
79
                String text =
80
                    PluginServices.getText(this, "abstract") + ":\n" + myAbstract +
81
                    "\n\n" +
82
                    PluginServices.getText(this, "covered_extension") + ":\n" + myLatLonTxt;
83
                
84
                setToolTipText(text);
85
                
86
                if (!showLayerNames) {
87
                	if (layer.getName() != null || layer.getName() == "") {
88
                		text = layer.toString();
89
                		text = text.substring(text.indexOf(']')+2, text.length());
90
                		setText(text);
91
                	}
92
                }
93
                
94
//                Dimension sz  = getPreferredSize();
95
//                sz.setSize((sz.getWidth()+50) - (3*count), sz.getHeight());
96
//                setPreferredSize(sz);
97
//                count++;
98
                
99
            } else {
100
                setToolTipText(null);
101
            }
102
            return this;
103
        }
104
    }
105
    
106
    
107
    /**
108
     * Cuts the message text to force its lines to be shorter or equal to 
109
     * lineLength.
110
     * @param message, the message.
111
     * @param lineLength, the max line length in number of characters.
112
     * @return the formated message.
113
     */
114
    public static String format(String message, int lineLength){
115
        if (message.length() <= lineLength) return message;
116
        String[] lines = message.split("\n");
117
        String theMessage = "";
118
        for (int i = 0; i < lines.length; i++) {
119
            String line = lines[i].trim();
120
            if (line.length()<lineLength)
121
                theMessage += line+"\n";
122
            else {
123
                String[] chunks = line.split(" ");
124
                String newLine = "";
125
                for (int j = 0; j < chunks.length; j++) {
126
                    int currentLength = newLine.length();
127
                    chunks[j] = chunks[j].trim();
128
                    if (chunks[j].length()==0)
129
                        continue;
130
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
131
                        newLine += chunks[j] + " ";
132
                    else {
133
                        newLine += "\n"+chunks[j]+" ";
134
                        theMessage += newLine;
135
                        newLine = "";
136
                    }
137
                }
138
            }
139
        }
140
        return theMessage;
141
    }
142
    
143
    public JToolTip createToolTip() {
144
    	MultiLineToolTip tip = new MultiLineToolTip();
145
    	tip.setComponent(this);
146
    	return tip;
147
    }
148
}
0 149

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/gui/panel/WebMapContextFileChooserAccessory.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.raster.wms.app.wmsclient.gui.panel;
24

  
25
import java.awt.Dimension;
26
import java.util.List;
27

  
28
import javax.swing.JComboBox;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31

  
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.app.project.ProjectManager;
34
import org.gvsig.app.project.documents.Document;
35
import org.gvsig.app.project.documents.view.DefaultViewDocument;
36
import org.gvsig.app.project.documents.view.ViewManager;
37
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
38

  
39

  
40
public class WebMapContextFileChooserAccessory extends JPanel {
41
	public static int NEW_VIEW = -1;
42
	public static int CURRENT_VIEW = -1;
43
	public static int USERS_VIEW_SELECTION = -1;
44

  
45
	private JComboBox cmbMode = null;
46
	private JComboBox cmbViews = null;
47
	private JLabel lblExplain = null;
48
	private String currentView = null;
49

  
50
	public WebMapContextFileChooserAccessory(String currentViewName) {
51
		super();
52
		currentView = currentViewName;
53
		initialize();
54
	}
55

  
56
	private void initialize() {
57
		lblExplain = new JLabel();
58
		lblExplain.setBounds(25, 52, 268, 55);
59
		lblExplain.setText(PluginServices.getText(this, "html_in_a_new_view"));
60
		setLayout(null);
61
		setSize(315, 240);
62
		setPreferredSize(new Dimension(315, 72));
63
		this.add(getCmbViews(), null);
64
		this.add(lblExplain, null);
65
		setBorder(javax.swing.BorderFactory.createTitledBorder(
66
				  null, PluginServices.getText(this, "open_layers_as"),
67
				  javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
68
				  javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
69
		this.add(getCmbMode(), null);
70
	}
71

  
72
	/**
73
	 * This method initializes cmbBoxMode
74
	 *
75
	 * @return javax.swing.JComboBox
76
	 */
77
	private JComboBox getCmbMode() {
78
		if (cmbMode == null) {
79
			cmbMode = new JComboBox();
80
			cmbMode.setBounds(25, 26, 268, 20);
81
			cmbMode.removeAllItems();
82
			cmbMode.addItemListener(new java.awt.event.ItemListener() {
83
				public void itemStateChanged(java.awt.event.ItemEvent e) {
84
					cmbViews.setVisible(false);
85

  
86
					if (cmbMode.getSelectedIndex() == NEW_VIEW) {
87
						lblExplain.setText(PluginServices.getText(this, "html_in_a_new_view"));
88
					} else if (cmbMode.getSelectedIndex() == CURRENT_VIEW) {
89
						lblExplain.setText(PluginServices.getText(this, "html_in_the_current_view"));
90
					} else if (cmbMode.getSelectedIndex() == USERS_VIEW_SELECTION) {
91
						lblExplain.setText(PluginServices.getText(this, "html_in_other_view"));
92
						cmbViews.setVisible(true);
93
					}
94
				}
95
			});
96
			cmbMode.addItem(PluginServices.getText(this, "a_new_view"));
97
			if (currentView!=null) {
98
				cmbMode.addItem(PluginServices.getText(this, "layers_in_the_current_view")+": "+currentView);
99
				CURRENT_VIEW = cmbMode.getItemCount()-1;
100
				cmbMode.setSelectedIndex(CURRENT_VIEW);
101
			}
102
			if (getCmbViews().getItemCount()>0) {
103
				cmbMode.addItem(PluginServices.getText(this, "layers_in_other_view"));
104
				USERS_VIEW_SELECTION = cmbMode.getItemCount() -1;
105
			}
106
		}
107

  
108
		return cmbMode;
109
	}
110

  
111
	public void setCurrentView(AbstractViewPanel v) {
112
		currentView = v.getName();
113
	}
114

  
115
	public DefaultViewDocument getSelectedView() {
116
		String viewName = null;
117
		if (getCmbMode().getSelectedIndex() == NEW_VIEW)
118
			return null;
119
		else if (getCmbMode().getSelectedIndex() == CURRENT_VIEW)
120
			viewName = currentView;
121
		else if (getCmbMode().getSelectedIndex() == USERS_VIEW_SELECTION)
122
			viewName = (String) getCmbViews().getSelectedItem();
123
		return (DefaultViewDocument) ProjectManager.getInstance().getCurrentProject().getDocument(viewName, ViewManager.TYPENAME);
124
//		ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
125
//		return (ProjectView) pe.getProject().getProjectDocumentByName(viewName, ProjectViewFactory.registerName);
126
	}
127

  
128
	public int getOption() {
129
		return cmbMode.getSelectedIndex();
130
	}
131

  
132
	/**
133
	 * This method initializes cmbViews
134
	 *
135
	 * @return javax.swing.JComboBox
136
	 */
137
	private JComboBox getCmbViews() {
138
		if (cmbViews == null) {
139
			cmbViews = new JComboBox();
140
			cmbViews.setBounds(25, 114, 266, 20);
141
			List<Document> views = ProjectManager.getInstance().getCurrentProject().getDocuments( ViewManager.TYPENAME);
142
			for (Document v : views) {
143
				cmbViews.addItem(v.getName());
144
			}
145
			
146
//			ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
147
//			ArrayList views = pe.getProject().getDocumentsByType(ProjectViewFactory.registerName);
148
//			for (int i = 0; i < views.size(); i++) {
149
//				ProjectView v = (ProjectView)views.get(i);
150
//				cmbViews.addItem(v.getName());
151
//			}
152
		}
153
		return cmbViews;
154
	}
155
}  //  @jve:decl-index=0:visual-constraint="10,0"
0 156

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.46/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/gui/panel/StyleTree.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.raster.wms.app.wmsclient.gui.panel;
24

  
25
import java.awt.Color;
26
import java.awt.Component;
27
import java.util.ArrayList;
28
import java.util.Vector;
29

  
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JRadioButton;
33
import javax.swing.JTree;
34
import javax.swing.event.TreeModelListener;
35
import javax.swing.tree.DefaultTreeCellRenderer;
36
import javax.swing.tree.TreeModel;
37
import javax.swing.tree.TreePath;
38

  
39
import org.gvsig.fmap.dal.coverage.RasterLocator;
40
import org.gvsig.raster.wms.io.RemoteWMSStyle;
41
import org.gvsig.raster.wms.io.WMSLayerNode;
42

  
43

  
44
/**
45
 * This class holds a visual tree that handles the selection of the styles in the
46
 * selected layers. It encapsulates any gui interface handling the mouse selection.
47
 * <p>
48
 * It has a method getStylesSelection that returns the current selection in a 
49
 * bi-dimensional string array containing the layer name and the selected style name.
50
 * </p>
51
 * <p>
52
 * Keep in mind that although it's similar to LayersTree it is not the same.
53
 * It does not use the same instances of the WMSLayerNode that LayerTreeModel
54
 * because it allows to repeat layers. So, each layer is a completely new 
55
 * WMSLayerNode containing same properties but not the same parent (which is always
56
 * the tree root) and each style is a completely new FMapStyle containing same
57
 * properties but its parent is one of the layers of the StylesTree and not one
58
 * of those of the Layers tree.
59
 * </p>
60
 * 
61
 * @author jaume dominguez faus
62
 *
63
 */
64
public class StyleTree extends JTree {
65
	public boolean showLayerNames = false;
66
    public StyleTree(){
67
        super();
68
        initialize();
69
    }
70
    
71
    private void initialize(){
72
        setToggleClickCount(1);
73
        setRowHeight(22);
74
        
75
        setCellRenderer(new DefaultTreeCellRenderer() {
76
            public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
77
                if (leaf) {
78
                    JPanel leafComponent = new JPanel();
79
                    leafComponent.setBackground(Color.WHITE);
80
                    JRadioButton leafRadioButton = new JRadioButton("", ((StyleTreeModel) getModel()).isSelected((RemoteWMSStyle) value));//selected);
81
                    leafRadioButton.setBackground(Color.WHITE);
82
                    leafComponent.add(leafRadioButton);
83
                    leafComponent.add(new JLabel(((RemoteWMSStyle) value).getTitle()));
84
                    return leafComponent;
85
                } else {
86
                	super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
87
                	if (value instanceof WMSLayerNode) {
88
                		WMSLayerNode layer = (WMSLayerNode) value;
89
                		if (!showLayerNames) {
90
                			if (layer.getName() != null || layer.getName() == "") {
91
                				String text = layer.toString();
92
                				text = text.substring(text.indexOf(']')+2, text.length());
93
                				setText(text);
94
                			}
95
                		}
96
                	}
97
            		return this;
98
                }
99
            }});
100
        addMouseListener(new java.awt.event.MouseAdapter() { 
101
            public void mouseClicked(java.awt.event.MouseEvent e) {
102
                ((StyleTreeModel)getModel()).setSelectedLeaf(getSelectionPath());
103
                clearSelection();
104
                repaint();
105
            }
106
        });
107
    }
108
    
109
    /**
110
     * Expands this tree.
111
     *
112
     */
113
    public void expandAll(){
114
        int row = 0; 
115
        while (row < getRowCount()) {
116
          expandRow(row);
117
          row++;
118
          }
119
    }
120
    /**
121
     * Returns a Vector of Strings containing the style titles.
122
     */
123
    public Vector getStyleSelectionTitles(){
124
        if (getModel() instanceof StyleTreeModel)
125
            return ((StyleTreeModel)getModel()).getStyleSelectionTitles();
126
        else
127
            return null;
128
    }
129
    
130
    /**
131
     * Sets the selected styles in the StylesTree. The argument styleNames is
132
     * a Vector with exactly the same amount of strings than the amount of
133
     * themes (layers) contained by the tree. A blank or null string will
134
     * leave the default style for that layer, but this element <b>must exist</b>
135
     * in the array in any case.
136
     * 
137
     * @param styleNames, Vector containing the style names. 
138
     * The styles order <b>must match</b> with the layer order. 
139
     */
140
    public void initSelections(Vector styleNames){
141
    	if (styleNames!=null) {
142
    		StyleTreeModel model = (StyleTreeModel) getModel();
143
    		model.setStylesSelection(styleNames);
144
    	}
145
    }
146
	
147
}
148

  
149
class StyleTreeModel implements TreeModel {
150
	private WMSLayerNode root;
151
	private ArrayList<WMSLayerNode> layers = new ArrayList<WMSLayerNode>();
152

  
153
	public StyleTreeModel(WMSLayerNode root){
154
        this.root = root;
155
        
156
    }
157
	
158
	/**
159
	 * Will return true if this style is selected.
160
	 * @param style
161
	 * @return
162
	 */
163
	public boolean isSelected(RemoteWMSStyle style) {
164
		return style.getParent().getSelectedStyle().equals(style);
165
	}
166

  
167
	/**
168
	 * Gets the names of the selected styles into a Vector using the same order
169
	 * as they was represented in the StylesTree.
170
	 * @return
171
	 */
172
	public Vector<String> getStyleSelectionTitles() {
173
		Vector<String> v = new Vector<String>();
174
		for (int i = 0; i < layers.size(); i++) {
175
			WMSLayerNode layer = (WMSLayerNode) layers.get(i);
176
			RemoteWMSStyle sty = layer.getSelectedStyle();
177
			if (sty == null) 
178
				v.add("");
179
			else 
180
				v.add(sty.getTitle());
181
		}
182
		return v;
183
	}
184

  
185
	/**
186
	 * Sets the selected styles in the StylesTree. The argument styleNames is
187
	 * a Vector with exactly the same amount of strings than the amount of
188
	 * themes (layers) contained by the tree. A blank or null string will
189
	 * leave the default style for that layer, but this element <b>must exist</b>
190
	 * in the array in any case.
191
	 * 
192
	 * @param styleNames, Vector containing the style names. 
193
	 * The styles order <b>must match</b> with the layer order. 
194
	 */
195
	public void setStylesSelection(Vector styleNames) {
196
		for (int i = 0; i < layers.size(); i++) {
197
			WMSLayerNode layer = (WMSLayerNode) layers.get(i);
198
			for (int j = 0; j < layer.getStyles().size(); j++) {
199
				RemoteWMSStyle sty = (RemoteWMSStyle) layer.getStyles().get(j);
200
				if ( sty.getName().equals((String) styleNames.get(i))) {
201
					layer.setSelectedStyleByIndex(j);
202
				}
203
			}
204
		}
205
	}
206
	
207
	/**
208
	 * Adds a new branch to this tree. It must be a layer node.
209
	 * @param node
210
	 * @return <b>True</b>, if the added branch actually defines any style.
211
	 *         <b>False</b>, if the layer has no styles.
212
	 */
213
	@SuppressWarnings("unchecked")
214
	public boolean addLayerBranch(WMSLayerNode node) {
215
		layers.add(node);
216
		if (node.getStyles()==null || node.getStyles().size()==0){
217
			return false;
218
		}
219
		for (int i = 0; i < node.getStyles().size(); i++) {
220
			((RemoteWMSStyle) node.getStyles().get(i)).setParent(node);
221
		}
222
		((WMSLayerNode)getRoot()).getChildren().add(node);
223
		return true;
224
	}
225
	
226
	/**
227
     * Sets a leaf (an style) selected.
228
     * @param selectionPath to this leaf.
229
     */
230
	protected void setSelectedLeaf(TreePath selectionPath) {
231
		if (selectionPath!=null){
232
			Object[] objects = selectionPath.getPath();
233
			Object item = objects[objects.length-1];
234
			if (isLeaf(item)){
235
				RemoteWMSStyle style = (RemoteWMSStyle) item;
236
				WMSLayerNode layer = style.getParent() ;
237
				for (int i = 0; i < layer.getStyles().size(); i++) {
238
					RemoteWMSStyle sty = (RemoteWMSStyle) layer.getStyles().get(i);
239
					if (sty.getName().equals(style.getName())) {
240
						layer.setSelectedStyleByIndex(i);
241
						return;
242
					}
243
				}
244
			}
245
		}
246
	}
247

  
248

  
249
	/*
250
	 *  (non-Javadoc)
251
	 * @see javax.swing.tree.TreeModel#getRoot()
252
	 */
253
	public Object getRoot() {
254
		if (root == null) {
255
            root = new WMSLayerNode();
256
            root.setParent(null);
257
        }
258
        return root;
259
	}
260

  
261
	/*
262
	 *  (non-Javadoc)
263
	 * @see javax.swing.tree.TreeModel#getChildCount(java.lang.Object)
264
	 */
265
	public int getChildCount(Object parent) {
266
        int count=0;
267
        
268
        if (parent == root)
269
            count = ((WMSLayerNode) parent).getChildren().size();
270
        else
271
            count = ((WMSLayerNode) parent).getStyles().size();
272
        return count;
273
    }
274

  
275
	/*
276
	 *  (non-Javadoc)
277
	 * @see javax.swing.tree.TreeModel#isLeaf(java.lang.Object)
278
	 */
279
	public boolean isLeaf(Object node) {
280
		return (node instanceof RemoteWMSStyle);
281
	}
282

  
283
	/*
284
	 *  (non-Javadoc)
285
	 * @see javax.swing.tree.TreeModel#addTreeModelListener(javax.swing.event.TreeModelListener)
286
	 */
287
	public void addTreeModelListener(TreeModelListener l) {
288
	}
289

  
290
	/*
291
	 *  (non-Javadoc)
292
	 * @see javax.swing.tree.TreeModel#removeTreeModelListener(javax.swing.event.TreeModelListener)
293
	 */
294
	public void removeTreeModelListener(TreeModelListener l) {
295
	}
296

  
297
	/*
298
	 *  (non-Javadoc)
299
	 * @see javax.swing.tree.TreeModel#getChild(java.lang.Object, int)
300
	 */
301
	public Object getChild(Object parent, int index) {
302
		if (parent instanceof RemoteWMSStyle)
303
            return null;
304
        if (parent == root)
305
            return ((WMSLayerNode) parent).getChildren().get(index);
306
        
307
        return ((WMSLayerNode) parent).getStyles().get(index);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff