svn-gvsig-desktop / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / ui / launcher / AlgorithmSelectionPanel.java @ 18530
History | View | Annotate | Download (5.46 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.ui.launcher; |
20 |
|
21 |
import java.awt.GridBagConstraints; |
22 |
import java.awt.GridBagLayout; |
23 |
import java.awt.Insets; |
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.event.ActionListener; |
26 |
|
27 |
import javax.swing.ButtonGroup; |
28 |
import javax.swing.JPanel; |
29 |
import javax.swing.JRadioButton; |
30 |
|
31 |
import org.gvsig.georeferencing.main.Georeferencing; |
32 |
import org.gvsig.raster.util.RasterToolsUtil; |
33 |
|
34 |
import com.iver.utiles.swing.JComboBox; |
35 |
|
36 |
/**
|
37 |
* Panel de selecci?n de algoritmo de georreferenciaci?n.
|
38 |
*
|
39 |
* 10/01/2008
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
41 |
*/
|
42 |
public class AlgorithmSelectionPanel extends JPanel implements ActionListener { |
43 |
private static final long serialVersionUID = 1L; |
44 |
private int polynomialDegree; |
45 |
|
46 |
private JRadioButton affine = null; |
47 |
private JRadioButton polynomial = null; |
48 |
private JComboBox degreeList = null; |
49 |
|
50 |
/**
|
51 |
* Constructor. Asigna la lista de nombres de vistas para el selector.
|
52 |
* @param viewList
|
53 |
*/
|
54 |
public AlgorithmSelectionPanel(int polynomialDegree) { |
55 |
this.polynomialDegree = polynomialDegree;
|
56 |
init(); |
57 |
} |
58 |
|
59 |
/**
|
60 |
* Acciones de inicializaci?n del panel
|
61 |
*/
|
62 |
public void init() { |
63 |
ButtonGroup group = new ButtonGroup(); |
64 |
group.add(getAffine()); |
65 |
group.add(getPolynomial()); |
66 |
getPolynomial().addActionListener(this);
|
67 |
getAffine().addActionListener(this);
|
68 |
|
69 |
GridBagLayout gl = new GridBagLayout(); |
70 |
setLayout(gl); |
71 |
setBorder(javax.swing.BorderFactory.createTitledBorder(null, RasterToolsUtil.getText(this, "georef_algorithm"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
72 |
|
73 |
GridBagConstraints gbc = new GridBagConstraints(); |
74 |
gbc.weightx = 1.0;
|
75 |
gbc.fill = GridBagConstraints.HORIZONTAL;
|
76 |
gbc.insets = new Insets(0, 5, 8, 0); |
77 |
add(getAffine(), gbc); |
78 |
|
79 |
gbc.gridy = 1;
|
80 |
gbc.insets = new Insets(0, 5, 8, 0); |
81 |
add(getPolynomial(), gbc); |
82 |
|
83 |
gbc.gridy = 2;
|
84 |
gbc.insets = new Insets(0, 35, 8, 0); |
85 |
add(getDegreeList(), gbc); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* Obtiene el radio but?n de la selecci?n sin cartograf?a de referencia
|
90 |
* @return JRadioButton
|
91 |
*/
|
92 |
public JRadioButton getAffine() { |
93 |
if(affine == null) { |
94 |
affine = new JRadioButton(RasterToolsUtil.getText(this, "affine_algorithm")); |
95 |
affine.setSelected(true);
|
96 |
actionPerformed(null);
|
97 |
} |
98 |
return affine;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Obtiene el radio but?n de la selecci?n con cartograf?a de referencia
|
103 |
* @return JRadioButton
|
104 |
*/
|
105 |
public JRadioButton getPolynomial() { |
106 |
if(polynomial == null) |
107 |
polynomial = new JRadioButton(RasterToolsUtil.getText(this, "polynomial_algorithm")); |
108 |
return polynomial;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Obtiene el combo con la lista de vistas para la selecci?n de la que contiene
|
113 |
* la cartograf?a de referencia.
|
114 |
* @return JComboBox
|
115 |
*/
|
116 |
public JComboBox getDegreeList() { |
117 |
if(degreeList == null) { |
118 |
degreeList = new JComboBox(); |
119 |
for (int i = 1; i <= polynomialDegree; i++) |
120 |
degreeList.addItem(RasterToolsUtil.getText(this, "degree") + ": " + i); |
121 |
} |
122 |
return degreeList;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* Eventos de selecci?n en los RadioButton de selecci?n de Algoritmo
|
127 |
*/
|
128 |
public void actionPerformed(ActionEvent e) { |
129 |
getDegreeList().setEnabled(getPolynomial().isSelected()); |
130 |
} |
131 |
|
132 |
|
133 |
//-------Consulta de propiedades seleccionadas---------
|
134 |
|
135 |
/**
|
136 |
* Obtiene el grado seleccionado
|
137 |
* @return valor del grado seleccionado
|
138 |
*/
|
139 |
public int getSelectedDegree() { |
140 |
if(degreeList != null && getPolynomial().isSelected()) { |
141 |
String s = (String)degreeList.getSelectedItem(); |
142 |
s = s.substring(s.lastIndexOf(": "), s.length());
|
143 |
try {
|
144 |
return Integer.valueOf(s).intValue(); |
145 |
} catch (NumberFormatException e) { |
146 |
return 0; |
147 |
} |
148 |
} |
149 |
return 0; |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Obtiene el algoritmo seleccionado
|
154 |
* @return constante definida en Georeferencing con el algoritmo seleccionado
|
155 |
*/
|
156 |
public int getAlgorithm() { |
157 |
if(getPolynomial().isSelected())
|
158 |
return Georeferencing.POLYNOMIAL;
|
159 |
if(getAffine().isSelected())
|
160 |
return Georeferencing.AFFINE;
|
161 |
return Georeferencing.UNDEFINED;
|
162 |
} |
163 |
|
164 |
/**
|
165 |
* Asigna el grado del polinomio seleccionado
|
166 |
* @param grado del polinomio
|
167 |
*/
|
168 |
public void setDegree(int degree) { |
169 |
for (int i = 0; i < degreeList.getItemCount(); i++) { |
170 |
String item = (String)degreeList.getItemAt(i); |
171 |
if(item.endsWith(": " + degree)) { |
172 |
degreeList.setSelectedIndex(i); |
173 |
return;
|
174 |
} |
175 |
} |
176 |
} |
177 |
|
178 |
/**
|
179 |
* Asigna el algoritmo
|
180 |
* @param alg
|
181 |
*/
|
182 |
public void setAlgorithm(int alg) { |
183 |
switch (alg) {
|
184 |
case Georeferencing.AFFINE:
|
185 |
getAffine().setSelected(true);
|
186 |
getPolynomial().setSelected(false);
|
187 |
break;
|
188 |
case Georeferencing.POLYNOMIAL:
|
189 |
getPolynomial().setSelected(true);
|
190 |
getAffine().setSelected(false);
|
191 |
break;
|
192 |
} |
193 |
} |
194 |
} |