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