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