Revision 9196

View differences:

org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/org.gvsig.raster.netcdf.app.netcdfclient/src/test/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/TestVarSelectionPanel.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 javax.swing.JFrame;
22

  
23
public class TestVarSelectionPanel {
24
	private int                          w        = 510;
25
	private int                          h        = 610;
26
	private JFrame                       frame    = new JFrame();
27
	private VariableSelectionPanel       desc     = null;
28

  
29
	public TestVarSelectionPanel() {
30
		desc = new VariableSelectionPanel();
31
		frame.getContentPane().add(desc);
32
		frame.setSize(w, h);
33
		frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
34
		frame.setVisible(true);
35
	}
36

  
37
	public static void main(String[] args) {
38
		new TestVarSelectionPanel();
39
	}
40
}
0 41

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/org.gvsig.raster.netcdf.app.netcdfclient/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.netcdf.app.netcdfclient:jar</include>
33
				<include>org.gvsig:org.gvsig.raster.netcdf.io:jar</include>
34
				<include>essi-unidata:netcdf-java:jar</include>
35
	  </includes>
36
	</dependencySet>
37
  </dependencySets>
38
</assembly>
0 39

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/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.about.AboutManager;
25
import org.gvsig.about.AboutParticipant;
26
import org.gvsig.andami.IconThemeHelper;
27
import org.gvsig.andami.PluginServices;
28
import org.gvsig.andami.plugins.Extension;
29
import org.gvsig.app.ApplicationLocator;
30
import org.gvsig.app.ApplicationManager;
31
import org.gvsig.tools.ToolsLocator;
32
import org.gvsig.tools.extensionpoint.ExtensionPoint;
33
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
34

  
35
/**
36
 * Extension for adding grid netcdf support to gvSIG.
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39
public class NetCDFClientExtension extends Extension {
40

  
41
	public void initialize() {
42
		registerIcons();
43
    	
44
    	ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
45
    	ExtensionPoint point = extensionPoints.add("View_TocActions");
46
    	point.append("NetCDF_TocActions", "NetCDF", NetCDFMenuEntry.getSingleton());
47
	}
48
	
49
	/**
50
	 * @see com.iver.andami.plugins.IExtension#postInitialize()
51
	 */
52
	@Override
53
	public void postInitialize() {
54
		super.postInitialize();
55
	    addAboutInfo();
56
	}
57
	
58
	private void addAboutInfo() {
59
        ApplicationManager application = ApplicationLocator.getManager();
60
        
61
        AboutManager about = application.getAbout();
62
        about.addDeveloper("PRODEVELOP", getClass().getClassLoader()
63
            .getResource("about/netcdf-about.html"), 2);
64

  
65
        AboutParticipant participant = about.getDeveloper("PRODEVELOP");
66
        participant.addContribution(
67
            "NetCDF Raster",
68
            "Soporte para NetCDF raster ", 
69
            2011,7,1, 
70
            2011,7,30
71
        );      
72
    }
73

  
74
	public void execute(String actionCommand) {
75
	}
76

  
77
	public boolean isEnabled() {
78
		return true;
79
	}
80

  
81
	public boolean isVisible() {
82
		return false;
83
	}
84
	
85
	/**
86
	 * Registra los iconos a utilizar en la botonera.
87
	 */
88
	private void registerIcons() {
89
		IconThemeHelper.registerIcon(null, "nextarrow-icon", this);
90
		IconThemeHelper.registerIcon(null, "prevarrow-icon", this);
91
		IconThemeHelper.registerIcon(null, "inspect-icon", this);
92
	}
93
}
0 94

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/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.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.io.IOException;
30
import java.util.ArrayList;
31
import java.util.Date;
32

  
33
import org.gvsig.andami.PluginServices;
34
import org.gvsig.andami.ui.mdiManager.IWindow;
35
import org.gvsig.andami.ui.mdiManager.WindowInfo;
36
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
37
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
38
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
39
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
40
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
41
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
42
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
43
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
44
import org.gvsig.raster.fmap.layers.FLyrRaster;
45
import org.gvsig.raster.netcdf.io.NetCDFDataParameters;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48

  
49
import ucar.nc2.Variable;
50

  
51
/**
52
 * Properties panel for NetCDF format.
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class NetCDFPanel extends DefaultButtonsPanel implements IWindow, ActionListener, ButtonsPanelListener {
56
	private static final long             serialVersionUID  = 1L;
57
	private static String                 NOVALUE           = "---";
58
	private VariableSelectionPanel        panel             = null;
59
	private FLyrRaster                    lyr               = null;
60
	private static boolean                blockRefreshEvent = false;
61
	private ArrayList<Variable>           listVars          = null;
62
	public static int                     HEIGHT            = 360;
63
	public static int                     WIDTH             = 340;
64
	private Logger                        logger            = LoggerFactory.getLogger(NetCDFPanel.class.toString());
65
	
66
	/**
67
	 * This method initializes
68
	 */
69
	public NetCDFPanel(FLyrRaster lyr) {
70
		super(ButtonsPanel.BUTTONS_APPLYCLOSE);
71
		addButtonPressedListener(this);
72
		this.lyr = lyr;
73
		initialize();
74
		
75
		try {
76
			loadVariablesFromParameters();
77
		} catch (IOException e) {
78
			panel.getGridVariableCombo().setSelectedIndex(0);
79
		} finally {
80
		}
81
		
82
		setStatus();
83
	}
84
	
85
	/**
86
	 * Initializes graphic components
87
	 */
