Revision 436

View differences:

org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/NetCDFMenuEntry.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.raster.netcdf.app.netcdfclient;
23
import javax.swing.Icon;
24

  
25
import org.gvsig.andami.PluginServices;
26
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
27
import org.gvsig.app.project.documents.view.toc.ITocItem;
28
import org.gvsig.fmap.mapcontext.layers.FLayer;
29
import org.gvsig.raster.fmap.layers.FLyrRaster;
30
import org.gvsig.raster.fmap.layers.ILayerState;
31
import org.gvsig.raster.netcdf.app.netcdfclient.gui.panel.NetCDFPanel;
32
import org.gvsig.raster.netcdf.io.NetCDFDataParameters;
33
import org.gvsig.raster.netcdf.io.NetCDFProvider;
34

  
35

  
36
/**
37
 * <p>
38
 * TOC menu entry for NetCDF files
39
 * <p>
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 *
42
 */
43
public class NetCDFMenuEntry extends AbstractTocContextMenuAction {
44
	static private NetCDFMenuEntry    singleton     = null;
45

  
46
	/**
47
	 * Nadie puede crear una instancia a esta clase ?nica, hay que usar el
48
	 * getSingleton()
49
	 */
50
	private NetCDFMenuEntry() {}
51

  
52
	/**
53
	 * Devuelve un objeto unico a dicha clase
54
	 * @return
55
	 */
56
	static public NetCDFMenuEntry getSingleton() {
57
		if (singleton == null)
58
			singleton = new NetCDFMenuEntry();
59
		return singleton;
60

  
61
	}
62

  
63
	/*
64
	 * (non-Javadoc)
65
	 * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
66
	 */
67
	public String getGroup() {
68
		return "Raster";
69
	}
70

  
71
	/*
72
	 * (non-Javadoc)
73
	 * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
74
	 */
75
	public int getGroupOrder() {
76
		return 50;
77
	}
78

  
79
	/*
80
	 * (non-Javadoc)
81
	 * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
82
	 */
83
	public int getOrder() {
84
		return 1;
85
	}
86

  
87
	/*
88
	 * (non-Javadoc)
89
	 * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
90
	 */
91
	public String getText() {
92
		return PluginServices.getText(this, "NetCDF");
93
	}
94

  
95
	/*
96
	 * (non-Javadoc)
97
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
98
	 */
99
	public boolean isEnabled(ITocItem item, FLayer[] selectedItems) {
100
		if ((selectedItems == null) || (selectedItems.length != 1))
101
			return false;
102

  
103
		if (!(selectedItems[0] instanceof ILayerState))
104
			return false;
105

  
106
		if (!((ILayerState) selectedItems[0]).isOpen())
107
			return false;
108

  
109
		return true;
110
	}
111

  
112
	/*
113
	 * (non-Javadoc)
114
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
115
	 */
116
	public boolean isVisible(ITocItem item, FLayer[] selectedItems) {
117
		if ((selectedItems == null) || (selectedItems.length != 1))
118
			return false;
119

  
120
		if (!(selectedItems[0] instanceof FLyrRaster))
121
			return false;
122

  
123
		return (((FLyrRaster) selectedItems[0]).getDataStore().getParameters() instanceof NetCDFDataParameters);
124
	}
125

  
126
	/*
127
	 * (non-Javadoc)
128
	 * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
129
	 */
130
	public void execute(ITocItem item, FLayer[] selectedItems) {
131
		FLayer lyr = null;
132

  
133
		if (selectedItems.length != 1)
134
			return;
135

  
136
		lyr = selectedItems[0];
137

  
138
		if (!(lyr instanceof FLyrRaster))
139
			return;
140
		
141
		FLyrRaster fLayer = (FLyrRaster)lyr;
142
		
143
		PluginServices.getMDIManager().addWindow(new NetCDFPanel(fLayer));
144
	}
145

  
146
	/*
147
	 * (non-Javadoc)
148
	 * @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
149
	 */
150
	public Icon getIcon() {
151
		return PluginServices.getIconTheme().get("save-icon");
152
	}
153
}
0 154

  
org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/NetCDFClientExtension.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.raster.netcdf.app.netcdfclient;
23

  
24
import org.gvsig.andami.plugins.Extension;
25
import org.gvsig.tools.ToolsLocator;
26
import org.gvsig.tools.extensionpoint.ExtensionPoint;
27
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
28

  
29
/**
30
 * Extension for adding grid netcdf support to gvSIG.
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 */
33
public class NetCDFClientExtension extends Extension {
34

  
35
	public void initialize() {
36
    	initializeIcons();
37
    	
38
    	ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
39
    	ExtensionPoint point = extensionPoints.add("View_TocActions");
40
    	point.append("NetCDF_TocActions", "NetCDF", NetCDFMenuEntry.getSingleton());
41
	}
42

  
43
	public void execute(String actionCommand) {
44
	}
45

  
46
	public boolean isEnabled() {
47
		return true;
48
	}
49

  
50
	public boolean isVisible() {
51
		return false;
52
	}
53

  
54
	void initializeIcons(){
55
	}
56
}
0 57

  
org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/VariableSelectionPanel.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.netcdf.app.netcdfclient.gui.panel;
20

  
21
import java.awt.Color;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24

  
25
import javax.swing.BorderFactory;
26
import javax.swing.JComboBox;
27
import javax.swing.JLabel;
28
import javax.swing.JPanel;
29
import javax.swing.JTextArea;
30
import javax.swing.JTextField;
31

  
32
import org.gvsig.andami.PluginServices;
33

  
34
/**
35
 * Panel for selecting grid variables and dimensions
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class VariableSelectionPanel extends JPanel {
39
	private static final long       serialVersionUID     = 1L;
40
	private JLabel                  xdimLabel            = null;
41
	private JLabel                  ydimLabel            = null;
42
	private JLabel                  gridVariableLabel    = null;
43
	private JLabel                  varDescriptionLabel  = null;
44
	private JLabel                  levelLabel           = null;
45
	private JLabel                  timeLabel            = null;
46
	private JTextArea               txtDescription       = null;
47
	private JTextField              xdimField            = null;
48
	private JTextField              ydimField            = null;
49
	private JComboBox               gridVariableCombo    = null;
50
	private JComboBox               levelCombo           = null;
51
	private JComboBox               timeCombo            = null;
52
	private JPanel                  dimPanel             = null;
53

  
54
	public VariableSelectionPanel() {
55
		xdimLabel = new JLabel(PluginServices.getText(this, "xdim"));
56
		ydimLabel = new JLabel(PluginServices.getText(this, "ydim"));
57
		gridVariableLabel = new JLabel(PluginServices.getText(this, "gridvar"));
58
		varDescriptionLabel = new JLabel(PluginServices.getText(this, "vardescription"));
59
		levelLabel = new JLabel(PluginServices.getText(this, "level"));
60
		timeLabel = new JLabel(PluginServices.getText(this, "time"));
61
		init();
62
	}
63
	
64
	private void init() {
65
		setLayout(new GridBagLayout());
66
		setBorder(BorderFactory.createLineBorder(Color.gray));
67
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
68
		gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
69
		gridBagConstraints1.anchor = GridBagConstraints.CENTER;
70
		gridBagConstraints1.weightx = 1.0;
71
		gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
72
		
73
		gridBagConstraints1.gridy = 0;
74
		add(getDimPanel(), gridBagConstraints1);
75
		
76
		gridBagConstraints1.gridy = 1;
77
		add(levelLabel, gridBagConstraints1);
78
		
79
		gridBagConstraints1.gridy = 2;
80
		add(getLevelCombo(), gridBagConstraints1);
81
		
82
		gridBagConstraints1.gridy = 3;
83
		add(timeLabel, gridBagConstraints1);
84
		
85
		gridBagConstraints1.gridy = 4;
86
		add(getTimeCombo(), gridBagConstraints1);
87
		
88
		gridBagConstraints1.gridy = 5;
89
		add(gridVariableLabel, gridBagConstraints1);
90
		
91
		gridBagConstraints1.gridy = 6;
92
		add(getGridVariableCombo(), gridBagConstraints1);
93
		
94
		gridBagConstraints1.gridy = 7;
95
		add(varDescriptionLabel, gridBagConstraints1);
96
		
97
		gridBagConstraints1.gridy = 8;
98
		gridBagConstraints1.fill = GridBagConstraints.BOTH;
99
		gridBagConstraints1.weighty = 1.0;
100
		add(getTxtDescription(), gridBagConstraints1);
101
	}
102
	
103
	/**
104
	 * Gets the panel of dimension variables
105
	 * @return
106
	 */
