Revision 8302
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/buildNumber.properties | ||
---|---|---|
1 |
#Sun Oct 15 11:35:37 CEST 2017 |
|
2 |
buildNumber=114 |
|
0 | 3 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>${project.artifactId}</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
</file> |
|
16 |
</files> |
|
17 |
|
|
18 |
<fileSets> |
|
19 |
<fileSet> |
|
20 |
<directory>src/main/resources-plugin</directory> |
|
21 |
<outputDirectory>.</outputDirectory> |
|
22 |
</fileSet> |
|
23 |
</fileSets> |
|
24 |
|
|
25 |
|
|
26 |
<dependencySets> |
|
27 |
<dependencySet> |
|
28 |
<useProjectArtifact>false</useProjectArtifact> |
|
29 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
30 |
<outputDirectory>lib</outputDirectory> |
|
31 |
<includes> |
|
32 |
<include>org.gvsig:org.gvsig.raster.multifile.app.multifileclient:jar</include> |
|
33 |
<include>org.gvsig:org.gvsig.raster.multifile.io:jar</include> |
|
34 |
</includes> |
|
35 |
</dependencySet> |
|
36 |
</dependencySets> |
|
37 |
</assembly> |
|
0 | 38 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/MultiFileCreatorTocMenuEntry.java | ||
---|---|---|
1 |
package org.gvsig.raster.multifile.app; |
|
2 |
|
|
3 |
import javax.swing.Icon; |
|
4 |
|
|
5 |
import org.gvsig.andami.IconThemeHelper; |
|
6 |
import org.gvsig.andami.plugins.Extension; |
|
7 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
|
8 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
|
9 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
10 |
import org.gvsig.i18n.Messages; |
|
11 |
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author gvSIG team |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class MultiFileCreatorTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem { |
|
18 |
static private MultiFileCreatorTocMenuEntry singleton = null; |
|
19 |
private static Extension extension = null; |
|
20 |
|
|
21 |
|
|
22 |
/** |
|
23 |
* @param ext |
|
24 |
*/ |
|
25 |
public static void setExtension(Extension ext) { |
|
26 |
extension = ext; |
|
27 |
} |
|
28 |
|
|
29 |
private MultiFileCreatorTocMenuEntry() {} |
|
30 |
|
|
31 |
/** |
|
32 |
* @return MultiFileCreatorTocMenuEntry |
|
33 |
*/ |
|
34 |
static public MultiFileCreatorTocMenuEntry getSingleton() { |
|
35 |
if (singleton == null) |
|
36 |
singleton = new MultiFileCreatorTocMenuEntry(); |
|
37 |
return singleton; |
|
38 |
} |
|
39 |
|
|
40 |
public String getGroup() { |
|
41 |
return "Dataset"; |
|
42 |
} |
|
43 |
|
|
44 |
public int getGroupOrder() { |
|
45 |
return 55; |
|
46 |
} |
|
47 |
|
|
48 |
public int getOrder() { |
|
49 |
return 0; |
|
50 |
} |
|
51 |
|
|
52 |
public String getText() { |
|
53 |
return Messages.getText("create_multifile"); |
|
54 |
} |
|
55 |
|
|
56 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
|
57 |
return true; |
|
58 |
} |
|
59 |
|
|
60 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
|
61 |
return true; |
|
62 |
} |
|
63 |
|
|
64 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
|
65 |
extension.execute("MultifileCreator"); |
|
66 |
} |
|
67 |
|
|
68 |
public Icon getIcon() { |
|
69 |
return IconThemeHelper.getImageIcon("multifile-icon"); |
|
70 |
} |
|
71 |
|
|
72 |
} |
|
0 | 73 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorFileList.java | ||
---|---|---|
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 number of files |
|
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 |
} |
|
0 | 197 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/DriverFileFilter.java | ||
---|---|---|
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.io.File; |
|
25 |
import java.io.FileInputStream; |
|
26 |
|
|
27 |
import javax.swing.filechooser.FileFilter; |
|
28 |
|
|
29 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
|
30 |
/** |
|
31 |
* Clase para indicar los ficheros que se ver?n en el JFileChooser. |
|
32 |
* |
|
33 |
* @version 04/09/2007 |
|
34 |
* @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es) |
|
35 |
*/ |
|
36 |
public class DriverFileFilter extends FileFilter { |
|
37 |
|
|
38 |
|
|
39 |
public boolean accept(File f) { |
|
40 |
if (f.isDirectory()) |
|
41 |
return true; |
|
42 |
|
|
43 |
if (f.getParentFile().getName().equals("cellhd")) { |
|
44 |
if (f.getName().endsWith(".rmf") || f.getName().endsWith(".rmf~")) |
|
45 |
return false; |
|
46 |
return true; |
|
47 |
} |
|
48 |
|
|
49 |
// Comprobamos que no sea un rmf propio, osea, que contenga xml |
|
50 |
if (f.getName().toLowerCase().endsWith(".rmf")) { |
|
51 |
FileInputStream reader = null; |
|
52 |
try { |
|
53 |
reader = new FileInputStream(f); |
|
54 |
String xml = ""; |
|
55 |
for (int i = 0; i < 6; i++) |
|
56 |
xml += (char) reader.read(); |
|
57 |
if (xml.equals("<?xml ")) |
|
58 |
return false; |
|
59 |
} catch (Exception e) { |
|
60 |
} finally { |
|
61 |
try { |
|
62 |
reader.close(); |
|
63 |
} catch (Exception e) {} |
|
64 |
} |
|
65 |
} |
|
66 |
|
|
67 |
return DefaultFLyrRaster.isFileSupported(f); |
|
68 |
} |
|
69 |
|
|
70 |
public String getDescription() { |
|
71 |
return "gvSIG Raster Driver"; |
|
72 |
} |
|
73 |
} |
|
0 | 74 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorNewLayerListener.java | ||
---|---|---|
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.event.ActionEvent; |
|
25 |
import java.io.File; |
|
26 |
import java.net.URI; |
|
27 |
import java.util.ArrayList; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
import javax.swing.JRadioButton; |
|
31 |
|
|
32 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
33 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
|
34 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
35 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
36 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
37 |
import org.gvsig.fmap.dal.exception.InitializeException; |
|
38 |
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException; |
|
39 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel; |
|
40 |
import org.gvsig.gui.beans.swing.JFileChooser; |
|
41 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
|
42 |
import org.gvsig.i18n.Messages; |
|
43 |
import org.gvsig.raster.multifile.io.MultiFileDataParameters; |
|
44 |
import org.gvsig.raster.multifile.io.MultiFileProvider; |
|
45 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
46 |
import org.gvsig.raster.swing.basepanel.ButtonsPanelEvent; |
|
47 |
import org.gvsig.tools.locator.LocatorException; |
|
48 |
|
|
49 |
/** |
|
50 |
* Class to manage events when this functionality is call to create a new multifile layer |
|
51 |
* |
|
52 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
53 |
*/ |
|
54 |
public class BandSelectorNewLayerListener extends AbstractBandSelectorListener { |
|
55 |
protected RasterDataStore mainRasterStore = null; |
|
56 |
|
|
57 |
/** |
|
58 |
* Constructor |
|
59 |
* @param bs Panel del selector de bandas |
|
60 |
*/ |
|
61 |
public BandSelectorNewLayerListener(BandSelectorPanel bs) { |
|
62 |
super(bs); |
|
63 |
} |
|
64 |
|
|
65 |
public RasterDataStore getResult() { |
|
66 |
return mainRasterStore; |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Listener para la gesti?n de los botones de a?adir, eliminar fichero y |
|
71 |
* el combo de selecci?n de bandas. |
|
72 |
*/ |
|
73 |
public void actionPerformed(ActionEvent e) { |
|
74 |
if (e.getSource().equals(bandSetupPanel.getFileList().getJButtonAdd())) { |
|
75 |
addFileBand(); |
|
76 |
return; |
|
77 |
} |
|
78 |
|
|
79 |
if (e.getSource().equals(bandSetupPanel.getFileList().getJButtonRemove())) { |
|
80 |
delFileBand(); |
|
81 |
return; |
|
82 |
} |
|
83 |
if(e.getSource() instanceof JRadioButton) { |
|
84 |
return; |
|
85 |
} |
|
86 |
apply(); |
|
87 |
} |
|
88 |
|
|
89 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
|
90 |
|
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public void setNewBandsPositionInRendering() { |
|
95 |
|
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public void apply() { |
|
100 |
} |
|
101 |
|
|
102 |
@Override |
|
103 |
public void addFileBand() { |
|
104 |
JFileChooser fileChooser = createJFileChooser(); |
|
105 |
int result = fileChooser.showOpenDialog(bandSetupPanel); |
|
106 |
|
|
107 |
if (result == JFileChooser.APPROVE_OPTION) { |
|
108 |
File[] files = fileChooser.getSelectedFiles(); |
|
109 |
if(files == null || files.length <= 0) |
|
110 |
return; |
|
111 |
|
|
112 |
JFileChooser.setLastPath(FilesystemExplorerWizardPanel.OPEN_LAYER_FILE_CHOOSER_ID, files[0]); |
|
113 |
int initPosition = 0; |
|
114 |
|
|
115 |
if(mainRasterStore == null) { |
|
116 |
initPosition = 1; |
|
117 |
MultiFileProvider provider = createMultiFileProvider(file, folder); |
|
118 |
MultiFileDataParameters newParamsMultifile = (MultiFileDataParameters)provider.getDataParameters(); |
|
119 |
|
|
120 |
try { |
|
121 |
RasterDataStore firstDataStore = RasterLocator.getManager().getProviderServices().open(files[0].getAbsolutePath()); |
|
122 |
newParamsMultifile.addProvider(firstDataStore); |
|
123 |
mainRasterStore = RasterLocator.getManager().getProviderServices().open(provider, provider.getDataStoreParameters()); |
|
124 |
} catch (RasterDriverException e) { |
|
125 |
log.debug("Error loading the main store", e); |
|
126 |
} catch (LocatorException e) { |
|
127 |
log.debug("Error loading the main store", e); |
|
128 |
} catch (NotSupportedExtensionException e) { |
|
129 |
log.debug("Error loading the main store", e); |
|
130 |
} catch (InitializeException e) { |
|
131 |
log.debug("Error loading the main store", e); |
|
132 |
} catch (ProviderNotRegisteredException e) { |
|
133 |
log.debug("Error loading the main store", e); |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
List<File> fileList = new ArrayList<File>(); |
|
138 |
|
|
139 |
for (int i = initPosition; i < files.length; i++) { |
|
140 |
//Checks that the file does not exist |
|
141 |
URI[] uris = mainRasterStore.getURIByProvider(); |
|
142 |
boolean exists = false; |
|
143 |
for (int j = 0; j < uris.length; j++) { |
|
144 |
if (new File(uris[j]).getAbsolutePath().endsWith(files[i].getName())) { |
|
145 |
RasterSwingLibrary.messageBoxError( Messages.getText("fichero_existe") + ": " + files[i].getAbsolutePath(), bandSetupPanel); |
|
146 |
exists = true; |
|
147 |
break; |
|
148 |
} |
|
149 |
} |
|
150 |
if(!exists) |
|
151 |
fileList.add(files[i]); |
|
152 |
} |
|
153 |
|
|
154 |
if(!checkStoresCompatibility(mainRasterStore, fileList)) |
|
155 |
return; |
|
156 |
|
|
157 |
if(mainRasterStore.isMultiFile()) { |
|
158 |
for (int i = 0; i < fileList.size(); i++) { |
|
159 |
try { |
|
160 |
mainRasterStore.addFile(fileList.get(i)); //.getAbsolutePath()); |
|
161 |
} catch (InvalidSourceException e) { |
|
162 |
RasterSwingLibrary.messageBoxError(Messages.getText("addband_error"), bandSetupPanel, e); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
mainRasterStore.setProvider(mainRasterStore.getProvider()); |
|
167 |
|
|
168 |
//It shows the files and bands in the panel |
|
169 |
try { |
|
170 |
bandSetupPanel.addFiles(mainRasterStore); |
|
171 |
} catch (NotInitializeException e) { |
|
172 |
RasterSwingLibrary.messageBoxError("table_not_initialize", this, e); |
|
173 |
} |
|
174 |
} |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 |
@Override |
|
179 |
public void delFileBand() { |
|
180 |
if(mainRasterStore == null) |
|
181 |
return; |
|
182 |
|
|
183 |
Object[] objects = bandSetupPanel.getFileList().getJList().getSelectedValues(); |
|
184 |
|
|
185 |
for (int i = objects.length - 1; i >= 0; i--) { |
|
186 |
if (bandSetupPanel.getFileList().getNFiles() > 1) { |
|
187 |
String pathName = objects[i].toString(); |
|
188 |
mainRasterStore.removeFile(new File(pathName)); |
|
189 |
|
|
190 |
String file = pathName.substring(pathName.lastIndexOf(File.separator) + 1); |
|
191 |
file = file.substring(file.lastIndexOf("\\") + 1); |
|
192 |
bandSetupPanel.removeFile(file); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
setNewBandsPositionInRendering(); |
|
197 |
} |
|
198 |
|
|
199 |
|
|
200 |
} |
|
0 | 201 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorPanel.java | ||
---|---|---|
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.Dimension; |
|
25 |
import java.awt.GridBagConstraints; |
|
26 |
import java.awt.GridBagLayout; |
|
27 |
import java.awt.Insets; |
|
28 |
import java.awt.event.ComponentEvent; |
|
29 |
import java.awt.image.DataBuffer; |
|
30 |
import java.io.File; |
|
31 |
import java.net.URI; |
|
32 |
import java.util.ArrayList; |
|
33 |
import java.util.List; |
|
34 |
|
|
35 |
import javax.swing.JButton; |
|
36 |
import javax.swing.JComboBox; |
|
37 |
import javax.swing.JLabel; |
|
38 |
import javax.swing.JPanel; |
|
39 |
import javax.swing.event.TableModelEvent; |
|
40 |
import javax.swing.event.TableModelListener; |
|
41 |
import javax.swing.table.DefaultTableModel; |
|
42 |
|
|
43 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
44 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
45 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
46 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
47 |
import org.gvsig.gui.beans.panelGroup.panels.AbstractPanel; |
|
48 |
import org.gvsig.gui.beans.table.TableContainer; |
|
49 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
|
50 |
import org.gvsig.i18n.Messages; |
|
51 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
52 |
import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
|
53 |
import org.gvsig.raster.mainplugin.properties.RasterPropertiesTocMenuEntry; |
|
54 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
55 |
import org.slf4j.Logger; |
|
56 |
import org.slf4j.LoggerFactory; |
|
57 |
|
|
58 |
/** |
|
59 |
* Selecciona las bandas visibles en un raster. Contiene una tabla con una fila |
|
60 |
* por cada banda de la imagen. Por medio de checkbox se selecciona para cada |
|
61 |
* RGB que banda de la imagen ser? visualizada. |
|
62 |
* |
|
63 |
|
|
64 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
65 |
*/ |
|
66 |
public class BandSelectorPanel extends AbstractPanel implements TableModelListener { |
|
67 |
final private static long serialVersionUID = -3370601314380922368L; |
|
68 |
public static final int TYPE_PROPERTIES = 0; |
|
69 |
public static final int TYPE_DIALOG = 1; |
|
70 |
|
|
71 |
private final String[] columnNames = { "A", "R", "G", "B", "Band" }; |
|
72 |
private final int[] columnWidths = { 22, 22, 22, 22, 334 }; |
|
73 |
|
|
74 |
private FLyrRaster fLayer = null; |
|
75 |
|
|
76 |
private BandSelectorFileList fileList = null; |
|
77 |
|
|
78 |
// Ultima y penultima columnas activadas del jtable para cuando hay 2 bandas seleccionadas en el combo |
|
79 |
private int[] col = { 0, 1 }; |
|
80 |
private AbstractBandSelectorListener |
|
81 |
panelListener = null; |
|
82 |
private TableContainer table = null; |
|
83 |
private JButton saveButton = null; |
|
84 |
|
|
85 |
private JPanel buttonsPanel = null; |
|
86 |
private JComboBox jComboBox = null; |
|
87 |
|
|
88 |
private static final Logger logger = |
|
89 |
LoggerFactory.getLogger(BandSelectorPanel.class); |
|
90 |
/** |
|
91 |
* Constructor to be instantiated from the properties panels |
|
92 |
*/ |
|
93 |
public BandSelectorPanel() { |
|
94 |
super(); |
|
95 |
panelListener = new BandSelectorPropertiesListener(this); |
|
96 |
initialize(); |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* This method initializes |
|
101 |
* @param type |
|
102 |
*/ |
|
103 |
public BandSelectorPanel(int type) { |
|
104 |
super(); |
|
105 |
if(type == TYPE_PROPERTIES) |
|
106 |
panelListener = new BandSelectorPropertiesListener(this); |
|
107 |
if(type == TYPE_DIALOG) |
|
108 |
panelListener = new BandSelectorNewLayerListener(this); |
|
109 |
initialize(); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* @return AbstractBandSelectorListener |
|
114 |
*/ |
|
115 |
public AbstractBandSelectorListener getListener() { |
|
116 |
return panelListener; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* This method initializes this |
|
121 |
*/ |
|
122 |
protected void initialize() { |
|
123 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
124 |
setLayout(new GridBagLayout()); |
|
125 |
gbc.insets = new Insets(0, 0, 0, 0); |
|
126 |
gbc.fill = GridBagConstraints.BOTH; |
|
127 |
|
|
128 |
gbc.weightx = 1.0; |
|
129 |
gbc.weighty = 1.0; |
|
130 |
add(getFileList(), gbc); |
|
131 |
|
|
132 |
gbc.gridy = 1; |
|
133 |
add(getARGBTable(), gbc); |
|
134 |
|
|
135 |
gbc.weighty = 0; |
|
136 |
gbc.gridy = 2; |
|
137 |
gbc.fill = GridBagConstraints.EAST; |
|
138 |
gbc.anchor = GridBagConstraints.EAST; |
|
139 |
gbc.insets = new Insets(0, 0, 0, 8); |
|
140 |
if(panelListener instanceof BandSelectorPropertiesListener) |
|
141 |
add(getButtonsPanel(), gbc); |
|
142 |
|
|
143 |
this.setPreferredSize(new Dimension(100, 80)); |
|
144 |
super.setLabel(Messages.getText("bands_panel")); |
|
145 |
|
|
146 |
this.setPriority(80); |
|
147 |
} |
|
148 |
|
|
149 |
/** |
|
150 |
* Obtiene el panel que contiene la lista de ficheros por banda. |
|
151 |
* @return Panel FileList |
|
152 |
*/ |
|
153 |
public BandSelectorFileList getFileList() { |
|
154 |
if (fileList == null) |
|
155 |
fileList = new BandSelectorFileList(); |
|
156 |
return fileList; |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Obtiene la Tabla |
|
161 |
* @return Tabla de bandas de la imagen |
|
162 |
*/ |
|
163 |
public TableContainer getARGBTable() { |
|
164 |
if (table == null) { |
|
165 |
ArrayList<AbstractBandSelectorListener> listeners = new ArrayList<AbstractBandSelectorListener>(); |
|
166 |
listeners.add(panelListener); |
|
167 |
table = new TableContainer(columnNames, columnWidths, listeners); |
|
168 |
table.setModel("ARGBBandSelectorModel"); |
|
169 |
table.setControlVisible(false); |
|
170 |
table.getModel().addTableModelListener(this); |
|
171 |
table.initialize(); |
|
172 |
} |
|
173 |
return table; |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Obtiene el Panel con bot?n de salvado y selector de bandas. |
|
178 |
* @return JPanel |
|
179 |
*/ |
|
180 |
public JPanel getButtonsPanel() { |
|
181 |
if (buttonsPanel == null) { |
|
182 |
buttonsPanel = new JPanel(); |
|
183 |
buttonsPanel.setLayout(new GridBagLayout()); |
|
184 |
JLabel lbandasVisibles = new JLabel(); |
|
185 |
lbandasVisibles.setText(Messages.getText("bands")); |
|
186 |
|
|
187 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
188 |
gbc.insets = new Insets(0, 8, 0, 0); |
|
189 |
gbc.fill = GridBagConstraints.BOTH; |
|
190 |
gbc.weightx = 1.0; |
|
191 |
buttonsPanel.add(lbandasVisibles, gbc); |
|
192 |
|
|
193 |
gbc = new GridBagConstraints(); |
|
194 |
gbc.insets = new Insets(0, 8, 0, 0); |
|
195 |
gbc.fill = GridBagConstraints.BOTH; |
|
196 |
gbc.gridx = 1; |
|
197 |
getNumBandSelectorCombo().setMinimumSize(new Dimension(50, getNumBandSelectorCombo().getMinimumSize().height)); |
|
198 |
getNumBandSelectorCombo().setPreferredSize(new Dimension(50, getNumBandSelectorCombo().getMinimumSize().height)); |
|
199 |
buttonsPanel.add(getNumBandSelectorCombo(), gbc); |
|
200 |
|
|
201 |
gbc = new GridBagConstraints(); |
|
202 |
gbc.insets = new Insets(0, 8, 0, 0); |
|
203 |
gbc.fill = GridBagConstraints.BOTH; |
|
204 |
gbc.weightx = 1.0; |
|
205 |
gbc.gridx = 2; |
|
206 |
buttonsPanel.add(getSaveButton(), gbc); |
|
207 |
} |
|
208 |
return buttonsPanel; |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* Obtiene el combo del selector del n?mero de bandas |
|
213 |
* @return JComboBox |
|
214 |
*/ |
|
215 |
public JComboBox getNumBandSelectorCombo() { |
|
216 |
if (jComboBox == null) { |
|
217 |
String[] list = { "1", "2", "3" }; |
|
218 |
jComboBox = new JComboBox(list); |
|
219 |
jComboBox.setSelectedIndex(2); |
|
220 |
jComboBox.setPreferredSize(new java.awt.Dimension(36, 25)); |
|
221 |
} |
|
222 |
|
|
223 |
return jComboBox; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* Bot?n de salvar la interpretaci?n de color seleccionada como predeterminada en |
|
228 |
* la capa |
|
229 |
* @return JButton |
|
230 |
*/ |
|
231 |
public JButton getSaveButton() { |
|
232 |
if(saveButton == null) { |
|
233 |
saveButton = new JButton(Messages.getText("save")); |
|
234 |
saveButton.setToolTipText(Messages.getText("save_color_interpretation")); |
|
235 |
saveButton.addActionListener(panelListener); |
|
236 |
} |
|
237 |
return saveButton; |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* A?ade la lista de georasterfiles a la tabla |
|
242 |
* @param dstore |
|
243 |
* @throws NotInitializeException |
|
244 |
*/ |
|
245 |
public void addFiles(RasterDataStore dstore) throws NotInitializeException { |
|
246 |
getFileList().clear(); |
|
247 |
clear(); |
|
248 |
if(dstore.isMultiFile()) { |
|
249 |
URI[] uris = dstore.getURIByProvider(); |
|
250 |
for (int i = 0; i < uris.length; i++) { |
|
251 |
getFileList().addFName(new File(uris[i]).getAbsolutePath()); |
|
252 |
} |
|
253 |
} else |
|
254 |
getFileList().addFName(dstore.getName()); |
|
255 |
|
|
256 |
int nbands = dstore.getBandCount(); |
|
257 |
for (int i = 0; i < nbands; i++) { |
|
258 |
URI uriByBand = dstore.getURIByBand(i); |
|
259 |
String bandName = ""; |
|
260 |
if("FILE".equalsIgnoreCase(uriByBand.getScheme())){ |
|
261 |
File file = new File(uriByBand); |
|
262 |
bandName = file.getName(); |
|
263 |
} else { |
|
264 |
bandName = dstore.getFullName(); |
|
265 |
} |
|
266 |
|
|
267 |
String bandType = ""; |
|
268 |
|
|
269 |
switch (dstore.getDataType()[0]) { |
|
270 |
case DataBuffer.TYPE_BYTE: |
|
271 |
bandType = "8U"; |
|
272 |
break; |
|
273 |
case DataBuffer.TYPE_INT: |
|
274 |
bandType = "32"; |
|
275 |
break; |
|
276 |
case DataBuffer.TYPE_DOUBLE: |
|
277 |
bandType = "64"; |
|
278 |
break; |
|
279 |
case DataBuffer.TYPE_FLOAT: |
|
280 |
bandType = "32"; |
|
281 |
break; |
|
282 |
case DataBuffer.TYPE_SHORT: |
|
283 |
bandType = "16"; |
|
284 |
break; |
|
285 |
case DataBuffer.TYPE_USHORT: |
|
286 |
bandType = "16U"; |
|
287 |
break; |
|
288 |
case DataBuffer.TYPE_UNDEFINED: |
|
289 |
bandType = "??"; |
|
290 |
break; |
|
291 |
} |
|
292 |
|
|
293 |
addBand((i + 1) + " [" + bandType + "] " + bandName); |
|
294 |
} |
|
295 |
|
|
296 |
if(fLayer != null) { |
|
297 |
readDrawedBands(); |
|
298 |
saveStatus(); |
|
299 |
} |
|
300 |
//evaluateControlsEnabled(); |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* Elimina un fichero de la lista |
|
305 |
* @param file Nombre del fichero a eliminar |
|
306 |
*/ |
|
307 |
public void removeFile(String file) { |
|
308 |
getFileList().removeFName(file); |
|
309 |
|
|
310 |
for (int i = 0; i < ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); i++) { |
|
311 |
// Si el fichero borrado estaba seleccionado como banda visible. Pasaremos |
|
312 |
// esta visibilidad a la banda inmediata superior y si esta acci?n produce |
|
313 |
// una excepci?n (porque no hay) se pasa al inmediato inferior. |
|
314 |
if (((String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 4)).endsWith(file)) { |
|
315 |
try { |
|
316 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 0)).booleanValue()) { |
|
317 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 1); |
|
318 |
} |
|
319 |
} catch (ArrayIndexOutOfBoundsException exc) { |
|
320 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 1); |
|
321 |
} |
|
322 |
|
|
323 |
try { |
|
324 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 1)).booleanValue()) { |
|
325 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 2); |
|
326 |
} |
|
327 |
} catch (ArrayIndexOutOfBoundsException exc) { |
|
328 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 2); |
|
329 |
} |
|
330 |
|
|
331 |
try { |
|
332 |
if (((Boolean) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 2)).booleanValue()) { |
|
333 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i - 1, 3); |
|
334 |
} |
|
335 |
} catch (ArrayIndexOutOfBoundsException exc) { |
|
336 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(new Boolean(true), i + 1, 3); |
|
337 |
} |
|
338 |
|
|
339 |
((DefaultTableModel) getARGBTable().getModel()).removeRow(i); |
|
340 |
i--; // Ojo! que hemos eliminado una fila |
|
341 |
} |
|
342 |
} |
|
343 |
panelListener.setNewBandsPositionInRendering(); |
|
344 |
} |
|
345 |
|
|
346 |
/** |
|
347 |
* Cuando cambiamos el combo de seleccion de numero de bandas a visualizar |
|
348 |
* debemos resetear la tabla de checkbox para que no haya activados m?s de los |
|
349 |
* permitidos |
|
350 |
* @param mode |
|
351 |
*/ |
|
352 |
public void resetMode(int mode) { |
|
353 |
DefaultTableModel model = getARGBTable().getModel(); |
|
354 |
// Reseteamos los checkbox |
|
355 |
for (int i = 0; i < (model.getColumnCount() - 1); i++) |
|
356 |
for (int j = 0; j < model.getRowCount(); j++) |
|
357 |
model.setValueAt(Boolean.FALSE, j, i); |
|
358 |
|
|
359 |
// Asignamos los valores |
|
360 |
if (getNBands() >= 1) { |
|
361 |
switch (mode) { |
|
362 |
case 3: |
|
363 |
int b = 2; |
|
364 |
if (getNBands() < 3) |
|
365 |
b = getNBands() - 1; |
|
366 |
model.setValueAt(Boolean.TRUE, b, 3); |
|
367 |
case 2: |
|
368 |
int g = 1; |
|
369 |
if (getNBands() == 1) |
|
370 |
g = 0; |
|
371 |
model.setValueAt(Boolean.TRUE, g, 2); |
|
372 |
case 1: |
|
373 |
model.setValueAt(Boolean.TRUE, 0, 1); |
|
374 |
} |
|
375 |
} |
|
376 |
|
|
377 |
col[0] = 0; |
|
378 |
col[1] = 1; |
|
379 |
} |
|
380 |
|
|
381 |
/** |
|
382 |
* A?ade una banda a la tabla bandas de la imagen asignandole un nombre y |
|
383 |
* valor a los checkbox |
|
384 |
* @param bandName Nombre de la banda |
|
385 |
* @throws NotInitializeException |
|
386 |
*/ |
|
387 |
private void addBand(String bandName) throws NotInitializeException { |
|
388 |
Object[] row = { new Boolean(false), |
|
389 |
new Boolean(false), |
|
390 |
new Boolean(false), |
|
391 |
new Boolean(false), |
|
392 |
bandName }; |
|
393 |
getARGBTable().addRow(row); |
|
394 |
} |
|
395 |
|
|
396 |
/** |
|
397 |
* Elimina todas las entradas de la tabla de bandas. |
|
398 |
*/ |
|
399 |
private void clear() { |
|
400 |
int rows = ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); |
|
401 |
if (rows > 0) { |
|
402 |
for (int i = 0; i < rows; i++) |
|
403 |
((DefaultTableModel) getARGBTable().getModel()).removeRow(0); |
|
404 |
} |
|
405 |
} |
|
406 |
|
|
407 |
/** |
|
408 |
* Obtiene el n?mero de bandas de la lista |
|
409 |
* |
|
410 |
* @return the number of bands |
|
411 |
*/ |
|
412 |
public int getNBands() { |
|
413 |
return ((DefaultTableModel) getARGBTable().getModel()).getRowCount(); |
|
414 |
} |
|
415 |
|
|
416 |
/** |
|
417 |
* Obtiene el nombre de la banda de la posici?n i de la tabla |
|
418 |
* |
|
419 |
* @param i |
|
420 |
* @return the band name |
|
421 |
*/ |
|
422 |
public String getBandName(int i) { |
|
423 |
String s = (String) ((DefaultTableModel) getARGBTable().getModel()).getValueAt(i, 3); |
|
424 |
return s.substring(s.lastIndexOf("[8U]") + 5, s.length()); |
|
425 |
} |
|
426 |
|
|
427 |
/** |
|
428 |
* Mantiene la asignaci?n entre R, G o B y la banda de la imagen que le |
|
429 |
* corresponde |
|
430 |
* |
|
431 |
* @param nBand Banda de la imagen que corresponde |
|
432 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica |
|
433 |
*/ |
|
434 |
public void assignBand(int nBand, int flag) { |
|
435 |
Boolean t = new Boolean(true); |
|
436 |
try { |
|
437 |
if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND) |
|
438 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 0); |
|
439 |
|
|
440 |
if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND) |
|
441 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 1); |
|
442 |
|
|
443 |
if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND) |
|
444 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 2); |
|
445 |
|
|
446 |
if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND) |
|
447 |
((DefaultTableModel) getARGBTable().getModel()).setValueAt(t, nBand, 3); |
|
448 |
} catch (ArrayIndexOutOfBoundsException e) { |
|
449 |
|
|
450 |
} |
|
451 |
} |
|
452 |
|
|
453 |
/** |
|
454 |
* Obtiene la correspondencia entre el R, G o B y la banda asignada |
|
455 |
* |
|
456 |
* @param flag R, G o B se selecciona por medio de un flag que los identifica |
|
457 |
* @return Banda de la imagen asignada al flag pasado por par?metro |
|
458 |
*/ |
|
459 |
public int getColorInterpretationByColorBandBand(int flag) { |
|
460 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
|
461 |
if ((flag & RasterDataStore.ALPHA_BAND) == RasterDataStore.ALPHA_BAND) { |
|
462 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
|
463 |
if (((Boolean) model.getValueAt(nBand, 0)).booleanValue()) |
|
464 |
return nBand; |
|
465 |
} |
|
466 |
|
|
467 |
if ((flag & RasterDataStore.RED_BAND) == RasterDataStore.RED_BAND) { |
|
468 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
|
469 |
if (((Boolean) model.getValueAt(nBand, 1)).booleanValue()) |
|
470 |
return nBand; |
|
471 |
} |
|
472 |
|
|
473 |
if ((flag & RasterDataStore.GREEN_BAND) == RasterDataStore.GREEN_BAND) { |
|
474 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
|
475 |
if (((Boolean) model.getValueAt(nBand, 2)).booleanValue()) |
|
476 |
return nBand; |
|
477 |
} |
|
478 |
|
|
479 |
if ((flag & RasterDataStore.BLUE_BAND) == RasterDataStore.BLUE_BAND) { |
|
480 |
for (int nBand = 0; nBand < getARGBTable().getModel().getRowCount(); nBand++) |
|
481 |
if (((Boolean) model.getValueAt(nBand, 3)).booleanValue()) |
|
482 |
return nBand; |
|
483 |
} |
|
484 |
|
|
485 |
return -1; |
|
486 |
} |
|
487 |
|
|
488 |
/** |
|
489 |
* Obtiene la interpretaci?n de color por n?mero de banda |
|
490 |
* @param nBand N?mero de banda |
|
491 |
* @return Interpretaci?n de color. Constante definida en DatasetColorInterpretation |
|
492 |
*/ |
|
493 |
public String getColorInterpretationByBand(int nBand) { |
|
494 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
|
495 |
for (int col = 0; col < 4; col++) { |
|
496 |
if(((Boolean) model.getValueAt(nBand, col)).booleanValue()) { |
|
497 |
switch (col) { |
|
498 |
case 0: return ColorInterpretation.ALPHA_BAND; |
|
499 |
case 1: return ColorInterpretation.RED_BAND; |
|
500 |
case 2: return ColorInterpretation.GREEN_BAND; |
|
501 |
case 3: return ColorInterpretation.BLUE_BAND; |
|
502 |
} |
|
503 |
} |
|
504 |
} |
|
505 |
return ColorInterpretation.UNDEF_BAND; |
|
506 |
} |
|
507 |
|
|
508 |
/** |
|
509 |
* @return the color interpretation |
|
510 |
*/ |
|
511 |
public ColorInterpretation getSelectedColorInterpretation() { |
|
512 |
try { |
|
513 |
String[] colorInter = new String[getARGBTable().getRowCount()]; |
|
514 |
for (int iBand = 0; iBand < getARGBTable().getRowCount(); iBand++) { |
|
515 |
if(isSelected(iBand, 1) && isSelected(iBand, 2) && isSelected(iBand, 3)) { |
|
516 |
colorInter[iBand] = ColorInterpretation.GRAY_BAND; |
|
517 |
} else if(isSelected(iBand, 1) && isSelected(iBand, 2)) { |
|
518 |
colorInter[iBand] = ColorInterpretation.RED_GREEN_BAND; |
|
519 |
} else if(isSelected(iBand, 1) && isSelected(iBand, 3)) { |
|
520 |
colorInter[iBand] = ColorInterpretation.RED_BLUE_BAND; |
|
521 |
} else if(isSelected(iBand, 2) && isSelected(iBand, 3)) { |
|
522 |
colorInter[iBand] = ColorInterpretation.GREEN_BLUE_BAND; |
|
523 |
} else if(isSelected(iBand, 1)) { |
|
524 |
colorInter[iBand] = ColorInterpretation.RED_BAND; |
|
525 |
} else if(isSelected(iBand, 2)) { |
|
526 |
colorInter[iBand] = ColorInterpretation.GREEN_BAND; |
|
527 |
} else if(isSelected(iBand, 3)) { |
|
528 |
colorInter[iBand] = ColorInterpretation.BLUE_BAND; |
|
529 |
} else if(isSelected(iBand, 0)) { |
|
530 |
colorInter[iBand] = ColorInterpretation.ALPHA_BAND; |
|
531 |
} else |
|
532 |
colorInter[iBand] = ColorInterpretation.UNDEF_BAND; |
|
533 |
} |
|
534 |
return RasterLocator.getManager().getDataStructFactory().createColorInterpretation(colorInter); |
|
535 |
} catch (NotInitializeException e) { |
|
536 |
RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), this, e); |
|
537 |
} |
|
538 |
return null; |
|
539 |
} |
|
540 |
|
|
541 |
private boolean isSelected(int iBand, int col) { |
|
542 |
DefaultTableModel model = ((DefaultTableModel) getARGBTable().getModel()); |
|
543 |
return ((Boolean) model.getValueAt(iBand, col)).booleanValue(); |
|
544 |
} |
|
545 |
|
|
546 |
public void tableChanged(TableModelEvent e) { |
|
547 |
getARGBTable().revalidate(); |
|
548 |
revalidate(); |
|
549 |
} |
|
550 |
|
|
551 |
/** |
|
552 |
* @return RasterDataStore |
|
553 |
*/ |
|
554 |
public RasterDataStore getResult() { |
|
555 |
return panelListener.getResult(); |
|
556 |
} |
|
557 |
|
|
558 |
/** |
|
559 |
* Activa o desactiva la funcionalidad |
|
560 |
*/ |
|
561 |
private void actionEnabled() { |
|
562 |
boolean enabled = true; |
|
563 |
|
|
564 |
IRasterLayerActions actions = null; |
|
565 |
|
|
566 |
if(fLayer != null && fLayer instanceof IRasterLayerActions) |
|
567 |
actions = (IRasterLayerActions)fLayer; |
|
568 |
|
|
569 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST)) |
|
570 |
enabled = false; |
|
571 |
getFileList().setEnabled(enabled); |
|
572 |
|
|
573 |
enabled = true; |
|
574 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_RGB)) |
|
575 |
enabled = false; |
|
576 |
getARGBTable().setEnabled(enabled); |
|
577 |
|
|
578 |
// TODO: Mirar el setVisible... |
|
579 |
if (!actions.isActionEnabled(IRasterLayerActions.BANDS_FILE_LIST) && |
|
580 |
!actions.isActionEnabled(IRasterLayerActions.BANDS_RGB)) |
|
581 |
setVisible(false); |
|
582 |
else |
|
583 |
setVisible(true); |
|
584 |
|
|
585 |
if (!actions.isActionEnabled(IRasterLayerActions.SAVE_COLORINTERP)) |
|
586 |
getSaveButton().setVisible(false); |
|
587 |
} |
|
588 |
|
|
589 |
/** |
|
590 |
* Lee desde el renderizador las bandas que se han dibujado y en que posici?n se ha hecho. |
|
591 |
*/ |
|
592 |
public void readDrawedBands() { |
|
593 |
if (fLayer.getRender() != null) { |
|
594 |
int[] renderBands = fLayer.getRender().getRenderColorInterpretation().buildRenderBands(); |
|
595 |
Transparency transp = fLayer.getRender().getRenderingTransparency(); |
|
596 |
if(transp != null && transp.getAlphaBandNumber() != -1) |
|
597 |
this.assignBand(transp.getAlphaBandNumber(), RasterDataStore.ALPHA_BAND); |
|
598 |
for (int i = 0; i < renderBands.length; i++) { |
|
599 |
if (renderBands[i] >= 0) { |
|
600 |
switch (i) { |
|
601 |
case 0: |
|
602 |
this.assignBand(renderBands[i], RasterDataStore.RED_BAND); |
|
603 |
break; |
|
604 |
case 1: |
|
605 |
this.assignBand(renderBands[i], RasterDataStore.GREEN_BAND); |
|
606 |
break; |
|
607 |
case 2: |
|
608 |
this.assignBand(renderBands[i], RasterDataStore.BLUE_BAND); |
|
609 |
break; |
|
610 |
} |
|
611 |
} |
|
612 |
} |
|
613 |
} |
|
614 |
} |
|
615 |
|
|
616 |
public void accept() { |
|
617 |
if (!getPanelGroup().isPanelInGUI(this)) |
|
618 |
return; |
|
619 |
|
|
620 |
onlyApply(); |
|
621 |
} |
|
622 |
|
|
623 |
/** |
|
624 |
* Aplica y guarda los cambios del panel |
|
625 |
*/ |
|
626 |
public void apply() { |
|
627 |
if (!getPanelGroup().isPanelInGUI(this)) |
|
628 |
return; |
|
629 |
|
|
630 |
onlyApply(); |
|
631 |
saveStatus(); |
|
632 |
} |
|
633 |
|
|
634 |
/** |
|
635 |
* Aplicar los cambios sin guardar su estado |
|
636 |
*/ |
|
637 |
public void onlyApply() { |
|
638 |
if (RasterPropertiesTocMenuEntry.enableEvents) |
|
639 |
panelListener.apply(); |
|
640 |
} |
|
641 |
|
|
642 |
/** |
|
643 |
* Guarda el estado actual del panel |
|
644 |
*/ |
|
645 |
@SuppressWarnings("unchecked") |
|
646 |
private void saveStatus() { |
|
647 |
List<String> aux = new ArrayList<String>(); |
|
648 |
String[] valuesCI = fLayer.getRender().getRenderColorInterpretation().getValues(); |
|
649 |
for (int i = 0; i < valuesCI.length; i++) { |
|
650 |
aux.add(valuesCI[i]); |
|
651 |
} |
|
652 |
getPanelGroup().getProperties().put("renderBands", aux); |
|
653 |
} |
|
654 |
|
|
655 |
|
|
656 |
/** |
|
657 |
* Deja la capa en el ?ltimo estado guardado y la refresca |
|
658 |
*/ |
|
659 |
@SuppressWarnings("unchecked") |
|
660 |
public void restoreStatus() { |
|
661 |
if (fLayer != null) |
|
662 |
return; |
|
663 |
|
|
664 |
List<String> aux = (List<String>) getPanelGroup().getProperties().get("renderBands"); |
|
665 |
|
|
666 |
if(fLayer.getRender() != null) { |
|
667 |
ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation((String[])aux.toArray()); |
|
668 |
fLayer.getRender().setRenderColorInterpretation(ci); |
|
669 |
} |
|
670 |
|
|
671 |
fLayer.getMapContext().invalidate(); |
|
672 |
} |
|
673 |
|
|
674 |
public void cancel() { |
|
675 |
if (!getPanelGroup().isPanelInGUI(this)) |
|
676 |
return; |
|
677 |
|
|
678 |
restoreStatus(); |
|
679 |
} |
|
680 |
|
|
681 |
/** |
|
682 |
* Activa y desactiva el control |
|
683 |
* @param enabled true para activar y false para desactivar |
|
684 |
*/ |
|
685 |
public void setEnabled(boolean enabled) { |
|
686 |
if (panelListener != null) |
|
687 |
panelListener.setEnabledPanelAction(enabled); |
|
688 |
getARGBTable().setEnabled(enabled); |
|
689 |
getFileList().setEnabled(enabled); |
|
690 |
} |
|
691 |
|
|
692 |
/** |
|
693 |
* Sets the current layer when the panel is opened from |
|
694 |
* raster properties |
|
695 |
*/ |
|
696 |
public void setReference(Object ref) { |
|
697 |
super.setReference(ref); |
|
698 |
|
|
699 |
if (!(ref instanceof FLyrRaster)) |
|
700 |
return; |
|
701 |
|
|
702 |
fLayer = (FLyrRaster) ref; |
|
703 |
|
|
704 |
actionEnabled(); |
|
705 |
|
|
706 |
clear(); |
|
707 |
getFileList().clear(); |
|
708 |
|
|
709 |
//Si tiene tabla de color inicializamos solamente |
|
710 |
|
|
711 |
if (fLayer.existColorTable()) { |
|
712 |
((BandSelectorPropertiesListener)panelListener).init(fLayer); |
|
713 |
return; |
|
714 |
} |
|
715 |
|
|
716 |
//Si no tiene tabla de color se a?aden los ficheros e inicializamos |
|
717 |
try { |
|
718 |
addFiles(fLayer.getDataStore()); |
|
719 |
} catch (NotInitializeException e) { |
|
720 |
RasterSwingLibrary.messageBoxError(Messages.getText("table_not_initialize"), this); |
|
721 |
} |
|
722 |
|
|
723 |
((BandSelectorPropertiesListener)panelListener).init(fLayer); |
|
724 |
} |
|
725 |
|
|
726 |
/** |
|
727 |
* @param e |
|
728 |
*/ |
|
729 |
public void componentHidden(ComponentEvent e) {} |
|
730 |
/** |
|
731 |
* @param e |
|
732 |
*/ |
|
733 |
public void componentShown(ComponentEvent e) {} |
|
734 |
/** |
|
735 |
* @param e |
|
736 |
*/ |
|
737 |
public void componentMoved(ComponentEvent e) {} |
|
738 |
|
|
739 |
|
|
740 |
public void selected() { |
|
741 |
setReference(fLayer); |
|
742 |
} |
|
743 |
} |
|
0 | 744 |
org.gvsig.raster.multifile/tags/org.gvsig.raster.multifile-2.2.62/org.gvsig.raster.multifile.app.multifileclient/src/main/java/org/gvsig/raster/multifile/app/panel/BandSelectorPropertiesListener.java | ||
---|---|---|
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.event.ActionEvent; |
|
25 |
import java.awt.geom.Point2D; |
|
26 |
import java.io.File; |
|
27 |
import java.net.URI; |
|
28 |
import java.util.ArrayList; |
|
29 |
import java.util.List; |
|
30 |
|
|
31 |
import org.apache.commons.io.FilenameUtils; |
|
32 |
|
|
33 |
import org.gvsig.andami.PluginServices; |
|
34 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
35 |
import org.gvsig.fmap.dal.DALLocator; |
|
36 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
37 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException; |
|
38 |
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException; |
|
39 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
|
40 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterDataParameters; |
|
41 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
42 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
43 |
import org.gvsig.fmap.dal.coverage.util.ProviderServices; |
|
44 |
import org.gvsig.fmap.dal.raster.spi.CoverageStoreProvider; |
|
45 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.swing.FilesystemExplorerWizardPanel; |
|
46 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
47 |
import org.gvsig.fmap.dal.spi.DataStoreProvider; |
|
48 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
49 |
import org.gvsig.gui.beans.swing.JFileChooser; |
|
50 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
|
51 |
import org.gvsig.i18n.Messages; |
|
52 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
|
53 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
54 |
import org.gvsig.raster.mainplugin.RasterMainPluginUtils; |
|
55 |
import org.gvsig.raster.mainplugin.config.Configuration; |
|
56 |
import org.gvsig.raster.multifile.io.MultiFileDataParameters; |
|
57 |
import org.gvsig.raster.multifile.io.MultiFileProvider; |
|
58 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
59 |
import org.gvsig.raster.swing.basepanel.ButtonsPanelEvent; |
|
60 |
|
|
61 |
/** |
|
62 |
* Clase que maneja los eventos del panel BandSetupPanel. Gestiona el a?adir o |
|
63 |
* eliminar ficheros de la lista y contiene las acciones a realizar cuando en |
|
64 |
* panel registrable se pulsa aceptar, aplicar o cancelar. |
|
65 |
* |
|
66 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
67 |
*/ |
|
68 |
public class BandSelectorPropertiesListener extends AbstractBandSelectorListener { |
|
69 |
private JFileChooser fileChooser = null; |
|
70 |
private FLyrRaster fLayer = null; |
|
71 |
private List<File> fileList = null; |
|
72 |
|
|
73 |
/** |
|
74 |
* Constructor |
|
75 |
* @param bs Panel del selector de bandas |
|
76 |
*/ |
|
77 |
public BandSelectorPropertiesListener(BandSelectorPanel bs) { |
|
78 |
super(bs); |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Constructor |
|
83 |
* @param lyr Capa raster |
|
84 |
*/ |
|
85 |
public void init(FLyrRaster lyr) { |
|
86 |
fLayer = lyr; |
|
87 |
} |
|
88 |
|
|
89 |
public RasterDataStore getResult() { |
|
90 |
return fLayer.getDataStore(); |
|
91 |
} |
Also available in: Unified diff