Revision 21683 trunk/extensions/extRasterTools-SE/src/org/gvsig/rastertools/reproject/ui/LayerReprojectPanel.java

View differences:

LayerReprojectPanel.java
19 19
package org.gvsig.rastertools.reproject.ui;
20 20

  
21 21
import java.awt.GridBagConstraints;
22
import java.awt.GridBagLayout;
23
import java.awt.Insets;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
22 26

  
23 27
import javax.swing.BorderFactory;
24 28
import javax.swing.JPanel;
......
26 30
import org.cresques.cts.IProjection;
27 31
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
28 32
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
29
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
30 33
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
31
import org.gvsig.raster.beans.createlayer.CreateLayerPanel;
32
import org.gvsig.raster.beans.createlayer.SelectDirectoryPanel;
34
import org.gvsig.raster.beans.createlayer.NewLayerPanel;
33 35

  
34 36
import com.iver.andami.PluginServices;
35 37
import com.iver.andami.ui.mdiManager.IWindow;
36 38
import com.iver.andami.ui.mdiManager.WindowInfo;
37 39
import com.iver.cit.gvsig.fmap.crs.CRSFactory;
38

  
40
import com.iver.cit.gvsig.gui.panels.CRSSelectPanel;
41
import com.iver.cit.gvsig.project.documents.view.gui.View;
39 42
/**
40 43
 * Panel para la reproyecci?n de capas cargadas.
44
 * 
41 45
 * 28/04/2008
42 46
 * @author Nacho Brodin nachobrodin@gmail.com
43 47
 */
