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 / AvailableTablesCheckBoxList.java @ 40557
History | View | Annotate | Download (4.75 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 |
|
30 |
import javax.swing.JList; |
31 |
import javax.swing.JOptionPane; |
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 |
import org.slf4j.Logger; |
39 |
import org.slf4j.LoggerFactory; |
40 |
|
41 |
import org.gvsig.andami.PluginServices; |
42 |
|
43 |
|
44 |
|
45 |
/**
|
46 |
* Utility class to keep the list of available tables.
|
47 |
*
|
48 |
* @author jldominguez
|
49 |
*
|
50 |
*/
|
51 |
public class AvailableTablesCheckBoxList extends JList { |
52 |
protected static Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); |
53 |
|
54 |
private static final Logger LOG = LoggerFactory |
55 |
.getLogger(AvailableTablesCheckBoxList.class); |
56 |
private WizardDB parent = null; |
57 |
private TablesListItem actingTable = null; |
58 |
|
59 |
public AvailableTablesCheckBoxList(WizardDB p) {
|
60 |
parent = p; |
61 |
|
62 |
setCellRenderer(new CellRenderer());
|
63 |
|
64 |
addMouseListener(new MouseAdapter() { |
65 |
public void mousePressed(MouseEvent e) { |
66 |
int index = locationToIndex(e.getPoint());
|
67 |
|
68 |
if (index == -1) { |
69 |
return;
|
70 |
} |
71 |
|
72 |
actingTable = (TablesListItem) getModel().getElementAt(index); |
73 |
|
74 |
if ((e.getClickCount() == 2) || (e.getX() < 15)) { |
75 |
if (!actingTable.isActivated()) {
|
76 |
actingTable.activate(); |
77 |
} |
78 |
|
79 |
actingTable.setSelected(!actingTable.isSelected()); |
80 |
|
81 |
if (actingTable.isSelected()) {
|
82 |
actingTable.setEnabledPanels(true);
|
83 |
} |
84 |
else {
|
85 |
actingTable.setEnabledPanels(false);
|
86 |
} |
87 |
|
88 |
repaint(); |
89 |
} |
90 |
|
91 |
try {
|
92 |
parent.setSettingsPanels(actingTable); |
93 |
parent.checkFinishable(); |
94 |
} |
95 |
catch (Exception e1) { |
96 |
actingTable.setEnabledPanels(false);
|
97 |
actingTable.setSelected(false);
|
98 |
LOG.info( |
99 |
"Error while setting selected table: " +
|
100 |
e1.getMessage(), e1); |
101 |
showConnectionErrorMessage(e1.getMessage()); |
102 |
} |
103 |
} |
104 |
}); |
105 |
|
106 |
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
107 |
} |
108 |
|
109 |
private void showConnectionErrorMessage(String _msg) { |
110 |
if (_msg==null) { |
111 |
_msg="";
|
112 |
} |
113 |
String msg = (_msg.length() > 300) ? "" : (": " + _msg); |
114 |
String title = PluginServices.getText(this, "connection_error"); |
115 |
JOptionPane.showMessageDialog(this, title + msg, title, |
116 |
JOptionPane.ERROR_MESSAGE);
|
117 |
} |
118 |
|
119 |
protected class CellRenderer implements ListCellRenderer { |
120 |
public Component getListCellRendererComponent(JList list, Object value, |
121 |
int index, boolean isSelected, boolean cellHasFocus) { |
122 |
TablesListItem checkbox = (TablesListItem) value; |
123 |
checkbox.setBackground(isSelected ? getSelectionBackground() |
124 |
: getBackground()); |
125 |
checkbox.setForeground(isSelected ? getSelectionForeground() |
126 |
: getForeground()); |
127 |
checkbox.setEnabled(isEnabled()); |
128 |
checkbox.setFont(getFont()); |
129 |
checkbox.setFocusPainted(false);
|
130 |
checkbox.setBorderPainted(true);
|
131 |
checkbox.setBorder(isSelected |
132 |
? UIManager.getBorder("List.focusCellHighlightBorder") |
133 |
: noFocusBorder); |
134 |
|
135 |
return checkbox;
|
136 |
} |
137 |
} |
138 |
} |