107
	private JPanel getDimPanel() {
108
		if(dimPanel == null) {
109
			dimPanel = new JPanel();
110
			dimPanel.setLayout(new GridBagLayout());
111
			
112
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
113
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
114
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
115
			gridBagConstraints1.weightx = 1.0;
116
			gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
117
			
118
			gridBagConstraints1.gridx = 0;
119
			gridBagConstraints1.gridy = 0;
120
			dimPanel.add(xdimLabel, gridBagConstraints1);
121
			
122
			gridBagConstraints1.gridx = 1;
123
			gridBagConstraints1.gridy = 0;
124
			dimPanel.add(ydimLabel, gridBagConstraints1);
125
			
126
			gridBagConstraints1.gridx = 0;
127
			gridBagConstraints1.gridy = 1;
128
			dimPanel.add(getXDimField(), gridBagConstraints1);
129
			
130
			gridBagConstraints1.gridx = 1;
131
			gridBagConstraints1.gridy = 1;
132
			dimPanel.add(getYDimField(), gridBagConstraints1);
133
		}
134
		return dimPanel;
135
	}
136
	
137
	public javax.swing.JTextArea getTxtDescription() {
138
		if (txtDescription == null) {
139
			txtDescription = new javax.swing.JTextArea();
140
			txtDescription.setWrapStyleWord(true);
141
			txtDescription.setColumns(30);
142
			txtDescription.setLineWrap(true);
143
			txtDescription.setEditable(false);
144
		}
145
		return txtDescription;
146
	}
