gvsig-raster / org.gvsig.raster.multifile / trunk / org.gvsig.raster.multifile / org.gvsig.raster.multifile.app / org.gvsig.raster.multifile.app.multifileclient / src / main / java / org / gvsig / raster / multifile / app / panel / BandSelectorFileList.java @ 1874
History | View | Annotate | Download (4.9 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.multifile.app.panel; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.GridBagLayout; |
27 |
import java.awt.Insets; |
28 |
|
29 |
import javax.swing.DefaultListModel; |
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JList; |
32 |
import javax.swing.JPanel; |
33 |
import javax.swing.JScrollPane; |
34 |
import javax.swing.ListSelectionModel; |
35 |
|
36 |
import org.gvsig.gui.beans.Messages; |
37 |
|
38 |
|
39 |
/**
|
40 |
* Panel que contiene la lista de ficheros cargados desde donde se leen las
|
41 |
* bandas visualizadas. Contiene controles para a?adir y eliminar los ficheros,
|
42 |
* as? como un control para seleccionar el n?mero de bandas a visualizar.
|
43 |
*
|
44 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
45 |
*/
|
46 |
public class BandSelectorFileList extends JPanel { |
47 |
private static final long serialVersionUID = 3329020254004687818L; |
48 |
private JScrollPane jScrollPane = null; |
49 |
private JButton addButton = null; |
50 |
private JButton delButton = null; |
51 |
private JList jList = null; |
52 |
private DefaultListModel listModel = null; |
53 |
private JPanel jPanel1 = null; |
54 |
|
55 |
/**
|
56 |
* This is the default constructor
|
57 |
*/
|
58 |
public BandSelectorFileList() {
|
59 |
super();
|
60 |
listModel = new DefaultListModel(); |
61 |
initialize(); |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Inicializaci?n de componentes gr?ficos
|
66 |
*
|
67 |
*/
|
68 |
private void initialize() { |
69 |
setLayout(new BorderLayout()); |
70 |
add(getJScrollPane(), BorderLayout.CENTER);
|
71 |
add(getButtonsPanel(), BorderLayout.EAST);
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* This method initializes jScrollPane
|
76 |
*
|
77 |
* @return javax.swing.JScrollPane
|
78 |
*/
|
79 |
private JScrollPane getJScrollPane() { |
80 |
if (jScrollPane == null) { |
81 |
jScrollPane = new JScrollPane(); |
82 |
jScrollPane.setViewportView(getJList()); |
83 |
} |
84 |
return jScrollPane;
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* Obtiene el bot?n de a?adir fichero
|
89 |
* @return JButton
|
90 |
*/
|
91 |
public JButton getJButtonAdd() { |
92 |
if (addButton == null) { |
93 |
addButton = new JButton(Messages.getText("anadir")); |
94 |
addButton.setPreferredSize(new java.awt.Dimension(80, 25)); |
95 |
} |
96 |
return addButton;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Obtiene el bot?n de eliminar fichero
|
101 |
* @return JButton
|
102 |
*/
|
103 |
public JButton getJButtonRemove() { |
104 |
if (delButton == null) { |
105 |
delButton = new JButton(Messages.getText("eliminar")); |
106 |
delButton.setPreferredSize(new java.awt.Dimension(80, 25)); |
107 |
} |
108 |
return delButton;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* This method initializes jList
|
113 |
*
|
114 |
* @return javax.swing.JList
|
115 |
*/
|
116 |
public JList getJList() { |
117 |
if (jList == null) { |
118 |
jList = new JList(listModel); |
119 |
jList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
120 |
jList.setLayoutOrientation(JList.VERTICAL);
|
121 |
} |
122 |
return jList;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* This method initializes jPanel1
|
127 |
*
|
128 |
* @return javax.swing.JPanel
|
129 |
*/
|
130 |
private JPanel getButtonsPanel() { |
131 |
if (jPanel1 == null) { |
132 |
jPanel1 = new JPanel(); |
133 |
GridBagConstraints gbc = new GridBagConstraints(); |
134 |
gbc.insets = new Insets(0, 0, 3, 0); |
135 |
gbc.weightx = 1.0;
|
136 |
jPanel1.setLayout(new GridBagLayout()); |
137 |
jPanel1.add(getJButtonAdd(), gbc); |
138 |
gbc.gridy = 1;
|
139 |
jPanel1.add(getJButtonRemove(), gbc); |
140 |
} |
141 |
return jPanel1;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* A?ade el nombre de un fichero a la lista
|
146 |
* @param fName
|
147 |
*/
|
148 |
public void addFName(String fName) { |
149 |
listModel.addElement(fName); |
150 |
} |
151 |
|
152 |
/**
|
153 |
* Elimina un fichero de la lista
|
154 |
* @param fName
|
155 |
*/
|
156 |
public void removeFName(String fName) { |
157 |
for (int i = 0; i < listModel.size(); i++) { |
158 |
if(((String)listModel.get(i)).endsWith(fName)) |
159 |
listModel.remove(i); |
160 |
} |
161 |
} |
162 |
|
163 |
/**
|
164 |
* Elimina todos los ficheros de la lista
|
165 |
*/
|
166 |
public void clear(){ |
167 |
listModel.clear(); |
168 |
} |
169 |
|
170 |
/**
|
171 |
* Obtiene el n?mero de ficheros en la lista
|
172 |
* @return
|
173 |
*/
|
174 |
public int getNFiles() { |
175 |
return listModel.size();
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* Obtiene el modelo de la lista
|
180 |
* @return DefaultListModel
|
181 |
*/
|
182 |
public DefaultListModel getModel() { |
183 |
return listModel;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* Activa y desactiva el control
|
188 |
* @param enabled true para activar y false para desactivar
|
189 |
*/
|
190 |
public void setEnabled(boolean enabled) { |
191 |
getJButtonAdd().setEnabled(enabled); |
192 |
getJButtonRemove().setEnabled(enabled); |
193 |
getJList().setEnabled(enabled); |
194 |
getJScrollPane().setEnabled(enabled); |
195 |
} |
196 |
} |