88
	protected void initialize() {
89
		GridBagConstraints gbc = new GridBagConstraints();
90
		setLayout(new GridBagLayout());
91
		
92
		gbc.insets = new Insets(0, 0, 0, 0);
93
		gbc.fill = GridBagConstraints.BOTH;
94
		gbc.anchor = GridBagConstraints.CENTER;
95
		gbc.weightx = 1.0;
96
		gbc.weighty = 1.0;
97
		
98
		add(getVariableSelectionPanel(), gbc);
99
		panel.getLevelCombo().addActionListener(this);
100
		panel.getTimeCombo().addActionListener(this);
101
		panel.getGridVariableCombo().addActionListener(this);
102
		panel.getGridVarUpDownPanel().getUpButton().addActionListener(this);
103
		panel.getGridVarUpDownPanel().getDownButton().addActionListener(this);
104
		panel.getTimeUpDownPanel().getUpButton().addActionListener(this);
105
		panel.getTimeUpDownPanel().getDownButton().addActionListener(this);
106
		panel.getLevelUpDownPanel().getUpButton().addActionListener(this);
107
		panel.getLevelUpDownPanel().getDownButton().addActionListener(this);
108
		panel.getVarPropertiesButton().addActionListener(this);
109
		panel.getVariableCombo().addActionListener(this);
110
	}
111
	
112
	/**
113
	 * Sets the variable status
114
	 * @param params
115
	 */
116
	private void setStatus() {
117
		NetCDFDataParameters params = (NetCDFDataParameters)lyr.getDataStore().getInternalParameters();
118
		Integer time = params.getFieldTime();
119
		Integer level = params.getFieldLevel();
120
		String fieldVar = params.getStringVariable();
121
		
122
		blockRefreshEvent = true;
123
		for (int i = 0; i < panel.getGridVariableCombo().getItemCount(); i++) {
124
			if(fieldVar.compareTo((String)panel.getGridVariableCombo().getItemAt(i)) == 0) {
125
				panel.getGridVariableCombo().setSelectedIndex(i);
126
				break;
127
			}
128
		}
129
		panel.getTimeCombo().setSelectedIndex(time.intValue());
130
		panel.getLevelCombo().setSelectedIndex(level.intValue());
131
		blockRefreshEvent = false;
132
	}
133
	
134
	/**
135
	 * Loads the main window of data
136
	 * @throws IOException
137
	 */
138
	private void loadVariablesFromParameters() throws IOException {
139
		NetCDFDataParameters params = ((NetCDFDataParameters)lyr.getDataStore().getInternalParameters());
140
		
141
		panel.getXDimField().setText(params.getXDimVariable());
142
		panel.getYDimField().setText(params.getYDimVariable());
143
		
144
		blockRefreshEvent = true;
145
		ArrayList<String[]> listGridVars = params.getGridVariables();
146
		panel.getGridVariableCombo().removeAllItems();
147
		for (int i = 0; i < listGridVars.size(); i++) {
148
			panel.getGridVariableCombo().addItem(listGridVars.get(i)[0]);
149
		}
150
		
151
		listVars = params.getVariables();
152
		panel.getVariableCombo().removeAllItems();
153
		if(listVars != null) {
154
			for (int i = 0; i < listVars.size(); i++) {
155
				panel.getVariableCombo().addItem(listVars.get(i).getName());
156
			}
157
		} else {
158
			panel.getLevelCombo().addItem(NOVALUE);
159
		}
160

  
161
		Date[] dateList = params.getTimeList(params.getStringVariable());
162
		panel.getTimeCombo().removeAllItems();
163
		if(dateList != null) {
164
			for (int i = 0; i < dateList.length; i++) {
165
				panel.getTimeCombo().addItem(dateList[i]);
166
			}
167
		} else
168
			panel.getTimeCombo().addItem(NOVALUE);
169
		
170
		panel.getLevelCombo().removeAllItems();
171
		double[] levels = params.getLevelList(params.getStringVariable());
172
		if(levels != null) {
173
			for (int i = 0; i < levels.length; i++) {
174
				panel.getLevelCombo().addItem(levels[i]);
175
			}
176
		} else
177
			panel.getLevelCombo().addItem(NOVALUE);
178
		
179
		blockRefreshEvent = false;
180
	}
181
	
182
	/**
183
	 * Loads the description of the selected variable
184
	 * @param selectedVariable
185
	 * @throws IOException
186
	 */
187
	private void loadDescription(String selectedVariable) throws IOException {
188
		NetCDFDataParameters params = ((NetCDFDataParameters)lyr.getDataStore().getInternalParameters());
189
		ArrayList<String[]> list = params.getGridVariables();
190
		for (int i = 0; i < list.size(); i++) {
191
			String[] values = list.get(i);
192
			if(values[0].compareTo(selectedVariable) == 0)
193
				panel.getTxtDescription().setText(values[1]);
194
		}
195
	}
196
	
197
	/**
198
	 * Loads the list of levels of the selected variable
199
	 */
200
	private void loadLevel() {
201
		NetCDFDataParameters params = ((NetCDFDataParameters)lyr.getDataStore().getInternalParameters());
202
		double[] levels = params.getLevelList((String)panel.getGridVariableCombo().getSelectedItem());
203
		blockRefreshEvent = true;
204
		panel.getLevelCombo().removeAllItems();
205
		if(levels != null) {
206
			for (int i = 0; i < levels.length; i++) {
207
				panel.getLevelCombo().addItem(levels[i]);
208
			}
209
		} else
210
			panel.getLevelCombo().addItem(NOVALUE);
211
		blockRefreshEvent = false;
212
	}
