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