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