Statistics
| Revision:

root / trunk / extensions / extCAD / src / com / iver / cit / gvsig / project / documents / view / snapping / gui / SnapConfig.java @ 30232

History | View | Annotate | Download (8.73 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 == 3)
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://CheckBox
113
                                snap.setEnabled(((Boolean)aValue).booleanValue());
114
                                break;
115
                        case 3://Prioridad
116
                                snap.setPriority(((Integer)aValue).intValue());
117
                                break;
118
                        }
119
                }
120

    
121
                public Object getValueAt(int rowIndex, int columnIndex) {
122
                        ISnapper snap = (ISnapper) mySnappers.get(rowIndex);
123
                        switch (columnIndex)
124
                        {
125
                        case 0:
126
                                return new Boolean(snap.isEnabled());
127
                        case 1:
128
                                return snap.getClass().getName();
129
                        case 2:
130
                                return snap.getToolTipText();
131
                        case 3:
132
                                return new Integer(snap.getPriority());
133
                        case 4:
134
                                return new JButton();
135
                        }
136
                        return null;
137
                }
138

    
139
                public Class getColumnClass(int columnIndex) {
140
                        switch (columnIndex)
141
                        {
142
                        case 0:
143
                                return Boolean.class;
144
                        case 1:
145
                                return String.class;
146
                        case 2:
147
                                return String.class;
148
                        case 3:
149
                                return Integer.class;
150
                        case 4:
151
                                return JButton.class;
152
                        }
153
                        return null;
154
                }
155

    
156
                public String getColumnName(int columnIndex) {
157
                        switch (columnIndex){
158
                        case 0:
159
                                return PluginServices.getText(this,"aplicar");
160
                        case 1:
161
                                return PluginServices.getText(this,"simbolo");
162
                        case 2:
163
                                return PluginServices.getText(this,"tipo");
164
                        case 3:
165
                                return PluginServices.getText(this,"prioridad");
166
                        case 4:
167
                                return PluginServices.getText(this,"propiedades");
168
                        }
169
                        return null;
170
                }
171

    
172
        }
173

    
174
         class MyCellRenderer extends JCheckBox implements ListCellRenderer {
175

    
176
             // This is the only method defined by ListCellRenderer.
177
             // We just reconfigure the JLabel each time we're called.
178

    
179
             public Component getListCellRendererComponent(
180
               JList list,
181
               Object value,            // value to display
182
               int index,               // cell index
183
               boolean isSelected,      // is the cell selected
184
               boolean cellHasFocus)    // the list and the cell have the focus
185
             {
186
                     ISnapper snapper = (ISnapper) value;
187
                 String s = snapper.getToolTipText();
188
                 setText(s);
189

    
190
                      if (isSelected) {
191
                     setBackground(list.getSelectionBackground());
192
                       setForeground(list.getSelectionForeground());
193
                   }
194
                 else {
195
                       setBackground(list.getBackground());
196
                       setForeground(list.getForeground());
197
                   }
198
                   setEnabled(list.isEnabled());
199
                   setFont(list.getFont());
200
                 setOpaque(true);
201
                 return this;
202
             }
203

    
204
                public void doClick() {
205
                        super.doClick();
206
                        System.out.println("Click");
207
                }
208

    
209

    
210
         }
211

    
212

    
213
        /**
214
         * This method initializes
215
         *
216
         */
217
        public SnapConfig() {
218
                super();
219
                initialize();
220
        }
221

    
222
        /**
223
         * This method initializes this
224
         *
225
         */
226
        private void initialize() {
227
        this.setLayout(null);
228
        this.setSize(new java.awt.Dimension(463,239));
229
        this.setPreferredSize(new java.awt.Dimension(463,239));
230
        this.add(getJChkBoxRefentActive(), null);
231
        this.add(getJPanel(), null);
232

    
233
        }
234

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

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

    
262
        /**
263
         * This method initializes jPanel
264
         *
265
         * @return javax.swing.JPanel
266
         */
267
        private JPanel getJPanel() {
268
                if (jPanel == null) {
269
                        jPanel = new JPanel();
270
                        jPanel.setLayout(null);
271
                        jPanel.setBounds(new java.awt.Rectangle(19,40,423,181));
272
                        jPanel.add(getJScrollPane(), null);
273
                }
274
                return jPanel;
275
        }
276

    
277
        /**
278
         * This method initializes jScrollPane
279
         *
280
         * @return javax.swing.JScrollPane
281
         */
282
        private JScrollPane getJScrollPane() {
283
                if (jScrollPane == null) {
284
                        jScrollPane = new JScrollPane();
285
                        jScrollPane.setBounds(new java.awt.Rectangle(9,9,402,163));
286
                        jScrollPane.setViewportView(getJListSnappers());
287
                }
288
                return jScrollPane;
289
        }
290

    
291
        public ArrayList getSnappers() {
292
                return snappers;
293
        }
294

    
295
        public void setSnappers(ArrayList snappers) {
296
                this.snappers = snappers;
297
                MyTableModel listModel = new MyTableModel(snappers);
298
                getJListSnappers().setModel(listModel);
299
                TableColumn tc=getJListSnappers().getColumnModel().getColumn(0);
300
                setUpSymbolColumn(getJListSnappers().getColumnModel().getColumn(1));
301
                setUpPropertyColumn(getJListSnappers().getColumnModel().getColumn(4));
302
                getJListSnappers().setCellSelectionEnabled(false);
303
                tc.setMaxWidth(40);
304
        tc.setMinWidth(20);
305
        }
306
        public TableModel getTableModel() {
307
                return getJListSnappers().getModel();
308
        }
309
        public boolean applySnappers() {
310
                return getJChkBoxRefentActive().isSelected();
311
        }
312

    
313
        public void selectSnappers(TreeMap selected) {
314
                for (int i=0;i<snappers.size();i++) {
315
                        Boolean b=(Boolean)selected.get(snappers.get(i));
316
                        if (b!=null)
317
                                getTableModel().setValueAt(b,i,0);
318
                        else
319
                                getTableModel().setValueAt(new Boolean(false),i,0);
320
                }
321

    
322
        }
323
        public void setApplySnappers(boolean applySnappers) {
324
                getJChkBoxRefentActive().setSelected(applySnappers);
325
        }
326
        public void setUpSymbolColumn(TableColumn column) {
327
            DrawSnapCellRenderer symbolCellRenderer = new DrawSnapCellRenderer(snappers);
328
        column.setCellRenderer(symbolCellRenderer);
329
    }
330
         public void setUpPropertyColumn(TableColumn column) {
331
                PropertySnapCellEditor propertyeditor = new PropertySnapCellEditor(snappers);
332
                column.setCellEditor(propertyeditor);
333

    
334
                PropertySnapCellRenderer renderer = new PropertySnapCellRenderer(snappers);
335
                column.setCellRenderer(renderer);
336
            }
337
}  //  @jve:decl-index=0:visual-constraint="10,10"
338

    
339