147
	
148
	private JComboBox getTimeCombo() {
149
		if(timeCombo == null) {
150
			timeCombo = new JComboBox();
151
		}
152
		return timeCombo;
153
	}
154
	
155
	private JComboBox getLevelCombo() {
156
		if(levelCombo == null) {
157
			levelCombo = new JComboBox();
158
		}
159
		return levelCombo;
160
	}
161
	
162
	private JTextField getXDimField() {
163
		if(xdimField == null) {
164
			xdimField = new JTextField();
165
			xdimField.setEditable(false);
166
		}
167
		return xdimField;
168
	}
169
	
170
	private JTextField getYDimField() {
171
		if(ydimField == null) {
172
			ydimField = new JTextField();
173
			ydimField.setEditable(false);
174
		}
175
		return ydimField;
176
	}
177
	
178
	public JComboBox getGridVariableCombo() {
179
		if(gridVariableCombo == null) {
180
			gridVariableCombo = new JComboBox();
181
		}
182
		return gridVariableCombo;
183
	}
184
}
0 185

  
org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf/org.gvsig.raster.netcdf.app/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/NetCDFPanel.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.raster.netcdf.app.netcdfclient.gui.panel;
23

  
24
import java.awt.GridBagConstraints;
25
import java.awt.GridBagLayout;
26
import java.awt.Insets;
27
import java.io.IOException;
28
import java.util.ArrayList;
29

  
30
import org.gvsig.andami.PluginServices;
31
import org.gvsig.andami.ui.mdiManager.IWindow;
32
import org.gvsig.andami.ui.mdiManager.WindowInfo;
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataServerExplorer;
36
import org.gvsig.fmap.dal.exception.DataException;
37
import org.gvsig.fmap.dal.exception.ValidateDataParametersException;
38
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer;
39
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
40
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
41
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
42
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
43
import org.gvsig.raster.fmap.layers.FLyrRaster;
44
import org.gvsig.raster.netcdf.io.NetCDFFilesystemServerExplorer;
45
import org.gvsig.raster.netcdf.io.NetCDFProvider;
46

  
47
/**
48
 * Properties panel for NetCDF format.
49
 * @author Nacho Brodin (nachobrodin@gmail.com)
50
 */
