svn-gvsig-desktop / branches / v10 / frameworks / _fwAndami / src / com / iver / andami / ui / wizard / UnsavedDataPanel.java @ 12595
History | View | Annotate | Download (12 KB)
1 |
package com.iver.andami.ui.wizard; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.GridBagConstraints; |
8 |
import java.awt.GridBagLayout; |
9 |
import java.awt.event.ActionEvent; |
10 |
import java.awt.event.ActionListener; |
11 |
import java.awt.event.ComponentListener; |
12 |
import java.awt.event.MouseEvent; |
13 |
import java.awt.event.MouseListener; |
14 |
import java.lang.reflect.Array; |
15 |
import java.util.ArrayList; |
16 |
import java.util.Iterator; |
17 |
|
18 |
import javax.swing.JCheckBox; |
19 |
import javax.swing.JLabel; |
20 |
import javax.swing.JPanel; |
21 |
import javax.swing.JScrollPane; |
22 |
|
23 |
import org.gvsig.gui.beans.swing.JButton; |
24 |
|
25 |
import com.iver.andami.PluginServices; |
26 |
import com.iver.andami.plugins.status.IUnsavedData; |
27 |
import com.iver.andami.ui.mdiManager.IWindow; |
28 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
29 |
|
30 |
public class UnsavedDataPanel extends JPanel implements IWindow, ActionListener { |
31 |
private JPanel pResources = null; |
32 |
private JPanel pButtons = null; |
33 |
private JScrollPane pScrollList = null; |
34 |
private myList list = null; |
35 |
private JLabel lblDescription = null; |
36 |
private JButton botSave = null; |
37 |
private JButton botDontExit = null; |
38 |
private JPanel pActionButtons = null; |
39 |
private JPanel pSelectionButtons = null; |
40 |
private JButton botSelectAll = null; |
41 |
private JButton botDeselectAll = null; |
42 |
|
43 |
private ArrayList listeners = new ArrayList(); |
44 |
private JLabel lblResourceDescription = null; |
45 |
private IUnsavedData[] unsavedDataList; |
46 |
|
47 |
|
48 |
|
49 |
/**
|
50 |
* This is the default constructor
|
51 |
*/
|
52 |
public UnsavedDataPanel(IUnsavedData[] unsavedDatalist) { |
53 |
super();
|
54 |
initialize(); |
55 |
} |
56 |
|
57 |
/**
|
58 |
* This method initializes this
|
59 |
*
|
60 |
* @return void
|
61 |
*/
|
62 |
private void initialize() { |
63 |
BorderLayout borderLayout = new BorderLayout(); |
64 |
borderLayout.setHgap(5);
|
65 |
borderLayout.setVgap(5);
|
66 |
lblDescription = new JLabel(); |
67 |
lblDescription.setText(PluginServices.getText(this, "select_resorces_to_save_before_exit")); |
68 |
lblDescription.setPreferredSize(new Dimension(497, 40)); |
69 |
lblDescription.setName("lblDescription");
|
70 |
this.setLayout(borderLayout);
|
71 |
this.setSize(388, 412); |
72 |
this.add(getPResources(), java.awt.BorderLayout.CENTER);
|
73 |
this.add(getPButtons(), java.awt.BorderLayout.SOUTH);
|
74 |
this.add(lblDescription, BorderLayout.NORTH); |
75 |
} |
76 |
|
77 |
/**
|
78 |
* This method initializes pResources
|
79 |
*
|
80 |
* @return javax.swing.JPanel
|
81 |
*/
|
82 |
private JPanel getPResources() { |
83 |
if (pResources == null) { |
84 |
pResources = new JPanel(); |
85 |
pResources.setLayout(new BorderLayout()); |
86 |
pResources.add(getPScrollList(), BorderLayout.CENTER);
|
87 |
pResources.add(getLblResourceDescription(), BorderLayout.SOUTH);
|
88 |
} |
89 |
return pResources;
|
90 |
} |
91 |
|
92 |
|
93 |
/**
|
94 |
* This method initializes lblResourceDescription
|
95 |
*
|
96 |
* @return javax.swing.JLabel
|
97 |
*/
|
98 |
private JLabel getLblResourceDescription() { |
99 |
if (lblResourceDescription == null) { |
100 |
lblResourceDescription = new JLabel(); |
101 |
lblResourceDescription.setText("");
|
102 |
lblResourceDescription.setPreferredSize(new Dimension(38, 50)); |
103 |
lblResourceDescription.setName("lblResourceDescription");
|
104 |
} |
105 |
return lblResourceDescription;
|
106 |
} |
107 |
|
108 |
|
109 |
/**
|
110 |
* This method initializes pButtons
|
111 |
*
|
112 |
* @return javax.swing.JPanel
|
113 |
*/
|
114 |
private JPanel getPButtons() { |
115 |
if (pButtons == null) { |
116 |
BorderLayout borderLayout2 = new BorderLayout(); |
117 |
borderLayout2.setHgap(5);
|
118 |
borderLayout2.setVgap(5);
|
119 |
pButtons = new JPanel(); |
120 |
pButtons.setLayout(borderLayout2); |
121 |
pButtons.add(getPSelectionButtons(), BorderLayout.NORTH);
|
122 |
pButtons.add(getPActionButtons(), BorderLayout.SOUTH);
|
123 |
} |
124 |
return pButtons;
|
125 |
} |
126 |
|
127 |
/**
|
128 |
* This method initializes pScrollList
|
129 |
*
|
130 |
* @return javax.swing.JScrollPane
|
131 |
*/
|
132 |
private JScrollPane getPScrollList() { |
133 |
if (pScrollList == null) { |
134 |
pScrollList = new JScrollPane(); |
135 |
pScrollList.setPreferredSize(new java.awt.Dimension(350,350)); |
136 |
pScrollList.setViewportView(getList()); |
137 |
} |
138 |
return pScrollList;
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* This method initializes list
|
143 |
*
|
144 |
* @return javax.swing.JList
|
145 |
*/
|
146 |
private myList getList() {
|
147 |
if (list == null) { |
148 |
list = new myList();
|
149 |
} |
150 |
return list;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* This method initializes botSave
|
155 |
*
|
156 |
* @return javax.swing.JButton
|
157 |
*/
|
158 |
private JButton getBotSave() { |
159 |
if (botSave == null) { |
160 |
botSave = new JButton(); |
161 |
botSave.setName("botSave");
|
162 |
botSave.setToolTipText(PluginServices.getText(this, "save_selected_resources_and_exit")); |
163 |
botSave.setText(PluginServices.getText(this, "save_resources")); |
164 |
botSave.setActionCommand("Save");
|
165 |
botSave.addActionListener(this);
|
166 |
} |
167 |
return botSave;
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* This method initializes botDontExit
|
172 |
*
|
173 |
* @return javax.swing.JButton
|
174 |
*/
|
175 |
private JButton getBotDontExit() { |
176 |
if (botDontExit == null) { |
177 |
botDontExit = new JButton(); |
178 |
botDontExit.setName("botDontExit");
|
179 |
botDontExit.setToolTipText(PluginServices.getText(this, "cancel_the_exit_from_the_application")); |
180 |
botDontExit.setText(PluginServices.getText(this, "dont_exit")); |
181 |
botDontExit.setActionCommand("DontExit");
|
182 |
botDontExit.addActionListener(this);
|
183 |
} |
184 |
return botDontExit;
|
185 |
} |
186 |
|
187 |
/**
|
188 |
* This method initializes pActionButtons
|
189 |
*
|
190 |
* @return javax.swing.JPanel
|
191 |
*/
|
192 |
private JPanel getPActionButtons() { |
193 |
if (pActionButtons == null) { |
194 |
FlowLayout flowLayout = new FlowLayout(); |
195 |
flowLayout.setAlignment(FlowLayout.RIGHT);
|
196 |
pActionButtons = new JPanel(); |
197 |
pActionButtons.setLayout(flowLayout); |
198 |
pActionButtons.setName("pActionButtons");
|
199 |
pActionButtons.add(getBotSave(), null);
|
200 |
pActionButtons.add(getBotDontExit(), null);
|
201 |
} |
202 |
return pActionButtons;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* This method initializes pSelectionButtons
|
207 |
*
|
208 |
* @return javax.swing.JPanel
|
209 |
*/
|
210 |
private JPanel getPSelectionButtons() { |
211 |
if (pSelectionButtons == null) { |
212 |
FlowLayout flowLayout1 = new FlowLayout(); |
213 |
flowLayout1.setAlignment(FlowLayout.LEFT);
|
214 |
pSelectionButtons = new JPanel(); |
215 |
pSelectionButtons.setLayout(flowLayout1); |
216 |
pSelectionButtons.setName("pSelectionButtons");
|
217 |
pSelectionButtons.add(getBotSelectAll(), null);
|
218 |
pSelectionButtons.add(getBotDeselectAll(), null);
|
219 |
} |
220 |
return pSelectionButtons;
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* This method initializes botSelectAll
|
225 |
*
|
226 |
* @return javax.swing.JButton
|
227 |
*/
|
228 |
private JButton getBotSelectAll() { |
229 |
if (botSelectAll == null) { |
230 |
botSelectAll = new JButton(); |
231 |
botSelectAll.setText(PluginServices.getText(this, "select_all")); |
232 |
botSelectAll.setName("botSelectAll");
|
233 |
botSelectAll.setToolTipText(PluginServices.getText(this, "select_all_resources")); |
234 |
botSelectAll.addActionListener(this);
|
235 |
} |
236 |
return botSelectAll;
|
237 |
} |
238 |
|
239 |
/**
|
240 |
* This method initializes botDeselectAll
|
241 |
*
|
242 |
* @return javax.swing.JButton
|
243 |
*/
|
244 |
private JButton getBotDeselectAll() { |
245 |
if (botDeselectAll == null) { |
246 |
botDeselectAll = new JButton(); |
247 |
botDeselectAll.setName("botDeselectAll");
|
248 |
botDeselectAll.setToolTipText(PluginServices.getText(this, "deselect_all_resources")); |
249 |
botDeselectAll.setText(PluginServices.getText(this, "deselect_all")); |
250 |
botDeselectAll.addActionListener(this);
|
251 |
} |
252 |
return botDeselectAll;
|
253 |
} |
254 |
|
255 |
public WindowInfo getWindowInfo() {
|
256 |
// TODO Auto-generated method stub
|
257 |
return null; |
258 |
} |
259 |
|
260 |
public void addActionListener(UnsavedDataPanelListener listener){ |
261 |
this.listeners.add(listener);
|
262 |
} |
263 |
|
264 |
public void removeActionListener(UnsavedDataPanelListener listener){ |
265 |
this.listeners.remove(listener);
|
266 |
} |
267 |
|
268 |
public class UnsavedDataPanelListener { |
269 |
public void dontExit(UnsavedDataPanel panel){ |
270 |
|
271 |
} |
272 |
|
273 |
public void saveData(UnsavedDataPanel panel){ |
274 |
|
275 |
} |
276 |
} |
277 |
|
278 |
private class myList extends JPanel{ |
279 |
|
280 |
/**
|
281 |
*
|
282 |
*/
|
283 |
private static final long serialVersionUID = 3179254463477354501L; |
284 |
|
285 |
private GridBagConstraints constraints; |
286 |
|
287 |
public myList(){
|
288 |
super();
|
289 |
initialize(); |
290 |
} |
291 |
|
292 |
private void initialize(){ |
293 |
this.setLayout(new GridBagLayout()); |
294 |
this.constraints = new GridBagConstraints(); |
295 |
this.constraints.fill = GridBagConstraints.HORIZONTAL; |
296 |
this.constraints.gridy = 0; |
297 |
this.constraints.gridwidth =GridBagConstraints.REMAINDER; |
298 |
this.constraints.weightx = 1.0; |
299 |
|
300 |
} |
301 |
|
302 |
public void addItem(myUnsavedItem item){ |
303 |
this.add(item, this.constraints); |
304 |
} |
305 |
} |
306 |
|
307 |
private class myUnsavedItem extends JPanel{ |
308 |
/**
|
309 |
*
|
310 |
*/
|
311 |
private static final long serialVersionUID = -6280057775368437349L; |
312 |
private JCheckBox chkChecked; |
313 |
private JLabel lblText; |
314 |
private IUnsavedData dataItem;
|
315 |
|
316 |
public myUnsavedItem(IUnsavedData dataItem ){
|
317 |
super();
|
318 |
this.initialize();
|
319 |
this.setData(dataItem);
|
320 |
} |
321 |
|
322 |
private void initialize(){ |
323 |
this.setLayout(new BorderLayout()); |
324 |
this.add(this.getChkChecked(),BorderLayout.WEST); |
325 |
this.add(this.getLblText(),BorderLayout.CENTER); |
326 |
} |
327 |
|
328 |
private JLabel getLblText() { |
329 |
if (lblText == null){ |
330 |
lblText = new JLabel(); |
331 |
lblText.setName("lblText");
|
332 |
} |
333 |
return lblText;
|
334 |
} |
335 |
|
336 |
private JCheckBox getChkChecked() { |
337 |
if (chkChecked == null){ |
338 |
chkChecked = new JCheckBox(); |
339 |
chkChecked.setName("chkChecked");
|
340 |
chkChecked.setSelected(true);
|
341 |
} |
342 |
return chkChecked;
|
343 |
} |
344 |
|
345 |
public boolean isSelected(){ |
346 |
return getChkChecked().isSelected();
|
347 |
} |
348 |
|
349 |
public void setSelected(boolean selected){ |
350 |
getChkChecked().setSelected(selected); |
351 |
} |
352 |
|
353 |
public void setData(IUnsavedData dataItem){ |
354 |
this.dataItem = dataItem;
|
355 |
JLabel lbl = getLblText();
|
356 |
lbl.setIcon(dataItem.getIcon()); |
357 |
lbl.setText(dataItem.getResourceName()); |
358 |
getChkChecked().setSelected(true);
|
359 |
} |
360 |
|
361 |
public IUnsavedData getData(){
|
362 |
return this.dataItem; |
363 |
} |
364 |
|
365 |
public String getDescription(){ |
366 |
return this.dataItem.getDescription(); |
367 |
} |
368 |
|
369 |
|
370 |
} |
371 |
|
372 |
public void actionPerformed(ActionEvent e) { |
373 |
if (e.getActionCommand() == "DontExit"){ |
374 |
fireDontExitEvent(); |
375 |
return;
|
376 |
} |
377 |
if (e.getActionCommand() == "Save"){ |
378 |
fireSaveEvent(); |
379 |
return;
|
380 |
} |
381 |
if (e.getActionCommand() == "SelectAll"){ |
382 |
selectAll(); |
383 |
return;
|
384 |
} |
385 |
if (e.getActionCommand() == "DeselectAll"){ |
386 |
deselectAll(); |
387 |
return;
|
388 |
} |
389 |
} |
390 |
|
391 |
private void fireSaveEvent() { |
392 |
Iterator iter = this.listeners.iterator(); |
393 |
while (iter.hasNext()){
|
394 |
((UnsavedDataPanelListener)iter.next()).dontExit(this);
|
395 |
} |
396 |
|
397 |
} |
398 |
|
399 |
private void fireDontExitEvent() { |
400 |
Iterator iter = this.listeners.iterator(); |
401 |
while (iter.hasNext()){
|
402 |
((UnsavedDataPanelListener)iter.next()).dontExit(this);
|
403 |
} |
404 |
} |
405 |
|
406 |
private void setSelectedsAll( boolean selected){ |
407 |
int i;
|
408 |
myList theList = getList(); |
409 |
myUnsavedItem item; |
410 |
for (i=0;i < theList.getComponentCount();i++){ |
411 |
item = (myUnsavedItem)theList.getComponent(i); |
412 |
item.setSelected(selected); |
413 |
} |
414 |
} |
415 |
|
416 |
private void deselectAll() { |
417 |
this.setSelectedsAll(false); |
418 |
} |
419 |
|
420 |
private void selectAll() { |
421 |
this.setSelectedsAll(true); |
422 |
} |
423 |
|
424 |
|
425 |
public void setUnsavedDataArray(IUnsavedData[] unsavedDatalist){ |
426 |
int i;
|
427 |
this.unsavedDataList = unsavedDatalist;
|
428 |
myList theList = getList(); |
429 |
theList.removeAll(); |
430 |
|
431 |
for (i=0;i < unsavedDatalist.length;i++){ |
432 |
theList.addItem(this.newItem(unsavedDatalist[i]));
|
433 |
} |
434 |
|
435 |
} |
436 |
|
437 |
private myUnsavedItem newItem(IUnsavedData itemData){
|
438 |
myUnsavedItem item; |
439 |
item = new myUnsavedItem(itemData);
|
440 |
item.addMouseListener(new MouseListener(){ |
441 |
|
442 |
public void mouseClicked(MouseEvent e) { |
443 |
myUnsavedItem item = (myUnsavedItem)e.getComponent(); |
444 |
getLblResourceDescription().setText( |
445 |
PluginServices.getText(this, item.getDescription())
|
446 |
); |
447 |
} |
448 |
|
449 |
public void mouseEntered(MouseEvent e) { |
450 |
// TODO Auto-generated method stub
|
451 |
|
452 |
} |
453 |
|
454 |
public void mouseExited(MouseEvent e) { |
455 |
// TODO Auto-generated method stub
|
456 |
|
457 |
} |
458 |
|
459 |
public void mousePressed(MouseEvent e) { |
460 |
// TODO Auto-generated method stub
|
461 |
|
462 |
} |
463 |
|
464 |
public void mouseReleased(MouseEvent e) { |
465 |
// TODO Auto-generated method stub
|
466 |
|
467 |
} |
468 |
|
469 |
|
470 |
}); |
471 |
return item;
|
472 |
} |
473 |
|
474 |
private IUnsavedData[] getUnsavedData(boolean selected){ |
475 |
int i;
|
476 |
myList theList = getList(); |
477 |
ArrayList aList = new ArrayList(); |
478 |
myUnsavedItem item; |
479 |
IUnsavedData[] result;
|
480 |
|
481 |
for (i=0;i < theList.getComponentCount();i++){ |
482 |
item = (myUnsavedItem)theList.getComponent(i); |
483 |
if (item.isSelected() == selected){
|
484 |
aList.add(item.getData()); |
485 |
} |
486 |
} |
487 |
result = new IUnsavedData[aList.size()];
|
488 |
System.arraycopy(aList.toArray(), 0, result, 0, aList.size()); |
489 |
return result;
|
490 |
} |
491 |
|
492 |
|
493 |
public IUnsavedData[] getSelectedsUnsavedData(){ |
494 |
return this.getUnsavedData(true); |
495 |
|
496 |
} |
497 |
|
498 |
public IUnsavedData[] getUnselectedsUnsavedData(){ |
499 |
return this.getUnsavedData(false); |
500 |
} |
501 |
|
502 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
503 |
|