Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toolListeners / snapping / gui / SnapConfig.java @ 40558

History | View | Annotate | Download (9.37 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.app.project.documents.view.toolListeners.snapping.gui;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.awt.event.MouseListener;
29

    
30
import javax.swing.JButton;
31
import javax.swing.JCheckBox;
32
import javax.swing.JList;
33
import javax.swing.JPanel;
34
import javax.swing.JScrollPane;
35
import javax.swing.JTable;
36
import javax.swing.ListCellRenderer;
37
import javax.swing.border.EmptyBorder;
38
import javax.swing.table.AbstractTableModel;
39
import javax.swing.table.TableColumn;
40
import javax.swing.table.TableModel;
41

    
42
import org.gvsig.andami.PluginServices;
43
import org.gvsig.fmap.mapcontrol.MapControl;
44
import org.gvsig.fmap.mapcontrol.MapControlLocator;
45
import org.gvsig.fmap.mapcontrol.MapControlManager;
46
import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper;
47

    
48
/**
49
 * @author fjp
50
 *
51
 * Necesitamos un sitio donde est?n registrados todos los snappers que
52
 * se pueden usar. ExtensionPoints es el sitio adecuado.
53
 * Este di?logo recuperar? esa lista para que el usuario marque los
54
 * snappers con los que desea trabajar.
55
 */
56
public class SnapConfig extends JPanel {
57

    
58
        private JCheckBox jChkBoxRefentActive = null;
59
        private JTable jListSnappers = null;
60
        private JPanel jPanel = null;
61
        private JScrollPane jScrollPane = null;
62

    
63
        //        private ArrayList snappers;
64
        private MapControl mc;
65
        private static MapControlManager mapControlManager = MapControlLocator.getMapControlManager();
66

    
67
        /**
68
         * @author fjp
69
         * primera columna editable con un check box para habilitar/deshabilitar el snapper
70
         * segunda columna con el s?mbolo del snapper
71
         * tercera con el tooltip
72
         * cuarta con un bot?n para configurar el snapper si es necesario.
73
         */
74
        class MyTableModel extends AbstractTableModel {
75

    
76
                public MyTableModel()
77
                {
78
                        
79
                }
80

    
81
                public int getColumnCount() {
82
                        return 5;
83
                }
84

    
85
                public int getRowCount() {
86
                        return mapControlManager.getSnapperCount();
87
                }
88

    
89
                public boolean isCellEditable(int rowIndex, int columnIndex) {
90
                        if (columnIndex == 0 || columnIndex == 3)
91
                                return true;
92
                        return false;
93
                }
94

    
95
                public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
96
                        ISnapper snap = mapControlManager.getSnapperAt(rowIndex);
97
                        switch (columnIndex)
98
                        {
99
                        case 0://CheckBox
100
                                snap.setEnabled(((Boolean)aValue).booleanValue());
101
                                break;
102
                        case 3://Prioridad
103
                                snap.setPriority(((Integer)aValue).intValue());
104
                                break;
105
                        }
106
                }
107

    
108
                public Object getValueAt(int rowIndex, int columnIndex) {
109
                        ISnapper snap = mapControlManager.getSnapperAt(rowIndex);
110
                        switch (columnIndex)
111
                        {
112
                        case 0:
113
                                return new Boolean(snap.isEnabled());
114
                        case 1:
115
                                return snap.getClass().getName();
116
                        case 2:
117
                                return snap.getToolTipText();
118
                        case 3:
119
                                return new Integer(snap.getPriority());
120
                        case 4:
121
                                return new JButton();
122
                        }
123
                        return null;
124
                }
125

    
126
                public Class getColumnClass(int columnIndex) {
127
                        switch (columnIndex)
128
                        {
129
                        case 0:
130
                                return Boolean.class;
131
                        case 1:
132
                                return String.class;
133
                        case 2:
134
                                return String.class;
135
                        case 3:
136
                                return Integer.class;
137
                        case 4:
138
                                return JButton.class;
139
                        }
140
                        return null;
141
                }
142

    
143
                public String getColumnName(int columnIndex) {
144
                        switch (columnIndex){
145
                        case 0:
146
                                return PluginServices.getText(this,"aplicar");
147
                        case 1:
148
                                return PluginServices.getText(this,"simbolo");
149
                        case 2:
150
                                return PluginServices.getText(this,"tipo");
151
                        case 3:
152
                                return PluginServices.getText(this,"prioridad");
153
                        case 4:
154
                                return PluginServices.getText(this,"propiedades");
155
                        }
156
                        return null;
157
                }
158

    
159
        }
160

    
161
        class MyCellRenderer extends JCheckBox implements ListCellRenderer {
162

    
163
                // This is the only method defined by ListCellRenderer.
164
                // We just reconfigure the JLabel each time we're called.
165

    
166
                public Component getListCellRendererComponent(
167
                                JList list,
168
                                Object value,            // value to display
169
                                int index,               // cell index
170
                                boolean isSelected,      // is the cell selected
171
                                boolean cellHasFocus)    // the list and the cell have the focus
172
                {
173
                        ISnapper snapper = (ISnapper) value;
174
                        String s = snapper.getToolTipText();
175
                        setText(s);
176

    
177
                        if (isSelected) {
178
                                setBackground(list.getSelectionBackground());
179
                                setForeground(list.getSelectionForeground());
180
                        }
181
                        else {
182
                                setBackground(list.getBackground());
183
                                setForeground(list.getForeground());
184
                        }
185
                        setEnabled(list.isEnabled());
186
                        setFont(list.getFont());
187
                        setOpaque(true);
188
                        return this;
189
                }
190

    
191
                public void doClick() {
192
                        super.doClick();
193
                        System.out.println("Click");
194
                }
195

    
196

    
197
        }
198

    
199

    
200
        /**
201
         * This method initializes
202
         *
203
         */
204
        public SnapConfig(MapControl mc) {
205
                super();
206
                this.mc=mc;
207
                initialize();
208
        }
209
        
210
        
211
        /**
212
         * This constructor allows an aditional parameter
213
         * which will be notified of the mouse events
214
         * in the relevant components of this panel
215
         * 
216
         * @param mc
217
         * @param mouseListener the mouse listener to be notified
218
         */
219
        public SnapConfig(MapControl mc, MouseListener mouseListener) {
220
            this(mc);
221
            getJListSnappers().addMouseListener(mouseListener);
222
            getJChkBoxRefentActive().addMouseListener(mouseListener);
223
        }
224

    
225
        /**
226
         * This method initializes this
227
         *
228
         */
229
        private void initialize() {
230
                this.setLayout(new BorderLayout());
231
                this.setBorder(new EmptyBorder(10, 10, 10, 10));
232
                this.setSize(new java.awt.Dimension(463,239));
233
                this.setPreferredSize(new java.awt.Dimension(463,239));
234
                this.add(getJChkBoxRefentActive(), BorderLayout.NORTH);
235
                this.add(getJPanel(), BorderLayout.CENTER);
236

    
237
        }
238

    
239
        /**
240
         * This method initializes jChkBoxRefentActive
241
         *
242
         * @return javax.swing.JCheckBox
243
         */
244
        private JCheckBox getJChkBoxRefentActive() {
245
                if (jChkBoxRefentActive == null) {
246
                        jChkBoxRefentActive = new JCheckBox();
247
                        jChkBoxRefentActive.setText("Referencia a Objetos Activada:");
248
                        jChkBoxRefentActive.setBounds(new java.awt.Rectangle(26,10,418,23));
249
                }
250
                return jChkBoxRefentActive;
251
        }
252

    
253
        /**
254
         * This method initializes jListSnappers
255
         *
256
         * @return javax.swing.JList
257
         */
258
        private JTable getJListSnappers() {
259
                if (jListSnappers == null) {
260
                        jListSnappers = new JTable();
261
                        // jListSnappers.setCellRenderer(new MyCellRenderer());
262
                }
263
                return jListSnappers;
264
        }
265

    
266
        /**
267
         * This method initializes jPanel
268
         *
269
         * @return javax.swing.JPanel
270
         */
271
        private JPanel getJPanel() {
272
                if (jPanel == null) {
273
                        jPanel = new JPanel();
274
                        jPanel.setLayout(new BorderLayout());
275
                        jPanel.setBorder(new EmptyBorder(5, 0, 0, 0));
276
                        jPanel.setBounds(new java.awt.Rectangle(19,40,423,181));
277
                        jPanel.add(getJScrollPane(), BorderLayout.CENTER);
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