@Override public void internalFrameDeactivated(InternalFrameEvent e) { final ProductSceneView sceneView = getView(e); if (sceneView != null) { productTree.deregisterActiveProductNodes(sceneView.getRasters()); deregisterActiveVectorDataNode(sceneView); } }
@Override public void internalFrameClosed(InternalFrameEvent e) { final ProductSceneView sceneView = getView(e); if (sceneView != null) { sceneView.removePropertyChangeListener( ProductSceneView.PROPERTY_NAME_SELECTED_LAYER, selectedLayerPCL); productTree.deregisterOpenedProductNodes(sceneView.getRasters()); productTree.deregisterActiveProductNodes(sceneView.getRasters()); deregisterActiveVectorDataNode(sceneView); } }
@Override public void actionPerformed(CommandEvent event) { JTextArea textArea = new JTextArea(16, 32); textArea.setEditable(true); JPanel contentPanel = new JPanel(new BorderLayout(4, 4)); contentPanel.add(new JLabel("Geometry Well-Known-Text (WKT):"), BorderLayout.NORTH); contentPanel.add(new JScrollPane(textArea), BorderLayout.CENTER); VisatApp visatApp = VisatApp.getApp(); ModalDialog modalDialog = new ModalDialog(visatApp.getApplicationWindow(), DLG_TITLE, ModalDialog.ID_OK_CANCEL, null); modalDialog.setContent(contentPanel); modalDialog.center(); if (modalDialog.show() == ModalDialog.ID_OK) { String wellKnownText = textArea.getText(); if (wellKnownText == null || wellKnownText.isEmpty()) { return; } ProductSceneView sceneView = visatApp.getSelectedProductSceneView(); VectorDataLayer vectorDataLayer = InsertFigureInteractorInterceptor.getActiveVectorDataLayer(sceneView); if (vectorDataLayer == null) { return; } SimpleFeatureType wktFeatureType = PlainFeatureFactory.createDefaultFeatureType(DefaultGeographicCRS.WGS84); ListFeatureCollection newCollection = new ListFeatureCollection(wktFeatureType); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(wktFeatureType); SimpleFeature wktFeature = featureBuilder.buildFeature("ID" + Long.toHexString(currentFeatureId++)); Geometry geometry; try { geometry = new WKTReader().read(wellKnownText); } catch (ParseException e) { visatApp.handleError("Failed to convert WKT into geometry", e); return; } wktFeature.setDefaultGeometry(geometry); newCollection.add(wktFeature); FeatureCollection<SimpleFeatureType, SimpleFeature> productFeatures = FeatureUtils.clipFeatureCollectionToProductBounds( newCollection, sceneView.getProduct(), null, ProgressMonitor.NULL); if (productFeatures.isEmpty()) { visatApp.showErrorDialog(DLG_TITLE, "The geometry is not contained in the product."); } else { vectorDataLayer.getVectorDataNode().getFeatureCollection().addAll(productFeatures); } } }
private static void setSelectedVectorDataNode( ProductSceneView sceneView, final VectorDataNode vectorDataNode) { final LayerFilter layerFilter = new LayerFilter() { @Override public boolean accept(Layer layer) { return layer instanceof VectorDataLayer && ((VectorDataLayer) layer).getVectorDataNode() == vectorDataNode; } }; Layer layer = LayerUtils.getChildLayer(sceneView.getRootLayer(), LayerUtils.SEARCH_DEEP, layerFilter); if (layer != null) { sceneView.setSelectedLayer(layer); } }
private static VectorDataNode getSelectedVectorDataNode(ProductSceneView sceneView) { final Layer layer = sceneView.getSelectedLayer(); if (layer instanceof VectorDataLayer) { final VectorDataLayer vectorDataLayer = (VectorDataLayer) layer; return vectorDataLayer.getVectorDataNode(); } else { return null; } }
static boolean insertImageLayer(LayerSourcePageContext pageContext) { AffineTransform transform = (AffineTransform) pageContext.getPropertyValue(PROPERTY_NAME_WORLD_TRANSFORM); String imageFilePath = (String) pageContext.getPropertyValue(PROPERTY_NAME_IMAGE_FILE_PATH); try { ProductSceneView sceneView = SnapApp.getDefault().getSelectedProductSceneView(); final ImageFileLayerType type = LayerTypeRegistry.getLayerType(ImageFileLayerType.class); final PropertySet configuration = type.createLayerConfig(sceneView); configuration.setValue(ImageFileLayerType.PROPERTY_NAME_IMAGE_FILE, new File(imageFilePath)); configuration.setValue(ImageFileLayerType.PROPERTY_NAME_WORLD_TRANSFORM, transform); Layer layer = type.createLayer(sceneView, configuration); layer.setName(FileUtils.getFileNameFromPath(imageFilePath)); Layer rootLayer = sceneView.getRootLayer(); rootLayer.getChildren().add(sceneView.getFirstImageLayerIndex(), layer); return true; } catch (Exception e) { pageContext.showErrorDialog(e.getMessage()); return false; } }