gvsig-raster / org.gvsig.raster.principalcomponents / branches / org.gvsig.raster.principalcomponents_dataaccess_refactoring / org.gvsig.raster.principalcomponents.app.principalcomponentsclient / src / main / java / org / gvsig / raster / principalcomponents / app / PrincipalComponentsExtension.java @ 2379
History | View | Annotate | Download (8.18 KB)
1 |
package org.gvsig.raster.principalcomponents.app; |
---|---|
2 |
|
3 |
import java.awt.event.ActionEvent; |
4 |
import java.awt.event.ActionListener; |
5 |
import java.util.HashMap; |
6 |
|
7 |
import javax.swing.JPanel; |
8 |
|
9 |
import org.gvsig.andami.IconThemeHelper; |
10 |
import org.gvsig.andami.PluginServices; |
11 |
import org.gvsig.andami.plugins.Extension; |
12 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
13 |
import org.gvsig.app.project.documents.view.gui.IView; |
14 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
15 |
import org.gvsig.fmap.mapcontrol.MapControl; |
16 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
17 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
18 |
import org.gvsig.i18n.Messages; |
19 |
import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
20 |
import org.gvsig.raster.algorithm.process.DataProcess; |
21 |
import org.gvsig.raster.algorithm.process.IProcessActions; |
22 |
import org.gvsig.raster.algorithm.process.ProcessParamsManagement; |
23 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
24 |
import org.gvsig.raster.principalcomponents.algorithm.PCStatsDataStructure; |
25 |
import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsAlgorithmLibrary; |
26 |
import org.gvsig.raster.principalcomponents.app.toolbox.ToolboxPCLoader; |
27 |
import org.gvsig.raster.principalcomponents.swing.PrincipalComponentsSwingLibrary; |
28 |
import org.gvsig.raster.principalcomponents.swing.PrincipalComponentsSwingLocator; |
29 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
32 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
33 |
|
34 |
|
35 |
public class PrincipalComponentsExtension extends Extension implements ActionListener, IProcessActions { |
36 |
private BasicAPISwingPanel mainPanel = null; |
37 |
private BasicAPISwingPanel componentsPanel = null; |
38 |
private MainWindow windowMainPanel = null; |
39 |
private MainWindow windowComponentsPanel = null; |
40 |
private MainWindow statisticsPanel = null; |
41 |
private FLyrRaster lyr = null; |
42 |
private PCStatsDataStructure stats = null; |
43 |
|
44 |
public void initialize() { |
45 |
|
46 |
// Adds an entry to the TOC's floating menu to those layers defined in this extension
|
47 |
|
48 |
//ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("My_TocActions");
|
49 |
//exPoint.append("MyMenuEntry", "", new PrincipalComponentsTocMenuEntry());
|
50 |
|
51 |
// Adds a new tab to the "add layer" dialog
|
52 |
|
53 |
//AddLayer.addWizard(PrincipalComponentsWizard.class);
|
54 |
|
55 |
// Adds a new button in the raster bar
|
56 |
// TODO: Remove for providers
|
57 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
58 |
ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
|
59 |
point.append("PrincipalComponents", "", PrincipalComponentsTocMenuEntry.getSingleton()); |
60 |
PrincipalComponentsTocMenuEntry.setExtension(this);
|
61 |
|
62 |
Messages.addResourceFamily("org.gvsig.raster.principalcomponents.app.i18n.text",
|
63 |
PrincipalComponentsExtension.class.getClassLoader(), |
64 |
PrincipalComponentsExtension.class.getClass().getName()); |
65 |
|
66 |
initilizeIcons(); |
67 |
} |
68 |
|
69 |
public void postInitialize() { |
70 |
new ToolboxPCLoader().registerTool();
|
71 |
} |
72 |
|
73 |
public void execute(String actionCommand) { |
74 |
if (actionCommand.compareTo("PrincipalComponents") == 0) { |
75 |
lyr = getSelectedLayer(); |
76 |
if(lyr == null) { |
77 |
RasterSwingLibrary.messageBoxError(Messages.getText("layer_not_found"), null); |
78 |
return;
|
79 |
} |
80 |
|
81 |
String defaultROIEPSG = getFirstMapCtrl().getProjection().getAbrev();
|
82 |
|
83 |
mainPanel = PrincipalComponentsSwingLocator.getSwingManager().createPCAMainPanel( |
84 |
lyr.getDataStore(), |
85 |
lyr.getName(), |
86 |
lyr.getDataStore().getBandCount(), |
87 |
defaultROIEPSG); |
88 |
|
89 |
windowMainPanel = new MainWindow(mainPanel.getComponent(),
|
90 |
Messages.getText("principal_components"),
|
91 |
400, 350, |
92 |
this);
|
93 |
|
94 |
PluginServices.getMDIManager().addCentredWindow(windowMainPanel); |
95 |
|
96 |
mainPanel.initialize(); |
97 |
} |
98 |
} |
99 |
|
100 |
/**
|
101 |
* Gets the Mapcontrol for the first view found.
|
102 |
* @return
|
103 |
*/
|
104 |
private MapControl getFirstMapCtrl() {
|
105 |
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
106 |
for (int i = 0; i < windowList.length; i++) { |
107 |
if(windowList[i] instanceof IView) { |
108 |
return ((IView)windowList[i]).getMapControl();
|
109 |
} |
110 |
} |
111 |
return null; |
112 |
} |
113 |
|
114 |
/**
|
115 |
* Gets the selected and valid layer
|
116 |
* @return
|
117 |
*/
|
118 |
private FLyrRaster getSelectedLayer() {
|
119 |
FLayer[] lyrList = getFirstMapCtrl().getMapContext().getLayers().getActives();
|
120 |
for (int i = 0; i < lyrList.length; i++) { |
121 |
if(lyrList[i] instanceof FLyrRaster) |
122 |
return (FLyrRaster)lyrList[i];
|
123 |
} |
124 |
return null; |
125 |
} |
126 |
|
127 |
public boolean isEnabled() { |
128 |
return false; |
129 |
} |
130 |
|
131 |
public boolean isVisible() { |
132 |
return false; |
133 |
} |
134 |
|
135 |
void initilizeIcons(){
|
136 |
IconThemeHelper.registerIcon(null, "principal-components", this); |
137 |
} |
138 |
|
139 |
public void actionPerformed(ActionEvent e) { |
140 |
//ACCEPT MAIN PANEL
|
141 |
if( e.getSource() == ((DefaultButtonsPanel)windowMainPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY) ||
|
142 |
e.getSource() == ((DefaultButtonsPanel)windowMainPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) { |
143 |
DataProcess task = null;
|
144 |
try {
|
145 |
task = (DataProcess)mainPanel.getResult(); |
146 |
} catch (Exception e1) { |
147 |
RasterSwingLibrary.messageBoxError(Messages.getText("problems_creating_process"), null); |
148 |
return;
|
149 |
} |
150 |
task.setActions(this);
|
151 |
task.init(); |
152 |
task.start(); |
153 |
} |
154 |
|
155 |
//GENERATE STATISTICS BUTTON
|
156 |
if( componentsPanel != null && |
157 |
PrincipalComponentsSwingLibrary.GENERATE_STATIST == componentsPanel.getComponentIDByObject(e.getSource())) { |
158 |
try {
|
159 |
Object[] result = (Object[])componentsPanel.getResult(); |
160 |
JPanel statsPanel = PrincipalComponentsSwingLocator.getSwingManager().createStatisticsPanel(
|
161 |
stats, |
162 |
(Boolean)result[1], |
163 |
(Boolean)result[2], |
164 |
(Boolean)result[3]); |
165 |
statisticsPanel = new MainWindow(statsPanel,
|
166 |
Messages.getText("stats"),
|
167 |
800, 500, |
168 |
this,
|
169 |
true);
|
170 |
|
171 |
PluginServices.getMDIManager().addWindow(statisticsPanel); |
172 |
} catch (Exception e1) { |
173 |
RasterSwingLibrary.messageBoxError(Messages.getText("problems_creating_process"), null); |
174 |
return;
|
175 |
} |
176 |
} |
177 |
|
178 |
//ACCEPT COMPONENTS PANEL
|
179 |
if( windowComponentsPanel != null && |
180 |
(e.getSource() == ((DefaultButtonsPanel)windowComponentsPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY) || |
181 |
e.getSource() == ((DefaultButtonsPanel)windowComponentsPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT))) { |
182 |
DataProcess task = null;
|
183 |
try {
|
184 |
Object[] result = (Object[])componentsPanel.getResult(); |
185 |
task = (DataProcess)result[0];
|
186 |
task.setActions(new ProcessEndActions(windowComponentsPanel, lyr));
|
187 |
task.init(); |
188 |
task.start(); |
189 |
} catch (Exception e1) { |
190 |
RasterSwingLibrary.messageBoxError(Messages.getText("problems_creating_process"), null); |
191 |
return;
|
192 |
} |
193 |
} |
194 |
} |
195 |
|
196 |
@SuppressWarnings("unchecked") |
197 |
public void end(Object param) { |
198 |
HashMap<String, Object> params = (HashMap<String, Object>)param; |
199 |
String processName = (String)params.get(ProcessParamsManagement.PROCESS_NAME); |
200 |
|
201 |
//END STATISTICS PROCESS (after accept main dialog)
|
202 |
if (processName.equals(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL)) {
|
203 |
PluginServices.getMDIManager().closeWindow(windowMainPanel); |
204 |
stats = (PCStatsDataStructure)params.get("STATS_RESULT");
|
205 |
String fileName = (String)params.get("PATH"); |
206 |
boolean[] bands = (boolean[])params.get("BANDS"); |
207 |
String rois = (String)params.get("ROI_EPSG"); |
208 |
|
209 |
componentsPanel = PrincipalComponentsSwingLocator.getSwingManager().createPCAComponentsListPanel( |
210 |
lyr.getDataStore(), |
211 |
stats, |
212 |
fileName, |
213 |
bands, |
214 |
rois); |
215 |
componentsPanel.addListener(this);
|
216 |
windowComponentsPanel = new MainWindow(componentsPanel.getComponent(),
|
217 |
Messages.getText("principal_components"),
|
218 |
400, 350, |
219 |
this);
|
220 |
PluginServices.getMDIManager().addCentredWindow(windowComponentsPanel); |
221 |
componentsPanel.initialize(); |
222 |
} |
223 |
} |
224 |
|
225 |
public void interrupted() { |
226 |
|
227 |
} |
228 |
|
229 |
public void updateProgress(int current, int total) { |
230 |
|
231 |
} |
232 |
} |