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