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 / gui / FPanelExtentSelector.java @ 47799

History | View | Annotate | Download (11.7 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.gui;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.FlowLayout;
28
import java.util.ArrayList;
29
import java.util.List;
30

    
31
import javax.swing.JButton;
32
import javax.swing.JPanel;
33
import javax.swing.ListModel;
34

    
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.andami.ui.mdiManager.IWindow;
37
import org.gvsig.andami.ui.mdiManager.WindowInfo;
38
import org.gvsig.app.ApplicationLocator;
39
import org.gvsig.app.ApplicationManager;
40
import org.gvsig.app.project.ProjectExtent;
41
import org.gvsig.app.project.documents.view.ListSelectorListener;
42
import org.gvsig.app.project.documents.view.ViewDocument;
43
import org.gvsig.app.project.documents.view.ViewManager;
44
import org.gvsig.tools.swing.api.ToolsSwingLocator;
45

    
46
/**
47
 * DOCUMENT ME!
48
 * 
49
 * @author Fernando Gonz?lez Cort?s
50
 */
51
public class FPanelExtentSelector extends JPanel implements IWindow {
52

    
53
    private static final long serialVersionUID = -8246729582621010542L;
54
    private javax.swing.JScrollPane jScrollPane = null;
55
    private javax.swing.JList lista = null;
56
    private JButton btnAceptar = null;
57
    private ListModel modelo = null;
58
    private List<ListSelectorListener> selectionListeners = new ArrayList<>();
59
    private JButton btnEliminar = null;
60
    private javax.swing.JPanel jPanel = null;
61
    private javax.swing.JPanel jPanel1 = null;
62
    private javax.swing.JLabel jLabel = null;
63
    private javax.swing.JTextField txtGuardar = null;
64
    private JButton btnGuardar = null;
65
    private WindowInfo m_viewinfo = null;
66
    private JPanel jPanel2 = null;
67
    private JPanel jPanel3 = null;
68

    
69
    /**
70
     * This is the default constructor
71
     */
72
    public FPanelExtentSelector() {
73
        super();
74
        initialize();
75
    }
76

    
77
    /**
78
     * This method initializes this
79
     */
80
    private void initialize() {
81
        this.setLayout(new BorderLayout());
82
        this.setSize(new java.awt.Dimension(530, 320));
83
        this.add(getJPanel(), java.awt.BorderLayout.NORTH);
84
        this.add(getJPanel1(), java.awt.BorderLayout.SOUTH);
85

    
86
    }
87

    
88
    /**
89
     * This method initializes jScrollPane
90
     * 
91
     * @return javax.swing.JScrollPane
92
     */
93
    private javax.swing.JScrollPane getJScrollPane() {
94
        if (jScrollPane == null) {
95
            jScrollPane = new javax.swing.JScrollPane();
96
            jScrollPane.setViewportView(getLista());
97
            jScrollPane.setBounds(11, 26, 508, 150);
98
            jScrollPane.setPreferredSize(new java.awt.Dimension(400, 150));
99
        }
100

    
101
        return jScrollPane;
102
    }
103

    
104
    /**
105
     * This method initializes lista
106
     * 
107
     * @return javax.swing.JList
108
     */
109
    private javax.swing.JList getLista() {
110
        if (lista == null) {
111
            lista = new javax.swing.JList();
112
        }
113

    
114
        return lista;
115
    }
116

    
117
    /**
118
     * Asigna el el array que se va a representar. Se crea una
119
     * copia del modelo, de forma que modificaciones en el modelo
120
     * fuera de esta clase ya no afectan al modelo copiado
121
     * 
122
     * @param model
123
     *            DOCUMENT ME!
124
     */
125
    public void setModel(ListModel model) {
126
        // modelo de la lista
127
        modelo = model;
128
        getLista().setModel(modelo);
129
    }
130

    
131
    public void addSelectionListener(ListSelectorListener listener) {
132
        getSelectionListeners().add(listener);
133
    }
134

    
135
    public void removeSelectionListener(ListSelectorListener listener) {
136
        getSelectionListeners().remove(listener);
137
    }
138

    
139
    private void callIndexesRemoved(int[] indices) {
140
        for (int i = 0; i < selectionListeners.size(); i++) {
141
            selectionListeners.get(i).indexesRemoved(indices);
142
        }
143
    }
144

    
145
    private void callIndexesSelected(int[] indices) {
146
        for (int i = 0; i < selectionListeners.size(); i++) {
147
            selectionListeners.get(i).indexesSelected(indices);
148
        }
149
    }
150

    
151
    private void callNewElement(String name) {
152
        for (int i = 0; i < selectionListeners.size(); i++) {
153
            selectionListeners.get(i).newElement(name);
154
        }
155
    }
156

    
157
    /**
158
     * This method initializes btnAceptar
159
     * 
160
     * @return JButton
161
     */
162
    private JButton getBtnAceptar() {
163
        if (btnAceptar == null) {
164
            btnAceptar =
165
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
166
            btnAceptar.setText(PluginServices.getText(this, "Seleccionar"));
167
            btnAceptar.addActionListener((java.awt.event.ActionEvent e) -> {
168
                doAccept();
169
            });
170
        }
171

    
172
        return btnAceptar;
173
    }
174

    
175
    /**
176
     * @return
177
     */
178
    private List<ListSelectorListener> getSelectionListeners() {
179
        return selectionListeners;
180
    }
181

    
182
    /**
183
     * This method initializes btnEliminar
184
     * 
185
     * @return JButton
186
     */
187
    private JButton getBtnEliminar() {
188
        if (btnEliminar == null) {
189
            btnEliminar =
190
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
191
            btnEliminar.setText(PluginServices.getText(this, "Eliminar"));
192
            btnEliminar.addActionListener((java.awt.event.ActionEvent e) -> {
193
                doDelete();
194
            });
195
        }
196
        return btnEliminar;
197
    }
198

    
199
    /**
200
     * This method initializes jPanel
201
     * 
202
     * @return javax.swing.JPanel
203
     */
204
    private javax.swing.JPanel getJPanel() {
205
        if (jPanel == null) {
206
            jPanel = new javax.swing.JPanel();
207
            jPanel.setLayout(null);
208

    
209
            jPanel.add(getJLabel(), null);
210
            jPanel.add(getTxtGuardar(), null);
211
            jPanel.setPreferredSize(new java.awt.Dimension(530, 100));
212
            jPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
213
                PluginServices.getText(this, "Guardar_el_zoom_actual"),
214
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
215
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
216
            jPanel.add(getJPanel3(), null);
217
        }
218
        return jPanel;
219
    }
220

    
221
    /**
222
     * This method initializes jPanel1
223
     * 
224
     * @return javax.swing.JPanel
225
     */
226
    private javax.swing.JPanel getJPanel1() {
227
        if (jPanel1 == null) {
228
            jPanel1 = new javax.swing.JPanel();
229
            jPanel1.setLayout(null);
230
            jPanel1.add(getJScrollPane(), null);
231
            jPanel1.setPreferredSize(new java.awt.Dimension(530, 220));
232
            jPanel1
233
                .setBorder(javax.swing.BorderFactory.createTitledBorder(null,
234
                    PluginServices.getText(this,
235
                        "Recuperar_y_eliminar_otros_zoom"),
236
                    javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
237
                    javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
238
                    null));
239
            jPanel1.add(getJPanel2(), null);
240
        }
241
        return jPanel1;
242
    }
243

    
244
    /**
245
     * This method initializes jLabel
246
     * 
247
     * @return javax.swing.JLabel
248
     */
249
    private javax.swing.JLabel getJLabel() {
250
        if (jLabel == null) {
251
            jLabel = new javax.swing.JLabel();
252
            jLabel.setBounds(7, 35, 248, 16);
253
            jLabel.setText(PluginServices.getText(this,
254
                "Nombre_que_se_le_dara_al_zoom") + ":");
255
        }
256
        return jLabel;
257
    }
258

    
259
    /**
260
     * This method initializes txtGuardar
261
     * 
262
     * @return javax.swing.JTextField
263
     */
264
    private javax.swing.JTextField getTxtGuardar() {
265
        if (txtGuardar == null) {
266
            txtGuardar = new javax.swing.JTextField();
267
            txtGuardar.setBounds(250, 34, 269, 20);
268
            txtGuardar.setPreferredSize(new java.awt.Dimension(330, 20));
269
        }
270
        return txtGuardar;
271
    }
272

    
273
    /**
274
     * This method initializes btnGuardar
275
     * 
276
     * @return JButton
277
     */
278
    private JButton getBtnGuardar() {
279
        if (btnGuardar == null) {
280
            btnGuardar =
281
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
282
            btnGuardar.setText(PluginServices.getText(this, "Guardar"));
283
            btnGuardar.addActionListener((java.awt.event.ActionEvent e) -> {
284
                doSave();
285
            });
286
        }
287
        return btnGuardar;
288
    }
289

    
290
    @Override
291
    public WindowInfo getWindowInfo() {
292
        if (m_viewinfo == null) {
293
            m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
294
            m_viewinfo.setWidth(this.getWidth() + 8);
295
            m_viewinfo.setHeight(this.getHeight());
296
            m_viewinfo.setTitle(PluginServices.getText(this, "Encuadre"));
297
        }
298
        return m_viewinfo;
299
    }
300

    
301
    public void viewActivated() {
302
    }
303

    
304
    /**
305
     * This method initializes jPanel2
306
     * 
307
     * @return javax.swing.JPanel
308
     */
309
    private JPanel getJPanel2() {
310
        if (jPanel2 == null) {
311
            jPanel2 = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 5));
312
            jPanel2.setBounds(new java.awt.Rectangle(11, 180, 508, 33));
313
            jPanel2.add(getBtnAceptar(), null);
314
            jPanel2.add(getBtnEliminar(), null);
315
        }
316
        return jPanel2;
317
    }