213
	
214
	/**
215
	 * Loads the list of dates of the selected variable.
216
	 */
217
	private void loadDates() {
218
		NetCDFDataParameters params = ((NetCDFDataParameters)lyr.getDataStore().getInternalParameters());
219
		Date[] dateList = params.getTimeList((String)panel.getGridVariableCombo().getSelectedItem());
220
		blockRefreshEvent = true;
221
		panel.getTimeCombo().removeAllItems();
222
		if(dateList != null) {
223
			for (int i = 0; i < dateList.length; i++) {
224
				panel.getTimeCombo().addItem(dateList[i]);
225
			}
226
		} else
227
			panel.getTimeCombo().addItem(NOVALUE);
228
		blockRefreshEvent = false;
229
	}
230
	
231
	/**
232
	 * Gets the main panel
233
	 * @return
234
	 */
235
	private VariableSelectionPanel getVariableSelectionPanel() {
236
		if(panel == null) {
237
			panel = new VariableSelectionPanel();
238
			panel.getGridVariableCombo().addActionListener(this);
239
		}
240
		return panel;
241
	}
242
	
243
	/*
244
	 * (non-Javadoc)
245
	 * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowInfo()
246
	 */
247
	public WindowInfo getWindowInfo() {
248
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
249
		m_viewinfo.setTitle(PluginServices.getText(this, "NetCDF_Variables"));
250
		m_viewinfo.setHeight(HEIGHT);
251
		m_viewinfo.setWidth(WIDTH);
252
		return m_viewinfo;
253
	}
254

  
255
	/*
256
	 * (non-Javadoc)
257
	 * @see org.gvsig.andami.ui.mdiManager.IWindow#getWindowProfile()
258
	 */
259
	public Object getWindowProfile() {
260
		return WindowInfo.PROPERTIES_PROFILE;
261
	}
262

  
263
	/*
264
	 * (non-Javadoc)
265
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
266
	 */
267
	public void actionPerformed(ActionEvent e) {
268
		if(blockRefreshEvent)
269
			return;
270
		
271
		if(e.getSource() == panel.getGridVariableCombo()) {
272
			try {
273
				loadDescription((String)panel.getGridVariableCombo().getSelectedItem());
274
				loadLevel();
275
				loadDates();
276
			} catch (IOException e1) {
277
				panel.getTxtDescription().setText("?");
278
			}
279
		}
280
		
281
		if(e.getSource() == panel.getGridVarUpDownPanel().getDownButton()) {
282
			panel.getGridVariableCombo().setSelectedIndex(
283
					Math.min(panel.getGridVariableCombo().getSelectedIndex() + 1,
284
					panel.getGridVariableCombo().getItemCount() - 1));
285
		}
286
		
287
		if(e.getSource() == panel.getGridVarUpDownPanel().getUpButton()) {
288
			panel.getGridVariableCombo().setSelectedIndex(
289
					Math.max(panel.getGridVariableCombo().getSelectedIndex() - 1,
290
					0));
291
		}
292
		
293
		if(e.getSource() == panel.getTimeUpDownPanel().getDownButton()) {
294
			panel.getTimeCombo().setSelectedIndex(
295
					Math.min(panel.getTimeCombo().getSelectedIndex() + 1,
296
					panel.getTimeCombo().getItemCount() - 1));
297
		}
298
		
299
		if(e.getSource() == panel.getTimeUpDownPanel().getUpButton()) {
300
			panel.getTimeCombo().setSelectedIndex(
301
					Math.max(panel.getTimeCombo().getSelectedIndex() - 1,
302
					0));
303
		}
304
		
305
		if(e.getSource() == panel.getLevelUpDownPanel().getDownButton()) {
306
			panel.getLevelCombo().setSelectedIndex(
307
					Math.min(panel.getLevelCombo().getSelectedIndex() + 1,
308
					panel.getLevelCombo().getItemCount() - 1));
309
		}
310
		
311
		if(e.getSource() == panel.getLevelUpDownPanel().getUpButton()) {
312
			panel.getLevelCombo().setSelectedIndex(
313
					Math.max(panel.getLevelCombo().getSelectedIndex() - 1,
314
					0));
315
		}
316
		
317
		if(e.getSource() == panel.getVarPropertiesButton()) {
318
			showVariableProperties((String)panel.getVariableCombo().getSelectedItem());
319
			openVariableTable();
320
		}
321
		
322
		if(e.getSource() == panel.getVariableCombo()) {
323
			showVariableProperties((String)panel.getVariableCombo().getSelectedItem());
324
		}
325
		
326
		//Apply when a selection changes
327
		if((e.getSource() == panel.getGridVariableCombo() || 
328
			e.getSource() == panel.getTimeCombo() || 
329
			e.getSource() == panel.getLevelCombo())) 
330
			actionButtonPressed(null);
331
	}
332
	
333
	/**
334
	 * Shows the dialog for properties variable
335
	 * @param var
336
	 */
