root / branches / v2_0_0_prep / extensions / extGeoDB / src / org / gvsig / geodb / vectorialdb / wizard / AvailableFieldsCheckBoxList.java @ 29628
History | View | Annotate | Download (4.16 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package org.gvsig.geodb.vectorialdb.wizard; |
44 |
|
45 |
import java.awt.Component; |
46 |
import java.awt.event.MouseAdapter; |
47 |
import java.awt.event.MouseEvent; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import javax.swing.JList; |
51 |
import javax.swing.ListCellRenderer; |
52 |
import javax.swing.ListSelectionModel; |
53 |
import javax.swing.UIManager; |
54 |
import javax.swing.border.Border; |
55 |
import javax.swing.border.EmptyBorder; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Utility class to keep the list of available fields.
|
60 |
*
|
61 |
* @author jldominguez
|
62 |
*
|
63 |
*/
|
64 |
public class AvailableFieldsCheckBoxList extends JList { |
65 |
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); |
66 |
|
67 |
public AvailableFieldsCheckBoxList() {
|
68 |
setCellRenderer(new CellRenderer());
|
69 |
|
70 |
addMouseListener(new MouseAdapter() { |
71 |
public void mousePressed(MouseEvent e) { |
72 |
int index = locationToIndex(e.getPoint());
|
73 |
|
74 |
if (index == -1) { |
75 |
return;
|
76 |
} |
77 |
|
78 |
FieldsListItem sel = (FieldsListItem) getModel() |
79 |
.getElementAt(index); |
80 |
|
81 |
if ((e.getClickCount() == 2) || (e.getX() < 15)) { |
82 |
sel.setSelected(!sel.isSelected()); |
83 |
} |
84 |
} |
85 |
}); |
86 |
|
87 |
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
88 |
} |
89 |
|
90 |
public Object[] getCheckedItems() { |
91 |
int size = getModel().getSize();
|
92 |
ArrayList resp = new ArrayList(); |
93 |
|
94 |
for (int i = 0; i < size; i++) { |
95 |
FieldsListItem item = (FieldsListItem) getModel().getElementAt(i); |
96 |
|
97 |
if (item.isSelected()) {
|
98 |
resp.add(item); |
99 |
} |
100 |
} |
101 |
|
102 |
return resp.toArray();
|
103 |
} |
104 |
|
105 |
public void checkAll(boolean b) { |
106 |
int size = getModel().getSize();
|
107 |
|
108 |
for (int i = 0; i < size; i++) { |
109 |
FieldsListItem item = (FieldsListItem) getModel().getElementAt(i); |
110 |
item.setSelected(b); |
111 |
} |
112 |
|
113 |
updateUI(); |
114 |
} |
115 |
|
116 |
protected class CellRenderer implements ListCellRenderer { |
117 |
public Component getListCellRendererComponent(JList list, Object value, |
118 |
int index, boolean isSelected, boolean cellHasFocus) { |
119 |
FieldsListItem checkbox = (FieldsListItem) value; |
120 |
checkbox.setBackground(isSelected ? getSelectionBackground() |
121 |
: getBackground()); |
122 |
checkbox.setForeground(isSelected ? getSelectionForeground() |
123 |
: getForeground()); |
124 |
checkbox.setEnabled(isEnabled()); |
125 |
checkbox.setFont(getFont()); |
126 |
checkbox.setFocusPainted(false);
|
127 |
checkbox.setBorderPainted(true);
|
128 |
checkbox.setBorder(isSelected |
129 |
? UIManager.getBorder("List.focusCellHighlightBorder") |
130 |
: noFocusBorder); |
131 |
|
132 |
return checkbox;
|
133 |
} |
134 |
} |
135 |
} |