svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / toc / GeoRasterTocMenuEntry.java @ 5584
History | View | Annotate | Download (8.29 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package org.gvsig.georeferencing.toc; |
42 |
|
43 |
import java.awt.event.ActionEvent; |
44 |
import java.awt.geom.Point2D; |
45 |
|
46 |
import javax.swing.JDesktopPane; |
47 |
import javax.swing.JInternalFrame; |
48 |
import javax.swing.JLayeredPane; |
49 |
import javax.swing.JMenuItem; |
50 |
|
51 |
import org.gvsig.georeferencing.gui.dialogs.GeoreferencingDialog; |
52 |
import org.gvsig.georeferencing.utils.GeoPointPersistence; |
53 |
import org.gvsig.georeferencing.utils.MathUtils; |
54 |
import org.gvsig.georeferencing.utils.PointManager; |
55 |
import org.gvsig.georeferencing.utils.StackZoom; |
56 |
|
57 |
import com.iver.andami.PluginServices; |
58 |
import com.iver.andami.ui.mdiFrame.MDIFrame; |
59 |
import com.iver.cit.gvsig.fmap.FMap; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
62 |
import com.iver.cit.gvsig.gui.View; |
63 |
import com.iver.cit.gvsig.gui.toc.FPopupMenu; |
64 |
import com.iver.cit.gvsig.gui.toc.TocMenuEntry; |
65 |
|
66 |
/**
|
67 |
* Entrada del men? del TOC que obtiene el cuadro de propiedades de capa
|
68 |
* georreferenciada.
|
69 |
*
|
70 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
71 |
*/
|
72 |
public class GeoRasterTocMenuEntry extends TocMenuEntry{ |
73 |
private JMenuItem propsMenuItem; |
74 |
private FLayer lyr = null; |
75 |
public static boolean isOpen = false; |
76 |
|
77 |
public void initialize(FPopupMenu m) { |
78 |
super.initialize(m);
|
79 |
|
80 |
if (isTocItemBranch()) {
|
81 |
lyr = getNodeLayer(); |
82 |
|
83 |
// Opcciones para capas FLyrGeoRaster
|
84 |
if ((lyr instanceof FLyrGeoRaster)) { |
85 |
propsMenuItem = new JMenuItem(PluginServices.getText(this, "georaster")); |
86 |
getMenu().add( propsMenuItem ); |
87 |
propsMenuItem.setFont(FPopupMenu.theFont); |
88 |
getMenu().setEnabled(true);
|
89 |
propsMenuItem.addActionListener(this);
|
90 |
} |
91 |
} |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Evento producido al pulsar la entrada de men? del toc
|
96 |
* que muestra el cuadro con el dialogo de las propiedades
|
97 |
* de la capa de raster georreferenciada.
|
98 |
*/
|
99 |
public void actionPerformed(ActionEvent e) { |
100 |
FLyrGeoRaster lyrGeoRaster = null;
|
101 |
GeoreferencingDialog geoDialog = null;
|
102 |
|
103 |
//Caso en el que se crea una capa de georreferenciaci?n al abrir un proyecto
|
104 |
//hay que crear el dialogo, la persistencia y la pila de zooms y asignarlo a
|
105 |
//la capa de puntos. Todo esto se hace aqu? porque al levantar la capa desde el
|
106 |
//setXMLEntity no podemos acceder al c?digo de gvSIG
|
107 |
if(((FLyrGeoRaster)lyr).getPersistence() == null && ((FLyrGeoRaster)lyr).getZoom() == null){ |
108 |
JInternalFrame panel = PointManager.getInternalFrame(this); |
109 |
geoDialog = new GeoreferencingDialog(panel, ((FLyrGeoRaster)lyr));
|
110 |
((FLyrGeoRaster)lyr).getStackZoom().setInitExtent(((FLyrGeoRaster)lyr).getAssignExtent(), true);
|
111 |
((FLyrGeoRaster)lyr).getFLyrPoints().saveState(); |
112 |
((FLyrGeoRaster)lyr).setGeoDialog(geoDialog); |
113 |
GeoPointPersistence geoPointPersistence = new GeoPointPersistence();
|
114 |
StackZoom zoom = new StackZoom();
|
115 |
((FLyrGeoRaster)lyr).setPersistence(geoPointPersistence); |
116 |
((FLyrGeoRaster)lyr).setZoom(zoom); |
117 |
GeoRasterTocMenuEntry.isOpen = true;
|
118 |
} |
119 |
|
120 |
if(isOpen){
|
121 |
GeoRasterTocMenuEntry.isOpen = false;
|
122 |
lyr = getNodeLayer(); |
123 |
|
124 |
PluginServices.getMainFrame().enableControls(); |
125 |
|
126 |
//Modificamos el nombre de la capa
|
127 |
if (lyr instanceof FLyrGeoRaster){ |
128 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
129 |
lyrGeoRaster.setName("*"+lyrGeoRaster.getName());
|
130 |
lyrGeoRaster.setActive(true);
|
131 |
geoDialog = (GeoreferencingDialog)lyrGeoRaster.getGeoDialog(); |
132 |
geoDialog.getSelectPointsPanel().resetControls(false);
|
133 |
geoDialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().clearTable(); |
134 |
geoDialog.getSelectPointsPanel().setEnlarge(true);
|
135 |
geoDialog.getLyrPoints().setVisible(true);
|
136 |
|
137 |
if(lyrGeoRaster.getFLyrPoints() != null){ |
138 |
//Salvamos el estado actual de la capa por si se cancela.
|
139 |
lyrGeoRaster.getFLyrPoints().saveState(); |
140 |
|
141 |
View theView = null; |
142 |
try{
|
143 |
theView = (View) PluginServices.getMDIManager().getActiveView();
|
144 |
}catch(ClassCastException exc){ |
145 |
return ;
|
146 |
} |
147 |
|
148 |
//Asignamos la capa de puntos como capa grafica
|
149 |
FMap fmap = theView.getMapControl().getMapContext(); |
150 |
if(fmap != null) |
151 |
fmap.setGraphicsLayer(lyrGeoRaster.getFLyrPoints()); |
152 |
|
153 |
//Hacemos visible la capa de puntos
|
154 |
lyrGeoRaster.getFLyrPoints().setVisible(true);
|
155 |
theView.getMapControl().getMapContext().invalidate(); |
156 |
|
157 |
geoDialog.getConectorPanel().getDataPointsTabPanel(). |
158 |
getSelectPointsPanel().getTableControlerPanel().setNItems(lyrGeoRaster.getFLyrPoints().getCountPoints()); |
159 |
|
160 |
if(lyrGeoRaster.getFLyrPoints().getCountPoints() > 0){ |
161 |
//Cargamos el primer punto en el panel
|
162 |
lyrGeoRaster.getFLyrPoints().getPointManager().selectPoint(0, geoDialog);
|
163 |
|
164 |
//Activamos controles
|
165 |
if(lyrGeoRaster.getFLyrPoints().getCountPoints() > 0){ |
166 |
geoDialog.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getBDelPoint().setEnabled(true);
|
167 |
geoDialog.getConectorPanel().getDataPointsTabPanel().getSelectPointsPanel().getTableControlerPanel().getBClear().setEnabled(true);
|
168 |
geoDialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getPButtonsExportImportPanel().getBSave().setEnabled(true);
|
169 |
geoDialog.getConectorPanel().getDataPointsTabPanel().getTablePointsPanel().getPButtonsExportImportPanel().getBExportToAscii().setEnabled(true);
|
170 |
} |
171 |
|
172 |
//Cargamos la tabla de puntos al abrir el dialogo con el valor actual de estos
|
173 |
for(int i=0;i<lyrGeoRaster.getFLyrPoints().getCountPoints();i++){ |
174 |
geoDialog.addTableNew(); |
175 |
geoDialog.setTableValueAt(String.valueOf(i + 1), i, 0); |
176 |
Point2D pixel = lyrGeoRaster.getFLyrPoints().getPoint(i).pixelPoint;
|
177 |
if(pixel != null){ |
178 |
geoDialog.setTableValueAt(MathUtils.tailDecimals(String.valueOf(pixel.getX()), 5), i, 1); |
179 |
geoDialog.setTableValueAt(MathUtils.tailDecimals(String.valueOf(pixel.getY()), 5), i, 2); |
180 |
} |
181 |
Point2D map = lyrGeoRaster.getFLyrPoints().getPoint(i).mapPoint;
|
182 |
if(map != null){ |
183 |
geoDialog.setTableValueAt(MathUtils.tailDecimals(String.valueOf(map.getX()), 5), i, 3); |
184 |
geoDialog.setTableValueAt(MathUtils.tailDecimals(String.valueOf(map.getY()), 5), i, 4); |
185 |
} |
186 |
geoDialog.getPointManager().setErrors(i); |
187 |
} |
188 |
|
189 |
} |
190 |
} |
191 |
} |
192 |
|
193 |
//Lanzamos el dialogo
|
194 |
JInternalFrame panel = PointManager.getInternalFrame(this); |
195 |
panel.getContentPane().add(geoDialog); |
196 |
geoDialog.setEnlarge(false);
|
197 |
geoDialog.setSelectedTab(0);
|
198 |
geoDialog.setFrame(panel); |
199 |
|
200 |
MDIFrame mainFrame = (MDIFrame) PluginServices.getMainFrame(); |
201 |
JLayeredPane lyrPane = mainFrame.getLayeredPane();
|
202 |
lyrPane.add(panel, JDesktopPane.PALETTE_LAYER);
|
203 |
panel.pack(); |
204 |
panel.setSize(geoDialog.getWidth() + 12, geoDialog.getHeight() + 10); |
205 |
panel.show(); |
206 |
|
207 |
PluginServices.getMainFrame().enableControls(); |
208 |
} |
209 |
} |
210 |
|
211 |
|
212 |
} |