57 |
57 |
private ROIMaskPanel panel = null;
|
58 |
58 |
private CreateNewLayerPanel newLayerPanel = null;
|
59 |
59 |
private static final Logger logger = LoggerFactory.getLogger(ROIMaskExtension.class);
|
60 |
|
|
|
60 |
|
61 |
61 |
public void initialize() {
|
62 |
|
|
|
62 |
|
63 |
63 |
// Adds an entry to the TOC's floating menu to those layers defined in this extension
|
64 |
|
|
|
64 |
|
65 |
65 |
//ExtensionPoint exPoint = ToolsLocator.getExtensionPointManager().add("My_TocActions");
|
66 |
66 |
//exPoint.append("MyMenuEntry", "", new ROIMaskTocMenuEntry());
|
67 |
67 |
|
68 |
68 |
// Adds a new tab to the "add layer" dialog
|
69 |
|
|
|
69 |
|
70 |
70 |
//AddLayer.addWizard(ROIMaskWizard.class);
|
71 |
|
|
|
71 |
|
72 |
72 |
// Adds a new button in the raster bar
|
73 |
|
|
|
73 |
|
74 |
74 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
|
75 |
75 |
ExtensionPoint point = extensionPoints.add("GenericToolBarMenu");
|
76 |
76 |
point.append("ROIMask", "", ROIMaskTocMenuEntry.getSingleton());
|
77 |
77 |
ROIMaskTocMenuEntry.setExtension(this);
|
78 |
|
|
|
78 |
|
79 |
79 |
Messages.addResourceFamily("org.gvsig.raster.roimask.app.i18n.text",
|
80 |
80 |
ROIMaskExtension.class.getClassLoader(),
|
81 |
|
ROIMaskExtension.class.getClass().getName());
|
|
81 |
ROIMaskExtension.class.getClass().getName());
|
82 |
82 |
|
83 |
83 |
initilizeIcons();
|
84 |
84 |
}
|
85 |
|
|
|
85 |
|
86 |
86 |
public void postInitialize() {
|
87 |
87 |
new ToolboxROIMaskLoader().registerTool();
|
88 |
88 |
}
|
... | ... | |
102 |
102 |
}
|
103 |
103 |
}
|
104 |
104 |
}
|
105 |
|
|
|
105 |
|
106 |
106 |
/**
|
107 |
107 |
* Creates and initializes the main panel
|
108 |
108 |
* @throws ReadException
|
109 |
|
* @throws ROIException
|
|
109 |
* @throws ROIException
|
110 |
110 |
*/
|
111 |
111 |
private void initializeMainPanel() throws ReadException, ROIException {
|
112 |
112 |
try {
|
... | ... | |
116 |
116 |
}
|
117 |
117 |
|
118 |
118 |
MainPanel mainPanel = new MainPanel(
|
119 |
|
getROIMaskPanel().getComponent(),
|
|
119 |
getROIMaskPanel().getComponent(),
|
120 |
120 |
(JComponent)getNewLayerPanel());
|
121 |
121 |
|
122 |
122 |
window = new ROIMaskWindow(
|
123 |
|
mainPanel,
|
124 |
|
(JPanel)getPreviewPanel(),
|
125 |
|
Messages.getText("roimask"),
|
126 |
|
windowWidth,
|
|
123 |
mainPanel,
|
|
124 |
(JPanel)getPreviewPanel(),
|
|
125 |
Messages.getText("roimask"),
|
|
126 |
windowWidth,
|
127 |
127 |
windowHeight,
|
128 |
128 |
false,
|
129 |
129 |
this);
|
... | ... | |
132 |
132 |
getPreviewPanel().previewInitializeSizes();
|
133 |
133 |
getPreviewPanel().refreshPreview();
|
134 |
134 |
}
|
135 |
|
|
|
135 |
|
136 |
136 |
/**
|
137 |
137 |
* Loads the main panel with the data
|
138 |
|
* @throws NotInitializeException
|
139 |
|
* @throws ROIException
|
|
138 |
* @throws NotInitializeException
|
|
139 |
* @throws ROIException
|
140 |
140 |
*/
|
141 |
141 |
private void loadROIMaskPanel() throws NotInitializeException, ROIException {
|
142 |
142 |
FLyrRaster lyr = getSelectedLayer();
|
143 |
143 |
LayerElement element = new LayerElement(lyr);
|
144 |
144 |
getROIMaskPanel().getDataModel().setInputLayer(element);
|
145 |
145 |
ColorInterpretation ci = lyr.getDataStore().getColorInterpretation();
|
146 |
|
|
|
146 |
|
147 |
147 |
if(ci.isRGB() || ci.isRGBA()) {
|
148 |
148 |
getROIMaskPanel().activeSlider(true);
|
149 |
149 |
} else
|
150 |
150 |
getROIMaskPanel().activeSlider(false);
|
151 |
|
|
|
151 |
|
152 |
152 |
if(lyr.getRois() == null || lyr.getRois().size() == 0)
|
153 |
153 |
getROIMaskPanel().showWarning(true);
|
154 |
154 |
else
|
155 |
155 |
getROIMaskPanel().showWarning(false);
|
156 |
|
|
|
156 |
|
157 |
157 |
getROIMaskPanel().getDataModel().clearROIs();
|
158 |
|
|
|
158 |
|
159 |
159 |
List<ROI> roisArray = lyr.getRois();
|
160 |
160 |
if (roisArray != null) {
|
161 |
161 |
for (int i = 0; i < roisArray.size(); i++) {
|
162 |
162 |
ROI roi = (ROI) roisArray.get(i);
|
163 |
|
|
|
163 |
|
164 |
164 |
Object row[] = {"", "", ""};
|
165 |
|
|
|
165 |
|
166 |
166 |
boolean active = false;
|
167 |
|
|
|
167 |
|
168 |
168 |
row[0] = new Boolean(active);
|
169 |
|
row[1] = roi.getName();
|
|
169 |
row[1] = roi.getName();
|
170 |
170 |
row[2] = new Integer(i);
|
171 |
171 |
getROIMaskPanel().getDataModel().addROI(row);
|
172 |
172 |
}
|
173 |
173 |
}
|
174 |
|
|
|
174 |
|
175 |
175 |
if(lyr != null) {
|
176 |
176 |
switch(lyr.getDataStore().getDataType()[0]) {
|
177 |
177 |
case Buffer.TYPE_BYTE:
|
... | ... | |
193 |
193 |
}
|
194 |
194 |
}
|
195 |
195 |
|
196 |
|
|
|
196 |
|
197 |
197 |
/**
|
198 |
198 |
* Gets the list of layers from the gvSIG view
|
199 |
199 |
* @return
|
200 |
200 |
*/
|
201 |
201 |
private FLayers getLayers() {
|
202 |
202 |
MapControl mapControl = null;
|
203 |
|
IWindow[] windowList = PluginServices.getMDIManager().getAllWindows();
|
|
203 |
IWindow[] windowList = PluginServices.getMDIManager().getOrderedWindows();
|
204 |
204 |
for (int i = 0; i < windowList.length; i++) {
|
205 |
|
if (windowList[i] instanceof AbstractViewPanel)
|
|
205 |
if (windowList[i] instanceof AbstractViewPanel) {
|
206 |
206 |
mapControl = ((AbstractViewPanel) windowList[i]).getMapControl();
|
|
207 |
break;
|
|
208 |
}
|
207 |
209 |
}
|
208 |
210 |
if (mapControl != null)
|
209 |
211 |
return mapControl.getMapContext().getLayers();
|
210 |
212 |
return null;
|
211 |
213 |
}
|
212 |
|
|
|
214 |
|
213 |
215 |
/**
|
214 |
216 |
* Gets the selected layer
|
215 |
217 |
* @return
|
... | ... | |
223 |
225 |
}
|
224 |
226 |
return null;
|
225 |
227 |
}
|
226 |
|
|
|
228 |
|
227 |
229 |
public boolean isEnabled() {
|
228 |
230 |
return false;
|
229 |
231 |
}
|
... | ... | |
237 |
239 |
IconThemeHelper.registerIcon(null, "mask-icon", this);
|
238 |
240 |
IconThemeHelper.registerIcon(null, "gvsig-icon16x16", this);
|
239 |
241 |
}
|
240 |
|
|
|
242 |
|
241 |
243 |
/**
|
242 |
244 |
* Gets the {@link ROIMaskPanel}
|
243 |
245 |
* @return {@link ROIMaskPanel}
|
... | ... | |
248 |
250 |
Messages.getText("create_output_layer"));
|
249 |
251 |
return newLayerPanel;
|
250 |
252 |
}
|
251 |
|
|
|
253 |
|
252 |
254 |
/**
|
253 |
255 |
* Gets the {@link PreviewPanel}
|
254 |
256 |
* @return {@link PreviewPanel}
|
... | ... | |
258 |
260 |
previewPanel = RasterSwingLocator.getSwingManager().createSinglePreviewPanel(null, getDataSourcePreview());
|
259 |
261 |
return previewPanel;
|
260 |
262 |
}
|
261 |
|
|
|
263 |
|
262 |
264 |
/**
|
263 |
265 |
* Gets the {@link ROIMaskPreview}
|
264 |
266 |
* @return {@link ROIMaskPreview}
|
... | ... | |
270 |
272 |
processPreview.setData(getROIMaskPanel().getDataModel());
|
271 |
273 |
return processPreview;
|
272 |
274 |
}
|
273 |
|
|
|
275 |
|
274 |
276 |
/**
|
275 |
277 |
* Gets the {@link ROIMaskPanel}
|
276 |
278 |
* @return {@link ROIMaskPanel}
|
... | ... | |
284 |
286 |
}
|
285 |
287 |
|
286 |
288 |
public void actionPerformed(ActionEvent e) {
|
287 |
|
if(window != null &&
|
|
289 |
if(window != null &&
|
288 |
290 |
(e.getSource() == ((ROIMaskWindow)window).getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT) ||
|
289 |
291 |
e.getSource() == ((ROIMaskWindow)window).getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY))) {
|
290 |
292 |
DataProcess task = null;
|
... | ... | |
295 |
297 |
}
|
296 |
298 |
task.setActions(this);
|
297 |
299 |
try {
|
298 |
|
getDataSourcePreview().addParams(task,
|
299 |
|
getNewLayerPanel().getDirectorySelected(),
|
|
300 |
getDataSourcePreview().addParams(task,
|
|
301 |
getNewLayerPanel().getDirectorySelected(),
|
300 |
302 |
getNewLayerPanel().getFileSelected());
|
301 |
303 |
} catch (ROIException e1) {
|
302 |
304 |
RasterSwingLibrary.messageBoxError("error_processing_layer", null, e1);
|
... | ... | |
304 |
306 |
task.start();
|
305 |
307 |
return;
|
306 |
308 |
}
|
307 |
|
|
|
309 |
|
308 |
310 |
getPreviewPanel().refreshPreview();
|
309 |
311 |
}
|
310 |
312 |
|
... | ... | |
318 |
320 |
RasterSwingLocator.getSwingManager().showSummaryProcessDialog(fName, milis);
|
319 |
321 |
}
|
320 |
322 |
}
|
321 |
|
|
|
323 |
|
322 |
324 |
private void processFinalize(String fileName, long milis) {
|
323 |
325 |
if (!new File(fileName).exists())
|
324 |
326 |
return;
|
... | ... | |
334 |
336 |
}
|
335 |
337 |
}
|
336 |
338 |
}
|
337 |
|
|
|
339 |
|
338 |
340 |
private String getViewName() {
|
339 |
341 |
FLyrRaster lyrRaster = getSelectedLayer();
|
340 |
342 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
... | ... | |
353 |
355 |
}
|
354 |
356 |
|
355 |
357 |
public void interrupted() {
|
356 |
|
|
|
358 |
|
357 |
359 |
}
|
358 |
|
|
|
360 |
|
359 |
361 |
public class LayerElement {
|
360 |
362 |
private FLayer lyr = null;
|
361 |
363 |
public LayerElement(FLayer lyr) {
|
362 |
364 |
this.lyr = lyr;
|
363 |
365 |
}
|
364 |
|
|
|
366 |
|
365 |
367 |
public FLayer getLayer() {
|
366 |
368 |
return lyr;
|
367 |
369 |
}
|
368 |
|
|
|
370 |
|
369 |
371 |
public String toString() {
|
370 |
372 |
return lyr.getName();
|
371 |
373 |
}
|
372 |
|
|
|
374 |
|
373 |
375 |
public int getNumOfElements() {
|
374 |
376 |
if(lyr instanceof FLyrRaster)
|
375 |
377 |
return ((FLyrRaster)lyr).getDataStore().getBandCount();
|
... | ... | |
379 |
381 |
|
380 |
382 |
public void updateProgress(int current, int total) {
|
381 |
383 |
// TODO Auto-generated method stub
|
382 |
|
|
|
384 |
|
383 |
385 |
}
|
384 |
386 |
}
|