svn-gvsig-desktop / tags / v1_0_2_Build_908 / extensions / extCAD / src / com / iver / cit / gvsig / gui / cad / snapping / panels / SnapConfig.java @ 11054
History | View | Annotate | Download (6.77 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. 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 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.cad.snapping.panels; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.util.ArrayList; |
45 |
import java.util.Vector; |
46 |
|
47 |
import javax.swing.JCheckBox; |
48 |
import javax.swing.JList; |
49 |
import javax.swing.JPanel; |
50 |
import javax.swing.JScrollPane; |
51 |
import javax.swing.JTable; |
52 |
import javax.swing.ListCellRenderer; |
53 |
import javax.swing.table.AbstractTableModel; |
54 |
import javax.swing.table.DefaultTableModel; |
55 |
|
56 |
import com.iver.cit.gvsig.gui.cad.snapping.ISnapper; |
57 |
; |
58 |
|
59 |
/**
|
60 |
* @author fjp
|
61 |
*
|
62 |
* Necesitamos un sitio donde est?n registrados todos los snappers que
|
63 |
* se pueden usar. ExtensionPoints es el sitio adecuado.
|
64 |
* Este di?logo recuperar? esa lista para que el usuario marque los
|
65 |
* snappers con los que desea trabajar.
|
66 |
*/
|
67 |
public class SnapConfig extends JPanel { |
68 |
|
69 |
private JCheckBox jChkBoxRefentActive = null; |
70 |
private JTable jListSnappers = null; |
71 |
private JPanel jPanel = null; |
72 |
private JScrollPane jScrollPane = null; |
73 |
|
74 |
private ArrayList snappers; |
75 |
|
76 |
/**
|
77 |
* @author fjp
|
78 |
* primera columna editable con un check box para habilitar/deshabilitar el snapper
|
79 |
* segunda columna con el s?mbolo del snapper
|
80 |
* tercera con el tooltip
|
81 |
* cuarta con un bot?n para configurar el snapper si es necesario.
|
82 |
*/
|
83 |
class MyTableModel extends AbstractTableModel { |
84 |
|
85 |
public ArrayList mySnappers; |
86 |
|
87 |
public MyTableModel(ArrayList snappers) |
88 |
{ |
89 |
this.mySnappers = snappers;
|
90 |
} |
91 |
|
92 |
public int getColumnCount() { |
93 |
return 4; |
94 |
} |
95 |
|
96 |
public int getRowCount() { |
97 |
return mySnappers.size();
|
98 |
} |
99 |
|
100 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
101 |
if (columnIndex == 0) |
102 |
return true; |
103 |
else
|
104 |
return false; |
105 |
} |
106 |
|
107 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
108 |
ISnapper snap = (ISnapper) mySnappers.get(rowIndex); |
109 |
switch (columnIndex)
|
110 |
{ |
111 |
case 0: |
112 |
snap.setEnabled(((Boolean)aValue).booleanValue());
|
113 |
} |
114 |
|
115 |
} |
116 |
|
117 |
public Object getValueAt(int rowIndex, int columnIndex) { |
118 |
ISnapper snap = (ISnapper) mySnappers.get(rowIndex); |
119 |
switch (columnIndex)
|
120 |
{ |
121 |
case 0: |
122 |
return new Boolean(snap.isEnabled()); |
123 |
case 1: |
124 |
return snap;
|
125 |
case 2: |
126 |
return snap.getToolTipText();
|
127 |
} |
128 |
return null; |
129 |
} |
130 |
|
131 |
public Class getColumnClass(int columnIndex) { |
132 |
switch (columnIndex)
|
133 |
{ |
134 |
case 0: |
135 |
return Boolean.class; |
136 |
case 1: |
137 |
return String.class; |
138 |
case 2: |
139 |
return String.class; |
140 |
case 3: |
141 |
return String.class; |
142 |
} |
143 |
return null; |
144 |
} |
145 |
|
146 |
public String getColumnName(int column) { |
147 |
// TODO Auto-generated method stub
|
148 |
return super.getColumnName(column); |
149 |
} |
150 |
|
151 |
} |
152 |
|
153 |
class MyCellRenderer extends JCheckBox implements ListCellRenderer { |
154 |
|
155 |
// This is the only method defined by ListCellRenderer.
|
156 |
// We just reconfigure the JLabel each time we're called.
|
157 |
|
158 |
public Component getListCellRendererComponent( |
159 |
JList list,
|
160 |
Object value, // value to display |
161 |
int index, // cell index |
162 |
boolean isSelected, // is the cell selected |
163 |
boolean cellHasFocus) // the list and the cell have the focus |
164 |
{ |
165 |
ISnapper snapper = (ISnapper) value; |
166 |
String s = snapper.getToolTipText();
|
167 |
setText(s); |
168 |
|
169 |
if (isSelected) {
|
170 |
setBackground(list.getSelectionBackground()); |
171 |
setForeground(list.getSelectionForeground()); |
172 |
} |
173 |
else {
|
174 |
setBackground(list.getBackground()); |
175 |
setForeground(list.getForeground()); |
176 |
} |
177 |
setEnabled(list.isEnabled()); |
178 |
setFont(list.getFont()); |
179 |
setOpaque(true);
|
180 |
return this; |
181 |
} |
182 |
|
183 |
public void doClick() { |
184 |
super.doClick();
|
185 |
System.out.println("Click"); |
186 |
} |
187 |
|
188 |
|
189 |
} |
190 |
|
191 |
|
192 |
/**
|
193 |
* This method initializes
|
194 |
*
|
195 |
*/
|
196 |
public SnapConfig() {
|
197 |
super();
|
198 |
initialize(); |
199 |
} |
200 |
|
201 |
/**
|
202 |
* This method initializes this
|
203 |
*
|
204 |
*/
|
205 |
private void initialize() { |
206 |
this.setLayout(null); |
207 |
this.setSize(new java.awt.Dimension(463,239)); |
208 |
this.setPreferredSize(new java.awt.Dimension(463,239)); |
209 |
this.add(getJChkBoxRefentActive(), null); |
210 |
this.add(getJPanel(), null); |
211 |
|
212 |
} |
213 |
|
214 |
/**
|
215 |
* This method initializes jChkBoxRefentActive
|
216 |
*
|
217 |
* @return javax.swing.JCheckBox
|
218 |
*/
|
219 |
private JCheckBox getJChkBoxRefentActive() { |
220 |
if (jChkBoxRefentActive == null) { |
221 |
jChkBoxRefentActive = new JCheckBox(); |
222 |
jChkBoxRefentActive.setText("Referencia a Objetos Activada:");
|
223 |
jChkBoxRefentActive.setBounds(new java.awt.Rectangle(26,10,418,23)); |
224 |
} |
225 |
return jChkBoxRefentActive;
|
226 |
} |
227 |
|
228 |
/**
|
229 |
* This method initializes jListSnappers
|
230 |
*
|
231 |
* @return javax.swing.JList
|
232 |
*/
|
233 |
private JTable getJListSnappers() { |
234 |
if (jListSnappers == null) { |
235 |
jListSnappers = new JTable(); |
236 |
// jListSnappers.setCellRenderer(new MyCellRenderer());
|
237 |
} |
238 |
return jListSnappers;
|
239 |
} |
240 |
|
241 |
/**
|
242 |
* This method initializes jPanel
|
243 |
*
|
244 |
* @return javax.swing.JPanel
|
245 |
*/
|
246 |
private JPanel getJPanel() { |
247 |
if (jPanel == null) { |
248 |
jPanel = new JPanel(); |
249 |
jPanel.setLayout(null);
|
250 |
jPanel.setBounds(new java.awt.Rectangle(19,40,423,181)); |
251 |
jPanel.add(getJScrollPane(), null);
|
252 |
} |
253 |
return jPanel;
|
254 |
} |
255 |
|
256 |
/**
|
257 |
* This method initializes jScrollPane
|
258 |
*
|
259 |
* @return javax.swing.JScrollPane
|
260 |
*/
|
261 |
private JScrollPane getJScrollPane() { |
262 |
if (jScrollPane == null) { |
263 |
jScrollPane = new JScrollPane(); |
264 |
jScrollPane.setBounds(new java.awt.Rectangle(9,9,402,163)); |
265 |
jScrollPane.setViewportView(getJListSnappers()); |
266 |
} |
267 |
return jScrollPane;
|
268 |
} |
269 |
|
270 |
public ArrayList getSnappers() { |
271 |
return snappers;
|
272 |
} |
273 |
|
274 |
public void setSnappers(ArrayList snappers) { |
275 |
this.snappers = snappers;
|
276 |
MyTableModel listModel = new MyTableModel(snappers);
|
277 |
getJListSnappers().setModel(listModel); |
278 |
} |
279 |
|
280 |
|
281 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
282 |
|
283 |
|