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