51
public class NetCDFPanel extends DefaultButtonsPanel implements IWindow {
52
	private static final long             serialVersionUID = 1L;
53
	private VariableSelectionPanel        panel            = null;
54
	private FLyrRaster                    lyr              = null;
55
	
56
	/**
57
	 * This method initializes
58
	 */
59
	public NetCDFPanel(FLyrRaster lyr) {
60
		super(ButtonsPanel.BUTTONS_APPLYCLOSE);
61
		this.lyr = lyr;
62
		//getButtonsPanel().getButton(ButtonsPanel.BUTTON_CLOSE).setEnabled(true);
63
		//getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setEnabled(true);
64
		initialize();
65
		
66
		try {
67
			DataServerExplorer explorer = lyr.getDataStore().getExplorer();
68
			DataManager datamanager = DALLocator.getDataManager();
69
			FilesystemServerExplorerParameters explorerParams = (FilesystemServerExplorerParameters)datamanager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
70
			explorer = datamanager.openServerExplorer(NetCDFProvider.NAME, explorerParams);
71
			
72
			if(explorer instanceof NetCDFFilesystemServerExplorer) {
73
				loadWindow((NetCDFFilesystemServerExplorer)explorer);
74
			}
75
		} catch (ValidateDataParametersException e) {
76
			// TODO Auto-generated catch block
77
			e.printStackTrace();
78
		} catch (DataException e) {
79
			// TODO Auto-generated catch block
80
			e.printStackTrace();
81
		} catch (IOException e) {
82
			// TODO Auto-generated catch block
83
			e.printStackTrace();
84
		}
85
	}
86
	
87
	private void loadWindow(NetCDFFilesystemServerExplorer exp) throws IOException {
88
		FilesystemStoreParameters par = (FilesystemStoreParameters)lyr.getDataStore().getParameters();
89
		ArrayList<String[]> list = exp.getGridVariables(par.getFile());
90
		
91
		//Loads Grid variables
92
		panel.getGridVariableCombo().removeAllItems();
93
		for (int i = 0; i < list.size(); i++) {
94
			panel.getGridVariableCombo().addItem(list.get(i)[0]);
95
		}
96
	}
97
	
98
	protected void initialize() {
99
		GridBagConstraints gbc = new GridBagConstraints();
100
		setLayout(new GridBagLayout());
101
		
102
		gbc.insets = new Insets(0, 0, 0, 0);
103
		gbc.fill = GridBagConstraints.BOTH;
104
		gbc.weightx = 1.0;
105
		gbc.weighty = 1.0;
106
		
107
		add(getVariableSelectionPanel(), gbc);
108
	}
109
	
110
	/**
111
	 * Gets the main panel
112
	 * @return
113
	 */
114
	private VariableSelectionPanel getVariableSelectionPanel() {
115
		if(panel == null)
116
			panel = new VariableSelectionPanel();
117
		return panel;
118
	}
119

  
120
	/*
121
	 * (non-Javadoc)
122
	 * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowInfo()
123
	 */
124
	public WindowInfo getWindowInfo() {
125
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
126
		m_viewinfo.setTitle(PluginServices.getText(this, "NetCDF_Properties"));
127
		m_viewinfo.setHeight(300);
128
		m_viewinfo.setWidth(280);
129
		return m_viewinfo;
130
	}
131

  
132
	/*
133
	 * (non-Javadoc)
134
	 * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowProfile()
135
	 */
136
	public Object getWindowProfile() {
137
		return WindowInfo.PROPERTIES_PROFILE;
138
	}
139
}
0 140

  

Also available in: Unified diff