337
	private void showVariableProperties(String var) {
338
		if(listVars != null) {
339
			ArrayList<String[]> varValue = new ArrayList<String[]>();
340
			for (int i = 0; i < listVars.size(); i++) {
341
				Variable v = listVars.get(i);
342
				String name = v.getName();
343
				if(name.compareTo(var) == 0) {
344
					varValue.add(new String[] {PluginServices.getText(this, "description"), v.getDescription()});
345
					varValue.add(new String[] {PluginServices.getText(this, "dimensions"), v.getDimensionsString()});
346
					int[] shape = v.getShape();
347
					String shapeString = "";
348
					for (int j = 0; j < shape.length; j++) {
349
						shapeString += shape[j] + ", ";
350
					}
351
					varValue.add(new String[] {PluginServices.getText(this, "shape"), shapeString});
352
					varValue.add(new String[] {PluginServices.getText(this, "units"), v.getUnitsString()});
353
					varValue.add(new String[] {PluginServices.getText(this, "dataType"), v.getDataType().toString()});
354
				}
355
			}
356
			try {
357
				panel.getTablePanel().getTable().removeAllRows();
358
			} catch (NotInitializeException e) {
359
				logger.debug(org.gvsig.i18n.Messages.getText("error_removing_rows"), e);
360
			}
361
			panel.getTablePanel().setRows(varValue);
362
		}
363
	}
364
	
365
	/**
366
	 * Opens variable table
367
	 */
368
	private void openVariableTable() {
369
		//Shows and hides the table of data
370
		if(panel.getSouthPanel().isVisible()) {
371
			panel.showTable(false);
372
			PluginServices.getMDIManager().getWindowInfo(this).setHeight(HEIGHT);
373
		} else {
374
			panel.showTable(true);
375
			PluginServices.getMDIManager().getWindowInfo(this).setHeight(500);
376
		}
377
	}
378

  
379
	/*
380
	 * (non-Javadoc)
381
	 * @see org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener#actionButtonPressed(org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent)
382
	 */
383
	public void actionButtonPressed(ButtonsPanelEvent e) {
384
		if(blockRefreshEvent)
385
			return;
386
			
387
		// Bot�n de Aplicar
388
		if (e == null || e.getButton() == ButtonsPanel.BUTTON_APPLY) {
389
			//DataManager datamanager = DALLocator.getDataManager();
390
			//FilesystemServerExplorerParameters explorerParams = (FilesystemServerExplorerParameters) datamanager.createServerExplorerParameters(FilesystemServerExplorer.NAME);
391
			//DataServerExplorer explorer = datamanager.openServerExplorer(FilesystemServerExplorer.NAME, explorerParams);
392
			//NewDataStoreParameters newParams = explorer.getAddParameters(NetCDFProvider.NAME);
393
			NetCDFDataParameters newParams = (NetCDFDataParameters)lyr.getDataStore().getInternalParameters();
394
			newParams.setDynValue(NetCDFDataParameters.FIELD_VARIABLE, panel.getGridVariableCombo().getSelectedItem());
395
			String value = (String)panel.getTimeCombo().getSelectedItem().toString();
396
			newParams.setDynValue(NetCDFDataParameters.FIELD_TIME, value.compareTo(NOVALUE) == 0 ? 0 : panel.getTimeCombo().getSelectedIndex());
397
			value = (String)panel.getLevelCombo().getSelectedItem().toString();
398
			newParams.setDynValue(NetCDFDataParameters.FIELD_LEVEL, value.compareTo(NOVALUE) == 0 ? new Integer(0) : new Integer(panel.getLevelCombo().getSelectedIndex()));
399

  
400
			//The statistics have to be recalculated for each subdataset
401
			try {
402
				lyr.getDataStore().getStatistics().forceToRecalc();
403
				lyr.getDataStore().getStatistics().calculate(1);
404
			} catch (FileNotOpenException e1) {
405
				logger.debug(org.gvsig.i18n.Messages.getText("error_stats"), e1);
406
			} catch (RasterDriverException e1) {
407
				logger.debug(org.gvsig.i18n.Messages.getText("error_stats"), e1);
408
			} catch (ProcessInterruptedException e1) {
409
			}
410

  
411
			//If there is a color table this will have to be adapted to subdataset range
412
			if(lyr.getRender().getColorTable() != null)
413
				lyr.getRender().getColorTable().createColorTableInRange(lyr.getDataStore().getStatistics().getMinimun(), lyr.getDataStore().getStatistics().getMaximun(), false);
414
			lyr.getMapContext().invalidate();
415
		}
416
		
417
		// Bot�n de Cerrar
418
		if (e != null && e.getButton() == ButtonsPanel.BUTTON_CLOSE)
419
			PluginServices.getMDIManager().closeWindow(this);
420
	}