318

    
319
    /**
320
     * This method initializes jPanel3
321
     * 
322
     * @return javax.swing.JPanel
323
     */
324
    private JPanel getJPanel3() {
325
        if (jPanel3 == null) {
326
            jPanel3 = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 5));
327
            jPanel3.setBounds(new java.awt.Rectangle(8, 59, 511, 33));
328
            jPanel3.add(getBtnGuardar(), null);
329
        }
330
        return jPanel3;
331
    }
332

    
333
    public Object getWindowProfile() {
334
        return WindowInfo.TOOL_PROFILE;
335
    }
336

    
337
    private void doAccept() {
338
        int n = lista.getSelectedIndex();
339
        if( n<0 ) {
340
            return;
341
        }
342
        ExtentListSelectorModel model = (ExtentListSelectorModel) lista.getModel();
343
        if( model.isView(n) ) {
344
            ProjectExtent ex = model.getElementAt(n);
345
            if( ex == null ) {
346
                return;
347
            }
348
            ApplicationManager application = ApplicationLocator.getApplicationManager();
349
            ViewDocument view = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME);
350
            if( view == null ) {
351
                return;
352
            }            
353
            view.getMapContext().getViewPort().setEnvelope(ex.getExtent());
354
            return;
355
        }
356
        int[] indices = lista.getSelectedIndices();
357
        if (indices.length != 0) {
358
            callIndexesSelected(indices);
359
        }
360
    }
361
    
362
    private void doSave() {
363
        String text = txtGuardar.getText().trim();
364
        if (text.length() > 0) {
365
            callNewElement(text);
366
        }
367
    }
368
    
369
    private void doDelete() {
370
        int n = lista.getSelectedIndex();
371
        if( n<0 ) {
372
            return;
373
        }
374
        ExtentListSelectorModel model = (ExtentListSelectorModel) lista.getModel();
375
        if( model.isView(n) ) {
376
            return;
377
        }
378
        int[] indices = lista.getSelectedIndices();
379
        if (indices.length != 0) {
380
            callIndexesRemoved(indices);
381
        }
382
    }
383
}