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; } }
@Override public void cancel(LayerSourcePageContext pageContext) { pageContext.setPropertyValue(PROPERTY_NAME_IMAGE_FILE_PATH, null); }