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 | 2089 | nbrodin | package org.gvsig.raster.principalcomponents.app; |
---|---|---|---|
2 | |||
3 | import java.awt.event.ActionEvent; |
||
4 | import java.awt.event.ActionListener; |
||
5 | 2097 | nbrodin | import java.util.HashMap; |
6 | 2089 | nbrodin | |
7 | 2099 | nbrodin | import javax.swing.JPanel; |
8 | |||
9 | 2089 | nbrodin | 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 | 2099 | nbrodin | import org.gvsig.raster.algorithm.BasicAPISwingPanel; |
20 | 2097 | nbrodin | import org.gvsig.raster.algorithm.process.DataProcess; |
21 | import org.gvsig.raster.algorithm.process.IProcessActions; |
||
22 | import org.gvsig.raster.algorithm.process.ProcessParamsManagement; |
||
23 | 2089 | nbrodin | import org.gvsig.raster.fmap.layers.FLyrRaster; |
24 | 2098 | nbrodin | import org.gvsig.raster.principalcomponents.algorithm.PCStatsDataStructure; |
25 | 2097 | nbrodin | import org.gvsig.raster.principalcomponents.algorithm.PrincipalComponentsAlgorithmLibrary; |
26 | 2379 | nbrodin | import org.gvsig.raster.principalcomponents.app.toolbox.ToolboxPCLoader; |
27 | 2099 | nbrodin | import org.gvsig.raster.principalcomponents.swing.PrincipalComponentsSwingLibrary; |
28 | 2089 | nbrodin | import org.gvsig.raster.principalcomponents.swing.PrincipalComponentsSwingLocator; |
29 | 2107 | nbrodin | import org.gvsig.raster.swing.RasterSwingLibrary; |
30 | 2089 | nbrodin | import org.gvsig.tools.ToolsLocator; |
31 | import org.gvsig.tools.extensionpoint.ExtensionPoint; |
||
32 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
33 | |||
34 | |||
35 | 2097 | nbrodin | public class PrincipalComponentsExtension extends Extension implements ActionListener, IProcessActions { |
36 | 2099 | nbrodin | private BasicAPISwingPanel mainPanel = null; |
37 | private BasicAPISwingPanel componentsPanel = null; |
||
38 | private MainWindow windowMainPanel = null; |
||
39 | private MainWindow windowComponentsPanel = null; |
||
40 | 2115 | nbrodin | private MainWindow statisticsPanel = null; |
41 | 2099 | nbrodin | private FLyrRaster lyr = null; |
42 | private PCStatsDataStructure stats = null; |
||
43 | 2089 | nbrodin | |
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 | 2379 | nbrodin | new ToolboxPCLoader().registerTool();
|
71 | 2089 | nbrodin | } |
72 | |||
73 | public void execute(String actionCommand) { |
||
74 | if (actionCommand.compareTo("PrincipalComponents") == 0) { |
||
75 | lyr = getSelectedLayer(); |
||
76 | if(lyr == null) { |
||
77 | 2107 | nbrodin | RasterSwingLibrary.messageBoxError(Messages.getText("layer_not_found"), null); |
78 | 2089 | nbrodin | return;
|
79 | } |
||
80 | |||
81 | 2127 | nbrodin | String defaultROIEPSG = getFirstMapCtrl().getProjection().getAbrev();
|
82 | |||
83 | 2099 | nbrodin | mainPanel = PrincipalComponentsSwingLocator.getSwingManager().createPCAMainPanel( |
84 | 2089 | nbrodin | lyr.getDataStore(), |
85 | lyr.getName(), |
||
86 | 2102 | nbrodin | lyr.getDataStore().getBandCount(), |
87 | 2127 | nbrodin | defaultROIEPSG); |
88 | 2089 | nbrodin | |
89 | 2099 | nbrodin | windowMainPanel = new MainWindow(mainPanel.getComponent(),
|
90 | 2089 | nbrodin | Messages.getText("principal_components"),
|
91 | 400, 350, |
||
92 | this);
|
||
93 | |||
94 | 2099 | nbrodin | PluginServices.getMDIManager().addCentredWindow(windowMainPanel); |
95 | 2089 | nbrodin | |
96 | 2099 | nbrodin | mainPanel.initialize(); |
97 | 2089 | nbrodin | } |
98 | } |
||
99 | |||
100 | /**
|
||
101 | * Gets the Mapcontrol for the first view found.
|
||
102 | * @return
|
||
103 | */
|
||
104 | 2104 | nbrodin | 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 | 2089 | nbrodin | */
|
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 | 2102 | nbrodin | //ACCEPT MAIN PANEL
|
141 | 2099 | nbrodin | if( e.getSource() == ((DefaultButtonsPanel)windowMainPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY) ||
|
142 | e.getSource() == ((DefaultButtonsPanel)windowMainPanel).getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) { |
||
143 | 2097 | nbrodin | DataProcess task = null;
|
144 | try {
|
||
145 | 2099 | nbrodin | task = (DataProcess)mainPanel.getResult(); |
146 | } catch (Exception e1) { |
||
147 | 2107 | nbrodin | RasterSwingLibrary.messageBoxError(Messages.getText("problems_creating_process"), null); |
148 | 2097 | nbrodin | return;
|
149 | } |
||
150 | task.setActions(this);
|
||
151 | 2089 | nbrodin | task.init(); |
152 | task.start(); |
||
153 | 2097 | nbrodin | } |
154 | 2099 | nbrodin | |
155 | 2102 | nbrodin | //GENERATE STATISTICS BUTTON
|
156 | 2099 | nbrodin | 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 | 2115 | nbrodin | statisticsPanel = new MainWindow(statsPanel,
|
166 | 2099 | nbrodin | Messages.getText("stats"),
|
167 | 800, 500, |
||
168 | this,
|
||
169 | true);
|
||
170 | |||
171 | 2115 | nbrodin | PluginServices.getMDIManager().addWindow(statisticsPanel); |
172 | 2099 | nbrodin | } catch (Exception e1) { |
173 | 2107 | nbrodin | RasterSwingLibrary.messageBoxError(Messages.getText("problems_creating_process"), null); |
174 | 2099 | nbrodin | return;
|
175 | } |
||
176 | } |
||
177 | |||
178 | 2102 | nbrodin | //ACCEPT COMPONENTS PANEL
|
179 | 2099 | nbrodin | 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 | 2101 | nbrodin | task.setActions(new ProcessEndActions(windowComponentsPanel, lyr));
|
187 | 2099 | nbrodin | task.init(); |
188 | task.start(); |
||
189 | } catch (Exception e1) { |
||
190 | 2107 | nbrodin | RasterSwingLibrary.messageBoxError(Messages.getText("problems_creating_process"), null); |
191 | 2099 | nbrodin | return;
|
192 | } |
||
193 | } |
||
194 | 2089 | nbrodin | } |
195 | 2097 | nbrodin | |
196 | 2102 | nbrodin | @SuppressWarnings("unchecked") |
197 | 2097 | nbrodin | public void end(Object param) { |
198 | HashMap<String, Object> params = (HashMap<String, Object>)param; |
||
199 | String processName = (String)params.get(ProcessParamsManagement.PROCESS_NAME); |
||
200 | 2099 | nbrodin | |
201 | 2102 | nbrodin | //END STATISTICS PROCESS (after accept main dialog)
|
202 | 2101 | nbrodin | if (processName.equals(PrincipalComponentsAlgorithmLibrary.PC_STATS_PROCESS_LABEL)) {
|
203 | 2099 | nbrodin | PluginServices.getMDIManager().closeWindow(windowMainPanel); |
204 | 2101 | nbrodin | stats = (PCStatsDataStructure)params.get("STATS_RESULT");
|
205 | String fileName = (String)params.get("PATH"); |
||
206 | boolean[] bands = (boolean[])params.get("BANDS"); |
||
207 | 2127 | nbrodin | String rois = (String)params.get("ROI_EPSG"); |
208 | 2102 | nbrodin | |
209 | componentsPanel = PrincipalComponentsSwingLocator.getSwingManager().createPCAComponentsListPanel( |
||
210 | lyr.getDataStore(), |
||
211 | stats, |
||
212 | fileName, |
||
213 | bands, |
||
214 | rois); |
||
215 | 2099 | nbrodin | componentsPanel.addListener(this);
|
216 | windowComponentsPanel = new MainWindow(componentsPanel.getComponent(),
|
||
217 | 2098 | nbrodin | Messages.getText("principal_components"),
|
218 | 400, 350, |
||
219 | this);
|
||
220 | 2099 | nbrodin | PluginServices.getMDIManager().addCentredWindow(windowComponentsPanel); |
221 | componentsPanel.initialize(); |
||
222 | 2097 | nbrodin | } |
223 | } |
||
224 | |||
225 | public void interrupted() { |
||
226 | |||
227 | } |
||
228 | 2127 | nbrodin | |
229 | public void updateProgress(int current, int total) { |
||
230 | |||
231 | } |
||
232 | 2089 | nbrodin | } |