421
}
0 422

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/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.BorderLayout;
22
import java.awt.Color;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25

  
26
import javax.swing.BorderFactory;
27
import javax.swing.ImageIcon;
28
import javax.swing.JButton;
29
import javax.swing.JComboBox;
30
import javax.swing.JLabel;
31
import javax.swing.JPanel;
32
import javax.swing.JTextArea;
33
import javax.swing.JTextField;
34

  
35
import org.gvsig.andami.IconThemeHelper;
36
import org.gvsig.andami.PluginServices;
37

  
38
/**
39
 * Panel for selecting grid variables and dimensions
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public class VariableSelectionPanel extends JPanel {
43
	private static final long       serialVersionUID         = 1L;
44
	private JLabel                  xdimLabel                = null;
45
	private JLabel                  ydimLabel                = null;
46
	private JLabel                  gridVariableLabel        = null;
47
	private JLabel                  gridVarDescriptionLabel  = null;
48
	private JLabel                  varDescriptionLabel      = null;
49
	private JLabel                  levelLabel               = null;
50
	private JLabel                  timeLabel                = null;
51
	private JTextArea               txtDescription           = null;
52
	private JTextField              xdimField                = null;
53
	private JTextField              ydimField                = null;
54
	private JComboBox               gridVariableCombo        = null;
55
	private JComboBox               levelCombo               = null;
56
	private JComboBox               timeCombo                = null;
57
	private JComboBox               variableCombo            = null;
58
	private UpDownPanel             varUpDown                = null;
59
	private UpDownPanel             timeUpDown               = null;
60
	private UpDownPanel             levelUpDown              = null;
61
	private JPanel                  varPanel                 = null;
62
	private JPanel                  gridVarPanel             = null;
63
	private JPanel                  timePanel                = null;
64
	private JPanel                  levelPanel               = null;
65
	private JPanel                  dimPanel                 = null;
66
	private JPanel                  northPanel               = null;
67
	private JPanel                  southPanel               = null;
68
	private JPanel                  centerPanel              = null;
69
	private JPanel                  auxPanel                 = new JPanel();
70
	private JButton                 varPropertiesButton      = null;
71
	private VariableTablePanel      tablePanel               = null;
72
	private String                  pathToImagesForTest      = "/src/main/resources/images/";
73
	
74
	public VariableSelectionPanel() {
75
		xdimLabel = new JLabel(PluginServices.getText(this, "xdim"));
76
		ydimLabel = new JLabel(PluginServices.getText(this, "ydim"));
77
		gridVariableLabel = new JLabel(PluginServices.getText(this, "gridvar"));
78
		gridVarDescriptionLabel = new JLabel(PluginServices.getText(this, "gridvardescription"));
79
		varDescriptionLabel = new JLabel(PluginServices.getText(this, "vardescription"));
80
		levelLabel = new JLabel(PluginServices.getText(this, "level"));
81
		timeLabel = new JLabel(PluginServices.getText(this, "time"));
82
		init();
83
	}
84
	
85
	GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
86
	
87
	private void init() {
88
		setLayout(new GridBagLayout());
89
		gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
90
		gridBagConstraints1.weightx = 1.0;
91
		gridBagConstraints1.weighty = 0.0;
92
		gridBagConstraints1.anchor = GridBagConstraints.CENTER;
93
		gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
94
		
95
		add(getNorthPanel(), gridBagConstraints1);
96
		
97
		gridBagConstraints1.gridy = 1;
98
		add(getCenterPanel(), gridBagConstraints1);
99
		
100
		showTable(false);
101
	}
102
	
103
	/**
104
	 * Shows and hides the table of data
105
	 * @param show
106
	 */
107
	public void showTable(boolean show) {
108
		gridBagConstraints1.fill = GridBagConstraints.BOTH;
109
		gridBagConstraints1.weightx = 1.0;
110
		gridBagConstraints1.weighty = 1.0;
111
		gridBagConstraints1.gridy = 2;
112
		
113
		if(show) {
114
			remove(auxPanel);
115
			add(getSouthPanel(), gridBagConstraints1);
116
			getSouthPanel().setVisible(true);
117
		} else {
118
			remove(getSouthPanel());
119
			add(auxPanel, gridBagConstraints1);
120
			getSouthPanel().setVisible(false);
121
		}
122
	}
123
	
124
	/**
125
	 * Gets the south panel
126
	 * @return
127
	 */
128
	public JPanel getSouthPanel() {
129
		if(southPanel == null) {
130
			southPanel = new JPanel();
131
			southPanel.setLayout(new BorderLayout());
132
			southPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
133
			southPanel.add(getTablePanel(), BorderLayout.CENTER);
134
		}
135
		return southPanel;
136
	}
137
	
138
	/**
139
	 * Gets the north panel
140
	 * @return
141
	 */
142
	private JPanel getNorthPanel() {
143
		if(northPanel == null) {
144
			northPanel = new JPanel();
145
			northPanel.setLayout(new GridBagLayout());
146
			northPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
147
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
148
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
149
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
150
			gridBagConstraints1.weightx = 1.0;
151
			gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
152
			
153
			gridBagConstraints1.gridy = 0;
154
			northPanel.add(getDimPanel(), gridBagConstraints1);
155
			
156
			gridBagConstraints1.gridy = 1;
157
			northPanel.add(levelLabel, gridBagConstraints1);
158
			
159
			gridBagConstraints1.gridy = 2;
160
			northPanel.add(getLevelPanel(), gridBagConstraints1);
161
			
162
			gridBagConstraints1.gridy = 3;
163
			northPanel.add(timeLabel, gridBagConstraints1);
164
			
165
			gridBagConstraints1.gridy = 4;
166
			northPanel.add(getTimePanel(), gridBagConstraints1);
167
			
168
			gridBagConstraints1.gridy = 5;
169
			northPanel.add(gridVariableLabel, gridBagConstraints1);
170
			
171
			gridBagConstraints1.gridy = 6;
172
			northPanel.add(getGridVarPanel(), gridBagConstraints1);
173
			
174
			gridBagConstraints1.gridy = 7;
175
			northPanel.add(gridVarDescriptionLabel, gridBagConstraints1);
176
			
177
			gridBagConstraints1.gridy = 8;
178
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
179
			gridBagConstraints1.weighty = 1.0;
180
			northPanel.add(getTxtDescription(), gridBagConstraints1);
181
			
182
			//gridBagConstraints1.gridy = 9;
183
			//gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
184
			//gridBagConstraints1.weighty = 0.0;
185
			//northPanel.add(varDescriptionLabel, gridBagConstraints1);
186
			
187
			//gridBagConstraints1.gridy = 10;
188
			//northPanel.add(getVarPanel(), gridBagConstraints1);
189
		}
190
		return northPanel;
191
	}
