01: package com.vividsolutions.jump.workbench.ui.plugin.imagery;
02:
03: import java.awt.Color;
04: import java.util.Collection;
05:
06: import com.vividsolutions.jump.I18N;
07: import com.vividsolutions.jump.feature.FeatureDataset;
08: import com.vividsolutions.jump.workbench.imagery.ImageryLayerDataset;
09: import com.vividsolutions.jump.workbench.imagery.ReferencedImageStyle;
10: import com.vividsolutions.jump.workbench.model.Layer;
11: import com.vividsolutions.jump.workbench.model.LayerManager;
12: import com.vividsolutions.jump.workbench.model.StandardCategoryNames;
13: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
14: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
15:
16: public class AddImageLayerPlugIn extends AbstractPlugIn {
17: private static int nameCounter = 1;
18:
19: public String getName() {
20: return I18N
21: .get("ui.plugin.imagery.AddImageLayerPlugIn.Add-Image-Layer");
22: }
23:
24: public boolean execute(PlugInContext context) throws Exception {
25: LayerManager lm = context.getLayerManager();
26: ImageFeatureCreator ifc = new ImageFeatureCreator();
27:
28: lm.setFiringEvents(false);
29: Layer layer = createLayer(lm);
30: lm.setFiringEvents(true);
31:
32: Collection features = ifc.getImages(context, layer);
33:
34: if (features != null) {
35: lm.addLayer(chooseCategory(context), layer);
36: layer.getFeatureCollectionWrapper().addAll(features);
37: ifc.setLayerSelectability(layer);
38: }
39:
40: return false;
41: }
42:
43: private String chooseCategory(PlugInContext context) {
44: return context.getLayerNamePanel() == null ? StandardCategoryNames.WORKING
45: : context.getLayerNamePanel().getSelectedCategories()
46: .isEmpty() ? StandardCategoryNames.WORKING
47: : context.getLayerNamePanel()
48: .getSelectedCategories().iterator()
49: .next().toString();
50: }
51:
52: private Layer createLayer(LayerManager lm) {
53: String newLayerName = I18N
54: .get("ui.plugin.imagery.AddImageLayerPlugIn.Image")
55: + "_" + nameCounter++;
56: Layer layer = new Layer(newLayerName, Color.black,
57: new FeatureDataset(ImageryLayerDataset.getSchema()), lm);
58: layer.setEditable(true);
59: // Set fill just for the icon beside the layer name [Jon Aquino
60: // 2005-04-11]
61: layer.getBasicStyle().setRenderingFill(false);
62: layer.getBasicStyle().setEnabled(false);
63: layer.addStyle(new ReferencedImageStyle());
64: return layer;
65: }
66:
67: }
|