gvsig-raster / org.gvsig.raster.mosaic / trunk / org.gvsig.raster.mosaic / org.gvsig.raster.mosaic.app / src / main / java / org / gvsig / raster / mosaic / app / MosaicSupportExtension.java @ 2191
History | View | Annotate | Download (5.77 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.mosaic.app; |
23 |
|
24 |
import java.awt.event.ActionEvent; |
25 |
import java.awt.event.ActionListener; |
26 |
import java.util.Locale; |
27 |
|
28 |
import javax.swing.JComponent; |
29 |
|
30 |
import org.gvsig.andami.IconThemeHelper; |
31 |
import org.gvsig.andami.PluginServices; |
32 |
import org.gvsig.andami.plugins.Extension; |
33 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
34 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
35 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
38 |
import org.gvsig.i18n.Messages; |
39 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
40 |
import org.gvsig.raster.mosaic.app.gui.MainWindow; |
41 |
import org.gvsig.raster.mosaic.swing.MosaicSwingLocator; |
42 |
import org.gvsig.raster.mosaic.swing.main.AddFilesPanel; |
43 |
import org.gvsig.raster.swing.RasterSwingLocator; |
44 |
import org.gvsig.raster.swing.basepanel.IButtonsPanel; |
45 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
46 |
import org.gvsig.tools.ToolsLocator; |
47 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
48 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
49 |
|
50 |
/**
|
51 |
* Extension to add mosaic support. This extension adds a panel to the properties raster dialog
|
52 |
*
|
53 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
54 |
*/
|
55 |
public class MosaicSupportExtension extends Extension implements ActionListener { |
56 |
//private Logger log = LoggerFactory.getLogger(MosaicSupportExtension.class);
|
57 |
private CreateNewLayerPanel newLayerPanel = null; |
58 |
private MainWindow layerNamewindow = null; |
59 |
private MainWindow addFilesWindow = null; |
60 |
private AddFilesPanel addFilesPanel = null; |
61 |
private MainDialogActions actions = null; |
62 |
|
63 |
public void execute(String actionCommand) { |
64 |
if (actionCommand.compareTo("MosaicCreator") == 0) { |
65 |
layerNamewindow = new MainWindow((JComponent)getNewLayerPanel(), |
66 |
Messages.getText("select_output_file"), 300, 150, this); |
67 |
PluginServices.getMDIManager().addCentredWindow(layerNamewindow); |
68 |
} |
69 |
} |
70 |
|
71 |
public CreateNewLayerPanel getNewLayerPanel() {
|
72 |
if(newLayerPanel == null) { |
73 |
newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel(); |
74 |
} |
75 |
return newLayerPanel;
|
76 |
} |
77 |
|
78 |
public void initialize() { |
79 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
80 |
|
81 |
ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
|
82 |
point.append("Mosaic", "", MosaicTocMenuEntry.getSingleton()); |
83 |
MosaicTocMenuEntry.setExtension(this);
|
84 |
|
85 |
if (!Messages.hasLocales()) {
|
86 |
Messages.addLocale(Locale.getDefault());
|
87 |
} |
88 |
|
89 |
Messages.addResourceFamily("org.gvsig.raster.multifile.app.i18n.text",
|
90 |
MosaicSupportExtension.class.getClassLoader(), |
91 |
MosaicSupportExtension.class.getClass().getName()); |
92 |
|
93 |
initilizeIcons(); |
94 |
} |
95 |
|
96 |
public boolean isEnabled() { |
97 |
return true; |
98 |
} |
99 |
|
100 |
public boolean isVisible() { |
101 |
return true; |
102 |
} |
103 |
|
104 |
private void initilizeIcons() { |
105 |
IconThemeHelper.registerIcon(null, "mosaic-icon", this); |
106 |
} |
107 |
|
108 |
public void actionPerformed(ActionEvent e) { |
109 |
if(e.getSource() == layerNamewindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_ACCEPT)) {
|
110 |
String[] suffixList = RasterLocator.getManager().getProviderServices().getReadOnlyFormatList(); |
111 |
|
112 |
addFilesPanel = MosaicSwingLocator.getSwingManager().createAddFilesPanel(suffixList); |
113 |
loadFilesInAddFilesPanel(addFilesPanel); |
114 |
|
115 |
String file = getNewLayerPanel().getFileSelected();
|
116 |
String folder = getNewLayerPanel().getDirectorySelected();
|
117 |
actions = new MainDialogActions(addFilesPanel, file, folder);
|
118 |
addFilesPanel.addListener(actions); |
119 |
|
120 |
addFilesWindow = new MainWindow(addFilesPanel.getJComponent(), Messages.getText("add_files"), 480, 420, this, true); |
121 |
PluginServices.getMDIManager().addCentredWindow(addFilesWindow); |
122 |
} |
123 |
|
124 |
if(e.getSource() == addFilesWindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR1)) {
|
125 |
} |
126 |
|
127 |
if(e.getSource() == addFilesWindow.getButtonsPanel().getButton(IButtonsPanel.BUTTON_USR2)) {
|
128 |
} |
129 |
} |
130 |
|
131 |
private void loadFilesInAddFilesPanel(AddFilesPanel panel) { |
132 |
FLayers lyrs = getActiveView().getMapControl().getMapContext().getLayers(); |
133 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
134 |
FLayer lyr = lyrs.getLayer(i); |
135 |
if(lyr instanceof FLyrRaster) { |
136 |
FLyrRaster lyrRaster = (FLyrRaster)lyr; |
137 |
panel.addSrcFile( |
138 |
lyrRaster.getDataStore(), |
139 |
lyrRaster.getName(), |
140 |
lyrRaster.getDataStore().getBandCount(), |
141 |
lyrRaster.getDataStore().getDataType()[0]);
|
142 |
} |
143 |
} |
144 |
} |
145 |
|
146 |
public AbstractViewPanel getActiveView() {
|
147 |
IWindow w = PluginServices.getMDIManager().getActiveWindow(); |
148 |
if(w instanceof AbstractViewPanel) |
149 |
return (AbstractViewPanel)w;
|
150 |
|
151 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
152 |
for (int i = 0; i < wList.length; i++) { |
153 |
if(wList[i] instanceof AbstractViewPanel) |
154 |
return (AbstractViewPanel)wList[i];
|
155 |
} |
156 |
return null; |
157 |
} |
158 |
|
159 |
} |