svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / com / iver / cit / gvsig / gui / panels / DataPointsTabPanel.java @ 4831
History | View | Annotate | Download (7.12 KB)
1 | 4686 | nacho | package com.iver.cit.gvsig.gui.panels; |
---|---|---|---|
2 | |||
3 | import java.awt.Component; |
||
4 | 4769 | nacho | import java.awt.Cursor; |
5 | 4686 | nacho | import java.awt.geom.Point2D; |
6 | |||
7 | import javax.swing.JOptionPane; |
||
8 | import javax.swing.JPanel; |
||
9 | import javax.swing.JTabbedPane; |
||
10 | import javax.swing.event.ChangeEvent; |
||
11 | import javax.swing.event.ChangeListener; |
||
12 | |||
13 | import com.iver.andami.PluginServices; |
||
14 | import com.iver.cit.gvsig.gui.View; |
||
15 | import com.iver.cit.gvsig.gui.dialogs.GeoreferencingDialog; |
||
16 | import com.iver.cit.gvsig.gui.pointsTable.TablePointsPanel; |
||
17 | import com.iver.cit.gvsig.gui.selectPoints.DataPointPanel; |
||
18 | import com.iver.cit.gvsig.gui.selectPoints.SelectPointsPanel; |
||
19 | |||
20 | public class DataPointsTabPanel extends JPanel implements ChangeListener{ |
||
21 | |||
22 | 4750 | nacho | 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 | 4686 | nacho | |
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 | 4735 | nacho | this.setPreferredSize(new java.awt.Dimension(395,210)); |
45 | this.setSize(new java.awt.Dimension(395,210)); |
||
46 | 4686 | nacho | 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 | 4735 | nacho | tbPoints.setPreferredSize(new java.awt.Dimension(390,205)); |
90 | 4686 | nacho | 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 | 4769 | nacho | if (((JTabbedPane)ev.getSource()).getSelectedIndex() == 0 || ((JTabbedPane)ev.getSource()).getSelectedIndex() == 2){ |
112 | 4686 | nacho | 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 | 4769 | nacho | parent.newFrameSize(parent.getTmpWidth(), parent.getEnlargeHeight()); |
129 | 4686 | nacho | }else{
|
130 | parent.getFrame().setSize(parent.getTmpWidth(), parent.getNormalHeight() + 10);
|
||
131 | 4769 | nacho | parent.newFrameSize(parent.getTmpWidth(), parent.getNormalHeight()); |
132 | 4686 | nacho | } |
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 | 4700 | nacho | parent.getPointManager().updateData(getSelectPointsPanel().getTableControlerPanel().getCPoint().getSelectedIndex() + 1,
|
170 | 4686 | nacho | 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 | } |