root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / project / documents / view / snapping / gui / SnapConfig.java @ 8943
History | View | Annotate | Download (8.63 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.project.documents.view.snapping.gui; |
42 |
|
43 |
import java.awt.Component; |
44 |
import java.util.ArrayList; |
45 |
import java.util.TreeMap; |
46 |
|
47 |
import javax.swing.JButton; |
48 |
import javax.swing.JCheckBox; |
49 |
import javax.swing.JList; |
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JScrollPane; |
52 |
import javax.swing.JTable; |
53 |
import javax.swing.ListCellRenderer; |
54 |
import javax.swing.table.AbstractTableModel; |
55 |
import javax.swing.table.TableColumn; |
56 |
import javax.swing.table.TableModel; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.cit.gvsig.project.documents.view.snapping.ISnapper; |
60 |
|
61 |
/**
|
62 |
* @author fjp
|
63 |
*
|
64 |
* Necesitamos un sitio donde est?n registrados todos los snappers que
|
65 |
* se pueden usar. ExtensionPoints es el sitio adecuado.
|
66 |
* Este di?logo recuperar? esa lista para que el usuario marque los
|
67 |
* snappers con los que desea trabajar.
|
68 |
*/
|
69 |
public class SnapConfig extends JPanel { |
70 |
|
71 |
private JCheckBox jChkBoxRefentActive = null; |
72 |
private JTable jListSnappers = null; |
73 |
private JPanel jPanel = null; |
74 |
private JScrollPane jScrollPane = null; |
75 |
|
76 |
private ArrayList snappers; |
77 |
|
78 |
/**
|
79 |
* @author fjp
|
80 |
* primera columna editable con un check box para habilitar/deshabilitar el snapper
|
81 |
* segunda columna con el s?mbolo del snapper
|
82 |
* tercera con el tooltip
|
83 |
* cuarta con un bot?n para configurar el snapper si es necesario.
|
84 |
*/
|
85 |
class MyTableModel extends AbstractTableModel { |
86 |
|
87 |
public ArrayList mySnappers; |
88 |
|
89 |
public MyTableModel(ArrayList snappers) |
90 |
{ |
91 |
this.mySnappers = snappers;
|
92 |
} |
93 |
|
94 |
public int getColumnCount() { |
95 |
return 5; |
96 |
} |
97 |
|
98 |
public int getRowCount() { |
99 |
return mySnappers.size();
|
100 |
} |
101 |
|
102 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
103 |
if (columnIndex == 0 || columnIndex == 4) |
104 |
return true; |
105 |
return false; |
106 |
} |
107 |
|
108 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
109 |
ISnapper snap = (ISnapper) mySnappers.get(rowIndex); |
110 |
switch (columnIndex)
|
111 |
{ |
112 |
case 0: |
113 |
snap.setEnabled(((Boolean)aValue).booleanValue());
|
114 |
} |
115 |
|
116 |
} |
117 |
|
118 |
public Object getValueAt(int rowIndex, int columnIndex) { |
119 |
ISnapper snap = (ISnapper) mySnappers.get(rowIndex); |
120 |
switch (columnIndex)
|
121 |
{ |
122 |
case 0: |
123 |
return new Boolean(snap.isEnabled()); |
124 |
case 1: |
125 |
return snap.getClass().getName();
|
126 |
case 2: |
127 |
return snap.getToolTipText();
|
128 |
case 3: |
129 |
return String.valueOf(snap.getPriority()); |
130 |
case 4: |
131 |
return new JButton(); |
132 |
} |
133 |
return null; |
134 |
} |
135 |
|
136 |
public Class getColumnClass(int columnIndex) { |
137 |
switch (columnIndex)
|
138 |
{ |
139 |
case 0: |
140 |
return Boolean.class; |
141 |
case 1: |
142 |
return String.class; |
143 |
case 2: |
144 |
return String.class; |
145 |
case 3: |
146 |
return String.class; |
147 |
case 4: |
148 |
return JButton.class; |
149 |
} |
150 |
return null; |
151 |
} |
152 |
|
153 |
public String getColumnName(int columnIndex) { |
154 |
switch (columnIndex){
|
155 |
case 0: |
156 |
return PluginServices.getText(this,"aplicar"); |
157 |
case 1: |
158 |
return PluginServices.getText(this,"simbolo"); |
159 |
case 2: |
160 |
return PluginServices.getText(this,"tipo"); |
161 |
case 3: |
162 |
return PluginServices.getText(this,"prioridad"); |
163 |
case 4: |
164 |
return PluginServices.getText(this,"propiedades"); |
165 |
} |
166 |
return null; |
167 |
} |
168 |
|
169 |
} |
170 |
|
171 |
class MyCellRenderer extends JCheckBox implements ListCellRenderer { |
172 |
|
173 |
// This is the only method defined by ListCellRenderer.
|
174 |
// We just reconfigure the JLabel each time we're called.
|
175 |
|
176 |
public Component getListCellRendererComponent( |
177 |
JList list,
|
178 |
Object value, // value to display |
179 |
int index, // cell index |
180 |
boolean isSelected, // is the cell selected |
181 |
boolean cellHasFocus) // the list and the cell have the focus |
182 |
{ |
183 |
ISnapper snapper = (ISnapper) value; |
184 |
String s = snapper.getToolTipText();
|
185 |
setText(s); |
186 |
|
187 |
if (isSelected) {
|
188 |
setBackground(list.getSelectionBackground()); |
189 |
setForeground(list.getSelectionForeground()); |
190 |
} |
191 |
else {
|
192 |
setBackground(list.getBackground()); |
193 |
setForeground(list.getForeground()); |
194 |
} |
195 |
setEnabled(list.isEnabled()); |
196 |
setFont(list.getFont()); |
197 |
setOpaque(true);
|
198 |
return this; |
199 |
} |
200 |
|
201 |
public void doClick() { |
202 |
super.doClick();
|
203 |
System.out.println("Click"); |
204 |
} |
205 |
|
206 |
|
207 |
} |
208 |
|
209 |
|
210 |
/**
|
211 |
* This method initializes
|
212 |
*
|
213 |
*/
|
214 |
public SnapConfig() {
|
215 |
super();
|
216 |
initialize(); |
217 |
} |
218 |
|
219 |
/**
|
220 |
* This method initializes this
|
221 |
*
|
222 |
*/
|
223 |
private void initialize() { |
224 |
this.setLayout(null); |
225 |
this.setSize(new java.awt.Dimension(463,239)); |
226 |
this.setPreferredSize(new java.awt.Dimension(463,239)); |
227 |
this.add(getJChkBoxRefentActive(), null); |
228 |
this.add(getJPanel(), null); |
229 |
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* This method initializes jChkBoxRefentActive
|
234 |
*
|
235 |
* @return javax.swing.JCheckBox
|
236 |
*/
|
237 |
private JCheckBox getJChkBoxRefentActive() { |
238 |
if (jChkBoxRefentActive == null) { |
239 |
jChkBoxRefentActive = new JCheckBox(); |
240 |
jChkBoxRefentActive.setText("Referencia a Objetos Activada:");
|
241 |
jChkBoxRefentActive.setBounds(new java.awt.Rectangle(26,10,418,23)); |
242 |
} |
243 |
return jChkBoxRefentActive;
|
244 |
} |
245 |
|
246 |
/**
|
247 |
* This method initializes jListSnappers
|
248 |
*
|
249 |
* @return javax.swing.JList
|
250 |
*/
|
251 |
private JTable getJListSnappers() { |
252 |
if (jListSnappers == null) { |
253 |
jListSnappers = new JTable(); |
254 |
// jListSnappers.setCellRenderer(new MyCellRenderer());
|
255 |
} |
256 |
return jListSnappers;
|
257 |
} |
258 |
|
259 |
/**
|
260 |
* This method initializes jPanel
|
261 |
*
|
262 |
* @return javax.swing.JPanel
|
263 |
*/
|
264 |
private JPanel getJPanel() { |
265 |
if (jPanel == null) { |
266 |
jPanel = new JPanel(); |
267 |
jPanel.setLayout(null);
|
268 |
jPanel.setBounds(new java.awt.Rectangle(19,40,423,181)); |
269 |
jPanel.add(getJScrollPane(), null);
|
270 |
} |
271 |
return jPanel;
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* This method initializes jScrollPane
|
276 |
*
|
277 |
* @return javax.swing.JScrollPane
|
278 |
*/
|
279 |
private JScrollPane getJScrollPane() { |
280 |
if (jScrollPane == null) { |
281 |
jScrollPane = new JScrollPane(); |
282 |
jScrollPane.setBounds(new java.awt.Rectangle(9,9,402,163)); |
283 |
jScrollPane.setViewportView(getJListSnappers()); |
284 |
} |
285 |
return jScrollPane;
|
286 |
} |
287 |
|
288 |
public ArrayList getSnappers() { |
289 |
return snappers;
|
290 |
} |
291 |
|
292 |
public void setSnappers(ArrayList snappers) { |
293 |
this.snappers = snappers;
|
294 |
MyTableModel listModel = new MyTableModel(snappers);
|
295 |
getJListSnappers().setModel(listModel); |
296 |
TableColumn tc=getJListSnappers().getColumnModel().getColumn(0); |
297 |
setUpSymbolColumn(getJListSnappers().getColumnModel().getColumn(1));
|
298 |
setUpPropertyColumn(getJListSnappers().getColumnModel().getColumn(4));
|
299 |
getJListSnappers().setCellSelectionEnabled(false);
|
300 |
tc.setMaxWidth(40);
|
301 |
tc.setMinWidth(20);
|
302 |
} |
303 |
public TableModel getTableModel() { |
304 |
return getJListSnappers().getModel();
|
305 |
} |
306 |
public boolean applySnappers() { |
307 |
return getJChkBoxRefentActive().isSelected();
|
308 |
} |
309 |
|
310 |
public void selectSnappers(TreeMap selected) { |
311 |
for (int i=0;i<snappers.size();i++) { |
312 |
Boolean b=(Boolean)selected.get(snappers.get(i)); |
313 |
if (b!=null) |
314 |
getTableModel().setValueAt(b,i,0);
|
315 |
else
|
316 |
getTableModel().setValueAt(new Boolean(false),i,0); |
317 |
} |
318 |
|
319 |
} |
320 |
|
321 |
public void setApplySnappers(boolean applySnappers) { |
322 |
getJChkBoxRefentActive().setSelected(applySnappers); |
323 |
} |
324 |
public void setUpSymbolColumn(TableColumn column) { |
325 |
DrawSnapCellRenderer symbolCellRenderer = new DrawSnapCellRenderer(snappers);
|
326 |
column.setCellRenderer(symbolCellRenderer); |
327 |
} |
328 |
public void setUpPropertyColumn(TableColumn column) { |
329 |
PropertySnapCellEditor propertyeditor = new PropertySnapCellEditor(snappers);
|
330 |
column.setCellEditor(propertyeditor); |
331 |
|
332 |
PropertySnapCellRenderer renderer = new PropertySnapCellRenderer(snappers);
|
333 |
column.setCellRenderer(renderer); |
334 |
} |
335 |
} // @jve:decl-index=0:visual-constraint="10,10"
|
336 |
|
337 |
|