Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / toolListeners / snapping / gui / SnapConfig.java @ 38765

History | View | Annotate | Download (9.64 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.BorderLayout;
44
import java.awt.Component;
45
import java.awt.event.MouseListener;
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.border.EmptyBorder;
55
import javax.swing.table.AbstractTableModel;
56
import javax.swing.table.TableColumn;
57
import javax.swing.table.TableModel;
58

    
59
import org.gvsig.andami.PluginServices;
60
import org.gvsig.fmap.mapcontrol.MapControl;
61
import org.gvsig.fmap.mapcontrol.MapControlLocator;
62
import org.gvsig.fmap.mapcontrol.MapControlManager;
63
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper;
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
        /**
229
         * This constructor allows an aditional parameter
230
         * which will be notified of the mouse events
231
         * in the relevant components of this panel
232
         * 
233
         * @param mc
234
         * @param mouseListener the mouse listener to be notified
235
         */
236
        public SnapConfig(MapControl mc, MouseListener mouseListener) {
237
            this(mc);
238
            getJListSnappers().addMouseListener(mouseListener);
239
            getJChkBoxRefentActive().addMouseListener(mouseListener);
240
        }
241

    
242
        /**
243
         * This method initializes this
244
         *
245
         */
246
        private void initialize() {
247
                this.setLayout(new BorderLayout());
248
                this.setBorder(new EmptyBorder(10, 10, 10, 10));
249
                this.setSize(new java.awt.Dimension(463,239));
250
                this.setPreferredSize(new java.awt.Dimension(463,239));
251
                this.add(getJChkBoxRefentActive(), BorderLayout.NORTH);
252
                this.add(getJPanel(), BorderLayout.CENTER);
253

    
254
        }
255

    
256
        /**
257
         * This method initializes jChkBoxRefentActive
258
         *
259
         * @return javax.swing.JCheckBox
260
         */
261
        private JCheckBox getJChkBoxRefentActive() {
262
                if (jChkBoxRefentActive == null) {
263
                        jChkBoxRefentActive = new JCheckBox();
264
                        jChkBoxRefentActive.setText("Referencia a Objetos Activada:");
265
                        jChkBoxRefentActive.setBounds(new java.awt.Rectangle(26,10,418,23));
266
                }
267
                return jChkBoxRefentActive;
268
        }
269

    
270
        /**
271
         * This method initializes jListSnappers
272
         *
273
         * @return javax.swing.JList
274
         */
275
        private JTable getJListSnappers() {
276
                if (jListSnappers == null) {
277
                        jListSnappers = new JTable();
278
                        // jListSnappers.setCellRenderer(new MyCellRenderer());
279
                }
280
                return jListSnappers;
281
        }
282

    
283
        /**
284
         * This method initializes jPanel
285
         *
286
         * @return javax.swing.JPanel
287
         */
288
        private JPanel getJPanel() {
289
                if (jPanel == null) {
290
                        jPanel = new JPanel();
291
                        jPanel.setLayout(new BorderLayout());
292
                        jPanel.setBorder(new EmptyBorder(5, 0, 0, 0));
293
                        jPanel.setBounds(new java.awt.Rectangle(19,40,423,181));
294
                        jPanel.add(getJScrollPane(), BorderLayout.CENTER);
295
                }
296
                return jPanel;
297
        }
298

    
299
        /**
300
         * This method initializes jScrollPane
301
         *
302
         * @return javax.swing.JScrollPane
303
         */
304
        private JScrollPane getJScrollPane() {
305
                if (jScrollPane == null) {
306
                        jScrollPane = new JScrollPane();
307
                        jScrollPane.setBounds(new java.awt.Rectangle(9,9,402,163));
308
                        jScrollPane.setViewportView(getJListSnappers());
309
                }
310
                return jScrollPane;
311
        }
312

    
313
        //        public ArrayList getSnappers() {
314
        //                return snappers;
315
        //        }
316

    
317
        public void setSnappers() {                
318
                MyTableModel listModel = new MyTableModel();
319
                getJListSnappers().setModel(listModel);
320
                TableColumn tc=getJListSnappers().getColumnModel().getColumn(0);
321
                setUpSymbolColumn(getJListSnappers().getColumnModel().getColumn(1));
322
                setUpPropertyColumn(getJListSnappers().getColumnModel().getColumn(4));
323
                getJListSnappers().setCellSelectionEnabled(false);
324
                tc.setMaxWidth(40);
325
                tc.setMinWidth(20);
326
        }
327
        public TableModel getTableModel() {
328
                return getJListSnappers().getModel();
329
        }
330
        public boolean applySnappers() {
331
                return getJChkBoxRefentActive().isSelected();
332
        }
333

    
334

    
335
        public void selectSnappers() {
336
                for (int i=0;i<mapControlManager.getSnapperCount();i++) {
337
                        getTableModel().setValueAt(mapControlManager.getSnapperAt(i).isEnabled(),i,0);                        
338
                }
339

    
340
        }
341

    
342
        public void setApplySnappers(boolean applySnappers) {
343
                getJChkBoxRefentActive().setSelected(applySnappers);
344
        }
345

    
346
        public void setUpSymbolColumn(TableColumn column) {
347
                DrawSnapCellRenderer symbolCellRenderer = new DrawSnapCellRenderer();
348
                column.setCellRenderer(symbolCellRenderer);
349
        }
350
        public void setUpPropertyColumn(TableColumn column) {
351

    
352
                PropertySnapCellEditor propertyeditor = new PropertySnapCellEditor();
353
                column.setCellEditor(propertyeditor);
354

    
355
                PropertySnapCellRenderer renderer = new PropertySnapCellRenderer();
356
                column.setCellRenderer(renderer);
357
        }
358
}  //  @jve:decl-index=0:visual-constraint="10,10"
359

    
360