44 48
public class LayerReprojectPanel extends DefaultButtonsPanel implements IWindow {
45
	private static final long        serialVersionUID   = 1L;
46
	private CreateLayerPanel         createLayerPanel   = null;
47
	private JPanel                   nameFile           = null;
48
	private ProjectionChooserPanel   projectionSelector = null;
49
	private int                      w                  = 420;
50
	private int                      h                  = 290;
51
	private IProjection              proj               = null;
52
	private SelectDirectoryPanel     dirPanel           = null;
53
	private JPanel                   filePanel          = null;
54
	
49
	private static final long serialVersionUID = -1011688195806336071L;
50
	private NewLayerPanel          newLayerPanel         = null;
51
	private JPanel                 nameFile              = null;
52
	private CRSSelectPanel         projectionSrcSelector = null;
53
	private CRSSelectPanel         projectionDstSelector = null;
54
	private IProjection            projSrc               = null;
55
	private IProjection            projDst               = null;
56
	private JPanel                 filePanel             = null;
57
	private LayerReprojectListener reprojectListener     = null;
58
	private FLyrRasterSE           lyr                   = null;
59
	private String                 viewName              = null;
60

  
55 61
	/**
56 62
	 * Constructor
57 63
	 */
58 64
	public LayerReprojectPanel(FLyrRasterSE lyr) {
59
		proj = lyr.getProjection();
60
		getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setVisible(true);
61
		new LayerReprojectListener(lyr, this);
62
		
65
		super(ButtonsPanel.BUTTONS_ACCEPTCANCEL);
66
		setLayer(lyr);
63 67
		init();
64 68
	}
65 69
	
70
	/*
71
	 * (non-Javadoc)
72
	 * @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
73
	 */
74
	public WindowInfo getWindowInfo() {
75
		WindowInfo windowInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
76
		windowInfo.setTitle(PluginServices.getText(this, "capa_a_reproyectar"));
77
		windowInfo.setWidth(320);
78
		windowInfo.setHeight(280);
79
		return windowInfo;
80
	}
81
	
82
	private void setLayer(FLyrRasterSE lyr) {
83
		this.lyr = lyr;
84

  
85
		if (this.lyr == null)
86
			return;
87

  
88
		
89
		View view = (View) PluginServices.getMDIManager().getActiveWindow();
90
		viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle();
91
		
92
		projSrc = this.lyr.readProjection();
93
		if (projSrc == null)
94
			projSrc = CRSFactory.getCRS("EPSG:23030");
95

  
96
		projDst = CRSFactory.getCRS("EPSG:23030");
97

  
98
		getLayerReprojectListener().setLayer(this.lyr);
99
	}
100
	
101
	private LayerReprojectListener getLayerReprojectListener() {
102
		if (reprojectListener == null) {
103
			reprojectListener = new LayerReprojectListener(this);
104
			addButtonPressedListener(reprojectListener);
105
		}
106
		return reprojectListener;
107
	}
108
	
66 109
	/**
67 110
	 * Inicializaci?n de los componentes gr?ficos.
68 111
	 */
69 112
	private void init() {
70
		java.awt.GridBagConstraints gbc;
71
		setLayout(new java.awt.GridBagLayout());
113
		GridBagConstraints gridBagConstraints;
114

  
115
		setLayout(new GridBagLayout());
72 116
		
73
		gbc = new java.awt.GridBagConstraints();
74
		gbc.gridx = 0;
75
		gbc.gridy = 0;
76
		gbc.weightx = 1D;
77
		gbc.fill = GridBagConstraints.HORIZONTAL;
78
		gbc.anchor = GridBagConstraints.WEST;
79
		gbc.insets = new java.awt.Insets(0, 0, 0, 5);
80
		add(getProjectionSelector(), gbc);
117
		int posy = 0;
118
		gridBagConstraints = new GridBagConstraints();
119
		gridBagConstraints.fill = GridBagConstraints.BOTH;
120
		gridBagConstraints.gridx = 0;
121
		gridBagConstraints.gridy = posy;
122
		gridBagConstraints.weightx = 1.0;
123
		gridBagConstraints.insets = new Insets(5, 5, 2, 5);
124
		add(getProjectionSrcSelector(), gridBagConstraints);
125

  
126
		posy++;
127
		gridBagConstraints = new GridBagConstraints();
128
		gridBagConstraints.fill = GridBagConstraints.BOTH;
129
		gridBagConstraints.gridx = 0;
130
		gridBagConstraints.gridy = posy;
131
		gridBagConstraints.weightx = 1.0;
132
		gridBagConstraints.insets = new Insets(2, 5, 2, 5);
133
		add(getProjectionDstSelector(), gridBagConstraints);
81 134
		
82
		gbc.gridy = 1;
83
		//add(getCreateLayerPanel(), gbc);
135
		posy++;
136
		gridBagConstraints = new GridBagConstraints();
137
		gridBagConstraints.gridx = 0;
138
		gridBagConstraints.gridy = posy;
139
		gridBagConstraints.fill = GridBagConstraints.BOTH;
140
		gridBagConstraints.insets = new Insets(2, 5, 2, 5);
141
		add(getNewLayerPanel().getJPanel(), gridBagConstraints);
84 142
		
85
		gbc.gridy = 2;
86
		add(getFilePanel(), gbc);
143
		posy++;
144
		gridBagConstraints = new GridBagConstraints();
145
		gridBagConstraints.gridx = 0;
146
		gridBagConstraints.gridy = posy;
147
		gridBagConstraints.fill = GridBagConstraints.BOTH;
148
		gridBagConstraints.insets = new Insets(2, 5, 0, 5);
149
		add(getFilePanel(), gridBagConstraints);
150

  
151
		// Insertamos un panel vacio
152
		posy++;
153
		gridBagConstraints = new GridBagConstraints();
154
		gridBagConstraints.gridx = 0;
155
		gridBagConstraints.gridy = posy;
156
		gridBagConstraints.weighty = 1.0;
157
		gridBagConstraints.insets = new Insets(0, 0, 0, 0);
158
		JPanel emptyPanel = new JPanel();
159
		add(emptyPanel, gridBagConstraints);
87 160
	}
88 161
	
89 162
	/**
90 163
	 * Obtiene el panel de destino de fichero y nombre de capa
91 164
	 * @return JPanel
92 165
	 */
93
	public JPanel getFilePanel() {
94
		if(filePanel == null) {
166
	private JPanel getFilePanel() {
167
		if (filePanel == null) {
95 168
			filePanel = new JPanel();
96 169
			filePanel.setBorder(BorderFactory.createTitledBorder("dest_file"));
97
			filePanel.setLayout(new java.awt.GridBagLayout());
98
			
99
			GridBagConstraints gbc = new java.awt.GridBagConstraints();
170
			filePanel.setLayout(new GridBagLayout());
171

  
172
			GridBagConstraints gbc = new GridBagConstraints();
100 173
			gbc.gridx = 0;
101 174
			gbc.gridy = 0;
102 175
			gbc.weightx = 1D;
103 176
			gbc.fill = GridBagConstraints.HORIZONTAL;
104 177
			gbc.anchor = GridBagConstraints.WEST;
105
			gbc.insets = new java.awt.Insets(0, 0, 0, 5);
178
			gbc.insets = new Insets(0, 0, 0, 5);
106 179
			filePanel.add(getNameFilePanel(), gbc);
107
			
108
			gbc.gridy = 1;
109
			filePanel.add(getDirPanel(), gbc);
110 180
		}
111 181
		return filePanel;
112 182
	}
113
	
183

  
114 184
	/**
115
	 * Obtiene el panel para la selecci?n de directorios
116
	 * @return
185
	 * Obtiene el desplegable con la lista de capas
186
	 * @return JComboBox
117 187
	 */
118
	public JPanel getDirPanel() {
119
		if(dirPanel == null) {
120
			dirPanel = new SelectDirectoryPanel();
188
	protected NewLayerPanel getNewLayerPanel() {
189
		if (newLayerPanel == null) {
190
			newLayerPanel = new NewLayerPanel();
191
			newLayerPanel.getJPanel().setBorder(BorderFactory.createTitledBorder("layer"));
121 192
		}
122
		return dirPanel;
193
		return newLayerPanel;
123 194
	}
124 195
	
125 196
	/**
126
	 * Obtiene el desplegable con la lista de capas
127
	 * @return JComboBox
197
	 * Obtiene el nombre de la vista
198
	 * @return
128 199
	 */
129
	public CreateLayerPanel getCreateLayerPanel() {
130
		if(createLayerPanel == null) {
131
			createLayerPanel = new CreateLayerPanel();
132
			//createLayerPanel.setBorder(BorderFactory.createTitledBorder("layer"));
133
		}
134
		return createLayerPanel;
200
	public String getViewName() {
201
		return viewName;
135 202
	}
136 203
	
137 204
	/**
138 205
	 * Obtiene el desplegable con la lista de capas
139 206
	 * @return JComboBox
140 207
	 */
141
	public JPanel getNameFilePanel() {
208
	private JPanel getNameFilePanel() {
142 209
		if(nameFile == null) {
143
			nameFile = getCreateLayerPanel().getFileNamePanel();
210
			nameFile = getNewLayerPanel().getFileNamePanel();
144 211
		}
145 212
		return nameFile;
146 213
	}
147
		
214

  
148 215
	/**
149 216
	 * Obtiene el bot?n que lanza el panel de selecci?n de proyecciones.
150 217
	 * @return
151 218
	 */
152
	public ProjectionChooserPanel getProjectionSelector() {
153
		if(projectionSelector == null) {
154
			IProjection crs = null;
155
			try {
156
				crs = CRSFactory.getCRS("23030");
157
			} catch (NumberFormatException ex) {
158
				return null;
159
			}
160
			projectionSelector =  new ProjectionChooserPanel(proj);
161
			projectionSelector.setBorder(BorderFactory.createTitledBorder("dest_proj"));
162
			//projectionSelector.
163
			//((CRSMainPanel)projectionSelector.getContentPanel()).getJButtonAccept().setVisible(false);
164
			//((CRSMainPanel)projectionSelector.getContentPanel()).getJButtonCancel().setVisible(false);
219
	private CRSSelectPanel getProjectionSrcSelector() {
220
		if (projectionSrcSelector == null) {
221
			projectionSrcSelector = CRSSelectPanel.getPanel(projSrc);
222
			projectionSrcSelector.setTransPanelActive(true);
223
			projectionSrcSelector.setPreferredSize(null);
224
			projectionSrcSelector.addActionListener(new ActionListener() {
225
				public void actionPerformed(ActionEvent e) {
226
					if (projectionSrcSelector.isOkPressed()) {
227
						projSrc = projectionSrcSelector.getCurProj();
228
					}
229
				}
230
			});
231
			projectionSrcSelector.setBorder(BorderFactory.createTitledBorder("src_proj"));
165 232
		}
166
		return projectionSelector;
233
		return projectionSrcSelector;
167 234
	}
168 235
	
169
	/* (non-Javadoc)
170
	 * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
236
	/**
237
	 * Obtiene el bot?n que lanza el panel de selecci?n de proyecciones.
238
	 * @return
171 239
	 */
172
	public WindowInfo getWindowInfo() {
173
		WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
174
  		m_viewinfo.setTitle(PluginServices.getText(this, "capa_a_reproyectar"));
175
  		m_viewinfo.setWidth(w);
176
  		m_viewinfo.setHeight(h);
177
		return m_viewinfo;
240
	private CRSSelectPanel getProjectionDstSelector() {
241
		if (projectionDstSelector == null) {
242
			projectionDstSelector = CRSSelectPanel.getPanel(projDst);
243
			projectionDstSelector.setTransPanelActive(true);
244
			projectionDstSelector.setPreferredSize(null);
245
			projectionDstSelector.addActionListener(new ActionListener() {
246
				public void actionPerformed(ActionEvent e) {
247
					if (projectionDstSelector.isOkPressed()) {
248
						projDst = projectionDstSelector.getCurProj();
249
					}
250
				}
251
			});
252
			projectionDstSelector.setBorder(BorderFactory.createTitledBorder("dest_proj"));
253
		}
254
		return projectionDstSelector;
178 255
	}
179
	
180
	public void actionButtonPressed(ButtonsPanelEvent e) {
181
		
256

  
257
	/**
258
	 * @return the projSrc
259
	 */
260
	public IProjection getProjectionSrc() {
261
		return projSrc;
182 262
	}
183
}
263

  
264
	/**
265
	 * @return the projDst
266
	 */
267
	public IProjection getProjectionDst() {
268
		return projDst;
269
	}
270
}

Also available in: Unified diff