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 @ 41852

History | View | Annotate | Download (9.55 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
import org.gvsig.tools.ToolsLocator;
48
import org.gvsig.tools.i18n.I18nManager;
49

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

    
60
        private JCheckBox jChkBoxRefentActive = null;
61
        private JTable jListSnappers = null;
62
        private JPanel jPanel = null;
63
        private JScrollPane jScrollPane = null;
64

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

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

    
78
                public MyTableModel()
79
                {
80
                        
81
                }
82

    
83
                public int getColumnCount() {
84
                        return 5;
85
                }
86

    
87
                public int getRowCount() {
88
                        return mapControlManager.getSnapperCount();
89
                }
90

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

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

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

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

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

    
161
        }
162

    
163
        class MyCellRenderer extends JCheckBox implements ListCellRenderer {
164

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

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

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

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

    
198

    
199
        }
200

    
201

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

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

    
239
        }
240

    
241
        /**
242
         * This method initializes jChkBoxRefentActive
243
         *
244
         * @return javax.swing.JCheckBox
245
         */
246
        private JCheckBox getJChkBoxRefentActive() {
247
                if (jChkBoxRefentActive == null) {
248
                        I18nManager i18nManager = ToolsLocator.getI18nManager();
249
                        jChkBoxRefentActive = new JCheckBox();
250
                        jChkBoxRefentActive.setText(i18nManager.getTranslation("activate_reference_to_objects"));
251
                        jChkBoxRefentActive.setBounds(new java.awt.Rectangle(26,10,418,23));
252
                }
253
                return jChkBoxRefentActive;
254
        }
255

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

    
269
        /**
270
         * This method initializes jPanel
271
         *
272
         * @return javax.swing.JPanel
273
         */
274
        private JPanel getJPanel() {
275
                if (jPanel == null) {
276
                        jPanel = new JPanel();
277
                        jPanel.setLayout(new BorderLayout());
278
                        jPanel.setBorder(new EmptyBorder(5, 0, 0, 0));
279
                        jPanel.setBounds(new java.awt.Rectangle(19,40,423,181));
280
                        jPanel.add(getJScrollPane(), BorderLayout.CENTER);
281
                }
282
                return jPanel;
283
        }
284

    
285
        /**
286
         * This method initializes jScrollPane
287
         *
288
         * @return javax.swing.JScrollPane
289
         */
290
        private JScrollPane getJScrollPane() {
291
                if (jScrollPane == null) {
292
                        jScrollPane = new JScrollPane();
293
                        jScrollPane.setBounds(new java.awt.Rectangle(9,9,402,163));
294
                        jScrollPane.setViewportView(getJListSnappers());
295
                }
296
                return jScrollPane;
297
        }
298

    
299
        //        public ArrayList getSnappers() {
300
        //                return snappers;
301
        //        }
302

    
303
        public void setSnappers() {                
304
                MyTableModel listModel = new MyTableModel();
305
                getJListSnappers().setModel(listModel);
306
                TableColumn tc=getJListSnappers().getColumnModel().getColumn(0);
307
                setUpSymbolColumn(getJListSnappers().getColumnModel().getColumn(1));
308
                setUpPropertyColumn(getJListSnappers().getColumnModel().getColumn(4));
309
                getJListSnappers().setCellSelectionEnabled(false);
310
                tc.setMaxWidth(40);
311
                tc.setMinWidth(20);
312
        }
313
        public TableModel getTableModel() {
314
                return getJListSnappers().getModel();
315
        }
316
        public boolean applySnappers() {
317
                return getJChkBoxRefentActive().isSelected();
318
        }
319

    
320

    
321
        public void selectSnappers() {
322
                for (int i=0;i<mapControlManager.getSnapperCount();i++) {
323
                        getTableModel().setValueAt(mapControlManager.getSnapperAt(i).isEnabled(),i,0);                        
324
                }
325

    
326
        }
327

    
328
        public void setApplySnappers(boolean applySnappers) {
329
                getJChkBoxRefentActive().setSelected(applySnappers);
330
        }
331

    
332
        public void setUpSymbolColumn(TableColumn column) {
333
                DrawSnapCellRenderer symbolCellRenderer = new DrawSnapCellRenderer();
334
                column.setCellRenderer(symbolCellRenderer);
335
        }
336
        public void setUpPropertyColumn(TableColumn column) {
337

    
338
                PropertySnapCellEditor propertyeditor = new PropertySnapCellEditor();
339
                column.setCellEditor(propertyeditor);
340

    
341
                PropertySnapCellRenderer renderer = new PropertySnapCellRenderer();
342
                column.setCellRenderer(renderer);
343
        }
344
}  //  @jve:decl-index=0:visual-constraint="10,10"
345

    
346