root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / NewCRSPanel.java @ 10789
History | View | Annotate | Download (10.8 KB)
1 |
package org.gvsig.crs.gui.panels; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
5 |
import java.awt.FlowLayout; |
6 |
import java.awt.GridLayout; |
7 |
import java.awt.event.ActionEvent; |
8 |
import java.awt.event.ActionListener; |
9 |
import java.awt.event.KeyEvent; |
10 |
import java.awt.event.KeyListener; |
11 |
|
12 |
import javax.swing.ButtonGroup; |
13 |
import javax.swing.JButton; |
14 |
import javax.swing.JLabel; |
15 |
import javax.swing.JPanel; |
16 |
import javax.swing.JRadioButton; |
17 |
import javax.swing.JScrollPane; |
18 |
import javax.swing.JTable; |
19 |
import javax.swing.JTextField; |
20 |
import javax.swing.ListSelectionModel; |
21 |
import javax.swing.border.CompoundBorder; |
22 |
import javax.swing.border.EmptyBorder; |
23 |
import javax.swing.table.DefaultTableModel; |
24 |
import javax.swing.table.TableColumn; |
25 |
|
26 |
import org.gvsig.crs.gui.panels.wizard.MainPanel; |
27 |
|
28 |
import com.iver.andami.PluginServices; |
29 |
import com.iver.cit.gvsig.gui.TableSorter; |
30 |
|
31 |
/**
|
32 |
* Crea la interfaz de definici?n de un nuevo crs por el usuario
|
33 |
* @author Luisa Marina Fernandez Ruiz (luisam.fernandez@uclm.es)
|
34 |
*
|
35 |
*/
|
36 |
public class NewCRSPanel extends JPanel implements ActionListener,KeyListener{ |
37 |
private static final long serialVersionUID = 1L; |
38 |
|
39 |
private JRadioButton codeRadioButton = null; |
40 |
private JRadioButton nameRadioButton = null; |
41 |
private JRadioButton areaRadioButton = null; |
42 |
private JLabel lblCriterio=null; |
43 |
private JButton searchButton = null; |
44 |
private JTextField searchTextField = null; |
45 |
private JButton infoCrs; |
46 |
private JButton btnNuevo; |
47 |
private JButton btnEditar; |
48 |
private JButton btnEliminar; |
49 |
private JScrollPane jScrollPane=null; |
50 |
private JTable jTable; |
51 |
public TableSorter sorter = null; |
52 |
public DefaultTableModel dtm = null; |
53 |
|
54 |
public NewCRSPanel() {
|
55 |
super();
|
56 |
initialize(); |
57 |
//fijar los listener de todos los componentes
|
58 |
setListener(); |
59 |
habilitarJbuttons(false);
|
60 |
} |
61 |
/**
|
62 |
* Inicializa this
|
63 |
*
|
64 |
*/
|
65 |
private void initialize(){ |
66 |
this.setLayout(new BorderLayout()); |
67 |
this.setBorder(new EmptyBorder(1,1,1,1)); |
68 |
//Este panel contiene los componentes de radio button
|
69 |
JPanel radio=new JPanel(); |
70 |
radio.setLayout(new GridLayout(1,4,10,0)); |
71 |
radio.add(getLblCriterio()); |
72 |
radio.add(getCodeRadioButton()); |
73 |
radio.add(getNameRadioButton()); |
74 |
radio.add(getAreaRadioButton()); |
75 |
//Agrupar los radioButtons
|
76 |
agruparRadioButtons(); |
77 |
//Este panel contiene los componentes relacionados con la b?squeda
|
78 |
JPanel busqueda=new JPanel(); |
79 |
busqueda.setLayout(new FlowLayout(FlowLayout.LEFT,10,1)); |
80 |
busqueda.add(getSearchButton()); |
81 |
busqueda.add(getSearchTextField()); |
82 |
//busqueda.setBackground(Color.red);
|
83 |
JPanel pNorth=new JPanel(); |
84 |
pNorth.setLayout(new GridLayout(2,1)); |
85 |
pNorth.add(radio); |
86 |
pNorth.add(busqueda); |
87 |
this.add(pNorth,BorderLayout.NORTH); |
88 |
//agregar los botones de la tabla
|
89 |
JPanel pInSouth=new JPanel(); |
90 |
pInSouth.setLayout(new FlowLayout(FlowLayout.LEFT,10,0)); |
91 |
pInSouth.add(getInfoCrs()); |
92 |
pInSouth.add(getBtnNuevo()); |
93 |
pInSouth.add(getBtnEditar()); |
94 |
pInSouth.add(getBtnEliminar()); |
95 |
JPanel pCenter=new JPanel(); |
96 |
pCenter.setLayout(new BorderLayout()); |
97 |
pCenter.add(getJScrollPane(),BorderLayout.CENTER);
|
98 |
pCenter.add(pInSouth,BorderLayout.SOUTH);
|
99 |
this.add(pCenter,BorderLayout.CENTER); |
100 |
|
101 |
|
102 |
|
103 |
} |
104 |
/**
|
105 |
* Inicializa el bot?n que muestra la informaci?n de CRS seleccionado
|
106 |
* @return
|
107 |
*/
|
108 |
public JButton getInfoCrs() { |
109 |
if(infoCrs == null) { |
110 |
infoCrs = new JButton(); |
111 |
infoCrs.setPreferredSize(new Dimension(85,23)); |
112 |
infoCrs.setText(PluginServices.getText(this,"infocrs")); |
113 |
infoCrs.setMnemonic('I');
|
114 |
infoCrs.setToolTipText(PluginServices.getText(this,"more_info")); |
115 |
|
116 |
} |
117 |
return infoCrs;
|
118 |
} |
119 |
/**
|
120 |
* Inicializa el panel que contiene la tabla de resultados
|
121 |
* @return
|
122 |
*/
|
123 |
private JScrollPane getJScrollPane() { |
124 |
if (jScrollPane == null) { |
125 |
jScrollPane = new JScrollPane(getJTable(),JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
126 |
jScrollPane.setPreferredSize(new Dimension(500,150)); |
127 |
jScrollPane.setBorder(new CompoundBorder(new EmptyBorder(3,10,3,10),jScrollPane.getBorder())); |
128 |
jScrollPane.setViewportView(getJTable()); |
129 |
} |
130 |
return jScrollPane;
|
131 |
} |
132 |
/**
|
133 |
* Inicializa la tabla que se utiliza para mostrar
|
134 |
* los resultados de la b?squeda
|
135 |
* @return
|
136 |
*/
|
137 |
public JTable getJTable() { |
138 |
if (jTable == null) { |
139 |
//TODO: Poner los titulos de las columnas correspondientes
|
140 |
String[] columnNames= {PluginServices.getText(this,"codigo"), |
141 |
PluginServices.getText(this,"nombre"), |
142 |
PluginServices.getText(this,"tipo"), |
143 |
PluginServices.getText(this,"area"), |
144 |
PluginServices.getText(this,"descripcion")}; |
145 |
Object[][]data = {}; |
146 |
dtm = new DefaultTableModel(data, columnNames) |
147 |
{ |
148 |
private static final long serialVersionUID = 1L; |
149 |
public boolean isCellEditable(int row, int column) { |
150 |
return false; |
151 |
} |
152 |
/*
|
153 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
154 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
155 |
* actual al seleccionar una fila (non-Javadoc)
|
156 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
157 |
*/
|
158 |
public Class getColumnClass(int column) |
159 |
{ |
160 |
return getValueAt(0, column).getClass(); |
161 |
} |
162 |
}; |
163 |
sorter = new TableSorter(dtm);
|
164 |
|
165 |
jTable = new JTable(sorter); |
166 |
//jTable.setPreferredSize(new Dimension(800, 100));
|
167 |
sorter.setTableHeader(jTable.getTableHeader()); |
168 |
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
169 |
jTable.setCellSelectionEnabled(false);
|
170 |
jTable.setRowSelectionAllowed(true);
|
171 |
jTable.setColumnSelectionAllowed(false);
|
172 |
jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
173 |
TableColumn column = null; |
174 |
for (int i = 0; i < columnNames.length; i++) { |
175 |
column = jTable.getColumnModel().getColumn(i); |
176 |
if (i == 0) { |
177 |
column.setPreferredWidth(50); //code column is shorter |
178 |
} |
179 |
else if (i == 2) { |
180 |
column.setPreferredWidth(80);
|
181 |
} |
182 |
else if (i==4){ |
183 |
column.setPreferredWidth(300);
|
184 |
} |
185 |
else {
|
186 |
column.setPreferredWidth(140);
|
187 |
} |
188 |
} |
189 |
} |
190 |
|
191 |
return jTable;
|
192 |
|
193 |
} |
194 |
/**
|
195 |
* Inicializa el radioButton 'Codigo'
|
196 |
* @return jRadioButton
|
197 |
*/
|
198 |
public JRadioButton getCodeRadioButton() { |
199 |
if (codeRadioButton == null) { |
200 |
codeRadioButton = new JRadioButton(); |
201 |
codeRadioButton.setText(PluginServices.getText(this,"por_codigo")); |
202 |
codeRadioButton.setSelected(true);
|
203 |
codeRadioButton.addActionListener(this);
|
204 |
} |
205 |
return codeRadioButton;
|
206 |
} |
207 |
/**
|
208 |
* Inicializa el radioButton 'Name'
|
209 |
* @return jRadioButton
|
210 |
*/
|
211 |
public JRadioButton getNameRadioButton() { |
212 |
if (nameRadioButton == null) { |
213 |
nameRadioButton = new JRadioButton(); |
214 |
nameRadioButton.setText(PluginServices.getText(this,"por_nombre")); |
215 |
nameRadioButton.addActionListener(this);
|
216 |
} |
217 |
return nameRadioButton;
|
218 |
} |
219 |
/**
|
220 |
* Inicializa el radioButton 'Area'
|
221 |
* @return jRadioButton
|
222 |
*/
|
223 |
public JRadioButton getAreaRadioButton() { |
224 |
if (areaRadioButton == null) { |
225 |
areaRadioButton = new JRadioButton(); |
226 |
areaRadioButton.setText(PluginServices.getText(this,"por_area")); |
227 |
areaRadioButton.addActionListener(this);
|
228 |
} |
229 |
return areaRadioButton;
|
230 |
} |
231 |
/**
|
232 |
* Agrupa los radioButtons
|
233 |
*/
|
234 |
private void agruparRadioButtons(){ |
235 |
ButtonGroup group= new ButtonGroup(); |
236 |
group.add(getCodeRadioButton()); |
237 |
group.add(getNameRadioButton()); |
238 |
group.add(getAreaRadioButton()); |
239 |
} |
240 |
/**
|
241 |
* Inicializa el label 'Criterio de B?squeda'
|
242 |
* @return jLabel
|
243 |
*/
|
244 |
public JLabel getLblCriterio() { |
245 |
lblCriterio = new JLabel(); |
246 |
lblCriterio.setText(PluginServices.getText(this, "criterio_busqueda")+":"); |
247 |
return lblCriterio;
|
248 |
} |
249 |
/**
|
250 |
* Inicializa el bot?n 'Buscar'
|
251 |
* @return jButton
|
252 |
*/
|
253 |
public JButton getSearchButton() { |
254 |
if (searchButton == null) { |
255 |
searchButton = new JButton(); |
256 |
searchButton.setPreferredSize(new Dimension(75,20)); |
257 |
searchButton.setText(PluginServices.getText(this,"buscar")); |
258 |
searchButton.setMnemonic('S');
|
259 |
searchButton.setToolTipText(PluginServices.getText(this,"buscar_por_criterio_seleccion")); |
260 |
|
261 |
} |
262 |
return searchButton;
|
263 |
} |
264 |
/**
|
265 |
* Inicializa el TextField
|
266 |
* en el que se incluye el texto a buscar
|
267 |
* @return jTextField
|
268 |
*/
|
269 |
public JTextField getSearchTextField() { |
270 |
if (searchTextField == null) { |
271 |
searchTextField = new JTextField(); |
272 |
searchTextField.setPreferredSize(new Dimension(340,20)); |
273 |
|
274 |
} |
275 |
return searchTextField;
|
276 |
} |
277 |
/**
|
278 |
* Manejador de eventos
|
279 |
*/
|
280 |
public void actionPerformed(ActionEvent e) { |
281 |
if (e.getSource().equals(getCodeRadioButton())){
|
282 |
getSearchTextField().setText("");
|
283 |
}else if (e.getSource().equals(getNameRadioButton())){ |
284 |
getSearchTextField().setText("");
|
285 |
}else if (e.getSource().equals(getAreaRadioButton())){ |
286 |
getSearchTextField().setText("");
|
287 |
}else if (e.getSource().equals(getInfoCrs())){ |
288 |
//abrir el panel de informacion
|
289 |
|
290 |
}else if (e.getSource().equals(getBtnEditar())){ |
291 |
//editar la fila seleccionada de la tabla (si hay)
|
292 |
}else if (e.getSource().equals(getBtnEliminar())){ |
293 |
//eliminar la fila seleccionada de la tabla
|
294 |
}else if (e.getSource().equals(getBtnNuevo())){ |
295 |
//mostrar el asistente de nuevo crs
|
296 |
|
297 |
MainPanel wizard = new MainPanel();
|
298 |
PluginServices.getMDIManager().addWindow(wizard); |
299 |
|
300 |
}else if (e.getSource().equals(getSearchButton())){ |
301 |
//comprobar el texto y buscar
|
302 |
} |
303 |
} |
304 |
public void keyPressed(KeyEvent e) { |
305 |
//Si se pulsa intro-->Buscar
|
306 |
if (e.getSource() == this.getSearchTextField()) { |
307 |
if (e.getKeyCode() == 10) { |
308 |
getSearchTextField().setText("Buscar el texto");
|
309 |
//searchButton();
|
310 |
} |
311 |
} |
312 |
} |
313 |
public void keyReleased(KeyEvent e) { |
314 |
|
315 |
} |
316 |
public void keyTyped(KeyEvent e) { |
317 |
|
318 |
} |
319 |
/**
|
320 |
* Inicializa el bot?n 'Editar' una fila de la tabla
|
321 |
* @return jButton
|
322 |
*/
|
323 |
public JButton getBtnEditar() { |
324 |
if (btnEditar==null){ |
325 |
btnEditar=new JButton(); |
326 |
btnEditar.setText(PluginServices.getText(this,"editar")); |
327 |
} |
328 |
return btnEditar;
|
329 |
} |
330 |
/**
|
331 |
* Inicializa el bot?n 'Eliminar' una fila de la tabla
|
332 |
* @return
|
333 |
*/
|
334 |
public JButton getBtnEliminar() { |
335 |
if (btnEliminar==null){ |
336 |
btnEliminar=new JButton(); |
337 |
btnEliminar.setText(PluginServices.getText(this,"eliminar")); |
338 |
} |
339 |
return btnEliminar;
|
340 |
} |
341 |
/**
|
342 |
* Inicializa el bot?n 'Nuevo' para la creaci?n de un nuevo Crs
|
343 |
* @return
|
344 |
*/
|
345 |
public JButton getBtnNuevo() { |
346 |
if (btnNuevo==null){ |
347 |
btnNuevo=new JButton(); |
348 |
btnNuevo.setText(PluginServices.getText(this,"nuevo")); |
349 |
} |
350 |
return btnNuevo;
|
351 |
} |
352 |
/**
|
353 |
* Establece los listener de todos los componentes
|
354 |
*/
|
355 |
private void setListener(){ |
356 |
getBtnEditar().addActionListener(this);
|
357 |
getBtnEliminar().addActionListener(this);
|
358 |
getBtnNuevo().addActionListener(this);
|
359 |
getInfoCrs().addActionListener(this);
|
360 |
getCodeRadioButton().addActionListener(this);
|
361 |
getNameRadioButton().addActionListener(this);
|
362 |
getAreaRadioButton().addActionListener(this);
|
363 |
getSearchButton().addActionListener(this);
|
364 |
getSearchTextField().addKeyListener(this);
|
365 |
|
366 |
} |
367 |
private void habilitarJbuttons(boolean b){ |
368 |
getInfoCrs().setEnabled(b); |
369 |
getBtnEditar().setEnabled(b); |
370 |
getBtnEliminar().setEnabled(b); |
371 |
} |
372 |
|
373 |
} |