svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / Panels / DataPointsTabPanel.java @ 3102
History | View | Annotate | Download (6.26 KB)
1 |
package com.iver.cit.gvsig.gui.Panels; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.awt.geom.Point2D; |
5 |
|
6 |
import javax.swing.JOptionPane; |
7 |
import javax.swing.JPanel; |
8 |
import javax.swing.JTabbedPane; |
9 |
import javax.swing.event.ChangeEvent; |
10 |
import javax.swing.event.ChangeListener; |
11 |
|
12 |
import com.iver.andami.PluginServices; |
13 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
14 |
import com.iver.cit.gvsig.fmap.layers.FLyrGeoRaster; |
15 |
import com.iver.cit.gvsig.fmap.layers.FLyrPoints; |
16 |
import com.iver.cit.gvsig.gui.View; |
17 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
18 |
|
19 |
public class DataPointsTabPanel extends JPanel implements ChangeListener{ |
20 |
|
21 |
private GeoreferencingDialog parent = null; |
22 |
private SelectPointsPanel selectPointsPanel = null; |
23 |
private TablePointsPanel tablePointsPanel = null; |
24 |
private JTabbedPane tbPoints = null; |
25 |
private int widthTab = 380, heightTab = 185; |
26 |
|
27 |
/**
|
28 |
* This is the default constructor
|
29 |
*/
|
30 |
public DataPointsTabPanel(GeoreferencingDialog p) {
|
31 |
super();
|
32 |
this.parent = p;
|
33 |
initialize(); |
34 |
} |
35 |
|
36 |
/**
|
37 |
* This method initializes this
|
38 |
*
|
39 |
* @return void
|
40 |
*/
|
41 |
private void initialize() { |
42 |
this.setPreferredSize(new java.awt.Dimension(widthTab, heightTab)); |
43 |
this.setSize(new java.awt.Dimension(widthTab, heightTab)); |
44 |
this.setLocation(new java.awt.Point(0,0)); |
45 |
this.add(getTbPoints(), null); |
46 |
} |
47 |
|
48 |
/**
|
49 |
* @return Returns the selectPointsPanel.
|
50 |
*/
|
51 |
public TablePointsPanel getTablePointsPanel() {
|
52 |
if(tablePointsPanel == null){ |
53 |
tablePointsPanel = new TablePointsPanel(parent);
|
54 |
} |
55 |
return tablePointsPanel;
|
56 |
} |
57 |
|
58 |
/**
|
59 |
* @return Returns the selectPointsPanel.
|
60 |
*/
|
61 |
public SelectPointsPanel getSelectPointsPanel() {
|
62 |
if(selectPointsPanel == null){ |
63 |
selectPointsPanel = new SelectPointsPanel(parent);
|
64 |
} |
65 |
return selectPointsPanel;
|
66 |
} |
67 |
|
68 |
/**
|
69 |
* This method initializes jTabbedPane
|
70 |
*
|
71 |
* @return javax.swing.JTabbedPane
|
72 |
*/
|
73 |
public JTabbedPane getTbPoints() { |
74 |
if (tbPoints == null) { |
75 |
tbPoints = new JTabbedPane(); |
76 |
tbPoints.setSize(widthTab, heightTab); |
77 |
tbPoints.setPreferredSize(new java.awt.Dimension(widthTab, heightTab));
|
78 |
tbPoints.addTab("georef", this.getSelectPointsPanel()); |
79 |
tbPoints.addTab("table", this.getTablePointsPanel()); |
80 |
tbPoints.addChangeListener(this);
|
81 |
} |
82 |
return tbPoints;
|
83 |
} |
84 |
|
85 |
/**
|
86 |
* Cuando cambiamos de tab controlamos lo siguiente:
|
87 |
* <UL>
|
88 |
* <LI>Comprobamos que los TextField del selector de puntos no esten en
|
89 |
* blanco</LI>
|
90 |
* <LI>Controlamos que la ventana sea redimensionable solo cuando
|
91 |
* est? en el tab de tabla</LI>
|
92 |
* <LI>Actualizamos los controles de la ventana a la que vamos con lo
|
93 |
* que se seleccion? en la ventana de la que venimos</LI>
|
94 |
* </UL>
|
95 |
*/
|
96 |
public void stateChanged(ChangeEvent ev) { |
97 |
if (((JTabbedPane)ev.getSource()).getSelectedIndex() == 0){ |
98 |
parent.getFrame().setResizable(false);
|
99 |
if(getTablePointsPanel().getTableControlerPanel().getSelectedIndex() != -1) |
100 |
getSelectPointsPanel().updateComboPoint( |
101 |
getTablePointsPanel().getTableControlerPanel().getSelectedIndex() |
102 |
); |
103 |
} |
104 |
|
105 |
if (((JTabbedPane)ev.getSource()).getSelectedIndex() == 1){ |
106 |
try{
|
107 |
getSelectPointsPanel().checkInfoPointText(); |
108 |
}catch(NoSuchFieldException exc){ |
109 |
//Si no se han salvado los valores de un punto cuando se activa
|
110 |
//el cambio de tab las coordenadas a las que no se les ha dado
|
111 |
//valor se pondr?n a 0 y se guardar?n.
|
112 |
double tx = 0D, ty = 0D, lon = 0D, lat = 0D; |
113 |
try{
|
114 |
DataPointPanel dp = getSelectPointsPanel().getDataPointPanel(); |
115 |
if(dp.getTX() != null && !dp.getTX().equals("")) |
116 |
tx = Double.valueOf(getSelectPointsPanel().getDataPointPanel().getTX().getText()).doubleValue();
|
117 |
if(dp.getTY() != null && !dp.getTY().equals("")) |
118 |
ty = Double.valueOf(getSelectPointsPanel().getDataPointPanel().getTY().getText()).doubleValue();
|
119 |
if(dp.getLongitud() != null && !dp.getLongitud().equals("")) |
120 |
lon = Double.valueOf(getSelectPointsPanel().getDataPointPanel().getLongitud().getText()).doubleValue();
|
121 |
if(dp.getLatitud() != null && !dp.getLatitud().equals("")) |
122 |
lat = Double.valueOf(getSelectPointsPanel().getDataPointPanel().getLatitud().getText()).doubleValue();
|
123 |
}catch(NumberFormatException ex){ |
124 |
|
125 |
} |
126 |
Point2D pixel = new Point2D.Double(); |
127 |
pixel.setLocation(tx, ty); |
128 |
Point2D map = new Point2D.Double(); |
129 |
map.setLocation(lon, lat); |
130 |
|
131 |
FLyrGeoRaster lyrGeoRaster = null;
|
132 |
View theView = null; |
133 |
try{
|
134 |
theView = (View)PluginServices.getMDIManager().getActiveView();
|
135 |
}catch(ClassCastException exce){ |
136 |
return;
|
137 |
} |
138 |
for(int i=0;i<theView.getMapControl().getMapContext().getLayers().getLayersCount();i++){ |
139 |
FLayer lyr = theView.getMapControl().getMapContext().getLayers().getLayer(i); |
140 |
if( lyr instanceof FLyrGeoRaster && |
141 |
lyr.getName().startsWith("*") &&
|
142 |
lyr.isActive()) |
143 |
lyrGeoRaster = (FLyrGeoRaster)lyr; |
144 |
} |
145 |
if(lyrGeoRaster != null){ |
146 |
try{
|
147 |
lyrGeoRaster.updateData(getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedIndex() + 1,
|
148 |
pixel, |
149 |
map, |
150 |
parent, |
151 |
theView, |
152 |
lyrGeoRaster.getFLyrPoints()); |
153 |
}catch(ArrayIndexOutOfBoundsException ex){ |
154 |
//Si da una excepci?n de este tipo es que no hay cargado nin?n punto
|
155 |
//por lo que no hacemos nada.
|
156 |
}catch(ClassCastException ex){ |
157 |
//Si da una excepci?n de este tipo lo m?s probable es que no haya una
|
158 |
//vista activa y no se pueda crear una capa de puntos. Tampoco se hace nada.
|
159 |
} |
160 |
}else{
|
161 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
162 |
PluginServices.getText(this, "error_capa_puntos")); |
163 |
} |
164 |
} |
165 |
parent.getFrame().setResizable(true);
|
166 |
if(getSelectPointsPanel().getTableControlerPanel().getSelectedIndex() != -1) |
167 |
getTablePointsPanel().updateComboPoint( |
168 |
getSelectPointsPanel().getTableControlerPanel().getSelectedIndex() |
169 |
); |
170 |
|
171 |
} |
172 |
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Calculo del nuevo tama?o a partir de un frame redimensionado
|
177 |
* @param w Ancho del frame
|
178 |
* @param h Alto del frame
|
179 |
*/
|
180 |
public void newFrameSize(int w, int h){ |
181 |
int initWFrame = 385; |
182 |
int initHFrame = 185; |
183 |
int initW = 380; |
184 |
|
185 |
widthTab = (int)((initW * w)/initWFrame);
|
186 |
|
187 |
this.resize(new java.awt.Dimension(widthTab, heightTab)); |
188 |
|
189 |
this.getTablePointsPanel().newFrameSize(w, h);
|
190 |
|
191 |
} |
192 |
|
193 |
} |