Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2058 / libraries / libUIComponent / src / org / gvsig / gui / beans / coordinatespanel / CoordinatesPanel.java @ 39252

History | View | Annotate | Download (10 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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
package org.gvsig.gui.beans.coordinatespanel;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.Font;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.Insets;
26
import java.net.URL;
27
import java.util.ArrayList;
28
import java.util.EventObject;
29
import java.util.Iterator;
30

    
31
import javax.swing.BorderFactory;
32
import javax.swing.ImageIcon;
33
import javax.swing.JLabel;
34
import javax.swing.JPanel;
35
import javax.swing.border.TitledBorder;
36

    
37
import org.gvsig.gui.beans.datainput.DataInputContainer;
38
import org.gvsig.gui.beans.datainput.DataInputContainerListener;
39
/**
40
 * 
41
 * @version 06/09/2007
42
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
43
 */
44
@SuppressWarnings("unchecked")
45
public class CoordinatesPanel extends JPanel implements DataInputContainerListener {
46
        private static final long  serialVersionUID       = 3336324382874763427L;
47
        private String             pathToImages           = "images/";
48
        private ArrayList          actionChangedListeners = new ArrayList();
49

    
50
        private JPanel             pCoord                 = null;
51
        private JLabel             lTitulo1               = null;
52
        private JLabel             lTitulo2               = null;
53
        private DataInputContainer dataInputContainer11   = null;
54
        private DataInputContainer dataInputContainer12   = null;
55
        private DataInputContainer dataInputContainer21   = null;
56
        private DataInputContainer dataInputContainer22   = null;
57

    
58
        /**
59
         * This is the default constructor
60
         */
61
        public CoordinatesPanel() {
62
                initialize();
63
        }
64

    
65
        /**
66
         * This method initializes this
67
         *
68
         * @return void
69
         */
70
        private void initialize() {
71
                setLayout(new BorderLayout());
72
                add(getPCoord(), BorderLayout.CENTER);
73
        }
74

    
75
        /**
76
         * This method initializes jPanel
77
         *
78
         * @return javax.swing.JPanel
79
         */
80
        private JPanel getPCoord() {
81
                if (pCoord == null) {
82
                        GridBagConstraints gridBagConstraints;
83
                        pCoord = new JPanel();
84
                        pCoord.setLayout(new GridBagLayout());
85

    
86
                        int y = 0;
87
                        gridBagConstraints = new GridBagConstraints();
88
                        gridBagConstraints.gridx = 0;
89
                        gridBagConstraints.gridy = y;
90
                        gridBagConstraints.insets = new Insets(5, 5, 2, 2);
91
                        pCoord.add(getLTitulo1(), gridBagConstraints);
92

    
93
                        gridBagConstraints = new GridBagConstraints();
94
                        gridBagConstraints.gridx = 1;
95
                        gridBagConstraints.gridy = y;
96
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
97
                        gridBagConstraints.weightx = 1.0;
98
                        gridBagConstraints.insets = new Insets(5, 2, 2, 2);
99
                        pCoord.add(getDataInputContainer11(), gridBagConstraints);
100

    
101
                        gridBagConstraints = new GridBagConstraints();
102
                        gridBagConstraints.gridx = 2;
103
                        gridBagConstraints.gridy = y;
104
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
105
                        gridBagConstraints.weightx = 1.0;
106
                        gridBagConstraints.insets = new Insets(5, 2, 2, 5);
107
                        pCoord.add(getDataInputContainer12(), gridBagConstraints);
108

    
109
                        y++;
110
                        gridBagConstraints = new GridBagConstraints();
111
                        gridBagConstraints.gridx = 0;
112
                        gridBagConstraints.gridy = y;
113
                        gridBagConstraints.insets = new Insets(2, 5, 5, 2);
114
                        pCoord.add(getLTitulo2(), gridBagConstraints);
115

    
116
                        gridBagConstraints = new GridBagConstraints();
117
                        gridBagConstraints.gridx = 1;
118
                        gridBagConstraints.gridy = y;
119
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
120
                        gridBagConstraints.weightx = 1.0;
121
                        gridBagConstraints.insets = new Insets(2, 2, 5, 2);
122
                        pCoord.add(getDataInputContainer21(), gridBagConstraints);
123

    
124

    
125
                        gridBagConstraints = new GridBagConstraints();
126
                        gridBagConstraints.gridx = 2;
127
                        gridBagConstraints.gridy = y;
128
                        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
129
                        gridBagConstraints.weightx = 1.0;
130
                        gridBagConstraints.insets = new Insets(2, 2, 5, 5);
131
                        pCoord.add(getDataInputContainer22(), gridBagConstraints);                
132
                }
133
                return pCoord;
134
        }
135

    
136
        private JLabel getLTitulo1(){
137
                if (lTitulo1 == null){
138
                        URL resource = getClass().getResource(pathToImages + "upleft.png");
139
                        if(resource != null) {
140
                                ImageIcon icon = new ImageIcon(resource);
141
                                lTitulo1 = new JLabel(icon);
142
                        } else
143
                                lTitulo1 = new JLabel();
144
                }
145
                return lTitulo1;
146
        }
147

    
148
        private JLabel getLTitulo2() {
149
                if (lTitulo2 == null){
150
                        if (lTitulo2 == null){
151
                                URL resource = getClass().getResource(pathToImages + "downright.png");
152
                                if(resource != null) {
153
                                        ImageIcon icon = new ImageIcon(resource);
154
                                        lTitulo2 = new JLabel(icon);
155
                                } else
156
                                        lTitulo2 = new JLabel();
157
                        }
158
                }
159
                return lTitulo2;
160
        }
161

    
162
        /**
163
         * This method initializes jPanel
164
         *
165
         * @return javax.swing.JPanel
166
         */
167
        public DataInputContainer getDataInputContainer11() {
168
                if (dataInputContainer11 == null) {
169
                        dataInputContainer11 = new DataInputContainer();
170
                        dataInputContainer11.setLabelText("X");
171
                        dataInputContainer11.addValueChangedListener(this);
172
                }
173
                return dataInputContainer11;
174
        }
175

    
176
        /**
177
         * This method initializes jPanel1
178
         *
179
         * @return javax.swing.JPanel
180
         */
181
        public DataInputContainer getDataInputContainer12() {
182
                if (dataInputContainer12 == null) {
183
                        dataInputContainer12 = new DataInputContainer();
184
                        dataInputContainer12.setLabelText("Y");
185
                        dataInputContainer12.addValueChangedListener(this);
186
                }
187
                return dataInputContainer12;
188
        }
189

    
190
        /**
191
         * This method initializes jPanel2
192
         *
193
         * @return javax.swing.JPanel
194
         */
195
        public DataInputContainer getDataInputContainer21() {
196
                if (dataInputContainer21 == null) {
197
                        dataInputContainer21 = new DataInputContainer();
198
                        dataInputContainer21.setLabelText("X");
199
                        dataInputContainer21.addValueChangedListener(this);
200
                }
201
                return dataInputContainer21;
202
        }
203

    
204
        /**
205
         * This method initializes jPanel3
206
         *
207
         * @return javax.swing.JPanel
208
         */
209
        public DataInputContainer getDataInputContainer22() {
210
                if (dataInputContainer22 == null) {
211
                        dataInputContainer22 = new DataInputContainer();
212
                        dataInputContainer22.setLabelText("Y");
213
                        dataInputContainer22.addValueChangedListener(this);
214
                }
215
                return dataInputContainer22;
216
        }
217

    
218
        /**
219
         * M?todo para poner un titulo al panel.
220
         * 
221
         * @param titlePanel
222
         */
223
        public void setTitlePanel(String titlePanel) {
224
                getPCoord().setBorder(BorderFactory.createTitledBorder(null, titlePanel, TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.PLAIN, 12), null));
225
        }
226

    
227
        /**
228
         * Devuelve los valores del panel por orden de izquierda a derecha
229
         * y de arriba a bajo.
230
         * @return
231
         */
232
        public String[] getValues(){
233
                String[] values = {
234
                        getDataInputContainer11().getValue(),
235
                        getDataInputContainer12().getValue(),
236
                        getDataInputContainer21().getValue(),
237
                        getDataInputContainer22().getValue()
238
                };
239
                return values;
240
        }
241

    
242
        /**
243
         * Asigna los valores del panel por orden de izquierda a derecha
244
         * y de arriba a bajo.
245
         * @return
246
         */
247
        public void setValues(String[] values){
248
                getDataInputContainer11().setValue(values[0]);
249
                getDataInputContainer12().setValue(values[1]);
250
                getDataInputContainer21().setValue(values[2]);
251
                getDataInputContainer22().setValue(values[3]);
252
        }
253
        
254
        /**
255
         * A?adir un listener a la lista de eventos
256
         * @param listener
257
         */
258
        public void addValueChangedListener(CoordinatesListener listener) {
259
                if (!actionChangedListeners.contains(listener))
260
                        actionChangedListeners.add(listener);
261
        }
262

    
263
        /**
264
         * Borrar un listener de la lista de eventos
265
         * @param listener
266
         */
267
        public void removeValueChangedListener(CoordinatesListener listener) {
268
                actionChangedListeners.remove(listener);
269
        }
270
        
271
        /**
272
         * Invocar a los eventos asociados al componente
273
         */
274
        private void callValueChangedListeners(String component) {
275
                Iterator acIterator = actionChangedListeners.iterator();
276
                while (acIterator.hasNext()) {
277
                        CoordinatesListener listener = (CoordinatesListener) acIterator.next();
278
                        listener.actionValueChanged(new CoordinatesEvent(this, component));
279
                }
280
        }
281

    
282
        public void actionValueChanged(EventObject e) {
283
                if (e.getSource() == getDataInputContainer11().getDataInputField()) {
284
                        callValueChangedListeners("11");
285
                        return;
286
                }
287
                if (e.getSource() == getDataInputContainer12().getDataInputField()) {
288
                        callValueChangedListeners("12");
289
                        return;
290
                }
291
                if (e.getSource() == getDataInputContainer21().getDataInputField()) {
292
                        callValueChangedListeners("21");
293
                        return;
294
                }
295
                if (e.getSource() == getDataInputContainer22().getDataInputField()) {
296
                        callValueChangedListeners("22");
297
                        return;
298
                }
299
  }
300
        
301
        public String getValue11() {
302
                return getDataInputContainer11().getValue();
303
        }
304
        
305
        public String getValue12() {
306
                return getDataInputContainer12().getValue();
307
        }
308
        
309
        public String getValue21() {
310
                return getDataInputContainer21().getValue();
311
        }
312
        
313
        public String getValue22() {
314
                return getDataInputContainer22().getValue();
315
        }
316
        
317
        public void setValue11(String value) {
318
                getDataInputContainer11().setValue(value);
319
        }
320
        
321
        public void setValue12(String value) {
322
                getDataInputContainer12().setValue(value);
323
        }
324
        
325
        public void setValue21(String value) {
326
                getDataInputContainer21().setValue(value);
327
        }
328
        
329
        public void setValue22(String value) {
330
                getDataInputContainer22().setValue(value);
331
        }
332

    
333
        /*
334
         * (non-Javadoc)
335
         * @see javax.swing.JComponent#setEnabled(boolean)
336
         */
337
        public void setEnabled(boolean enabled) {
338
          super.setEnabled(enabled);
339
          getPCoord().setEnabled(enabled);
340
          getLTitulo1().setEnabled(enabled);
341
          getLTitulo2().setEnabled(enabled);
342
          getDataInputContainer11().setControlEnabled(enabled);
343
          getDataInputContainer12().setControlEnabled(enabled);
344
          getDataInputContainer21().setControlEnabled(enabled);
345
          getDataInputContainer22().setControlEnabled(enabled);
346
  }
347
}