192
	
193
	/**
194
	 * Gets the center panel
195
	 * @return
196
	 */
197
	public JPanel getCenterPanel() {
198
		if(centerPanel == null) {
199
			centerPanel = new JPanel();
200
			centerPanel.setLayout(new GridBagLayout());
201
			centerPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
202
			
203
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
204
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
205
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
206
			gridBagConstraints1.weightx = 1.0;
207
			gridBagConstraints1.weighty = 0.0;
208
			gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
209
			
210
			centerPanel.add(varDescriptionLabel, gridBagConstraints1);
211
			gridBagConstraints1.gridy = 1;
212
			centerPanel.add(getVarPanel(), gridBagConstraints1);
213
		}
214
		return centerPanel;
215
	}
216
	
217
	/**
218
	 * Gets the table panel 
219
	 * @return
220
	 */
221
	public VariableTablePanel getTablePanel() {
222
		if(tablePanel == null) {
223
			tablePanel = new VariableTablePanel();
224
		}
225
		return tablePanel;
226
	}
227
	
228
	/**
229
	 * Gets the panel of dimension variables
230
	 * @return
231
	 */
232
	private JPanel getDimPanel() {
233
		if(dimPanel == null) {
234
			dimPanel = new JPanel();
235
			dimPanel.setLayout(new GridBagLayout());
236
			
237
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
238
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
239
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
240
			gridBagConstraints1.weightx = 1.0;
241
			gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
242
			
243
			gridBagConstraints1.gridx = 0;
244
			gridBagConstraints1.gridy = 0;
245
			dimPanel.add(xdimLabel, gridBagConstraints1);
246
			
247
			gridBagConstraints1.gridx = 1;
248
			gridBagConstraints1.gridy = 0;
249
			dimPanel.add(ydimLabel, gridBagConstraints1);
250
			
251
			gridBagConstraints1.gridx = 0;
252
			gridBagConstraints1.gridy = 1;
253
			dimPanel.add(getXDimField(), gridBagConstraints1);
254
			
255
			gridBagConstraints1.gridx = 1;
256
			gridBagConstraints1.gridy = 1;
257
			dimPanel.add(getYDimField(), gridBagConstraints1);
258
		}
259
		return dimPanel;
260
	}
261
	
262
	public javax.swing.JTextArea getTxtDescription() {
263
		if (txtDescription == null) {
264
			txtDescription = new javax.swing.JTextArea();
265
			txtDescription.setWrapStyleWord(true);
266
			txtDescription.setColumns(30);
267
			txtDescription.setLineWrap(true);
268
			txtDescription.setEditable(false);
269
		}
270
		return txtDescription;
271
	}
272
	
273
	public JComboBox getTimeCombo() {
274
		if(timeCombo == null) {
275
			timeCombo = new JComboBox();
276
		}
277
		return timeCombo;
278
	}
279
	
280
	public JComboBox getLevelCombo() {
281
		if(levelCombo == null) {
282
			levelCombo = new JComboBox();
283
		}
284
		return levelCombo;
285
	}
286
	
287
	public JTextField getXDimField() {
288
		if(xdimField == null) {
289
			xdimField = new JTextField();
290
			xdimField.setEditable(false);
291
		}
292
		return xdimField;
293
	}
294
	
295
	public JTextField getYDimField() {
296
		if(ydimField == null) {
297
			ydimField = new JTextField();
298
			ydimField.setEditable(false);
299
		}
300
		return ydimField;
301
	}
302
	
303
	public JComboBox getGridVariableCombo() {
304
		if(gridVariableCombo == null) {
305
			gridVariableCombo = new JComboBox();
306
		}
307
		return gridVariableCombo;
308
	}
309
	
310
	public JComboBox getVariableCombo() {
311
		if(variableCombo == null) {
312
			variableCombo = new JComboBox();
313
		}
314
		return variableCombo;
315
	}
316
	
317
	public JButton getVarPropertiesButton() {
318
		if(varPropertiesButton == null) {
319
			varPropertiesButton = new JButton(loadIcon("inspect-icon"));
320
		}
321
		return varPropertiesButton;
322
	}
323
	
324
	/**
325
	 * Gets the panel of variable controls
326
	 * @return
327
	 */
328
	private JPanel getVarPanel() {
329
		if(varPanel == null) {
330
			varPanel = new JPanel();
331
			varPanel.setLayout(new GridBagLayout());
332
			
333
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
334
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
335
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
336
			gridBagConstraints1.weightx = 1.0;
337
			gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
338
			
339
			gridBagConstraints1.gridx = 0;
340
			gridBagConstraints1.gridy = 0;
341
			varPanel.add(getVariableCombo(), gridBagConstraints1);
342
			
343
			gridBagConstraints1.fill = GridBagConstraints.NONE;
344
			gridBagConstraints1.weightx = 0.0;
345
			gridBagConstraints1.gridx = 1;
346
			gridBagConstraints1.gridy = 0;
347
			varPanel.add(getVarPropertiesButton(), gridBagConstraints1);
348
		}
349
		return varPanel;
350
	}
351
	
352
	/**
353
	 * Gets the panel of variable controls
354
	 * @return
355
	 */
