svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.geodb.app / org.gvsig.geodb.app.mainplugin / src / main / java / org / gvsig / geodb / vectorialdb / wizard / AvailableFieldsCheckBoxList.java @ 40557
History | View | Annotate | Download (3.8 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.geodb.vectorialdb.wizard; |
25 |
|
26 |
import java.awt.Component; |
27 |
import java.awt.event.MouseAdapter; |
28 |
import java.awt.event.MouseEvent; |
29 |
import java.util.ArrayList; |
30 |
|
31 |
import javax.swing.JList; |
32 |
import javax.swing.ListCellRenderer; |
33 |
import javax.swing.ListSelectionModel; |
34 |
import javax.swing.UIManager; |
35 |
import javax.swing.border.Border; |
36 |
import javax.swing.border.EmptyBorder; |
37 |
|
38 |
|
39 |
/**
|
40 |
* Utility class to keep the list of available fields.
|
41 |
*
|
42 |
* @author jldominguez
|
43 |
*
|
44 |
*/
|
45 |
public class AvailableFieldsCheckBoxList extends JList { |
46 |
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); |
47 |
|
48 |
public AvailableFieldsCheckBoxList() {
|
49 |
setCellRenderer(new CellRenderer());
|
50 |
|
51 |
addMouseListener(new MouseAdapter() { |
52 |
public void mousePressed(MouseEvent e) { |
53 |
int index = locationToIndex(e.getPoint());
|
54 |
|
55 |
if (index == -1) { |
56 |
return;
|
57 |
} |
58 |
|
59 |
FieldsListItem sel = (FieldsListItem) getModel() |
60 |
.getElementAt(index); |
61 |
|
62 |
if ((e.getClickCount() == 2) || (e.getX() < 15)) { |
63 |
sel.setSelected(!sel.isSelected()); |
64 |
} |
65 |
} |
66 |
}); |
67 |
|
68 |
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
69 |
} |
70 |
|
71 |
public Object[] getCheckedItems() { |
72 |
int size = getModel().getSize();
|
73 |
ArrayList resp = new ArrayList(); |
74 |
|
75 |
for (int i = 0; i < size; i++) { |
76 |
FieldsListItem item = (FieldsListItem) getModel().getElementAt(i); |
77 |
|
78 |
if (item.isSelected()) {
|
79 |
resp.add(item); |
80 |
} |
81 |
} |
82 |
|
83 |
return resp.toArray();
|
84 |
} |
85 |
|
86 |
public void checkAll(boolean b) { |
87 |
int size = getModel().getSize();
|
88 |
|
89 |
for (int i = 0; i < size; i++) { |
90 |
FieldsListItem item = (FieldsListItem) getModel().getElementAt(i); |
91 |
item.setSelected(b); |
92 |
} |
93 |
|
94 |
updateUI(); |
95 |
} |
96 |
|
97 |
protected class CellRenderer implements ListCellRenderer { |
98 |
public Component getListCellRendererComponent(JList list, Object value, |
99 |
int index, boolean isSelected, boolean cellHasFocus) { |
100 |
FieldsListItem checkbox = (FieldsListItem) value; |
101 |
checkbox.setBackground(isSelected ? getSelectionBackground() |
102 |
: getBackground()); |
103 |
checkbox.setForeground(isSelected ? getSelectionForeground() |
104 |
: getForeground()); |
105 |
checkbox.setEnabled(isEnabled()); |
106 |
checkbox.setFont(getFont()); |
107 |
checkbox.setFocusPainted(false);
|
108 |
checkbox.setBorderPainted(true);
|
109 |
checkbox.setBorder(isSelected |
110 |
? UIManager.getBorder("List.focusCellHighlightBorder") |
111 |
: noFocusBorder); |
112 |
|
113 |
return checkbox;
|
114 |
} |
115 |
} |
116 |
} |