Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / ui / raster / FileList.java @ 8026

History | View | Annotate | Download (6.89 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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 2
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.ui.raster;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.FlowLayout;
28

    
29
import java.util.Vector;
30

    
31
import javax.swing.JButton;
32
import javax.swing.JComboBox;
33
import javax.swing.JLabel;
34
import javax.swing.JList;
35
import javax.swing.JPanel;
36
import javax.swing.JScrollPane;
37

    
38
/**
39
 * Panel que contiene la lista de ficheros cargados desde donde se leen las bandas visualizadas.
40
 * Contiene controles para a?adir y eliminar los ficheros, as? como un control para seleccionar
41
 * el n?mero de bandas a visualizar.
42
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
43
 * @author Nacho Brodin (brodin_ign@gva.es)
44
 */
45
public class FileList extends JPanel {
46
    final private static long serialVersionUID = -3370601314380922368L;
47
    private JScrollPane jScrollPane = null;
48
    private JPanel jPanel = null;
49
    private JButton jButton2 = null;
50
    private JButton jButton3 = null;
51
    private Vector fileNames = null;
52
    private JList jList = null;
53
    private JPanel jPanel1 = null;
54
    private JComboBox jComboBox = null;
55
    private JPanel jPanel2 = null;
56
    
57
    /**
58
     * Variable accesible para la traducci?n.
59
     */
60
    public JLabel lbandasVisibles = null;
61

    
62
    /**
63
    * This is the default constructor
64
    */
65
    public FileList() {
66
        super();
67
        initialize();
68
    }
69

    
70
    /**
71
     * This method initializes jScrollPane
72
     *
73
     * @return javax.swing.JScrollPane
74
     */
75
    private JScrollPane getJScrollPane() {
76
        if (jScrollPane == null) {
77
            jScrollPane = new JScrollPane();
78
            jScrollPane.setViewportView(getJList());
79
        }
80

    
81
        return jScrollPane;
82
    }
83

    
84
    /**
85
     * This method initializes jPanel
86
     *
87
     * @return javax.swing.JPanel
88
     */
89
    private JPanel getJPanel() {
90
        if (jPanel == null) {
91
            FlowLayout flowLayout2 = new FlowLayout();
92
            jPanel = new JPanel();
93
            jPanel.setLayout(flowLayout2);
94
            flowLayout2.setAlignment(java.awt.FlowLayout.RIGHT);
95
            jPanel.add(getJPanel1(), null);
96
        }
97

    
98
        return jPanel;
99
    }
100

    
101
    /**
102
     * This method initializes jButton2
103
     *
104
     * @return javax.swing.JButton
105
     */
106
    public JButton getJButtonAdd() {
107
        if (jButton2 == null) {
108
            jButton2 = new JButton("A?adir");
109
            jButton2.setPreferredSize(new java.awt.Dimension(80, 25));
110
        }
111

    
112
        return jButton2;
113
    }
114

    
115
    /**
116
     * This method initializes jButton3
117
     *
118
     * @return javax.swing.JButton
119
     */
120
    public JButton getJButtonRemove() {
121
        if (jButton3 == null) {
122
            jButton3 = new JButton("Eliminar");
123
            jButton3.setPreferredSize(new java.awt.Dimension(80, 25));
124
        }
125

    
126
        return jButton3;
127
    }
128

    
129
    /**
130
     * This method initializes jList
131
     *
132
     * @return javax.swing.JList
133
     */
134
    public JList getJList() {
135
        if (jList == null) {
136
            fileNames = new Vector();
137
            jList = new JList(fileNames);
138
        }
139

    
140
        return jList;
141
    }
142

    
143
    /**
144
     * This method initializes this
145
     *
146
     * @return void
147
     */
148
    private void initialize() {
149
        this.setLayout(new BorderLayout());
150
        this.setSize(300, 248);
151
        this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
152
        this.add(getJPanel(), java.awt.BorderLayout.EAST);
153
    }
154

    
155
    /**
156
     * This method initializes jPanel1
157
     *
158
     * @return javax.swing.JPanel
159
     */
160
    private JPanel getJPanel1() {
161
        if (jPanel1 == null) {
162
            jPanel1 = new JPanel();
163
            jPanel1.setPreferredSize(new java.awt.Dimension(86, 180));
164
            jPanel1.add(getJButtonAdd(), null);
165
            jPanel1.add(getJButtonRemove(), null);
166
            jPanel1.add(getJPanel2(), null);
167
        }
168

    
169
        return jPanel1;
170
    }
171

    
172
    /**
173
     * A?ade el nombre de un fichero a la lista
174
     * @param fName
175
     */
176
    public void addFName(String fName) {
177
        fileNames.add(fName);
178
        jList = new JList(fileNames);
179
        jScrollPane.setViewportView(jList);
180
        jList.show();
181
    }
182

    
183
    /**
184
     * Elimina un fichero de la lista
185
     * @param fName
186
     */
187
    public void removeFName(String fName) {
188
        for (int i = 0; i < fileNames.size(); i++) {
189
            if (((String) fileNames.get(i)).endsWith(fName)) {
190
                fileNames.remove(i);
191
            }
192
        }
193

    
194
        jList = new JList(fileNames);
195
        jScrollPane.setViewportView(jList);
196
        jList.show();
197
    }
198

    
199
    /**
200
     * Obtiene el n?mero de ficheros en la lista
201
     * @return
202
     */
203
    public int getNFiles() {
204
        return fileNames.size();
205
    }
206

    
207
    /**
208
     * Asigna al combo del n?mero de bandas la lista de ellas
209
     */
210
    public void setList(String[] list) {
211
        if (jComboBox != null) {
212
            jComboBox.removeAllItems();
213

    
214
            for (int i = 0; i < list.length; i++)
215
                jComboBox.addItem(list[i]);
216

    
217
            jComboBox.setSelectedIndex(list.length - 1);
218
        }
219
    }
220

    
221
    /**
222
     * This method initializes jComboBox
223
     *
224
     * @return javax.swing.JComboBox
225
     */
226
    public JComboBox getJComboBox() {
227
        if (jComboBox == null) {
228
            String[] list = { "1", "2", "3" };
229
            jComboBox = new JComboBox(list);
230
            jComboBox.setSelectedIndex(2);
231
            jComboBox.setPreferredSize(new java.awt.Dimension(36, 25));
232
        }
233

    
234
        return jComboBox;
235
    }
236

    
237
    /**
238
     * This method initializes jPanel2
239
     *
240
     * @return javax.swing.JPanel
241
     */
242
    private JPanel getJPanel2() {
243
        if (jPanel2 == null) {
244
            lbandasVisibles = new JLabel();
245
            jPanel2 = new JPanel();
246
            lbandasVisibles.setText("Bandas");
247
            jPanel2.add(lbandasVisibles, null);
248
            jPanel2.add(getJComboBox(), null);
249
        }
250

    
251
        return jPanel2;
252
    }
253
    
254
    public void setResize (int nWidth, int nHeight){
255
            this.jScrollPane.setSize(this.jScrollPane.getSize().width + 1, this.jScrollPane.getSize().height + 1);
256
            this.jList.setSize(this.jList.getSize().width + 1, this.jList.getSize().height + 1);
257
            this.setSize(428 + nWidth, 110 + nHeight/2);
258
    }
259
} //  @jve:decl-index=0:visual-constraint="10,10"