356
	private JPanel getGridVarPanel() {
357
		if(gridVarPanel == null) {
358
			gridVarPanel = new JPanel();
359
			gridVarPanel.setLayout(new GridBagLayout());
360
			
361
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
362
			gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
363
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
364
			gridBagConstraints1.weightx = 1.0;
365
			gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
366
			
367
			gridBagConstraints1.gridx = 0;
368
			gridBagConstraints1.gridy = 0;
369
			gridVarPanel.add(getGridVariableCombo(), gridBagConstraints1);
370
			
371
			gridBagConstraints1.fill = GridBagConstraints.NONE;
372
			gridBagConstraints1.weightx = 0.0;
373
			gridBagConstraints1.gridx = 1;
374
			gridBagConstraints1.gridy = 0;
375
			gridVarPanel.add(getGridVarUpDownPanel(), gridBagConstraints1);
376
		}
377
		return gridVarPanel;
378
	}
379
	
380
	/**
381
	 * Gets the panel of time controls
382
	 * @return
383
	 */
384
	private JPanel getTimePanel() {
385
		if(timePanel == null) {
386
			timePanel = new JPanel();
387
			timePanel.setLayout(new GridBagLayout());
388
			
389
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
390
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
391
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
392
			gridBagConstraints1.weightx = 1.0;
393
			gridBagConstraints1.weighty = 1.0;
394
			gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
395
			
396
			gridBagConstraints1.gridx = 0;
397
			gridBagConstraints1.gridy = 0;
398
			timePanel.add(getTimeCombo(), gridBagConstraints1);
399
			
400
			gridBagConstraints1.fill = GridBagConstraints.NONE;
401
			gridBagConstraints1.weightx = 0.0;
402
			gridBagConstraints1.weighty = 0.0;
403
			gridBagConstraints1.gridx = 1;
404
			gridBagConstraints1.gridy = 0;
405
			timePanel.add(getTimeUpDownPanel(), gridBagConstraints1);
406
		}
407
		return timePanel;
408
	}
409
	
410
	/**
411
	 * Gets the panel of level controls
412
	 * @return
413
	 */
414
	private JPanel getLevelPanel() {
415
		if(levelPanel == null) {
416
			levelPanel = new JPanel();
417
			levelPanel.setLayout(new GridBagLayout());
418
			
419
			GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
420
			gridBagConstraints1.fill = GridBagConstraints.BOTH;
421
			gridBagConstraints1.anchor = GridBagConstraints.CENTER;
422
			gridBagConstraints1.weightx = 1.0;
423
			gridBagConstraints1.weighty = 1.0;
424
			gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0);
425
			
426
			gridBagConstraints1.gridx = 0;
427
			gridBagConstraints1.gridy = 0;
428
			levelPanel.add(getLevelCombo(), gridBagConstraints1);
429
			
430
			gridBagConstraints1.fill = GridBagConstraints.NONE;
431
			gridBagConstraints1.weightx = 0.0;
432
			gridBagConstraints1.weighty = 0.0;
433
			gridBagConstraints1.gridx = 1;
434
			gridBagConstraints1.gridy = 0;
435
			levelPanel.add(getLevelUpDownPanel(), gridBagConstraints1);
436
		}
437
		return levelPanel;
438
	}
439
	
440
	public UpDownPanel getGridVarUpDownPanel() {
441
		if(varUpDown == null) {
442
			varUpDown = new UpDownPanel();
443
		}
444
		return varUpDown;
445
	}
446
	
447
	public UpDownPanel getTimeUpDownPanel() {
448
		if(timeUpDown == null) {
449
			timeUpDown = new UpDownPanel();
450
		}
451
		return timeUpDown;
452
	}
453
	
454
	public UpDownPanel getLevelUpDownPanel() {
455
		if(levelUpDown == null) {
456
			levelUpDown = new UpDownPanel();
457
		}
458
		return levelUpDown;
459
	}
460
	
461
	private ImageIcon loadIcon(String iconName) {
462
		ImageIcon icon = null;
463
		try {
464
			icon = IconThemeHelper.getImageIcon(iconName);
465
		} catch(NullPointerException e) {}
466
		if(icon == null) 
467
			icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".png", "");
468
		if(icon == null) 
469
			icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".gif", "");
470
		return icon;
471
	}
472
}
0 473

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/UpDownPanel.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.GridBagConstraints;
22
import java.awt.GridBagLayout;
23

  
24
import javax.swing.ImageIcon;
25
import javax.swing.JButton;
26
import javax.swing.JPanel;
27

  
28
import org.gvsig.andami.IconThemeHelper;
29

  
30
/**
31
 * Panel for up and down button
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public class UpDownPanel extends JPanel {
35
	private static final long       serialVersionUID     = 1L;
36
	private JButton                 up                   = null;
37
	private JButton                 down                 = null;
38
	private String                  pathToImagesForTest  = "/src/main/resources/images/";
39
	
40
	public UpDownPanel() {
41
		init();
42
	}
43
	
44
	private void init() {
45
		setLayout(new GridBagLayout());
46
		
47
		GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
48
		gridBagConstraints1.fill = GridBagConstraints.BOTH;
49
		gridBagConstraints1.anchor = GridBagConstraints.CENTER;
50
		gridBagConstraints1.weightx = 1.0;
51
		gridBagConstraints1.weighty = 1.0;
52
		
53
		add(getDownButton(), gridBagConstraints1);
54
				
55
		gridBagConstraints1.gridx = 1;
56
		add(getUpButton(), gridBagConstraints1);
57
	}
58

  
59
	public JButton getUpButton() {
60
		if(up == null) {
61
			up = new JButton(loadIcon("nextarrow-icon"));
62
			//up.setPreferredSize(new Dimension(32, 12));
63
		}
64
		return up;
65
	}
66
	
67
	public JButton getDownButton() {
68
		if(down == null) {
69
			down = new JButton(loadIcon("prevarrow-icon"));
70
			//down.setPreferredSize(new Dimension(32, 12));
71
		}
72
		return down;
73
	}
74
	
75
	private ImageIcon loadIcon(String iconName) {
76
		ImageIcon icon = null;
77
		try {
78
			icon = IconThemeHelper.getImageIcon(iconName);
79
		} catch(NullPointerException e) {}
80
		if(icon == null) 
81
			icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".png", "");
82
		if(icon == null) 
83
			icon = new ImageIcon(System.getProperty("user.dir") + pathToImagesForTest + iconName + ".gif", "");
84
		return icon;
85
	}
86
}
0 87

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/org.gvsig.raster.netcdf.app.netcdfclient/src/main/java/org/gvsig/raster/netcdf/app/netcdfclient/gui/panel/VariableTablePanel.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.BorderLayout;
22
import java.util.ArrayList;
23

  
24
import javax.swing.JPanel;
25

  
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.gui.beans.table.TableContainer;
28
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
29
import org.slf4j.Logger;
30
import org.slf4j.LoggerFactory;
31

  
32
/**
33
 * Panel for show variables
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public class VariableTablePanel extends JPanel {
37
	private static final long serialVersionUID = 1L;
38
	private Logger            logger           = LoggerFactory.getLogger(VariableTablePanel.class.toString());
39
	private TableContainer    table            = null;
40
	private String[]          columnNames      = null;
41
	private int[]             columnWidths     = null;
42
	
43
	public VariableTablePanel() {
44
		init();
45
	}
46
	
47
	public TableContainer getTable() {
48
		if(table == null) {
49
			columnNames = new String[]{PluginServices.getText(this, "property"), PluginServices.getText(this, "value")};
50
			columnWidths = new int[]{(int)(NetCDFPanel.WIDTH * 0.3) , (int)(NetCDFPanel.WIDTH * 0.7)};
51
			table = new TableContainer(columnNames, columnWidths);
52
			table.initialize();
53
			table.setControlVisible(false);
54
		}
55
		return table;
56
	}
57

  
58
	private void init() {
59
		setLayout(new BorderLayout());
60
		add(getTable(), BorderLayout.CENTER);
61
	}
62
	
63
	public void setRows(ArrayList<String[]> varValue) {
64
		for (int i = 0; i < varValue.size(); i++) {
65
			try {
66
				table.addRow(varValue.get(i));
67
			} catch (NotInitializeException e) {
68
				logger.debug(org.gvsig.i18n.Messages.getText("error_adding_rows"), e);
69
			}
70
		}
71
	}
72

  
73
}
0 74

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/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.IconThemeHelper;
26
import org.gvsig.andami.PluginServices;
27
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction;
28
import org.gvsig.app.project.documents.view.toc.ITocItem;
29
import org.gvsig.fmap.mapcontext.layers.FLayer;
30
import org.gvsig.raster.fmap.layers.FLyrRaster;
31
import org.gvsig.raster.fmap.layers.ILayerState;
32
import org.gvsig.raster.netcdf.app.netcdfclient.gui.panel.NetCDFPanel;
33
import org.gvsig.raster.netcdf.io.NetCDFDataParameters;
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_Variables");
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
		if(((FLyrRaster) selectedItems[0]).getDataStore() != null)
124
			return (((FLyrRaster) selectedItems[0]).getDataStore().getInternalParameters() instanceof NetCDFDataParameters);
125
		return false;
126
	}
127

  
128
	/*
129
	 * (non-Javadoc)
130
	 * @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[])
131
	 */
132
	public void execute(ITocItem item, FLayer[] selectedItems) {
133
		FLayer lyr = null;
134

  
135
		if (selectedItems.length != 1)
136
			return;
137

  
138
		lyr = selectedItems[0];
139

  
140
		if (!(lyr instanceof FLyrRaster))
141
			return;
142
		
143
		FLyrRaster fLayer = (FLyrRaster)lyr;
144
		
145
		NetCDFPanel panel = new NetCDFPanel(fLayer);
146
		PluginServices.getMDIManager().addWindow(panel);
147
		//Esto es porque la llamada setHeight de getWindowInfo no funciona igual que esta. Asignan tama?os diferentes 
148
		PluginServices.getMDIManager().getWindowInfo(panel).setHeight(NetCDFPanel.HEIGHT);
149
	}
150

  
151
	/*
152
	 * (non-Javadoc)
153
	 * @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
154
	 */
155
	public Icon getIcon() {
156
		return IconThemeHelper.getImageIcon("save-icon");
157
	}
158
}
0 159

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.71/org.gvsig.raster.netcdf.app.netcdfclient/src/main/resources-plugin/text_en.properties
1
level=Level
2
gridvar=Grid Variable
3
NetCDF_Properties=NetCDF properties
4
NetCDF_Variables=NetCDF variables
5
error_stats=Error while calculatin statistics
6
coordSys=Coordinate system
7
dataType=Type of data
8
description=Description
9
dimensions=Dimensions
10
group=Group
11
name=Name
12
shape=Shape
13
units=Units
14
property=Property
15
variable_info=Variable information
16
vardescription=Variable description
17
gridvardescription=Grid variable description
18
error_adding_rows=Error while adding rows to the table
0 19

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

Also available in: Unified diff